From c2af480c157a7e35bf1532aa21b5edc436ad1577 Mon Sep 17 00:00:00 2001 From: Ethan Clevenger Date: Fri, 1 Jan 2016 20:22:57 -0600 Subject: [PATCH 1/4] added composer.json --- .gitignore | 1 + composer.json | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..20fa4c8 --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "ethanclevenger91/amazon-wish-lister", + "description": "\u001b[2~Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/", + "authors": [ + { + "name": "Justin Scarpetti", + "homepage": "http://www.justinscarpetti.com/" + } + ], + "require": {} +} From 38712b4ad7d3f304284f93498d47206558d7c3ff Mon Sep 17 00:00:00 2001 From: Ethan Clevenger Date: Fri, 1 Jan 2016 20:24:07 -0600 Subject: [PATCH 2/4] updated author information --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 20fa4c8..3b55679 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "ethanclevenger91/amazon-wish-lister", - "description": "\u001b[2~Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/", + "name": "doitlikejustin/amazon-wish-lister", + "description": "Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/", "authors": [ { "name": "Justin Scarpetti", From c15f720cbcfca0e57f1c4fb416acc79233d49b0e Mon Sep 17 00:00:00 2001 From: Ethan Clevenger Date: Sun, 17 Jan 2016 18:52:11 -0600 Subject: [PATCH 3/4] added isbn and author functionality --- composer.json | 4 +- src/phpquery.php | 44 ++++++++++----------- src/wishlist.php | 101 +++++++++++++++++++++++++++++------------------ 3 files changed, 87 insertions(+), 62 deletions(-) diff --git a/composer.json b/composer.json index 20fa4c8..3b55679 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "ethanclevenger91/amazon-wish-lister", - "description": "\u001b[2~Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/", + "name": "doitlikejustin/amazon-wish-lister", + "description": "Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/", "authors": [ { "name": "Justin Scarpetti", diff --git a/src/phpquery.php b/src/phpquery.php index 708b7a3..b8476aa 100644 --- a/src/phpquery.php +++ b/src/phpquery.php @@ -280,7 +280,7 @@ protected function loadMarkupHTML($markup, $requestedCharset = null) { // @see http://www.w3.org/International/O-HTTP-charset if (! $documentCharset) { $documentCharset = 'ISO-8859-1'; - $addDocumentCharset = true; + $addDocumentCharset = true; } // Should be careful here, still need 'magic encoding detection' since lots of pages have other 'default encoding' // Worse, some pages can have mixed encodings... we'll try not to worry about that @@ -567,7 +567,7 @@ public function import($source, $sourceCharset = null) { // if ($fake === false) // throw new Exception("Error loading documentFragment markup"); // else -// $return = array_merge($return, +// $return = array_merge($return, // $this->import($fake->root->childNodes) // ); // } else { @@ -969,24 +969,24 @@ function getName(); } /** * Callback class introduces currying-like pattern. - * + * * Example: * function foo($param1, $param2, $param3) { * var_dump($param1, $param2, $param3); * } - * $fooCurried = new Callback('foo', - * 'param1 is now statically set', + * $fooCurried = new Callback('foo', + * 'param1 is now statically set', * new CallbackParam, new CallbackParam * ); * phpQuery::callbackRun($fooCurried, * array('param2 value', 'param3 value' * ); - * - * Callback class is supported in all phpQuery methods which accepts callbacks. + * + * Callback class is supported in all phpQuery methods which accepts callbacks. * * @link http://code.google.com/p/phpquery/wiki/Callbacks#Param_Structures * @author Tobiasz Cudnik - * + * * @TODO??? return fake forwarding function created via create_function * @TODO honor paramStructure */ @@ -995,7 +995,7 @@ class Callback public $callback = null; public $params = null; protected $name; - public function __construct($callback, $param1 = null, $param2 = null, + public function __construct($callback, $param1 = null, $param2 = null, $param3 = null) { $params = func_get_args(); $params = array_slice($params, 1); @@ -1024,11 +1024,11 @@ public function setName($name) { } /** * Shorthand for new Callback(create_function(...), ...); - * + * * @author Tobiasz Cudnik */ class CallbackBody extends Callback { - public function __construct($paramList, $code, $param1 = null, $param2 = null, + public function __construct($paramList, $code, $param1 = null, $param2 = null, $param3 = null) { $params = func_get_args(); $params = array_slice($params, 2); @@ -1038,7 +1038,7 @@ public function __construct($paramList, $code, $param1 = null, $param2 = null, } /** * Callback type which on execution returns reference passed during creation. - * + * * @author Tobiasz Cudnik */ class CallbackReturnReference extends Callback @@ -1060,7 +1060,7 @@ public function hasName() { } /** * Callback type which on execution returns value passed during creation. - * + * * @author Tobiasz Cudnik */ class CallbackReturnValue extends Callback @@ -1087,7 +1087,7 @@ public function hasName() { } /** * CallbackParameterToReference can be used when we don't really want a callback, - * only parameter passed to it. CallbackParameterToReference takes first + * only parameter passed to it. CallbackParameterToReference takes first * parameter's value and passes it to reference. * * @author Tobiasz Cudnik @@ -1095,7 +1095,7 @@ public function hasName() { class CallbackParameterToReference extends Callback { /** * @param $reference - * @TODO implement $paramIndex; + * @TODO implement $paramIndex; * param index choose which callback param will be passed to reference */ public function __construct(&$reference){ @@ -2994,7 +2994,7 @@ public function php($code = null) { } /** * Enter description here... - * + * * @param $code * @return unknown_type */ @@ -3005,7 +3005,7 @@ public function markupPHP($code = null) { } /** * Enter description here... - * + * * @param $code * @return unknown_type */ @@ -4034,7 +4034,7 @@ public function map($callback, $param1 = null, $param2 = null, $param3 = null) { } /** * Enter description here... - * + * * @param $key * @param $value */ @@ -4051,7 +4051,7 @@ public function data($key, $value = null) { } /** * Enter description here... - * + * * @param $key */ public function removeData($key) { @@ -4392,8 +4392,8 @@ function mb_substr_count($haystack, $needle) */ abstract class phpQuery { /** - * XXX: Workaround for mbstring problems - * + * XXX: Workaround for mbstring problems + * * @var bool */ public static $mbstringSupport = true; @@ -5699,4 +5699,4 @@ function pq($arg1, $context = null) { phpQuery::$plugins = new phpQueryPlugins(); // include bootstrap file (personal library config) if (file_exists(dirname(__FILE__).'/phpQuery/bootstrap.php')) - require_once dirname(__FILE__).'/phpQuery/bootstrap.php'; \ No newline at end of file + require_once dirname(__FILE__).'/phpQuery/bootstrap.php'; diff --git a/src/wishlist.php b/src/wishlist.php index d2b5f94..d3f344a 100644 --- a/src/wishlist.php +++ b/src/wishlist.php @@ -5,12 +5,12 @@ * * URL: http://www.justinscarpetti.com/projects/amazon-wish-lister/ * URL: https://github.com/doitlikejustin/amazon-wish-lister - * + * * Author: Justin Scarpetti - * + * */ -// error_reporting(0); -set_time_limit(60); +error_reporting(E_ERROR); +set_time_limit(300); require_once('phpquery.php'); //?id=YOUR_AMAZON_ID @@ -21,7 +21,7 @@ //?tld=AMAZON_COUNTRY //Set the regional variant of Amazon to use. e.g `?tld=co.uk` or `?tld=de` or ?tld=com`. Defaults to `com` //Tested with: `ca`, `com`, `com.br`, `co.jp`, `co.uk`, `de`, `fr`, `in`, `it` -//Currently no wishlists available for: `com.au`, `com.mx`, `es`, `nl` +//Currently no wishlists available for: `com.au`, `com.mx`, `es`, `nl` if(isset($_GET['tld'])) $amazon_country = $_GET['tld']; else $amazon_country = 'com'; @@ -69,14 +69,14 @@ { $pages = count(pq('#wishlistPagination li[data-action="pag-trigger"]')); } - + //if no "$pages" then only 1 page exists if(empty($pages)) $pages=1; - + for($page_num=1; $page_num<=$pages; $page_num++) { $contents = phpQuery::newDocumentFile("$baseurl/registry/wishlist/$amazon_id?$reveal&$sort&layout=standard&page=$page_num"); - + if($contents == '') { echo('ERROR'); @@ -85,18 +85,18 @@ else { //get all items - $items = pq('tbody.itemWrapper'); - + $items = pq('tbody.itemWrapper'); + //if items exist (the let's use the old Amazon wishlist if($items->html()) { //loop through items foreach($items as $item) { - $check_if_regular = pq($item)->find('span.commentBlock nobr'); - + $check_if_regular = pq($item)->find('span.commentBlock nobr'); + if($check_if_regular != '') - { + { //$array[$i]['array'] = pq($item)->html(); $array[$i]['num'] = $i + 1; $array[$i]['name'] = text_prepare(pq($item)->find('span.productTitle strong a')->html()); @@ -113,7 +113,13 @@ $array[$i]['ASIN'] = get_ASIN($array[$i]['link']); $array[$i]['large-ssl-image'] = get_large_ssl_image($array[$i]['picture']); $array[$i]['affiliate-url'] = get_affiliate_link($array[$i]['ASIN']); - + if($_GET['isbn'] == true) { + $array[$i]['isbn'] = get_ISBN($array[$i]['link']); + } + if($_GET['author'] == true) { + $array[$i]['author'] = get_Author($array[$i]['link']); + } + $i++; } } @@ -123,19 +129,19 @@ else { $items = pq('.g-items-section div[id^="item_"]'); - + //loop through items foreach($items as $item) { $name = htmlentities(trim(pq($item)->find('a[id^="itemName_"]')->html())); $link = pq($item)->find('a[id^="itemName_"]')->attr('href'); - + if(!empty($name) && !empty($link)) { $total_ratings = pq($item)->find('div[id^="itemInfo_"] div:a-spacing-small:first a.a-link-normal:last')->html(); $total_ratings = trim(str_replace(array('(', ')'), '', $total_ratings)); $total_ratings = is_numeric($total_ratings) ? $total_ratings : ''; - + //$array[$i]['array'] = pq($item)->html(); $array[$i]['num'] = $i + 1; $array[$i]['name'] = $name; @@ -152,24 +158,43 @@ $array[$i]['ASIN'] = get_ASIN($array[$i]['link']); $array[$i]['large-ssl-image'] = get_large_ssl_image($array[$i]['picture']); $array[$i]['affiliate-url'] = get_affiliate_link($array[$i]['ASIN']); - + if($_GET['isbn'] == true) { + $array[$i]['isbn'] = get_ISBN($array[$i]['link']); + } + if($_GET['author'] == true) { + $array[$i]['author'] = pq($item)->find('div[id^="itemInfo_"] .a-row.a-size-small:has(h5 a[id^="itemName_"])'); + $array[$i]['author']->find('h5')->remove(); + $array[$i]['author'] = trim(preg_replace('/\([\ \w]+\)/', '', str_replace('by', '', $array[$i]['author']->text()))); + } + $i++; } } } - } + } } } +//go to product details page for isbn +function get_ISBN($url) { + $productPage = phpQuery::newDocumentFile($url); + return trim(str_replace("ISBN-13:", "", text_prepare(pq($productPage)->find('.bucket .content li:has(b:contains("ISBN-13"))')->text()))); +} + +function get_Author($url) { + $productPage = phpQuery::newDocumentFile($url); + return trim(str_replace('(Author)', '', text_prepare(pq($productPage)->find('#byline .author .a-popover-preload .a-size-medium')->text()))); +} + //format the xml (old style) function xml_ecode($array) { $xml = ''; if (is_array($array) || is_object($array)) { foreach ($array as $key=>$value) { if (is_numeric($key)) { - $key = 'item'; + $key = 'item'; } - + //create the xml tags $xml .= '<' . $key . '>' . xml_ecode($value) . ''; } @@ -180,9 +205,9 @@ function xml_ecode($array) { //Convert an array into valid XML //From http://stackoverflow.com/a/5965940/1127699 function xml_encode($data, &$xml_data) { - foreach( $data as $key => $value ) + foreach( $data as $key => $value ) { - if( is_array($value) ) + if( is_array($value) ) { if( is_numeric($key) ) { @@ -217,9 +242,9 @@ function rss_encode($data) { en-gb '.$pubDate.''; - foreach( $data as $key => $value ) + foreach( $data as $key => $value ) { - if( is_array($value) ) + if( is_array($value) ) { $rss .= ' '.$value['comment'].' '.$value['new-price'] .' @@ -278,7 +303,7 @@ function get_ASIN($url) { function get_large_ssl_image($image_url) { /* - Change + Change http://ecx.images-amazon.com/images/I/41kWB4Z4PTL._SL250_.jpg To https://images-eu.ssl-images-amazon.com/images/I/41kWB4Z4PTL._SL2500_.jpg @@ -316,27 +341,27 @@ function get_affiliate_link($AISN) { //?format=json //format the wishlist (json, xml, or php array object) defaults to json -if($_REQUEST['format'] == 'json') { +if($_REQUEST['format'] == 'json') { header('Content-Type: application/json; charset=utf-8'); - echo json_encode($array); + echo json_encode($array); } -elseif($_REQUEST['format'] == 'xml') { +elseif($_REQUEST['format'] == 'xml') { header('Content-Type: text/xml; charset=utf-8'); - echo xml_ecode($array); + echo xml_ecode($array); } -elseif($_REQUEST['format'] == 'XML') { +elseif($_REQUEST['format'] == 'XML') { header('Content-Type: text/xml; charset=utf-8'); - echo xml_encode($array, new SimpleXMLElement('')); + echo xml_encode($array, new SimpleXMLElement('')); } -elseif($_REQUEST['format'] == 'array') { +elseif($_REQUEST['format'] == 'array') { header('Content-Type: text/html; charset=utf-8'); - print_r($array); + print_r($array); } -elseif($_REQUEST['format'] == 'rss') { +elseif($_REQUEST['format'] == 'rss') { header('Content-Type: application/rss+xml; charset=utf-8'); - echo rss_encode($array); + echo rss_encode($array); } -else { +else { header('Content-Type: application/json; charset=utf-8'); - echo json_encode($array); + echo json_encode($array); } From f6692c80f84a51e1434edfb4e8d12834cde4441a Mon Sep 17 00:00:00 2001 From: Ethan Clevenger Date: Fri, 19 Feb 2016 17:01:25 -0600 Subject: [PATCH 4/4] updated composer --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3b55679..47b8248 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "doitlikejustin/amazon-wish-lister", - "description": "Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/", + "name": "ethanclevenger91/amazon-wish-lister", + "description": "Retrieve Amazon Wishlist and output to JSON, XML, or PHP Array Object http://www.justinscarpetti.com/portfolio/amazon-wish-lister/. Forked Feb. 2016 to add Author & ISBN cap.", "authors": [ { "name": "Justin Scarpetti",