📄 general.php
字号:
if ($date_separator_idx != $format_separator_idx) {
return false;
}
if ($date_separator_idx != -1) {
$format_string_array = explode( $separators[$date_separator_idx], $format_string );
if (sizeof($format_string_array) != 3) {
return false;
}
$date_to_check_array = explode( $separators[$date_separator_idx], $date_to_check );
if (sizeof($date_to_check_array) != 3) {
return false;
}
for ($i=0; $i<sizeof($format_string_array); $i++) {
if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm') $month = $date_to_check_array[$i];
if ($format_string_array[$i] == 'dd') $day = $date_to_check_array[$i];
if ( ($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa') ) $year = $date_to_check_array[$i];
}
} else {
if (strlen($format_string) == 8 || strlen($format_string) == 9) {
$pos_month = strpos($format_string, 'mmm');
if ($pos_month != false) {
$month = substr( $date_to_check, $pos_month, 3 );
for ($i=0; $i<sizeof($month_abbr); $i++) {
if ($month == $month_abbr[$i]) {
$month = $i;
break;
}
}
} else {
$month = substr($date_to_check, strpos($format_string, 'mm'), 2);
}
} else {
return false;
}
$day = substr($date_to_check, strpos($format_string, 'dd'), 2);
$year = substr($date_to_check, strpos($format_string, 'yyyy'), 4);
}
if (strlen($year) != 4) {
return false;
}
if (!settype($year, 'integer') || !settype($month, 'integer') || !settype($day, 'integer')) {
return false;
}
if ($month > 12 || $month < 1) {
return false;
}
if ($day < 1) {
return false;
}
if (tep_is_leap_year($year)) {
$no_of_days[1] = 29;
}
if ($day > $no_of_days[$month - 1]) {
return false;
}
$date_array = array($year, $month, $day);
return true;
}
////
// Check if year is a leap year
function tep_is_leap_year($year) {
if ($year % 100 == 0) {
if ($year % 400 == 0) return true;
} else {
if (($year % 4) == 0) return true;
}
return false;
}
////
// Return table heading with sorting capabilities
function tep_create_sort_heading($sortby, $colnum, $heading) {
global $PHP_SELF;
$sort_prefix = '';
$sort_suffix = '';
if ($sortby) {
$sort_prefix = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('page', 'info', 'x', 'y', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a'), 'NONSSL') . '" title="' . TEXT_SORT_PRODUCTS . ($sortby == $colnum . 'd' || substr($sortby, 0, 1) != $colnum ? TEXT_ASCENDINGLY : TEXT_DESCENDINGLY) . TEXT_BY . $heading . '">' ;
$sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . '</a>';
}
return $sort_prefix . $heading . $sort_suffix;
}
////
// Recursively go through the categories and retreive all parent categories IDs
// TABLES: categories
function tep_get_parent_categories(&$categories, $categories_id) {
$parent_categories_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $categories_id . "'");
while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
if ($parent_categories['parent_id'] == 0) return true;
$categories[sizeof($categories)] = $parent_categories['parent_id'];
if ($parent_categories['parent_id'] != $categories_id) {
tep_get_parent_categories($categories, $parent_categories['parent_id']);
}
}
}
////
// Construct a category path to the product
// TABLES: products_to_categories
function tep_get_product_path($products_id) {
$cPath = '';
$cat_count_sql = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");
$cat_count_data = tep_db_fetch_array($cat_count_sql);
if ($cat_count_data['count'] == 1) {
$categories = array();
$cat_id_sql = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");
$cat_id_data = tep_db_fetch_array($cat_id_sql);
tep_get_parent_categories($categories, $cat_id_data['categories_id']);
for ($i=sizeof($categories)-1; $i>=0; $i--) {
if ($cPath != '') $cPath .= '_';
$cPath .= $categories[$i];
}
if ($cPath != '') $cPath .= '_';
$cPath .= $cat_id_data['categories_id'];
}
return $cPath;
}
////
// Return a product ID with attributes
function tep_get_uprid($prid, $params) {
$uprid = $prid;
if ( (is_array($params)) && (!strstr($prid, '{')) ) {
while (list($option, $value) = each($params)) {
$uprid = $uprid . '{' . $option . '}' . $value;
}
}
return $uprid;
}
////
// Return a product ID from a product ID with attributes
function tep_get_prid($uprid) {
$pieces = split('[{]', $uprid, 2);
return $pieces[0];
}
////
// Return a customer greeting
function tep_customer_greeting() {
global $HTTP_COOKIE_VARS, $customer_id, $customer_first_name;
if ($HTTP_COOKIE_VARS['first_name']) {
$first_name = stripslashes($HTTP_COOKIE_VARS['first_name']);
} elseif ($customer_first_name) {
$first_name = $customer_first_name;
}
if ($first_name) {
$greeting_string = sprintf(TEXT_GREETING_PERSONAL, $first_name, tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL'));
if (!$customer_id) {
$greeting_string .= '<br>' . sprintf(TEXT_GREETING_PERSONAL_RELOGON, $first_name, tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}
} else {
$greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
}
return $greeting_string;
}
////
//! Send email (text/html) using MIME
// This is the central mail function. The SMTP Server should be configured
// correct in php.ini
// Parameters:
// $to_name The name of the recipient, e.g. "Jan Wildeboer"
// $to_email_address The eMail address of the recipient,
// e.g. jan.wildeboer@gmx.de
// $email_subject The subject of the eMail
// $email_text The text of the eMail, may contain HTML entities
// $from_email_name The name of the sender, e.g. Shop Administration
// $from_email_adress The eMail address of the sender,
// e.g. info@mytepshop.com
function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
if (SEND_EMAILS != 'true') return false;
// Instantiate a new mail object
$message = new email(array('X-Mailer: osC mailer'));
// Build the text version
$text = strip_tags($email_text);
if (EMAIL_USE_HTML == 'true') {
$message->add_html($email_text, $text);
} else {
$message->add_text($text);
}
// Send message
$message->build_message();
$message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
}
////
// Check if product has attributes
function tep_has_product_attributes($products_id) {
$attributes_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $products_id . "'");
$attributes = tep_db_fetch_array($attributes_query);
if ($attributes['count'] > 0) {
return true;
} else {
return false;
}
}
////
// Get the number of times a word/character is present in a string
function tep_word_count($string, $needle) {
$temp_array = split($needle, $string);
return sizeof($temp_array);
}
function tep_count_modules($modules = '') {
if (!$modules) return '0';
$modules_array = split(';', $modules);
return sizeof($modules_array);
}
function tep_count_payment_modules() {
return tep_count_modules(MODULE_PAYMENT_INSTALLED);
}
function tep_count_shipping_modules() {
return tep_count_modules(MODULE_SHIPPING_INSTALLED);
}
function tep_create_random_value($length, $type = 'mixed') {
if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;
$rand_value = '';
mt_srand((double) microtime() * 1000000);
while (strlen($rand_value)<$length) {
if ($type == 'digits') {
$char = mt_rand(0,9);
} else {
$char = chr(mt_rand(0,255));
}
if ($type == 'mixed') {
if (eregi('^[a-z0-9]$', $char)) $rand_value .= $char;
} elseif ($type == 'chars') {
if (eregi('^[a-z]$', $char)) $rand_value .= $char;
} elseif ($type == 'digits') {
if (ereg('^[0-9]$', $char)) $rand_value .= $char;
}
}
return $rand_value;
}
function tep_output_warning($warning) {
new errorBox(array(array('text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $warning)));
}
function tep_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') {
if ($exclude == '') $exclude = array();
$get_string = '';
if (sizeof($array) > 0) {
while (list($key, $value) = each($array)) {
if ( (!in_array($key, $exclude)) && ($key != 'x') && ($key != 'y') ) {
$get_string .= $key . $equals . $value . $separator;
}
}
$remove_chars = strlen($separator);
$get_string = substr($get_string, 0, -$remove_chars);
}
return $get_string;
}
function tep_not_null($value) {
if (is_array($value)) {
if (sizeof($value) > 0) {
return true;
} else {
return false;
}
} else {
if (($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) {
return true;
} else {
return false;
}
}
}
////
// Output the tax percentage with optional padded decimals
function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
if (strpos($value, '.')) {
$loop = true;
while ($loop) {
if (substr($value, -1) == '0') {
$value = substr($value, 0, -1);
} else {
$loop = false;
if (substr($value, -1) == '.') {
$value = substr($value, 0, -1);
}
}
}
}
if ($padding > 0) {
if ($decimal_pos = strpos($value, '.')) {
$decimals = strlen(substr($value, ($decimal_pos+1)));
for ($i=$decimals; $i<$padding; $i++) {
$value .= '0';
}
} else {
$value .= '.';
for ($i=0; $i<$padding; $i++) {
$value .= '0';
}
}
}
return $value;
}
////
// Checks to see if the currency code exists as a currency
// TABLES: currencies
function tep_currency_exists($code) {
$currency_code = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . $code . "'");
if (tep_db_num_rows($currency_code)) {
return $code;
} else {
return false;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -