VkBridge.php 2.2 KB

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