diff --git TODO.txt TODO.txt deleted file mode 100644 index d5cf75f..0000000 --- TODO.txt +++ /dev/null @@ -1,17 +0,0 @@ -$Id$ - -API -* Handle update/delete cases cleanly (currently inefficient) - -Search -* Paged searching -* Advanced search options -* Properly themed search results - -Theming -* Document variables - -Functionality -* Wish lists (separate module? -* Related Books block for nodes (separate module?) -* Reading List module (separate module?) diff --git aat_legacy/aat_legacy.d5-migrate.inc aat_legacy/aat_legacy.d5-migrate.inc deleted file mode 100644 index 2b11b52..0000000 --- aat_legacy/aat_legacy.d5-migrate.inc +++ /dev/null @@ -1,66 +0,0 @@ -nid] = $node->title; - - $context['sandbox']['progress']++; - $context['sandbox']['current_node'] = $node->nid; - $context['message'] = t('Processing nid %nid, %title', array('!url' => url("node/$node->nid"), '%nid' => $node->nid, '%title' => $node->title)); - } - } -} -/** - * Batch 'finished' callback - */ -function _aat_legacy_migrate_fields_finished($success, $results, $operations) { - if ($success) { - $message = t('%count legacy fields (amazonnodes and links) were imported.', array('%count' => count($results))); - $message .= theme('item_list', $results); - } - else { - // An error occurred. - // $operations contains the operations that remained unprocessed. - $error_operation = reset($operations); - $message = t('An error occurred while processing %op. with arguments = %args.', array('%op' => $error_operation[0], '%args' => print_r($error_operation[0], TRUE))); - } - drupal_set_message($message); -} - -/** - * Process one node. - * @param $nid - * The nid to which we are to add values. - * @param $type - * The ntype field from amazonnode table: the content type we're working with. - * @return - * the updated node. - */ -function _aat_legacy_migrate_from_d5($nid, $type) { - $results = db_query("SELECT asin, ntype FROM {amazonnode} an WHERE an.nid = %d and an.ntype = '%s'", $nid, $type); - $dirty = FALSE; - $node = node_load($nid); - - while ($asin = db_fetch_object($results)) { - // if (!in_array($asin->asin, array_keys(array_values($node->field_legacy_asin)))) { - $node->field_legacy_asin[]['asin'] = $asin->asin; - // } - } - node_save($node); - $sql = "DELETE FROM {amazonnode} WHERE nid = %d AND ntype = '%s'"; - db_query($sql, $nid, $type); - - return $node; -} \ No newline at end of file diff --git aat_legacy/aat_legacy.info aat_legacy/aat_legacy.info deleted file mode 100644 index ea7f0eb..0000000 --- aat_legacy/aat_legacy.info +++ /dev/null @@ -1,8 +0,0 @@ -; $Id$ -name = Amazon legacy importer -description = This module is used only to import legacy Drupal 5 Amazontools data. After upgrade it should be disabled. -package = Amazon -dependencies[] = amazon -dependencies[] = asin -core = 6.x -php = 5.2 diff --git aat_legacy/aat_legacy.install aat_legacy/aat_legacy.install deleted file mode 100644 index a76649e..0000000 --- aat_legacy/aat_legacy.install +++ /dev/null @@ -1,10 +0,0 @@ - "Amazontools Legacy Import", - 'page callback' => 'drupal_get_form', - 'access arguments' => array('administer site configuration'), - 'page arguments' => array('aat_legacy_import_form') - ); - return $items; -} - -/** - * Form to start the import process. - */ -function aat_legacy_import_form() { - $form = array(); - $form['explanation'] = array( - '#type' => 'markup', - '#prefix' => "
'. print_r($form_state['amazon_item'], TRUE) .''; + $markup = theme('amazon_item', array('item' => $form_state['amazon_item'], 'style' => 'default')); + $markup .= '
' . print_r($form_state['amazon_item'], TRUE) . ''; $form['item_data'] = array( '#type' => 'markup', - '#value' => $markup, + '#markup' => $markup, '#weight' => 10, ); } @@ -131,7 +134,8 @@ function amazon_test_form_submit($form, &$form_state) { // causes a serialization operation. Whoops. $form_state['amazon_item'] = $item; $form_state['rebuild'] = TRUE; - } else { + } + else { drupal_set_message(t("Test failed for this ASIN. Please check the !link for messages.", array('!link' => l(t("error log"), 'admin/reports/dblog')))); } } diff --git amazon.admin.js amazon.admin.js index 1dfc277..5f9579a 100644 --- amazon.admin.js +++ amazon.admin.js @@ -1,24 +1,28 @@ -// $Id$ +//$Id$ +Drupal.behaviors.amazon = { + attach: { -jQuery(document).ready(function(){ jQuery("#edit-amazon-associate-setting").bind("change", function() { - if (this.value == 'custom') { - $("#amazon-associate-id-wrapper").show('fast'); - } - else { - $("#amazon-associate-id-wrapper").hide('fast'); - } - return false; -}) -}); - -jQuery(document).ready( - function(){ jQuery("#edit-amazon-cache").bind("change", function() { - if (this.checked == true) { - $("#amazon-storage-details").show('fast'); - } - else { - $("#amazon-storage-details").hide('fast'); - } - return false; + jQuery(document).ready(function(){ jQuery("#edit-amazon-associate-setting").bind("change", function() { + if (this.value == 'custom') { + $("#amazon-associate-id-wrapper").show('fast'); + } + else { + $("#amazon-associate-id-wrapper").hide('fast'); + } + return false; }) -}); + }); + + jQuery(document).ready( + function(){ jQuery("#edit-amazon-cache").bind("change", function() { + if (this.checked == true) { + $("#amazon-storage-details").show('fast'); + } + else { + $("#amazon-storage-details").hide('fast'); + } + return false; + }) + }); +} +}; \ No newline at end of file diff --git amazon.info amazon.info index 959fe18..6e73357 100644 --- amazon.info +++ amazon.info @@ -1,5 +1,24 @@ name = Amazon API -description = Provides integration with the Amazon Ecommerce APIs. +description = Provides integration with the Amazon Product Advertising API. package = Amazon -core = 6.x +core = 7.x php = 5.2 + +files[] = amazon-inline-item.tpl.php +files[] = amazon-item-detail.tpl.php +files[] = amazon-item-details.tpl.php +files[] = amazon-item-thumbnail.tpl.php +files[] = amazon-item.tpl.php +files[] = amazon-views-view-row-item.tpl.php +files[] = amazon.admin.inc +files[] = amazon.install +files[] = amazon.module +files[] = amazon.theme.inc +files[] = includes/amazon.views.inc +files[] = includes/amazon_views_plugin_row_amazon_view.inc +files[] = includes/views_handler_field_amazon_date.inc +files[] = includes/views_handler_field_amazon_image.inc +files[] = includes/views_handler_field_amazon_participant.inc +files[] = includes/views_handler_field_amazon_title.inc +files[] = includes/views_handler_filter_amazon_node_module.inc +files[] = includes/views_handler_filter_string_compare.inc diff --git amazon.install amazon.install index 0518d15..dd54281 100644 --- amazon.install +++ amazon.install @@ -1,4 +1,10 @@ l(t("Amazon API Setttings"),'admin/settings/amazon')))); + drupal_set_message(t("The Amazon API must be configured with an Access Key ID and an Amazon AWS Secret Access Key to function. Go to !settings.", array("!settings" => l(t("Amazon API Setttings"), 'admin/settings/amazon')))); $requirement['title'] = t("Amazon AWS Secret Access Key"); $requirement['severity'] = REQUIREMENT_WARNING; $requirement['value'] = t("Not Set"); - $requirement['description'] = t("The Amazon API must be configured with an Access Key ID and an Amazon AWS Secret Access Key to function. Go to !settings.",array("!settings"=>l(t("Amazon API Setttings"),'admin/settings/amazon'))); - return array('amazon_aws_secret_access_key',$requirement); + $requirement['description'] = t("The Amazon API must be configured with an Access Key ID and an Amazon AWS Secret Access Key to function. Go to !settings.", array("!settings" => l(t("Amazon API Setttings"), 'admin/settings/amazon'))); + return array('amazon_aws_secret_access_key', $requirement); } return NULL; @@ -130,7 +137,7 @@ function amazon_schema() { 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), 'asin' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), - 'notes' => array('type' => 'text','not null' => FALSE), + 'notes' => array('type' => 'text', 'not null' => FALSE), 'module' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'amazon'), 'delta' => array('type' => 'int', 'default' => 0), ), @@ -147,171 +154,12 @@ function amazon_schema() { } /** - * Update variables from legacy AAT module where possible. Add mpn field. - */ -function amazon_update_6001() { - $ret = array(); - db_add_column($ret, 'amazon_item', 'mpn', 'varchar(128)'); - - // If the access key is not set, and there is a D5 amazontools access key, use it. - $d6_aws_access_key = variable_get('amazon_aws_access_key', ""); - if (empty($d6_aws_access_key)) { - $old_access_key = variable_get('amazon_awsaccess_key', ""); - if (!empty($old_access_key)) { - variable_set('amazon_aws_access_key', $old_access_key); - variable_del('amazon_awsaccess_key'); - $ret[] = array('success' => TRUE, 'query' => 'Updated Amazon AWS Access Key from D5 AAT'); - } - } - // Bring over the d5 associate id if possible. - $d6_associate_id = variable_get("amazon_custom_associate_id", ""); - if (empty($d6_associate_id)) { - $associate_id = variable_get("amazon_associate_id", ""); - if (!empty($associate_id)) { - variable_set('amazon_custom_associate_id', $associate_id); - variable_set('amazon_associate_setting', 'custom'); - variable_del("amazon_associate_id"); - $ret[] = array('success' => TRUE, 'query' => 'Updated Amazon Associate ID from D5 AAT'); - } - } - if (is_numeric(variable_get('amazon_locale',"US"))) { - variable_del('amazon_locale'); - drupal_set_message(t("The Amazon locale setting was invalid. Please visit the Amazon settings page to correct it.", array('!url' => url('admin/settings/amazon')))); - } - - return $ret; -} - -function amazon_update_6002() { - $ret = array(); - // Make sure that primary keys are correct - db_drop_primary_key($ret, 'amazon_item_image'); - db_add_primary_key($ret, 'amazon_item_image', array('asin', 'size')); - return $ret; -} - -/** - * http://drupal.org/node/426786 - Allow longer image url fields. - */ -function amazon_update_6003() { - $ret = array(); - db_change_field($ret, 'amazon_item_image', 'url', 'url', - array('type' => 'varchar', 'length' => 128, 'not null' => TRUE)); - return $ret; -} - -/** - * Ugly hack for those updating from amazon module in D5. - */ -function amazon_update_6004() { - $ret = array(); - - if (!db_table_exists('amazon_item')) { - drupal_install_schema('amazon'); - $ret[] = array('success' => TRUE, 'query' => 'Force-installed Amazon module tables after botched D5 upgrade.'); - } - - return $ret; -} - -function amazon_update_6005() { - $ret = array(); - db_change_field($ret, 'amazon_item', 'detailpageurl', 'detailpageurl', - array('type' => 'text')); - db_change_field($ret, 'amazon_item', 'brand', 'brand', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'publisher', 'publisher', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'manufacturer', 'manufacturer', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'studio', 'studio', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'label', 'label', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'binding', 'binding', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'releasedate', 'releasedate', - array('type' => 'varchar', 'length' => 64)); - db_change_field($ret, 'amazon_item', 'productgroup', 'productgroup', - array('type' => 'varchar', 'length' => 255)); - db_change_field($ret, 'amazon_item', 'producttypename', 'producttypename', - array('type' => 'varchar', 'length' => 255)); - - return $ret; -} - -function amazon_update_6006() { - $ret = array(); - db_add_field($ret, 'amazon_item', 'invalid_asin', array('type' => 'int', 'default' => 0)); - return $ret; -} - -function amazon_update_6007() { - $ret = array(); - if (variable_get('amazon_associate_setting', 'associate') == 'author') { - variable_del('amazon_associate_setting'); // go with the default. - $ret[] = array('success' => TRUE, 'query' => t('Replaced "author" Amazon associate setting with the default.')); - } - return $ret; -} - -/** - * Change listpriceamount field to numeric. It's not floating anyway. - */ -function amazon_update_6008() { - $ret = array(); - db_change_field($ret, 'amazon_item', 'listpriceamount', 'listpriceamount', - array('type' => 'numeric')); - return $ret; -} - -/** - * Change key on amazon_item_node (again). - * - * It looks like nid should be the correct portion of the key, since there - * is no vid coming in. In fact... There should be no vid. - * - */ -function amazon_update_6009() { - $ret = array(); - db_drop_primary_key($ret, 'amazon_item_node'); - db_add_primary_key($ret, 'amazon_item_node', array('nid', 'asin', 'module')); - return $ret; -} - - -/** - * Change key on editorial reviews, since it shouldn't be primary. - */ -function amazon_update_6010() { - $ret = array(); - db_drop_primary_key($ret, 'amazon_item_editorial_review'); - db_add_index($ret, 'amazon_item_editorial_review', 'amazon_item_editorial_review', array('asin')); - return $ret; -} - -/** - * Add Customer Reviews table so we can handle that. - * @return unknown_type - */ -function amazon_update_6011() { - $schema = amazon_schema(); - if (!db_table_exists('amazon_item_customer_review')) { - db_create_table($ret, 'amazon_item_customer_review', $schema['amazon_item_customer_review']); - } - return $ret; -} - -/** - * Add new elements to the amazon_item table: Lowest price, etc. - * @return unknown_type + * Fix messed up type for currency code in update 6012. */ -function amazon_update_6012() { - db_add_field($ret, 'amazon_item', 'lowestpriceamount', array('type' => 'numeric')); - db_add_field($ret, 'amazon_item', 'lowestpricecurrencycode', array('type' => 'numeric')); - db_add_field($ret, 'amazon_item', 'lowestpriceformattedprice', array('type' => 'varchar', 'length' => 32)); - db_add_field($ret, 'amazon_item', 'amazonpriceamount', array('type' => 'numeric')); - db_add_field($ret, 'amazon_item', 'amazonpricecurrencycode', array('type' => 'numeric')); - db_add_field($ret, 'amazon_item', 'amazonpriceformattedprice', array('type' => 'varchar', 'length' => 32)); - return $ret; +function amazon_update_7100() { + db_change_field('amazon_item', 'lowestpricecurrencycode', 'lowestpricecurrencycode', + array('type' => 'varchar', 'length' => 32)); + db_change_field('amazon_item', 'amazonpricecurrencycode', 'amazonpricecurrencycode', + array('type' => 'varchar', 'length' => 32)); + return(t("Updated currency code column types")); } diff --git amazon.module amazon.module index a0a0db5..9a8c093 100644 --- amazon.module +++ amazon.module @@ -21,7 +21,7 @@ define('AMAZON_IMAGE_SIZES', 'SmallImage,MediumImage,LargeImage'); */ function amazon_menu() { $items = array(); - $items['admin/settings/amazon'] = array( + $items['admin/config/amazon'] = array( 'title' => 'Amazon API', 'description' => 'Global settings for the Amazon Ecommerce API.', 'page callback' => 'drupal_get_form', @@ -31,7 +31,7 @@ function amazon_menu() { 'access arguments' => array('administer amazon'), 'type' => MENU_NORMAL_ITEM ); - $items['admin/settings/amazon/storage'] = array( + $items['admin/config/amazon/storage'] = array( 'title' => 'Storage', 'description' => 'Local data storage settings for Amazon products.', 'page callback' => 'drupal_get_form', @@ -41,7 +41,7 @@ function amazon_menu() { 'access arguments' => array('administer amazon'), 'type' => MENU_LOCAL_TASK ); - $items['admin/settings/amazon/test'] = array( + $items['admin/config/amazon/test'] = array( 'title' => 'Test', 'page callback' => 'drupal_get_form', 'page arguments' => array('amazon_test_form'), @@ -50,14 +50,7 @@ function amazon_menu() { 'access arguments' => array('administer amazon'), 'type' => MENU_LOCAL_TASK ); - $items['admin/settings/amazon/upgrade'] = array( - 'page callback' => '_amazon_upgrade', - 'file' => 'amazon.admin.inc', - 'access callback' => 'user_access', - 'access arguments' => array('administer amazon'), - 'type' => MENU_CALLBACK - ); - $items['admin/settings/amazon/api'] = array( + $items['admin/config/amazon/api'] = array( 'title' => 'Settings', 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK @@ -67,10 +60,15 @@ function amazon_menu() { } /** - * Implementation of hook_perm + * Implementation of hook_permission */ -function amazon_perm() { - return array('administer amazon'); +function amazon_permission() { + return array( + 'administer amazon' => array( + 'title' => t('Administer Amazon module'), + 'description' => t('Configure and test Amazon module.'), + ), + ); } /** @@ -79,19 +77,19 @@ function amazon_perm() { function amazon_theme() { $templates = array( 'amazon_item' => array( - 'arguments' => array('item' => array(), 'style' => 'default'), + 'variables' => array('item' => array(), 'style' => 'default'), 'pattern' => 'amazon_item__', 'template' => 'amazon-item', ), 'amazon_inline_item' => array( - 'arguments' => array('item' => array()), + 'variables' => array('item' => array()), 'template' => 'amazon-inline-item', // Re-use the existing infrastructure. 'preprocess functions' => 'amazon_preprocess_amazon_item', ), // Allows use of whatever is provided in preprocessed $variables. 'amazon_detail' => array( - 'arguments' => array('item' => array(), 'detail' => NULL), + 'variables' => array('item' => array(), 'detail' => NULL), 'template' => 'amazon-item-detail', 'preprocess functions' => array('amazon_preprocess_amazon_item'), ), @@ -103,13 +101,12 @@ function amazon_theme() { /** * hook_preprocess: amazon_item. */ -function amazon_preprocess_amazon_item(&$variables) { +function amazon_preprocess_amazon_item(&$variables, $theme_type) { $item = $variables['item']; - // Do a quick cycle through the simple keys on the item, check_plain() them, // and stick them in the variables collection. - foreach($item as $key => $value) { + foreach ($item as $key => $value) { if (is_string($value)) { $variables[$key] = filter_xss($value); } @@ -117,10 +114,25 @@ function amazon_preprocess_amazon_item(&$variables) { $variables['type'] = _amazon_clean_type($item['producttypename']); $variables['detailpageurl'] = check_url($item['detailpageurl']); - $variables['editorialreview'] = !empty($item['editorialreviews']) ? check_markup($item['editorialreviews'][0]['content']) : ''; - $variables['customerreview'] = !empty($item['customerreviews']) ? check_markup($item['customerreviews'][0]['content']) : ''; + $variables['editorialreview'] = !empty($item['editorialreviews']) ? filter_xss($item['editorialreviews'][0]['content']) : ''; + if (!empty($item['customerreviews'])) { + foreach ($item['customerreviews'] as &$review) { + $review['content'] = filter_xss($review['content']); + $review['summary'] = filter_xss($review['summary']); + } + } + $variables['customerreview'] = !empty($item['customerreviews']) ? filter_xss($item['customerreviews'][0]['content']) : ''; $variables['invalid_asin'] = !empty($item['invalid_asin']) ? 1 : 0; + $variables['detailpageurl'] = check_url($variables['detailpageurl']); + + if (!empty($variables['customerreviews'])) { + foreach($variables['customerreviews'] as $key => $review) { + $variables['customerreviews'][$key] = filter_xss($variables['customerreviews'][$key]); + } + } + $variables['invalid_asin'] = !empty($variables['invalid_asin']) ? 1 : 0; + if (!empty($variables['theatricalreleasedate'])) { $date = explode('-', $variables['theatricalreleasedate']); $variables['releaseyear'] = $date[0]; @@ -142,7 +154,7 @@ function amazon_preprocess_amazon_item(&$variables) { $variables['participants'] = filter_xss(filter_xss(implode(', ', $item['participants']))); $participant_types = split(',', AMAZON_PARTICIPANT_TYPES); - foreach($participant_types as $participant_type) { + foreach ($participant_types as $participant_type) { $participant_type = strtolower($participant_type); if (!empty($item[$participant_type])) { if (is_string($item[$participant_type])) { @@ -165,8 +177,8 @@ function amazon_preprocess_amazon_item(&$variables) { // Handle supported image resolutions. if (isset($item['imagesets'])) { - foreach($item['imagesets'] as $key => $image) { - $variables[$key] = theme('image', $image['url'], t('Image of') . ' ' . check_plain($item['title']), check_plain($item['title']), array('height' => $image['height'], 'width' => $image['width']), FALSE); + foreach ($item['imagesets'] as $key => $image) { + $variables[$key] = theme('image', array('path' => $image['url'], 'alt' => t('Image of') . ' ' . check_markup($item['title']), 'title' => check_markup($item['title']), 'attributes' => array('height' => $image['height'], 'width' => $image['width']), 'getsize' => FALSE)); $variables["{$key}url"] = check_url($image['url']); $variables["{$key}height"] = check_plain($image['height']); $variables["{$key}width"] = check_plain($image['width']); @@ -174,13 +186,19 @@ function amazon_preprocess_amazon_item(&$variables) { } $variables['image'] = !empty($variables['mediumimage']) ? $variables['mediumimage'] : ''; + $variables['attributes_array'] = array(); + $variables['title_attributes_array'] = array(); + $variables['content_attributes_array'] = array(); + if (!empty($variables['detail']) && $theme_type == 'amazon_detail') { + $variables['classes_array'] = array("amazon-item", "amazon-item-detail-{$variables['detail']}"); + } if (!empty($variables['style'])) { $variables['classes'] = _amazon_item_classes($item) . ' amazon-item-' . check_plain($variables['style']); // A set of more specific templates to use when displaying items. $variables['template_files'][] = 'amazon-item-' . $variables['style']; $variables['template_files'][] = 'amazon-item-' . strtolower($variables['type']); - $variables['template_files'][] = 'amazon-item-' . strtolower($variables['type']) .'-'. $variables['style']; + $variables['template_files'][] = 'amazon-item-' . strtolower($variables['type']) . '-' . $variables['style']; if (!empty($item['view']) && !empty($item['view']->name)) { $vars['template_files'][] = 'amazon-item-view-' . $item['view']->name; @@ -196,7 +214,7 @@ function _amazon_clean_type($type) { } function _amazon_item_classes($item) { - return 'amazon-item amazon-item-'. str_replace('_', '-', _amazon_clean_type($item['producttypename'])); + return 'amazon-item amazon-item-' . str_replace('_', '-', _amazon_clean_type($item['producttypename'])); } @@ -223,37 +241,37 @@ function amazon_http_request($operation, $parameters = array(), $locale = NULL) if (!empty($parameters_after_hook)) { $parameters = $parameters_after_hook; } - $parameters += array('Timestamp' => gmdate("Y-m-d\TH:i:s"). 'Z'); + $parameters += array('Timestamp' => gmdate("Y-m-d\TH:i:s") . 'Z'); uksort($parameters, 'strnatcmp'); $params = array(); - foreach($parameters as $key => $value) { + foreach ($parameters as $key => $value) { if (is_array($value)) { $value = implode(',', $value); } $param = str_replace("%7E", "~", rawurlencode($key)); $value = str_replace("%7E", "~", rawurlencode($value)); - $params[] = $param .'='. $value; + $params[] = $param . '=' . $value; } - $secret_access_key=variable_get('amazon_aws_secret_access_key',""); + $secret_access_key = variable_get('amazon_aws_secret_access_key', ""); if ($secret_access_key == "") { - watchdog('amazon',"No Secret Access Key configured. You must configure one at Admin->Settings->Amazon API",NULL,'error'); + watchdog('amazon', "No Secret Access Key configured. You must configure one at Admin->Settings->Amazon API", NULL, 'error'); drupal_set_message(t("Amazon Module: No Secret Access Key is configured. Please contact your site administrator")); return FALSE; } // Thanks for signature creation code from http://mierendo.com/software/aws_signed_query/ - $query_string = implode('&',$params); + $query_string = implode('&', $params); $parsed_url = parse_url($locale_data['url']); - $host=strtolower($parsed_url['host']); - $string_to_sign="GET\n$host\n{$parsed_url['path']}\n$query_string"; + $host = strtolower($parsed_url['host']); + $string_to_sign = "GET\n$host\n{$parsed_url['path']}\n$query_string"; $signature = base64_encode(hash_hmac('sha256', $string_to_sign, $secret_access_key, TRUE)); $signature = str_replace("%7E", "~", rawurlencode($signature)); $query_string .= "&Signature=$signature"; - $url = $locale_data['url'] .'?'. $query_string; + $url = $locale_data['url'] . '?' . $query_string; // Make the request and return a SimpleXML object. - $results = drupal_http_request($url, array(), 'GET'); + $results = drupal_http_request($url, array('method' => 'GET')); if ($results->code == 200) { $xml = new SimpleXMLElement($results->data); return $xml; @@ -261,11 +279,12 @@ function amazon_http_request($operation, $parameters = array(), $locale = NULL) if ($results->code >= 400 && $results->code < 500) { try { $xml = new SimpleXMLElement($results->data); - } catch (Exception $e) { - watchdog('amazon', "Error handling results: http_code=%http_code, data=%data.",array('%http_code' => $results->code, '%data' => (string)$results->data) ); + } + catch (Exception $e) { + watchdog('amazon', "Error handling results: http_code=%http_code, data=%data.", array('%http_code' => $results->code, '%data' => (string) $results->data) ); return FALSE; } - watchdog('amazon', "HTTP code %http_code accessing Amazon's AWS service: %code, %message", array('%http_code' => $results->code, '%code' => (string)$xml->Error->Code, '%message' => (string)$xml->Error->Message)); + watchdog('amazon', "HTTP code %http_code accessing Amazon's AWS service: %code, %message", array('%http_code' => $results->code, '%code' => (string) $xml->Error->Code, '%message' => (string) $xml->Error->Message)); return FALSE; } watchdog('amazon', "Error accessing Amazon AWS web service. HTTP result code=%code, error=%error", array('%code' => $results->code, '%error' => $results->error)); @@ -315,10 +334,10 @@ function amazon_item_lookup($item_ids = array(), $force_lookup = FALSE) { * Array of cleaned XML structures keyed by ASIN. */ function amazon_item_lookup_from_web($item_ids = array()) { - $amazon_limit = 10; // Amazon will accept no more than 10 items + $amazon_limit = 10; // Amazon will accept no more than 10 items $asins = array(); $results = array(); - $item_ids = array_filter($item_ids); // Remove any empty items. + $item_ids = array_filter($item_ids); // Remove any empty items. foreach ($item_ids as $asin) { if (!empty($asin)) { $asins[] = $asin; @@ -348,22 +367,30 @@ function _amazon_item_batch_lookup_from_web($item_ids = array()) { ); $results = amazon_http_request('ItemLookup', $params); if (!empty($results->Items->Request->Errors)) { - foreach($results->Items->Request->Errors->Error as $error) { - $code = (string)$error->Code; - $message = (string)$error->Message; + foreach ($results->Items->Request->Errors->Error as $error) { + $code = (string) $error->Code; + $message = (string) $error->Message; $matches = array(); // Find and extract the failing ASIN, so we can mark it in the db. if (preg_match('/^([^ ]+) is not a valid value for ItemId/', $message, $matches)) { $error_asin = $matches[1]; - $query = "update {amazon_item} set invalid_asin = TRUE where asin = '%s'"; - db_query($query, $error_asin); + try { + $result = db_update('amazon_item') + ->fields(array('invalid_asin' => TRUE)) + ->condition('asin', $error_asin) + ->execute(); + } + catch(Exception $e) { + amazon_db_error_watchdog('Failed to update invalid_asin=TRUE on amazon_item.', $e); + } + } - watchdog('amazon','Error retrieving Amazon item %code, message: %message.', array('%code' => $code, '%message' => $message), WATCHDOG_WARNING); + watchdog('amazon', 'Error retrieving Amazon item %code, message: %message.', array('%code' => $code, '%message' => $message), WATCHDOG_WARNING); } } $items = array(); if (!empty($results->Items->Item)) { - foreach($results->Items->Item as $xml) { + foreach ($results->Items->Item as $xml) { $item = amazon_item_clean_xml($xml); amazon_item_insert($item); $items["{$item['asin']}"] = $item; @@ -383,12 +410,12 @@ function _amazon_item_batch_lookup_from_web($item_ids = array()) { */ function amazon_item_lookup_from_db($item_ids = array()) { if (!empty($item_ids)) { - $sql = "SELECT * FROM {amazon_item} ai WHERE ai.asin IN ("; - $sql .= implode(',', array_fill(0, count($item_ids), "'%s'")) .') '; - $sql .= 'AND ai.timestamp > %d'; - $results = db_query($sql, $item_ids, time() - variable_get('amazon_refresh_schedule', 86400)); + $timestamp = REQUEST_TIME - variable_get('amazon_refresh_schedule', 86400); + $result = db_query('SELECT * from {amazon_item} WHERE asin IN (:asins) AND timestamp > :timestamp', + array('asins' => $item_ids, 'timestamp' => $timestamp), + array('fetch' => PDO::FETCH_ASSOC)); $items = array(); - while ($item = db_fetch_array($results)) { + foreach ($result as $item) { _amazon_load_child_data($item); $item += module_invoke_all('amazon_item_load', $item); $items["{$item['asin']}"] = $item; @@ -404,24 +431,38 @@ function amazon_item_lookup_from_db($item_ids = array()) { * Amazon data structure. */ function _amazon_load_child_data(&$item) { - $result = db_query("SELECT type, participant FROM {amazon_item_participant} WHERE asin = '%s'", $item['asin']); - while ($participant = db_fetch_array($result)) { + $result = db_query('SELECT type, participant FROM {amazon_item_participant} WHERE asin = :asin', + array('asin' => $item['asin']), + array('fetch' => PDO::FETCH_ASSOC)); + foreach ($result as $participant) { unset($participant['asin']); $item[$participant['type']][] = $participant['participant']; $item['participants'][] = $participant['participant']; } - $result = db_query("SELECT * FROM {amazon_item_image} WHERE asin = '%s'", $item['asin']); - while ($image = db_fetch_array($result)) { + $result = db_query('SELECT * FROM {amazon_item_image} WHERE asin = :asin', + array('asin' => $item['asin']), + array('fetch' => PDO::FETCH_ASSOC)); + foreach ($result as $image) { unset($image['asin']); $item['imagesets'][$image['size']] = $image; } - $result = db_query("SELECT * FROM {amazon_item_editorial_review} WHERE asin = '%s'", $item['asin']); - while ($review = db_fetch_array($result)) { + $result = db_query('SELECT * FROM {amazon_item_editorial_review} WHERE asin = :asin', + array('asin' => $item['asin']), + array('fetch' => PDO::FETCH_ASSOC)); + foreach ($result as $review) { unset($review['asin']); $item['editorialreviews'][] = $review; } + $result = db_query('SELECT * FROM {amazon_item_customer_review} WHERE asin = :asin', + array('asin' => $item['asin']), + array('fetch' => PDO::FETCH_ASSOC)); + foreach ($result as $review) { + unset($review['asin']); + $item['customerreviews'][] = $review; + } + } /** @@ -435,41 +476,40 @@ function _amazon_load_child_data(&$item) { function amazon_item_clean_xml($xml) { $metadata = amazon_data_cache(); $item = array(); - // Pull the absolute basic information Amazon keeps at the top level // of the XML tree, cast to string, and move on. - $item['asin'] = (string)$xml->ASIN; + $item['asin'] = (string) $xml->ASIN; if (empty($item['isbn'])) { - $item['isbn'] = (string)$xml->ItemAttributes->ISBN; + $item['isbn'] = (string) $xml->ItemAttributes->ISBN; } if (empty($item['ean'])) { - $item['ean'] = (string)$xml->ItemAttributes->EAN; + $item['ean'] = (string) $xml->ItemAttributes->EAN; } - $item['salesrank'] = (string)$xml->SalesRank; - $item['detailpageurl'] = (string)$xml->DetailPageURL; + $item['salesrank'] = (string) $xml->SalesRank; + $item['detailpageurl'] = (string) $xml->DetailPageURL; if (!empty($xml->ItemAttributes->ListPrice)) { - $item['listpriceamount'] = (string)$xml->ItemAttributes->ListPrice->Amount; - $item['listpricecurrencycode'] = (string)$xml->ItemAttributes->ListPrice->CurrencyCode; - $item['listpriceformattedprice'] = (string)$xml->ItemAttributes->ListPrice->FormattedPrice; + $item['listpriceamount'] = (string) $xml->ItemAttributes->ListPrice->Amount; + $item['listpricecurrencycode'] = (string) $xml->ItemAttributes->ListPrice->CurrencyCode; + $item['listpriceformattedprice'] = (string) $xml->ItemAttributes->ListPrice->FormattedPrice; } if (!empty($xml->OfferSummary->LowestNewPrice)) { - $item['lowestpriceamount'] = (string)$xml->OfferSummary->LowestNewPrice->Amount; - $item['lowestpricecurrencycode'] = (string)$xml->OfferSummary->LowestNewPrice->CurrencyCode; - $item['lowestpriceformattedprice'] = (string)$xml->OfferSummary->LowestNewPrice->FormattedPrice; + $item['lowestpriceamount'] = (string) $xml->OfferSummary->LowestNewPrice->Amount; + $item['lowestpricecurrencycode'] = (string) $xml->OfferSummary->LowestNewPrice->CurrencyCode; + $item['lowestpriceformattedprice'] = (string) $xml->OfferSummary->LowestNewPrice->FormattedPrice; } // Note that this one assumes we've searched with Merchant = Amazon. // Otherwise we can do an xpath search looking for the actual amazon listing. - if (!empty($xml->Offers->Offer[0]->OfferListing->Price) && (string)$xml->Offers->Offer[0]->Merchant->MerchantId == 'ATVPDKIKX0DER') { - $item['amazonpriceamount'] = (string)$xml->Offers->Offer[0]->OfferListing->Price->Amount; - $item['amazonpricecurrencycode'] = (string)$xml->Offers->Offer[0]->OfferListing->Price->CurrencyCode; - $item['amazonpriceformattedprice'] = (string)$xml->Offers->Offer[0]->OfferListing->Price->FormattedPrice; + if (!empty($xml->Offers->Offer[0]->OfferListing->Price) && (string) $xml->Offers->Offer[0]->Merchant->MerchantId == 'ATVPDKIKX0DER') { + $item['amazonpriceamount'] = (string) $xml->Offers->Offer[0]->OfferListing->Price->Amount; + $item['amazonpricecurrencycode'] = (string) $xml->Offers->Offer[0]->OfferListing->Price->CurrencyCode; + $item['amazonpriceformattedprice'] = (string) $xml->Offers->Offer[0]->OfferListing->Price->FormattedPrice; } $participant_types = split(',', AMAZON_PARTICIPANT_TYPES); // Pull in the basics of the ItemAttributes collection. - foreach((array)($xml->ItemAttributes) as $key => $value) { + foreach ((array) ($xml->ItemAttributes) as $key => $value) { if (is_string($value) && !in_array($key, $participant_types)) { $key = strtolower($key); $item[$key] = $value; @@ -479,9 +519,9 @@ function amazon_item_clean_xml($xml) { // Handle the Authors/Artists/Etc. foreach ($participant_types as $key) { if (isset($xml->ItemAttributes->$key)) { - foreach($xml->ItemAttributes->$key as $value) { - $item[strtolower($key)][] = (string)$value; - $item['participants'][] = (string)$value; + foreach ($xml->ItemAttributes->$key as $value) { + $item[strtolower($key)][] = (string) $value; + $item['participants'][] = (string) $value; } } } @@ -491,12 +531,12 @@ function amazon_item_clean_xml($xml) { // and ignore the rest for now. $supported_sizes = split(',', AMAZON_IMAGE_SIZES); if (isset($xml->ImageSets->ImageSet)) { - foreach((array)$xml->ImageSets->ImageSet as $key => $data) { + foreach ((array) $xml->ImageSets->ImageSet as $key => $data) { if (in_array($key, $supported_sizes)) { $item['imagesets'][strtolower($key)] = array( - 'url' => (string)$data->URL, - 'height' => (string)$data->Height, - 'width' => (string)$data->Width, + 'url' => (string) $data->URL, + 'height' => (string) $data->Height, + 'width' => (string) $data->Width, ); } } @@ -504,22 +544,22 @@ function amazon_item_clean_xml($xml) { // Handle the editorial reviews. if (isset($xml->EditorialReviews)) { - foreach($xml->EditorialReviews->EditorialReview as $data) { + foreach ($xml->EditorialReviews->EditorialReview as $data) { $item['editorialreviews'][] = array( - 'source' => (string)$data->Source, - 'content' => (string)$data->Content, + 'source' => (string) $data->Source, + 'content' => (string) $data->Content, ); } } // And the customer reviews. if (isset($xml->CustomerReviews)) { - foreach($xml->CustomerReviews->Review as $data) { + foreach ($xml->CustomerReviews->Review as $data) { $item['customerreviews'][] = array( - 'rating' => (string)$data->Rating, - 'date' => (string)$data->Date, - 'summary' => (string)$data->Summary, - 'content' => (string)$data->Content, + 'rating' => (string) $data->Rating, + 'date' => (string) $data->Date, + 'summary' => (string) $data->Summary, + 'content' => (string) $data->Content, ); } } @@ -528,7 +568,7 @@ function amazon_item_clean_xml($xml) { // that would otherwise be ignored. We can't use module_invoke_all, as it // would lose the reference. foreach (module_implements('amazon_item_clean_xml') as $module) { - $function = $module .'_amazon_item_clean_xml'; + $function = $module . '_amazon_item_clean_xml'; $function($item, $xml); } return $item; @@ -542,24 +582,48 @@ function amazon_item_clean_xml($xml) { * No return value. */ function amazon_item_insert($item) { + static $item_keys = NULL; + if (empty($item_keys)) { + require_once('amazon.install'); + $schema = amazon_schema(); + $item_keys = $schema['amazon_item']['fields']; + } // We have boatloads of data to insert in here, so we're going to // cheat and blow away the old entries first. amazon_item_delete($item['asin']); $metadata = amazon_data_cache(); - $item['timestamp'] = time(); - drupal_write_record('amazon_item', $item); + $item['timestamp'] = REQUEST_TIME; + + // The db_insert needs fields that match exactly to the database, + // so we'll intersect with what the actual schema says. + $db_item = array_intersect_key($item, $item_keys); + try { + db_insert('amazon_item') + ->fields($db_item) + ->execute(); + } + catch (Exception $e) { + amazon_db_error_watchdog("Failed to insert item into amazon_item table", $e); + } // Handle the various credits for a product, including Artist, Author, // Actor, etc. We map these to a separate table. if (in_array('creators', variable_get('amazon_core_data', array('creators', 'images')))) { $participant_types = split(',', AMAZON_PARTICIPANT_TYPES); foreach ($participant_types as $type) { - if (isset($item[strtolower($type)])){ - foreach((array)$item[strtolower($type)] as $participant) { + if (isset($item[strtolower($type)])) { + foreach ((array) $item[strtolower($type)] as $participant) { $item_participant = array('asin' => $item['asin'], 'type' => strtolower($type), 'participant' => $participant); - drupal_write_record('amazon_item_participant', $item_participant); + try { + db_insert('amazon_item_participant') + ->fields($item_participant) + ->execute(); + } + catch (Exception $e) { + amazon_db_error_watchdog("Failed to insert item into amazon_item_participant table", $e); + } } } } @@ -568,9 +632,16 @@ function amazon_item_insert($item) { // Save the product images if they exist. if (in_array('images', variable_get('amazon_core_data', array('creators', 'images')))) { if (isset($item['imagesets'])) { - foreach($item['imagesets'] as $size => $data) { + foreach ($item['imagesets'] as $size => $data) { $image = array('asin' => $item['asin'], 'size' => $size, 'height' => $data['height'], 'width' => $data['width'], 'url' => $data['url']); - drupal_write_record('amazon_item_image', $image); + try { + db_insert('amazon_item_image') + ->fields($image) + ->execute(); + } + catch (Exception $e) { + amazon_db_error_watchdog("Failed to insert item into amazon_item_image table", $e); + } } } } @@ -578,18 +649,33 @@ function amazon_item_insert($item) { // Save the editorial reviews if they exist. if (in_array('editorial_reviews', variable_get('amazon_core_data', array('creators', 'images')))) { if (isset($item['editorialreviews'])) { - foreach($item['editorialreviews'] as $data) { + foreach ($item['editorialreviews'] as $data) { $review = array('asin' => $item['asin'], 'source' => $data['source'], 'content' => $data['content']); - drupal_write_record('amazon_item_editorial_review', $review); + try { + db_insert('amazon_item_editorial_review') + ->fields($review) + ->execute(); + } + catch (Exception $e) { + amazon_db_error_watchdog("Failed to insert item into amazon_item_editorial_review table", $e); + } } } } // Save the customer reviews if they exist. if (in_array('customer_reviews', variable_get('amazon_core_data', array('creators', 'images')))) { if (isset($item['customerreviews'])) { - foreach($item['customerreviews'] as $data) { + foreach ($item['customerreviews'] as $data) { $review = array('asin' => $item['asin'], 'rating' => $data['rating'], 'date' => $data['date'], 'summary' => $data['summary'], 'content' => $data['content']); - drupal_write_record('amazon_item_customer_review', $review); + try { + db_insert('amazon_item_customer_review') + ->fields($review) + ->execute(); + } + catch (Exception $e) { + amazon_db_error_watchdog("Failed to insert item into amazon_item_editorial_review table", $e); + } + } } } @@ -605,11 +691,21 @@ function amazon_item_insert($item) { */ function amazon_item_delete($asin) { module_invoke_all('amazon_item_delete', $asin); - db_query("DELETE FROM {amazon_item} WHERE asin = '%s'", $asin); - db_query("DELETE FROM {amazon_item_participant} WHERE asin = '%s'", $asin); - db_query("DELETE FROM {amazon_item_image} WHERE asin = '%s'", $asin); - db_query("DELETE FROM {amazon_item_editorial_review} WHERE asin = '%s'", $asin); - db_query("DELETE FROM {amazon_item_customer_review} WHERE asin = '%s'", $asin); + db_delete('amazon_item') + ->condition('asin', $asin) + ->execute(); + db_delete('amazon_item_participant') + ->condition('asin', $asin) + ->execute(); + db_delete('amazon_item_image') + ->condition('asin', $asin) + ->execute(); + db_delete('amazon_item_editorial_review') + ->condition('asin', $asin) + ->execute(); + db_delete('amazon_item_customer_review') + ->condition('asin', $asin) + ->execute(); } /** @@ -623,7 +719,7 @@ function amazon_item_delete($asin) { * after removing dashes. */ function amazon_convert_to_asin($input) { - $input = preg_replace('/-/','',$input); // Remove dashes. + $input = preg_replace('/-/', '', $input); // Remove dashes. if (preg_match('/^https?:/', $input)) { $parts = preg_split('/\//', $input); $asin = $parts[5]; // 6th section of split, right after /dp/ @@ -654,7 +750,7 @@ function amazon_ean_to_asin($ean) { ); $results = amazon_http_request('ItemLookup', $params); if (!empty($results->Items->Item->ASIN)) { - $asin = (string)$results->Items->Item->ASIN; + $asin = (string) $results->Items->Item->ASIN; } return $asin; } @@ -664,30 +760,34 @@ function amazon_ean_to_asin($ean) { function amazon_item_node_save($asin, $node, $module = 'amazon', $weight = 0) { amazon_item_node_delete($asin, $nid, $module); - db_query("INSERT INTO {amazon_item_node} (asin, vid, nid, module, weight) VALUES ('%s', %d, '%s', %d)", $asin, $nid, $module, $weight); + try { + $id = db_insert('amazon_item_node') + ->fields(array( + 'asin' => $asin, + 'nid' => $nid, + 'module' => $module, + 'weight' => $weight, + )) + ->execute(); + } catch(Exception $e) { + amazon_db_error_watchdog('Failed to save amazon_item_node.', $e); + } } function amazon_item_node_delete($asin = NULL, $nid = NULL, $module = NULL) { - $sql = "DELETE FROM {amazon_item_node} WHERE 1 = 1"; - $params = array(); + $delete = db_delete('amazon_item_node'); if (isset($asin)) { - $sql = " AND asin = '%s'"; - $params[] = $asin; + $delete = $delete->condition('asin', $asin); } if (isset($nid)) { - $sql = " AND nid = %d"; - $params[] = $nid; + $delete = $delete->condition('nid', $nid); } if (isset($module)) { - $sql = " AND module = '%s'"; - $params[] = $module; - } - - if (count($params)) { - db_query($sql, $params); + $delete = $delete->condition('module', $module); } + $delete->execute(); } @@ -759,14 +859,14 @@ function amazon_get_associate_id() { function amazon_cron() { // Here, we're going to chug through all the existing ASINs and update them. // We'll grab 50 at a time to avoid thrashing things. - $sql = "SELECT asin FROM {amazon_item} WHERE timestamp < %d"; - $result = db_query_range($sql, time() - variable_get('amazon_refresh_schedule', 86400), 0, 50); - $asins = array(); - - while($item = db_fetch_array($result)) { - $asins[] = $item['asin']; - } - + $per_cron_limit = 50; + $needs_update_time = REQUEST_TIME - variable_get('amazon_refresh_schedule', 86400); + $result = db_select('amazon_item', NULL, array('fetch' => PDO::FETCH_ASSOC)) + ->fields('amazon_item', array('asin')) + ->condition('timestamp', $needs_update_time, '<') + ->range(0, $per_cron_limit) + ->execute(); + $asins = $result->FetchCol(); if (!empty($asins)) { if ($items = amazon_item_lookup_from_web($asins)) { foreach ($items as $item) { @@ -780,6 +880,7 @@ function amazon_cron() { } } +//D6FIX: hook_token_info function amazon_token_list($type = 'all') { if ($type == 'amazon_item' || $type == 'all') { $tokens['amazon_item']['asin'] = t('Product ID'); @@ -802,9 +903,10 @@ function amazon_token_list($type = 'all') { } } +//D6FIX: hook_tokens() function amazon_token_values($type, $object = NULL, $options = array()) { if ($type == 'amazon_item' || $type == 'all') { - $item = (array)$object; + $item = (array) $object; $values['asin'] = check_plain($item['asin']); $values['isbn'] = check_plain($item['isbn']); $values['ean'] = check_plain($item['ean']); @@ -851,10 +953,10 @@ function template_preprocess_amazon_views_view_row_item(&$vars) { $item['view'] = $vars['view']; $vars['amazon_item'] = $item; if ($options['display_format'] == 'inline') { - $vars['content'] = theme('amazon_item_inline', $item, $options['display_format']); + $vars['content'] = theme('amazon_item_inline', array('item' => $item, 'style' => $options['display_format'])); } else { - $vars['content'] = theme('amazon_item', $item, $options['display_format']); + $vars['content'] = theme('amazon_item', array('item' => $item, 'style' => $options['display_format'])); } } } @@ -862,3 +964,18 @@ function template_preprocess_amazon_views_view_row_item(&$vars) { function amazon_init() { drupal_add_css(drupal_get_path('module', 'amazon') . '/amazon.css'); } + +/** + * Have watchdog emit complete errors about a database exception. + * + * @param $msg + * The message explaining the error. + * The message should not be localized, as it will be passed to watchdog(). + * @param $e + * The exception which was caught + * + */ +function amazon_db_error_watchdog($msg, $e) { + watchdog('amazon', "$msg: Message = %message, query= %query", + array('%message' => $e->getMessage(), '%query' => $e->query_string)); +} \ No newline at end of file diff --git amazon_examples/amazon_examples.defaults.inc amazon_examples/amazon_examples.defaults.inc deleted file mode 100644 index 1f57c07..0000000 --- amazon_examples/amazon_examples.defaults.inc +++ /dev/null @@ -1,66 +0,0 @@ - 'field_asin', - 'type_name' => 'amazon_example', - 'display_settings' => array( - 'label' => array( - 'format' => 'above', - 'exclude' => 0, - ), - 'teaser' => array( - 'format' => 'default', - 'exclude' => 0, - ), - 'full' => array( - 'format' => 'default', - 'exclude' => 0, - ), - '4' => array( - 'format' => 'default', - 'exclude' => 0, - ), - '2' => array( - 'format' => 'default', - 'exclude' => 0, - ), - '3' => array( - 'format' => 'default', - 'exclude' => 0, - ), - ), - 'widget_active' => '1', - 'type' => 'asin', - 'required' => '1', - 'multiple' => '0', - 'module' => 'asin', - 'active' => '1', - 'widget' => array( - 'default_value' => array( - '0' => array( - 'asin' => '', - ), - ), - 'default_value_php' => NULL, - 'label' => 'ASIN', - 'weight' => '-4', - 'description' => 'Enter a 10-digit ASIN that identifies an Amazon item. ', - 'type' => 'asin_text', - 'module' => 'asin', - ), - ); - - // Translatables - array( - t('ASIN'), - ); - - return $fields; -} diff --git amazon_examples/amazon_examples.features.inc amazon_examples/amazon_examples.features.inc deleted file mode 100644 index 65d3f87..0000000 --- amazon_examples/amazon_examples.features.inc +++ /dev/null @@ -1,28 +0,0 @@ - array( - 'name' => t('Amazon Example'), - 'module' => 'features', - 'description' => t('This is just an example content type to show how Amazon module can be used with CCK fields. A single CCK field is provided. You can populate a few nodes and then see how views work and how these are displayed. A sample view that uses this CCK type is provided.'), - 'has_title' => '1', - 'title_label' => t('Title'), - 'has_body' => '0', - 'body_label' => '', - 'min_word_count' => '0', - 'help' => '', - ), - ); - return $items; -} diff --git amazon_examples/amazon_examples.features.views.inc amazon_examples/amazon_examples.features.views.inc deleted file mode 100644 index 3f5dc9d..0000000 --- amazon_examples/amazon_examples.features.views.inc +++ /dev/null @@ -1,291 +0,0 @@ -name = 'amazon_example_view'; - $view->description = 'Amazon Example View'; - $view->tag = 'examples'; - $view->view_php = ''; - $view->base_table = 'node'; - $view->is_cacheable = FALSE; - $view->api_version = 2; - $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ - $handler = $view->new_display('default', 'Defaults', 'default'); - $handler->override_option('relationships', array( - 'field_asin_asin' => array( - 'label' => 'field_asin_asin', - 'required' => 1, - 'id' => 'field_asin_asin', - 'table' => 'node_data_field_asin', - 'field' => 'field_asin_asin', - 'relationship' => 'none', - ), - )); - $handler->override_option('fields', array( - 'nid' => array( - 'id' => 'nid', - 'table' => 'node', - 'field' => 'nid', - ), - 'asin' => array( - 'label' => 'ASIN', - 'alter' => array( - 'alter_text' => 0, - 'text' => '', - 'make_link' => 0, - 'path' => '', - 'link_class' => '', - 'alt' => '', - 'prefix' => '', - 'suffix' => '', - 'help' => '', - 'trim' => 0, - 'max_length' => '', - 'word_boundary' => 1, - 'ellipsis' => 1, - 'strip_tags' => 0, - 'html' => 0, - ), - 'exclude' => 0, - 'id' => 'asin', - 'table' => 'amazon_item', - 'field' => 'asin', - 'relationship' => 'field_asin_asin', - ), - 'title' => array( - 'label' => 'Title', - 'alter' => array( - 'alter_text' => 0, - 'text' => '', - 'make_link' => 0, - 'path' => '', - 'link_class' => '', - 'alt' => '', - 'prefix' => '', - 'suffix' => '', - 'help' => '', - 'trim' => 0, - 'max_length' => '', - 'word_boundary' => 1, - 'ellipsis' => 1, - 'strip_tags' => 0, - 'html' => 0, - ), - 'link_format' => 'plain', - 'exclude' => 0, - 'id' => 'title', - 'table' => 'amazon_item', - 'field' => 'title', - 'relationship' => 'field_asin_asin', - ), - 'detailpageurl' => array( - 'label' => 'Detail page URL', - 'alter' => array( - 'alter_text' => 0, - 'text' => '', - 'make_link' => 0, - 'path' => '', - 'link_class' => '', - 'alt' => '', - 'prefix' => '', - 'suffix' => '', - 'help' => '', - 'trim' => 0, - 'max_length' => '', - 'word_boundary' => 1, - 'ellipsis' => 1, - 'strip_tags' => 0, - 'html' => 0, - ), - 'exclude' => 1, - 'id' => 'detailpageurl', - 'table' => 'amazon_item', - 'field' => 'detailpageurl', - 'relationship' => 'field_asin_asin', - 'override' => array( - 'button' => 'Override', - ), - ), - 'listpriceformattedprice' => array( - 'id' => 'listpriceformattedprice', - 'table' => 'amazon_item', - 'field' => 'listpriceformattedprice', - ), - 'publisher' => array( - 'id' => 'publisher', - 'table' => 'amazon_item', - 'field' => 'publisher', - ), - 'publicationdate' => array( - 'label' => 'Publication date', - 'alter' => array( - 'alter_text' => 0, - 'text' => '', - 'make_link' => 0, - 'path' => '', - 'link_class' => '', - 'alt' => '', - 'prefix' => '', - 'suffix' => '', - 'help' => '', - 'trim' => 0, - 'max_length' => '', - 'word_boundary' => 1, - 'ellipsis' => 1, - 'strip_tags' => 0, - 'html' => 0, - ), - 'date_format' => 'default', - 'custom_date_format' => '', - 'exclude' => 0, - 'id' => 'publicationdate', - 'table' => 'amazon_book', - 'field' => 'publicationdate', - 'relationship' => 'field_asin_asin', - ), - 'product_image' => array( - 'label' => 'Image URL', - 'alter' => array( - 'alter_text' => 0, - 'text' => '', - 'make_link' => 0, - 'path' => '', - 'link_class' => '', - 'alt' => '', - 'prefix' => '', - 'suffix' => '', - 'help' => '', - 'trim' => 0, - 'max_length' => '', - 'word_boundary' => 1, - 'ellipsis' => 1, - 'strip_tags' => 0, - 'html' => 0, - ), - 'image_size' => 'mediumimage', - 'link_format' => 'plain', - 'exclude' => 1, - 'id' => 'product_image', - 'table' => 'amazon_item_image', - 'field' => 'product_image', - 'relationship' => 'field_asin_asin', - 'presentation_format' => 'plain_url', - ), - 'nothing' => array( - 'label' => 'Custom: Example Link to Image', - 'alter' => array( - 'text' => 'Example link/image:
\$asins[$asin]=" . print_r($asins["$asin"], TRUE) . ""); - drupal_set_message("asin='$asin'; asins=".print_r($asins,TRUE)); + drupal_set_message("asin='$asin'; asins=" . print_r($asins, TRUE)); } - return theme('amazon_inline_item', $asins[$asin]); + return theme('amazon_inline_item', array('item' => $asins[$asin])); } } @@ -369,12 +370,12 @@ function asin_text_validate($element, &$form_state) { function theme_asin_text($element) { - drupal_add_css(drupal_get_path('module', 'asin') .'/asin.css', 'module', 'all', FALSE); + drupal_add_css(drupal_get_path('module', 'asin') . '/asin.css', array('preprocess' => FALSE)); $output = $element['#children']; if (!empty($element['#value']) && !empty($element['#value']['asin'])) { $asin = $element['#value']['asin']; if ($data = amazon_item_lookup(array($asin))) { - $output .= '
'. check_plain($data[$asin]['title']) .'
'; + $output .= '' . check_plain($data[$asin]['title']) . '
'; } } return $output; diff --git includes/amazon.views.inc includes/amazon.views.inc index 474aec8..26ee056 100644 --- includes/amazon.views.inc +++ includes/amazon.views.inc @@ -138,8 +138,8 @@ function amazon_views_data() { _amazon_make_simple_text_field($data, 'amazon_item', 'amazonpriceformattedprice', 'Amazon price (formatted)', "Amazon's current price for the item."); _amazon_make_simple_boolean_field($data, 'amazon_item', 'invalid_asin', 'Invalid ASIN', 'If nonzero, the ASIN is invalid or discontinued by Amazon'); unset($data['amazon_item']['listpriceformattedprice']['argument']); - unset($data['amazon_item']['lowestformattedprice']['argument']); - unset($data['amazon_item']['amazonpriceformattedprice']['argument']); + unset($data['amazon_item']['lowestformattedprice']['argument']); + unset($data['amazon_item']['amazonpriceformattedprice']['argument']); // Define the base group of this table. Fields that don't // have a group defined will go into this field by default. diff --git includes/views_handler_field_amazon_date.inc includes/views_handler_field_amazon_date.inc index ef8fdaa..0bd3e0e 100644 --- includes/views_handler_field_amazon_date.inc +++ includes/views_handler_field_amazon_date.inc @@ -10,7 +10,7 @@ class views_handler_field_amazon_date extends views_handler_field_date { function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); - $time = time(); + $time = REQUEST_TIME; $form['date_format']['#options'] = array( 'default' => format_date($time, 'custom', 'Y-m-d'), 'custom' => t('Custom'), @@ -29,7 +29,7 @@ class views_handler_field_amazon_date extends views_handler_field_date { return theme('views_nodate'); } else { - $time_diff = time() - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence) + $time_diff = REQUEST_TIME - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence) switch ($format) { case 'custom': return format_date($value, $format, $custom_format); diff --git includes/views_handler_field_amazon_image.inc includes/views_handler_field_amazon_image.inc index 9f2485b..24872b4 100644 --- includes/views_handler_field_amazon_image.inc +++ includes/views_handler_field_amazon_image.inc @@ -103,22 +103,24 @@ class views_handler_field_amazon_image extends views_handler_field { // Choose presentation style if ($this->options['presentation_format'] == 'markup') { - $image = theme('image', $values->{$this->table_alias . '_url'}, NULL, NULL, $attributes, FALSE); - } else { + $image = theme('image', array('path' => $values->{$this->table_alias . '_url'}, 'alt' => NULL, 'title' => NULL, 'attributes' => $attributes, 'getsize' => FALSE)); + } + else { $image = $values->{$this->table_alias . '_url'}; } - switch($this->options['link_format']) { + switch ($this->options['link_format']) { case 'plain': return $image; break; case 'node': - return l($image, 'node/'. $values->nid, array('html' => TRUE)); + return l($image, 'node/' . $values->nid, array('html' => TRUE)); break; case 'amazon': if (!empty($values->{$this->aliases['detailpageurl']})) { $urlfield = $values->{$this->aliases['detailpageurl']}; return l($image, $urlfield, array('html' => TRUE)); - } else { + } + else { return $image; } break; diff --git includes/views_handler_field_amazon_title.inc includes/views_handler_field_amazon_title.inc index 582244b..12e67a0 100644 --- includes/views_handler_field_amazon_title.inc +++ includes/views_handler_field_amazon_title.inc @@ -38,12 +38,12 @@ class views_handler_field_amazon_title extends views_handler_field { function render($values) { $title = check_plain($values->{$this->field_alias}); - switch($this->options['link_format']) { + switch ($this->options['link_format']) { case 'plain': return $title; break; case 'node': - return l($title, 'node/'. $values->nid, array('html' => TRUE)); + return l($title, 'node/' . $values->nid, array('html' => TRUE)); break; case 'amazon': return l($title, check_url($values->{$this->table_alias . '_detailpageurl'}), array('html' => TRUE)); diff --git includes/views_handler_filter_amazon_node_module.inc includes/views_handler_filter_amazon_node_module.inc index 6f0efd3..a77022a 100644 --- includes/views_handler_filter_amazon_node_module.inc +++ includes/views_handler_filter_amazon_node_module.inc @@ -24,52 +24,3 @@ class views_handler_filter_amazon_node_module extends views_handler_filter_in_op } } -class views_handler_field_amazon_title extends views_handler_field { - function options(&$options) { - parent::options($options); - $options['link_format'] = 'amazon'; - } - - /** - * Override init function to provide generic option to link to node. - */ - function init(&$view, &$data) { - parent::init($view, $data); - if (!empty($data['link_format']) && $data['link_format'] == 'amazon') { - $this->additional_fields[] = 'detailpageurl'; - } - } - - /** - * Provide link to node option - */ - function options_form(&$form, &$form_state) { - $form['link_format'] = array( - '#title' => t('Link behavior'), - '#type' => 'radios', - '#options' => array( - 'plain' => t('No link'), - 'amazon' => t("A link to the product's Amazon page"), - ), - '#default_value' => !empty($this->options['link_format']) ? $this->options['link_format'] : 'plain', - ); - if ($this->view->base_table == 'node') { - $form['link_format']['#options']['node'] = t('A link to the node the product is associated with'); - } - } - - function render($values) { - $title = check_plain($values->{$this->field_alias}); - switch($this->options['link_format']) { - case 'plain': - return $title; - break; - case 'node': - return l($title, 'node/'. $values->nid, array('html' => TRUE)); - break; - case 'amazon': - return l($title, check_url($values->{$this->table_alias . '_detailpageurl'}), array('html' => TRUE, 'attributes' => array('rel' => 'nofollow'))); - break; - } - } -} diff --git includes/views_handler_filter_string_compare.inc includes/views_handler_filter_string_compare.inc index 0fb7818..ba4a551 100644 --- includes/views_handler_filter_string_compare.inc +++ includes/views_handler_filter_string_compare.inc @@ -241,7 +241,7 @@ class views_handler_filter_string_compare extends views_handler_filter { foreach ($matches as $match) { $phrase = false; // Strip off phrase quotes - if ($match[2]{0} == '"') { + if ($match[2][0] == '"') { $match[2] = substr($match[2], 1, -1); $phrase = true; }