[EtsyBridge] Add new bridge
This bridge generates feeds for a given search term, optionally adds the picture to the content and allows for additional query extensions (GET parameters) to be passed to the bridge. That way custom filter can be applied without the need to reproduce them in this bridge (they got a lot!) Etsy provides a good set of feeds as described here: https://www.etsy.com/help/article/100 (so there is no need to include them here) References #492
This commit is contained in:
parent
e3b335b9ff
commit
360f9da072
1 changed files with 83 additions and 0 deletions
83
bridges/EtsyBridge.php
Normal file
83
bridges/EtsyBridge.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
class EtsyBridge extends BridgeAbstract {
|
||||
|
||||
const NAME = 'Etsy search';
|
||||
const URI = 'https://www.etsy.com';
|
||||
const DESCRIPTION = 'Returns feeds for search results';
|
||||
const MAINTAINER = 'logmanoriginal';
|
||||
const PARAMETERS = array(
|
||||
array(
|
||||
'query' => array(
|
||||
'name' => 'Search query',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'title' => 'Insert your search term here',
|
||||
'exampleValue' => 'Enter your search term'
|
||||
),
|
||||
'queryextension' => array(
|
||||
'name' => 'Query extension',
|
||||
'type' => 'text',
|
||||
'requied' => false,
|
||||
'title' => 'Insert additional query parts here
|
||||
(anything after ?search=<your search query>)',
|
||||
'exampleValue' => '&explicit=1&locationQuery=2921044'
|
||||
),
|
||||
'showimage' => array(
|
||||
'name' => 'Show image in content',
|
||||
'type' => 'checkbox',
|
||||
'requrired' => false,
|
||||
'title' => 'Activate to show the image in the content',
|
||||
'defaultValue' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public function collectData(){
|
||||
$html = getSimpleHTMLDOM($this->getURI())
|
||||
or returnServerError('Failed to receive ' . $this->getURI());
|
||||
|
||||
$results = $html->find('div.block-grid-item');
|
||||
|
||||
foreach($results as $result){
|
||||
// Skip banner cards (ads for categories)
|
||||
if($result->find('a.banner-card'))
|
||||
continue;
|
||||
|
||||
$item = array();
|
||||
|
||||
$item['title'] = $result->find('a', 0)->title;
|
||||
$item['uri'] = $result->find('a', 0)->href;
|
||||
$item['author'] = $result->find('div.card-shop-name', 0)->plaintext;
|
||||
|
||||
$item['content'] = '<p>'
|
||||
. $result->find('div.card-price', 0)->plaintext
|
||||
. '</p><p>'
|
||||
. $result->find('div.card-title', 0)->plaintext
|
||||
. '</p>';
|
||||
|
||||
$image = $result->find('img.placeholder', 0)->src;
|
||||
|
||||
if($this->getInput('showimage')){
|
||||
$item['content'] .= '<img src="' . $image . '">';
|
||||
}
|
||||
|
||||
$item['enclosures'] = array($image);
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
if(!is_null($this->getInput('query'))){
|
||||
$uri = self::URI . '/search?q=' . urlencode($this->getInput('query'));
|
||||
|
||||
if(!is_null($this->getInput('queryextension'))){
|
||||
$uri .= $this->getInput('queryextension');
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
return parent::getURI();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue