summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2008-01-18 16:29:43 +0100
committerHugues Hiegel <hugues@hiegel.fr>2008-01-18 16:29:43 +0100
commitab117cb1e09998929e19d21291accf73a9e24e13 (patch)
treee7df830f78c352bfbc028f8ee8682b863554a2a6
Repository creation from my ~/www
-rw-r--r--.todo26
l---------Badges.php1
-rw-r--r--Badges_v1.php245
-rw-r--r--Badges_v2.php264
-rw-r--r--Badges_v3.php242
-rw-r--r--Config.php63
-rw-r--r--Last.fm.php199
l---------Monthly.php1
l---------TotalTracks.php1
l---------TrueFalse.php1
10 files changed, 1043 insertions, 0 deletions
diff --git a/.todo b/.todo
new file mode 100644
index 0000000..f9cfb95
--- /dev/null
+++ b/.todo
@@ -0,0 +1,26 @@
+<todo version="0.1.19">
+ <title>
+ Last.fm badges
+ </title>
+ <note priority="veryhigh" time="1169636004" done="1182292103">
+ Proposer la TRANSPARENCE en vrai
+ <comment>
+ C'est fait :)
+ </comment>
+ </note>
+ <note priority="medium" time="1169635922" done="1174032572">
+ Proposer des couleurs
+ </note>
+ <note priority="medium" time="1169635992" done="1182292123">
+ Proposer un texte modifiable a volonte. En fait proposer un seul texte modifiable.... Mais faire ca une fois que j'aurai mieux maitrise le calcul et le positionnement dudit texte
+ <comment>
+ Je gère beaucoup mieux le positionnement du texte maintenant ;o)
+ </comment>
+ </note>
+ <note priority="high" time="1174667659" done="1185320316">
+ Corriger la gestion des username contenant des caracteres tels que '[' et ']'
+ </note>
+ <note priority="medium" time="1169635953">
+ Proposer des tailles differentes (mieux, proposer des TYPES de tailles : badge, signature)
+ </note>
+</todo>
diff --git a/Badges.php b/Badges.php
new file mode 120000
index 0000000..acb2261
--- /dev/null
+++ b/Badges.php
@@ -0,0 +1 @@
+Badges_v2.php \ No newline at end of file
diff --git a/Badges_v1.php b/Badges_v1.php
new file mode 100644
index 0000000..7f475d0
--- /dev/null
+++ b/Badges_v1.php
@@ -0,0 +1,245 @@
+<?
+
+clearstatcache();
+
+$Pathinfo=$_SERVER['PATH_INFO'];
+$pathinfo=explode("/", $Pathinfo);
+$script=explode("/", $_SERVER['SCRIPT_NAME']);
+
+$username=$pathinfo[1];
+$type=$pathinfo[2];
+$style=$pathinfo[3];
+$color=$pathinfo[4];
+
+include("Config.php");
+
+$Stats=CACHE_FOLDER."/Stats/".strtolower(rawurlencode($username)).".xml";
+$Cache=CACHE_FOLDER."/Pictures/".strtolower(rawurlencode($username))."_$type-$style-$color.png";
+//if ($username == "gugusse") $Cache="";
+
+function GetColor($color, $code) {
+ switch($color)
+ {
+ case "r":
+ return ($code >> 16) & 0xff;
+ break;
+ case "g":
+ return ($code >> 8) & 0xff;
+ break;
+ case "b":
+ return ($code >> 0) & 0xff;
+ break;
+ }
+}
+
+header("Content-Type: image/png");
+
+if ( ! is_file($Stats)
+ ||(filemtime($Stats) + CACHE < $_SERVER['REQUEST_TIME']))
+{
+ system("wget --no-cache http://ws.audioscrobbler.com/1.0/user/".rawurlencode($username)."/profile.xml -O $Stats");
+}
+
+if ( is_file($Cache)
+ && is_file($Stats)
+ &&(filemtime($Cache) > filemtime($Stats))
+ )
+{
+ $fd=fopen($Cache, "r");
+ echo fread($fd, filesize($Cache));
+ fclose($fd);
+ exit;
+}
+
+
+class Text {
+ var $width = 0;
+ var $height = 0;
+ var $x = 0;
+ var $y = 0;
+
+ var $font = "";
+ var $size = 24;
+ var $angle = 0;
+ var $color = 0;
+ var $value = "";
+
+ function initiate($size) {
+ $this->width = max($size[0], $size[2], $size[4], $size[6]) - min(0, $size[0], $size[2], $size[4], $size[6]);
+ $this->height= max($size[1], $size[3], $size[5], $size[7]) - min(0, $size[1], $size[3], $size[5], $size[7]);
+ }
+}
+
+/*system("wget http://ws.audioscrobbler.com/1.0/user/gugusse/friends.txt -O - | grep -i $username > /dev/null", $exitcode);*/
+
+$MainText = new Text;
+$Info = new Text;
+
+$feed=new XMLReader();
+if ($feed->open($Stats))
+ while ($feed->read())
+ {
+ switch ($feed->name)
+ {
+ case "playcount":
+ $feed->read();
+ $playcount=$feed->value;
+ $feed->read();
+ break;
+
+ case "registered":
+ case "statsreset":
+ $statsstart=$feed->getAttribute("unixtime");
+ $feed->read();
+ $feed->read();
+ break;
+
+ case "profile":
+ $username=$feed->getAttribute("username");
+ break;
+ }
+ }
+
+if (! $playcount)
+{
+ $MainText->value="Sorry, $username is not";
+ $Info->value="a valid Last.fm account";
+ $MainText->angle=2;
+ $Info->angle=1;
+ $FinalHeight=50;
+ $Cache="";
+}
+else
+{
+ $duration = $_SERVER['REQUEST_TIME'] - $statsstart;
+ $months = $duration / (60*60*24*30);
+ $weeks = $duration / (60*60*24*7);
+ $days = $duration / (60*60*24);
+ $permonth = floor($playcount / $months);
+ $perweek = floor($playcount / $weeks);
+ $perday = floor($playcount / $days);
+
+ switch($type)
+ {
+ case "PerDay":
+ $MainText->value = "$perday tracks per Day";
+ $MainText->angle = 2;
+ $Info->value = "";
+ $FinalHeight=20;
+ break;
+ case "PerWeek":
+ $MainText->value = "$perweek tracks per Week";
+ $MainText->angle = 2;
+ $Info->value = "";
+ $FinalHeight=20;
+ break;
+ case "PerMonth":
+ $MainText->value = "$permonth tracks per Month";
+ $MainText->angle = 2;
+ $Info->value = "";
+ $FinalHeight=20;
+ break;
+ case "Trueness":
+ $MainText->value = ucfirst($username)." is ";
+ $MainText->value .= ($permonth > TRUENESS ? "an" : "a");
+ $MainText->angle = 3;
+ $FinalHeight=50;
+ $Info->value = ($permonth > TRUENESS ? "untrue" : "true");
+ $Info->value .= " listener";
+ $Info->angle = 2;
+ break;
+ case "Total":
+ $MainText->value = "$playcount tracks played";
+ $MainText->angle = 2;
+ $Info->angle = 1;
+ $Info->value = strftime("since %B %Y", $statsstart);
+ $FinalHeight=40;
+ break;
+ default:
+ $MainText->value = "Sorry, unavailable !";
+ break;
+ }
+
+ $MainText->font = "import/" . $Styles[$style];
+ $Info->font = $MainText->font;
+
+
+}
+
+$size=imageftbbox($MainText->size, $MainText->angle, $MainText->font, $MainText->value);
+$MainText->initiate($size);
+$MainText->x=0;
+$MainText->y=$MainText->height;
+if ($Info->value != "")
+{
+ $size=imageftbbox($Info->size, $Info->angle, $Info->font, $Info->value);
+ $Info->initiate($size);
+ $Info->x=0;
+ $Info->y=$MainText->height + $Info->height;
+}
+
+$Image = new Text;
+$Image->width=max($MainText->width, $Info->width);
+$Image->height=$MainText->height;
+$Image->height+=$Info->height;
+
+$MainText->x = max(0, floor(($Image->width - $MainText->width) / 2));
+$MainText->y = 0;
+$Info->x = max(0, floor(($Image->width - $Info->width) / 2));
+$Info->y = $MainText->height + 1;
+
+$img=imagecreatetruecolor($Image->width, $Image->height);
+imagealphablending($img, FALSE);
+imagesavealpha($img, TRUE);
+
+$MainText->color=imagecolorallocate($img, GetColor("r", $Colors[$color]),
+ GetColor("g", $Colors[$color]),
+ Getcolor("b", $Colors[$color]));
+$Info->color=$MainText->color;
+
+
+$transparent=imagecolorallocatealpha($img, 255, 255, 255, 127);
+$area=imagefilledrectangle($img, 0, 0, $Image->width, $Image->height, $transparent);
+
+imagettftext($img, $MainText->size, $MainText->angle, $MainText->x, $MainText->y + $MainText->height - 1, $MainText->color, $MainText->font, $MainText->value);
+if ($Info->value != "")
+ imagettftext($img, $Info->size, $Info->angle, $Info->x, $Info->y + $Info->height - 1, $Info->color, $Info->font, $Info->value);
+
+$new=imagecreatetruecolor(150, $FinalHeight);
+imagealphablending($new, FALSE);
+imagesavealpha($new, TRUE);
+
+$area=imagefilledrectangle($new, 0, 0, 150, $FinalHeight, $transparent);
+
+$y=floor($MainText->height * $FinalHeight / $Image->height);
+
+imagecopyresampled($new,
+ $img,
+ 0,
+ 0,
+ $MainText->x,
+ $MainText->y,
+ 150,
+ $y,
+ $MainText->width,
+ $MainText->height);
+
+if ($Info->value != "")
+ imagecopyresampled($new,
+ $img,
+ 0,
+ $y + 1,
+ $Info->x,
+ $Info->y,
+ 150,
+ ceil($Info->height * $FinalHeight / $Image->height),
+ $Info->width,
+ $Info->height);
+ //imagecopyresampled($new, $img, 0, 0, 0, 0, 150, $FinalHeight, $Image->width, $Image->height);
+imagedestroy($img);
+
+if ($Cache != "") imagepng($new, $Cache);
+imagepng($new);
+imagedestroy($new);
+
+?>
diff --git a/Badges_v2.php b/Badges_v2.php
new file mode 100644
index 0000000..e194121
--- /dev/null
+++ b/Badges_v2.php
@@ -0,0 +1,264 @@
+<?
+
+clearstatcache();
+
+$Pathinfo=$_SERVER['PATH_INFO'];
+$pathinfo=explode("/", $Pathinfo);
+$script=explode("/", $_SERVER['SCRIPT_NAME']);
+
+$username=$pathinfo[1];
+$type=$pathinfo[2];
+$style=$pathinfo[3];
+$color=$pathinfo[4];
+
+include("Config.php");
+
+$UserName = str_replace("_", " ", ucfirst($username));
+
+$Stats=CACHE_FOLDER."/Stats/".escapeshellcmd(strtolower($username)).".xml";
+$XmlStats=CACHE_FOLDER."/Stats/".strtolower($username).".xml";
+$Cache=CACHE_FOLDER."/Pictures/".escapeshellcmd(strtolower($username))."_$type-$style-$color.png";
+if (strtolower($username) == "gugusse") $Cache="";
+
+function GetColor($color, $code) {
+ switch($color)
+ {
+ case "r":
+ return ($code >> 16) & 0xff;
+ break;
+ case "g":
+ return ($code >> 8) & 0xff;
+ break;
+ case "b":
+ return ($code >> 0) & 0xff;
+ break;
+ }
+}
+
+header("Content-Type: image/png");
+
+if ( ! is_file($Stats)
+ ||(filemtime($Stats) + CACHE < $_SERVER['REQUEST_TIME']))
+{
+ system("wget --no-cache http://ws.audioscrobbler.com/1.0/user/".rawurlencode($username)."/profile.xml -O $Stats.tmp");
+ system("mv $Stats.tmp $Stats");
+}
+
+if ( is_file($Cache)
+ && is_file($Stats)
+ &&(filemtime($Cache) > filemtime($Stats))
+ )
+{
+ $fd=fopen($Cache, "r");
+ echo fread($fd, filesize($Cache));
+ fclose($fd);
+ exit;
+}
+
+
+class Text {
+ var $width = 0;
+ var $height = 0;
+ var $x = 0;
+ var $y = 0;
+
+ var $font = "";
+ var $size = 150; // High values to better quality
+ var $angle = 2;
+ var $color = 0;
+ var $value = "";
+
+ function initiate($size) {
+ $this->x = 0;
+ $this->width = abs(
+ max($size[0], $size[2], $size[4], $size[6])
+ - min($size[0], $size[2], $size[4], $size[6])
+ );
+ $this->height= abs(
+ max($size[1], $size[3], $size[5], $size[7])
+ - min($size[1], $size[3], $size[5], $size[7])
+ );
+
+ $ratio = WIDTH / $this->width;
+
+ $this->width = WIDTH;
+ $this->height *= $ratio;
+ $this->size = floor($this->size * $ratio);
+ }
+}
+$Lines = array();
+$Lines[] = new Text;
+
+$feed=new XMLReader();
+if ($feed->open($XmlStats))
+ while ($feed->read())
+ {
+ switch ($feed->name)
+ {
+ case "playcount":
+ $feed->read();
+ $playcount=$feed->value;
+ $feed->read();
+ break;
+
+ case "registered":
+ case "statsreset":
+ $statsstart=$feed->getAttribute("unixtime");
+ $feed->read();
+ $feed->read();
+ break;
+
+ case "profile":
+ $username=$feed->getAttribute("username");
+ break;
+ }
+ }
+
+if (! $playcount)
+{
+ $Lines[0]->value="Sorry, $username is not";
+ $Lines[0]->angle=2;
+ $Lines[] = new Text;
+ $Lines[1]->value="a valid Last.fm account";
+ $Lines[1]->angle=1;
+ define(HEIGHT, 50);
+ $Cache="";
+}
+else
+{
+ $duration = $_SERVER['REQUEST_TIME'] - $statsstart;
+ $months = $duration / (60*60*24*30);
+ $weeks = $duration / (60*60*24*7);
+ $days = $duration / (60*60*24);
+ $permonth = floor($playcount / $months);
+ $perweek = floor($playcount / $weeks);
+ $perday = floor($playcount / $days);
+
+ switch($type)
+ {
+ case "PerDay":
+ $Lines[0]->value = "$perday tracks per Day";
+ $Lines[0]->angle = 2;
+ break;
+ case "PerWeek":
+ $Lines[0]->value = "$perweek tracks per Week";
+ $Lines[0]->angle = 2;
+ break;
+ case "PerMonth":
+ $Lines[0]->value = "$permonth tracks per Month";
+ $Lines[0]->angle = 2;
+ break;
+ case "PerDay2":
+ $Lines[] = new Text;
+ $Lines[0]->value = "$perday";
+ $Lines[1]->value = "tracks per Day";
+ break;
+ case "PerWeek2":
+ $Lines[] = new Text;
+ $Lines[0]->value = "$perweek";
+ $Lines[1]->value = "tracks per Week";
+ break;
+ case "PerMonth2":
+ $Lines[] = new Text;
+ $Lines[1]->value = "tracks per Month";
+ $Lines[0]->value = "$permonth";
+ break;
+ case "Trueness":
+ $Lines[0]->value = "is ";
+ $Lines[0]->value .= ($permonth > TRUENESS ? "an" : "a");
+ $Lines[0]->angle = 3;
+ define(HEIGHT, 50);
+ $Lines[] = new Text;
+ $Lines[1]->value = ($permonth > TRUENESS ? "untrue" : "true");
+ $Lines[1]->value .= " listener";
+ $Lines[1]->angle = 2;
+
+ if (strlen($username." ".$Lines[0]->value) >= strlen($Lines[1]->value))
+ {
+ $Lines[1]->value = $Lines[0]->value." ".$Lines[1]->value;
+ $Lines[0]->value = $UserName;
+ }
+ else
+ {
+ $Lines[0]->value = $UserName." ".$Lines[0]->value;
+ }
+ break;
+ case "Trueness2":
+ $Lines[] = new Text;
+ $Lines[] = new Text;
+ $Lines[0]->value = "$UserName is ";
+ $Lines[0]->value .= ($permonth > TRUENESS ? "an" : "a" ) ;
+ $Lines[1]->value = ($permonth > TRUENESS ? "Untrue" : "True");
+ $Lines[2]->value = "listener";
+ break;
+ case "Since":
+ $Lines[0]->value = strftime("since %B %Y", $statsstart);
+ $Lines[0]->angle = 1;
+ break;
+ case "Since2":
+ $Lines[] = new Text;
+ $Lines[] = new Text;
+ $Lines[0]->value = "listening since";
+ $Lines[1]->value = strftime("%B", $statsstart);
+ $Lines[2]->value = strftime("%Y", $statsstart);
+ break;
+ case "Total":
+ $Lines[0]->value = "$playcount tracks played";
+ $Lines[0]->angle = 1;
+ define(HEIGHT, 40);
+ break;
+ case "Total2":
+ $Lines[0]->value = "$playcount";
+ $Lines[] = new Text;
+ $Lines[1]->value = "tracks played";
+ break;
+ default:
+ $Lines[0]->value = "Sorry !";
+ $Lines[] = new Text;
+ $Lines[1]->value = "Not available anymore";
+ define(HEIGHT, 50);
+ break;
+ }
+
+ foreach ($Lines as $Line)
+ $Line->font = "import/" . $Styles[$style];
+
+}
+
+$y=0;
+foreach ($Lines as $Line)
+{
+ $size=imageftbbox($Line->size, $Line->angle, $Line->font, $Line->value);
+ $Line->initiate($size);
+ $y+=$Line->height;
+ $Line->y=$y;
+}
+
+$Image = new Text;
+$Image->width = WIDTH;
+$Image->height = $y;
+
+$img=imagecreatetruecolor($Image->width, $Image->height);
+imagealphablending($img, FALSE);
+imagesavealpha($img, TRUE);
+
+foreach ($Lines as $Line)
+{
+ $Line->color=imagecolorallocate($img, GetColor("r", $Colors[$color]),
+ GetColor("g", $Colors[$color]),
+ Getcolor("b", $Colors[$color]));
+}
+
+$transparent=imagecolorallocatealpha($img, 255, 255, 255, 127);
+
+imagefilledrectangle($img, 0, 0, $Image->width, $Image->height, $transparent);
+
+foreach ($Lines as $Line)
+ imagettftext($img, $Line->size, $Line->angle, $Line->x, $Line->y, $Line->color, $Line->font, $Line->value);
+
+imagepng($img);
+
+if ($Cache != "") imagepng($img, $Cache);
+imagedestroy($img);
+
+?>
diff --git a/Badges_v3.php b/Badges_v3.php
new file mode 100644
index 0000000..c8e43d3
--- /dev/null
+++ b/Badges_v3.php
@@ -0,0 +1,242 @@
+<?
+
+clearstatcache();
+
+$Pathinfo=$_SERVER['PATH_INFO'];
+$pathinfo=explode("/", $Pathinfo);
+$script=explode("/", $_SERVER['SCRIPT_NAME']);
+
+$username=$pathinfo[1];
+$type=$pathinfo[2];
+$style=$pathinfo[3];
+$color=$pathinfo[4];
+
+include("Config.php");
+
+$UserName = str_replace("_", " ", ucfirst($username));
+
+$Stats=CACHE_FOLDER."/Stats/".strtolower(rawurlencode($username)).".xml";
+$Cache=CACHE_FOLDER."/Pictures/".strtolower(rawurlencode($username))."_$type-$style-$color.png";
+if ($username == "gugusse") $Cache="";
+
+function GetColor($color, $code) {
+ switch($color)
+ {
+ case "r":
+ return ($code >> 16) & 0xff;
+ break;
+ case "g":
+ return ($code >> 8) & 0xff;
+ break;
+ case "b":
+ return ($code >> 0) & 0xff;
+ break;
+ }
+}
+
+header("Content-Type: image/png");
+
+if ( ! is_file($Stats)
+ ||(filemtime($Stats) + CACHE < $_SERVER['REQUEST_TIME']))
+{
+ system("wget --no-cache http://ws.audioscrobbler.com/1.0/user/".rawurlencode($username)."/profile.xml -O $Stats.tmp 2>/dev/null");
+ system("mv $Stats.tmp $Stats 2>/dev/null");
+}
+
+if ( is_file($Cache)
+ && is_file($Stats)
+ &&(filemtime($Cache) > filemtime($Stats))
+ )
+{
+ $fd=fopen($Cache, "r");
+ echo fread($fd, filesize($Cache));
+ fclose($fd);
+ exit;
+}
+
+
+class Text {
+ var $width = 0;
+ var $height = 0;
+ var $x = 0;
+ var $y = 0;
+
+ var $font = "";
+ var $size = 150; // High values to better quality
+ var $angle = 0;
+ var $color = 0;
+ var $value = "";
+
+ function initiate($size) {
+ $this->width = abs(
+ max($size[0], $size[2], $size[4], $size[6])
+ - min(0, $size[0], $size[2], $size[4], $size[6])
+ );
+ $this->height= abs(
+ max($size[1], $size[3], $size[5], $size[7])
+ - min(0, $size[1], $size[3], $size[5], $size[7])
+ );
+
+ $ratio = WIDTH / $this->width;
+
+ $this->width *= WIDTH;
+ $this->height *= $ratio;
+ $this->size *= $ratio;
+ }
+}
+
+
+$Line1 = new Text;
+$Line2 = new Text;
+
+$feed=new XMLReader();
+if ($feed->open($Stats))
+ while ($feed->read())
+ {
+ switch ($feed->name)
+ {
+ case "playcount":
+ $feed->read();
+ $playcount=$feed->value;
+ $feed->read();
+ break;
+
+ case "registered":
+ case "statsreset":
+ $statsstart=$feed->getAttribute("unixtime");
+ $feed->read();
+ $feed->read();
+ break;
+
+ case "profile":
+ $username=$feed->getAttribute("username");
+ break;
+ }
+ }
+
+if (! $playcount)
+{
+ $Line1->value="Sorry, $username is not";
+ $Line2->value="a valid Last.fm account";
+ $Line1->angle=2;
+ $Line2->angle=1;
+ //define(HEIGHT, 50);
+ $Cache="";
+}
+else
+{
+ $duration = $_SERVER['REQUEST_TIME'] - $statsstart;
+ $months = $duration / (60*60*24*30);
+ $weeks = $duration / (60*60*24*7);
+ $days = $duration / (60*60*24);
+ $permonth = floor($playcount / $months);
+ $perweek = floor($playcount / $weeks);
+ $perday = floor($playcount / $days);
+
+ switch($type)
+ {
+ case "PerDay":
+ $Line1->value = "$perday tracks per Day";
+ $Line1->angle = 2;
+ $Line2->value = "";
+ break;
+ case "PerWeek":
+ $Line1->value = "$perweek tracks per Week";
+ $Line1->angle = 2;
+ $Line2->value = "";
+ break;
+ case "PerMonth":
+ $Line1->value = "$permonth tracks per Month";
+ $Line1->angle = 2;
+ $Line2->value = "";
+ break;
+ case "Trueness":
+ $Line1->value = "is ";
+ $Line1->value .= ($permonth > TRUENESS ? "an" : "a");
+ $Line1->angle = 3;
+ //define(HEIGHT, 50);
+ $Line2->value = ($permonth > TRUENESS ? "untrue" : "true");
+ $Line2->value .= " listener";
+ $Line2->angle = 2;
+
+ if (strlen($username." ".$Line1->value) >= strlen($Line2->value))
+ {
+ $Line2->value = $Line1->value." ".$Line2->value;
+ $Line1->value = $UserName;
+ }
+ else
+ {
+ $Line1->value = $UserName." ".$Line1->value;
+ }
+ break;
+ case "Listens":
+ $Line1->value = $UserName . " listens to";
+ $Line1->angle = 2;
+ break;
+ case "Since":
+ $Line1->value = strftime("since %B %Y", $statsstart);
+ $Line1->angle = 1;
+ break;
+ case "Total":
+ $Line1->value = "$playcount tracks played";
+ $Line1->angle = 1;
+ //define(HEIGHT, 40);
+ break;
+ default:
+ $Line1->value = "Sorry, unavailable !";
+ break;
+ }
+
+ $Line1->font = "import/" . $Styles[$style];
+ $Line2->font = $Line1->font;
+}
+
+$size=imageftbbox($Line1->size, $Line1->angle, $Line1->font, $Line1->value);
+$Line1->initiate($size);
+
+$Line1->x=0;
+$Line1->y=$Line1->height - 1;
+if ($Line2->value != "")
+{
+ $size=imageftbbox($Line2->size, $Line2->angle, $Line2->font, $Line2->value);
+ $Line2->initiate($size);
+ $Line2->x=0;
+ $Line2->y=$Line1->height + $Line2->height - 1;
+
+ $Line1->size = min($Line1->size, $Line2->size);
+ $Line2->size = $Line1->size;
+}
+
+$Image = new Text;
+$Image->width = WIDTH;
+$Image->height = $Line1->height;
+$Image->height += $Line2->height;
+$Image->height += $Image->height * 0.3;
+
+$Line1->x = max(0, floor(($Image->width - $Line1->width) / 2));
+$Line1->y = 0;
+$Line2->x = max(0, floor(($Image->width - $Line2->width) / 2));
+$Line2->y = $Line1->height + 1;
+
+$img=imagecreatetruecolor($Image->width, $Image->height);
+imagealphablending($img, FALSE);
+imagesavealpha($img, TRUE);
+
+$Line1->color=imagecolorallocate($img, GetColor("r", $Colors[$color]),
+ GetColor("g", $Colors[$color]),
+ Getcolor("b", $Colors[$color]));
+$Line2->color=$Line1->color;
+
+
+$transparent=imagecolorallocatealpha($img, 255, 255, 255, 127);
+
+imagefilledrectangle($img, 0, 0, $Image->width, $Image->height, $transparent);
+imagettftext($img, $Line1->size, $Line1->angle, $Line1->x, $Line1->y + $Line1->height - 1, $Line1->color, $Line1->font, $Line1->value);
+if ($Line2->value != "")
+ imagettftext($img, $Line2->size, $Line2->angle, $Line2->x, $Line2->y + $Line2->height - 1, $Line2->color, $Line2->font, $Line2->value);
+imagepng($img);
+
+if ($Cache != "") imagepng($img, $Cache);
+imagedestroy($img);
+
+?>
diff --git a/Config.php b/Config.php
new file mode 100644
index 0000000..1b2633e
--- /dev/null
+++ b/Config.php
@@ -0,0 +1,63 @@
+<?
+
+define(TRUENESS, 4000);
+define(CACHE, (3600*24));
+define(WIDTH, 160);
+define(HEIGHT, 20);
+putenv("GDFONTPATH=/usr/share/fonts/truetype");
+
+define(CACHE_FOLDER, "/var/www/cache/.lastfm");
+
+$Styles = array ("Modern" => "It_wasn_t_me",
+ "Letters" => "JackOLantern",
+ "Romantic" => "Shelley_Volante",
+ "Elegant" => "ITCEdScr",
+ "Screamy" => "Junkyard",
+ "Girlie" => "girlw___",
+ "Funny" => "PenguinAttack",
+ "Curly" => "Curlz___",
+ "Ruritania"=> "Ruritania",
+ "Simple" => "Georgia",
+ "Morpheus" => "Morpheus",
+ "Flamy" => "Baileysc",
+ "FaceLift" => "facerg__",
+ "TypeO" => "typeo___",
+ "Grindy" => "Jack_the_Hipper",
+ "Horrorful"=> "horrh___"
+ );
+
+$Colors = array(
+ "Black" => 0x000000,
+ "Red" => 0xd11f3c,
+ "Green" => 0x32dc32,
+ "Yellow" => 0xdcdc32,
+ "Blue" => 0x3232dc,
+ "LightBlue" => 0x6666aa,
+ "Gray" => 0xdcdcdc,
+ "White" => 0xffffff
+ );
+
+$Types = array(
+ "Total" => "Total tracks_ #1",
+ "Total2" => "Total tracks_ #2",
+ "PerDay" => "Daily tracks_ #1",
+ "PerDay2" => "Daily tracks_ #2",
+ "PerWeek" => "Weekly tracks_ #1",
+ "PerWeek2" => "Weekly tracks_ #2",
+ "PerMonth" => "Monthly tracks_ #1",
+ "PerMonth2" => "Monthly tracks_ #2",
+ "Since" => "Since #1",
+ "Since2" => "Since #2",
+ "Trueness" => "Trueness #1",
+ "Trueness2" => "Trueness #2"
+ );
+
+$Description = array("Trueness" => "<a href=\"http://www.last.fm/group/true+listener\">What's the heck is this </a> ?");
+
+// DEFAULT VALUES //
+if ($user == "") $user="gugusse";
+if (!array_key_exists($style, $Styles)) $style="TypeO";
+if (!array_key_exists($color, $Colors)) $color="Black";
+if (!array_key_exists($type, $Types)) { $type="UNAVAILABLE" ; $color="Black" ; $username="gugusse" ; }
+
+?>
diff --git a/Last.fm.php b/Last.fm.php
new file mode 100644
index 0000000..228b6a8
--- /dev/null
+++ b/Last.fm.php
@@ -0,0 +1,199 @@
+<?
+
+$Pathinfo=$_SERVER['PATH_INFO'];
+$pathinfo=explode("/", $Pathinfo);
+$script=explode("/", $_SERVER['SCRIPT_NAME']);
+
+$type=$script[3];
+$username=$pathinfo[1];
+if ($username == "") $username="gugusse";
+
+//$Stats=".lastfm/Stats/".strtolower(rawurlencode($username)).".xml";
+$Cache="/blackhole/.lastfm/Oldies/UNAVAILABLE.png";
+//$Cache="";
+$CacheTime = array("Monthly" => 7*24*60*60,
+ "TotalTracks" => 600,
+ "TrueFalse" => 7*24*60*60);
+
+if (! array_key_exists($type, $CacheTime))
+ exit;
+
+header("Content-Type: image/png");
+
+/*if ( ! is_file($Stats)
+ ||(filemtime($Stats) + $CACHE < $_SERVER['REQUEST_TIME']))
+{
+// system("wget --no-cache http://ws.audioscrobbler.com/1.0/user/".rawurlencode($username)."/profile.xml -O $Stats");
+}*/
+
+if ( is_file($Cache)
+/* && is_file($Stats)
+ &&(filemtime($Cache) > filemtime($Stats))*/
+ )
+{
+ $fd=fopen($Cache, "r");
+ echo fread($fd, filesize($Cache));
+ fclose($fd);
+ exit;
+}
+
+putenv("GDFONTPATH=/usr/share/fonts/truetype");
+
+class Text {
+ var $width = 0;
+ var $height = 0;
+ var $x = 0;
+ var $y = 0;
+
+ var $font = "import/typeo___";
+ var $size = 0;
+ var $angle = 0;
+ var $color = 0;
+ var $value = "";
+
+ function initiate($size) {
+ $this->width = max($size[0], $size[2], $size[4], $size[6]) - min(0, $size[0], $size[2], $size[4], $size[6]);
+ $this->height= max($size[1], $size[3], $size[5], $size[7]) - min(0, $size[1], $size[3], $size[5], $size[7]);
+ }
+}
+
+/*system("wget http://ws.audioscrobbler.com/1.0/user/gugusse/friends.txt -O - | grep -i $username > /dev/null", $exitcode);*/
+
+$MainText = new Text;
+$Info = new Text;
+
+//$feed=new XMLReader();
+/*if ($feed->open("$Stats"))
+ while ($feed->read())
+ {
+ switch ($feed->name)
+ {
+ case "playcount":
+ $feed->read();
+ $playcount=$feed->value;
+ $feed->read();
+ break;
+
+ case "registered":
+ case "statsreset":
+ $registration=$feed->getAttribute("unixtime");
+ $feed->read();
+ $feed->read();
+ break;
+
+ case "profile":
+ $username=$feed->getAttribute("username");
+ break;
+ }
+ }*/
+
+/*if (! $playcount)
+{
+ $MainText->value="Sorry, $username is not";
+ $Info->value="a valid Last.fm account";
+ $MainText->size=30;
+ $MainText->angle=2;
+ $Info->angle=1;
+ $Info->size=30;
+ $FinalHeight=50;
+ $Cache="";
+}
+else*/
+{
+/* $TrueFalse = $_SERVER['REQUEST_TIME'] - $registration;
+ $TrueFalse /= (60*60*24*30);
+ $TrueFalse = floor($playcount / $TrueFalse);*/
+ $MainText->size=180;
+
+ switch($type)
+ {
+ default:
+ $MainText->value = "Not available anymore";
+ $MainText->size = 180;
+ $Info->value = "Go check Updates";
+ $Info->size = 150;
+ $MainText->angle = 1;
+ $Info->angle = 1;
+ $FinalHeight=50;
+ break;
+ }
+}
+
+$size=imageftbbox($MainText->size, $MainText->angle, $MainText->font, $MainText->value);
+$MainText->initiate($size);
+$MainText->x=0;
+$MainText->y=$MainText->height;
+if ($Info->value != "")
+{
+ $size=imageftbbox($Info->size, $Info->angle, $Info->font, $Info->value);
+ $Info->initiate($size);
+ $Info->x=0;
+ $Info->y=$MainText->height + $Info->height;
+}
+
+$Image = new Text;
+$Image->width=max($MainText->width, $Info->width);
+$Image->height=$MainText->height;
+$Image->height+=$Info->height;
+
+$MainText->x = max(0, floor(($Image->width - $MainText->width) / 2));
+$MainText->y = 0;
+$Info->x = max(0, floor(($Image->width - $Info->width) / 2));
+$Info->y = $MainText->height + 1;
+
+$img=imagecreatetruecolor($Image->width, $Image->height);
+
+if ( isset($TrueFalse)
+ && $TrueFalse > 3000)
+ $MainText->color=imagecolorallocate($img, 0, 0, 0);
+else
+ $MainText->color=imagecolorallocate($img, 220, 50, 50);
+$Info->color=$MainText->color;
+
+imagealphablending($img, FALSE);
+$transparent=imagecolorallocatealpha($img, 255, 255, 255, 127);
+$area=imagefilledrectangle($img, 0, 0, $Image->width, $Image->height, $transparent);
+
+imagealphablending($img, TRUE);
+imagettftext($img, $MainText->size, $MainText->angle, $MainText->x, $MainText->y + $MainText->height - 1, $MainText->color, $MainText->font, $MainText->value);
+if ($Info->value != "")
+ imagettftext($img, $Info->size, $Info->angle, $Info->x, $Info->y + $Info->height - 1, $Info->color, $Info->font, $Info->value);
+
+$new=imagecreatetruecolor(150, $FinalHeight);
+imagealphablending($new, FALSE);
+$white=imagecolorallocatealpha($new, 255, 255, 255, 0);
+$area=imagefilledrectangle($new, 0, 0, 150, $FinalHeight, $white);
+imagealphablending($new, FALSE);
+
+$y=floor($MainText->height * $FinalHeight / $Image->height);
+
+imagecopyresampled($new,
+ $img,
+ 0,
+ 0,
+ $MainText->x,
+ $MainText->y,
+ 150,
+ $y,
+ $MainText->width,
+ $MainText->height);
+
+if ($Info->value != "")
+ imagecopyresampled($new,
+ $img,
+ 0,
+ $y + 1,
+ $Info->x,
+ $Info->y,
+ 150,
+ ceil($Info->height * $FinalHeight / $Image->height),
+ $Info->width,
+ $Info->height);
+ //imagecopyresampled($new, $img, 0, 0, 0, 0, 150, $FinalHeight, $Image->width, $Image->height);
+
+if ($Cache != "") imagepng($new, $Cache);
+imagepng($new);
+imagedestroy($img);
+imagedestroy($new);
+
+?>
diff --git a/Monthly.php b/Monthly.php
new file mode 120000
index 0000000..8d6834d
--- /dev/null
+++ b/Monthly.php
@@ -0,0 +1 @@
+Last.fm.php \ No newline at end of file
diff --git a/TotalTracks.php b/TotalTracks.php
new file mode 120000
index 0000000..8d6834d
--- /dev/null
+++ b/TotalTracks.php
@@ -0,0 +1 @@
+Last.fm.php \ No newline at end of file
diff --git a/TrueFalse.php b/TrueFalse.php
new file mode 120000
index 0000000..8d6834d
--- /dev/null
+++ b/TrueFalse.php
@@ -0,0 +1 @@
+Last.fm.php \ No newline at end of file