forked from WPPlugins/wp-tmkm-amazon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-tmkm-amazon.php
701 lines (598 loc) · 28.6 KB
/
wp-tmkm-amazon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<?php
/*
Plugin Name: wp-tmkm-amazon
Plugin URI: http://blog.openmedialabo.net/
Description: ASIN を指定して Amazon から個別商品の情報を取出します。BOOKS, DVD, CD は詳細情報を取り出せます。
Author: ともかめ / Romeo
Version: 1.5b
Author URI: http://blog.openmedialabo.net/
Special Thanks: Keith Devens.com (http://keithdevens.com/software/phpxml)
Special Thanks: websitepublisher.net (http://www.websitepublisher.net/article/aws-php/)
Special Thanks: hiromasa.zone :o) (http://hiromasa.zone.ne.jp/)
Special Thanks: みやび ( http://shinonon-web.net/ )
Special Thanks: PEAR :: Package :: Cache_Lite (http://pear.php.net/package/Cache_Lite)
*/
/******************************************************************************
* wp-tmkm-amazon-function : amazon ECS search engine
*****************************************************************************/
if( basename( $_SERVER['SCRIPT_FILENAME'] ) == 'wp-tmkm-amazon.php' ) {
die();
}
$tmkm_plugin_directory = get_option('siteurl') . '/wp-content/plugins/' . basename(dirname(__FILE__));
$tmkm_amazon_php = '/wp-tmkm-amazon.php';
$tmkm_amazon_search_php = '/wp-tmkm-amazon-search.php';
$tmkm_amazon_settings = get_option('wp_tmkm_admin_options');
/******************************************************************************
* THIS FILE IS CALLED ONLY.
*****************************************************************************/
include_once('wp-tmkm-amazon-function.php');
/******************************************************************************
* 管理画面からオプションを設定
*****************************************************************************/
class WpTmkmAmazonAdmin {
var $tmkm_amazon_settings, $tmkm_amazon_options;
function WpTmkmAmazonAdmin() {
if ( !get_option('wp_tmkm_admin_options') ){
// create default options
$tmkm_amazon_options = array(
'associatesid' => '',
'windowtarget' => 'self',
'jacketimgsize' => 'small',
'goodsimgsize' => 'small',
'layout_type' => '0',
// ** 追加 (2009/6/22)
'devtoken' => '',
'secretkey' => '',
// ここまで **
// ** 追加 (2011/9/5)
'homedisp' => '0',
// ここまで
);
update_option('wp_tmkm_admin_options', $tmkm_amazon_options);
}
}
function tmkm_amazon_options_page() {
global $tmkm_amazon_settings;
$tmkm_amazon_options = get_option('wp_tmkm_admin_options');
$tmkm_amazon_admin_html =
'<div class="wrap" id="footnote-options">' . "\n".
'<h2>Wp-Tmkm-Amazon プラグイン設定</h2>' . "\n";
if ( $_POST['action'] ){
$tmkm_amazon_admin_html .= '<div class="updated"><p><strong>設定を保存しました。</strong></p></div>';
}
switch( $tmkm_amazon_options['homedisp']) {
case '0': $dispon = ' checked'; $dispoff = ''; break;
case '1': $dispon = ''; $dispoff = ' checked'; break;
}
switch( $tmkm_amazon_options['windowtarget']) {
case 'newwin': $newwindow = ' checked'; $selfwindow = ''; break;
case 'self': $newwindow = ''; $selfwindow = ' checked'; break;
}
switch( $tmkm_amazon_options['jacketimgsize'] ) {
case 'medium': $m_jacketsize = ' checked'; $s_jacketsize = ''; break;
case 'small': $m_jacketsize = ''; $s_jacketsize = ' checked'; break;
}
switch( $tmkm_amazon_options['goodsimgsize'] ) {
case 'medium': $m_goodssize = ' checked'; $s_goodssize = ''; break;
case 'small': $m_goodssize = ''; $s_goodssize = ' checked'; break;
}
switch( $tmkm_amazon_options['layout_type'] ) {
case 0: $default_layout = ' checked';$medium_layout = ''; $simple_layout = ''; $noimage_layout = ''; break;
case 1: $default_layout = ''; $medium_layout = ' checked'; $simple_layout = ''; $noimage_layout = ''; break;
case 2: $default_layout = ''; $medium_layout = ''; $simple_layout = ' checked'; $noimage_layout = ''; break;
case 3: $default_layout = ''; $medium_layout = ''; $simple_layout = ''; $noimage_layout = ' checked'; break;
}
$tmkm_amazon_admin_html .=
'<form method="post" action="' . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . '">' .
'<input type="hidden" name="action" value="save_options" />' .
'<table class="form-table">' .
'<tr>' . "\n" .
'<th>あなたのアソシエイト ID</th>' . "\n" .
'<td><input type="text" name="associatesid" value="' . $tmkm_amazon_options['associatesid'] . '" /></td>' . "\n" .
// ** 追加 (2009/6/22)
'</tr>' . "\n" .
'<tr>' . "\n" .
'<th>あなたのAccess Key ID</th>' . "\n" .
'<td><input type="text" name="devtoken" value="' . $tmkm_amazon_options['devtoken'] . '" /></td>' . "\n" .
'</tr>' . "\n" .
'<tr>' . "\n" .
'<th>あなたのSecret Access Key</th>' . "\n" .
'<td><input type="text" name="secretkey" value="' . $tmkm_amazon_options['secretkey'] . '" /></td>' . "\n" .
'</tr>' . "\n" .
// ここまで **
// ** 追加 (2011/9/5)
'<tr><th>HOME画面に適用するか(default:適用する)</th>' . "\n" .
'<td><input type="radio" name="homedisp" value="0"' . $dispon . ' /> 適用する<br />' . "\n" .
'<input type="radio" name="homedisp" value="1"' . $dispoff . ' /> 適用しない</td>' . "\n" .
'</tr>' . "\n" .
//
'<tr>' . "\n" .
'<tr><th>商品リンクの動作</th>' . "\n" .
'<td><input type="radio" name="windowtarget" value="self"' . $selfwindow . ' /> 同じウィンドウ( target 指定なし )<br />' . "\n" .
'<input type="radio" name="windowtarget" value="newwin"' . $newwindow . ' /> 新規ウィンドウ( target="_blank" )</td>' . "\n" .
'</tr>' . "\n" .
'<tr><th>商品詳細の表示スタイル</th>' . "\n" .
'<td><input type="radio" name="layout_type" value="0"' . $default_layout . ' /> 画像、タイトル、出版社、発売時期、著者、価格、本のタイプ、ページ数、ISBN( 初期設定。本以外はこれに準ずる項目 )<br />' . "\n" .
'<input type="radio" name="layout_type" value="1"' . $medium_layout . ' /> 画像、タイトル、出版社、著者、発売時期( 初期設定から価格情報とコード情報を省略 )<br />' . "\n" .
'<input type="radio" name="layout_type" value="2"' . $simple_layout . ' /> 画像とタイトルのみ<br />' . "\n" .
'<input type="radio" name="layout_type" value="3"' . $noimage_layout . ' /> タイトルのみ</td>' . "\n" .
'</tr>' . "\n" .
'<tr><th>CD ジャケットの画像サイズ</th>' . "\n" .
'<td><input type="radio" name="jacketimgsize" value="small"' . $s_jacketsize . ' /> 小サイズ( 初期設定 )<br />' . "\n" .
'<input type="radio" name="jacketimgsize" value="medium"' . $m_jacketsize . ' /> 中サイズ</td>' . "\n" .
'</tr>' . "\n" .
'<tr><th>その他( 本、DVD、CD 以外 )の画像サイズ</th>' . "\n" .
'<td><input type="radio" name="goodsimgsize" value="small"' . $s_goodssize . ' /> 小サイズ( 初期設定 )<br />' . "\n" .
'<input type="radio" name="goodsimgsize" value="medium"' . $m_goodssize . ' /> 中サイズ</td>' . "\n" .
'</tr>' . "\n" .
'</table>' . "\n" .
'<p class="submit"><input type="submit" name="Submit" value="設定を保存する »" /></p>' . "\n" .
'</form>' . "\n" .
'</div>' . "\n";
echo $tmkm_amazon_admin_html;
}
function tmkm_amazon_add_options() {
global $tmkm_amazon_php;
// Add a new menu under Options:
add_options_page(
'Wp_Tmkm_Amazon',
'Wp_Tmkm_Amazon',
8,
$tmkm_amazon_php,
array(&$this, 'tmkm_amazon_options_page')
);
}
function tmkm_amazon_save_options() {
// create array
$tmkm_amazon_options = array(
'associatesid' => $_POST['associatesid'],
'windowtarget' => $_POST['windowtarget'],
'jacketimgsize' => $_POST['jacketimgsize'],
'goodsimgsize' => $_POST['goodsimgsize'],
'layout_type' => $_POST['layout_type'],
// ** 追加 (2009/6/22)
'devtoken' => $_POST['devtoken'],
'secretkey' => $_POST['secretkey'],
// ここまで **
// ** 追加 (2011/9/5)
'homedisp' => $_POST['homedisp'],
// ここまで **
);
update_option('wp_tmkm_admin_options', $tmkm_amazon_options);
$options_saved = true;
}
}
/******************************************************************************
* 記事本文中に Amazon から取得した商品情報を表示
*****************************************************************************/
class WpTmkmAmazonView {
/**
* The Constructor
*
* @param none
* @return none
*/
function WpTmkmAmazonView() {
$this->makedetailview = & new MakeAmazonHtml();
}
/**
* 記事本文中のコードを個別商品表示 HTML に置き換える
*
* @param $content
* @return $transformedstring
*/
function _replacestrings($content) { // 記事本文中の呼び出しコードを変換
global $post,$tmkm_amazon_settings;
// $poststring = '/\[tmkm-amazon type\=([a-z]+)\]([a-zA-Z0-9,]+)\[\/tmkm-amazon\]/';
$poststring = '/\[tmkm-amazon\]([a-zA-Z0-9,]+)\[\/tmkm-amazon\]/';
$transformedstring = $content;
if( !is_home() || ( is_home() && $tmkm_amazon_settings['homedisp'] == 0 ) ){
if( preg_match_all($poststring, $content, $regs1) ) {
for ($i=0; $i<count($regs1[0]); $i++) {
// $type = $regs1[1][$i];
$SearchString = $regs1[1][$i];
// $display = $this->makedetailview->format_amazon( $SearchString, $type );
$display = $this->makedetailview->format_amazon( $SearchString, 'detail' );
if( ereg( $SearchString, $regs1[0][$i], $str ) ) { // ASINコードの置換
$transformedstring = str_replace($regs1[0][$i], $display, $transformedstring);
}
}
}
$transformedstring = str_replace('<p><div id="tmkm-amazon-view">', '<div id="tmkm-amazon-view">', $transformedstring);
$transformedstring = str_replace('<hr class="tmkm-amazon-clear" /></div></p>', '<hr class="tmkm-amazon-clear" /></div>', $transformedstring);
}
return $transformedstring;
}
/**
* PHP 関数として Amazon の個別商品 HTML を呼び出す
*
* @param $SearchString ( ASIN )
* @param $type ( book / dvd / cd )
* @return echo $display ( HTML )
*/
function tmkm_amazon_view( $SearchString ) { // PHPファイル中に記述する関数
$display = $this->makedetailview->format_amazon( $SearchString, 'detail' );
echo $display;
}
}
/******************************************************************************
* PHP を記述した箇所にブログの記事で参照している Amazon の商品一覧を表示
*****************************************************************************/
class WpTmkmAmazonList {
var $sql;
var $ordersql;
function WpTmkmAmazonList() {
$this->makedetailview = & new MakeAmazonHtml();
$this->sql = '';
$this->ordersql = '';
}
function tmkm_amazon_list( $attr ) {
global $wpdb, $tmkm_amazon_settings;
extract( shortcode_atts( array(
'orderby' => 'post_id',
'order' => 'asc',
), $attr ));
$orderby = strval( $orderby );
$order = strval( $order );
$output = '';
switch( $orderby ) {
case 'post_id': $this->ordersql = "$wpdb->posts.ID " . $order; break;
case 'post_title': $this->ordersql = "$wpdb->posts.post_title " . $order; break;
case 'post_date': $this->ordersql = "$wpdb->posts.post_date " . $order; break;
case 'modified_date': $this->ordersql = "$wpdb->posts.post_modified " . $order; break;
}
$this->sql =
"SELECT " .
"ID, post_title, " .
"DATE_FORMAT(post_date, '%Y/%m/%d') as mdate, " .
"meta_key, meta_value " .
"FROM " .
"$wpdb->posts, $wpdb->postmeta " .
"WHERE " .
"$wpdb->posts.ID = $wpdb->postmeta.post_id AND " .
"$wpdb->posts.post_date <= NOW() AND " .
"$wpdb->posts.post_status = 'publish' AND " .
"$wpdb->postmeta.meta_key = 'tmkm-amazon' " .
"ORDER BY " .
$this->ordersql;
$this->countsql =
"SELECT " .
"COUNT(*) " .
"FROM " .
"$wpdb->posts, $wpdb->postmeta " .
"WHERE " .
"$wpdb->posts.ID = $wpdb->postmeta.post_id AND " .
"$wpdb->posts.post_date <= NOW() AND " .
"$wpdb->posts.post_status = 'publish' AND " .
"$wpdb->postmeta.meta_key = 'tmkm-amazon' ";
$PostRetainAsin = $wpdb->get_results($this->sql);
$postcount = $wpdb->get_var($this->countsql);
$itemnum = '1';
// $itemperpage = $tmkm_amazon_settings['itemperpage'];
if( $PostRetainAsin ) {
$heredoc = '<div id="amazonlist">' . "\n";
foreach( $PostRetainAsin as $asinlist ) {
$asins = explode(',',$asinlist->meta_value);
foreach( $asins as $asin ) {
$permalink = get_permalink($asinlist->ID);
$display = $this->makedetailview->format_amazon( $asin, 'list' );
$pagenum = (int)( $itemnum/6 );
$heredoc .=
'<dl>' . "\n" .
"<dt><a href=\"$permalink\">$asinlist->post_title</a></dt>\n" .
'<dd>' . "\n" .
"<p class=\"p-date\">記事投稿日:$asinlist->mdate</p>\n" .
$display . "\n" .
// "<p>$itemnum / $postcount</p>\n" .
'</dd>' . "\n" .
'</dl>' . "\n";
if( $itemnum == $pagenum*5 ) {
$heredoc .= '<!--nextpage-->' . "\n";
}
$itemnum ++;
}
}
$heredoc .= '</div>' . "\n";
} else {
$heredoc = "<p>まだブログで書籍が紹介されていません。</p>\n";
}
$output .= $heredoc;
return $output;
}
}
/******************************************************************************
* Amazon ECS から取得した XML から HTML を生成
*****************************************************************************/
class MakeAmazonHtml {
var $plugin_path;
var $mediumimgfile;
var $smallimgfile;
var $associatesid;
function MakeAmazonHtml() {
$this->amazonparse = & new GetAmazonXmlParse();
$this->generalfunclib = & new generalFuncLibrary();
}
/**
* Amazon 商品の HTML ソースを生成
* @param $SearchString ( ASIN )
* @param $mediatype ( book / dvd / cd )
* @return $output ( HTML )
*/
function format_amazon( $SearchString, $formattype ) {
global $tmkm_amazon_settings, $tmkm_plugin_directory;
$this->mediumimgfile = '/amazon_noimg.png';
$this->smallimgfile = '/amazon_noimg_small.png';
$associatesid = $tmkm_amazon_settings['associatesid'];
switch( $tmkm_amazon_settings['windowtarget']) {
case 'newwin': $windowtarget = ' target="_blank"'; break;
case 'self': $windowtarget = '';
}
$output = '';
if( strlen( $SearchString ) == 13 ){
$SearchString = $this->generalfunclib->calc_chkdgt_isbn10( substr( $SearchString, 3, 9 ) );
}
// --- Call Amazon XML function ---
if(( $formattype == 'list' ) || ( $tmkm_amazon_settings['layout_type'] == '2' )) {
$AmazonXml = $this->amazonparse->getamazonxml( $associatesid, $SearchString, 'single', '', 'Images,Small', '' );
} elseif( $tmkm_amazon_settings['layout_type'] == '3' ) {
$AmazonXml = $this->amazonparse->getamazonxml( $associatesid, $SearchString, 'single', '', 'ItemAttributes', '' );
} else {
$AmazonXml = $this->amazonparse->getamazonxml( $associatesid, $SearchString, 'single', '', 'Medium,Offers', '' );
}
// DEBUG
/*
echo "<pre>\n";
print_r($AmazonXml);
echo "</pre>\n";
*/
// --- Get results of the Amazon function ---
if( false === $AmazonXml ){ // Amazon function was returned false, so AWS is down
$output = '<p>アマゾンのサーバでエラーが起こっているかもしれません。<br />一度ページを再読み込みしてみてください。</p>';
}else{ // Amazon function returned XML data
$status = $AmazonXml["ItemLookupResponse"]["Items"]["Request"];
if( $status["IsValid"] == 'False' ){ // Request is invalid
$output = '<p>与えられたリクエストが正しくありません</p>';
}else{ // results were found, so display the products
// --- Display the product data returned from the XML ---
$item = $AmazonXml["ItemLookupResponse"]["Items"]["Item"];
$url = $this->amazonparse->get_amazon_text($item,'url');
$Title = $this->amazonparse->get_amazon_text($item,'title');
$ProductGroup = $this->amazonparse->get_amazon_text($item,'productgroup');
if( $tmkm_amazon_settings['layout_type'] != '3' ) {
$mediumimage = $this->amazonparse->get_goods_image( $item,'medium' );
if( $mediumimage == '' ) { $mediumimage = $tmkm_plugin_directory . $this->mediumimgfile; }
$smallimage = $this->amazonparse->get_goods_image( $item,'small' );
if( $smallimage == '' ) { $smallimage = $tmkm_plugin_directory . $this->smallimgfile; }
switch( $tmkm_amazon_settings['jacketimgsize'] ) {
case 'small': $cdjacketimg = $smallimage; break;
case 'medium': $cdjacketimg = $mediumimage; break;
}
switch( $tmkm_amazon_settings['goodsimgsize'] ) {
case 'small': $goodsimage = $smallimage; break;
case 'medium': $goodsimage = $mediumimage; break;
}
}
if( $tmkm_amazon_settings['layout_type'] < 2 ) {
$Manufacturer = $this->amazonparse->get_amazon_text($item,'manufacturer');
$Binding = $this->amazonparse->get_amazon_text($item,'binding');
$ReleaseDate = $this->amazonparse->get_amazon_text($item,'releasedate');
$ASIN = $this->amazonparse->get_amazon_text($item,'asincode');
$EANcode = $this->amazonparse->get_amazon_text($item,'eancode');
if( $tmkm_amazon_settings['layout_type'] == 0 ) {
$Price = $this->amazonparse->get_amazon_text($item,'price');
$OurPrice = $this->amazonparse->get_amazon_text($item,'ourprice');
$LowestUsedPrice = $this->amazonparse->get_amazon_text($item,'lowestusedprice');
$ISBN10 = $this->amazonparse->get_amazon_text($item,'isbn10');
if( $LowestUsedPrice != '' ) {
$usedpricememo = ' ( 中古価格 '. $LowestUsedPrice . ' より )';
} else {
$usedpricememo = '';
}
}
switch( $ProductGroup ){
case Book:
$Role = $this->amazonparse->get_amazon_text($item,'role');
$Pages = $this->amazonparse->get_amazon_text($item,'pages');
$Author = $this->amazonparse->get_amazon_text($item,'author');
$PublicationDate = $this->amazonparse->get_amazon_text($item,'publicationdate');
break;
case DVD:
$RunningTime = $this->amazonparse->get_amazon_text($item,'runningtime');
$numofdisc = $this->amazonparse->get_amazon_text($item,'numofdisc');
break;
case Music:
$Format = $this->amazonparse->get_amazon_text($item,'format');
$Artist = $this->amazonparse->get_amazon_text($item,'artist');
break;
}
}
if( $tmkm_amazon_settings['layout_type'] != 3 ) { $output = '<div id="tmkm-amazon-view">' . "\n"; }
if( $formattype == 'detail' ) {
if( $ProductGroup == 'Book' ){
switch ( $tmkm_amazon_settings['layout_type'] ) {
case 3: // noimage( Title only )
$output .= '<a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
break;
case 2: // simple( Image + Title )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $mediumimage . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
break;
case 1: // medium( Fully - Price & Code )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $mediumimage . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
if( $Author !="" ) {
$output .= "\t" . "<p><em>著者/訳者:</em>";
if( count($Author) == 1 ) {
$output .= $Author;
} else {
foreach($Author as $auth){ $output .= $auth.' '; }
}
$output .= '</p>' . "\n";
}
$output .= "\t" . "<p><em>出版社:</em>$Manufacturer( $PublicationDate )</p>" . "\n";
$output .= "\t" . "<p>$Binding ( $Pages ページ )</p>" . "\n";
break;
case 0: // Fully
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $mediumimage . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
if( $Author !="" ) {
$output .= "\t" . "<p><em>著者/訳者:</em>";
if( count($Author) == 1 ) {
$output .= $Author;
} else {
foreach($Author as $auth){ $output .= $auth.' '; }
}
$output .= '</p>' . "\n";
}
$output .= "\t" . "<p><em>出版社:</em>$Manufacturer( $PublicationDate )</p>" . "\n";
$output .= "\t" . "<p><em>定価:</em>$Price</p>" . "\n";
if( $OurPrice != '' ) {
$output .= "\t" . "<p><em>Amazon価格:</em>$OurPrice</p>" . "\n";
}
$output .= "\t" . "<p>$Binding ( $Pages ページ )</p>" . "\n";
$output .= "\t" . "<p>ISBN-10 : $ISBN10</p>" . "\n";
$output .= "\t" . "<p>ISBN-13 : $EANcode</p>" . "\n";
break;
}
} elseif( $ProductGroup == 'DVD' ) {
switch ( $tmkm_amazon_settings['layout_type'] ) {
case 3: // noimage( Title only )
$output .= '<a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
break;
case 2: // simple( Image + Title )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $mediumimage . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
break;
case 1: // medium( Fully - Price & Code )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $mediumimage . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
$output .= "\t" . "<p><em>販売元:</em>$Manufacturer( $ReleaseDate )</p>" . "\n";
$output .= "\t" . "<p><em>時間:</em>$RunningTime 分</p>" . "\n";
$output .= "\t" . "<p>$numofdisc" . " 枚組 ( " . $Binding . " )</p>" . "\n";
break;
case 0: // Fully
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $mediumimage . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
$output .= "\t" . "<p><em>販売元:</em>$Manufacturer( $ReleaseDate )</p>" . "\n";
$output .= "\t" . "<p><em>定価:</em>$Price$usedpricememo</p>" . "\n";
if( $OurPrice != '' ) {
$output .= "\t" . "<p><em>Amazon価格:</em>$OurPrice</p>" . "\n";
}
$output .= "\t" . "<p><em>時間:</em>$RunningTime 分</p>" . "\n";
$output .= "\t" . "<p>$numofdisc" . " 枚組 ( " . $Binding . " )</p>" . "\n";
break;
}
} elseif( $ProductGroup == 'Music' ) {
switch ( $tmkm_amazon_settings['layout_type'] ) {
case 3: // noimage( Title only )
$output .= '<a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
break;
case 2: // simple( Image + Title )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $cdjacketimg . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
break;
case 1: // medium( Fully - Price & Code )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $cdjacketimg . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
$output .= ' / ' . $Artist . "</p>" . "\n";
$output .= "\t" . "<p>$Manufacturer( $ReleaseDate )</p>" . "\n";
break;
case 0: // Fully
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $cdjacketimg . '" border="0" alt="" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
$output .= ' / ' . $Artist;
$output .= " / $Binding ( $ProductGroup )</p>\n";
$output .= "\t" . "<p>$Manufacturer( $ReleaseDate )</p>" . "\n";
$output .= "\t" . "<p><em>定価:</em>$Price$usedpricememo</p>" . "\n";
break;
}
} else {
switch ( $tmkm_amazon_settings['layout_type'] ) {
case 3: // noimage( Title only )
$output .= '<a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
break;
case 2: // simple( Image + Title )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $goodsimage . '" border="0" alt="' . $Title . '" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
break;
case 1: // medium( Fully - Price & Code )
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $goodsimage . '" border="0" alt="' . $Title . '" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
if( $ReleaseDate != '' ) { $output .= "\t" . "<p><em>発売日:</em>$ReleaseDate</p>" . "\n"; }
break;
case 0: // Fully
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $goodsimage . '" border="0" alt="' . $Title . '" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a>';
if( $Price != '' ) {
$output .= "\t" . "<p><em>定価:</em>$Price</p>" . "\n";
} elseif( $LowestUsedPrice != '' ) {
$output .= "\t" . "<p><em>中古価格: </em>$LowestUsedPrice より</p>" . "\n";
}
if( $OurPrice != '' ) {
$output .= "\t" . "<p><em>Amazon価格:</em>$OurPrice</p>" . "\n";
}
$output .= "\t" . "<p>カテゴリ:$Binding</p>\n";
if( $ReleaseDate != '' ) { $output .= "\t" . "<p><em>発売日:</em>$ReleaseDate</p>" . "\n"; }
break;
}
}
if( $tmkm_amazon_settings['layout_type'] != 3 ) { $output .= '<hr class="tmkm-amazon-clear" /></div>'; }
} elseif( $formattype == 'list' ) {
$output = "\t" . '<p><a href="'.$url.'"' . $windowtarget . '><img src="' . $smallimage . '" border="0" alt="' . $Title . '" /></a></p>' . "\n";
$output .= "\t" . '<p><a href="'.$url.'"' . $windowtarget . '>' . $Title . '</a></p>' . "\n";
}
}
}
return $output;
}
}
/******************************************************************************
* 記事投稿画面に検索フォームを追加
*****************************************************************************/
class WpTmkmAmazonFind {
var $searchphp_path;
function InsertSearchForm() {
global $wpdb, $tmkm_amazon_settings, $tmkm_plugin_directory, $tmkm_amazon_search_php;
$associatesid = $tmkm_amazon_settings['associatesid'];
$this->searchphp_path = $tmkm_plugin_directory . $tmkm_amazon_search_php;
$this->searchphp_path .= '?AID=' . $associatesid;
?>
<div id="wptmkmamazon" class="postbox if-js-closed">
<h3>wp-tmkm-amazon</h3>
<div class="inside">
<p>iframe 内に検索フォームが表示されない方は<a href="<?php echo $this->searchphp_path; ?>" target="_blank">別ウィンドウ</a>で検索をお願いします。</p>
<iframe id="uploading" frameborder="0" width="600" height="500" src="<?php echo $this->searchphp_path; ?>">IFRAME による表示がサポートされている環境が必要です。</iframe>
</div>
</div>
<?php
}
}
if(!function_exists('tmkm_amazon_view')) {
function tmkm_amazon_view($Searchstring) {
global $wpTmkmAmazonView;
$wpTmkmAmazonView->tmkm_amazon_view($Searchstring);
}
}
function add_tmkmamazon_stylesheet(){
global $tmkm_plugin_directory;
?>
<link rel="stylesheet" href="<?php echo $tmkm_plugin_directory; ?>/tmkm-amazon.css" type="text/css" media="screen" />
<?php
}
/******************************************************************************
* WpTmkmAmazon WordPress Plugin Class & Funtcion Define
*****************************************************************************/
$wpTmkmAmazonView = & new WpTmkmAmazonView();
$wpTmkmAmazonList = & new WpTmkmAmazonList();
$wpTmkmAmazonFind = & new WpTmkmAmazonFind();
$wpTmkmAmazonAdmin = & new WpTmkmAmazonAdmin();
add_action('wp_head', 'add_tmkmamazon_stylesheet');
add_action('admin_menu', array(&$wpTmkmAmazonAdmin, 'tmkm_amazon_add_options')); // Insert the Admin panel.
if ( $_POST['action'] == 'save_options' ){
add_action('admin_menu', array(&$wpTmkmAmazonAdmin, 'tmkm_amazon_save_options'));
}
add_shortcode('tmkm-amazon-list', array (&$wpTmkmAmazonList, 'tmkm_amazon_list'));
add_filter('the_content', array(&$wpTmkmAmazonView, '_replacestrings'));
add_filter('edit_form_advanced', array(&$wpTmkmAmazonFind, 'InsertSearchForm'));
add_filter('edit_page_form', array(&$wpTmkmAmazonFind, 'InsertSearchForm'));
?>