[VK] До нового года осталось…

Представляю новый счетчик, теперь графический.

Для запуска через PHP-Launcher скопируйте файлы из архива в папку C:\PHP-Launcher\php\. Только после этого скрипт будет нормально работать

UPD: скрипт был обновлен 18.12.11 в 14:00. Убраны различные косяки
UPD: был добавлен новый желтый фон (в архиве по ссылке выше)

Код:
<?php
 
$mail = "qweqwe@gmail.com"; //e-mail или логин от контакта
$pass = "zxczxc"; //пароль от контакта
$text = "С новым годом!"; //сообщение при наступлении события
$textx = "Обновление каждую минуту ^_^"; //текст рядом с счетчиком
$sleep = "60"; //интервал между обновлениями
$dir = "C:\PHP-Launcher\php\\"; //папка с файлами из count.zip
 
$key="1233456789"; //ключ antigate.com
 
$res=get_headers('http://login.vk.com/?act=login&email='.urlencode($mail).'&pass='.urlencode($pass));
preg_match("/Set-Cookie: (.*?);/",$res[26],$cookie);
 
$res=curl("http://vk.com/feed.php",$cookie[1]);
preg_match("/id=([0-9]+),/",$res,$mid);
 
$res=curl("http://vk.com/wall$mid[1]",$cookie[1]);
preg_match("/post_hash\":\"(.*?)\"/",$res,$post_hash);
 
$text=iconv('cp1251','utf-8',$text);
$textx=iconv('cp1251','utf-8',$textx);
 
while(1) {
   $secondsDiff = mktime('0','0','0','1','1','2012') - time();
 
   if(substr_count($secondsDiff,"-")) {
    	$res=curl("http://vk.com/al_wall.php",$cookie[1],"act=post&al=1&hash=$post_hash[1]&message=$text&to_id=$mid[1]&type=full_all");
	exit;
   } else {
	if($deletePost[1]) {
	    $res=curl("http://vk.com/al_wall.php",$cookie[1],"act=delete&al=1&from=wall&hash=$deletePost[1]&post=$mid[1]_$post_id[1]&root=0");
	}
 
    	$remainingDay=floor($secondsDiff/60/60/24);
    	$remainingHour=floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
    	$remainingMinutes=floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
 
	if(strlen($remainingDay) < 2) {
	    $remainingDay="0$remainingDay";
	}
	if(strlen($remainingHour) < 2) {
	    $remainingHour="0$remainingHour";
	}
	if(strlen($remainingMinutes) < 2) {
	    $remainingMinutes="0$remainingMinutes";
	}
 
	$image = imagecreatetruecolor('300','100');
	$bkgrnd = imagecreatefrompng($dir.'bkgrnd.png');
 
	imagecopy($image,$bkgrnd,0,0,0,0,'300','100');
 
	imagettftext($image, 50, 0, 13, 60, imagecolorallocate($image, 255, 255, 255), $dir.'tahoma.ttf',$remainingDay);
	imagettftext($image, 50, 0, 113, 60, imagecolorallocate($image, 255, 255, 255), $dir.'tahoma.ttf',$remainingHour); 
	imagettftext($image, 50, 0, 213, 60, imagecolorallocate($image, 255, 255, 255), $dir.'tahoma.ttf',$remainingMinutes); 
 
	imagejpeg($image,$dir.'photo.jpg',100);
 
	$res=curl("http://vk.com/photos.php",$cookie[1],"act=a_choose_photo_box&al=1&mail_add=&scrollbar_width=16&to_id=$mid[1]");
	preg_match("/\"hash\":\"(.*?)\",\"rhash\":\"(.*?)\"/",$res,$hash);
	preg_match("/server: ([0-9]+),/",$res,$server);
 
	$res=curl("http://cs$server[1].vk.com/upload.php?act=do_add&aid=-14&gid=0&mid=$mid[1]&hash=$hash[1]&rhash=$hash[2]&vk=1&from_host=vk.com&ajx=1",$cookie[1],array('photo'=>'@'.$dir.'photo.jpg'));
 
	$res=curl("http://vk.com/al_photos.php",$cookie[1],"act=choose_uploaded&al=1&$res");
 
	preg_match("/<!>0<!>$mid[1]_([0-9]+)<!><!json>/",$res,$photo_id);
 
	$res=curl("http://vk.com/al_wall.php",$cookie[1],"act=post&al=1&attach1=$mid[1]_$photo_id[1]&attach1_type=photo&hash=$post_hash[1]&message=$textx&to_id=$mid[1]&type=full_all");
 
	preg_match('#([0-9]+)<!><!>([0-9]+)<!>([0-9]+)<!>([0-9]+)<!>#', $res, $m); 
 
	if($m[4]=="2") {
	    print("captcha!\n");
	    preg_match("/<!>$m[3]<!>2<!>([0-9]+)<!>0/",$res,$csid);
 
	    file_put_contents($dir.'captcha.jpg',file_get_contents('http://vk.com/captcha.php?sid='.$csid[1]));
 
	    while(1) {
    $res=curl("http://antigate.com/in.php",'',array('method'=>'post','is_russian'=>'1','key'=>$key,'file'=>'@'.$dir.'captcha.jpg'));
 
	    	if($res=="ERROR_KEY_DOES_NOT_EXIST" or $res=="ERROR_WRONG_USER_KEY") {
        die("antigate key error\n");
    }
 
	    	if($res!=="ERROR_NO_SLOT_AVAILABLE") {
	    	    $ckey=str_replace("OK|","",$res);
        sleep('2');
 
        while(1) {
    	$res=curl("http://antigate.com/res.php?key=$key&action=get&id=$ckey",'');
 
    	if($res=="ERROR_NO_SUCH_CAPCHA_ID") {
    	    $delid="1";
    	    break;
    	}
 
        	if(substr_count($res,"OK")) {
    	    $canswer=str_replace("OK|","",$res);
    	    break;
    	} else {
    	    sleep('3');
    	}
        }
    } else {
        continue;
    }
 
    if($delid=="1") {
        $delid="0";
        continue;
    } else {
        $res=curl("http://vk.com/al_wall.php",$cookie[1],"act=post&al=1&captcha_sid=$csid[1]&captcha_key=$canswer&attach1=$mid[1]_$photo_id[1]&attach1_type=photo&hash=$post_hash[1]&message=$textx&to_id=$mid[1]&type=full_all");
 
        preg_match('#([0-9]+)<!><!>([0-9]+)<!>([0-9]+)<!>([0-9]+)<!>#', $res, $m); 
 
        if($m[4]=="2") {
    	curl("http://antigate.com/res.php?key=$key&action=reportbad&id=$ckey",'');
	        preg_match("/<!>$m[3]<!>2<!>([0-9]+)<!>0/",$res,$csid);
 
	        file_put_contents($dir.'captcha.jpg',file_get_contents('http://vk.com/captcha.php?sid='.$csid[1]));
    	continue;
        }
        break;
    }
	    }
	}
 
	print("send\n");
 
	preg_match("/<!>$m[2]<!>$m[3]<!>$m[4]<!><div id=\"post$mid[1]_([0-9]+)\"/",$res,$post_id);
	preg_match("/deletePost\(\'$mid[1]_$post_id[1]\', '(.*?)\'/",$res,$deletePost);
   }
 
   sleep($sleep);
}
 
function curl($link, $cookie, $post=null) {
 
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
 
if($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
 
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
 
?>