📄 general.php
字号:
return $number;
}
function tep_get_categories($categories_array = '', $parent_id = '0', $indent = '') {
global $languages_id, $db, $table_categories, $table_categories_description ;
if (!is_array($categories_array)) $categories_array = array();
$categories_query = $db->query("select c.categories_id, cd.categories_name from $table_categories c, $table_categories_description cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
while ($categories = $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 = '') {
global $db, $table_manufacturers;
if (!is_array($manufacturers_array)) $manufacturers_array = array();
$manufacturers_query = $db->query("select manufacturers_id, manufacturers_name from $table_manufacturers order by manufacturers_name");
while ($manufacturers = $db->fetch_array($manufacturers_query)) {
$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']);
}
return $manufacturers_array;
}
function tep_get_subcategories(&$subcategories_array, $parent_id = 0) {
global $db, $table_categories;
$subcategories_query = $db->query("select categories_id from $table_categories where parent_id = '" . (int)$parent_id . "'");
while ($subcategories = $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']);
}
}
}
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));
}
function tep_date_short($raw_date) {
if ( ($raw_date == '0000-00-00 00:00:00') || empty($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);
if (@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 tep_parse_search_string($search_str = '', &$objects) {
$search_str = trim(strtolower($search_str));
$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] = '';
}
}
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 {
$tmpstring = trim(ereg_replace('"', ' ', $pieces[$k]));
if (substr($pieces[$k], -1 ) == '"') {
$flag = 'off';
$objects[] = trim($pieces[$k]);
for ($j=0; $j<count($post_objects); $j++) {
$objects[] = $post_objects[$j];
}
unset($tmpstring);
continue;
}
$flag = 'on';
$k++;
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 (substr($pieces[$k], -1) != '"') {
$tmpstring .= ' ' . $pieces[$k];
$k++;
continue;
} else {
$tmpstring .= ' ' . trim(ereg_replace('"', ' ', $pieces[$k]));
$objects[] = trim($tmpstring);
for ($j=0; $j<count($post_objects); $j++) {
$objects[] = $post_objects[$j];
}
unset($tmpstring);
$flag = 'off';
}
}
}
}
$temp = array();
for($i=0; $i<(count($objects)-1); $i++) {
$temp[] = $objects[$i];
if ( ($objects[$i] != 'and') &&
($objects[$i] != 'or') &&
($objects[$i] != '(') &&
($objects[$i+1] != 'and') &&
($objects[$i+1] != 'or') &&
($objects[$i+1] != ')') ) {
$temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR;
}
}
$temp[] = $objects[$i];
$objects = $temp;
$keyword_count = 0;
$operator_count = 0;
$balance = 0;
for($i=0; $i<count($objects); $i++) {
if ($objects[$i] == '(') $balance --;
if ($objects[$i] == ')') $balance ++;
if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) {
$operator_count ++;
} elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {
$keyword_count ++;
}
}
if ( ($operator_count < $keyword_count) && ($balance == 0) ) {
return true;
} else {
return false;
}
}
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;
}
$size = sizeof($separators);
for ($i=0; $i<$size; $i++) {
$pos_separator = strpos($date_to_check, $separators[$i]);
if ($pos_separator != false) {
$date_separator_idx = $i;
break;
}
}
for ($i=0; $i<$size; $i++) {
$pos_separator = strpos($format_string, $separators[$i]);
if ($pos_separator != false) {
$format_separator_idx = $i;
break;
}
}
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;
}
$size = sizeof($format_string_array);
for ($i=0; $i<$size; $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 );
$size = sizeof($month_abbr);
for ($i=0; $i<$size; $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;
}
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;
}
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) . '" ><font style="color:#ffffff">' ;
$sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? '+' : '-') : '') . '</font></a>';
}
return $sort_prefix . $heading . $sort_suffix;
}
function tep_get_parent_categories(&$categories, $categories_id) {
global $db , $table_categories;
$parent_categories_query = $db->query("select parent_id from $table_categories where categories_id = '" . (int)$categories_id . "'");
while ($parent_categories = $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']);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -