* Copyright (c)2010 ValueCommerce,Co.Ltd. */ require_once 'VCPDBDriver/VCPDBDriver.php'; require_once 'PageBody.php'; /* * このサンプルでは内部エンコーディングはUTF-8です。 */ mb_internal_encoding("UTF-8"); /* * VCPDBDriverクラスのインスタンスを生成します。 */ $api = new VCPDBDriver(VCPDBDRIVER_API_URL); /* * このサンプルではキーワードは固定です。 */ $api->setParam('keyword', 'iPad'); /* * page パラメータが存在することと、pageパラメータの値が数値であることを確認してから、 * パラメータに収めます。 */ if (array_key_exists('page', $_GET) && is_numeric($_GET['page'])) { $api->setParam('page', $_GET['page']); } /* * ページ本体の生成 */ $pageBody = new PageBody('Views/Pagination.html', 'Views/FormattedItem.html', 10, $api); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
/** * ページに表示ヘッダを出力します。 */ protected function compose() { $itemHtml = parent::compose(); global $_GET; /* * ソート種別 */ $options = ""; foreach (self::$SORT_BY as $code => $name) { $options .= '<option value="' . $code . '" '; if ($this->sort_by && $code == $this->sort_by) { $options .= 'selected'; } $options .= '>' . $name . '</option>'; } $itemHtml = str_replace('${SORT_BY}', $options, $itemHtml); /* * ソート順 */ $options = ""; foreach (self::$SORT_ORDER as $code => $name) { $options .= '<option value="' . $code . '" '; if ($this->sort_order && $code == $this->sort_order || !$this->sort_order && $code == '') { $options .= 'selected'; } $options .= '>' . $name . '</option>'; } $itemHtml = str_replace('${SORT_ORDER}', $options, $itemHtml); // カテゴリ $categories = "<option value=''></option>"; $api = new VCPDBDriver(VCPDBDRIVER_CATEGORY_API_URL); $api->setParam("category_level", "1"); $api->setFlag("childless"); $response = $api->executeQuery(); if (gettype($response) == "object") { $itemElements = $response->xpath('/rss/channel/item'); foreach ($itemElements as $item) { $titleStr = null; $descStr = null; $title = $item->xpath('title'); if (count($title) > 0) { $titleStr = $title[0]; } $desc = $item->xpath('description'); if (count($desc) > 0) { $descStr = $desc[0]; } if ($titleStr == null || $descStr == null) { continue; } $categories .= '<option value="' . $titleStr . '" '; if ($this->category && $titleStr == $this->category) { $categories .= 'selected'; } $categories .= '>' . $descStr . '</option>'; } } $itemHtml = str_replace('${CATEGORIES}', $categories, $itemHtml); return $itemHtml; }