2014-01-30 17:55:35 +04:00
|
|
|
<?php
|
2017-04-10 00:26:35 +03:00
|
|
|
class PinterestBridge extends FeedExpander {
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'pauder';
|
|
|
|
const NAME = 'Pinterest Bridge';
|
2017-04-10 00:26:35 +03:00
|
|
|
const URI = 'https://www.pinterest.com';
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns the newest images on a board';
|
2016-08-27 22:03:26 +03:00
|
|
|
|
2016-09-17 20:09:33 +03:00
|
|
|
const PARAMETERS = array(
|
|
|
|
'By username and board' => array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
'b' => array(
|
|
|
|
'name' => 'board',
|
|
|
|
'required' => true
|
2017-04-10 00:26:35 +03:00
|
|
|
),
|
|
|
|
'r' => array(
|
|
|
|
'name' => 'Use provided RSS',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'required' => false,
|
|
|
|
'defaultValue' => 'checked',
|
|
|
|
'title' => 'Uncheck to return data via custom filters (more data)'
|
2016-09-17 20:09:33 +03:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'From search' => array(
|
|
|
|
'q' => array(
|
|
|
|
'name' => 'Keyword',
|
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
public function collectData(){
|
2017-04-10 00:26:35 +03:00
|
|
|
switch($this->queriedContext){
|
2016-09-17 20:09:33 +03:00
|
|
|
case 'By username and board':
|
2017-04-10 00:26:35 +03:00
|
|
|
if($this->getInput('r')){
|
|
|
|
$this->collectExpandableDatas($this->getURI() . '.rss');
|
|
|
|
} else {
|
|
|
|
$html = getSimpleHTMLDOMCached($this->getURI());
|
|
|
|
$this->getUserResults($html);
|
|
|
|
}
|
|
|
|
break;
|
2016-09-17 20:09:33 +03:00
|
|
|
case 'From search':
|
2017-04-10 00:26:35 +03:00
|
|
|
default:
|
|
|
|
$html = getSimpleHTMLDOMCached($this->getURI());
|
|
|
|
$this->getSearchResults($html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getUserResults($html){
|
|
|
|
$json = json_decode($html->find('#jsInit1', 0)->innertext, true);
|
|
|
|
$results = $json['tree']['children'][0]['children'][0]['children'][0]['options']['props']['data']['board_feed'];
|
|
|
|
$username = $json['resourceDataCache'][0]['data']['owner']['username'];
|
|
|
|
$fullname = $json['resourceDataCache'][0]['data']['owner']['full_name'];
|
|
|
|
$avatar = $json['resourceDataCache'][0]['data']['owner']['image_small_url'];
|
|
|
|
|
|
|
|
foreach($results as $result){
|
|
|
|
$item = array();
|
|
|
|
|
|
|
|
$item['uri'] = $result['link'];
|
|
|
|
|
|
|
|
// 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['description']);
|
|
|
|
|
|
|
|
$item['timestamp'] = strtotime($result['created_at']);
|
|
|
|
$item['username'] = $username;
|
|
|
|
$item['fullname'] = $fullname;
|
|
|
|
$item['avatar'] = $avatar;
|
|
|
|
$item['author'] = $item['username'] . ' (' . $item['fullname'] . ')';
|
|
|
|
$item['content'] = '<img align="left" style="margin: 2px 4px;" src="'
|
|
|
|
. htmlentities($item['avatar'])
|
|
|
|
. '" /><p><strong>'
|
|
|
|
. $item['username']
|
|
|
|
. '</strong><br>'
|
|
|
|
. $item['fullname']
|
|
|
|
. '</p><br><img src="'
|
|
|
|
. $result['images']['736x']['url']
|
|
|
|
. '" alt="" /><br><p>'
|
|
|
|
. $result['description']
|
|
|
|
. '</p>';
|
|
|
|
|
|
|
|
$item['enclosures'] = array($result['images']['orig']['url']);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
2016-09-17 20:09:33 +03:00
|
|
|
}
|
2017-04-10 00:26:35 +03:00
|
|
|
}
|
2016-09-17 20:09:33 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
private function getSearchResults($html){
|
|
|
|
$json = json_decode($html->find('#jsInit1', 0)->innertext, true);
|
|
|
|
$results = $json['resourceDataCache'][0]['data']['results'];
|
2016-09-17 20:09:33 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
foreach($results as $result){
|
|
|
|
$item = array();
|
2016-09-17 20:14:05 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
$item['uri'] = self::URI . $result['board']['url'];
|
2016-09-17 20:09:33 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
// Some use regular titles, others provide 'advanced' infos, a few
|
|
|
|
// provide even less info. Thus we attempt multiple options.
|
|
|
|
$item['title'] = trim($result['title']);
|
2016-02-26 17:58:03 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
if($item['title'] === "")
|
|
|
|
$item['title'] = trim($result['rich_summary']['display_name']);
|
2016-09-17 20:09:33 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
if($item['title'] === "")
|
|
|
|
$item['title'] = trim($result['grid_description']);
|
2016-09-17 20:09:33 +03:00
|
|
|
|
2017-04-10 00:26:35 +03:00
|
|
|
$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'] = '<img align="left" style="margin: 2px 4px;" src="'
|
2016-09-17 20:09:33 +03:00
|
|
|
. htmlentities($item['avatar'])
|
2017-04-10 00:26:35 +03:00
|
|
|
. '" /><p><strong>'
|
2016-09-17 20:09:33 +03:00
|
|
|
. $item['username']
|
2017-04-10 00:26:35 +03:00
|
|
|
. '</strong><br>'
|
|
|
|
. $item['fullname']
|
|
|
|
. '</p><br><img src="'
|
|
|
|
. $result['images']['736x']['url']
|
|
|
|
. '" alt="" /><br><p>'
|
|
|
|
. $result['description']
|
|
|
|
. '</p>';
|
|
|
|
|
|
|
|
$item['enclosures'] = array($result['images']['orig']['url']);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
2016-09-17 20:09:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username and board':
|
2017-04-10 00:26:35 +03:00
|
|
|
$uri = self::URI . '/' . urlencode($this->getInput('u')) . '/' . urlencode($this->getInput('b'));// . '.rss';
|
2016-09-17 20:09:33 +03:00
|
|
|
break;
|
|
|
|
case 'From search':
|
2017-04-10 00:26:35 +03:00
|
|
|
$uri = self::URI . '/search/?q=' . urlencode($this->getInput('q'));
|
2016-09-17 20:09:33 +03:00
|
|
|
break;
|
2016-12-17 18:39:18 +03:00
|
|
|
default: return parent::getURI();
|
2016-09-17 20:09:33 +03:00
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username and board':
|
2017-04-10 00:26:35 +03:00
|
|
|
$specific = $this->getInput('u') . ' - ' . $this->getInput('b');
|
2016-09-17 20:09:33 +03:00
|
|
|
break;
|
|
|
|
case 'From search':
|
|
|
|
$specific = $this->getInput('q');
|
|
|
|
break;
|
2016-12-17 18:39:18 +03:00
|
|
|
default: return parent::getName();
|
2016-09-17 20:09:33 +03:00
|
|
|
}
|
|
|
|
return $specific . ' - ' . self::NAME;
|
|
|
|
}
|
2014-01-30 17:55:35 +04:00
|
|
|
}
|