2014-01-30 14:55:35 +01:00
|
|
|
<?php
|
|
|
|
class PinterestBridge extends BridgeAbstract{
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
public $maintainer = "pauder";
|
|
|
|
public $name = "Pinterest Bridge";
|
2016-08-29 21:51:48 +02:00
|
|
|
public $uri = "http://www.pinterest.com/";
|
2016-08-27 21:03:26 +02:00
|
|
|
public $description = "Returns the newest images on a board";
|
|
|
|
|
|
|
|
public $parameters = array(
|
|
|
|
'By username and board' => array(
|
2016-08-29 21:51:48 +02:00
|
|
|
'u'=>array(
|
|
|
|
'name'=>'username',
|
|
|
|
'required'=>true
|
|
|
|
),
|
|
|
|
'b'=>array(
|
|
|
|
'name'=>'board',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
'From search' => array(
|
2016-08-29 21:51:48 +02:00
|
|
|
'q'=>array(
|
|
|
|
'name'=>'Keyword',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-29 21:51:48 +02:00
|
|
|
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.');
|
2014-01-30 14:55:35 +01:00
|
|
|
}
|
2016-08-29 21:51:48 +02:00
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2014-01-30 14:55:35 +01:00
|
|
|
foreach($html->find('div.pinWrapper') as $div)
|
|
|
|
{
|
|
|
|
$a = $div->find('a.pinImageWrapper',0);
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2014-01-30 14:55:35 +01:00
|
|
|
$img = $a->find('img', 0);
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $this->getURI().$a->getAttribute('href');
|
|
|
|
$item['content'] = '<img src="' . htmlentities(str_replace('/236x/', '/736x/', $img->getAttribute('src'))) . '" alt="" />';
|
2016-07-08 19:06:35 +02:00
|
|
|
|
|
|
|
|
2016-08-29 21:51:48 +02:00
|
|
|
if ($this->queriedContext==='From search')
|
2014-01-30 15:25:25 +01:00
|
|
|
{
|
2016-02-26 15:58:03 +01:00
|
|
|
$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);
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['username'] =$username->innertext;
|
|
|
|
$item['fullname'] = $board->innertext;
|
|
|
|
$item['avatar'] = $avatar;
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] .= '<br /><img align="left" style="margin: 2px 4px;" src="'.htmlentities($item['avatar']).'" /> <strong>'.$item['username'].'</strong>';
|
|
|
|
$item['content'] .= '<br />'.$item['fullname'];
|
2014-01-30 15:25:25 +01:00
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['title'] = $img->getAttribute('alt');
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
//$item['timestamp'] = $media->created_time;
|
2014-01-30 14:55:35 +01:00
|
|
|
$this->items[] = $item;
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2014-01-30 14:55:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 21:51:48 +02:00
|
|
|
public function getURI(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username and board':
|
|
|
|
$uri = $this->uri.urlencode($this->getInput('u')).'/'.urlencode($this->getInput('b'));
|
|
|
|
break;
|
|
|
|
case 'From search':
|
|
|
|
$uri = $this->uri.'search/?q='.urlencode($this->getInput('q'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2016-08-29 21:51:48 +02:00
|
|
|
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 .' - '.$this->name;
|
2014-01-30 14:55:35 +01:00
|
|
|
}
|
|
|
|
}
|