private static function search($keyword)
{
if ($output = self::fetchCache($keyword)) {
return $output;
}
$options = get_option('wp_rakuten_options');
// 楽天商品検索
$client = new RakutenRws_Client();
$client->setApplicationId($options['developer_id']);
$client->setAffiliateId($options['affiliate_id']);
$response = $client->execute('IchibaItemSearch', array('keyword' => $keyword, 'availability' => '1', 'sort' => '+affiliateRate', 'hits' => 1));
$html = '';
foreach ($response as $item) {
if ((int) $item['imageFlag'] === 1) {
$html .= "<p>";
$html .= "<a href=\"{$item['affiliateUrl']}\">";
$html .= "<img src=\"{$item['mediumImageUrls'][0]['imageUrl']}\"><br />";
$html .= "{$item['itemName']}</a>";
$html .= "</p>";
}
}
$output = '<!-- Rakuten Plugin Start -->';
$output .= $html;
$output .= '<!-- Rakuten Plugin End -->';
self::createCache($keyword, $output);
return $output;
}