Advertisement
KiberInfinity

vk ava

May 1st, 2013
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.02 KB | None | 0 0
  1. <?php
  2.  
  3. $login = 'example@mail.ru'; // логин
  4. $pass  = 'pA$s'; // пароль
  5. $photo = '1234_56798';// id фотографии аватарки, вместо которой будет грузиться
  6.  
  7. #####################################################
  8. $time = time()-0900; // коррекция времени
  9. $bd_month = 3; //день рождения
  10. $bd_day = 30; // месяц рождения
  11. $reg_day = 30; // день регистрации вконтакте
  12. $reg_month = 5; // месяц регистрации вконтакте
  13. $reg_year = 2008; // год регистрации вконтакте
  14. $weather_link = 'http://rp5.ua/informer/120x60x2.php?f=1&id=9421&lang=ru';  //ссылка на информер
  15.  
  16. #####################################################
  17. $width = 200;
  18. $heigth = 500;
  19. $dir = dirname(__FILE__) . '/';
  20. $background_filename = $dir.'bkgrnd.png';
  21. $photo_filename = $dir.'photo.jpg';
  22. $font = $dir.'tahoma.ttf';
  23. $font_bold = $dir.'tahomabd.ttf';
  24. #####################################################
  25. function curl_exec_follow($ch, &$maxredirect = null) {
  26.     $mr = $maxredirect === null ? 5 : intval($maxredirect);
  27.     if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
  28.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
  29.         curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
  30.     } else {
  31.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  32.         if ($mr > 0) {
  33.             $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  34.  
  35.             $rch = curl_copy_handle($ch);
  36.             curl_setopt($rch, CURLOPT_HEADER, true);
  37.             curl_setopt($rch, CURLOPT_NOBODY, true);
  38.             curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
  39.             curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
  40.             do {
  41.                 curl_setopt($rch, CURLOPT_URL, $newurl);
  42.                 $header = curl_exec($rch);
  43.                 if (curl_errno($rch)) {
  44.                     $code = 0;
  45.                 } else {
  46.                     $code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
  47.                     if ($code == 301 || $code == 302) {
  48.                         preg_match('/Location:(.*?)\n/', $header, $matches);
  49.                         $newurl = trim(array_pop($matches));
  50.                     } else {
  51.                         $code = 0;
  52.                     }
  53.                 }
  54.             } while ($code && --$mr);
  55.             curl_close($rch);
  56.             if (!$mr) {
  57.                 if ($maxredirect === null) {
  58.                     trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
  59.                 } else {
  60.                     $maxredirect = 0;
  61.                 }
  62.                 return false;
  63.             }
  64.             curl_setopt($ch, CURLOPT_URL, $newurl);
  65.         }
  66.     }
  67.     return curl_exec($ch);
  68. }
  69. function curl($url, $post = null){
  70.     $ch = curl_init($url);
  71.    
  72.    //curl_setopt($ch, CURLOPT_HEADER, true);
  73.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  74.     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');
  75.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//!!!!
  76.    
  77.     curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie');
  78.     curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie');
  79.    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false );
  80.    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );  
  81.     if($post)
  82.     {
  83.         curl_setopt($ch, CURLOPT_POST, 1);
  84.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  85.     }
  86.     //$response =curl_exec_follow($ch);
  87.     $response = curl_exec($ch);
  88.     curl_close($ch);
  89.     return $response;
  90. }
  91.  
  92. function vk_auth($email, $pass) {
  93.     global $login,$pass;
  94.     $j=json_decode( curl('http://vk.com/feed2.php'), true );
  95.     $t="by login/pass";
  96.     if ($j['user']['id']==-1){
  97.       $response = curl('http://login.vk.com/?act=login&email='.$login.'&pass='.$pass);
  98.       //echo '>>>>>>'.$response.'<<<<<<<';
  99.       $json=curl('http://vk.com/feed2.php');
  100.       $j=json_decode( $json, true );
  101.     } else {
  102.       $t='by cookie';
  103.     }
  104.  
  105.     if ($j['user']['id']==-1){
  106.       return null;
  107.     } else {
  108.       return 'Logined as id'.$j['user']['id'].' '.$t;
  109.     }
  110.     /*
  111.     preg_match('|Set-Cookie: remixsid=(.*); exp|', $response, $cm);
  112.     return $cm[1];*/
  113. }
  114. function vk_get_feed ($cookies) {
  115.    // global $json;
  116.     $str=curl('http://vk.com/feed2.php');
  117.     $result = json_decode( $str, true );//$json->decode($str);
  118.     return $result;
  119. }
  120. function imagegettextsize($img,$size,$angle,$font_file,$text) {
  121.     $arr = imagettftext($img,$size,$angle,-1000,-1000,0,$font_file,$text);
  122.     return $arr[2]-$arr[0];
  123. }
  124. function print_text ($ava, $x, $y, $left, $size, $color, $text, $font_file, $angle) {
  125.     if ($left) $x = 200 - $x - imagegettextsize($ava,$size,$angle,$font_file,$text);
  126.     $color = imagecolorallocate($ava,$color['red'],$color['green'],$color['blue']);
  127.     imagettftext($ava,$size,$angle,$x,$y,$color,$font_file,$text);
  128. }
  129. function todate ($d,$m,$y) {
  130.     global $time;
  131.     return round((mktime(0,0,0,$m,$d,$y)-$time)/(3600*24),0);
  132. }
  133. function vk_avatar ($cookies, $filename) {    
  134.    global $photo;
  135.    $get_data = curl('http://vk.com/al_photos.php', array('act' => 'edit_photo', 'al' => 1, 'photo' => $photo));
  136.  
  137.    
  138.    preg_match('/"upload_url":"(.*?)"/', $get_data, $upload_url);
  139.    preg_match("/'{$photo}', '(.*?)'/", $get_data, $hash);
  140.    $upload_url = str_replace('\/', '/', $upload_url[1]);
  141.    
  142.    echo "\r\n-----{parse info}-----\r\n";
  143.    //echo iconv('cp1251','utf-8',$get_data);
  144.   // echo "\r\n-----\r\n";
  145.    echo '$hash='.$hash[1]."\r\n";
  146.    echo '$photo='.$photo."\r\n";
  147.    echo '$upload_url='.$upload_url."\r\n";
  148.    $upload = curl($upload_url, array('photo' => '@'.$filename));
  149.    
  150.  
  151.    
  152.    $postdata = array(
  153.       '_query'   => $upload,
  154.       'act'          => 'save_desc',
  155.       'aid'          => '-7',
  156.       'al'       => 1,
  157.       'conf'         => '///',
  158.       'cover'    => '',
  159.       'filter_num' => 0,
  160.       'hash'         => $hash[1],
  161.       'photo'        => $photo,
  162.       'text'         => ''
  163.    );
  164.    $save_desc = curl('http://vk.com/al_photos.php', $postdata);
  165.    echo "-------{result}-------\r\n";
  166.    echo iconv('cp1251','utf-8',$save_desc);
  167.    echo "\r\n--------{end}---------\r\n\r\n";
  168.    echo 'OK';
  169.    //unlink('./cookie');
  170. }
  171. header("Content-Type: text/plain");
  172. echo '/usr/bin/php '.$dir.'index.php > /dev/null'.chr(10)."\r\n";
  173. echo /*microtime(1)."\r\n" .*/ " Авторизация ВКонтакте...\r\n";
  174. $email = iconv('utf-8','cp1251',$email);
  175. $pass = iconv('utf-8','cp1251',$pass);
  176. $sid = vk_auth($email, $pass)
  177.     or die('Error!');
  178. echo $sid."\r\n";
  179. $cookies = '';//'remixsid='.$sid;
  180. $vk_feed = vk_get_feed($cookies);
  181.  
  182. echo /*microtime(1)."\r\n" .*/ " Создание аватара...\r\n";
  183. $ava = imagecreatetruecolor($width,$heigth);
  184. $bkgrnd = imagecreatefrompng($background_filename);
  185. $colorsub = array ('red'=>mt_rand(-50,50),'green'=>mt_rand(-50,50),'blue'=>mt_rand(-50,50),'alpha'=>0);
  186. for ($i=0; $i<=255; $i++) {
  187.     $color = imagecolorsforindex($bkgrnd,$i);
  188.     foreach ($color as $key => $value) {
  189.         $color[$key] += $colorsub[$key];
  190.         if ($color[$key]<0) $color[$key]=0;
  191.         if ($color[$key]>255) $color[$key]=255;
  192.     }
  193.     imagecolorset($bkgrnd, $i, $color['red'], $color['green'], $color['blue']);
  194. }
  195.  
  196. foreach ($colorsub as $key => $value) {
  197.     $color_text[$key] = $value+10;
  198.     if ($color_text[$key]<0) $color_text[$key]=0;
  199.     if ($color_text[$key]>255) $color_text[$key]=255;
  200.     $color_info[$key] = $value+30;
  201.     if ($color_info[$key]<0) $color_info[$key]=0;
  202.     if ($color_info[$key]>255) $color_info[$key]=255;
  203. }
  204.  
  205. imagecopy($ava,$bkgrnd,0,0,0,0,$width,$heigth);
  206. $img = imagecreatefromjpeg($photo_filename);
  207. imagecopy($ava,$img,8,8,0,0,184,254);
  208. $img = imagecreatefrompng($weather_link);
  209. imagecopymerge($ava,$img,40,410,0,0,120,60,80);
  210. ## STATIC TEXT
  211. print_text($ava,11,285,0,8, $color_text, 'До дня рождения:',$font,0);
  212. print_text($ava,11,301,0,8, $color_text, 'До лета:',$font,0);
  213. print_text($ava,11,318,0,8, $color_text, 'Заявки в друзья:',$font,0);
  214. print_text($ava,11,335,0,8, $color_text, 'Новые сообщения:',$font,0);
  215. print_text($ava,11,352,0,8, $color_text, 'Дней ВКонтакте:',$font,0);
  216. print_text($ava,11,369,0,8, $color_text, 'Обновлено:',$font,0);
  217. ## DYNAMIC TEXT
  218. print_text($ava,12,285,1,8, $color_info, todate($bd_month, $bd_day, 2010). ' дн.',$font_bold,0);
  219. print_text($ava,12,301,1,8, $color_info, todate(1,6,2010) . ' дн.',$font_bold,0);
  220. print_text($ava,12,318,1,8, $color_info, $vk_feed['friends']['count'],$font_bold,0);
  221. print_text($ava,12,335,1,8, $color_info, $vk_feed['messages']['count'],$font_bold,0);
  222. print_text($ava,12,352,1,8, $color_info, -todate($reg_day,$reg_month,$reg_year),$font_bold,0);
  223. print_text($ava,12,369,1,8, $color_info, date('H:i', $time),$font_bold,0);
  224. imagejpeg($ava,$dir.'avatar.jpg',100);
  225. echo /*microtime(1)."\r\n" .*/ " Загрузка аватара...\r\n";
  226. vk_avatar($cookies, $dir . 'avatar.jpg');
  227. echo /*microtime(1)."\r\n" .*/ " Готово!\r\n";
  228. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement