Advertisement
Guest User

Untitled

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