Advertisement
go8765

Untitled

Nov 13th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.32 KB | None | 0 0
  1. <?php
  2. ######################
  3. #       bafoed       #
  4. ######################
  5. error_reporting (E_ALL ^ E_NOTICE);
  6. set_time_limit(0);
  7. @ini_set('max_execution_time', '0');
  8. $myid        = 'ххх'; // свой айди
  9. $id          = ''; // айди кого бекапим (только если не всех друзей)
  10. $all_friends = true; // дампить всех друзей
  11. $token       = 'ууу'; // Получить тут: http://oauth.vk.com/authorize?client_id=2626107&scope=16383&redirect_uri=http://api.vk.com/blank.html&response_type=token
  12. $zip         = true; // зиповать (замедляет скорость работы)
  13.  
  14.  
  15. /* ############### */
  16. $messages = array();
  17. function API($method, $sett)
  18. {
  19.     global $token;
  20.     $ch = curl_init('https://api.vk.com/method/' . $method . '.json?' . http_build_query($sett) . '&access_token=' . $token);
  21.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  22.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  23.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  24.     $response = curl_exec($ch);
  25.     curl_close($ch);
  26.     return json_decode($response, true);
  27. }
  28.  
  29.  
  30. function create_zip($files = array(), $destination = '', $overwrite = false)
  31. {
  32.     // ZIP архивация от http://davidwalsh.name/create-zip-php
  33.     if (file_exists($destination) && !$overwrite) {
  34.         return false;
  35.     }
  36.     $valid_files = array();
  37.     if (is_array($files)) {
  38.         foreach ($files as $file) {
  39.             if (file_exists($file)) {
  40.                 $valid_files[] = $file;
  41.             }
  42.         }
  43.     }
  44.     if (count($valid_files)) {
  45.         $zip = new ZipArchive();
  46.         if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
  47.             return false;
  48.         }
  49.         foreach ($valid_files as $file) {
  50.             $zip->addFile($file, $file);
  51.         }
  52.         $zip->close();
  53.        
  54.         return file_exists($destination);
  55.     } else {
  56.         return false;
  57.     }
  58. }
  59.  
  60.  
  61. function dump($id)
  62. {
  63.     global $myid, $zip;
  64.     $info      = API('getProfiles', array(
  65.         'uid' => $id,
  66.         'fields' => 'photo'
  67.     ));
  68.     if(empty($info['response'])) {
  69.         die('<pre>Error</pre>');
  70.     }
  71.    
  72.     $s_name    = $info['response'][0]['first_name']; //
  73.     $s_surname = $info['response'][0]['last_name']; // -- Граббинг инфы о собеседнике
  74.     $s_photo   = $info['response'][0]['photo']; // //
  75.     $s_tabname = $s_name . " " . $s_surname;
  76.    
  77.     $info    = API('getProfiles', array(
  78.         'uid' => $myid,
  79.         'fields' => 'photo'
  80.     ));
  81.     $name    = $info['response'][0]['first_name']; //
  82.     $surname = $info['response'][0]['last_name']; // -- Граббинг инфы о себе
  83.     $photo   = $info['response'][0]['photo']; // //
  84.    
  85.    
  86.     # Let`s get is started!
  87.    $page  = API('messages.getHistory', array(
  88.         'uid' => $id,
  89.         'count' => '1'
  90.     ));
  91.     $count = (int) $page['response'][0]; // Количество сообщений с данным человеком
  92.    
  93.     $first      = $count % 100; // API позволяет получать не больше 100 сообщений за раз, сначала получим те, которые не получить при count = 100
  94.     $iterations = ($count - $first) / 100; // Сколько раз получать по 100 сообщений
  95.    
  96.     $page = API('messages.getHistory', array(
  97.         'uid' => $id,
  98.         'count' => $first,
  99.         'offset' => (string) ($iterations * 100)
  100.     ));
  101.     unset($page['response'][0]); // Количество сообшений мы уже знаем
  102.     $messages = array_reverse(array_values($page['response'])); // ВК отдает сообщения сверху вниз
  103.    
  104.    
  105.     for ($i = $iterations; $i >= 0; $i--) {
  106.         $page = API('messages.getHistory', array(
  107.             'uid' => $id,
  108.             'count' => 100,
  109.             'offset' => (string) ($i * 100)
  110.         ));
  111.         unset($page['response'][0]);
  112.         $messages = array_merge($messages, array_reverse(array_values($page['response'])));
  113.     }
  114.    
  115.     $page = str_replace('%username%', $s_tabname, file_get_contents(dirname(__FILE__) . '/head.tpl'));
  116.     $lines = array(); // Линии файла упрощенного стиля
  117.    
  118.     foreach ($messages as $msg) { // Обрабатываем каждое сообщение
  119.         if ($msg['from_id'] == $myid) {
  120.             $tname  = "$name $surname";
  121.             $tphoto = $photo;
  122.             $tid    = $myid;
  123.         } else {
  124.             $tname  = "$s_name $s_surname";
  125.             $tphoto = $s_photo;
  126.             $tid    = $id;
  127.         }
  128.        
  129.        
  130.         $body = $msg['body'];
  131.         $date = (string) ((int) $msg['date'] + 3600);
  132.         $time = date("d.m.Y H:i", $date);
  133.        
  134.         $lines[] = "$tname ($time): $body";
  135.         $page .= <<<EOF
  136.  <tr class="im_in">
  137.       <td class="im_log_act">
  138.         <div class="im_log_check_wrap"><div class="im_log_check"></div></div>
  139.       </td>
  140.       <td class="im_log_author"><div class="im_log_author_chat_thumb"><a href="http://vk.com/id$tid"><img src="$tphoto" class="im_log_author_chat_thumb"></a></div></td>
  141.       <td class="im_log_body"><div class="wrapped"><div class="im_log_author_chat_name"><a href="http://vk.com/id$tid" class="mem_link">$tname</a></div>$body</div></td>
  142.       <td class="im_log_date"><a class="im_date_link">$time</a><input type="hidden" value="$date"></td>
  143.       <td class="im_log_rspacer"></td>
  144.     </tr>
  145. EOF;
  146.     }
  147.     $page .= file_get_contents(dirname(__FILE__) . '/foot.tpl');
  148.    
  149.    
  150.     file_put_contents($id . '.htm', iconv('utf-8', 'windows-1251//IGNORE', $page));
  151.     file_put_contents($id . '.txt', iconv('utf-8', 'windows-1251//IGNORE', implode("\r\n", $lines)));
  152.     if ($zip) {
  153.         $add = array();
  154.         $add = array_merge($add, glob("dialog_files/*"));
  155.         $add = array_merge($add, array(
  156.             $id . '.htm',
  157.             $id . '.txt'
  158.         ));
  159.         create_zip($add, 'zip/dump-' . $id . '.zip');
  160.         unlink($id . '.txt');
  161.         unlink($id . '.htm');
  162.     }
  163. }
  164.  
  165. if ($all_friends) {
  166.     $friends = API('friends.get', array());
  167.     $friends = $friends['response'];
  168.       foreach ($friends as $id)
  169.      dump($id);
  170.    
  171. } else {
  172.     dump($id);
  173. }
  174.  
  175. echo '<pre>Completed.</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement