Plugin Directory

Changeset 536232


Ignore:
Timestamp:
04/25/2012 02:44:18 PM (14 years ago)
Author:
cottonspace
Message:

Add support Yahoo! Shopping API.

Location:
cs-shop/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • cs-shop/trunk/cs-shop-options.php

    r530738 r536232  
    1818        "シークレットアクセスキー" => "csshop_amazon_secret_id",
    1919        "アソシエイトID" => "csshop_amazon_assoc"
     20    ),
     21    "Yahoo!ショッピング" => array(
     22        "アプリケーションID" => "csshop_yahoo_appid",
     23        "アフィリエイトID" => "csshop_yahoo_affiliate_id"
    2024    )
    2125);
  • cs-shop/trunk/cs-shop.php

    r535926 r536232  
    44Plugin URI: http://www.csync.net/category/blog/wp-plugin/cs-shop/
    55Description: You can easily create a product search page from the affiliate services of Japan.
    6 Version: 0.9.5.3
     6Version: 0.9.6
    77Author: cottonspace
    88Author URI: http://www.csync.net/
     
    2929 * プラグインのバージョン
    3030 */
    31 define('CS_SHOP_VER', '0.9.5.3');
     31define('CS_SHOP_VER', '0.9.6');
    3232
    3333/**
     
    3535 */
    3636define('CS_SHOP_URL', parse_url(WP_PLUGIN_URL, PHP_URL_PATH) . "/cs-shop");
     37
     38/**
     39 * 開発・デバッグ用の設定
     40 */
     41ini_set('display_errors', 1);
     42ini_set('error_reporting', E_ALL);
    3743
    3844/**
     
    96102            ));
    97103            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;
    98115        default:
    99116
     
    112129            }
    113130
     131            // ページサイズ値の補正
     132            if (!isset($params["pagesize"]) || empty($params["pagesize"])) {
     133                $params["pagesize"] = "10";
     134            }
     135
     136            // 商品検索条件の設定
     137            $service->setRequestParams($params);
     138
    114139            // 商品検索実行
    115             $items = $service->getItems($params);
     140            $items = $service->getItems();
    116141
    117142            // 検索フォーム表示
  • cs-shop/trunk/function-view.php

    r534388 r536232  
    118118            }
    119119        } else {
    120             $output .= "<option value=\"" . o_escape($current) . "\">変更しない</option>\n";
     120            $output .= "<option value=\"" . o_escape($current) . "\">選択中のカテゴリ</option>\n";
    121121        }
    122122        $output .= "<option value=\"\">すべてのカテゴリ</option>\n";
     
    131131 * 並び替え方法選択用ドロップダウンリスト
    132132 * @param object $service サービス情報
    133  * @param string $category 現在のカテゴリ
    134133 * @param string $current 現在の並び替え方法
    135134 * @return string 出力コンテンツ
    136135 */
    137 function showSortTypeSelector(&$service, $category, $current)
     136function showSortTypeSelector(&$service, $current)
    138137{
    139138    // 出力コンテンツ
     
    156155
    157156    // 対応している並び替え方法の取得
    158     $supportTypes = $service->getSortTypes($category);
     157    $supportTypes = $service->getSortTypes();
    159158
    160159    // 並び替え方法の表示
    161160    $output .= "<select name=\"sort\" onchange=\"submit();\">\n";
    162     $output .= "<option value=\"\">指定なし</option>\n";
     161    $output .= "<option value=\"\">並び順の指定なし</option>\n";
    163162    foreach ($supportTypes as $k1 => $v1) {
    164163        $selected = ($current == $k1) ? " selected" : "";
     
    235234
    236235    // 並び替え方法変更リストの表示
    237     $output .= showSortTypeSelector($service, $params["category"], $params["sort"]);
     236    $output .= showSortTypeSelector($service, $params["sort"]);
    238237
    239238    // 検索フォームの終了
  • cs-shop/trunk/readme.txt

    r535926 r536232  
    44Requires at least: 3.0
    55Tested up to: 3.0
    6 Stable tag: 0.9.5.3
     6Stable tag: 0.9.6
    77
    88You can easily create a product search page from the affiliate services of Japan.
     
    2929
    3030== Changelog ==
     31
     32= 0.9.6 =
     33* Add support Yahoo! Shopping API.
    3134
    3235= 0.9.5.3 =
     
    6063
    6164== Upgrade Notice ==
     65
     66= 0.9.6 =
     67Support Yahoo! Shopping.
    6268
    6369= 0.9.5.3 =
  • cs-shop/trunk/service-amazon.php

    r534388 r536232  
    1717{
    1818    /**
    19      * 商品検索ページ総数
    20      * @var int 商品検索ページ総数
    21      */
    22     private $pageCount;
    23 
    24     /**
    2519     * SearchIndex定義
    2620     * @var array SearchIndex定義
     
    428422            return explode(',', $category, 2);
    429423        } 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);
    433428            }
    434429        }
     
    439434     * カテゴリ検索クエリ生成
    440435     * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html
    441      * @param string $parent 対象カテゴリ
     436     * @param string $node_id 対象カテゴリ(BrowseNode)
    442437     * @return array クエリ情報(署名されていないRESTクエリ文字列,署名されたRESTクエリ文字列)
    443438     */
    444     private function queryCategories($parent)
     439    private function queryCategories($node_id)
    445440    {
    446441        // クエリ生成
     
    452447        $params["Version"] = "2009-07-01";
    453448        $params["Operation"] = "BrowseNodeLookup";
    454         $params["BrowseNodeId"] = $parent;
     449        $params["BrowseNodeId"] = $node_id;
    455450        ksort($params);
    456451        $no_signed_query = $this->http_build_query_3986($params);
     
    465460     * 商品検索クエリ生成
    466461     * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html
    467      * @param array $search 商品検索条件
    468462     * @return string RESTクエリ文字列
    469463     */
    470     private function queryItems(&$search)
     464    private function queryItems()
    471465    {
    472466        // カテゴリ情報を分割
    473         $category_array = $this->parseCategory($search["category"]);
     467        $category_array = $this->parseCategory($this->requests["category"]);
    474468
    475469        // クエリ生成
     
    484478
    485479        // ページ番号の指定(Amazon のページサイズは10固定)
    486         if (!empty($search["page"])) {
    487             $params["ItemPage"] = $search["page"];
     480        if (!empty($this->requests["page"])) {
     481            $params["ItemPage"] = $this->requests["page"];
    488482        }
    489483
     
    493487            // SearchIndex が All の場合は Keywords のみ指定可能
    494488            $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"];
    497491            }
    498492        } else {
     
    503497
    504498            // 並び替えの設定
    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"]];
    508502            }
    509503
     
    513507            }
    514508            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];
    517511                }
    518512            }
     
    538532    /**
    539533     * 商品検索ソート方法取得
    540      * @param string $category 選択カテゴリ
    541534     * @return array ソート指定の連想配列
    542535     */
    543     public function getSortTypes($category = "")
     536    public function getSortTypes()
    544537    {
    545538        // カテゴリ情報を分割
    546         $category_array = $this->parseCategory($category);
     539        $category_array = $this->parseCategory($this->requests["category"]);
    547540
    548541        // SearchIndexを取得
     
    559552
    560553    /**
    561      * 商品検索ページ総数
    562      * @return int 商品検索ページ総数
    563      */
    564     public function getPageCount()
    565     {
    566         return $this->pageCount;
    567     }
    568 
    569     /**
    570554     * カテゴリ検索
    571555     * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html
    572      * @param string $parent 基底カテゴリ
     556     * @param string $category 基底カテゴリ
    573557     * @return array カテゴリ情報の連想配列
    574558     */
    575     public function getCategories($parent = "")
     559    public function getCategories($category = "")
    576560    {
    577561        // カテゴリ情報を分割
    578         $category_array = $this->parseCategory($parent);
     562        $category_array = $this->parseCategory($category);
    579563
    580564        // ブラウズノードを取得
    581         $nodeid = $category_array[1];
     565        $node_id = $category_array[1];
    582566
    583567        // Amazon はルートカテゴリが存在しないため定義情報から取得
    584         if (empty($nodeid)) {
     568        if (empty($node_id)) {
    585569            $hash = array();
    586570            foreach ($this->search_indexes as $search_index_name => $search_index_hash) {
     
    591575
    592576        // RESTクエリ情報を取得
    593         $queries = $this->queryCategories($nodeid);
     577        $queries = $this->queryCategories($node_id);
    594578
    595579        // RESTクエリ実行
     
    597581        $objxml = simplexml_load_string($strxml);
    598582        $hash = array();
    599         if (isset($objxml->BrowseNodes->BrowseNode)) {
     583        if (isset($objxml->BrowseNodes->BrowseNode->Children)) {
    600584            foreach ($objxml->BrowseNodes->BrowseNode->Children->BrowseNode as $node) {
    601585                $hash[$category_array[0] . ',' . (string)$node->BrowseNodeId] = (string)$node->Name;
     
    608592     * 商品検索
    609593     * @link http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/Welcome.html
    610      * @param array $search 商品検索条件
    611594     * @return array 商品情報の連想配列
    612595     */
    613     public function getItems(&$search)
     596    public function getItems()
    614597    {
    615598        // RESTクエリ情報を取得
    616         $queries = $this->queryItems($search);
     599        $queries = $this->queryItems();
    617600
    618601        // RESTクエリ実行
     
    621604        $hash = array();
    622605        if (isset($objxml->Items)) {
    623             $this->pageCount = 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));
    624607            foreach ($objxml->Items->Item as $node) {
    625608                array_push($hash, array(
     
    629612                            array(
    630613                                "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))
    634617                            )
    635618                        ),
    636619                        "shop" => "Amazon.co.jp",
    637                         "score" => floatval((string)$node->CustomerReviews->AverageRating), // 現在は AverageRating は存在しない
     620                        "score" => floatval((string)@$node->CustomerReviews->AverageRating), // 現在は AverageRating は存在しない
    638621                        "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,
    640623                        "surl" => "http://www.amazon.co.jp/"
    641624                    )
     
    643626            }
    644627        } else {
    645             $this->pageCount = 0;
     628            $this->pages = 0;
    646629        }
    647630        return $hash;
  • cs-shop/trunk/service-base.php

    r534388 r536232  
    2828
    2929    /**
     30     * 商品検索条件
     31     * @var array 商品検索条件の連想配列
     32     */
     33    protected $requests;
     34
     35    /**
    3036     * キャッシュオブジェクト
    3137     * @var object キャッシュオブジェクト
    3238     */
    3339    protected $cache;
     40
     41    /**
     42     * 商品検索ページ総数
     43     * @var int 商品検索ページ総数
     44     */
     45    protected $pages;
    3446
    3547    /**
     
    107119
    108120    /**
     121     * 商品検索条件の設定
     122     * @param array $params 商品検索条件
     123     */
     124    public function setRequestParams(&$params)
     125    {
     126        $this->requests = $params;
     127    }
     128
     129    /**
    109130     * サービス識別名
    110131     * @return string サービス識別名
     
    126147    /**
    127148     * 商品検索ソート方法取得
    128      * @param string $category 検索対象のカテゴリ名
    129149     * @return array ソート指定の連想配列
    130150     */
    131     public function getSortTypes($category = "")
     151    public function getSortTypes()
    132152    {
    133153        return array();
     
    140160    public function getPageCount()
    141161    {
    142         return 0;
     162        return $this->pages;
    143163    }
    144164
    145165    /**
    146166     * カテゴリ検索
    147      * @param string $parent 基底カテゴリ
     167     * @param string $category 基底カテゴリ
    148168     * @return array カテゴリ情報の連想配列
    149169     */
    150     public function getCategories($parent = "")
     170    public function getCategories($category = "")
    151171    {
    152172        return array();
     
    155175    /**
    156176     * 商品検索
    157      * @param array $search 商品検索条件
    158177     * @return array 商品情報の連想配列
    159178     */
    160     public function getItems(&$search)
     179    public function getItems()
    161180    {
    162181        return array();
  • cs-shop/trunk/service-rakuten.php

    r534388 r536232  
    1616class Rakuten extends ServiceBase
    1717{
    18     /**
    19      * 商品検索ページ総数
    20      * @var int 商品検索ページ総数
    21      */
    22     private $pageCount;
    23 
    2418    /**
    2519     * 商品検索ソート方法
     
    6054     * カテゴリ検索クエリ生成
    6155     * @link http://webservice.rakuten.co.jp/api/genresearch/
    62      * @param string $parent 対象カテゴリ
     56     * @param string $category 対象カテゴリ
    6357     * @return string RESTクエリ文字列
    6458     */
    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;
    6963        }
    7064        $baseurl = "http://api.rakuten.co.jp/rws/3.0/rest";
     
    7569        $params["version"] = "2007-04-11";
    7670        $params["genrePath"] = 0;
    77         $params["genreId"] = $parent;
     71        $params["genreId"] = $category;
    7872        ksort($params);
    7973        return $baseurl . "?" . http_build_query($params);
     
    8377     * 商品検索クエリ生成
    8478     * @link http://webservice.rakuten.co.jp/api/itemsearch/
    85      * @param array $search 商品検索条件
    8679     * @return string RESTクエリ文字列
    8780     */
    88     private function queryItems(&$search)
     81    private function queryItems()
    8982    {
    9083        $baseurl = "http://api.rakuten.co.jp/rws/3.0/rest";
     
    9487        $params["operation"] = "ItemSearch";
    9588        $params["version"] = "2010-09-15";
    96         $params["hits"] = empty($search["pagesize"]) ? 10 : $search["pagesize"];
     89        $params["hits"] = $this->requests["pagesize"];
    9790        $params["availability"] = 1;
    9891        $params["field"] = 1;
    99         $params["carrier"] = empty($search["mobile"]) ? 0 : 1;
     92        $params["carrier"] = empty($this->requests["mobile"]) ? 0 : 1;
    10093        $params["imageFlag"] = 1;
    10194        $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"]];
    111104        } else {
    112105            $params["sort"] = "standard";
    113106        }
    114         $params["page"] = $search["page"];
     107        $params["page"] = $this->requests["page"];
    115108        ksort($params);
    116109        return $baseurl . "?" . http_build_query($params);
     
    142135    /**
    143136     * 商品検索ソート方法取得
    144      * @param string $category 検索対象のカテゴリ名
    145137     * @return array ソート指定の連想配列
    146138     */
    147     public function getSortTypes($category = "")
     139    public function getSortTypes()
    148140    {
    149141        return $this->sortTypes;
    150     }
    151 
    152     /**
    153      * 商品検索ページ総数
    154      * @return int 商品検索ページ総数
    155      */
    156     public function getPageCount()
    157     {
    158         return $this->pageCount;
    159142    }
    160143
     
    162145     * カテゴリ検索
    163146     * @link http://webservice.rakuten.co.jp/api/genresearch/
    164      * @param string $parent 基底カテゴリ
     147     * @param string $category 基底カテゴリ
    165148     * @return array カテゴリ情報の連想配列
    166149     */
    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;
    171154        }
    172155
    173156        // RESTクエリ情報を取得
    174         $query = $this->queryCategories($parent);
     157        $query = $this->queryCategories($category);
    175158
    176159        // RESTクエリ実行
     
    191174     * 商品検索
    192175     * @link http://webservice.rakuten.co.jp/api/itemsearch/
    193      * @param array $search 商品検索条件
    194176     * @return array 商品情報の連想配列
    195177     */
    196     public function getItems(&$search)
     178    public function getItems()
    197179    {
    198180        // RESTクエリ情報を取得
    199         $query = $this->queryItems($search);
     181        $query = $this->queryItems();
    200182
    201183        // RESTクエリ実行
     
    206188        $hash = array();
    207189        if (isset($objxml->Body->ItemSearch)) {
    208             $this->pageCount = intval($objxml->Body->ItemSearch->pageCount);
     190            $this->pages = intval($objxml->Body->ItemSearch->pageCount);
    209191            foreach ($objxml->Body->ItemSearch->Items->Item as $node) {
    210192                array_push($hash, array(
     
    213195                        "desc" => (string)$node->itemCaption,
    214196                        "shop" => (string)$node->shopName,
    215                         "score"=> floatval((string)$node->reviewAverage),
     197                        "score" => floatval((string)$node->reviewAverage),
    216198                        "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,
    218200                        "surl" => (string)$node->shopUrl)
    219201                );
    220202            }
    221203        } else {
    222             $this->pageCount = 0;
     204            $this->pages = 0;
    223205        }
    224206        return $hash;
  • cs-shop/trunk/service.php

    r534388 r536232  
    1515
    1616    /**
     17     * 商品検索条件の設定
     18     * @param array $params 商品検索条件
     19     */
     20    public function setRequestParams(&$params);
     21
     22    /**
    1723     * サービス識別名
    1824     * @return string サービス識別名
     
    2834    /**
    2935     * 商品検索ソート方法取得
    30      * @param string $category 検索対象のカテゴリ名
    3136     * @return array ソート指定の連想配列
    3237     */
    33     public function getSortTypes($category = "");
     38    public function getSortTypes();
    3439
    3540    /**
     
    4146    /**
    4247     * カテゴリ検索
    43      * @param string $parent 基底カテゴリ
     48     * @param string $category 基底カテゴリ
    4449     * @return array カテゴリ情報の連想配列
    4550     */
    46     public function getCategories($parent = "");
     51    public function getCategories($category = "");
    4752
    4853    /**
    4954     * 商品検索
    50      * @param array $search 商品検索条件
    5155     * @return array 商品情報の連想配列
    5256     */
    53     public function getItems(&$search);
     57    public function getItems();
    5458}
    5559
Note: See TracChangeset for help on using the changeset viewer.