[Pinterest] Cleanup code
This commit is contained in:
parent
1819943451
commit
c1cc4da8ef
1 changed files with 78 additions and 80 deletions
|
@ -1,101 +1,99 @@
|
||||||
<?php
|
<?php
|
||||||
class PinterestBridge extends BridgeAbstract{
|
class PinterestBridge extends BridgeAbstract {
|
||||||
|
|
||||||
const MAINTAINER = "pauder";
|
const MAINTAINER = "pauder";
|
||||||
const NAME = "Pinterest Bridge";
|
const NAME = "Pinterest Bridge";
|
||||||
const URI = "http://www.pinterest.com/";
|
const URI = "http://www.pinterest.com/";
|
||||||
const DESCRIPTION = "Returns the newest images on a board";
|
const DESCRIPTION = "Returns the newest images on a board";
|
||||||
|
|
||||||
const PARAMETERS = array(
|
const PARAMETERS = array(
|
||||||
'By username and board' => array(
|
'By username and board' => array(
|
||||||
'u'=>array(
|
'u' => array(
|
||||||
'name'=>'username',
|
'name' => 'username',
|
||||||
'required'=>true
|
'required' => true
|
||||||
),
|
),
|
||||||
'b'=>array(
|
'b' => array(
|
||||||
'name'=>'board',
|
'name' => 'board',
|
||||||
'required'=>true
|
'required' => true
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'From search' => array(
|
'From search' => array(
|
||||||
'q'=>array(
|
'q' => array(
|
||||||
'name'=>'Keyword',
|
'name' => 'Keyword',
|
||||||
'required'=>true
|
'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(){
|
foreach($html->find('div.pinWrapper') as $div){
|
||||||
$html = $this->getSimpleHTMLDOM($this->getURI()) ;
|
$a = $div->find('a.pinImageWrapper', 0);
|
||||||
if(!$html){
|
$img = $a->find('img', 0);
|
||||||
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.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($html->find('div.pinWrapper') as $div)
|
$item = array();
|
||||||
{
|
$item['uri'] = $this->getURI() . $a->getAttribute('href');
|
||||||
$a = $div->find('a.pinImageWrapper',0);
|
$item['content'] = '<img src="'
|
||||||
|
. htmlentities(str_replace('/236x/', '/736x/', $img->getAttribute('src')))
|
||||||
|
. '" alt="" />';
|
||||||
|
|
||||||
$img = $a->find('img', 0);
|
if($this->queriedContext === 'From search'){
|
||||||
|
$avatar = $div->find('div.creditImg', 0)->find('img', 0);
|
||||||
$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 = $avatar->getAttribute('data-src');
|
$avatar = $avatar->getAttribute('data-src');
|
||||||
$avatar = str_replace("\\", "", $avatar);
|
$avatar = str_replace("\\", "", $avatar);
|
||||||
|
|
||||||
|
$username = $div->find('div.creditName', 0);
|
||||||
|
$board = $div->find('div.creditTitle', 0);
|
||||||
|
|
||||||
$username = $div->find('div.creditName', 0);
|
$item['username'] = $username->innertext;
|
||||||
$board = $div->find('div.creditTitle', 0);
|
$item['fullname'] = $board->innertext;
|
||||||
|
$item['avatar'] = $avatar;
|
||||||
|
|
||||||
$item['username'] =$username->innertext;
|
$item['content'] .= '<br /><img align="left" style="margin: 2px 4px;" src="'
|
||||||
$item['fullname'] = $board->innertext;
|
. htmlentities($item['avatar'])
|
||||||
$item['avatar'] = $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['title'] = $img->getAttribute('alt');
|
||||||
$item['content'] .= '<br />'.$item['fullname'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$item['title'] = $img->getAttribute('alt');
|
$this->items[] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//$item['timestamp'] = $media->created_time;
|
public function getURI(){
|
||||||
$this->items[] = $item;
|
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':
|
||||||
public function getURI(){
|
$specific = $this->getInput('u') . '-' . $this->getInput('b');
|
||||||
switch($this->queriedContext){
|
break;
|
||||||
case 'By username and board':
|
case 'From search':
|
||||||
$uri = self::URI.urlencode($this->getInput('u')).'/'.urlencode($this->getInput('b'));
|
$specific = $this->getInput('q');
|
||||||
break;
|
break;
|
||||||
case 'From search':
|
}
|
||||||
$uri = self::URI.'search/?q='.urlencode($this->getInput('q'));
|
return $specific . ' - ' . self::NAME;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue