📄 general.php
字号:
}
$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', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a')) . '" title="' . tep_output_string(TEXT_SORT_PRODUCTS . ($sortby == $colnum . 'd' || substr($sortby, 0, 1) != $colnum ? TEXT_ASCENDINGLY : TEXT_DESCENDINGLY) . TEXT_BY . $heading) . '" class="productListing-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 = '" . (int)$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 = '';
$category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "' and p.products_status = '1' and p.products_id = p2c.products_id limit 1");
if (tep_db_num_rows($category_query)) {
$category = tep_db_fetch_array($category_query);
$categories = array();
tep_get_parent_categories($categories, $category['categories_id']);
$categories = array_reverse($categories);
$cPath = implode('_', $categories);
if (tep_not_null($cPath)) $cPath .= '_';
$cPath .= $category['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 = explode('{', $uprid);
return $pieces[0];
}
////
// Return a customer greeting
function tep_customer_greeting() {
global $customer_id, $customer_first_name;
if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {
$greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name), tep_href_link(FILENAME_PRODUCTS_NEW));
} 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: osCommerce 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 = '" . (int)$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 = '') {
$count = 0;
if (empty($modules)) return $count;
$modules_array = split(';', $modules);
for ($i=0, $n=sizeof($modules_array); $i<$n; $i++) {
$class = substr($modules_array[$i], 0, strrpos($modules_array[$i], '.'));
if (is_object($GLOBALS[$class])) {
if ($GLOBALS[$class]->enabled) {
$count++;
}
}
}
return $count;
}
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 = '';
while (strlen($rand_value) < $length) {
if ($type == 'digits') {
$char = tep_rand(0,9);
} else {
$char = chr(tep_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_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') {
if (!is_array($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 != '') && (strtolower($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) {
$code = tep_db_prepare_input($code);
$currency_code = tep_db_query("select currencies_id from " . TABLE_CURRENCIES . " where code = '" . tep_db_input($code) . "'");
if (tep_db_num_rows($currency_code)) {
return $code;
} else {
return false;
}
}
function tep_string_to_int($string) {
return (int)$string;
}
////
// Parse and secure the cPath parameter values
function tep_parse_category_path($cPath) {
// make sure the category IDs are integers
$cPath_array = array_map('tep_string_to_int', explode('_', $cPath));
// make sure no duplicate category IDs exist which could lock the server in a loop
$tmp_array = array();
$n = sizeof($cPath_array);
for ($i=0; $i<$n; $i++) {
if (!in_array($cPath_array[$i], $tmp_array)) {
$tmp_array[] = $cPath_array[$i];
}
}
return $tmp_array;
}
////
// Return a random value
function tep_rand($min = null, $max = null) {
static $seeded;
if (!isset($seeded)) {
mt_srand((double)microtime()*1000000);
$seeded = true;
}
if (isset($min) && isset($max)) {
if ($min >= $max) {
return $min;
} else {
return mt_rand($min, $max);
}
} else {
return mt_rand();
}
}
function tep_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) {
setcookie($name, $value, $expire, $path, (tep_not_null($domain) ? $domain : ''), $secure);
}
function tep_get_ip_address() {
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} else {
$ip = getenv('REMOTE_ADDR');
}
}
return $ip;
}
function tep_count_customer_orders($id = '', $check_session = true) {
global $customer_id;
if (is_numeric($id) == false) {
if (tep_session_is_registered('customer_id')) {
$id = $customer_id;
} else {
return 0;
}
}
if ($check_session == true) {
if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) {
return 0;
}
}
$orders_check_query = tep_db_query("select count(*) as total from " . TABLE_ORDERS . " where customers_id = '" . (int)$id . "'");
$orders_check = tep_db_fetch_array($orders_check_query);
return $orders_check['total'];
}
function tep_count_customer_address_book_entries($id = '', $check_session = true) {
global $customer_id;
if (is_numeric($id) == false) {
if (tep_session_is_registered('customer_id')) {
$id = $customer_id;
} else {
return 0;
}
}
if ($check_session == true) {
if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) {
return 0;
}
}
$addresses_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$id . "'");
$addresses = tep_db_fetch_array($addresses_query);
return $addresses['total'];
}
// nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \n)
function tep_convert_linefeeds($from, $to, $string) {
if ((PHP_VERSION < "4.0.5") && is_array($from)) {
return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
} else {
return str_replace($from, $to, $string);
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -