📄 general.php
字号:
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | license@zen-cart.com so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: general.php 3415 2006-04-11 04:51:22Z drbyte $
//
////
// Redirect to another page or site
function zen_redirect($url) {
global $logger;
// clean up URL before executing it
while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
// header locates should not have the & in the address it breaks things
while (strstr($url, '&')) $url = str_replace('&', '&', $url);
header('Location: ' . $url);
if (STORE_PAGE_PARSE_TIME == 'true') {
if (!is_object($logger)) $logger = new logger;
$logger->timer_stop();
}
exit;
}
////
// Parse the data used in the html tags to ensure the tags will not break
function zen_parse_input_field_data($data, $parse) {
return strtr(trim($data), $parse);
}
function zen_output_string($string, $translate = false, $protected = false) {
if ($protected == true) {
return htmlspecialchars($string);
} else {
if ($translate == false) {
return zen_parse_input_field_data($string, array('"' => '"'));
} else {
return zen_parse_input_field_data($string, $translate);
}
}
}
function zen_output_string_protected($string) {
return zen_output_string($string, false, true);
}
function zen_sanitize_string($string) {
$string = ereg_replace(' +', ' ', $string);
return preg_replace("/[<>]/", '_', $string);
}
function zen_customers_name($customers_id) {
global $db;
$customers_values = $db->Execute("select customers_firstname, customers_lastname
from " . TABLE_CUSTOMERS . "
where customers_id = '" . (int)$customers_id . "'");
return $customers_values->fields['customers_firstname'] . ' ' . $customers_values->fields['customers_lastname'];
}
function zen_get_path($current_category_id = '') {
global $cPath_array, $db;
// set to 0 if Top Level
if ($current_category_id == '') {
if (empty($cPath_array)) {
$cPath_new= '';
} else {
$cPath_new = implode('_', $cPath_array);
}
} else {
if (sizeof($cPath_array) == 0) {
$cPath_new = $current_category_id;
} else {
$cPath_new = '';
$last_category = $db->Execute("select parent_id
from " . TABLE_CATEGORIES . "
where categories_id = '" . (int)$cPath_array[(sizeof($cPath_array)-1)] . "'");
$current_category = $db->Execute("select parent_id
from " . TABLE_CATEGORIES . "
where categories_id = '" . (int)$current_category_id . "'");
if ($last_category->fields['parent_id'] == $current_category->fields['parent_id']) {
for ($i = 0, $n = sizeof($cPath_array) - 1; $i < $n; $i++) {
$cPath_new .= '_' . $cPath_array[$i];
}
} else {
for ($i = 0, $n = sizeof($cPath_array); $i < $n; $i++) {
$cPath_new .= '_' . $cPath_array[$i];
}
}
$cPath_new .= '_' . $current_category_id;
if (substr($cPath_new, 0, 1) == '_') {
$cPath_new = substr($cPath_new, 1);
}
}
}
return 'cPath=' . $cPath_new;
}
function zen_get_all_get_params($exclude_array = '') {
global $_GET;
if ($exclude_array == '') $exclude_array = array();
$get_url = '';
reset($_GET);
while (list($key, $value) = each($_GET)) {
if (($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array))) $get_url .= $key . '=' . $value . '&';
}
return $get_url;
}
function zen_date_long($raw_date) {
if ( ($raw_date == '0001-01-01 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
// NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers
function zen_date_short($raw_date) {
if ( ($raw_date == '0001-01-01 00:00:00') || ($raw_date == '') ) return false;
$year = 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);
// error on 1969 only allows for leap year
if ($year != 1969 && @date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) {
return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
} else {
return ereg_replace('2037' . '$', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
}
}
function zen_datetime_short($raw_datetime) {
if ( ($raw_datetime == '0001-01-01 00:00:00') || ($raw_datetime == '') ) return false;
$year = (int)substr($raw_datetime, 0, 4);
$month = (int)substr($raw_datetime, 5, 2);
$day = (int)substr($raw_datetime, 8, 2);
$hour = (int)substr($raw_datetime, 11, 2);
$minute = (int)substr($raw_datetime, 14, 2);
$second = (int)substr($raw_datetime, 17, 2);
return strftime(DATE_TIME_FORMAT, mktime($hour, $minute, $second, $month, $day, $year));
}
function zen_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = '', $include_itself = false, $category_has_products = false, $limit = false) {
global $db;
if ($limit) {
$limit_count = " limit 1";
} else {
$limit_count = '';
}
if (!is_array($category_tree_array)) $category_tree_array = array();
if ( (sizeof($category_tree_array) < 1) && ($exclude != '0') ) $category_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);
if ($include_itself) {
$category = $db->Execute("select cd.categories_name
from " . TABLE_CATEGORIES_DESCRIPTION . " cd
where cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and cd.categories_id = '" . (int)$parent_id . "'");
$category_tree_array[] = array('id' => $parent_id, 'text' => $category->fields['categories_name']);
}
$categories = $db->Execute("select c.categories_id, cd.categories_name, c.parent_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id = cd.categories_id
and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and c.parent_id = '" . (int)$parent_id . "'
order by c.sort_order, cd.categories_name");
while (!$categories->EOF) {
if ($category_has_products == true and zen_products_in_category_count($categories->fields['categories_id'], '', false, true) >= 1) {
$mark = '*';
} else {
$mark = ' ';
}
if ($exclude != $categories->fields['categories_id']) $category_tree_array[] = array('id' => $categories->fields['categories_id'], 'text' => $spacing . $categories->fields['categories_name'] . $mark);
$category_tree_array = zen_get_category_tree($categories->fields['categories_id'], $spacing . ' ', $exclude, $category_tree_array, '', $category_has_products);
$categories->MoveNext();
}
return $category_tree_array;
}
////
// products with name, model and price pulldown
function zen_draw_products_pull_down($name, $parameters = '', $exclude = '', $show_id = false, $set_selected = false, $show_model = false, $show_current_category = false) {
global $currencies, $db, $current_category_id;
if ($exclude == '') {
$exclude = array();
}
$select_string = '<select name="' . $name . '"';
if ($parameters) {
$select_string .= ' ' . $parameters;
}
$select_string .= '>';
if ($show_current_category) {
// only show $current_categories_id
$products = $db->Execute("select p.products_id, pd.products_name, p.products_price, p.products_model, ptc.categories_id
from " . TABLE_PRODUCTS . " p
left join " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc on ptc.products_id = p.products_id, " .
TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id = pd.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and ptc.categories_id = '" . $current_category_id . "'
order by products_name");
} else {
$products = $db->Execute("select p.products_id, pd.products_name, p.products_price, p.products_model
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id = pd.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
order by products_name");
}
while (!$products->EOF) {
if (!in_array($products->fields['products_id'], $exclude)) {
$display_price = zen_get_products_base_price($products->fields['products_id']);
$select_string .= '<option value="' . $products->fields['products_id'] . '"';
if ($set_selected == $products->fields['products_id']) $select_string .= ' SELECTED';
$select_string .= '>' . $products->fields['products_name'] . ' (' . $currencies->format($display_price) . ')' . ($show_model ? ' [' . $products->fields['products_model'] . '] ' : '') . ($show_id ? ' - ID# ' . $products->fields['products_id'] : '') . '</option>';
}
$products->MoveNext();
}
$select_string .= '</select>';
return $select_string;
}
function zen_options_name($options_id) {
global $db;
$options_id = str_replace('txt_','',$options_id);
$options_values = $db->Execute("select products_options_name
from " . TABLE_PRODUCTS_OPTIONS . "
where products_options_id = '" . (int)$options_id . "'
and language_id = '" . (int)$_SESSION['languages_id'] . "'");
return $options_values->fields['products_options_name'];
}
function zen_values_name($values_id) {
global $db;
$values_values = $db->Execute("select products_options_values_name
from " . TABLE_PRODUCTS_OPTIONS_VALUES . "
where products_options_values_id = '" . (int)$values_id . "'
and language_id = '" . (int)$_SESSION['languages_id'] . "'");
return $values_values->fields['products_options_values_name'];
}
function zen_info_image($image, $alt, $width = '', $height = '') {
if (zen_not_null($image) && (file_exists(DIR_FS_CATALOG_IMAGES . $image)) ) {
$image = zen_image(DIR_WS_CATALOG_IMAGES . $image, $alt, $width, $height);
} else {
$image = TEXT_IMAGE_NONEXISTENT;
}
return $image;
}
function zen_break_string($string, $len, $break_char = '-') {
$l = 0;
$output = '';
for ($i=0, $n=strlen($string); $i<$n; $i++) {
$char = substr($string, $i, 1);
if ($char != ' ') {
$l++;
} else {
$l = 0;
}
if ($l > $len) {
$l = 1;
$output .= $break_char;
}
$output .= $char;
}
return $output;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -