diff --git amazon-item-thumbnail.tpl.php amazon-item-thumbnail.tpl.php
index 83d1b38..f2fc746 100644
--- amazon-item-thumbnail.tpl.php
+++ amazon-item-thumbnail.tpl.php
@@ -1,4 +1,4 @@
This item is no longer valid on Amazon.
"; } ?>
-
+
diff --git amazon.admin.inc amazon.admin.inc
index 3445f8d..38a3cb6 100644
--- amazon.admin.inc
+++ amazon.admin.inc
@@ -1,5 +1,13 @@
t('Amazon.com uses separate product databases and Ecommerce features in different locales; pricing and availability information, as well as product categorization, differs from one locale to the next. Be sure to select the locale your site will be running in.'),
);
- $form['amazon_associate_setting'] = array(
- '#type' => 'select',
+ $form['associate_setting'] = array(
+ '#type' => 'fieldset',
'#title' => t('Amazon referral settings'),
+ );
+ $form['associate_setting']['amazon_associate_setting'] = array(
+ '#type' => 'select',
+ '#title' => t('What Amazon associate ID do you want to use?'),
'#default_value' => variable_get('amazon_associate_setting', 'association'),
'#options' => array(
'association' => t('Use the Drupal Association\'s associate ID'),
@@ -26,17 +38,18 @@ function amazon_settings_form($form, &$form_state) {
'#description' => t('Outgoing links to Amazon.com can include an associate ID code. When shoppers purchase Amazon products via one of those links, the associate ID is used to determine who should receive a referral bonus from Amazon.com.'),
);
- $form['amazon_custom_associate_id'] = array(
+ $form['associate_setting']['amazon_custom_associate_id'] = array(
'#type' => 'textfield',
'#title' => t('Your associate ID'),
'#description' => t('Enter your own associate ID to receive referral bonuses when shoppers purchase Amazon products via your site.'),
'#default_value' => variable_get('amazon_custom_associate_id', ''),
- '#prefix' => '',
- '#suffix' => '
',
+ '#states' => array(
+ 'visible' => array(
+ "select[name=amazon_associate_setting]" => array('value' => 'custom'),
+ ),
+ ),
+
);
- if (variable_get('amazon_associate_setting', 'association') != 'custom') {
- $form['amazon_custom_associate_id']['#prefix'] = '';
- }
$form['amazon_aws_access_key'] = array(
'#type' => 'textfield',
@@ -54,12 +67,12 @@ function amazon_settings_form($form, &$form_state) {
'#required' => TRUE,
);
- // Now add the Javascript that does the fancy hide/show effects.
- drupal_add_js(drupal_get_path('module', 'amazon') . '/amazon.admin.js');
-
return system_settings_form($form);
}
+/**
+ * Form to determine how long things get cached.
+ */
function amazon_storage_settings_form($form, &$form_state) {
$period = drupal_map_assoc(array(3600, 7200, 14400, 21600, 43200, 86400), 'format_interval');
@@ -83,9 +96,6 @@ function amazon_storage_settings_form($form, &$form_state) {
),
);
- // Now add the Javascript that does the fancy hide/show effects.
- drupal_add_js(drupal_get_path('module', 'amazon') . '/amazon.admin.js');
-
return system_settings_form($form);
}
diff --git amazon.admin.js amazon.admin.js
deleted file mode 100644
index 5f9579a..0000000
--- amazon.admin.js
+++ /dev/null
@@ -1,28 +0,0 @@
-//$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;
- })
- });
-}
-};
\ No newline at end of file
diff --git amazon.install amazon.install
index dd54281..52f78d3 100644
--- amazon.install
+++ amazon.install
@@ -11,15 +11,12 @@
* Implements hook_install.
*/
function amazon_install() {
- drupal_install_schema('amazon');
}
/**
* Implements hook_uninstall().
*/
function amazon_uninstall() {
- // TODO The drupal_(un)install_schema functions are called automatically in D7.;
- // drupal_uninstall_schema('amazon');
$variables = preg_split('/\s+/',
"amazon_media_data
amazon_locale
@@ -44,11 +41,11 @@ function amazon_requirements($phase) {
$api_key = variable_get('amazon_aws_access_key', "");
$requirement = array();
if (empty($secret_access_key) || empty($api_key)) {
- 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'))));
+ 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/config/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')));
+ $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/config/amazon')));
return array('amazon_aws_secret_access_key', $requirement);
}
diff --git amazon.module amazon.module
index 0116a09..2cc4cc9 100644
--- amazon.module
+++ amazon.module
@@ -83,24 +83,19 @@ function amazon_theme() {
'amazon_inline_item' => array(
'variables' => array('item' => array()),
'template' => 'amazon-inline-item',
- // Re-use the existing infrastructure.
- 'preprocess functions' => 'template_preprocess_amazon_item',
+ 'preprocess functions' => array('template_preprocess_amazon_item'),
),
- // Allows use of whatever is provided in preprocessed $variables.
'amazon_detail' => array(
'variables' => array('item' => array(), 'detail' => NULL),
'template' => 'amazon-item-detail',
'preprocess functions' => array('template_preprocess_amazon_item'),
),
- );
- // Templates provided at the module level have to be explicitly listed.
- $templates += array(
- 'amazon_item_thumbnail' => array(
+ // All templates provided at the module level have to be explicitly listed.
+ 'amazon_item_detail' => array(
'variables' => array('item' => array()),
- 'template' => 'amazon-item-thumbnail',
+ 'template' => 'amazon-item-detail',
'preprocess functions' => array('template_preprocess_amazon_item'),
-
),
'amazon_item_details' => array(
'variables' => array('item' => array()),
@@ -112,6 +107,11 @@ function amazon_theme() {
'template' => 'amazon-item',
'preprocess functions' => array('template_preprocess_amazon_item'),
),
+ 'amazon_item_thumbnail' => array(
+ 'variables' => array('item' => array()),
+ 'template' => 'amazon-item-thumbnail',
+ 'preprocess functions' => array('template_preprocess_amazon_item'),
+ ),
);
return $templates;
@@ -229,16 +229,41 @@ function template_preprocess_amazon_item(&$variables, $theme_type) {
}
-
+/**
+ * Convert a type like ABIS_whatever into just whatever.
+ * @param unknown_type $type
+ */
function _amazon_clean_type($type) {
return check_plain(strtolower(str_replace(array('ABIS_', 'CONSOLE_', 'VIDEO_', ' '), array('', '', '', '_'), $type)));
}
+/**
+ * Create name of the extra css class for an item.
+ *
+ * @param $item
+ * The amazon_item.
+ */
function _amazon_item_classes($item) {
return 'amazon-item amazon-item-' . str_replace('_', '-', _amazon_clean_type($item['producttypename']));
}
+/**
+ * Create an issue an HTTP request to the Amazon API.
+ *
+ * Most of this is determined by the Amazon Product Advertising API.
+ * @see http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?CHAP_response_elements.html
+ *
+ *
+ * @param $operation
+ * Must be 'AWSECommerceService'
+ * @param $parameters
+ * An associative array with the parameters for the API call.
+ * @param $locale
+ * The (optional) locale, a 2-character Amazon locale indicator. This has
+ * nothing to do with an actual locale - it's really shorthand for what
+ * Amazon site to use.
+ */
function amazon_http_request($operation, $parameters = array(), $locale = NULL) {
if (!isset($locale)) {
$locale = variable_get('amazon_locale', 'US');
@@ -456,7 +481,7 @@ function _amazon_load_child_data(&$item) {
array('asin' => $item['asin']),
array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $participant) {
- unset($participant['asin']);
+ // unset($participant['asin']);
$item[$participant['type']][] = $participant['participant'];
$item['participants'][] = $participant['participant'];
}
diff --git amazon_filter/amazon_filter.module amazon_filter/amazon_filter.module
index b575811..220f1f7 100644
--- amazon_filter/amazon_filter.module
+++ amazon_filter/amazon_filter.module
@@ -73,14 +73,19 @@ function _amazon_filter_process_text($text) {
$replace[] = theme('amazon_inline_item', array('item' =>$item));
break;
- case 'thumbnail':
- // Handle themeable cases, like thumbnail, full.
+ // Full is a synonym of 'details'.
case 'full':
- $replace[] = theme('amazon_item', array('item' => $item, 'style' => $action));
+ case 'details':
+ $replace[] = theme('amazon_item', array('item' => $item));
+ break;
+
+ // Handle themeable cases, like thumbnail.
+ case 'thumbnail':
+ $replace[] = theme('amazon_item_thumbnail', array('item' => $item));
break;
default:
- // Allow to use anything found in the item.
+ // Allow to use anything found in the item.
$replace[] = theme('amazon_detail', array('item' => $item, 'detail' => $action));
break;
}
diff --git amazon_media/amazon_media.info amazon_media/amazon_media.info
index d47d695..e7d0bad 100644
--- amazon_media/amazon_media.info
+++ amazon_media/amazon_media.info
@@ -2,7 +2,7 @@ name = Amazon media
description = Stores extended Amazon product information for books, music, DVDs, and software.
package = Amazon
dependencies[] = amazon
-core = 6.x
+core = 7.x
php = 5.2
files[] = amazon-item-book-details.tpl.php
diff --git amazon_media/amazon_media.install amazon_media/amazon_media.install
index 9de7d3c..77f398c 100644
--- amazon_media/amazon_media.install
+++ amazon_media/amazon_media.install
@@ -8,7 +8,10 @@
// $Id$
function amazon_media_install() {
- drupal_install_schema('amazon_media');
+ amazon_media_update_7002(); // Set system weight.
+}
+
+function amazon_media_uninstall() {
}
function amazon_media_schema() {
@@ -63,10 +66,11 @@ function amazon_media_schema() {
return $schema;
}
-function amazon_media_uninstall() {
- db_query("DROP TABLE {amazon_book}");
- db_query("DROP TABLE {amazon_dvd}");
- db_query("DROP TABLE {amazon_music}");
- db_query("DROP TABLE {amazon_software}");
-}
-
+/**
+ * Set the weight on amazon_media to be higher than amazon.
+ *
+ * This allows amazon_media to override theme settings that amazon has done.
+ */
+function amazon_media_update_7002() {
+ db_query("UPDATE {system} SET weight = 10 WHERE name = 'amazon_media'");
+}
\ No newline at end of file
diff --git amazon_media/amazon_media.module amazon_media/amazon_media.module
index 3232726..a8e58c5 100644
--- amazon_media/amazon_media.module
+++ amazon_media/amazon_media.module
@@ -55,16 +55,16 @@ function amazon_media_theme() {
// amazon_item tpl's.
function amazon_media_theme_registry_alter(&$theme_registry) {
$theme_registry['amazon_item']['theme path'] = drupal_get_path('module', 'amazon_media');
-// if (!empty($theme_registry['amazon_item'])) {
-// // We'll try our best to avoid stepping on theme template files.
-// if (!empty($theme_registry['amazon_item']['theme_paths']) && count($theme_registry['amazon_item']['theme paths']) > 1) {
-// $theme = array_pop($theme_registry['amazon_item']['theme paths']);
-// }
-// $theme_registry['amazon_item']['theme paths'][] = drupal_get_path('module', 'amazon_media');
-// if (isset($theme)) {
-// $theme_registry['amazon_item']['theme paths'][] = $theme;
-// }
-// }
+ if (!empty($theme_registry['amazon_item'])) {
+ // We'll try our best to avoid stepping on theme template files.
+ if (!empty($theme_registry['amazon_item']['theme_paths']) && count($theme_registry['amazon_item']['theme paths']) > 1) {
+ $theme = array_pop($theme_registry['amazon_item']['theme paths']);
+ }
+ $theme_registry['amazon_item']['theme paths'][] = drupal_get_path('module', 'amazon_media');
+ if (isset($theme)) {
+ $theme_registry['amazon_item']['theme paths'][] = $theme;
+ }
+ }
}
/**
@@ -127,7 +127,9 @@ function amazon_media_get_table_name($item) {
'VIDEO_GAMES' => 'amazon_software',
'SOFTWARE' => 'amazon_software',
);
- return $names[$item['producttypename']];
+ if (!empty($names[$item['producttypename']])) {
+ return $names[$item['producttypename']];
+ }
}
/**
@@ -144,17 +146,20 @@ function amazon_media_amazon_item_insert($item) {
}
$table = amazon_media_get_table_name($item);
- // We need to present a record that only has the items in it used by
- // this table.
- $db_item = array_intersect_key($item, $item_keys[$table]['fields']);
+ if (!empty($table)) {
- try {
- db_insert($table)
- ->fields($db_item)
- ->execute();
- }
- catch (Exception $e) {
- amazon_db_error_watchdog("Failed to insert item into amazon table", $e);
+ // We need to present a record that only has the items in it used by
+ // this table.
+ $db_item = array_intersect_key($item, $item_keys[$table]['fields']);
+
+ try {
+ db_insert($table)
+ ->fields($db_item)
+ ->execute();
+ }
+ catch (Exception $e) {
+ amazon_db_error_watchdog("Failed to insert item into amazon table", $e);
+ }
}
}
diff --git amazon_media/amazon_media.theme.inc amazon_media/amazon_media.theme.inc
index 25dffef..773ee95 100644
--- amazon_media/amazon_media.theme.inc
+++ amazon_media/amazon_media.theme.inc
@@ -11,6 +11,7 @@
*/
function theme_amazon_item__dvd($item, $style = 'default') {
+ drupal_set_message('Theming with theme_amazon_item__dvd');
$output = '';
$type = $item['type'];
switch ($style) {
diff --git amazon_search/amazon_search.module amazon_search/amazon_search.module
index 4b90698..6fbcac0 100644
--- amazon_search/amazon_search.module
+++ amazon_search/amazon_search.module
@@ -27,6 +27,9 @@ function amazon_search_search_access() {
return user_access('access amazon search');
}
+/**
+ * Implements hook_search_info().
+ */
function amazon_search_search_info() {
return array(
'title' => 'Amazon',
@@ -34,7 +37,7 @@ function amazon_search_search_info() {
);
}
/**
- * Implements hook_search(). Implements remote Amazon searching.
+ * Implements hook_search_execute(). Implements remote Amazon searching.
*/
function amazon_search_search_execute($keys = NULL) {
$products = array();
diff --git asin/asin.d5-migrate.inc asin/asin.d5-migrate.inc
deleted file mode 100644
index 5f0fc51..0000000
--- asin/asin.d5-migrate.inc
+++ /dev/null
@@ -1,78 +0,0 @@
-nid;
- }
-
- foreach ($nids as $nid) {
- if ($node = _asin_migrate_from_d5($nid, $fields)) {
- $context['results'][$node->nid] = $node->title;
-
- $context['sandbox']['progress']++;
- $context['sandbox']['current_node'] = $node->nid;
- $context['message'] = t('Now processing %node', array('%node' => $node->title));
- }
- }
- // Inform the batch engine that we are not finished,
- // and provide an estimation of the completion level we reached.
- if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
- $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
- }
-}
-
-/**
- * Batch 'finished' callback
- */
-function _asin_migrate_fields_finished($success, $results, $operations) {
- if ($success) {
- // Here we do something meaningful with the results.
- $message = count($results) .' nodes migrated to new ASIN field structure.';
- $message .= theme('item_list', $results);
- }
- else {
- // An error occurred.
- // $operations contains the operations that remained unprocessed.
- $error_operation = reset($operations);
- $message = 'An error occurred while processing '. $error_operation[0] .' with arguments :'. print_r($error_operation[0], TRUE);
- }
- drupal_set_message($message);
-}
-
-function _asin_migrate_from_d5($nid, $fields) {
- $results = db_query("SELECT asin, ntype FROM {amazonnode} an WHERE an.nid = %d", $nid);
- $dirty = FALSE;
- $node = node_load($nid);
-
- while ($asin = db_fetch_object($results)) {
- if (array_key_exists($asin->ntype, $fields)) {
- $node->{$asin->ntype}[]['asin'] = $asin->asin;
- }
- }
-
- node_save($node);
- $sql = "DELETE FROM {amazonnode} WHERE nid = %d AND ntype IN (" . db_placeholders($fields, 'varchar') . ")";
- $params = array_keys($fields);
- array_unshift($params, $nid);
- db_query($sql, $params);
-
- return $node;
-}
\ No newline at end of file
diff --git asin/asin.module asin/asin.module
index b6fab3a..d5e1946 100644
--- asin/asin.module
+++ asin/asin.module
@@ -34,33 +34,33 @@ function asin_field_schema($field) {
}
-/**
- * @todo: This is the leftover from D6 hook_field. Seems that there's some
- * views stuff yet to be done?
- */
-function asin_field_settings($op, $field) {
-// TODO: Views data stuff
- $data = content_views_field_views_data($field);
- $db_info = content_database_info($field);
- $table_alias = content_views_tablename($field);
-
- // Filter: Add a 'many to one' filter.
- $copy = $data[$table_alias][$field['field_name'] . '_asin'];
- $copy['title'] = t('@label (!name) - Allowed values', array('@label' => $field['widget']['label'], '!name' => $field['field_name']));
- $copy['filter']['handler'] = 'views_handler_filter_many_to_one';
- unset($copy['field'], $copy['argument'], $copy['sort']);
- $data[$table_alias][$field['field_name'] . '_value_many_to_one'] = $copy;
- // Argument : swap the handler to the 'many to one' operator.
- $data[$table_alias][$field['field_name'] . '_value']['argument']['handler'] = 'views_handler_argument_many_to_one';
-
- // Add a relationship for related node.
- $data[$table_alias][$field['field_name'] . '_asin']['relationship'] = array(
- 'base' => 'amazon_item',
- 'field' => $db_info['columns']['asin']['column'],
- 'handler' => 'views_handler_relationship',
- );
- return $data;
-}
+///**
+// * @todo: This is the leftover from D6 hook_field. Seems that there's some
+// * views stuff yet to be done?
+// */
+//function asin_field_settings($op, $field) {
+//// TODO: Views data stuff
+// $data = content_views_field_views_data($field);
+// $db_info = content_database_info($field);
+// $table_alias = content_views_tablename($field);
+//
+// // Filter: Add a 'many to one' filter.
+// $copy = $data[$table_alias][$field['field_name'] . '_asin'];
+// $copy['title'] = t('@label (!name) - Allowed values', array('@label' => $field['widget']['label'], '!name' => $field['field_name']));
+// $copy['filter']['handler'] = 'views_handler_filter_many_to_one';
+// unset($copy['field'], $copy['argument'], $copy['sort']);
+// $data[$table_alias][$field['field_name'] . '_value_many_to_one'] = $copy;
+// // Argument : swap the handler to the 'many to one' operator.
+// $data[$table_alias][$field['field_name'] . '_value']['argument']['handler'] = 'views_handler_argument_many_to_one';
+//
+// // Add a relationship for related node.
+// $data[$table_alias][$field['field_name'] . '_asin']['relationship'] = array(
+// 'base' => 'amazon_item',
+// 'field' => $db_info['columns']['asin']['column'],
+// 'handler' => 'views_handler_relationship',
+// );
+// return $data;
+//}
/**
@@ -68,12 +68,15 @@ function asin_field_settings($op, $field) {
*
* Checks each instance to see if it's valid on Amazon.
*/
-function asin_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
+function asin_field_validate($entity_type, $entity, $field, $instance, $langcode, &$items, &$errors) {
foreach ($items as $delta => &$item) {
$asin = $item['asin'];
if (!empty($asin)) { // Only continue if the ASIN is populated.
$results = _asin_load_items($asin);
- if (empty($results)) {
+ if (!empty($results)) {
+ $item['asin'] = key($results);
+ }
+ else {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => t('No Amazon product with the ASIN "%id" could be located.', array('%id' => $item['asin'])),
);
@@ -162,6 +165,7 @@ function asin_field_formatter_info() {
*/
function asin_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
+
foreach ($items as $delta => $item) {
$asin = trim($item['asin']);
$asins = array();
diff --git includes/amazon.views.inc includes/amazon.views.inc
index 26ee056..8ac341b 100644
--- includes/amazon.views.inc
+++ includes/amazon.views.inc
@@ -13,6 +13,7 @@
* @{
*/
+
/**
* Implementation of hook_views_plugins
*/
@@ -90,6 +91,7 @@ function amazon_views_data() {
'weight' => 10,
);
+
// ----------------------------------------------------------------
// Fields
_amazon_make_simple_text_field($data, 'amazon_item', 'asin', 'ASIN', 'The product ID of the item.');