| 1 |
<?php |
<?php |
| 2 |
/* $Id: amazon.module,v 1.63.2.2 2007/01/26 02:44:51 prometheus6 Exp $ */ |
/* $Id: amazon.module,v 1.63.2.3 2007/01/26 03:30:41 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 |
} |
} |
| 329 |
} |
} |
| 330 |
|
|
| 331 |
function amazon_form($node) { |
function amazon_form($node) { |
| 332 |
|
$type = node_get_types('type', $node); |
| 333 |
$form = array(); |
$form = array(); |
| 334 |
if (is_null($node->nid)) { |
if (is_null($node->nid)) { |
| 335 |
$form['asin'] = array( |
$form['asin'] = array( |
| 358 |
if ($node->type == 'amazon') { |
if ($node->type == 'amazon') { |
| 359 |
$form['title'] = array( |
$form['title'] = array( |
| 360 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 361 |
'#title' => t('Title'), |
'#title' => check_plain($type->title_label), |
| 362 |
'#default_value' => $node->title, |
'#default_value' => $node->title, |
| 363 |
'#size' => 20, |
'#size' => 20, |
| 364 |
'#required' => TRUE, |
'#required' => TRUE, |
| 365 |
); |
); |
| 366 |
$form['body'] = array( |
$form['body'] = array( |
| 367 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 368 |
'#title' => t('Body'), |
'#title' => check_plain($type->body_label), |
| 369 |
'#default_value' => $node->body, |
'#default_value' => $node->body, |
| 370 |
'#cols' => 60, |
'#cols' => 60, |
| 371 |
'#rows' => 20, |
'#rows' => 20, |
| 428 |
function amazon_node_form_validate($form_id, &$form_values) { |
function amazon_node_form_validate($form_id, &$form_values) { |
| 429 |
$asin = $form_values['asin']; |
$asin = $form_values['asin']; |
| 430 |
$amazondata = _amazon_product_data_from_Amazon($asin); |
$amazondata = _amazon_product_data_from_Amazon($asin); |
| 431 |
|
|
| 432 |
if (count($amazondata) == 0) { |
if (count($amazondata) == 0) { |
| 433 |
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)); |
| 434 |
} |
} |
| 453 |
return node_form_submit($form_id, $form_values); |
return node_form_submit($form_id, $form_values); |
| 454 |
} |
} |
| 455 |
|
|
| 456 |
|
function amazon_node_form_submit($form_id, &$form_values) { |
| 457 |
|
$asin = $form_values['asin']; |
| 458 |
|
$amazon_result = _amazon_product_data_from_Amazon($asin); |
| 459 |
|
$form_values['title'] = $form_values['title'] ? $form_values['title'] : truncate_utf8($amazon_result[0]->title, 128, TRUE); |
| 460 |
|
$form_values['body'] = $form_values['body'] ? $form_values['body'] : $amazon_result[0]->editorialreview; |
| 461 |
|
$form_values['log'] = $form_values['log'] ? $form_values['log'] : ''; |
| 462 |
|
if ($form_values['op'] == 'Submit') { |
| 463 |
|
return node_form_submit($form_id, $form_values); |
| 464 |
|
} |
| 465 |
|
} |
| 466 |
|
|
| 467 |
function amazon_help($section) { |
function amazon_help($section) { |
| 468 |
switch ($section) { |
switch ($section) { |
| 469 |
case 'node/add#amazon': |
case 'node/add#amazon': |
| 531 |
function amazon_item_manage() { |
function amazon_item_manage() { |
| 532 |
// get total number of amazon item and number of stale dated items |
// get total number of amazon item and number of stale dated items |
| 533 |
$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 |
| 534 |
$counterquery = db_query("SELECT 'total' as counttype, count(asin) AS count from {amazonitem} |
$cq = "SELECT 'total' as counttype, count(asin) AS count from {amazonitem} |
| 535 |
UNION |
UNION |
| 536 |
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'"; |
| 537 |
|
$counterquery = db_query($cq); |
| 538 |
while ($counter_record = db_fetch_object($counterquery)) { |
while ($counter_record = db_fetch_object($counterquery)) { |
| 539 |
switch ($counter_record->counttype) { |
switch ($counter_record->counttype) { |
| 540 |
case 'stale': |
case 'stale': |
| 636 |
} |
} |
| 637 |
|
|
| 638 |
function amazon_node_info() { |
function amazon_node_info() { |
| 639 |
return array('amazon' => array('name' => t('amazon'), 'module' => 'amazon', |
return array( |
| 640 |
'description' => t('Review an item at Amazon.com.')), |
'amazon' => array( |
| 641 |
'amazon_node' => array('name' => t('amazon node'), 'module' => 'amazon', |
'name' => t('amazon'), |
| 642 |
'description' => t('Amazon.com data for "related product" links.'))); |
'module' => 'amazon', |
| 643 |
|
'description' => t('Review an item at Amazon.com.') |
| 644 |
|
), |
| 645 |
|
'amazon_node' => array( |
| 646 |
|
'name' => t('amazon node'), |
| 647 |
|
'module' => 'amazon', |
| 648 |
|
'description' => t('Amazon.com data for "related product" links.') |
| 649 |
|
) |
| 650 |
|
); |
| 651 |
} |
} |
| 652 |
|
|
| 653 |
function amazon_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
function amazon_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
| 948 |
if ($_current_page > 1) { |
if ($_current_page > 1) { |
| 949 |
$output['leftfloat'] = array( |
$output['leftfloat'] = array( |
| 950 |
'#type' => 'markup', |
'#type' => 'markup', |
| 951 |
'#value' => '<div style="float: left">' |
'#value' => '<div style="float: left;">' |
| 952 |
); |
); |
| 953 |
$output[]['op'] = array( |
$output[]['op'] = array( |
| 954 |
'#type' => 'button', |
'#type' => 'button', |
| 974 |
if ($_current_page < $_TotalPages) { |
if ($_current_page < $_TotalPages) { |
| 975 |
$output['rightfloat']= array( |
$output['rightfloat']= array( |
| 976 |
'#type' => 'markup', |
'#type' => 'markup', |
| 977 |
'#value' => '<div style="float: right">' |
'#value' => '<div style="float: right;">' |
| 978 |
); |
); |
| 979 |
$output[]['op'] = array( |
$output[]['op'] = array( |
| 980 |
'#type' => 'button', |
'#type' => 'button', |
| 1016 |
$_current_page = $_current_page ? $_current_page : 1; |
$_current_page = $_current_page ? $_current_page : 1; |
| 1017 |
$output['centerfloatstart']= array( |
$output['centerfloatstart']= array( |
| 1018 |
'#type' => 'markup', |
'#type' => 'markup', |
| 1019 |
'#value' => "<div style=\"text-align: center; verticle-align: top\">", |
'#value' => '<div style="text-align: center; verticle-align: top">', |
| 1020 |
); |
); |
| 1021 |
$output[]['op'] = array( |
$output[]['op'] = array( |
| 1022 |
'#type' => 'button', |
'#type' => 'button', |
| 1233 |
if (count($_search_form_values) > 0) { |
if (count($_search_form_values) > 0) { |
| 1234 |
$_search_form_values['op'] = $_POST['op'] ? $_POST['op'] : 'Search'; |
$_search_form_values['op'] = $_POST['op'] ? $_POST['op'] : 'Search'; |
| 1235 |
if (!isset($_search_form_values['SearchIndex'])) { |
if (!isset($_search_form_values['SearchIndex'])) { |
| 1236 |
$search_index = array_keys($_amazon_search_browse_fields); |
if (arg(2)) { |
| 1237 |
$_search_form_values['SearchIndex'] = $search_index[0]; |
$_search_form_values['SearchIndex'] = arg(2); |
| 1238 |
|
} |
| 1239 |
|
else { |
| 1240 |
|
$search_index = array_keys($_amazon_search_browse_fields); |
| 1241 |
|
$_search_form_values['SearchIndex'] = $search_index[0]; |
| 1242 |
|
} |
| 1243 |
} |
} |
| 1244 |
} |
} |
| 1245 |
$_amazon_search_params = _amazon_search_params($_search_form_values, $_amazon_locale); |
$_amazon_search_params = _amazon_search_params($_search_form_values, $_amazon_locale); |
| 1256 |
$command = $_POST['op']; |
$command = $_POST['op']; |
| 1257 |
switch ($command) { |
switch ($command) { |
| 1258 |
case t('Mark all prices stale'): |
case t('Mark all prices stale'): |
| 1259 |
db_query("UPDATE amazonitem SET pricedate = '01/01/01'"); |
db_query("UPDATE amazonitem SET pricedate = '1901-01-01'"); |
| 1260 |
|
db_query("UPDATE amazonitem SET pricedate = '1901-01-01'"); |
| 1261 |
break; |
break; |
| 1262 |
case t('Refresh prices'): |
case t('Refresh prices'): |
| 1263 |
$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']; |
| 1268 |
} |
} |
| 1269 |
} |
} |
| 1270 |
|
|
| 1271 |
function amazon_input_result_form($_amazon_search_params, $_search_form_values) { |
function amazon_import_result_form($_amazon_search_params, $_search_form_values) { |
| 1272 |
global $_amazon_search_amazon_shop_URI; |
global $_amazon_search_amazon_shop_URI; |
| 1273 |
global $_amazon_search_amazonDOM; |
global $_amazon_search_amazonDOM; |
| 1274 |
global $_amazon_taxonomy_term_select; |
global $_amazon_taxonomy_term_select; |
| 1338 |
'#execute' => TRUE, |
'#execute' => TRUE, |
| 1339 |
'#prefix' => '<tr><td colspan="3">' |
'#prefix' => '<tr><td colspan="3">' |
| 1340 |
); |
); |
| 1341 |
$output[]['op'] = array( |
if($_amazon_search_params['ItemPage'] < $_amazon_search_params['TotalPages']){ |
| 1342 |
'#type' => 'button', |
$output[]['op'] = array( |
| 1343 |
'#input' => TRUE, |
'#type' => 'button', |
| 1344 |
'#name' => 'op', |
'#input' => TRUE, |
| 1345 |
'#button_type' => 'submit', |
'#name' => 'op', |
| 1346 |
'#value' => 'Import and continue', |
'#button_type' => 'submit', |
| 1347 |
'#execute' => TRUE, |
'#value' => 'Import and continue', |
| 1348 |
'#suffix' => '</td></tr>' |
'#execute' => TRUE, |
| 1349 |
); |
'#suffix' => '</td></tr>' |
| 1350 |
// $output['pager'] = array_merge(array( |
); |
| 1351 |
// '#prefix' => '<tr><td colspan="4">', |
} |
|
// '#suffix' => '</td></tr>' |
|
|
// ), drupal_get_form(_amazon_search_pager($_amazon_search_params))); |
|
| 1352 |
$output['pager'] = array( |
$output['pager'] = array( |
| 1353 |
'#type' => 'markup', |
'#type' => 'markup', |
| 1354 |
'#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>' |
| 1393 |
} |
} |
| 1394 |
// the search form itself |
// the search form itself |
| 1395 |
$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); |
| 1396 |
$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); |
| 1397 |
return $search_form . $output; |
return $search_form . $output; |
| 1398 |
} |
} |
| 1399 |
|
|
| 1426 |
|
|
| 1427 |
} |
} |
| 1428 |
if ($selected_book->rating) { |
if ($selected_book->rating) { |
| 1429 |
$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 />"; |
| 1430 |
} |
} |
| 1431 |
$blockcontent .= '</div>'; |
$blockcontent .= '</div>'; |
| 1432 |
return $blockcontent; |
return $blockcontent; |
| 1459 |
} |
} |
| 1460 |
|
|
| 1461 |
if ($node->rating) { |
if ($node->rating) { |
| 1462 |
$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 />"; |
| 1463 |
} |
} |
| 1464 |
|
|
| 1465 |
if ($node->asin) { |
if ($node->asin) { |