From 2500d0df9329cddfe8c07b49036c42561e784f51 Mon Sep 17 00:00:00 2001
From: logmanoriginal '
. $item['username']
- . '';
+ $item['uri'] = $result['link'];
- $avatar = $div->find('div.creditImg', 0)->find('img', 0);
- $avatar = $avatar->getAttribute('data-src');
- $avatar = str_replace("\\", "", $avatar);
+ // Some use regular titles, others provide 'advanced' infos, a few
+ // provide even less info. Thus we attempt multiple options.
+ $item['title'] = trim($result['title']);
- $username = $div->find('div.creditName', 0);
- $board = $div->find('div.creditTitle', 0);
+ if($item['title'] === "")
+ $item['title'] = trim($result['rich_summary']['display_name']);
- $item['username'] = $username->innertext;
- $item['fullname'] = $board->innertext;
- $item['avatar'] = $avatar;
+ if($item['title'] === "")
+ $item['title'] = trim($result['description']);
- $item['content'] .= '
'
+ . '" />
'
- . $item['fullname'];
+ . '
'
+ . $item['fullname']
+ . '
' + . $result['description'] + . '
'; - $item['title'] = $img->getAttribute('alt'); - $this->items[] = $item; - } - } elseif($this->queriedContext === 'By username and board'){ - $container = $html->find('SCRIPT[type="application/ld+json"]', 0) - or returnServerError('Unable to find data container!'); + $item['enclosures'] = array($result['images']['orig']['url']); - $json = json_decode($container->innertext, true); + $this->items[] = $item; + } + } - foreach($json['itemListElement'] as $element){ - $item = array(); + private function getSearchResults($html){ + $json = json_decode($html->find('#jsInit1', 0)->innertext, true); + $results = $json['resourceDataCache'][0]['data']['results']; - $item['uri'] = $element['item']['sharedContent']['author']['url']; - $item['title'] = $element['item']['name']; - $item['author'] = $element['item']['user']['name']; - $item['timestamp'] = strtotime($element['item']['datePublished']); - $item['content'] = <<{$element['item']['text']}
-EOD; + foreach($results as $result){ + $item = array(); - $this->items[] = $item; - } + $item['uri'] = self::URI . $result['board']['url']; + + // Some use regular titles, others provide 'advanced' infos, a few + // provide even less info. Thus we attempt multiple options. + $item['title'] = trim($result['title']); + + if($item['title'] === "") + $item['title'] = trim($result['rich_summary']['display_name']); + + if($item['title'] === "") + $item['title'] = trim($result['grid_description']); + + $item['timestamp'] = strtotime($result['created_at']); + $item['username'] = $result['pinner']['username']; + $item['fullname'] = $result['pinner']['full_name']; + $item['avatar'] = $result['pinner']['image_small_url']; + $item['author'] = $item['username'] . ' (' . $item['fullname'] . ')'; + $item['content'] = ''
+ . $item['username']
+ . '
'
+ . $item['fullname']
+ . '
' + . $result['description'] + . '
'; + + $item['enclosures'] = array($result['images']['orig']['url']); + + $this->items[] = $item; } } public function getURI(){ switch($this->queriedContext){ case 'By username and board': - $uri = self::URI . urlencode($this->getInput('u')) . '/' . urlencode($this->getInput('b')); + $uri = self::URI . '/' . urlencode($this->getInput('u')) . '/' . urlencode($this->getInput('b'));// . '.rss'; break; case 'From search': - $uri = self::URI . 'search/?q=' . urlencode($this->getInput('q')); + $uri = self::URI . '/search/?q=' . urlencode($this->getInput('q')); break; default: return parent::getURI(); } @@ -110,7 +152,7 @@ EOD; public function getName(){ switch($this->queriedContext){ case 'By username and board': - $specific = $this->getInput('u') . '-' . $this->getInput('b'); + $specific = $this->getInput('u') . ' - ' . $this->getInput('b'); break; case 'From search': $specific = $this->getInput('q');