No
Image';
return $noImg;
}
//長い文字列を切り詰める
function CutShort( $text, $max ) {
if ( mb_strlen( $text ) > $max ) {
$newText = mb_substr( $text, 0, $max-1 )."...";
} else {
$newText = $text;
}
return $newText;
}
//データ整形
function TidyValue( $theValue ) {
$theValue = rtrim( $theValue, ", " );
$theValue = trim( $theValue );
$theValue = rtrim( $theValue, "," );
return $theValue;
}
//XML要素の開始時処理
function StartElm( $parser, $elmName ) {
global $aryTmp, $cnt, $cur, $thisImage;
if ( $elmName == "ITEM" ) {
$aryTmp[$cnt] = array();
$thisImage = "";
} else if ( strstr( $elmName, "IMAGE" ) ) {
if (!isset($aryTmp[$cnt][$elmName])) {//imageSets対策
$aryTmp[$cnt][$elmName] = array();
$thisImage = $elmName;
}
} else {
$cur = $elmName;
if ( $cur=="AUTHOR" || $cur=="ARTIST" || $cur=="DIRECTOR" || $cur=="ACTOR" ) {
if ( $aryTmp[$cnt][$cur] ) {
$aryTmp[$cnt][$cur] .= ", ";
}
} else if ($cur=="FORMATTEDPRICE") {
$aryTmp[$cnt][$cur] = "";
}
}
}
//XML要素の終了時処理
function EndElm( $parser, $elmName ) {
global $aryTmp, $cnt, $cur, $resetUrl, $cache_data, $thisImage;
if ( $elmName == "ITEM" ) {
$cnt++;
} else if ( strstr( $elmName, "IMAGE" ) ) {
$thisImage = "";
} else if ($elmName=="PRICE") {
$aryTmp[$cnt]['our_price'] = $aryTmp[$cnt]["FORMATTEDPRICE"];
} else if ( $elmName == "CODE" ) { //Amazonよりエラーメッセージ
if ( strstr($aryTmp[$cnt][$elmName],"NoExactMatches") ) { //「該当商品なし」
ShowDefault();
} else { //それ以外は一時的障害とみなしキャッシュ強制表示モードで再実行
if ($cache_data) {
$tmpUrl = str_replace("reset", "tmp_error", $resetUrl);
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://".$_SERVER["HTTP_HOST"].$tmpUrl);
exit();
} else { //キャッシュしない設定ならエラーメッセージ表示して終了
echo $aryTmp[$cnt][$elmName];
exit();
}
}
}
$aryTmp[$cnt][$cur] = TidyValue( $aryTmp[$cnt][$cur] );
}
//XML要素のデータ部分処理
function ChrDat( $parser, $dat ) {
global $aryTmp, $cnt, $cur, $thisImage;
if ( $thisImage && ( $cur=="URL" || $cur=="HEIGHT" || $cur=="WIDTH" ) ) {
$aryTmp[$cnt][$thisImage][$cur] .= $dat;
} else {
$aryTmp[$cnt][$cur] .= mb_convert_encoding( $dat, "UTF-8", "auto" );
}
}
//古いキャッシュファイル削除
function CleanUp( $dirName, $keepHours ) {
$keepLimit = time() - ( $keepHours * 60 * 60 );
$cacheDir = dir( $dirName );
while( $fileName = $cacheDir -> read() ) {
if ( $fileName != "." && $fileName != ".." ) {
$currentFile = $dirName . "/" . $fileName;
if ( filemtime( $currentFile ) < $keepLimit ) {
unlink( $currentFile );
}
}
}
}
////////////////////////////////
// //
// 初期設定 //
// //
////////////////////////////////
//データ保存フォルダのパス
$data_path = "lilbox_data/";
//画像保存フォルダのパス
$img_path = "lilbox_img/";
//商品設定
if ( isset($_GET['books-jp']) ) {
$key = $_GET['books-jp'];
$catalog = "Books";
} else if ( isset($_GET['book']) ) {
$key = $_GET['book'];
$catalog = "Books";
} else if ( isset($_GET['Books']) ) {
$key = $_GET['Books'];
$catalog = "Books";
} else if ( isset($_GET['books']) ) {
$key = $_GET['books'];
$catalog = "Books";
} else if ( isset($_GET['books-us']) ) {
$key = $_GET['books-us'];
$catalog = "ForeignBooks";
} else if ( isset($_GET['foreign']) ) {
$key = $_GET['foreign'];
$catalog = "ForeignBooks";
} else if ( isset($_GET['ForeignBooks']) ) {
$key = $_GET['ForeignBooks'];
$catalog = "ForeignBooks";
} else if ( isset($_GET['foreignbooks']) ) {
$key = $_GET['foreignbooks'];
$catalog = "ForeignBooks";
} else if ( isset($_GET['music-jp']) ) {
$key = $_GET['music-jp'];
$catalog = "Music";
} else if ( isset($_GET['pops']) ) {
$key = $_GET['pops'];
$catalog = "Music";
} else if ( isset($_GET['Music']) ) {
$key = $_GET['Music'];
$catalog = "Music";
} else if ( isset($_GET['music']) ) {
$key = $_GET['music'];
$catalog = "Music";
} else if ( isset($_GET['classical-jp']) ) {
$key = $_GET['classical-jp'];
$catalog = "Classical";
} else if ( isset($_GET['classic']) ) {
$key = $_GET['classic'];
$catalog = "Classical";
} else if ( isset($_GET['Classical']) ) {
$key = $_GET['Classical'];
$catalog = "Classical";
} else if ( isset($_GET['classical']) ) {
$key = $_GET['classical'];
$catalog = "Classical";
} else if ( isset($_GET['dvd-jp']) ) {
$key = $_GET['dvd-jp'];
$catalog = "DVD";
} else if ( isset($_GET['dvd']) ) {
$key = $_GET['dvd'];
$catalog = "DVD";
} else if ( isset($_GET['DVD']) ) {
$key = $_GET['DVD'];
$catalog = "DVD";
} else if ( isset($_GET['VHS']) ) {
$key = $_GET['VHS'];
$catalog = "VHS";
} else if ( isset($_GET['vhs']) ) {
$key = $_GET['vhs'];
$catalog = "VHS";
} else if ( isset($_GET['Video']) ) {
$key = $_GET['Video'];
$catalog = "Video";
} else if ( isset($_GET['video']) ) {
$key = $_GET['video'];
$catalog = "Video";
} else if ( isset($_GET['videogames-jp']) ) {
$key = $_GET['videogames-jp'];
$catalog = "VideoGames";
} else if ( isset($_GET['game']) ) {
$key = $_GET['game'];
$catalog = "VideoGames";
} else if ( isset($_GET['VideoGames']) ) {
$key = $_GET['VideoGames'];
$catalog = "VideoGames";
} else if ( isset($_GET['videogames']) ) {
$key = $_GET['videogames'];
$catalog = "VideoGames";
} else if ( isset($_GET['software-jp']) ) {
$key = $_GET['software-jp'];
$catalog = "Software";
} else if ( isset($_GET['software']) ) {
$key = $_GET['software'];
$catalog = "Software";
} else if ( isset($_GET['Software']) ) {
$key = $_GET['Software'];
$catalog = "Software";
} else if ( isset($_GET['electronics-jp']) ) {
$key = $_GET['electronics-jp'];
$catalog = "Electronics";
} else if ( isset($_GET['electronics']) ) {
$key = $_GET['electronics'];
$catalog = "Electronics";
} else if ( isset($_GET['Electronics']) ) {
$key = $_GET['Electronics'];
$catalog = "Electronics";
} else if ( isset($_GET['kitchen-jp']) ) {
$key = $_GET['kitchen-jp'];
$catalog = "Kitchen";
} else if ( isset($_GET['kitchen']) ) {
$key = $_GET['kitchen'];
$catalog = "Kitchen";
} else if ( isset($_GET['Kitchen']) ) {
$key = $_GET['Kitchen'];
$catalog = "Kitchen";
} else if ( isset($_GET['toys-jp']) ) {
$key = $_GET['toys-jp'];
$catalog = "Toys";
} else if ( isset($_GET['Toys']) ) {
$key = $_GET['Toys'];
$catalog = "Toys";
} else if ( isset($_GET['toys']) ) {
$key = $_GET['toys'];
$catalog = "Toys";
} else if ( isset($_GET['SportingGoods']) ) {
$key = $_GET['SportingGoods'];
$catalog = "SportingGoods";
} else if ( isset($_GET['sportinggoods']) ) {
$key = $_GET['sportinggoods'];
$catalog = "SportingGoods";
} else if ( isset($_GET['HealthPersonalCare']) ) {
$key = $_GET['HealthPersonalCare'];
$catalog = "HealthPersonalCare";
} else if ( isset($_GET['healthpersonalcare']) ) {
$key = $_GET['healthpersonalcare'];
$catalog = "HealthPersonalCare";
} else if ( isset($_GET['Watches']) ) {
$key = $_GET['Watches'];
$catalog = "Watches";
} else if ( isset($_GET['watches']) ) {
$key = $_GET['watches'];
$catalog = "Watches";
} else if ( isset($_GET['Baby']) ) {
$key = $_GET['Baby'];
$catalog = "Baby";
} else if ( isset($_GET['baby']) ) {
$key = $_GET['baby'];
$catalog = "Baby";
} else if ( isset($_GET['apparel']) ) {
$key = $_GET['apparel'];
$catalog = "Apparel";
} else if ( isset($_GET['Apparel']) ) {
$key = $_GET['Apparel'];
$catalog = "Apparel";
} else if ( isset($_GET['Blended']) ) {
$key = $_GET['Blended'];
$catalog = "Blended";
} else if ( isset($_GET['blended']) ) {
$key = $_GET['blended'];
$catalog = "Blended";
} else if ( isset($_GET['category']) ) {
$key = $_GET['key'];
$catalog = $_GET['category'];
} else {
$key = $default_key;
$catalog = $default_catalog;
}
//キーワード処理
$key = CutShort( addslashes( stripslashes($key) ), 51 );
AmCatalog( $catalog, $key );
$search_type = ( ereg("^[0-9]+$",$key) )? "BrowseNode":"Keywords";
$tmpEncode = mb_detect_encoding( urldecode($key), "auto" );
$keyUTF = mb_convert_encoding( $key, "UTF-8", $tmpEncode );
$keyEUC = mb_convert_encoding( $key, "UTF-8", $tmpEncode );
//カスタマイズ値
if ( $_GET['new'] ) {
$new = true;
}
if ( $new ) {//新商品モード
$random = 0; //ランダム表示強制解除
if ( $catalog=="Books" || $catalog=="ForeignBooks" ) {
$sort = "daterank";
} else if ( $catalog=="Classical" || $catalog=="DVD" || $catalog=="Music" || $catalog=="VHS" || $catalog=="Video" ) {
$sort = "-orig-rel-date";
} else if ( $catalog=="Electronics" || $catalog=="Kitchen" || $catalog=="Software" || $catalog=="SportingGoods" || $catalog=="Toys" || $catalog=="VideoGames" ) {
$sort = "-release-date";
} else {
$sort = "";
$new = false;
}
} else {
$sort = "";
}
if ( isset($_GET['no_cache']) ) {
if ( $_GET['no_cache']=="both" ) {
$cache_data = 0;
$cache_img = 0;
} else if ( $_GET['no_cache']=="data" ) {
$cache_data = 0;
} else if ( $_GET['no_cache']=="img" ) {
$cache_img = 0;
}
}
if ( isset($_GET['cache']) ) {
if ( $_GET['cache']=="both" ) {
$cache_data = 1;
$cache_img = 1;
} else if ( $_GET['cache']=="data" ) {
$cache_data = 1;
} else if ( $_GET['cache']=="img" ) {
$cache_img = 1;
}
}
if ( ereg("^[a-fA-F0-9]+$",$_GET['bg']) ) {
$bg_color = strval("#".$_GET['bg']);
}
if ( ereg("^[a-fA-F0-9]+$",$_GET['border']) ) {
$border_color = strval("#".$_GET['border']);
}
if ( ereg("^[a-fA-F0-9]+$",$_GET['title']) ) {
$title_color = strval("#".$_GET['title']);
}
if ( ereg("^[a-fA-F0-9]+$",$_GET['author']) ) {
$author_color = strval("#".$_GET['author']);
}
if ( ereg("^[a-fA-F0-9]+$",$_GET['price']) ) {
$price_color = strval("#".$_GET['price']);
}
if (isset($_GET['type'])) {
$type = addslashes($_GET['type']);
}
if (isset($_GET['id'])) {
if (in_array($_GET['id'], $extra_id)) {
$associate_id = $_GET['id'];
}
}
//リセットのためのURL準備
$resetUrl = $_SERVER[ "PHP_SELF" ].'?reset=true';
if ($type) {
$resetUrl .= '&type='.$type;
}
if ($_GET['bg']) {
$resetUrl .= '&bg='.$_GET['bg'];
}
if ($_GET['border']) {
$resetUrl .= '&border='.$_GET['border'];
}
if ($_GET['title']) {
$resetUrl .= '&title='.$_GET['title'];
}
if ($_GET['author']) {
$resetUrl .= '&author='.$_GET['author'];
}
if ($_GET['price']) {
$resetUrl .= '&price='.$_GET['price'];
}
if ($_GET['cache']) {
$resetUrl .= '&cache='.$_GET['cache'];
}
if ($_GET['no_cache']) {
$resetUrl .= '&no_cache='.$_GET['no_cache'];
}
if ($_GET['new']) {
$resetUrl .= '&new=true';
}
if ($_GET['id']) {
$resetUrl .= '&id='.$_GET['id'];
}
$resetUrl .= '&'.$catalog.'='.urlencode($keyEUC);
//表示用
//共通値
$border_width = "1px";
$border_style = "solid";
$titleTopHeight = 13;
//表示スタイル設定
//幅や高さを変更したら、呼び出しコード(iframeタグ)側の変更もお忘れなく。
//商品名などの文字列は短めにしておくのが、レイアウト崩れを防ぐコツです。
switch ($type) {
case "mini":
$num = 1; //表示商品数
$width = 130; //全体の幅(ピクセル)
$height = 85; //全体の高さ(ピクセル)
$tdWidth = 100; //1セルの幅(%)
$length = 8; //商品名の長さ(ダブルバイト文字数)
$author = 5; //著者・アーティスト名(同上)
$titleBottomHeight = 0; //lilbox表記を下部に置く場合、高さをピクセル指定。しない場合0
$small = 60; //画像を縮小させる場合、縦の長さをピクセル指定。縮小させない場合0。(指定されているとマージンも縮小)
$vertical = 0; //縦に並べるレイアウトなら1
$double = 0; //2列並べるレイアウトなら1
$linebreak = 0; //商品名等を画像の下へまわすなら1
break;
case "btn":
$num = 1;
$width = 125;
$height = 125;
$tdWidth = 100;
$length = 16;
$author = 14;
$titleBottomHeight = 16;
$small = 60;
$vertical = 0;
$double = 0;
$linebreak = 0;
break;
case "banner":
$num = 2;
$width = 468;
$height = 60;
$tdWidth = 50;
$length = 16;
$author = 16;
$titleBottomHeight = 0;
$small = 40;
$vertical = 0;
$double = 0;
$linebreak = 0;
break;
case "halfbanner":
$num = 1;
$width = 234;
$height = 60;
$tdWidth = 100;
$length = 16;
$author = 16;
$titleBottomHeight = 0;
$small = 40;
$vertical = 0;
$double = 0;
$linebreak = 0;
break;
case "tbanner":
$num = 2;
$width = 468;
$height = 100;
$tdWidth = 50;
$length = 20;
$author = 20;
$titleBottomHeight = 0;
$small = 0;
$vertical = 0;
$double = 0;
$linebreak = 0;
break;
case "bigbanner":
$num = 4;
$width = 728;
$height = 90;
$tdWidth = 25;
$length = 18;
$author = 18;
$titleBottomHeight = 0;
$small = 60;
$vertical = 0;
$double = 0;
$linebreak = 0;
break;
case "sky":
$num = 4;
$width = 120;
$height = 600;
$tdWidth = 100;
$length = 10;
$author = 10;
$titleBottomHeight = 30;
$small = 0;
$vertical = 1;
$double = 0;
$linebreak = 1;
break;
case "halfsky":
$num = 1;
$width = 120;
$height = 240;
$tdWidth = 100;
$length = 46;
$author = 46;
$titleBottomHeight = 16;
$small = 0;
$vertical = 1;
$double = 0;
$linebreak = 1;
break;
case "widesky":
$num = 5;
$width = 160;
$height = 600;
$tdWidth = 100;
$length = 16;
$author = 16;
$titleBottomHeight = 30;
$small = 0;
$vertical = 1;
$double = 0;
$linebreak = 0;
break;
case "bigsky":
$num = 5;
$width = 148;
$height = 800;
$tdWidth = 100;
$length = 26;
$author = 12;
$titleBottomHeight = 40;
$small = 0;
$vertical = 1;
$double = 0;
$linebreak = 1;
break;
case "square":
$num = 4;
$width = 250;
$height = 250;
$tdWidth = 50;
$length = 12;
$author = 12;
$titleBottomHeight = 0;
$small = 60;
$vertical = 0;
$double = 1;
$linebreak = 1;
break;
case "rect":
$num = 4;
$width = 300;
$height = 250;
$tdWidth = 50;
$length = 24;
$author = 24;
$titleBottomHeight = 0;
$small = 0;
$vertical = 0;
$double = 1;
$linebreak = 0;
break;
case "smallrect":
$num = 1;
$width = 180;
$height = 150;
$tdWidth = 100;
$length = 60;
$author = 60;
$titleBottomHeight = 16;
$small = 0;
$vertical = 0;
$double = 0;
$linebreak = 0;
break;
case "bigrect":
$num = 6;
$width = 336;
$height = 280;
$tdWidth = 50;
$length = 16;
$author = 16;
$titleBottomHeight = 0;
$small = 0;
$vertical = 0;
$double = 1;
$linebreak = 0;
break;
default:
$num = 100;
$width = 200;
$height = 400;
$tdWidth = 100;
$length = 100;
$author = 100;
$titleBottomHeight = 0;
$small = 0;
$vertical = 1;
$double = 0;
$linebreak = 0;
break;
}
////////////////////////////////
// //
// データ更新 //
// //
////////////////////////////////
$keep = 1; //何時間ごとにデータ更新?
$keepImg = 24; //何時間ごとに画像更新?
$updateLimit = mktime( date("H")-$keep, date("i"), date("s"), date("m"), date("d"), date("Y") );
$updateLimitImg = mktime( date("H")-$keepImg, date("i"), date("s"), date("m"), date("d"), date("Y") );
$mustUpdate = false;
$cacheData = "";
$aryTmp = array();
$cnt = 0;
$cur = "";
//データファイル更新チェック
$localPath = $data_path.$catalog."_".urlencode($keyEUC);
$localPath .= ($new)? "_new":"";
$localPath .= ".xml";
if ( $_REQUEST['tmp_error'] ) { //Amazonサーバー障害時
$mustUpdate = false;
} else if ( $_REQUEST['reset'] || $_REQUEST['retry'] ) { //Reset
$mustUpdate = true;
} else if ( !file_exists( $localPath ) ) { //ローカルファイルなし
$mustUpdate = true;
} else if ( !filemtime( $localPath ) ) { //サーバーがatime非対応
$mustUpdate = true;
} else if ( filemtime( $localPath ) < $updateLimit ) { //1時間以上前のもの
$mustUpdate = true;
}
if ( $mustUpdate ) {
$amazonPath = "http://ecs.amazonaws.".$locale."/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=" .$access_key_id ."&Operation=ItemSearch&SearchIndex=".$catalog."&".$search_type."=".urlencode($keyUTF)."&ResponseGroup=ItemAttributes,Images,Offers&Version=2011-08-01";
$amazonPath .= "&Timestamp=".$timestamp;
$amazonPath .= ( $calalog!="Blended" && $sort!="" )? "&Sort=".$sort:"";
$amazonPath .= "&AssociateTag=".$associate_id;
$amazonPath = aa_signrequest($amazonPath,$secret_access_key);
$dataFile = fopen( $amazonPath, "r" );
}
if (!$dataFile) {
$dataFile = fopen( $localPath, "r" );
}
if ($dataFile) {
$xml = xml_parser_create();
xml_set_element_handler( $xml, "StartElm", "EndElm" );
xml_set_character_data_handler( $xml, "ChrDat" );
while ( $data = fread( $dataFile, 4096 ) ) {
$cacheData .= $data; //cache
//$data = mb_ereg_replace( ">[\n ]*<", "><", $data );
if ( !xml_parse( $xml, $data, feof( $dataFile ) ) ) {
echo '
'; echo '':' target="_blank">'; echo 'lilbox'; echo '':' target="_blank">'; echo ' 初音版 | '; echo '
'; print_r($aryData); echo ''; */ ?>