📄 general.php
字号:
}
}
////
// Return a formatted address
// TABLES: address_format
function tep_address_format($address_format_id, $address, $html, $boln, $eoln) {
$address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . $address_format_id . "'");
$address_format = tep_db_fetch_array($address_format_query);
$firstname = addslashes($address['firstname']);
$lastname = addslashes($address['lastname']);
$street = addslashes($address['street_address']);
$suburb = addslashes($address['suburb']);
$city = addslashes($address['city']);
$state = addslashes($address['state']);
$country_id = $address['country_id'];
$zone_id = $address['zone_id'];
$postcode = addslashes($address['postcode']);
$zip = $postcode;
$country = tep_get_country_name($country_id);
$state = tep_get_zone_code($country_id, $zone_id, $state);
if ($html) {
// HTML Mode
$HR = '<hr>';
$hr = '<hr>';
if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults
$CR = '<br>';
$cr = '<br>';
$eoln = $cr;
} else { // Use values supplied
$CR = $eoln . $boln;
$cr = $CR;
}
} else {
// Text Mode
$CR = $eoln;
$cr = $CR;
$HR = '----------------------------------------';
$hr = '----------------------------------------';
}
$statecomma = '';
$streets = $street;
if ($suburb != '') $streets = $street . $cr . $suburb;
if ($firstname == '') $firstname = addslashes($address['name']);
if ($country == '') $country = addslashes($address['country']);
if ($state != '') $statecomma = $state . ', ';
$fmt = $address_format['format'];
eval("\$address = \"$fmt\";");
$address = stripslashes($address);
return $boln . $address . $eoln;
}
////
// Return a formatted address
// TABLES: customers, address_book
function tep_address_label($customers_id, $address_id = 1, $html = false, $boln = '', $eoln = "\n") {
$address_query = tep_db_query("select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . $customers_id . "' and address_book_id = '" . $address_id . "'");
$address = tep_db_fetch_array($address_query);
$format_id = tep_get_address_format_id($address['country_id']);
return tep_address_format($format_id, $address, $html, $boln, $eoln);
}
////
// Return a formatted address
// TABLES: address_book, address_format
function tep_address_summary($customers_id, $address_id) {
$customers_id = tep_db_prepare_input($customers_id);
$address_id = tep_db_prepare_input($address_id);
$address_query = tep_db_query("select ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_state, ab.entry_country_id, ab.entry_zone_id, c.countries_name, c.address_format_id from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_COUNTRIES . " c where ab.address_book_id = '" . tep_db_input($address_id) . "' and ab.customers_id = '" . tep_db_input($customers_id) . "' and ab.entry_country_id = c.countries_id");
$address = tep_db_fetch_array($address_query);
$street_address = $address['entry_street_address'];
$suburb = $address['entry_suburb'];
$postcode = $address['entry_postcode'];
$city = $address['entry_city'];
$state = tep_get_zone_code($address['entry_country_id'], $address['entry_zone_id'], $address['entry_state']);
$country = $address['countries_name'];
$address_format_query = tep_db_query("select address_summary from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . $address['address_format_id'] . "'");
$address_format = tep_db_fetch_array($address_format_query);
eval("\$address = \"{$address_format['address_summary']}\";");
return $address;
}
function tep_row_number_format($number) {
if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = '0' . $number;
return $number;
}
function tep_get_categories($categories_array = '', $parent_id = '0', $indent = '') {
global $languages_id;
$parent_id = tep_db_prepare_input($parent_id);
if (!is_array($categories_array)) $categories_array = array();
$categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . tep_db_input($parent_id) . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $languages_id . "' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query)) {
$categories_array[] = array('id' => $categories['categories_id'],
'text' => $indent . $categories['categories_name']);
if ($categories['categories_id'] != $parent_id) {
$categories_array = tep_get_categories($categories_array, $categories['categories_id'], $indent . ' ');
}
}
return $categories_array;
}
function tep_get_manufacturers($manufacturers_array = '') {
if (!is_array($manufacturers_array)) $manufacturers_array = array();
$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']);
}
return $manufacturers_array;
}
////
// Return all subcategory IDs
// TABLES: categories
function tep_get_subcategories(&$subcategories_array, $parent_id = 0) {
$subcategories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . $parent_id . "'");
while ($subcategories = tep_db_fetch_array($subcategories_query)) {
$subcategories_array[sizeof($subcategories_array)] = $subcategories['categories_id'];
if ($subcategories['categories_id'] != $parent_id) {
tep_get_subcategories($subcategories_array, $subcategories['categories_id']);
}
}
}
// Output a raw date string in the selected locale date format
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
function tep_date_long($raw_date) {
if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);
return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));
}
////
// Output a raw date string in the selected locale date format
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
function tep_date_short($raw_date) {
if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);
return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
}
////
// Parse search string into indivual objects
function tep_parse_search_string($search_str = '', &$objects) {
$search_str = trim(strtolower($search_str));
// Break up $search_str on whitespace; quoted string will be reconstructed later
$pieces = split('[[:space:]]+', $search_str);
$objects = array();
$tmpstring = '';
$flag = '';
for ($k=0; $k<count($pieces); $k++) {
while (substr($pieces[$k], 0, 1) == '(') {
$objects[] = '(';
if (strlen($pieces[$k]) > 1) {
$pieces[$k] = substr($pieces[$k], 1);
} else {
$pieces[$k] = '';
}
}
$post_objects = array();
while (substr($pieces[$k], -1) == ')') {
$post_objects[] = ')';
if (strlen($pieces[$k]) > 1) {
$pieces[$k] = substr($pieces[$k], 0, -1);
} else {
$pieces[$k] = '';
}
}
// Check individual words
if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) {
$objects[] = trim($pieces[$k]);
for ($j=0; $j<count($post_objects); $j++) {
$objects[] = $post_objects[$j];
}
} else {
/* This means that the $piece is either the beginning or the end of a string.
So, we'll slurp up the $pieces and stick them together until we get to the
end of the string or run out of pieces.
*/
// Make sure the $tmpstring is empty
$tmpstring = '';
// Add this word to the $tmpstring, starting the $tmpstring
$tmpstring .= trim(ereg_replace('"', ' ', $pieces[$k]));
// Check for one possible exception to the rule. That there is a single quoted word.
if (substr($pieces[$k], -1 ) == '"') {
// Turn the flag off for future iterations
$flag = 'off';
$objects[] = trim($pieces[$k]);
for ($j=0; $j<count($post_objects); $j++) {
$objects[] = $post_objects[$j];
}
unset($tmpstring);
// Stop looking for the end of the string and move onto the next word.
continue;
}
// Otherwise, turn on the flag to indicate no quotes have been found attached to this word in the string.
$flag = 'on';
// Move on to the next word
$k++;
// Keep reading until the end of the string as long as the $flag is on
while ( ($flag == 'on') && ($k < count($pieces)) ) {
while (substr($pieces[$k], -1) == ')') {
$post_objects[] = ')';
if (strlen($pieces[$k]) > 1) {
$pieces[$k] = substr($pieces[$k], 0, -1);
} else {
$pieces[$k] = '';
}
}
// If the word doesn't end in double quotes, append it to the $tmpstring.
if (substr($pieces[$k], -1) != '"') {
// Tack this word onto the current string entity
$tmpstring .= ' ' . $pieces[$k];
// Move on to the next word
$k++;
continue;
} else {
/* If the $piece ends in double quotes, strip the double quotes, tack the
$piece onto the tail of the string, push the $tmpstring onto the $haves,
kill the $tmpstring, turn the $flag "off", and return.
*/
$tmpstring .= ' ' . trim(ereg_replace('"', ' ', $pieces[$k]));
// Push the $tmpstring onto the array of stuff to search for
$objects[] = trim($tmpstring);
for ($j=0; $j<count($post_objects); $j++) {
$objects[] = $post_objects[$j];
}
unset($tmpstring);
// Turn off the flag to exit the loop
$flag = 'off';
}
}
}
}
// add default logical operators if needed
$temp = array();
for($i=0; $i<(count($objects)-1); $i++) {
$temp[sizeof($temp)] = $objects[$i];
if ( ($objects[$i] != 'and') &&
($objects[$i] != 'or') &&
($objects[$i] != '(') &&
($objects[$i] != ')') &&
($objects[$i+1] != 'and') &&
($objects[$i+1] != 'or') &&
($objects[$i+1] != '(') &&
($objects[$i+1] != ')') ) {
$temp[sizeof($temp)] = ADVANCED_SEARCH_DEFAULT_OPERATOR;
}
}
$temp[sizeof($temp)] = $objects[$i];
$objects = $temp;
$keyword_count = 0;
$operator_count = 0;
for($i=0; $i<count($objects); $i++) {
if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) {
$operator_count ++;
} elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {
$keyword_count ++;
}
}
if ($operator_count < $keyword_count) {
return true;
} else {
return false;
}
}
////
// Check date
function tep_checkdate($date_to_check, $format_string, &$date_array) {
$separator_idx = -1;
$separators = array('-', ' ', '/', '.');
$month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
$no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$format_string = strtolower($format_string);
if (strlen($date_to_check) != strlen($format_string)) {
return false;
}
for ($i=0; $i<sizeof($separators); $i++) {
$pos_separator = strpos($date_to_check, $separators[$i]);
if ($pos_separator != false) {
$date_separator_idx = $i;
break;
}
}
for ($i=0; $i<sizeof($separators); $i++) {
$pos_separator = strpos($format_string, $separators[$i]);
if ($pos_separator != false) {
$format_separator_idx = $i;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -