<?

#$_GET['code'] = 'supergreen';



define('SCRIPT_PATH'dirname(__FILE__) . '/');



function 
getFBReadersCnt($sFeedUrl)
{     
# http://code.google.com/apis/feedburner/awareness_api.html#current_basic_feed_awareness_data     $s 'http://api.feedburner.com/awareness/1.0/GetFeedData?uri=' $sFeedUrl;
    
# В API защит никаких, пожалуй, не будет. Выдираем данные самым простым способом.
    
if (!($sResp file_get_contents($s)))
        return -
1;

    
# Цифра циркулирующих :) юзеров это то, что нам надо
    
preg_match('/circulation="(\d+)"/'$sResp$a);

    
# Если была ошибка, то вернется 0, иначе все будет ок.
    
return (int)@$a[1]; }


function 
getCodes()
{     
$aLines file(SCRIPT_PATH 'conf');

    foreach (
$aLines as $sLine)
    {
        
$a explode('#'trim($sLine));

        
$sCode trim($a[0]);

        
$result[$sCode] = array();

        unset(
$a[0]);

        foreach (
$a as $aInf)
        {             list(
$sKey$sValue) = explode('='$aInf);

            
$result[$sCode][trim($sKey)] = trim($sValue);         }     }

    return 
$result; }


$sUrl = @$_GET['url'];
if (!
$sUrl) die();


# Следующих пару строк можно удалить :)
if (!in_array($sUrl, array('http://feeds.feedburner.com/mannodesign''http://feeds.feedburner.com/ewgenij')))
    die();


$iCnt getFBReadersCnt($sUrl);
#$iCnt = 23;

$aCodes getCodes();

$sCode trim(urldecode(@$_GET['code']));

if (!isset(
$aCodes[$sCode])) die();

$sImage SCRIPT_PATH 'temp/' $sCode '-' $iCnt '.gif';


# Нужно кешировать по коду и урлу, а не по картинке. Разбирайтесь самостоятельно :)
if (file_exists($sImage))
{
    
readfile($sImage);
    die();
}

# header('Content-type: image/gif');
# header('Expires: ' . date('r', strtotime('tomorrow')));

$aConf $aCodes[$sCode];

$rImage imagecreatefromgif(SCRIPT_PATH 'images/' $aConf['image']);
$iW        imagesx($rImage);
$iH        imagesy($rImage);

list(
$sRed$sGreen$sBlue) = explode(','$aConf['color']);

# http://www.php.net/manual/ru/function.imagecopy.php#80830
$iTrans imagecolortransparent($rImage);
if (
$iTrans >= 0)
{
    
$hRGB    imagecolorsforindex($rImage$iTrans);
    
$rTmp    $rImage;
    
$rImage    imagecreatetruecolor($iW$iH);
    
$iColor    imagecolorallocate($rImage$hRGB['red'], $hRGB['green'], $hRGB['blue']);
    
imagefilledrectangle($rImage00$iW$iH$iColor);
    
imagecopy($rImage$rTmp0000$iW$iH);
}

$iColor imagecolorallocate($rImage, (int)$sRed, (int)$sGreen, (int)$sBlue);

imagettftext($rImage$aConf['size'], 0$aConf['x'], $aConf['y'], $iColorSCRIPT_PATH 'fonts/' $aConf['font'], $iCnt);

imagegif($rImage$sImage);

imagedestroy($rImage);

readfile($sImage);

?>