<?
# Copyright 2010 by Ben Collins <bcollins@ubuntu.com>
# Licensed under the GPLv3
#
# July 29, 2010: Flattr v0.2 load.js does not expect bin2hex for data
# anymore. Pass arguments as normal GET

include_once("simple_html_dom.php");

function 
errout($msg) {
//    echo $msg;
}

function 
uriencode($data) {
    
$ret str_replace(array('\r\n''\r''\n'), ''$data);
    
$ret urlencode($ret);
    return 
$ret;
}

if (!isset(
$_GET['link']))
    
errout("Need link passed");

$uid "895";
$link $_GET['link'];
$btn_url "http://api.flattr.com/button/view/?";

$data "uid=$uid&url=$link&lng=$lng";

# Now retrieve the button and extract some info from it
$btn file_get_html($btn_url $data);

if (
$btn == '')
    
errout("Failed to get button code: $btn_url" $data);

$els $btn->find("span.flattr-count");
$count $els[0]->innertext;

if (
$count == "!")
    
errout("Error from flattr.com");

$els $btn->find("a.flattr-pop");
$link $els[0]->href;

$els $btn->find("span.flattr-link");
$txt $els[0]->innertext;

if (
$link == '' or $txt == '')
    
errout("Invalid information from flattr.com");

echo 
$count;
?>