2017-03-27 20:18:16 +02:00
|
|
|
<?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',
|
2018-10-20 13:08:03 +02:00
|
|
|
'required' => false,
|
2017-03-27 20:18:16 +02:00
|
|
|
'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',
|
2018-10-20 13:08:03 +02:00
|
|
|
'required' => false,
|
2017-03-27 20:18:16 +02:00
|
|
|
'title' => 'Activate to show the image in the content',
|
2018-10-20 13:08:03 +02:00
|
|
|
'defaultValue' => 'checked'
|
2017-03-27 20:18:16 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
public function collectData(){
|
|
|
|
$html = getSimpleHTMLDOM($this->getURI())
|
|
|
|
or returnServerError('Failed to receive ' . $this->getURI());
|
|
|
|
|
2018-10-20 13:08:03 +02:00
|
|
|
$results = $html->find('li.block-grid-item');
|
2017-03-27 20:18:16 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($results as $result) {
|
2017-03-27 20:18:16 +02:00
|
|
|
// Skip banner cards (ads for categories)
|
2018-10-20 13:08:03 +02:00
|
|
|
if($result->find('span.ad-indicator'))
|
2017-03-27 20:18:16 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
$item = array();
|
|
|
|
|
|
|
|
$item['title'] = $result->find('a', 0)->title;
|
|
|
|
$item['uri'] = $result->find('a', 0)->href;
|
2018-10-20 13:08:03 +02:00
|
|
|
$item['author'] = $result->find('p.text-gray-lighter', 0)->plaintext;
|
2017-03-27 20:18:16 +02:00
|
|
|
|
|
|
|
$item['content'] = '<p>'
|
2018-10-20 13:08:03 +02:00
|
|
|
. $result->find('span.currency-value', 0)->plaintext . ' '
|
|
|
|
. $result->find('span.currency-symbol', 0)->plaintext
|
2017-03-27 20:18:16 +02:00
|
|
|
. '</p><p>'
|
2018-10-20 13:08:03 +02:00
|
|
|
. $result->find('a', 0)->title
|
2017-03-27 20:18:16 +02:00
|
|
|
. '</p>';
|
|
|
|
|
2018-10-20 13:08:03 +02:00
|
|
|
$image = $result->find('img.display-block', 0)->src;
|
2017-03-27 20:18:16 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if($this->getInput('showimage')) {
|
2017-03-27 20:18:16 +02:00
|
|
|
$item['content'] .= '<img src="' . $image . '">';
|
|
|
|
}
|
|
|
|
|
|
|
|
$item['enclosures'] = array($image);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!is_null($this->getInput('query'))) {
|
2017-03-27 20:18:16 +02:00
|
|
|
$uri = self::URI . '/search?q=' . urlencode($this->getInput('query'));
|
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!is_null($this->getInput('queryextension'))) {
|
2017-03-27 20:18:16 +02:00
|
|
|
$uri .= $this->getInput('queryextension');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getURI();
|
|
|
|
}
|
|
|
|
}
|