Merge branch 'FixPinterestBridge' of https://github.com/logmanoriginal/rss-bridge
This commit is contained in:
commit
e0407326c3
1 changed files with 96 additions and 76 deletions
|
@ -1,101 +1,121 @@
|
|||
<?php
|
||||
class PinterestBridge extends BridgeAbstract{
|
||||
class PinterestBridge extends BridgeAbstract {
|
||||
|
||||
const MAINTAINER = "pauder";
|
||||
const NAME = "Pinterest Bridge";
|
||||
const URI = "http://www.pinterest.com/";
|
||||
const DESCRIPTION = "Returns the newest images on a board";
|
||||
|
||||
const PARAMETERS = array(
|
||||
'By username and board' => array(
|
||||
'u'=>array(
|
||||
'name'=>'username',
|
||||
'required'=>true
|
||||
),
|
||||
'b'=>array(
|
||||
'name'=>'board',
|
||||
'required'=>true
|
||||
)
|
||||
),
|
||||
'From search' => array(
|
||||
'q'=>array(
|
||||
'name'=>'Keyword',
|
||||
'required'=>true
|
||||
)
|
||||
)
|
||||
);
|
||||
const PARAMETERS = array(
|
||||
'By username and board' => array(
|
||||
'u' => array(
|
||||
'name' => 'username',
|
||||
'required' => true
|
||||
),
|
||||
'b' => array(
|
||||
'name' => 'board',
|
||||
'required' => true
|
||||
)
|
||||
),
|
||||
'From search' => array(
|
||||
'q' => array(
|
||||
'name' => 'Keyword',
|
||||
'required' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public function collectData(){
|
||||
$html = $this->getSimpleHTMLDOM($this->getURI());
|
||||
if(!$html){
|
||||
switch($this->queriedContext){
|
||||
case 'By username and board':
|
||||
$this->returnServerError('Username and/or board not found');
|
||||
case 'From search':
|
||||
$this->returnServerError('Could not request Pinterest.');
|
||||
}
|
||||
}
|
||||
|
||||
public function collectData(){
|
||||
$html = $this->getSimpleHTMLDOM($this->getURI()) ;
|
||||
if(!$html){
|
||||
switch($this->queriedContext){
|
||||
case 'By username and board':
|
||||
$this->returnServerError('Username and/or board not found');
|
||||
case 'From search':
|
||||
$this->returnServerError('Could not request Pinterest.');
|
||||
}
|
||||
}
|
||||
if($this->queriedContext === 'From search'){
|
||||
foreach($html->find('div.pinWrapper') as $div){
|
||||
$item = array();
|
||||
|
||||
foreach($html->find('div.pinWrapper') as $div)
|
||||
{
|
||||
$a = $div->find('a.pinImageWrapper',0);
|
||||
$a = $div->find('a.pinImageWrapper', 0);
|
||||
$img = $a->find('img', 0);
|
||||
|
||||
$img = $a->find('img', 0);
|
||||
$item['uri'] = $this->getURI() . $a->getAttribute('href');
|
||||
$item['content'] = '<img src="'
|
||||
. htmlentities(str_replace('/236x/', '/736x/', $img->getAttribute('src')))
|
||||
. '" alt="" />';
|
||||
|
||||
$item = array();
|
||||
$item['uri'] = $this->getURI().$a->getAttribute('href');
|
||||
$item['content'] = '<img src="' . htmlentities(str_replace('/236x/', '/736x/', $img->getAttribute('src'))) . '" alt="" />';
|
||||
|
||||
|
||||
if ($this->queriedContext==='From search')
|
||||
{
|
||||
$avatar = $div->find('div.creditImg', 0)->find('img', 0);
|
||||
$avatar = $div->find('div.creditImg', 0)->find('img', 0);
|
||||
$avatar = $avatar->getAttribute('data-src');
|
||||
$avatar = str_replace("\\", "", $avatar);
|
||||
|
||||
$username = $div->find('div.creditName', 0);
|
||||
$board = $div->find('div.creditTitle', 0);
|
||||
|
||||
$username = $div->find('div.creditName', 0);
|
||||
$board = $div->find('div.creditTitle', 0);
|
||||
$item['username'] = $username->innertext;
|
||||
$item['fullname'] = $board->innertext;
|
||||
$item['avatar'] = $avatar;
|
||||
|
||||
$item['username'] =$username->innertext;
|
||||
$item['fullname'] = $board->innertext;
|
||||
$item['avatar'] = $avatar;
|
||||
$item['content'] .= '<br /><img align="left" style="margin: 2px 4px;" src="'
|
||||
. htmlentities($item['avatar'])
|
||||
. '" /> <strong>'
|
||||
. $item['username']
|
||||
. '</strong>'
|
||||
. '<br />'
|
||||
. $item['fullname'];
|
||||
|
||||
$item['content'] .= '<br /><img align="left" style="margin: 2px 4px;" src="'.htmlentities($item['avatar']).'" /> <strong>'.$item['username'].'</strong>';
|
||||
$item['content'] .= '<br />'.$item['fullname'];
|
||||
}
|
||||
$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 $this->returnServerError('Unable to find data container!');
|
||||
|
||||
$item['title'] = $img->getAttribute('alt');
|
||||
$json = json_decode($container->innertext, true);
|
||||
|
||||
//$item['timestamp'] = $media->created_time;
|
||||
$this->items[] = $item;
|
||||
foreach($json['itemListElement'] as $element){
|
||||
$item = array();
|
||||
|
||||
}
|
||||
}
|
||||
$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'] = <<<EOD
|
||||
<a href="{$item['uri']}">
|
||||
<img src="{$element['item']['image']}">
|
||||
</a>
|
||||
<p>{$element['item']['text']}</p>
|
||||
EOD;
|
||||
|
||||
public function getURI(){
|
||||
switch($this->queriedContext){
|
||||
case 'By username and board':
|
||||
$uri = self::URI.urlencode($this->getInput('u')).'/'.urlencode($this->getInput('b'));
|
||||
break;
|
||||
case 'From search':
|
||||
$uri = self::URI.'search/?q='.urlencode($this->getInput('q'));
|
||||
break;
|
||||
}
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
public function getURI(){
|
||||
switch($this->queriedContext){
|
||||
case 'By username and board':
|
||||
$uri = self::URI . urlencode($this->getInput('u')) . '/' . urlencode($this->getInput('b'));
|
||||
break;
|
||||
case 'From search':
|
||||
$uri = self::URI . 'search/?q=' . urlencode($this->getInput('q'));
|
||||
break;
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
switch($this->queriedContext){
|
||||
case 'By username and board':
|
||||
$specific = $this->getInput('u').'-'.$this->getInput('b');
|
||||
break;
|
||||
case 'From search':
|
||||
$specific = $this->getInput('q');
|
||||
break;
|
||||
}
|
||||
return $specific .' - '.self::NAME;
|
||||
}
|
||||
public function getName(){
|
||||
switch($this->queriedContext){
|
||||
case 'By username and board':
|
||||
$specific = $this->getInput('u') . '-' . $this->getInput('b');
|
||||
break;
|
||||
case 'From search':
|
||||
$specific = $this->getInput('q');
|
||||
break;
|
||||
}
|
||||
return $specific . ' - ' . self::NAME;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue