Пример #1
0
 function plugin_isbn_cache_fetch($target, $dir, $check = true)
 {
     $this->config['AMAZON_ASE_ID'] = $this->get_associate_tag($this->config['AMAZON_ASE_ID']);
     $filename = $dir . $target . '_' . $this->config['AMAZON_ASE_ID'] . '.isbn';
     $error = '';
     if (!empty($this->root->rtf['use_cache_always'])) {
         $check = false;
     }
     if (!is_file($filename) || $check && $this->config['ISBN_AMAZON_EXPIRE_TIT'] * 3600 * 24 < $this->cont['UTC'] - filemtime($filename)) {
         // データを取りに行く
         include_once XOOPS_TRUST_PATH . '/class/hyp_common/hsamazon/hyp_simple_amazon.php';
         $ama = new HypSimpleAmazon($this->config['AMAZON_ASE_ID']);
         if ($this->root->amazon_AccessKeyId) {
             $ama->AccessKeyId = $this->root->amazon_AccessKeyId;
         }
         if ($this->root->amazon_SecretAccessKey) {
             $ama->SecretAccessKey = $this->root->amazon_SecretAccessKey;
         }
         $ama->encoding = $this->cont['SOURCE_ENCODING'] === 'EUC-JP' ? 'EUCJP-win' : $this->cont['SOURCE_ENCODING'];
         $ama->itemLookup($target);
         $tmpary = $ama->getCompactArray();
         $error = $ama->error;
         $ama = NULL;
         $title = '';
         if (!empty($tmpary['Items'])) {
             $tmpary = $tmpary['Items'][0];
             $title = trim($tmpary['TITLE']);
             $category = @$tmpary['BINDING'];
             $price = @$tmpary['PRICE'];
             $author = @$tmpary['PRESENTER'];
             $artist = '';
             $releasedate = @$tmpary['RELEASEDATE'];
             $manufacturer = @$tmpary['MANUFACTURER'];
             $availability = @$tmpary['AVAILABILITY'];
             $listprice = @$tmpary['LISTPRICE'];
             $usedprice = @$tmpary['USEDPRICE'];
             $simg = $tmpary['SIMG'];
             //[10]
             $mimg = $tmpary['MIMG'];
             //[11]
             $limg = $tmpary['LIMG'];
             //[12]
         }
         if (!$error) {
             // タイトルがあれば、できるだけキャッシュに保存
             $title = "{$title}<>{$category}<>{$price}<>{$author}<>{$artist}<>{$releasedate}<>{$manufacturer}<>{$availability}<>{$listprice}<>{$usedprice}<>{$simg}<>{$mimg}<>{$limg}";
             $this->plugin_isbn_cache_save($title, $filename);
         }
         // Update plainDB
         $this->func->need_update_plaindb();
     } else {
         $title = file_get_contents($filename);
     }
     if (!$error) {
         return explode("<>", $title);
     } else {
         return array("\t" . $error);
     }
 }
Пример #2
0
 function plugin_amazon_get_asin($asin)
 {
     $false = array('', '', '');
     if (!$asin) {
         return $false;
     }
     $nocache = $nocachable = 0;
     $error = $title = $image = $creator = '';
     $cache_dir = $this->cont['CACHE_DIR'] . 'plugin';
     if (is_dir($cache_dir) === FALSE || is_writable($cache_dir) === FALSE) {
         $nocachable = 1;
     }
     // キャッシュ不可の場合
     $dat = $this->plugin_amazon_cache_fetch($cache_dir . '/', $asin);
     if ($dat && count($dat) === 3) {
         list($title, $image, $author) = $dat;
     } else {
         $nocache = 1;
         // キャッシュ見つからず
         include_once XOOPS_TRUST_PATH . '/class/hyp_common/hsamazon/hyp_simple_amazon.php';
         $ama = new HypSimpleAmazon($this->config['PLUGIN_AMAZON_AID']);
         if ($this->root->amazon_AccessKeyId) {
             $ama->AccessKeyId = $this->root->amazon_AccessKeyId;
         }
         if ($this->root->amazon_SecretAccessKey) {
             $ama->SecretAccessKey = $this->root->amazon_SecretAccessKey;
         }
         $ama->encoding = $this->cont['SOURCE_ENCODING'] === 'EUC-JP' ? 'EUCJP-win' : $this->cont['SOURCE_ENCODING'];
         $ama->itemLookup($this->asin);
         $tmpary = $ama->getCompactArray();
         if ($ama->error) {
             $error = $ama->error;
         }
         $ama = NULL;
         if (!empty($tmpary['Items'])) {
             $title = $tmpary['Items'][0]['TITLE'];
             $image = $tmpary['Items'][0]['MIMG'];
             $author = preg_replace('/^by: /', '', strip_tags($tmpary['Items'][0]['PRESENTER']));
         }
     }
     if ($title === '') {
         if ($error) {
             $false[] = $error;
         }
         return $false;
     } else {
         if ($nocache == 1 && $nocachable != 1) {
             $this->plugin_amazon_cache_save(join("\t", array($title, $image, $author)), $cache_dir);
         }
         return array($title, $image, $author, '');
     }
 }