VkBridge.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. class VkBridge extends BridgeAbstract
  3. {
  4. const MAINTAINER = 'ahiles3005';
  5. const NAME = 'VK.com';
  6. const URI = 'https://vk.com/';
  7. const CACHE_TIMEOUT = 300; // 5min
  8. const DESCRIPTION = 'Working with open pages';
  9. const PARAMETERS = array(
  10. array(
  11. 'u' => array(
  12. 'name' => 'Group or user name',
  13. 'required' => true
  14. )
  15. )
  16. );
  17. protected $pageName;
  18. public function getURI()
  19. {
  20. if (!is_null($this->getInput('u'))) {
  21. return static::URI . urlencode($this->getInput('u'));
  22. }
  23. return parent::getURI();
  24. }
  25. public function getName()
  26. {
  27. if ($this->pageName) {
  28. return $this->pageName;
  29. }
  30. return parent::getName();
  31. }
  32. public function collectData()
  33. {
  34. $text_html = $this->getContents()
  35. or returnServerError('No results for group or user name "' . $this->getInput('u') . '".');
  36. $text_html = iconv('windows-1251', 'utf-8', $text_html);
  37. $html = str_get_html($text_html);
  38. $pageName = $html->find('.page_name', 0)->plaintext;
  39. $this->pageName = $pageName;
  40. foreach ($html->find('.post') as $post) {
  41. if (is_object($post->find('a.wall_post_more', 0))) {
  42. //delete link "show full" in content
  43. $post->find('a.wall_post_more', 0)->outertext = '';
  44. }
  45. $item = array();
  46. $item['content'] = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '<br><img>');
  47. if (is_object($post->find('a.page_media_link_title', 0))) {
  48. $link = $post->find('a.page_media_link_title', 0)->getAttribute('href');
  49. //external link in the post
  50. $item['content'] .= "\n\rExternal link: "
  51. . str_replace('/away.php?to=', '', urldecode($link));
  52. }
  53. //get video on post
  54. if (is_object($post->find('span.post_video_title_content', 0))) {
  55. $titleVideo = $post->find('span.post_video_title_content', 0)->plaintext;
  56. $linkToVideo = self::URI . $post->find('a.page_post_thumb_video', 0)->getAttribute('href');
  57. $item['content'] .= "\n\r {$titleVideo}: {$linkToVideo}";
  58. }
  59. // get post link
  60. $item['uri'] = self::URI . $post->find('a.post_link', 0)->getAttribute('href');
  61. $item['timestamp'] = $this->getTime($post);
  62. $item['author'] = $pageName;
  63. $this->items[] = $item;
  64. }
  65. }
  66. private function getTime($post)
  67. {
  68. if ($time = $post->find('span.rel_date', 0)->getAttribute('time')) {
  69. return $time;
  70. } else {
  71. $strdate = $post->find('span.rel_date', 0)->plaintext;
  72. $date = date_parse($strdate);
  73. if (!$date['year']) {
  74. if (strstr($strdate, 'today') !== false) {
  75. $strdate = date('d-m-Y') . ' ' . $strdate;
  76. } elseif (strstr($strdate, 'yesterday ') !== false) {
  77. $time = time() - 60 * 60 * 24;
  78. $strdate = date('d-m-Y', $time) . ' ' . $strdate;
  79. } else {
  80. $strdate = $strdate . ' ' . date('Y');
  81. }
  82. $date = date_parse($strdate);
  83. }
  84. return strtotime($date['day'] . '-' . $date['month'] . '-' . $date['year'] . ' ' .
  85. $date['hour'] . ':' . $date['minute']);
  86. }
  87. }
  88. public function getContents()
  89. {
  90. ini_set('user-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0');
  91. $header = array('Accept-language: en', 'Cookie: remixlang=3');
  92. return getContents($this->getURI(), $header);
  93. }
  94. }