/[drupal]/contributions/modules/amazontools/amazon.module
ViewVC logotype

Diff of /contributions/modules/amazontools/amazon.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.63, Thu Jan 25 00:13:16 2007 UTC revision 1.64, Thu Aug 21 00:37:24 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* $Id: amazon.module,v 1.62 2007/01/07 04:55:45 prometheus6 Exp $ */  /* $Id: amazon.module,v 1.63.2.7 2007/02/15 02:45:50 prometheus6 Exp $ */
3  if (version_compare(phpversion(), '5', '<')) {  if (version_compare(phpversion(), '5', '<')) {
4    require_once('amazon.php4.inc');    require_once('amazon.php4.inc');
5  }  }
# Line 131  function _to_amazonnode($amazon) { Line 131  function _to_amazonnode($amazon) {
131    $exists = db_num_rows($exists_query);    $exists = db_num_rows($exists_query);
132    if (!$exists) {    if (!$exists) {
133      $node = array('type' => 'amazon_node');      $node = array('type' => 'amazon_node');
134      $amazon_node['asin'] = $amazon->asin;      $amazon_node = array(
135      $amazon_node['log'] = '';          'op' => t('Submit'),
136                'asin' => $amazon->asin,
137                'name' => $user->name,
138                'taxonomy' => $amazon->taxonomy,
139                'log' => '',
140        );
141      drupal_execute('amazon_node_node_form', $amazon_node, $node);      drupal_execute('amazon_node_node_form', $amazon_node, $node);
142    }    }
143  }  }
# Line 165  function amazon_block($op = 'list', $del Line 170  function amazon_block($op = 'list', $del
170        $form = array();        $form = array();
171        switch ($delta) {        switch ($delta) {
172          case 0:          case 0:
                 $form['amazon_read_blocktitle'] = array(  
                   '#type' => 'textfield',  
                   '#default_value' => variable_get('amazon_read_blocktitle', 'We read'),  
                   '#size' => 30,  
                   '#maxlength' => 120,  
                   '#description' => t('Enter the title for the Amazon product block'),  
                   '#title' => 'Block title',  
                 );  
173                  break;                  break;
174          case 1:          case 1:
                 $form['amazon_reviewed_blocktitle'] = array(  
                   '#type' => 'textfield',  
                   '#default_value' => variable_get('amazon_reviewed_blocktitle', 'We reviewed'),  
                   '#size' => 30,  
                   '#maxlength' => 120,  
                   '#description' => t('Enter the title for the reviewed Amazon product block'),  
                   '#title' => 'Block title',  
                 );  
175                  break;                  break;
176          case 2:          case 2:
                 $form['amazon_recommended_blocktitle'] = array(  
                   '#type' => 'textfield',  
                   '#default_value' => variable_get('amazon_recommended_blocktitle', 'We recommend'),  
                   '#size' => 30,  
                   '#maxlength' => 120,  
                   '#description' => t('Enter the title for the recommended Amazon product block'),  
                   '#title' => 'Block title',  
                 );  
177                  $options = array(t('<none>'));                  $options = array(t('<none>'));
178                  $options = array_merge($options, explode(',', variable_get('amazon_ratings_labels', 'Poor, Below average, Average, Above average, Excellent')));                  $options = array_merge($options, explode(',', variable_get('amazon_ratings_labels', 'Poor, Below average, Average, Above average, Excellent')));
179                  $form['amazon_recommended_minimum_rating'] = array(                  $form['amazon_recommended_minimum_rating'] = array(
# Line 209  function amazon_block($op = 'list', $del Line 190  function amazon_block($op = 'list', $del
190      case 'save': {      case 'save': {
191        switch ($delta) {        switch ($delta) {
192          case 0:          case 0:
                 variable_set('amazon_read_blocktitle', $edit['amazon_read_blocktitle']);  
193                  break;                  break;
194          case 1:          case 1:
                 variable_set('amazon_reviewed_blocktitle', $edit['amazon_reviewed_blocktitle']);  
195                  break;                  break;
196          case 2:          case 2:
                 variable_set('amazon_recommended_blocktitle', $edit['amazon_recommended_blocktitle']);  
197                  variable_set('amazon_recommended_minimum_rating', $edit['amazon_recommended_minimum_rating']);                  variable_set('amazon_recommended_minimum_rating', $edit['amazon_recommended_minimum_rating']);
198                  break;                  break;
199        }        }
200        break;        break;
201      }      }
202      case 'list': {      case 'list': {
203        $block[0]['info'] = "Amazon: ".variable_get('amazon_read_blocktitle', 'Random book');        $block[0]['info'] = 'Amazon: Random book';
204        $block[1]['info'] = "Amazon: ".variable_get('amazon_reviewed_blocktitle', 'Random review');        $block[1]['info'] = 'Amazon: Random review';
205        $block[2]['info'] = "Amazon: ".variable_get('amazon_recommended_blocktitle', 'We recommend');        $block[2]['info'] = 'Amazon: We recommend';
206        return $block;        return $block;
207      }      }
208      case 'view': {      case 'view': {
# Line 257  function amazon_block($op = 'list', $del Line 235  function amazon_block($op = 'list', $del
235          switch ($delta) {          switch ($delta) {
236            case 0:            case 0:
237              $selected_book = db_fetch_object(db_query("SELECT * from {amazonitem} LIMIT 1 OFFSET $random"));              $selected_book = db_fetch_object(db_query("SELECT * from {amazonitem} LIMIT 1 OFFSET $random"));
238              $blocksubject = variable_get('amazon_read_blocktitle', t('We read'));              $blocksubject = t('We read');
239              break;              break;
240            case 1:            case 1:
241              $selected_book = db_fetch_object(db_query("              $selected_book = db_fetch_object(db_query("
# Line 266  function amazon_block($op = 'list', $del Line 244  function amazon_block($op = 'list', $del
244                JOIN {amazonitem} a ON a.asin = n.asin                JOIN {amazonitem} a ON a.asin = n.asin
245                WHERE ntype = 'amazon'                WHERE ntype = 'amazon'
246                LIMIT 1 OFFSET $random"));                LIMIT 1 OFFSET $random"));
247              $blocksubject = variable_get('amazon_reviewed_blocktitle', t('We reviewed'));              $blocksubject = t('We reviewed');
248              break;              break;
249            case 2:            case 2:
250              $selected_book = db_fetch_object(db_query("              $selected_book = db_fetch_object(db_query("
# Line 276  function amazon_block($op = 'list', $del Line 254  function amazon_block($op = 'list', $del
254                WHERE n.rating >= $amazon_block_minimum_score                WHERE n.rating >= $amazon_block_minimum_score
255                LIMIT 1 OFFSET $random"                LIMIT 1 OFFSET $random"
256              ));              ));
257              $blocksubject = variable_get('amazon_recommended_blocktitle', t('We recommend'));              $blocksubject = t('We recommend');
258              break;              break;
259          }          }
260        }        }
# Line 327  function amazon_delete($node) { Line 305  function amazon_delete($node) {
305  }  }
306    
307  function amazon_form($node) {  function amazon_form($node) {
308            $type = node_get_types('type', $node);
309    $form = array();    $form = array();
310    if (is_null($node->nid)) {    if (is_null($node->nid)) {
311          $form['asin'] = array(          $form['asin'] = array(
# Line 355  function amazon_form($node) { Line 334  function amazon_form($node) {
334    if ($node->type == 'amazon') {    if ($node->type == 'amazon') {
335      $form['title'] = array(      $form['title'] = array(
336        '#type' => 'textfield',        '#type' => 'textfield',
337        '#title' => t('Title'),        '#title' => check_plain($type->title_label),
338        '#default_value' => $node->title,        '#default_value' => $node->title,
339        '#size' => 20,        '#size' => 20,
340          '#required' => TRUE,          '#required' => TRUE,
341      );      );
342      $form['body'] = array(      $form['body'] = array(
343        '#type' => 'textarea',        '#type' => 'textarea',
344        '#title' => t('Body'),        '#title' => check_plain($type->body_label),
345        '#default_value' => $node->body,        '#default_value' => $node->body,
346        '#cols' => 60,        '#cols' => 60,
347        '#rows' => 20,        '#rows' => 20,
# Line 377  function amazon_form_alter($form_id, &$f Line 356  function amazon_form_alter($form_id, &$f
356      $node_type = $form_values['old_type']['#value'];      $node_type = $form_values['old_type']['#value'];
357      if (strpos($node_type, 'amazon') === FALSE) {      if (strpos($node_type, 'amazon') === FALSE) {
358              $form_values['workflow']['amazon_related_link'] = array(              $form_values['workflow']['amazon_related_link'] = array(
359                '#type' => 'checkbox',                '#type' => 'radios',
360                '#title' => t('Allow Amazon.com related product link'),                '#title' => t('Allow Amazon.com related product link'),
361                '#default_value' => variable_get('amazon_related_link_'.$node_type, 0),                '#default_value' => variable_get('amazon_related_link_'.$node_type, 0),
362                  '#options' => array(t('Disabled'), t('Enabled')),
363              );              );
364      }      }
365    }    }
366    elseif (($form_id == $form_values['type']['#value'] .'_node_form')) {    elseif (($form_id == $form_values['type']['#value'] .'_node_form')) {
367          $node = $form_values['#node'];          $node = $form_values['#node'];
368      if (variable_get('amazon_related_link_'.$form_values['type']['#value'], 0) > 0) {      if (variable_get('amazon_related_link_'.$form_values['type']['#value'], 0) > 0) {
369        $form_values['asin'] = array(          $form_values['asin_field'] = array(
370            '#type' => 'fieldset',
371            '#title' => t('Related Amazon.com product id'),
372            '#collapsible' => TRUE,
373            '#collapsed' => empty($node->asin),
374            );
375          $form_values['asin_field']['asin'] = array(
376          '#type' => 'textfield',          '#type' => 'textfield',
377          '#title' => t('Related books'),          '#title' => t('Related product(s)'),
378          '#size' => 20,          '#size' => 20,
379          '#maxlength' => 110,          '#maxlength' => 110,
380          '#default_value' => $node->asin,          '#default_value' => $node->asin,
381          '#description' => t('Enter a comma delimited list of ASINs for the related books.'),          '#description' => t('Enter a comma delimited list of up to 10 ASINs for the related books.'),
382          '#weight' => 10,          '#weight' => 10,
383          '#valid' => 'asin',          '#valid' => 'asin',
384        );        );
# Line 425  function valid_asin() { Line 411  function valid_asin() {
411  function amazon_node_form_validate($form_id, &$form_values) {  function amazon_node_form_validate($form_id, &$form_values) {
412    $asin = $form_values['asin'];    $asin = $form_values['asin'];
413    $amazondata = _amazon_product_data_from_Amazon($asin);    $amazondata = _amazon_product_data_from_Amazon($asin);
414    
415    if (count($amazondata) == 0) {    if (count($amazondata) == 0) {
416          form_set_error('asin', t("No product: %asin exists at Amazon.com"), array('%asin' => $asin));          form_set_error('asin', t("No product: %asin exists at Amazon.com"), array('%asin' => $asin));
417    }    }
# Line 441  function amazon_node_node_form_validate( Line 428  function amazon_node_node_form_validate(
428  }  }
429    
430  function amazon_node_node_form_submit($form_id, &$form_values) {  function amazon_node_node_form_submit($form_id, &$form_values) {
431    
432      $asin = $form_values['asin'];
433      $amazon_result = _amazon_product_data_from_Amazon($asin);
434      $form_values['title'] = $form_values['title'] ? $form_values['title'] : truncate_utf8($amazon_result[0]->title, 128, TRUE);
435      $form_values['body'] = $form_values['body'] ? $form_values['body'] : $amazon_result[0]->editorialreview;
436      $form_values['log'] = $form_values['log'] ? $form_values['log'] : '';
437      if ($form_values['op'] == t('Submit')) {
438        return node_form_submit($form_id, $form_values);
439      }
440    }
441    
442    function amazon_node_form_submit($form_id, &$form_values) {
443    $asin = $form_values['asin'];    $asin = $form_values['asin'];
444    $amazon_result = _amazon_product_data_from_Amazon($asin);    $amazon_result = _amazon_product_data_from_Amazon($asin);
445    $form_values['title'] = $form_values['title'] ? $form_values['title'] : truncate_utf8($amazon_result[0]->title, 128, TRUE);    $form_values['title'] = $form_values['title'] ? $form_values['title'] : truncate_utf8($amazon_result[0]->title, 128, TRUE);
446    $form_values['body'] = $form_values['body'] ? $form_values['body'] : $amazon_result[0]->editorialreview;    $form_values['body'] = $form_values['body'] ? $form_values['body'] : $amazon_result[0]->editorialreview;
447    $form_values['log'] = $form_values['log'] ? $form_values['log'] : '';    $form_values['log'] = $form_values['log'] ? $form_values['log'] : '';
448    return node_form_submit($form_id, $form_values);    if ($form_values['op'] == t('Submit')) {
449        return node_form_submit($form_id, $form_values);
450      }
451  }  }
452    
453  function amazon_help($section) {  function amazon_help($section) {
# Line 516  function amazon_manage() { Line 517  function amazon_manage() {
517  function amazon_item_manage() {  function amazon_item_manage() {
518    // get total number of amazon item and number of stale dated items    // get total number of amazon item and number of stale dated items
519    $stale_price_date = date('Y-m-d', time() - 604800); //604800 is a week of seconds    $stale_price_date = date('Y-m-d', time() - 604800); //604800 is a week of seconds
520    $counterquery = db_query("SELECT 'total' as counttype, count(asin) AS count from amazonitem    $cq = "SELECT 'total' as counttype, count(asin) AS count from {amazonitem}
521    UNION    UNION
522    SELECT 'stale' as counttype, count(asin) FROM {amazonitem} WHERE pricedate <= '%s'", $stale_price_date);    SELECT 'stale' as counttype, count(asin) FROM {amazonitem} WHERE pricedate <= '$stale_price_date'";
523      $counterquery = db_query($cq);
524    while ($counter_record = db_fetch_object($counterquery)) {    while ($counter_record = db_fetch_object($counterquery)) {
525          switch ($counter_record->counttype) {          switch ($counter_record->counttype) {
526                  case 'stale':                  case 'stale':
# Line 580  function amazon_menu($may_cache) { Line 582  function amazon_menu($may_cache) {
582                       'callback' => 'amazon_import_page');                       'callback' => 'amazon_import_page');
583      foreach ($_amazon_search_browse_fields as $product_type => $data) {      foreach ($_amazon_search_browse_fields as $product_type => $data) {
584              $items[] = array('path' => 'admin/content/amazon_import/import/' . $product_type,              $items[] = array('path' => 'admin/content/amazon_import/import/' . $product_type,
585                               'title' => ($product_type),                               'title' => $product_type,
586                               'access' => TRUE,                               'access' => TRUE,
587                               'type' => MENU_LOCAL_TASK,                               'type' => MENU_LOCAL_TASK,
588                               'callback' => 'amazon_import_page',                               'callback' => 'amazon_import_page',
# Line 598  function amazon_menu($may_cache) { Line 600  function amazon_menu($may_cache) {
600                       'access' => user_access('search amazon.com'),                       'access' => user_access('search amazon.com'),
601                       'type' => MENU_LOCAL_TASK,                       'type' => MENU_LOCAL_TASK,
602                       'callback' => 'amazon_search_page');                       'callback' => 'amazon_search_page');
603        $tab_weight = 0;
604      foreach ($_amazon_search_browse_fields as $product_type => $data) {      foreach ($_amazon_search_browse_fields as $product_type => $data) {
605              $items[] = array('path' => 'search/amazon/' . $product_type,              $items[] = array('path' => 'search/amazon/' . $product_type,
606                               'title' => ($product_type),                               'title' => ($product_type),
# Line 619  function amazon_menu($may_cache) { Line 622  function amazon_menu($may_cache) {
622  }  }
623    
624  function amazon_node_info() {  function amazon_node_info() {
625    return array('amazon' => array('name' => t('amazon'), 'module' => 'amazon',    return array(
626                              'description' => t('Review an item at Amazon.com.')),                  'amazon' => array(
627                 'amazon_node' => array('name' => t('amazon node'), 'module' => 'amazon',                  'name' => t('amazon'),
628                                  'description' => t('Amazon.com data for "related product" links.')));                  'module' => 'amazon',
629                    'description' => t('Review an item at Amazon.com.')
630              ),
631              'amazon_node' => array(
632                    'name' => t('amazon node'),
633                    'module' => 'amazon',
634                    'description' => t('Amazon.com data for "related product" links.')
635              )
636      );
637  }  }
638    
639  function amazon_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {  function amazon_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
# Line 667  function amazon_nodeapi(&$node, $op, $te Line 678  function amazon_nodeapi(&$node, $op, $te
678            $amazondata = $node->amazonnode_data;            $amazondata = $node->amazonnode_data;
679          }          }
680          if ($amazondata) {          if ($amazondata) {
681            foreach($amazondata as $amazon_data) {                                          $related_links = theme('amazon_related_links', $amazondata);
             $related_links .= theme('amazon_related_link', $amazon_data);  
           }  
682            $node->content['related_links'] = array(            $node->content['related_links'] = array(
683                                                    '#weight' => 5,
684              '#value' => $related_links              '#value' => $related_links
685            );            );
686          }          }
# Line 765  function _amazon_bulk_import(&$_search_f Line 775  function _amazon_bulk_import(&$_search_f
775          $amazon_node->taxonomy = $_search_form_values['items']["$amazon_node->asin"]['taxonomy'];          $amazon_node->taxonomy = $_search_form_values['items']["$amazon_node->asin"]['taxonomy'];
776        }        }
777        $amazon_node->rating = 0;        $amazon_node->rating = 0;
778    //drupal_set_message(print_r($amazon_node, 1));
779        _to_amazonnode($amazon_node);        _to_amazonnode($amazon_node);
780      }      }
781    }    }
# Line 882  function _amazon_search_params($_search_ Line 892  function _amazon_search_params($_search_
892    
893  function _amazon_seach_search($_amazon_search_params) {  function _amazon_seach_search($_amazon_search_params) {
894    global $_amazon_search_amazonDOM;    global $_amazon_search_amazonDOM;
   $url = amazon_search_RESTURI($_amazon_search_params);  
 //  drupal_set_message("<a href=\"$url\">Raw XML</a>");  
895    // do the query    // do the query
896    $_amazon_search_amazonDOM = amazon_get_DOM($_amazon_search_params);    $_amazon_search_amazonDOM = amazon_get_DOM($_amazon_search_params);
897    // return the array of items    // return the array of items
# Line 923  function _amazon_search_pager($_amazon_s Line 931  function _amazon_search_pager($_amazon_s
931    if ($_current_page > 1) {    if ($_current_page > 1) {
932      $output['leftfloat'] = array(      $output['leftfloat'] = array(
933        '#type' => 'markup',        '#type' => 'markup',
934        '#value' => '<div style="float: left">'        '#value' => '<div style="float: left;">'
935      );      );
936      $output[]['op'] = array(      $output[]['op'] = array(
937        '#type' => 'button',        '#type' => 'button',
# Line 949  function _amazon_search_pager($_amazon_s Line 957  function _amazon_search_pager($_amazon_s
957    if ($_current_page < $_TotalPages) {    if ($_current_page < $_TotalPages) {
958      $output['rightfloat']= array(      $output['rightfloat']= array(
959        '#type' => 'markup',        '#type' => 'markup',
960        '#value' => '<div style="float: right">'        '#value' => '<div style="float: right;">'
961      );      );
962      $output[]['op'] = array(      $output[]['op'] = array(
963        '#type' => 'button',        '#type' => 'button',
# Line 991  function _amazon_search_pager($_amazon_s Line 999  function _amazon_search_pager($_amazon_s
999      $_current_page = $_current_page ? $_current_page : 1;      $_current_page = $_current_page ? $_current_page : 1;
1000      $output['centerfloatstart']= array(      $output['centerfloatstart']= array(
1001        '#type' => 'markup',        '#type' => 'markup',
1002        '#value' => "<div style=\"text-align: center; verticle-align: top\">",        '#value' => '<div style="text-align: center; verticle-align: top">',
1003      );      );
1004      $output[]['op'] = array(      $output[]['op'] = array(
1005        '#type' => 'button',        '#type' => 'button',
# Line 1095  function _amazon_import_format_item($nod Line 1103  function _amazon_import_format_item($nod
1103      $datacell .= "<img src=\"$node->smallimageurl\" height=\"$node->smallimageheight\" width=\"$node->smallimagewidth\" alt=\"cover of $node->title\" />";      $datacell .= "<img src=\"$node->smallimageurl\" height=\"$node->smallimageheight\" width=\"$node->smallimagewidth\" alt=\"cover of $node->title\" />";
1104    }    }
1105    else {    else {
1106      $datacell .= "<img src=\"$module_dir/images/missings.gif\" height=\"150\" width=\"100\" alt=\"no image\" />";      $datacell .= "<img src=\"/$module_dir/images/missings.gif\" height=\"100\" width=\"102\" alt=\"no image\" />";
1107    }    }
1108    $datacell .= '</td>';    $datacell .= '</td>';
1109    $datacell .= "<td>";    $datacell .= "<td>";
# Line 1166  function _amazon_taxonomy_term_control() Line 1174  function _amazon_taxonomy_term_control()
1174          foreach ($vtree as $vterm) {          foreach ($vtree as $vterm) {
1175            $options[$vterm->tid] = $vterm->name;            $options[$vterm->tid] = $vterm->name;
1176          }          }
1177          $control = array(          $control[$vocab->vid] = array(
1178            '#type' => 'select',            '#type' => 'select',
1179            '#multiple' => $vocab->multiple,            '#multiple' => $vocab->multiple,
1180            '#prefix' => '<td>',            '#prefix' => '<td>',
1181            '#suffix' => '</td>',            '#suffix' => '</td>',
1182              '#options' => $options,
1183          );          );
         $control['#options'] = $options;  
1184          break;          break;
1185        case 1:        case 1:
1186          $control['tags'][$vocab->vid] = array(          $control['tags'][$vocab->vid] = array(
# Line 1208  function amazon_search_page() { Line 1216  function amazon_search_page() {
1216    if (count($_search_form_values) > 0) {    if (count($_search_form_values) > 0) {
1217      $_search_form_values['op'] = $_POST['op'] ? $_POST['op'] : 'Search';      $_search_form_values['op'] = $_POST['op'] ? $_POST['op'] : 'Search';
1218      if (!isset($_search_form_values['SearchIndex'])) {      if (!isset($_search_form_values['SearchIndex'])) {
1219          $search_index = array_keys($_amazon_search_browse_fields);          if (arg(2)) {
1220          $_search_form_values['SearchIndex'] = $search_index[0];                  $_search_form_values['SearchIndex'] = arg(2);
1221            }
1222            else {
1223                    $search_index = array_keys($_amazon_search_browse_fields);
1224                    $_search_form_values['SearchIndex'] = $search_index[0];
1225            }
1226      }      }
1227    }    }
1228    $_amazon_search_params = _amazon_search_params($_search_form_values, $_amazon_locale);    $_amazon_search_params = _amazon_search_params($_search_form_values, $_amazon_locale);
# Line 1226  function amazon_item_manage_submit($form Line 1239  function amazon_item_manage_submit($form
1239    $command = $_POST['op'];    $command = $_POST['op'];
1240    switch ($command) {    switch ($command) {
1241      case t('Mark all prices stale'):      case t('Mark all prices stale'):
1242        db_query("UPDATE amazonitem SET pricedate = '01/01/01'");        db_query("UPDATE {amazonitem} SET pricedate = '2001-01-01'");
1243        break;        break;
1244      case t('Refresh prices'):      case t('Refresh prices'):
1245            set_time_limit(600);
1246        $max_pass = $form_values['pass_count'] ? $form_values['pass_count'] : $form_values['max_passes'];        $max_pass = $form_values['pass_count'] ? $form_values['pass_count'] : $form_values['max_passes'];
1247        for ($pass = 0; $pass < $max_pass; $pass++ ) {        for ($pass = 0; $pass < $max_pass; $pass++ ) {
1248          amazon_cron();          amazon_cron();
# Line 1237  function amazon_item_manage_submit($form Line 1251  function amazon_item_manage_submit($form
1251    }    }
1252  }  }
1253    
1254  function amazon_input_result_form($_amazon_search_params, $_search_form_values) {  function amazon_import_result_form($_amazon_search_params, $_search_form_values) {
1255    global $_amazon_search_amazon_shop_URI;    global $_amazon_search_amazon_shop_URI;
1256    global $_amazon_search_amazonDOM;    global $_amazon_search_amazonDOM;
1257    global $_amazon_taxonomy_term_select;    global $_amazon_taxonomy_term_select;
# Line 1307  function amazon_input_result_form($_amaz Line 1321  function amazon_input_result_form($_amaz
1321          '#execute' => TRUE,          '#execute' => TRUE,
1322          '#prefix' => '<tr><td colspan="3">'          '#prefix' => '<tr><td colspan="3">'
1323        );        );
1324        $output[]['op'] = array(        if($_amazon_search_params['ItemPage'] < $_amazon_search_params['TotalPages']){
1325          '#type' => 'button',          $output[]['op'] = array(
1326          '#input' => TRUE,                  '#type' => 'button',
1327          '#name' => 'op',                  '#input' => TRUE,
1328          '#button_type' => 'submit',                  '#name' => 'op',
1329          '#value' => 'Import and continue',                  '#button_type' => 'submit',
1330          '#execute' => TRUE,                  '#value' => 'Import and continue',
1331          '#suffix' => '</td></tr>'                  '#execute' => TRUE,
1332        );                  '#suffix' => '</td></tr>'
1333  //      $output['pager'] = array_merge(array(                );
1334  //        '#prefix' => '<tr><td colspan="4">',        }
 //        '#suffix' => '</td></tr>'  
 //      ), drupal_get_form(_amazon_search_pager($_amazon_search_params)));  
1335        $output['pager'] = array(        $output['pager'] = array(
1336          '#type' => 'markup',          '#type' => 'markup',
1337          '#value' => '<tr><td colspan="4">' . drupal_get_form('_amazon_search_pager', $_amazon_search_params) . '</td></tr>'          '#value' => '<tr><td colspan="4">' . drupal_get_form('_amazon_search_pager', $_amazon_search_params) . '</td></tr>'
# Line 1347  function amazon_import_page() { Line 1359  function amazon_import_page() {
1359    global $_amazon_search_amazonDOM;    global $_amazon_search_amazonDOM;
1360    global $_amazon_search_params;    global $_amazon_search_params;
1361    global $_amazon_taxonomy_term_select;    global $_amazon_taxonomy_term_select;
1362      global $_amazon_search_browse_fields;
1363    
1364    $_amazon_locale_index =  variable_get('amazon_locale', '0');    $_amazon_locale_index =  variable_get('amazon_locale', '0');
1365    $_amazon_locale_list = array_keys($_amazon_search_amazon_shop_URI);    $_amazon_locale_list = array_keys($_amazon_search_amazon_shop_URI);
1366    $_amazon_locale = $_amazon_locale_list[$_amazon_locale_index];    $_amazon_locale = $_amazon_locale_list[$_amazon_locale_index];
1367            $search_indexes = array_keys($_amazon_search_browse_fields);
1368    
1369    $_search_form_values = $_POST;    $_search_form_values = $_POST;
1370    $_search_form_values['op'] = $_POST['op'];    $_search_form_values['op'] = $_POST['op'];
1371    $_search_form_values['SearchIndex'] = arg(4) ? arg(4) : 'Books';    $_search_form_values['SearchIndex'] = arg(4) ? arg(4) : $search_indexes[0];
1372    
1373    
1374    $_amazon_search_params = _amazon_search_params($_search_form_values,$_amazon_locale);    $_amazon_search_params = _amazon_search_params($_search_form_values,$_amazon_locale);
1375    if (($_search_form_values['op'] == 'Import') or ($_search_form_values['op'] == 'Import and continue')) {    if (($_search_form_values['op'] == 'Import') or ($_search_form_values['op'] == 'Import and continue')) {
# Line 1362  function amazon_import_page() { Line 1377  function amazon_import_page() {
1377    }    }
1378    // the search form itself    // the search form itself
1379    $search_form = drupal_get_form('_amazon_search_form', $_amazon_operation_request, $_search_form_values, $_amazon_locale);    $search_form = drupal_get_form('_amazon_search_form', $_amazon_operation_request, $_search_form_values, $_amazon_locale);
1380    $output = drupal_get_form('amazon_input_result_form', $_amazon_search_params, $_search_form_values);    $output = drupal_get_form('amazon_import_result_form', $_amazon_search_params, $_search_form_values);
1381    return $search_form . $output;    return $search_form . $output;
1382  }  }
1383    
# Line 1372  function theme_amazon_block($selected_bo Line 1387  function theme_amazon_block($selected_bo
1387          $review_url = url("node/$selected_book->nid");          $review_url = url("node/$selected_book->nid");
1388    }    }
1389    $module_dir = drupal_get_path('module', 'amazon');    $module_dir = drupal_get_path('module', 'amazon');
1390    $book_image = $selected_book->mediumimageurl ? $selected_book->mediumimageurl : "$module_dir/images/missingm.gif";    $book_image = $selected_book->mediumimageurl ? $selected_book->mediumimageurl : "/$module_dir/images/missingm.gif";
1391    $blockcontent = '<div class="amazontools_block">';    $blockcontent = '<div class="amazontools_block">';
1392    if ($is_review) {    if ($is_review) {
1393      $blockcontent .= "<a href=\"$review_url\">";      $blockcontent .= "<a href=\"$review_url\">";
# Line 1380  function theme_amazon_block($selected_bo Line 1395  function theme_amazon_block($selected_bo
1395      $blockcontent .= '</a>';      $blockcontent .= '</a>';
1396      $blockcontent .= "<span class=\"amazontools_detailpage_link\"> <a href=\"$selected_book->detailpageurl\" target=\"_blank\">";      $blockcontent .= "<span class=\"amazontools_detailpage_link\"> <a href=\"$selected_book->detailpageurl\" target=\"_blank\">";
1397      $blockcontent .= $selected_book->title;      $blockcontent .= $selected_book->title;
1398      $blockcontent .= '</a></span>';      $blockcontent .= '</a></span><br>';
1399      $blockcontent .= "<span class=\"amazontools_review_link\"><a href=\"$review_url\">";      $blockcontent .= "<span class=\"amazontools_review_link\"><a href=\"$review_url\">";
1400      $blockcontent .= t('Read the review');      $blockcontent .= t('Read the review');
1401      $blockcontent .= '</a></span>';      $blockcontent .= '</a></span>';
# Line 1395  function theme_amazon_block($selected_bo Line 1410  function theme_amazon_block($selected_bo
1410    
1411    }    }
1412    if ($selected_book->rating) {    if ($selected_book->rating) {
1413      $output .= "rating: <img src=\"$module_dir/images/rating$selected_book->rating.gif\" alt=\"$selected_book->rating\" /><br />";      $output .= "rating: <img src=\"/$module_dir/images/rating$selected_book->rating.gif\" alt=\"$selected_book->rating\" /><br />";
1414    }    }
1415    $blockcontent .= '</div>';    $blockcontent .= '</div>';
1416    return $blockcontent;    return $blockcontent;
1417  }  }
1418    
1419  function theme_amazon_node($node) {  function theme_amazon_node($node) {
1420            // do an amazon cron run to update some stale prices
1421      amazon_cron();
1422      // refresh item if older than a week
1423      $stale_price_date = date('Y-m-d', time() - 604800); //604800 is a week of seconds
1424      if ($node->pricedate <= $stale_price_date) {
1425        $ASIN_update = _amazon_product_data_from_Amazon($node->asin);
1426            // update the amazonitem record
1427            if (count($ASIN_update) > 0) {
1428              foreach($ASIN_update as $ASIN_data) {
1429                _refresh_amazonitem_data($ASIN_data);
1430              }
1431          }
1432      }
1433    $module_dir = drupal_get_path('module', 'amazon');    $module_dir = drupal_get_path('module', 'amazon');
1434    $output = '';    $output = '';
1435    $output .= '<table class="amazontools_table">';    $output .= '<table class="amazontools_table">';
# Line 1411  function theme_amazon_node($node) { Line 1439  function theme_amazon_node($node) {
1439      $output .= "<img src=\"$node->mediumimageurl\" height=\"$node->mediumimageheight\" width=\"$node->mediumimagewidth\" alt=\"cover of $node->title\" />";      $output .= "<img src=\"$node->mediumimageurl\" height=\"$node->mediumimageheight\" width=\"$node->mediumimagewidth\" alt=\"cover of $node->title\" />";
1440    }    }
1441    else {    else {
1442      $output .= "<img src=\"$module_dir/images/missingm.gif\" height=\"150\" width=\"100\" alt=\"no image\" />";      $output .= "<img src=\"/$module_dir/images/missingm.gif\" height=\"150\" width=\"100\" alt=\"no image\" />";
1443    }    }
1444    $output .= "</a></td><td>";    $output .= "</a></td><td>";
1445    if ($node->type == 'amazon') {    if ($node->type == 'amazon') {
# Line 1428  function theme_amazon_node($node) { Line 1456  function theme_amazon_node($node) {
1456    }    }
1457    
1458    if ($node->rating) {    if ($node->rating) {
1459      $output .= "rating: <img src=\"$module_dir/images/rating$node->rating.gif\" alt=\"\" /><br />";      $output .= "rating: <img src=\"/$module_dir/images/rating$node->rating.gif\" alt=\"\" /><br />";
1460    }    }
1461    
1462    if ($node->asin) {    if ($node->asin) {
# Line 1449  function theme_amazon_node($node) { Line 1477  function theme_amazon_node($node) {
1477    return $output;    return $output;
1478  }  }
1479    
1480    function theme_amazon_related_links($amazondata) {
1481            $oddeven = 1;
1482            $output = '<table class="amazontools_related">';
1483            foreach($amazondata as $amazon_data) {
1484                    if ($oddeven == 1) {
1485                            $output .= "<tr class='odd'>";
1486                            $oddeven = 0;
1487                            }
1488                    else {
1489                            $output .= "<tr class='even'>";
1490                            $oddeven = 1;
1491                            }
1492            $output .= theme('amazon_related_link', $amazon_data);
1493                    $output .= "</tr>";
1494            }
1495      $output .= '</table>';
1496            return $output;
1497    }
1498    
1499  function theme_amazon_related_link($node) {  function theme_amazon_related_link($node) {
1500    $output = '';    $output = '';
1501    $output .= "<table class=\" class=\"amazontools_related\"><tr>";    $output .= '<td><a href="'.$node->detailpageurl.'" target="_blank">';
   $output .= "<td><a href=\"$node->detailpageurl\" target=\"_blank\">";  
1502          $module_dir = drupal_get_path('module', 'amazon');          $module_dir = drupal_get_path('module', 'amazon');
1503    if ($node->smallimageurl) {    if ($node->smallimageurl) {
1504      $output .= "<img src=\"$node->smallimageurl\" height=\"$node->smallimageheight\" width=\"$node->smallimagewidth\" alt=\"cover of $node->title\" />";      $output .= "<img src=\"$node->smallimageurl\" height=\"$node->smallimageheight\" width=\"$node->smallimagewidth\" alt=\"cover of $node->title\" />";
1505    }    }
1506    else {    else {
1507      $output .= "<img src=\"$module_dir/images/missings.gif\" height=\"150\" width=\"100\" alt=\"no image\" />";      $output .= "<img src=\"$module_dir/images/missings.gif\" height=\"100\" width=\"102\" alt=\"no image\" />";
1508    }    }
1509    $output .= '</a></td>';    $output .= '</a></td>';
1510    $output .= "<td>";    $output .= "<td>";
# Line 1474  function theme_amazon_related_link($node Line 1520  function theme_amazon_related_link($node
1520      $output .= 'asin: ' . $node->asin . '<br />';      $output .= 'asin: ' . $node->asin . '<br />';
1521    }    }
1522    $output .= '</td>';    $output .= '</td>';
   $output .= '</tr></table>';  
1523    return $output;    return $output;
1524  }  }

Legend:
Removed from v.1.63  
changed lines
  Added in v.1.64

  ViewVC Help
Powered by ViewVC 1.1.2