class VKLIKES { private $url = 'https://api.vk.com/method/'; // URL API private $owner_id; //ID private $post_id; //ID private $count = 1000; // "" "" private $users = array(); // private $countReposts; // private $findPost; //ID private $find; // / public function __construct($owner_id = '', $post_id = '') { $this->owner_id = $owner_id; $this->post_id = $post_id; } // private function printProgress($text, $start = true, $error = false) { if ($error) $color = 'red'; else if ($start) $color = '#444'; else $color = 'green'; echo '<li style="color: '.$color.';">'.$text.'</li>'; ob_flush(); flush(); } /* , * $onwer_id - ID * $post_id - ID- * $fitler - "likes" "copies" * $offset - . 1000 * $onlyCount - * $start - */ private function getUsers($owner_id, $post_id, $filter, $offset = 0, $onlyCount = false, $start = true) { // URL $url = $this->url.'likes.getList?type=post&friends_only=0&offset='.$offset.'&count='.$this->count.'&owner_id='.$owner_id.'&item_id='.$post_id.'&filter='.$filter; // JSON- $json = file_get_contents($url); // JSON $data = json_decode($json, true); // , if (!isset($data['response'])) return false; $response = $data['response']; $count = $response['count']; // //, if ($onlyCount) { $this->countReposts = $count; return true; } // , . offset. $users = $response['users']; if (count($users) == 0) return false; if ($start) { $this->users = $users; } else { $this->users = array_merge($this->users, $users); } $offset += $this->count; $this->getUsers($owner_id, $post_id, $filter, $offset, $onlyCount, false); } // . - ID vk.com private function remakeUsersArray($usersWithInfo) { $new = array(); foreach ($usersWithInfo as $value) { $new[$value['uid']] = $value; } return $new; } /* * $vkIDs - ID */ function getUsersInfo($vkIDs) { //$count = 1000; // , ID (ID , ) foreach ($vkIDs as $key => $val) { if ((int)$val < 0) unset($vkIDs[$key]); } $uids = implode(',', $vkIDs); $fields = 'uid,first_name,last_name,nickname,screen_name,sex,city,country,timezone,photo,photo_medium,photo_big,has_mobile,rate,online,counters'; $url = $this->url.'users.get?&uids='.$uids.'&fields='.$fields.'&name_case=nom'; $json = file_get_contents($url); $data = json_decode($json, true); if (isset($data['response'])) { $response = $data['response']; return $response; } return 0; } // private function getUsersPosts($owner_id, $offset = 0) { $maxNews = 600; // $count = 100; //100 - , // $maxNews if ($offset > $maxNews - $count) { $this->printProgress('<b> '.$maxNews.' ...</b>', false, true); $this->find = false; return false; } // URL $url = $this->url.'wall.get?'; $url .= 'owner_id='.$owner_id.'&'; $url .= 'offset='.$offset.'&'; $url .= 'count='.$count.'&'; $url .= 'filter=owner'; $json = file_get_contents($url); // JSON- $data = json_decode($json, true); // "" if (!isset($data['response'])) { $this->printProgress('<b> </b>', false, true); $this->find = false; return false; } $response = $data['response']; $this->printProgress(' '.($count + $offset).' ..'); // $count foreach ($response as $news) { if (!is_array($news)) continue; /* copy_owner_id - ID * copy_owner_id - ID */ if (isset($news['copy_owner_id'], $news['copy_post_id']) and $news['copy_owner_id'] == $this->owner_id and $news['copy_post_id'] == $this->post_id) { $this->users[$news['from_id']]['repost_id'] = $news['id']; $this->printProgress('<b> #'.$news['id'].'</b>', false); $this->findPost = $news['id']; $this->find = true; return true; } } $offset += $count; // $this->getUsersPosts($owner_id, $offset); // } // function findReposts() { echo '<ul>'; $this->printProgress(' ID , ...'); $this->getUsers($this->owner_id, $this->post_id, 'copies'); $this->printProgress(' ID ', false); $copies = $this->users; $this->printProgress(' ID , ...'); $this->getUsers($this->owner_id, $this->post_id, 'likes'); $this->printProgress(' ID ', false); foreach ($this->users as $id) { if (in_array($id, $copies)) continue; $copies[] = $id; } $this->users = $copies; $this->printProgress('<b> ID : '.count($this->users).'</b>'); $this->printProgress(' ID...'); $usersWithInfo = $this->getUsersInfo($this->users); $this->printProgress(' ', false); $this->printProgress('<b> ID : '.count($usersWithInfo).'</b>'); $this->printProgress(' ...'); $this->users = $this->remakeUsersArray($usersWithInfo); $this->printProgress(' ', false); $this->printProgress(' ...'); $k = 1; foreach ($this->users as $id => $data) { $this->printProgress('<i>'.$k.') : <a href="http://vk.com/id'.$id.'">id'.$id.'</a> - '.$data['last_name'].' '.$data['first_name'].'</i>'); $this->getUsersPosts($id); if ($this->find) { $this->printProgress(' #'.$this->findPost.' ...'); $this->getUsers($id, $this->findPost, 'copies', 0, true); $status = '<span'; if ($this->countReposts > 0) $status .= ' style="font-size: 20px;"'; $status .= '> #'.$this->findPost.': <b>'.$this->countReposts.'</b></span>'; $this->printProgress($status, false); $this->users[$id]['count_reposts'] = $this->countReposts; // $this->user[$id] } $k++; } $this->printProgress(' ', false); } }
Source: https://habr.com/ru/post/177641/
All Articles