From 877465d50854588b890e57e0b872093c20fb18ff Mon Sep 17 00:00:00 2001 From: Alexis CHEMEL Date: Tue, 6 Dec 2016 17:44:56 +0100 Subject: [PATCH] AmazonBridge --- bridges/AmazonBridge.php | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bridges/AmazonBridge.php diff --git a/bridges/AmazonBridge.php b/bridges/AmazonBridge.php new file mode 100644 index 0000000..52e5f11 --- /dev/null +++ b/bridges/AmazonBridge.php @@ -0,0 +1,69 @@ + array( + 'name' => 'Keyword', + 'required' => true, + ), + 'sort' => array( + 'name' => 'Sort by', + 'type' => 'list', + 'required' => false, + 'values' => array( + 'Pertinence' => 'relevanceblender', + 'Popularité' => 'popularity-rank', + 'Prix : par ordre croissant' => 'price-asc-rank', + 'Prix : par ordre décroissant' => 'price-desc-rank', + 'Note moyenne des commentaires' => 'review-rank', + 'Dernières nouveautés' => 'date-desc-rank', + ), + 'defaultValue' => 'popularity-rank', + ) + )); + + public function getName(){ + + return 'Amazon - '.$this->getInput('q'); + } + + public function collectData() { + + $url = self::URI.'s/?field-keywords='.urlencode($this->getInput('q')).'&sort='.$this->getInput('sort'); + + $html = getSimpleHTMLDOM($url) + or returnServerError('Could not request Amazon.'); + + foreach($html->find('li.s-result-item') as $element) { + + $item = array(); + + // Title + $title = $element->find('h2', 0); + + $item['title'] = html_entity_decode($title->innertext, ENT_QUOTES); + + // Url + $uri = $title->parent()->getAttribute('href'); + $uri = substr($uri, 0, strrpos($uri, '/')); + + $item['uri'] = substr($uri, 0, strrpos($uri, '/')); + + // Content + $image = $element->find('img', 0); + $price = $element->find('span.s-price', 0); + $price = ($price) ? $price->innertext : ''; + + $item['content'] = '
'.$price; + + $this->items[] = $item; + } + } +}