Changeset 536232
- Timestamp:
- 04/25/2012 02:44:18 PM (14 years ago)
- Location:
- cs-shop/trunk
- Files:
-
- 1 added
- 8 edited
-
cs-shop-options.php (modified) (1 diff)
-
cs-shop.php (modified) (5 diffs)
-
function-view.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
-
service-amazon.php (modified) (17 diffs)
-
service-base.php (modified) (5 diffs)
-
service-rakuten.php (modified) (10 diffs)
-
service-yahoo.php (added)
-
service.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cs-shop/trunk/cs-shop-options.php
r530738 r536232 18 18 "シークレットアクセスキー" => "csshop_amazon_secret_id", 19 19 "アソシエイトID" => "csshop_amazon_assoc" 20 ), 21 "Yahoo!ショッピング" => array( 22 "アプリケーションID" => "csshop_yahoo_appid", 23 "アフィリエイトID" => "csshop_yahoo_affiliate_id" 20 24 ) 21 25 ); -
cs-shop/trunk/cs-shop.php
r535926 r536232 4 4 Plugin URI: http://www.csync.net/category/blog/wp-plugin/cs-shop/ 5 5 Description: You can easily create a product search page from the affiliate services of Japan. 6 Version: 0.9. 5.36 Version: 0.9.6 7 7 Author: cottonspace 8 8 Author URI: http://www.csync.net/ … … 29 29 * プラグインのバージョン 30 30 */ 31 define('CS_SHOP_VER', '0.9. 5.3');31 define('CS_SHOP_VER', '0.9.6'); 32 32 33 33 /** … … 35 35 */ 36 36 define('CS_SHOP_URL', parse_url(WP_PLUGIN_URL, PHP_URL_PATH) . "/cs-shop"); 37 38 /** 39 * 開発・デバッグ用の設定 40 */ 41 ini_set('display_errors', 1); 42 ini_set('error_reporting', E_ALL); 37 43 38 44 /** … … 96 102 )); 97 103 break; 104 case "yahoo": 105 106 // Yahoo!ショッピング 107 require_once 'service-yahoo.php'; 108 $service = new Yahoo(array( 109 "appid" 110 => get_option("csshop_yahoo_appid"), 111 "affiliate_id" 112 => get_option("csshop_yahoo_affiliate_id") 113 )); 114 break; 98 115 default: 99 116 … … 112 129 } 113 130 131 // ページサイズ値の補正 132 if (!isset($params["pagesize"]) || empty($params["pagesize"])) { 133 $params["pagesize"] = "10"; 134 } 135 136 // 商品検索条件の設定 137 $service->setRequestParams($params); 138 114 139 // 商品検索実行 115 $items = $service->getItems( $params);140 $items = $service->getItems(); 116 141 117 142 // 検索フォーム表示 -
cs-shop/trunk/function-view.php
r534388 r536232 118 118 } 119 119 } else { 120 $output .= "<option value=\"" . o_escape($current) . "\"> 変更しない</option>\n";120 $output .= "<option value=\"" . o_escape($current) . "\">選択中のカテゴリ</option>\n"; 121 121 } 122 122 $output .= "<option value=\"\">すべてのカテゴリ</option>\n"; … … 131 131 * 並び替え方法選択用ドロップダウンリスト 132 132 * @param object $service サービス情報 133 * @param string $category 現在のカテゴリ134 133 * @param string $current 現在の並び替え方法 135 134 * @return string 出力コンテンツ 136 135 */ 137 function showSortTypeSelector(&$service, $c ategory, $current)136 function showSortTypeSelector(&$service, $current) 138 137 { 139 138 // 出力コンテンツ … … 156 155 157 156 // 対応している並び替え方法の取得 158 $supportTypes = $service->getSortTypes( $category);157 $supportTypes = $service->getSortTypes(); 159 158 160 159 // 並び替え方法の表示 161 160 $output .= "<select name=\"sort\" onchange=\"submit();\">\n"; 162 $output .= "<option value=\"\"> 指定なし</option>\n";161 $output .= "<option value=\"\">並び順の指定なし</option>\n"; 163 162 foreach ($supportTypes as $k1 => $v1) { 164 163 $selected = ($current == $k1) ? " selected" : ""; … … 235 234 236 235 // 並び替え方法変更リストの表示 237 $output .= showSortTypeSelector($service, $params[" category"], $params["sort"]);236 $output .= showSortTypeSelector($service, $params["sort"]); 238 237 239 238 // 検索フォームの終了 -
cs-shop/trunk/readme.txt
r535926 r536232 4 4 Requires at least: 3.0 5 5 Tested up to: 3.0 6 Stable tag: 0.9. 5.36 Stable tag: 0.9.6 7 7 8 8 You can easily create a product search page from the affiliate services of Japan. … … 29 29 30 30 == Changelog == 31 32 = 0.9.6 = 33 * Add support Yahoo! Shopping API. 31 34 32 35 = 0.9.5.3 = … … 60 63 61 64 == Upgrade Notice == 65 66 = 0.9.6 = 67 Support Yahoo! Shopping. 62 68 63 69 = 0.9.5.3 = -
cs-shop/trunk/service-amazon.php
r534388 r536232 17 17 { 18 18 /** 19 * 商品検索ページ総数20 * @var int 商品検索ページ総数21 */22 private $pageCount;23 24 /**25 19 * SearchIndex定義 26 20 * @var array SearchIndex定義 … … 428 422 return explode(',', $category, 2); 429 423 } else { 430 if (array_key_exists($category, $this->search_indexes)) { 431 $nodeid = $this->search_indexes[$category]["browse"]; 432 return array($category, $nodeid); 424 $search_index = $category; 425 if (array_key_exists($search_index, $this->search_indexes)) { 426 $node_id = $this->search_indexes[$search_index]["browse"]; 427 return array($search_index, $node_id); 433 428 } 434 429 } … … 439 434 * カテゴリ検索クエリ生成 440 435 * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html 441 * @param string $ parent 対象カテゴリ436 * @param string $node_id 対象カテゴリ(BrowseNode) 442 437 * @return array クエリ情報(署名されていないRESTクエリ文字列,署名されたRESTクエリ文字列) 443 438 */ 444 private function queryCategories($ parent)439 private function queryCategories($node_id) 445 440 { 446 441 // クエリ生成 … … 452 447 $params["Version"] = "2009-07-01"; 453 448 $params["Operation"] = "BrowseNodeLookup"; 454 $params["BrowseNodeId"] = $ parent;449 $params["BrowseNodeId"] = $node_id; 455 450 ksort($params); 456 451 $no_signed_query = $this->http_build_query_3986($params); … … 465 460 * 商品検索クエリ生成 466 461 * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html 467 * @param array $search 商品検索条件468 462 * @return string RESTクエリ文字列 469 463 */ 470 private function queryItems( &$search)464 private function queryItems() 471 465 { 472 466 // カテゴリ情報を分割 473 $category_array = $this->parseCategory($ search["category"]);467 $category_array = $this->parseCategory($this->requests["category"]); 474 468 475 469 // クエリ生成 … … 484 478 485 479 // ページ番号の指定(Amazon のページサイズは10固定) 486 if (!empty($ search["page"])) {487 $params["ItemPage"] = $ search["page"];480 if (!empty($this->requests["page"])) { 481 $params["ItemPage"] = $this->requests["page"]; 488 482 } 489 483 … … 493 487 // SearchIndex が All の場合は Keywords のみ指定可能 494 488 $params["SearchIndex"] = "All"; 495 if (!empty($ search["keyword"])) {496 $params["Keywords"] = $ search["keyword"];489 if (!empty($this->requests["keyword"])) { 490 $params["Keywords"] = $this->requests["keyword"]; 497 491 } 498 492 } else { … … 503 497 504 498 // 並び替えの設定 505 $sort_types = $this->getSortTypes( $category_array[0]);506 if (array_key_exists($ search["sort"], $sort_types)) {507 $params["Sort"] = $sort_types[$ search["sort"]];499 $sort_types = $this->getSortTypes(); 500 if (array_key_exists($this->requests["sort"], $sort_types)) { 501 $params["Sort"] = $sort_types[$this->requests["sort"]]; 508 502 } 509 503 … … 513 507 } 514 508 foreach ($extend_params as $k => $v) { 515 if (!empty($ search[$k])) {516 $params[$v] = $ search[$k];509 if (!empty($this->requests[$k])) { 510 $params[$v] = $this->requests[$k]; 517 511 } 518 512 } … … 538 532 /** 539 533 * 商品検索ソート方法取得 540 * @param string $category 選択カテゴリ541 534 * @return array ソート指定の連想配列 542 535 */ 543 public function getSortTypes( $category = "")536 public function getSortTypes() 544 537 { 545 538 // カテゴリ情報を分割 546 $category_array = $this->parseCategory($ category);539 $category_array = $this->parseCategory($this->requests["category"]); 547 540 548 541 // SearchIndexを取得 … … 559 552 560 553 /** 561 * 商品検索ページ総数562 * @return int 商品検索ページ総数563 */564 public function getPageCount()565 {566 return $this->pageCount;567 }568 569 /**570 554 * カテゴリ検索 571 555 * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html 572 * @param string $ parent基底カテゴリ556 * @param string $category 基底カテゴリ 573 557 * @return array カテゴリ情報の連想配列 574 558 */ 575 public function getCategories($ parent= "")559 public function getCategories($category = "") 576 560 { 577 561 // カテゴリ情報を分割 578 $category_array = $this->parseCategory($ parent);562 $category_array = $this->parseCategory($category); 579 563 580 564 // ブラウズノードを取得 581 $node id = $category_array[1];565 $node_id = $category_array[1]; 582 566 583 567 // Amazon はルートカテゴリが存在しないため定義情報から取得 584 if (empty($node id)) {568 if (empty($node_id)) { 585 569 $hash = array(); 586 570 foreach ($this->search_indexes as $search_index_name => $search_index_hash) { … … 591 575 592 576 // RESTクエリ情報を取得 593 $queries = $this->queryCategories($node id);577 $queries = $this->queryCategories($node_id); 594 578 595 579 // RESTクエリ実行 … … 597 581 $objxml = simplexml_load_string($strxml); 598 582 $hash = array(); 599 if (isset($objxml->BrowseNodes->BrowseNode )) {583 if (isset($objxml->BrowseNodes->BrowseNode->Children)) { 600 584 foreach ($objxml->BrowseNodes->BrowseNode->Children->BrowseNode as $node) { 601 585 $hash[$category_array[0] . ',' . (string)$node->BrowseNodeId] = (string)$node->Name; … … 608 592 * 商品検索 609 593 * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html 610 * @param array $search 商品検索条件611 594 * @return array 商品情報の連想配列 612 595 */ 613 public function getItems( &$search)596 public function getItems() 614 597 { 615 598 // RESTクエリ情報を取得 616 $queries = $this->queryItems( $search);599 $queries = $this->queryItems(); 617 600 618 601 // RESTクエリ実行 … … 621 604 $hash = array(); 622 605 if (isset($objxml->Items)) { 623 $this->page Count= min(intval($objxml->Items->TotalPages), (($objxml->Items->Request->ItemSearchRequest->SearchIndex == "All") ? 5 : 10));606 $this->pages = min(intval($objxml->Items->TotalPages), (($objxml->Items->Request->ItemSearchRequest->SearchIndex == "All") ? 5 : 10)); 624 607 foreach ($objxml->Items->Item as $node) { 625 608 array_push($hash, array( … … 629 612 array( 630 613 "ASIN: " . (string)$node->ASIN, 631 (string) $node->ItemAttributes->Manufacturer,632 str_replace(array("\r", "\n", " ", " "), " ", strip_tags((string) $node->ItemAttributes->Feature)),633 str_replace(array("\r", "\n", " ", " "), " ", strip_tags((string) $node->EditorialReviews->EditorialReview->Content))614 (string)@$node->ItemAttributes->Manufacturer, 615 str_replace(array("\r", "\n", " ", " "), " ", strip_tags((string)@$node->ItemAttributes->Feature)), 616 str_replace(array("\r", "\n", " ", " "), " ", strip_tags((string)@$node->EditorialReviews->EditorialReview->Content)) 634 617 ) 635 618 ), 636 619 "shop" => "Amazon.co.jp", 637 "score" => floatval((string) $node->CustomerReviews->AverageRating), // 現在は AverageRating は存在しない620 "score" => floatval((string)@$node->CustomerReviews->AverageRating), // 現在は AverageRating は存在しない 638 621 "aurl" => (string)$node->DetailPageURL, 639 "iurl" => empty($ search["mobile"]) ? (string)$node->MediumImage->URL : (string)$node->SmallImage->URL,622 "iurl" => empty($this->requests["mobile"]) ? (string)$node->MediumImage->URL : (string)$node->SmallImage->URL, 640 623 "surl" => "http://www.amazon.co.jp/" 641 624 ) … … 643 626 } 644 627 } else { 645 $this->page Count= 0;628 $this->pages = 0; 646 629 } 647 630 return $hash; -
cs-shop/trunk/service-base.php
r534388 r536232 28 28 29 29 /** 30 * 商品検索条件 31 * @var array 商品検索条件の連想配列 32 */ 33 protected $requests; 34 35 /** 30 36 * キャッシュオブジェクト 31 37 * @var object キャッシュオブジェクト 32 38 */ 33 39 protected $cache; 40 41 /** 42 * 商品検索ページ総数 43 * @var int 商品検索ページ総数 44 */ 45 protected $pages; 34 46 35 47 /** … … 107 119 108 120 /** 121 * 商品検索条件の設定 122 * @param array $params 商品検索条件 123 */ 124 public function setRequestParams(&$params) 125 { 126 $this->requests = $params; 127 } 128 129 /** 109 130 * サービス識別名 110 131 * @return string サービス識別名 … … 126 147 /** 127 148 * 商品検索ソート方法取得 128 * @param string $category 検索対象のカテゴリ名129 149 * @return array ソート指定の連想配列 130 150 */ 131 public function getSortTypes( $category = "")151 public function getSortTypes() 132 152 { 133 153 return array(); … … 140 160 public function getPageCount() 141 161 { 142 return 0;162 return $this->pages; 143 163 } 144 164 145 165 /** 146 166 * カテゴリ検索 147 * @param string $ parent基底カテゴリ167 * @param string $category 基底カテゴリ 148 168 * @return array カテゴリ情報の連想配列 149 169 */ 150 public function getCategories($ parent= "")170 public function getCategories($category = "") 151 171 { 152 172 return array(); … … 155 175 /** 156 176 * 商品検索 157 * @param array $search 商品検索条件158 177 * @return array 商品情報の連想配列 159 178 */ 160 public function getItems( &$search)179 public function getItems() 161 180 { 162 181 return array(); -
cs-shop/trunk/service-rakuten.php
r534388 r536232 16 16 class Rakuten extends ServiceBase 17 17 { 18 /**19 * 商品検索ページ総数20 * @var int 商品検索ページ総数21 */22 private $pageCount;23 24 18 /** 25 19 * 商品検索ソート方法 … … 60 54 * カテゴリ検索クエリ生成 61 55 * @link http://webservice.rakuten.co.jp/api/genresearch/ 62 * @param string $ parent対象カテゴリ56 * @param string $category 対象カテゴリ 63 57 * @return string RESTクエリ文字列 64 58 */ 65 private function queryCategories($ parent)66 { 67 if (empty($ parent)) {68 $ parent= 0;59 private function queryCategories($category) 60 { 61 if (empty($category)) { 62 $category = 0; 69 63 } 70 64 $baseurl = "http://api.rakuten.co.jp/rws/3.0/rest"; … … 75 69 $params["version"] = "2007-04-11"; 76 70 $params["genrePath"] = 0; 77 $params["genreId"] = $ parent;71 $params["genreId"] = $category; 78 72 ksort($params); 79 73 return $baseurl . "?" . http_build_query($params); … … 83 77 * 商品検索クエリ生成 84 78 * @link http://webservice.rakuten.co.jp/api/itemsearch/ 85 * @param array $search 商品検索条件86 79 * @return string RESTクエリ文字列 87 80 */ 88 private function queryItems( &$search)81 private function queryItems() 89 82 { 90 83 $baseurl = "http://api.rakuten.co.jp/rws/3.0/rest"; … … 94 87 $params["operation"] = "ItemSearch"; 95 88 $params["version"] = "2010-09-15"; 96 $params["hits"] = empty($search["pagesize"]) ? 10 : $search["pagesize"];89 $params["hits"] = $this->requests["pagesize"]; 97 90 $params["availability"] = 1; 98 91 $params["field"] = 1; 99 $params["carrier"] = empty($ search["mobile"]) ? 0 : 1;92 $params["carrier"] = empty($this->requests["mobile"]) ? 0 : 1; 100 93 $params["imageFlag"] = 1; 101 94 $params["purchaseType"] = 0; 102 $params["genreId"] = empty($ search["category"]) ? "0" : $search["category"];103 if (!empty($ search["keyword"])) {104 $params["keyword"] = $ search["keyword"];105 } 106 if (!empty($ search["shop"])) {107 $params["shopCode"] = $ search["shop"];108 } 109 if (!empty($ search["sort"]) && array_key_exists($search["sort"], $this->sortTypes)) {110 $params["sort"] = $this->sortTypes[$ search["sort"]];95 $params["genreId"] = empty($this->requests["category"]) ? "0" : $this->requests["category"]; 96 if (!empty($this->requests["keyword"])) { 97 $params["keyword"] = $this->requests["keyword"]; 98 } 99 if (!empty($this->requests["shop"])) { 100 $params["shopCode"] = $this->requests["shop"]; 101 } 102 if (!empty($this->requests["sort"]) && array_key_exists($this->requests["sort"], $this->sortTypes)) { 103 $params["sort"] = $this->sortTypes[$this->requests["sort"]]; 111 104 } else { 112 105 $params["sort"] = "standard"; 113 106 } 114 $params["page"] = $ search["page"];107 $params["page"] = $this->requests["page"]; 115 108 ksort($params); 116 109 return $baseurl . "?" . http_build_query($params); … … 142 135 /** 143 136 * 商品検索ソート方法取得 144 * @param string $category 検索対象のカテゴリ名145 137 * @return array ソート指定の連想配列 146 138 */ 147 public function getSortTypes( $category = "")139 public function getSortTypes() 148 140 { 149 141 return $this->sortTypes; 150 }151 152 /**153 * 商品検索ページ総数154 * @return int 商品検索ページ総数155 */156 public function getPageCount()157 {158 return $this->pageCount;159 142 } 160 143 … … 162 145 * カテゴリ検索 163 146 * @link http://webservice.rakuten.co.jp/api/genresearch/ 164 * @param string $ parent基底カテゴリ147 * @param string $category 基底カテゴリ 165 148 * @return array カテゴリ情報の連想配列 166 149 */ 167 public function getCategories($ parent= "")168 { 169 if (empty($ parent)) {170 $ parent= 0;150 public function getCategories($category = "") 151 { 152 if (empty($category)) { 153 $category = 0; 171 154 } 172 155 173 156 // RESTクエリ情報を取得 174 $query = $this->queryCategories($ parent);157 $query = $this->queryCategories($category); 175 158 176 159 // RESTクエリ実行 … … 191 174 * 商品検索 192 175 * @link http://webservice.rakuten.co.jp/api/itemsearch/ 193 * @param array $search 商品検索条件194 176 * @return array 商品情報の連想配列 195 177 */ 196 public function getItems( &$search)178 public function getItems() 197 179 { 198 180 // RESTクエリ情報を取得 199 $query = $this->queryItems( $search);181 $query = $this->queryItems(); 200 182 201 183 // RESTクエリ実行 … … 206 188 $hash = array(); 207 189 if (isset($objxml->Body->ItemSearch)) { 208 $this->page Count= intval($objxml->Body->ItemSearch->pageCount);190 $this->pages = intval($objxml->Body->ItemSearch->pageCount); 209 191 foreach ($objxml->Body->ItemSearch->Items->Item as $node) { 210 192 array_push($hash, array( … … 213 195 "desc" => (string)$node->itemCaption, 214 196 "shop" => (string)$node->shopName, 215 "score" => floatval((string)$node->reviewAverage),197 "score" => floatval((string)$node->reviewAverage), 216 198 "aurl" => (string)$node->affiliateUrl, 217 "iurl" => empty($ search["mobile"]) ? (string)$node->mediumImageUrl : (string)$node->smallImageUrl,199 "iurl" => empty($this->requests["mobile"]) ? (string)$node->mediumImageUrl : (string)$node->smallImageUrl, 218 200 "surl" => (string)$node->shopUrl) 219 201 ); 220 202 } 221 203 } else { 222 $this->page Count= 0;204 $this->pages = 0; 223 205 } 224 206 return $hash; -
cs-shop/trunk/service.php
r534388 r536232 15 15 16 16 /** 17 * 商品検索条件の設定 18 * @param array $params 商品検索条件 19 */ 20 public function setRequestParams(&$params); 21 22 /** 17 23 * サービス識別名 18 24 * @return string サービス識別名 … … 28 34 /** 29 35 * 商品検索ソート方法取得 30 * @param string $category 検索対象のカテゴリ名31 36 * @return array ソート指定の連想配列 32 37 */ 33 public function getSortTypes( $category = "");38 public function getSortTypes(); 34 39 35 40 /** … … 41 46 /** 42 47 * カテゴリ検索 43 * @param string $ parent基底カテゴリ48 * @param string $category 基底カテゴリ 44 49 * @return array カテゴリ情報の連想配列 45 50 */ 46 public function getCategories($ parent= "");51 public function getCategories($category = ""); 47 52 48 53 /** 49 54 * 商品検索 50 * @param array $search 商品検索条件51 55 * @return array 商品情報の連想配列 52 56 */ 53 public function getItems( &$search);57 public function getItems(); 54 58 } 55 59
Note: See TracChangeset
for help on using the changeset viewer.