VkBridge.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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( array(
  9. 'u'=>array(
  10. 'name'=>'Group or user name',
  11. 'required'=>true
  12. )
  13. )
  14. );
  15. public function getURI(){
  16. return static::URI.urlencode($this->getInput('u'));
  17. }
  18. public function collectData(){
  19. $text_html = getContents($this->getURI())
  20. or returnServerError('No results for group or user name "'.$this->getInput('u').'".');
  21. $text_html = iconv('windows-1251', 'utf-8', $text_html);
  22. $html = str_get_html($text_html);
  23. foreach ($html->find('div.post_table') as $post) {
  24. if (is_object($post->find('a.wall_post_more', 0))) {
  25. $post->find('a.wall_post_more', 0)->outertext = ''; //delete link "show full" in content
  26. }
  27. $item = array();
  28. $item['content'] = strip_tags($post->find('div.wall_post_text', 0)->innertext);
  29. if (is_object($post->find('a.page_media_link_title', 0))) {
  30. $link = $post->find('a.page_media_link_title', 0)->getAttribute('href');
  31. $item['content'] .= "\n\rExternal link: " . str_replace('/away.php?to=', '', urldecode($link)); //external link in the post
  32. }
  33. //get video on post
  34. if (is_object($post->find('span.post_video_title_content', 0))) {
  35. $titleVideo = $post->find('span.post_video_title_content', 0)->plaintext;
  36. $linkToVideo = self::URI . $post->find('a.page_post_thumb_video', 0)->getAttribute('href');
  37. $item['content'] .= "\n\r {$titleVideo}: {$linkToVideo}";
  38. }
  39. $item['uri'] = self::URI . $post->find('.reply_link_wrap', 0)->find('a', 0)->getAttribute('href'); // get post link
  40. $item['date'] = $post->find('span.rel_date', 0)->plaintext;
  41. $this->items[] = $item;
  42. // var_dump($item['date']);
  43. }
  44. }
  45. }