[Pinterest] Cleanup code

This commit is contained in:
logmanoriginal 2016-09-17 19:09:33 +02:00
parent 1819943451
commit c1cc4da8ef

View file

@ -1,5 +1,5 @@
<?php <?php
class PinterestBridge extends BridgeAbstract{ class PinterestBridge extends BridgeAbstract {
const MAINTAINER = "pauder"; const MAINTAINER = "pauder";
const NAME = "Pinterest Bridge"; const NAME = "Pinterest Bridge";
@ -8,26 +8,25 @@ class PinterestBridge extends BridgeAbstract{
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(){ public function collectData(){
$html = $this->getSimpleHTMLDOM($this->getURI()) ; $html = $this->getSimpleHTMLDOM($this->getURI());
if(!$html){ if(!$html){
switch($this->queriedContext){ switch($this->queriedContext){
case 'By username and board': case 'By username and board':
@ -37,65 +36,64 @@ class PinterestBridge extends BridgeAbstract{
} }
} }
foreach($html->find('div.pinWrapper') as $div) 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 = array(); $item = array();
$item['uri'] = $this->getURI().$a->getAttribute('href'); $item['uri'] = $this->getURI() . $a->getAttribute('href');
$item['content'] = '<img src="' . htmlentities(str_replace('/236x/', '/736x/', $img->getAttribute('src'))) . '" alt="" />'; $item['content'] = '<img src="'
. htmlentities(str_replace('/236x/', '/736x/', $img->getAttribute('src')))
. '" alt="" />';
if($this->queriedContext === 'From search'){
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 = $avatar->getAttribute('data-src');
$avatar = str_replace("\\", "", $avatar); $avatar = str_replace("\\", "", $avatar);
$username = $div->find('div.creditName', 0); $username = $div->find('div.creditName', 0);
$board = $div->find('div.creditTitle', 0); $board = $div->find('div.creditTitle', 0);
$item['username'] =$username->innertext; $item['username'] = $username->innertext;
$item['fullname'] = $board->innertext; $item['fullname'] = $board->innertext;
$item['avatar'] = $avatar; $item['avatar'] = $avatar;
$item['content'] .= '<br /><img align="left" style="margin: 2px 4px;" src="'.htmlentities($item['avatar']).'" /> <strong>'.$item['username'].'</strong>'; $item['content'] .= '<br /><img align="left" style="margin: 2px 4px;" src="'
$item['content'] .= '<br />'.$item['fullname']; . htmlentities($item['avatar'])
. '" /> <strong>'
. $item['username']
. '</strong>'
. '<br />'
. $item['fullname'];
} }
$item['title'] = $img->getAttribute('alt'); $item['title'] = $img->getAttribute('alt');
//$item['timestamp'] = $media->created_time;
$this->items[] = $item; $this->items[] = $item;
} }
} }
public function getURI(){ public function getURI(){
switch($this->queriedContext){ switch($this->queriedContext){
case 'By username and board': 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'));
break; break;
case 'From search': case 'From search':
$uri = self::URI.'search/?q='.urlencode($this->getInput('q')); $uri = self::URI . 'search/?q=' . urlencode($this->getInput('q'));
break; break;
} }
return $uri; return $uri;
} }
public function getName(){ public function getName(){
switch($this->queriedContext){ switch($this->queriedContext){
case 'By username and board': case 'By username and board':
$specific = $this->getInput('u').'-'.$this->getInput('b'); $specific = $this->getInput('u') . '-' . $this->getInput('b');
break; break;
case 'From search': case 'From search':
$specific = $this->getInput('q'); $specific = $this->getInput('q');
break; break;
} }
return $specific .' - '.self::NAME; return $specific . ' - ' . self::NAME;
} }
} }