VkBridge.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. class VkBridge extends BridgeAbstract {
  3. private $request;
  4. public function loadMetadatas() {
  5. $this->maintainer = "ahiles3005";
  6. $this->name = "VK.com";
  7. $this->uri = "http://www.vk.com/";
  8. $this->description = "Working with open pages";
  9. $this->update = "21/02/2016";
  10. $this->parameters["Url on page group or user"] = '[
  11. {
  12. "name" : "Url",
  13. "identifier" : "u"
  14. }
  15. ]';
  16. }
  17. public function collectData(array $param) {
  18. $html = '';
  19. if (isset($param['u'])) {
  20. $this->request = $param['u'];
  21. $text_html = file_get_contents(urldecode($this->request)) or $this->returnError('No results for this query.', 404);
  22. $text_html = iconv('windows-1251', 'utf-8', $text_html);
  23. $html = str_get_html($text_html);
  24. }
  25. foreach ($html->find('div.post_table') as $post) {
  26. if (is_object($post->find('a.wall_post_more', 0))) {
  27. $post->find('a.wall_post_more', 0)->outertext = ''; //delete link "show full" in content
  28. }
  29. $item = new \Item();
  30. $item->content = strip_tags($post->find('div.wall_post_text', 0)->innertext);
  31. if (is_object($post->find('a.page_media_link_title', 0))) {
  32. $link = $post->find('a.page_media_link_title', 0)->getAttribute('href');
  33. $item->content .= "\n\rExternal link: " . str_replace('/away.php?to=', '', urldecode($link)); //external link in the post
  34. }
  35. //get video on post
  36. if (is_object($post->find('span.post_video_title_content', 0))) {
  37. $titleVideo = $post->find('span.post_video_title_content', 0)->plaintext;
  38. $linkToVideo = 'https://vk.com' . $post->find('a.page_post_thumb_video', 0)->getAttribute('href');
  39. $item->content .= "\n\r {$titleVideo}: {$linkToVideo}";
  40. }
  41. $item->uri = 'https://vk.com' . $post->find('.reply_link_wrap', 0)->find('a', 0)->getAttribute('href'); // get post link
  42. $item->date = $post->find('span.rel_date', 0)->plaintext;
  43. $this->items[] = $item;
  44. // var_dump($item->date);
  45. }
  46. }
  47. public function getName() {
  48. return(isset($this->name) ? $this->name . ' - ' : '') . 'VK Bridge';
  49. }
  50. public function getURI() {
  51. return 'http://vk.com';
  52. }
  53. public function getCacheDuration() {
  54. return 300; // 5 minutes
  55. }
  56. }