diff --git a/amazon.plugin.php b/amazon.plugin.php
index ceb7bb1..818a31c 100755
--- a/amazon.plugin.php
+++ b/amazon.plugin.php
@@ -171,7 +171,7 @@ public function info()
{
return array(
'name' => 'Amazon',
- 'version' => '0.01',
+ 'version' => '0.02',
'url' => 'http://ayu.commun.jp/',
'author' => 'ayunyan',
'authorurl' => 'http://ayu.commun.jp/',
@@ -193,6 +193,7 @@ public function action_plugin_activation($file)
Options::set( 'amazon:country', 'com' );
Options::set( 'amazon:associate_tag', '' );
+ Options::set( 'amazon:template', 'reviewsummary' );
}
/**
@@ -218,9 +219,21 @@ public function action_plugin_ui($plugin_id, $action)
{
if ( $plugin_id != $this->plugin_id() ) return;
if ( $action == _t( 'Configure' ) ) {
+ $template_dir = dirname( $this->get_file() ) . DIRECTORY_SEPARATOR . 'templates';
+ $templates = array();
+ if ( $dh = opendir( $template_dir ) ) {
+ while ( ( $file = readdir( $dh ) ) !== false ) {
+ if ( substr( $file, -4 ) == '.php' ) {
+ $template = substr( $file, 0, strlen( $file ) - 4 );
+ $templates[$template] = $template;
+ }
+ }
+ }
+
$ui = new FormUI( strtolower( get_class( $this ) ) );
$country = $ui->add( 'select', 'country', _t( 'Country: ' ), $this->countries, Options::get( 'amazon:country' ) );
$associate_tag = $ui->add( 'text', 'associate_tag', _t( 'Associate Tag: ' ) );
+ $template = $ui->add( 'select', 'template', _t( 'Template: ' ), $templates, Options::get( 'amazon:template' ) );
$ui->on_success( array( $this, 'updated_config' ) );
$ui->out();
}
@@ -248,6 +261,7 @@ public function action_admin_header($theme)
{
if ( $theme->admin_page != 'publish' ) return;
Stack::add( 'admin_header_javascript', $this->get_url() . '/js/amazon.js' );
+ Stack::add( 'admin_stylesheet', array($this->get_url() . '/css/amazon.css', 'screen') );
}
/**
@@ -274,7 +288,13 @@ public function action_before_act_admin_ajax()
$keywords = InputFilter::filter($handler_vars['keywords']);
$search_index = InputFilter::filter($handler_vars['search_index']);
- $result = $this->item_search( $keywords, $search_index );
+ if ( empty( $handler_vars['page'] ) ) {
+ $page = 1;
+ } else {
+ $page = InputFilter::filter($handler_vars['page']);
+ }
+
+ $result = $this->item_search( $keywords, $search_index, $page );
$xml = simplexml_load_string( $result );
if ( (string)$xml->Items->Request->IsValid != 'True' ) {
@@ -288,9 +308,16 @@ public function action_before_act_admin_ajax()
}
$output = array();
-
$output['TotalResults'] = (int)$xml->Items->TotalResults;
$output['TotalPages'] = (int)$xml->Items->TotalPages;
+ $output['CurrentPage'] = $page;
+ $output['Start'] = ($page - 1) * 10 + 1;
+ $output['End'] = $output['Start'] + 10;
+ if ( $output['End'] > $output['TotalResults'] ) $output['End'] = $output['TotalResults'];
+ $output['HasPrev'] = false;
+ $output['HasNext'] = false;
+ if ( $page != 1 ) $output['HasPrev'] = true;
+ if ( $page < $output['TotalPages'] ) $output['HasNext'] = true;
$output['Items'] = array();
for ( $i = 0; $i < count( $xml->Items->Item ); $i++ ) {
$item = array();
@@ -325,31 +352,8 @@ public function action_before_act_admin_ajax()
$item =& $xml->Items->Item;
ob_start();
-?>
-
-
-
-
-
-
-ItemAttributes->Creator[0] ) ) echo (string)$item->ItemAttributes->Creator[0] . '
';
- if ( isset( $item->ItemAttributes->Publisher ) ) echo (string)$item->ItemAttributes->Publisher . '
';
- if ( isset( $item->SalesRank ) ) echo _t('Sales Rank: ') . (int)$item->SalesRank . '
';
- if ( isset( $item->CustomerReviews->AverageRating ) ) {
- echo '
';
- echo _t('Average Rating: ') . $this->ratingToStarImage( (float)$item->CustomerReviews->AverageRating ) . '
';
- for ( $i = 0; $i < 5; $i++ ) {
- if ( !isset( $item->CustomerReviews->Review[$i]) ) break;
- echo $this->ratingToStarImage( (int)$item->CustomerReviews->Review[$i]->Rating ) . ' ' . (string)$item->CustomerReviews->Review[$i]->Summary . '
';
- }
- }
-?>
-
-
-
-
-get_file() ) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php' );
$output['html'] = ob_get_contents();
ob_end_clean();
@@ -375,12 +379,13 @@ public function filter_publish_controls($controls)
+
access_key . '&Operation=ItemSearch&ResponseGroup=Small,Images,ItemAttributes&Keywords=' . urlencode($keywords) . '&SearchIndex=' . $search_index;
+ $url = 'http://ecs.amazonaws.' . Options::get( 'amazon:country' ) . '/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=' . $this->access_key . '&Operation=ItemSearch&ResponseGroup=Small,Images,ItemAttributes&Keywords=' . urlencode($keywords) . '&SearchIndex=' . $search_index . '&ItemPage=' . $page;
$associate_tag = Options::get( 'amazon:associate_tag' );
if ( !empty( $associate_tag ) ) $url .= '&AssociateTag=' . $associate_tag;
diff --git a/css/amazon.css b/css/amazon.css
new file mode 100755
index 0000000..04c3890
--- /dev/null
+++ b/css/amazon.css
@@ -0,0 +1,22 @@
+.amazon-result-nav {
+ margin: 20px 0px;
+ padding: 10px 0px;
+ background-color: #1e1e1e;
+ border-radius: 6px;
+ -moz-border-radius: 6px;
+ -webkit-border-radius: 6px;
+ -khtml-border-radius: 6px;
+ text-align: center;
+}
+
+.amazon-result-nav img {
+ margin: 0px;
+ padding: 0px;
+ vertical-align: middle;
+}
+
+.amazon-result-nav span {
+ margin: 0px 15px;
+ padding: 0px;
+}
+
diff --git a/img/backward-disabled.png b/img/backward-disabled.png
new file mode 100755
index 0000000..a507e5b
Binary files /dev/null and b/img/backward-disabled.png differ
diff --git a/img/backward.png b/img/backward.png
new file mode 100755
index 0000000..cb0daa0
Binary files /dev/null and b/img/backward.png differ
diff --git a/img/foward-disabled.png b/img/foward-disabled.png
new file mode 100755
index 0000000..e51374d
Binary files /dev/null and b/img/foward-disabled.png differ
diff --git a/img/foward.png b/img/foward.png
new file mode 100755
index 0000000..0ffcf20
Binary files /dev/null and b/img/foward.png differ
diff --git a/js/amazon.js b/js/amazon.js
index b2f4b2c..95a606c 100755
--- a/js/amazon.js
+++ b/js/amazon.js
@@ -1,20 +1,27 @@
var amazonSearch = {
+ query: {},
init: function() {
- $('#amazon_search').click(function () {
+ $('#amazon-search').click(function () {
amazonSearch.search();
});
+ $('#amazon-keywords').keypress(function (e) {
+ if (e.keyCode == 13) { // Enter
+ amazonSearch.search();
+ return false;
+ }
+ });
},
search: function() {
- spinner.start();
+ amazonSearch.startSpinner();
- var query= {};
-
- query['search_index'] = $('#amazon_search_index' ).children("option[@selected]").val();
- query['keywords'] = $('#amazon_keywords' ).val();
- $.post(habari.url.habari + '/admin_ajax/amazon_search', query, amazonSearch.searchShow, 'json');
+ amazonSearch.query= {};
+ amazonSearch.query['search_index'] = $('#amazon-search-index' ).children("option[@selected]").val();
+ amazonSearch.query['keywords'] = $('#amazon-keywords' ).val();
+ amazonSearch.query['page'] = 1;
+ $.post(habari.url.habari + '/admin_ajax/amazon_search', amazonSearch.query, amazonSearch.searchShow, 'json');
},
searchShow: function(result) {
- spinner.stop();
+ amazonSearch.stopSpinner();
if (result.errorMessage) {
humanMsg.displayMsg(result.errorMessage);
@@ -24,8 +31,24 @@ var amazonSearch = {
var amazon_result = $('#amazon-result');
amazon_result.empty();
var html = '';
+ var nav = '';
+
+ nav += '';
+ if ( result.HasPrev ) {
+ nav += '
';
+ } else {
+ nav += '
';
+ }
+ nav += '
' + result.Start + ' - ' + result.End + ' of ' + result.TotalResults + '';
+ if ( result.HasNext ) {
+ nav += '
';
+ } else {
+ nav += '
';
+ }
+ nav += '
';
+ html += '' + nav;
$( result.Items ).each( function() {
- html += '
';
+ html += '
';
html += '
' + this.Price + '
';
- html += '
';
+ html += '
';
});
- amazon_result.append(html);
+ html += nav + '';
+ amazon_result.html(html);
+ $('.amazon-prev').click(function () {
+ amazonSearch.prevPage();
+ });
+ $('.amazon-next').click(function () {
+ amazonSearch.nextPage();
+ });
},
insert: function(asin)
{
@@ -55,7 +85,25 @@ var amazonSearch = {
}
habari.editor.insertSelection(result.html);
- }
+ },
+ startSpinner: function() {
+ $('#amazon-result').html('Searching...
');
+ },
+ stopSpinner: function () {
+ $('#amazon-result').empty();
+ },
+ prevPage: function () {
+ amazonSearch.startSpinner();
+
+ amazonSearch.query['page']--;
+ $.post(habari.url.habari + '/admin_ajax/amazon_search', amazonSearch.query, amazonSearch.searchShow, 'json');
+ },
+ nextPage: function () {
+ amazonSearch.startSpinner();
+
+ amazonSearch.query['page']++;
+ $.post(habari.url.habari + '/admin_ajax/amazon_search', amazonSearch.query, amazonSearch.searchShow, 'json');
+ }
}
$(document).ready(function(){
diff --git a/templates/reviewsummary.php b/templates/reviewsummary.php
new file mode 100644
index 0000000..b6d9b99
--- /dev/null
+++ b/templates/reviewsummary.php
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+ItemAttributes->Creator[0] ) ) echo (string)$item->ItemAttributes->Creator[0] . '
';
+ if ( isset( $item->ItemAttributes->Publisher ) ) echo (string)$item->ItemAttributes->Publisher . '
';
+ if ( isset( $item->SalesRank ) ) echo _t('Sales Rank: ') . (int)$item->SalesRank . '
';
+ if ( isset( $item->CustomerReviews->AverageRating ) ) {
+ echo '
';
+ echo _t('Average Rating: ') . $this->ratingToStarImage( (float)$item->CustomerReviews->AverageRating ) . '
';
+ for ( $i = 0; $i < 5; $i++ ) {
+ if ( !isset( $item->CustomerReviews->Review[$i]) ) break;
+ echo $this->ratingToStarImage( (int)$item->CustomerReviews->Review[$i]->Rating ) . ' ' . (string)$item->CustomerReviews->Review[$i]->Summary . '
';
+ }
+ }
+?>
+
+
+
+
\ No newline at end of file