Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $login = 'example@mail.ru'; // логин
- $pass = 'pA$s'; // пароль
- $photo = '1234_56798';// id фотографии аватарки, вместо которой будет грузиться
- #####################################################
- $time = time()-0900; // коррекция времени
- $bd_month = 3; //день рождения
- $bd_day = 30; // месяц рождения
- $reg_day = 30; // день регистрации вконтакте
- $reg_month = 5; // месяц регистрации вконтакте
- $reg_year = 2008; // год регистрации вконтакте
- $weather_link = 'http://rp5.ua/informer/120x60x2.php?f=1&id=9421&lang=ru'; //ссылка на информер
- #####################################################
- $width = 200;
- $heigth = 500;
- $dir = dirname(__FILE__) . '/';
- $background_filename = $dir.'bkgrnd.png';
- $photo_filename = $dir.'photo.jpg';
- $font = $dir.'tahoma.ttf';
- $font_bold = $dir.'tahomabd.ttf';
- #####################################################
- function curl_exec_follow($ch, &$maxredirect = null) {
- $mr = $maxredirect === null ? 5 : intval($maxredirect);
- if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
- curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
- } else {
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- if ($mr > 0) {
- $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
- $rch = curl_copy_handle($ch);
- curl_setopt($rch, CURLOPT_HEADER, true);
- curl_setopt($rch, CURLOPT_NOBODY, true);
- curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
- curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
- do {
- curl_setopt($rch, CURLOPT_URL, $newurl);
- $header = curl_exec($rch);
- if (curl_errno($rch)) {
- $code = 0;
- } else {
- $code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
- if ($code == 301 || $code == 302) {
- preg_match('/Location:(.*?)\n/', $header, $matches);
- $newurl = trim(array_pop($matches));
- } else {
- $code = 0;
- }
- }
- } while ($code && --$mr);
- curl_close($rch);
- if (!$mr) {
- if ($maxredirect === null) {
- trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
- } else {
- $maxredirect = 0;
- }
- return false;
- }
- curl_setopt($ch, CURLOPT_URL, $newurl);
- }
- }
- return curl_exec($ch);
- }
- function curl($url, $post = null){
- $ch = curl_init($url);
- //curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//!!!!
- curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie');
- curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie');
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false );
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
- if($post)
- {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- }
- //$response =curl_exec_follow($ch);
- $response = curl_exec($ch);
- curl_close($ch);
- return $response;
- }
- function vk_auth($email, $pass) {
- global $login,$pass;
- $j=json_decode( curl('http://vk.com/feed2.php'), true );
- $t="by login/pass";
- if ($j['user']['id']==-1){
- $response = curl('http://login.vk.com/?act=login&email='.$login.'&pass='.$pass);
- //echo '>>>>>>'.$response.'<<<<<<<';
- $json=curl('http://vk.com/feed2.php');
- $j=json_decode( $json, true );
- } else {
- $t='by cookie';
- }
- if ($j['user']['id']==-1){
- return null;
- } else {
- return 'Logined as id'.$j['user']['id'].' '.$t;
- }
- /*
- preg_match('|Set-Cookie: remixsid=(.*); exp|', $response, $cm);
- return $cm[1];*/
- }
- function vk_get_feed ($cookies) {
- // global $json;
- $str=curl('http://vk.com/feed2.php');
- $result = json_decode( $str, true );//$json->decode($str);
- return $result;
- }
- function imagegettextsize($img,$size,$angle,$font_file,$text) {
- $arr = imagettftext($img,$size,$angle,-1000,-1000,0,$font_file,$text);
- return $arr[2]-$arr[0];
- }
- function print_text ($ava, $x, $y, $left, $size, $color, $text, $font_file, $angle) {
- if ($left) $x = 200 - $x - imagegettextsize($ava,$size,$angle,$font_file,$text);
- $color = imagecolorallocate($ava,$color['red'],$color['green'],$color['blue']);
- imagettftext($ava,$size,$angle,$x,$y,$color,$font_file,$text);
- }
- function todate ($d,$m,$y) {
- global $time;
- return round((mktime(0,0,0,$m,$d,$y)-$time)/(3600*24),0);
- }
- function vk_avatar ($cookies, $filename) {
- global $photo;
- $get_data = curl('http://vk.com/al_photos.php', array('act' => 'edit_photo', 'al' => 1, 'photo' => $photo));
- preg_match('/"upload_url":"(.*?)"/', $get_data, $upload_url);
- preg_match("/'{$photo}', '(.*?)'/", $get_data, $hash);
- $upload_url = str_replace('\/', '/', $upload_url[1]);
- echo "\r\n-----{parse info}-----\r\n";
- //echo iconv('cp1251','utf-8',$get_data);
- // echo "\r\n-----\r\n";
- echo '$hash='.$hash[1]."\r\n";
- echo '$photo='.$photo."\r\n";
- echo '$upload_url='.$upload_url."\r\n";
- $upload = curl($upload_url, array('photo' => '@'.$filename));
- $postdata = array(
- '_query' => $upload,
- 'act' => 'save_desc',
- 'aid' => '-7',
- 'al' => 1,
- 'conf' => '///',
- 'cover' => '',
- 'filter_num' => 0,
- 'hash' => $hash[1],
- 'photo' => $photo,
- 'text' => ''
- );
- $save_desc = curl('http://vk.com/al_photos.php', $postdata);
- echo "-------{result}-------\r\n";
- echo iconv('cp1251','utf-8',$save_desc);
- echo "\r\n--------{end}---------\r\n\r\n";
- echo 'OK';
- //unlink('./cookie');
- }
- header("Content-Type: text/plain");
- echo '/usr/bin/php '.$dir.'index.php > /dev/null'.chr(10)."\r\n";
- echo /*microtime(1)."\r\n" .*/ " Авторизация ВКонтакте...\r\n";
- $email = iconv('utf-8','cp1251',$email);
- $pass = iconv('utf-8','cp1251',$pass);
- $sid = vk_auth($email, $pass)
- or die('Error!');
- echo $sid."\r\n";
- $cookies = '';//'remixsid='.$sid;
- $vk_feed = vk_get_feed($cookies);
- echo /*microtime(1)."\r\n" .*/ " Создание аватара...\r\n";
- $ava = imagecreatetruecolor($width,$heigth);
- $bkgrnd = imagecreatefrompng($background_filename);
- $colorsub = array ('red'=>mt_rand(-50,50),'green'=>mt_rand(-50,50),'blue'=>mt_rand(-50,50),'alpha'=>0);
- for ($i=0; $i<=255; $i++) {
- $color = imagecolorsforindex($bkgrnd,$i);
- foreach ($color as $key => $value) {
- $color[$key] += $colorsub[$key];
- if ($color[$key]<0) $color[$key]=0;
- if ($color[$key]>255) $color[$key]=255;
- }
- imagecolorset($bkgrnd, $i, $color['red'], $color['green'], $color['blue']);
- }
- foreach ($colorsub as $key => $value) {
- $color_text[$key] = $value+10;
- if ($color_text[$key]<0) $color_text[$key]=0;
- if ($color_text[$key]>255) $color_text[$key]=255;
- $color_info[$key] = $value+30;
- if ($color_info[$key]<0) $color_info[$key]=0;
- if ($color_info[$key]>255) $color_info[$key]=255;
- }
- imagecopy($ava,$bkgrnd,0,0,0,0,$width,$heigth);
- $img = imagecreatefromjpeg($photo_filename);
- imagecopy($ava,$img,8,8,0,0,184,254);
- $img = imagecreatefrompng($weather_link);
- imagecopymerge($ava,$img,40,410,0,0,120,60,80);
- ## STATIC TEXT
- print_text($ava,11,285,0,8, $color_text, 'До дня рождения:',$font,0);
- print_text($ava,11,301,0,8, $color_text, 'До лета:',$font,0);
- print_text($ava,11,318,0,8, $color_text, 'Заявки в друзья:',$font,0);
- print_text($ava,11,335,0,8, $color_text, 'Новые сообщения:',$font,0);
- print_text($ava,11,352,0,8, $color_text, 'Дней ВКонтакте:',$font,0);
- print_text($ava,11,369,0,8, $color_text, 'Обновлено:',$font,0);
- ## DYNAMIC TEXT
- print_text($ava,12,285,1,8, $color_info, todate($bd_month, $bd_day, 2010). ' дн.',$font_bold,0);
- print_text($ava,12,301,1,8, $color_info, todate(1,6,2010) . ' дн.',$font_bold,0);
- print_text($ava,12,318,1,8, $color_info, $vk_feed['friends']['count'],$font_bold,0);
- print_text($ava,12,335,1,8, $color_info, $vk_feed['messages']['count'],$font_bold,0);
- print_text($ava,12,352,1,8, $color_info, -todate($reg_day,$reg_month,$reg_year),$font_bold,0);
- print_text($ava,12,369,1,8, $color_info, date('H:i', $time),$font_bold,0);
- imagejpeg($ava,$dir.'avatar.jpg',100);
- echo /*microtime(1)."\r\n" .*/ " Загрузка аватара...\r\n";
- vk_avatar($cookies, $dir . 'avatar.jpg');
- echo /*microtime(1)."\r\n" .*/ " Готово!\r\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement