EtsyBridge.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. class EtsyBridge extends BridgeAbstract {
  3. const NAME = 'Etsy search';
  4. const URI = 'https://www.etsy.com';
  5. const DESCRIPTION = 'Returns feeds for search results';
  6. const MAINTAINER = 'logmanoriginal';
  7. const PARAMETERS = array(
  8. array(
  9. 'query' => array(
  10. 'name' => 'Search query',
  11. 'type' => 'text',
  12. 'required' => true,
  13. 'title' => 'Insert your search term here',
  14. 'exampleValue' => 'Enter your search term'
  15. ),
  16. 'queryextension' => array(
  17. 'name' => 'Query extension',
  18. 'type' => 'text',
  19. 'requied' => false,
  20. 'title' => 'Insert additional query parts here
  21. (anything after ?search=<your search query>)',
  22. 'exampleValue' => '&explicit=1&locationQuery=2921044'
  23. ),
  24. 'showimage' => array(
  25. 'name' => 'Show image in content',
  26. 'type' => 'checkbox',
  27. 'requrired' => false,
  28. 'title' => 'Activate to show the image in the content',
  29. 'defaultValue' => false
  30. )
  31. )
  32. );
  33. public function collectData(){
  34. $html = getSimpleHTMLDOM($this->getURI())
  35. or returnServerError('Failed to receive ' . $this->getURI());
  36. $results = $html->find('div.block-grid-item');
  37. foreach($results as $result) {
  38. // Skip banner cards (ads for categories)
  39. if($result->find('a.banner-card'))
  40. continue;
  41. $item = array();
  42. $item['title'] = $result->find('a', 0)->title;
  43. $item['uri'] = $result->find('a', 0)->href;
  44. $item['author'] = $result->find('div.card-shop-name', 0)->plaintext;
  45. $item['content'] = '<p>'
  46. . $result->find('div.card-price', 0)->plaintext
  47. . '</p><p>'
  48. . $result->find('div.card-title', 0)->plaintext
  49. . '</p>';
  50. $image = $result->find('img.placeholder', 0)->src;
  51. if($this->getInput('showimage')) {
  52. $item['content'] .= '<img src="' . $image . '">';
  53. }
  54. $item['enclosures'] = array($image);
  55. $this->items[] = $item;
  56. }
  57. }
  58. public function getURI(){
  59. if(!is_null($this->getInput('query'))) {
  60. $uri = self::URI . '/search?q=' . urlencode($this->getInput('query'));
  61. if(!is_null($this->getInput('queryextension'))) {
  62. $uri .= $this->getInput('queryextension');
  63. }
  64. return $uri;
  65. }
  66. return parent::getURI();
  67. }
  68. }