From 6c749da19b8782991524c8d994d258633e9303dc Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Wed, 27 May 2009 16:10:33 +0200 Subject: [Badges] advert to new BigLine stuff --- Badges.php | 386 +-------------------------------------------------------- Config.php | 66 ---------- DISCLAIMER.php | 8 +- 3 files changed, 5 insertions(+), 455 deletions(-) mode change 100644 => 120000 Badges.php delete mode 100644 Config.php diff --git a/Badges.php b/Badges.php deleted file mode 100644 index 4e13816..0000000 --- a/Badges.php +++ /dev/null @@ -1,385 +0,0 @@ - - - Thanks to Pavel ZbytovskĂ˝ - www.zby.cz - for saving me time with the MySQL stuff ! - - -CREATE TABLE `users` ( - `username` varchar(100) NOT NULL, - `statsstart` bigint(11) NOT NULL, - `playcount` int(10) unsigned NOT NULL, - `lastupdate` bigint(11) unsigned NOT NULL, - PRIMARY KEY (`username`) -) ; - -CREATE TABLE `badges` ( - `username` varchar(100) NOT NULL, - `type` varchar(100) NOT NULL, - `style` varchar(100) NOT NULL, - `color` varchar(100) NOT NULL, - `lastupdate` bigint(11) default NULL, - `hits` bigint(20) unsigned NOT NULL, - `lasthit` bigint(11) unsigned default NULL, - `png` longblob, - PRIMARY KEY (`username`,`type`) -); - - * - */ - -/*get the parameters*/ -$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"); - -mysql_connect(MYSQL_HOST, MYSQL_USER); -mysql_select_db(MYSQL_DB); - -/*make cache data (array $data)*/ -$res = mysql_query("SELECT * FROM users WHERE username='" . gpc_addslashes(strtolower($username)) . "'"); -$data = mysql_fetch_assoc($res); - -if(($username AND !mysql_num_rows($res)) -OR ($data["lastupdate"] AND $data["lastupdate"]+CACHE < time())) - make_db_cache($username); - -/*output image cache*/ -$Cache=CACHE_FOLDER."/Pictures/".strtolower(rawurlencode($username))."_$type-$style-$color.png"; - -clearstatcache(); - -//if (is_file($Cache) AND (filemtime($Cache) >= $data['lastupdate'])){ - //header("Location: ".$Cache); //its faster, but you should set CACHE_FOLDER = "." -//} - -/*----------------------------------------------------------- - Ok, now we are ready to create the image with GD. -*/ - -$playcount = $data['playcount']; -$statsstart = $data['statsstart']; - -$Lines = array(); -$Lines[] = new Text; - -if (! $playcount) -{ - $Lines[0]->value="Sorry, $username is not"; - $Lines[0]->angle=rand(-1,2); - $Lines[] = new Text; - $Lines[1]->value="a valid Last.fm account"; - $Lines[1]->angle=rand(-2,1); - define(HEIGHT, 50); - $Cache=""; -} -else -{ - $res = mysql_query("SELECT * FROM badges WHERE username='" . gpc_addslashes(strtolower($username)) . "' AND type='$type' AND style='$style' AND color='$color';"); - $badge = mysql_fetch_assoc($res); - - if ( !is_file($Cache) - OR (filemtime($Cache) < $data['lastupdate']) - OR !filesize($Cache) - OR $username == "gugusse") - { - - $duration = $_SERVER['REQUEST_TIME'] - $statsstart; - $months = $duration / (60*60*24*30); - $weeks = $duration / (60*60*24*7); - $days = $duration / (60*60*24); - - $TPM = floor($playcount / $months); // TRACKS PER MONTH - $TPW = floor($playcount / $weeks); // TRACKS PER WEEK - $TPD = floor($playcount / $days); // TRACKS PER DAY - define(ALBUM_TRACKS, 13); - $APD = floor($TPD / ALBUM_TRACKS); // ALBUMS PER DAY - $APM = floor($TPM / ALBUM_TRACKS); // ALBUMS PER MONTH - $APW = floor($TPW / ALBUM_TRACKS); // ALBUMS PER WEEK - - // %N number - // %T track/album - // %D day/week/month - $FORMAT="%N %T per %D"; - // % - - define(ANGLE,rand(2,13)); - switch($type) - { - case "PerDay": - $Lines[0]->value = "$TPD track" . ($TPD==1 ? "" : "s") . " per Day"; - $Lines[0]->angle = ANGLE; - break; - case "AlbumsPerDay": - $Lines[0]->value = "" . floor($TPD / 13) . " album" . (floor($TPD/13)==1 ? "" : "s") . " per Day"; - $Lines[0]->angle = ANGLE; - break; - case "PerWeek": - $Lines[0]->value = "$TPW track" . ($TPW==1 ? "" : "s") . " per Week"; - $Lines[0]->angle = ANGLE; - break; - case "PerMonth": - $Lines[0]->value = "$TPM track" . ($TPM==1 ? "" : "s") . " per Month"; - $Lines[0]->angle = ANGLE; - break; - case "PerDay2": - $Lines[0]->value = "$TPD"; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = "track" . ($TPD==1 ? "" : "s") . " per Day"; - $Lines[1]->angle = ANGLE; - break; - case "PerWeek2": - $Lines[0]->value = "$TPW"; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = "track" . ($TPW==1 ? "" : "s") . " per Week"; - $Lines[1]->angle = ANGLE; - break; - case "PerMonth2": - $Lines[0]->value = "$TPM"; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = "track" . ($TPM==1 ? "" : "s") . " per Month"; - $Lines[1]->angle = ANGLE; - break; - case "Trueness": - $Lines[0]->value = "is "; - $Lines[0]->value .= ($TPM > TRUENESS ? "an" : "a"); - $Lines[0]->angle = ANGLE; - define(HEIGHT, 50); - $Lines[] = new Text; - $Lines[1]->value = ($TPM > TRUENESS ? "untrue" : "true"); - $Lines[1]->value .= " listener"; - $Lines[1]->angle = ANGLE; - - 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[0]->value = "$username is "; - $Lines[0]->value .= ($TPM > TRUENESS ? "an" : "a" ) ; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = ($TPM > TRUENESS ? "Untrue" : "True"); - $Lines[1]->angle = ANGLE; - $Lines[] = new Text; - $Lines[2]->value = "listener"; - $Lines[2]->angle = ANGLE; - break; - case "Since": - $Lines[0]->value = strftime("since %B %Y", $statsstart); - $Lines[0]->angle = ANGLE; - break; - case "Since2": - $Lines[0]->value = "listening since"; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = strftime("%B", $statsstart); - $Lines[1]->angle = ANGLE; - $Lines[] = new Text; - $Lines[2]->value = strftime("%Y", $statsstart); - $Lines[2]->angle = ANGLE; - break; - case "Total": - $Lines[0]->value = "$playcount track" . ($playcount==1 ? "" : "s") . " played"; - $Lines[0]->angle = ANGLE; - define(HEIGHT, 40); - break; - case "Total2": - $Lines[0]->value = "$playcount"; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = "track" . ($playcount==1 ? "" : "s") . " played"; - $Lines[1]->angle = ANGLE; - break; - default: - $Lines[0]->value = "Sorry !"; - $Lines[0]->angle = ANGLE; - $Lines[] = new Text; - $Lines[1]->value = "Not available"; - $Lines[1]->angle = ANGLE; - 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, $Cache); - imagedestroy($img); - - $QUERY=sprintf("REPLACE INTO badges (username, type, style, color, lastupdate, png) VALUES ('%s','%s','%s','%s', %s, '%s');", - $username, - $type, - $style, - $color, - time(), - $Cache ); - //echo $QUERY; - mysql_query($QUERY); - } - - if (is_file($Cache)) - { - touch_badge($username, $type, $style, $color); - header("Content-Type: image/png"); - //echo $Cache; - echo file_get_contents($Cache); - } -} - - - -function make_db_cache($username){ - global $data; - $profile_xml = file_get_contents("http://ws.audioscrobbler.com/1.0/user/".rawurlencode($username)."/profile.xml"); - - $feed=new XMLReader(); - if($feed->xml($profile_xml)){ - while ($feed->read()) - { - switch ($feed->name) - { - case "playcount": - $feed->read(); - $data['playcount']=intval($feed->value); - $feed->read(); - break; - - case "registered": - case "statsreset": - $data['statsstart']=$feed->getAttribute("unixtime"); - $feed->read(); - $feed->read(); - break; - - case "profile": - $data['username']=$feed->getAttribute("username"); - break; - } - } - - if ($data['playcount'] != 0) - { - $QUERY=(sprintf("REPLACE INTO users (statsstart,playcount,lastupdate,username) VALUES ('%s',%s,'%s','%s');", - time(), $data['playcount'], gpc_addslashes($data['statsstart']), gpc_addslashes(strtolower($username)))); - mysql_query($QUERY); - } - } -} - -function touch_badge($username, $type, $style, $color) -{ - $res = mysql_query("SELECT hits FROM badges WHERE username='" . gpc_addslashes(strtolower($username)) . "' AND type='$type' AND style='$style' AND color='$color';"); - $data = mysql_fetch_assoc($res); - - if(mysql_num_rows($res)) - $hits = $data["hits"]; - $hits++; - - $QUERY=sprintf("UPDATE badges SET hits=%s, lasthit='%s' WHERE username='%s' AND type='$type' AND style='$style' AND color='$color';", - $hits, time(), gpc_addslashes(strtolower($username))); - //echo $QUERY; - mysql_query($QUERY); -} - -function gpc_addslashes($str){ - return (get_magic_quotes_gpc() ? $str : addslashes($str)); -} - -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; - } -} - - -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; - } -} - diff --git a/Badges.php b/Badges.php new file mode 120000 index 0000000..c7187c3 --- /dev/null +++ b/Badges.php @@ -0,0 +1 @@ +DISCLAIMER.php \ No newline at end of file diff --git a/Config.php b/Config.php deleted file mode 100644 index 1cdef20..0000000 --- a/Config.php +++ /dev/null @@ -1,66 +0,0 @@ - "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", - "AlbumsPerDay" => "Daily albums_ #1", - "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" => "What's the heck is this ?"); - -// 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/DISCLAIMER.php b/DISCLAIMER.php index 91dd517..e1c2b19 100644 --- a/DISCLAIMER.php +++ b/DISCLAIMER.php @@ -47,14 +47,14 @@ class Text { $Lines = array(); $Lines[] = new Text; -$Lines[0]->value = "Sorry"; +$Lines[0]->value = "New stuff available !"; $Lines[0]->angle = 2; $Lines[] = new Text; -$Lines[1]->value = "due to too heavy load"; +$Lines[1]->value = "Go get the latest badge"; $Lines[] = new Text; -$Lines[2]->value = "badges will be suspended"; +$Lines[2]->value = "into my website"; $Lines[] = new Text; -$Lines[3]->value = "for some time..."; +$Lines[3]->value = "from NOW !"; foreach ($Lines as $Line) $Line->font = "import/Georgia"; -- cgit v1.2.3