VkBridge.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class VkBridge extends BridgeAbstract {
  3. const MAINTAINER = 'ahiles3005';
  4. const NAME = 'VK.com';
  5. const URI = 'http://vk.com/';
  6. const CACHE_TIMEOUT = 300; // 5min
  7. const DESCRIPTION = 'Working with open pages';
  8. const PARAMETERS = array(
  9. array(
  10. 'u' => array(
  11. 'name' => 'Group or user name',
  12. 'required' => true
  13. )
  14. )
  15. );
  16. public function getURI(){
  17. if(!is_null($this->getInput('u'))){
  18. return static::URI . urlencode($this->getInput('u'));
  19. }
  20. return parent::getURI();
  21. }
  22. public function collectData(){
  23. ini_set('user-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0');
  24. $text_html = getContents($this->getURI())
  25. or returnServerError('No results for group or user name "' . $this->getInput('u') . '".');
  26. $text_html = iconv('windows-1251', 'utf-8', $text_html);
  27. $html = str_get_html($text_html);
  28. foreach($html->find('.post') as $post){
  29. if(is_object($post->find('a.wall_post_more', 0))){
  30. //delete link "show full" in content
  31. $post->find('a.wall_post_more', 0)->outertext = '';
  32. }
  33. $item = array();
  34. $item['content'] = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '<br><img>');
  35. if(is_object($post->find('a.page_media_link_title', 0))){
  36. $link = $post->find('a.page_media_link_title', 0)->getAttribute('href');
  37. //external link in the post
  38. $item['content'] .= "\n\rExternal link: "
  39. . str_replace('/away.php?to=', '', urldecode($link));
  40. }
  41. //get video on post
  42. if(is_object($post->find('span.post_video_title_content', 0))){
  43. $titleVideo = $post->find('span.post_video_title_content', 0)->plaintext;
  44. $linkToVideo = self::URI . $post->find('a.page_post_thumb_video', 0)->getAttribute('href');
  45. $item['content'] .= "\n\r {$titleVideo}: {$linkToVideo}";
  46. }
  47. // get post link
  48. $item['uri'] = self::URI . $post->find('a.post_link', 0)->getAttribute('href');
  49. $item['date'] = $post->find('span.rel_date', 0)->plaintext;
  50. $this->items[] = $item;
  51. // var_dump($item['date']);
  52. }
  53. }
  54. }