以下函数出自 /includes/functions/functions_general.php 文件
- charsetClean()
- charsetConvertWinToUtf8()
- fmod_round()
- is_product_valid()
- is__writeable()
- replace_accents()
- set_unwritable()
- validate_for_category()
- validate_for_product()
- zen_array_to_string()
- zen_back_link()
- zen_break_string()
- zen_browser_detect()
- zen_check_url_get_terms()
- zen_checkdate()
- zen_clean_html()
- zen_convert_linefeeds()
- zen_count_modules()
- zen_count_payment_modules()
- zen_count_shipping_modules()
- zen_create_random_value()
- zen_create_sort_heading()
- zen_currency_exists()
- zen_date_diff()
- zen_date_long()
- zen_date_short()
- zen_db_input()
- zen_db_output()
- zen_db_prepare_input()
- zen_db_perform()
- zen_decode_specialchars()
- zen_exit()
- zen_field_type()
- zen_field_length()
- zen_get_all_get_params()
- zen_get_box_id()
- zen_get_buy_now_button()
- zen_get_country_zones()
- zen_get_file_directory()
- zen_get_ip_address()
- zen_get_module_directory()
- zen_get_prid()
- zen_get_shipping_enabled()
- zen_get_top_level_domain()
- zen_get_uprid()
- zen_get_uprid_OLD()
- zen_html_entity_decode()
- zen_is_leap_year()
- zen_js_zone_list()
- zen_not_null()
- zen_output_string()
- zen_output_string_protected()
- zen_parse_input_field_data()
- zen_parse_search_string()
- zen_prepare_country_zones_pull_down()
- zen_rand()
- zen_random_select()
- zen_redirect()
- zen_round()
- zen_row_number_format()
- zen_sanitize_string()
- zen_set_field_length()
- zen_setcookie()
- zen_string_to_int()
- zen_trunc_string()
- zen_truncate_paragraph()
- zen_word_count()
- 调用其它的函数文件
zen_exit()
- /**
- * 停止解析任何 PHP 代码
- */
- function zen_exit() {
- session_write_close();
- exit();
- }
zen_redirect()
- /**
- * 重新定向到另外的页面或者网站
- * @参数为字符串,需要重新定向到的 url
- */
- function zen_redirect($url, $httpResponseCode = '') {
- global $request_type;
- // 我们正在加载一个 SSL 页面吗?
- if ( (ENABLE_SSL == true) && ($request_type == 'SSL') ) {
- // 是的,但是服务器只提供 NONSSL url 支持
- if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_CATALOG)) == HTTP_SERVER . DIR_WS_CATALOG) {
- // 所以,在网站 SSL 的配置基础之上,把它改成 SSL
- $url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($url, strlen(HTTP_SERVER . DIR_WS_CATALOG));
- }
- }
- // 在执行之前清理 URL
- while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
- while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
- // 头文件的地址不应该有 &,它会坏事
- while (strstr($url, '&')) $url = str_replace('&', '&', $url);
- if ($httpResponseCode == '') {
- header('Location: ' . $url);
- session_write_close();
- } else {
- header('Location: ' . $url, TRUE, (int)$httpResponseCode);
- session_write_close();
- }
- exit();
- }
zen_parse_input_field_data()
- /**
- * 解析使用 html 标签的数据,确保标签不会断开
- * 基本上来说,这只是 PHP strstr 函数的一个扩展
- * @参数:字符串,需要被解析的字符串
- * @参数:字符串,需要在其中搜索的字符串
- */
- // 解析使用 html 标签的数据,确保其中的标签不会断开
- function zen_parse_input_field_data($data, $parse) {
- return strtr(trim($data), $parse);
- }
zen_output_string()
- /**
- * 返回一个出于安全考虑而转换的字符串
- * @参数:字符串,需要被解析的字符串
- * @参数:字符串,需要被转换的字符串,否则只有引号被转换
- * @参数:布尔值,是否需要对字符串实施 htmlspecialchars 操作
- */
- 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);
- }
- }
- }
zen_output_string_protected()
- /**
- * 返回一个出于安全考虑而转换的字符串
- *
- * 简单的调用 zen_ouput_string 函数
- * 带有将对字符串实施 htmlspecialchars 操作的参数
- * 然后将引号转换成 html entities
- *
- * @参数:字符串,将被解析的字符串
- */
- function zen_output_string_protected($string) {
- return zen_output_string($string, false, true);
- }
zen_sanitize_string()
- /**
- * 返回一个出于安全考虑而转换的字符串
- *
- * @参数:字符串,将被解析的字符串
- */
- function zen_sanitize_string($string) {
- $string = preg_replace('/ +/', ' ', $string);
- return preg_replace("/[<>]/", '_', $string);
- }
zen_break_string()
- /**
- * 如果一个字符串超过指定长度,将其中的字符分断
- *
- * @参数:字符串,需要被分断的字符串
- * @参数:整型,允许的最大长度
- * @参数:字符串,在分断结尾处将要使用的符号
- */
- 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;
- }
zen_get_all_get_params()
- /**
- * 返回全部的 HTTP GET 变量,参数所代表的 GET 变量除外
- *
- * 返回的是一个 urlencoded 字符串
- *
- * @参数:混合型,既可以是一个参数名字也可以是一个参数数组,这些参数代表的 GET 参数名字将不会被输出
- */
- // 返回全部的 HTTP GET 变量,参数所代表的 GET 变量除外
- function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {
- if (!is_array($exclude_array)) $exclude_array = array();
- $get_url = '';
- if (is_array($_GET) && (sizeof($_GET) > 0)) {
- reset($_GET);
- while (list($key, $value) = each($_GET)) {
- if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
- if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
- // die ('here');
- $get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';
- } else {
- $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';
- }
- }
- }
- }
- while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
- while (strstr($get_url, '&&')) $get_url = str_replace('&&', '&', $get_url);
- return $get_url;
- }
zen_browser_detect()
- /**
- * 返回客户端的浏览器类型
- */
- function zen_browser_detect($component) {
- global $HTTP_USER_AGENT;
- return stristr($HTTP_USER_AGENT, $component);
- }
zen_round()
- /**
- * round() 函数的扩展
- */
- function zen_round($value, $precision) {
- $value = round($value * pow(10, $precision), 0);
- $value = $value / pow(10, $precision);
- return $value;
- }
zen_row_number_format()
- /**
- * 默认以0填充一个数字,或者传递一个将要使用的填充符号,比如1,将会输出01
- */
- function zen_row_number_format($number, $filler='0') {
- if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = $filler . $number;
- return $number;
- }
zen_date_long()
- /**
- * 输出以本地化时间格式化的日期字符串
- * $raw_date 应该是这种格式: YYYY-MM-DD HH:MM:SS
- */
- 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));
- }
zen_date_short()
- /**
- * 输出指定本地化日期格式的日期字符串
- * $raw_date 应该是这种格式:YYYY-MM-DD HH:MM:SS
- * 注意:包括了一个应急方案,在 windows 服务器上对 01/01/1970 之前日期解析失败
- */
- function zen_date_short($raw_date) {
- if ( ($raw_date == '0001-01-01 00:00:00') || emptyempty($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);
- // 发生在1969年的错误
- 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 preg_replace('/2037$/', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037)));
- }
- }
zen_parse_search_string()
- /**
- * 将搜索字符串传递给各个对象
- */
- function zen_parse_search_string($search_str = '', &$objects) {
- $search_str = trim(strtolower($search_str)); // 将传递过来的参数转成小写,同时去掉首尾多余空格
- // 将 $search_str 按照空格断开,被引用的字符串将会在后面被重新组装
- $pieces = preg_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 {
- /*
- * 这将意味着,$piece 有可能是一个字符串的最开始,或者最末尾
- * 所以,我们吃掉 $pieces,同时把它们粘在一起,
- * 直到我们到达字符串的最末尾或者片断全部出尽为止
- */
- // 将这个单词添加到 $tmpstring,开始操作 $tmpstring
- $tmpstring = trim(preg_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++;
- // 继续读取字符串的末尾,直到 $flag 被打开
- 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] = '';
- }
- }
- // 如果单词不是以双引号结束,把它添加到 $tmpstring
- if (substr($pieces[$k], -1) != '"') {
- // 把这个单词添加到当前字符串
- $tmpstring .= ' ' . $pieces[$k];
- // 移动到下一个单词
- $k++;
- continue;
- } else {
- /*
- * 如果 $piece 以双引号结尾,去掉双引号,把 $piece 添加到字符串的末尾,
- * 把 $tmpstring 加入到 $haves,杀掉 $tmpstring,关闭 $flag,然后返回
- */
- $tmpstring .= ' ' . trim(preg_replace('/"/', ' ', $pieces[$k]));
- // 把 $tmpstring 添加到将被搜索的数组
- $objects[] = trim($tmpstring);
- for ($j=0; $j<count($post_objects); $j++) {
- $objects[] = $post_objects[$j];
- }
- unset($tmpstring);
- // 关闭 flag,然后退出循环
- $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;
- }
- }
zen_checkdate()
- function zen_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 (zen_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;
- }
zen_is_leap_year()
- /**
- * 检查一个年份是否闰年
- */
- function zen_is_leap_year($year) {
- if ($year % 100 == 0) {
- if ($year % 400 == 0) return true;
- } else {
- if (($year % 4) == 0) return true;
- }
- return false;
- }
zen_create_sort_heading()
- // 返回数据库表的头部,同时带有分类功能
- function zen_create_sort_heading($sortby, $colnum, $heading) {
- global $PHP_SELF;
- $sort_prefix = '';
- $sort_suffix = '';
- if ($sortby) {
- $sort_prefix = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('page', 'info', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a')) . '" mce_href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('page', 'info', 'sort')) . 'page=1&sort=' . $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a')) . '" title="' . zen_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' ? PRODUCT_LIST_SORT_ORDER_ASCENDING : PRODUCT_LIST_SORT_ORDER_DESCENDING) : '') . '</a>';
- }
- return $sort_prefix . $heading . $sort_suffix;
- }
zen_get_uprid_OLD()
- // 返回一件商品的 ID,同时带有该商品的属性
- //(这个是旧的函数,已经被下面的 zen_get_uprid() 函数所取代)
- /*
- function zen_get_uprid_OLD($prid, $params) {
- $uprid = $prid;
- if ( (is_array($params)) && (!strstr($prid, '{')) ) {
- while (list($option, $value) = each($params)) {
- $uprid = $uprid . '{' . $option . '}' . $value;
- }
- }
- return $uprid;
- }
- */
zen_get_uprid()
- // 返回一件商品的 ID,同时带有该商品的属性
- function zen_get_uprid($prid, $params) {
- //print_r($params);
- $uprid = $prid;
- if ( (is_array($params)) && (!strstr($prid, ':')) ) {
- while (list($option, $value) = each($params)) {
- if (is_array($value)) {
- while (list($opt, $val) = each($value)) {
- $uprid = $uprid . '{' . $option . '}' . trim($opt);
- }
- } else {
- //CLR 030714 Add processing around $value. This is needed for text attributes.
- $uprid = $uprid . '{' . $option . '}' . trim($value);
- }
- } //CLR 030228 Add else stmt to process product ids passed in by other routines.
- $md_uprid = '';
- $md_uprid = md5($uprid);
- return $prid . ':' . $md_uprid;
- } else {
- return $prid;
- }
- }
zen_get_prid()
- // 从一个带有商品属性的商品 ID 返回一件商品的 ID
- function zen_get_prid($uprid) {
- $pieces = explode(':', $uprid);
- return $pieces[0];
- }
zen_word_count()
- // 得到一个单词或者字母在一个字符串中出现的次数
- function zen_word_count($string, $needle) {
- $temp_array = preg_split('/'.$needle.'/', $string);
- return sizeof($temp_array);
- }
zen_count_modules()
- function zen_count_modules($modules = '') {
- $count = 0;
- if (emptyempty($modules)) return $count;
- $modules_array = preg_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;
- }
zen_count_payment_modules()
- function zen_count_payment_modules() {
- return zen_count_modules(MODULE_PAYMENT_INSTALLED);
- }
zen_count_shipping_modules()
- function zen_count_shipping_modules() {
- return zen_count_modules(MODULE_SHIPPING_INSTALLED);
- }
zen_create_random_value()
- function zen_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 = zen_rand(0,9);
- } else {
- $char = chr(zen_rand(0,255));
- }
- if ($type == 'mixed') {
- if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;
- } elseif ($type == 'chars') {
- if (preg_match('/^[a-z]$/i', $char)) $rand_value .= $char;
- } elseif ($type == 'digits') {
- if (preg_match('/^[0-9]$/', $char)) $rand_value .= $char;
- }
- }
- return $rand_value;
- }
zen_array_to_string()
- function zen_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') {
- if (!is_array($exclude)) $exclude = array();
- if (!is_array($array)) $array = 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;
- }
zen_not_null()
- function zen_not_null($value) {
- if (is_array($value)) {
- if (sizeof($value) > 0) {
- return true;
- } else {
- return false;
- }
- } elseif( is_a( $value, 'queryFactoryResult' ) ) {
- if (sizeof($value->result) > 0) {
- return true;
- } else {
- return false;
- }
- } else {
- if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
- return true;
- } else {
- return false;
- }
- }
- }
zen_currency_exists()
- // 检查货币代号是否已经存在
- // 数据库表: currencies
- function zen_currency_exists($code, $getFirstDefault = false) {
- global $db;
- $code = zen_db_prepare_input($code);
- $currency_code = "select code
- from " . TABLE_CURRENCIES . "
- where code = '" . zen_db_input($code) . "' LIMIT 1";
- $currency_first = "select code
- from " . TABLE_CURRENCIES . "
- order by value ASC LIMIT 1";
- $currency = $db->Execute(($getFirstDefault == false) ? $currency_code : $currency_first);
- if ($currency->RecordCount()) {
- return strtoupper($currency->fields['code']);
- } else {
- return false;
- }
- }
zen_string_to_int()
- function zen_string_to_int($string) {
- return (int)$string;
- }
zen_rand()
- // 返回一个随机数值
- function zen_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();
- }
- }
zen_get_top_level_domain()
- function zen_get_top_level_domain($url) {
- if (strpos($url, '://')) {
- $url = parse_url($url);
- $url = $url['host'];
- }
- //输出 $url;
- $domain_array = explode('.', $url);
- $domain_size = sizeof($domain_array);
- if ($domain_size > 1) {
- if (SESSION_USE_FQDN == 'True') return $url;
- if (is_numeric($domain_array[$domain_size-2]) && is_numeric($domain_array[$domain_size-1])) {
- return false;
- } else {
- $tld = "";
- foreach ($domain_array as $dPart)
- {
- if ($dPart != "www") $tld = $tld . "." . $dPart;
- }
- return substr($tld, 1);
- }
- } else {
- return false;
- }
- }
zen_setcookie()
- function zen_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) {
- setcookie($name, $value, $expire, $path, $domain, $secure);
- }
zen_get_ip_address()
- function zen_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;
- }
zen_convert_linefeeds()
- // PHP 4.2.0 之前版本的 nl2br() 函数不会在所有的操作系统上转换换行(它只转换 /n)
- function zen_convert_linefeeds($from, $to, $string) {
- if ((PHP_VERSION < "4.0.5") && is_array($from)) {
- return preg_replace('/(' . implode('|', $from) . ')/', $to, $string);
- } else {
- return str_replace($from, $to, $string);
- }
- }
is_product_valid()
- // 检查某件商品是否适用优惠券??
- function is_product_valid($product_id, $coupon_id) {
- global $db;
- $coupons_query = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "
- WHERE coupon_id = '" . (int)$coupon_id . "'
- ORDER BY coupon_restrict ASC";
- $coupons = $db->Execute($coupons_query);
- $product_query = "SELECT products_model FROM " . TABLE_PRODUCTS . "
- WHERE products_id = '" . (int)$product_id . "'";
- $product = $db->Execute($product_query);
- if (preg_match('/^GIFT/', $product->fields['products_model'])) {
- return false;
- }
- // modified to manage restrictions better - leave commented for now
- if ($coupons->RecordCount() == 0) return true;
- if ($coupons->RecordCount() == 1) {
- // If product is restricted(deny) and is same as tested prodcut deny
- if (($coupons->fields['product_id'] != 0) && $coupons->fields['product_id'] == (int)$product_id && $coupons->fields['coupon_restrict']=='Y') return false;
- // If product is not restricted(allow) and is not same as tested prodcut deny
- if (($coupons->fields['product_id'] != 0) && $coupons->fields['product_id'] != (int)$product_id && $coupons->fields['coupon_restrict']=='N') return false;
- // 如果分类目录是 restricted(deny) 那么商品应该在不允许使用优惠券的分类目录中
- if (($coupons->fields['category_id'] !=0) && (zen_product_in_category($product_id, $coupons->fields['category_id'])) && ($coupons->fields['coupon_restrict']=='Y')) return false;
- // if category is not restricted(allow) and product not in category deny
- if (($coupons->fields['category_id'] !=0) && (!zen_product_in_category($product_id, $coupons->fields['category_id'])) && ($coupons->fields['coupon_restrict']=='N')) return false;
- return true;
- }
- $allow_for_category = validate_for_category($product_id, $coupon_id);
- $allow_for_product = validate_for_product($product_id, $coupon_id);
- // 输出 '#'.$product_id . '#' . $allow_for_category;
- // 输出 '#'.$product_id . '#' . $allow_for_product;
- if ($allow_for_category == 'none') {
- if ($allow_for_product === 'none') return true;
- if ($allow_for_product === true) return true;
- if ($allow_for_product === false) return false;
- }
- if ($allow_for_category === true) {
- if ($allow_for_product === 'none') return true;
- if ($allow_for_product === true) return true;
- if ($allow_for_product === false) return false;
- }
- if ($allow_for_category === false) {
- if ($allow_for_product === 'none') return false;
- if ($allow_for_product === true) return true;
- if ($allow_for_product === false) return false;
- }
- return false; // 应该永远不会到这里
- }
validate_for_category()
- function validate_for_category($product_id, $coupon_id) {
- global $db;
- $retVal = 'none';
- $productCatPath = zen_get_product_path($product_id);
- $catPathArray = array_reverse(explode('_', $productCatPath));
- $sql = "SELECT count(*) AS total
- FROM " . TABLE_COUPON_RESTRICT . "
- WHERE category_id = -1
- AND coupon_restrict = 'Y'
- AND coupon_id = " . (int)$coupon_id . " LIMIT 1";
- $checkQuery = $db->execute($sql);
- foreach ($catPathArray as $catPath) {
- $sql = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "
- WHERE category_id = " . (int)$catPath . "
- AND coupon_id = " . (int)$coupon_id;
- $result = $db->execute($sql);
- if ($result->recordCount() > 0 && $result->fields['coupon_restrict'] == 'N') return true;
- if ($result->recordCount() > 0 && $result->fields['coupon_restrict'] == 'Y') return false;
- }
- if ($checkQuery->fields['total'] > 0) {
- return false;
- } else {
- return 'none';
- }
- }
validate_for_product()
- function validate_for_product($product_id, $coupon_id) {
- global $db;
- $sql = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "
- WHERE product_id = " . (int)$product_id . "
- AND coupon_id = " . (int)$coupon_id . " LIMIT 1";
- $result = $db->execute($sql);
- if ($result->recordCount() > 0) {
- if ($result->fields['coupon_restrict'] == 'N') return true;
- if ($result->fields['coupon_restrict'] == 'Y') return false;
- } else {
- return 'none';
- }
- }
zen_db_input()
- function zen_db_input($string) {
- return addslashes($string);
- }
zen_db_prepare_input()
- function zen_db_prepare_input($string) {
- if (is_string($string)) {
- return trim(zen_sanitize_string(stripslashes($string)));
- } elseif (is_array($string)) {
- reset($string);
- while (list($key, $value) = each($string)) {
- $string[$key] = zen_db_prepare_input($value);
- }
- return $string;
- } else {
- return $string;
- }
- }
zen_db_perform()
- function zen_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
- global $db;
- reset($data);
- if (strtolower($action) == 'insert') {
- $query = 'INSERT INTO ' . $table . ' (';
- while (list($columns, ) = each($data)) {
- $query .= $columns . ', ';
- }
- $query = substr($query, 0, -2) . ') VALUES (';
- reset($data);
- while (list(, $value) = each($data)) {
- switch ((string)$value) {
- case 'now()':
- $query .= 'now(), ';
- break;
- case 'null':
- $query .= 'null, ';
- break;
- default:
- $query .= '/'' . zen_db_input($value) . '/', ';
- break;
- }
- }
- $query = substr($query, 0, -2) . ')';
- } elseif (strtolower($action) == 'update') {
- $query = 'UPDATE ' . $table . ' SET ';
- while (list($columns, $value) = each($data)) {
- switch ((string)$value) {
- case 'now()':
- $query .= $columns . ' = now(), ';
- break;
- case 'null':
- $query .= $columns .= ' = null, ';
- break;
- default:
- $query .= $columns . ' = /'' . zen_db_input($value) . '/', ';
- break;
- }
- }
- $query = substr($query, 0, -2) . ' WHERE ' . $parameters;
- }
- return $db->Execute($query);
- }
zen_db_output()
- function zen_db_output($string) {
- return htmlspecialchars($string);
- }
zen_field_type()
- // 返回字段类型
- // $tbl = 数据表名, $fld = 字段名
- function zen_field_type($tbl, $fld) {
- global $db;
- $rs = $db->MetaColumns($tbl);
- $type = $rs[strtoupper($fld)]->type;
- return $type;
- }
zen_field_length()
- // 返回字段长度
- // $tbl = 数据表名, $fld = 字段名
- function zen_field_length($tbl, $fld) {
- global $db;
- $rs = $db->MetaColumns($tbl);
- $length = $rs[strtoupper($fld)]->max_length;
- return $length;
- }
zen_set_field_length()
- // 返回表单设置中的 size 和 maxlength 属性,默认的最大 size 是 70
- // 使用 $tbl = 数据库表的名字, $fld = 字段名
- // 举例: zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')
- function zen_set_field_length($tbl, $fld, $max=70) {
- $field_length= zen_field_length($tbl, $fld);
- switch (true) {
- case ($field_length > $max):
- $length= 'size = "' . ($max+1) . '" maxlength= "' . $field_length . '"';
- break;
- default:
- $length= 'size = "' . ($field_length+1) . '" maxlength = "' . $field_length . '"';
- break;
- }
- return $length;
- }
zen_back_link()
- // 设置返回键(就是返回之前页面的那个按钮)
- function zen_back_link($link_only = false) {
- if (sizeof($_SESSION['navigation']->path)-2 >= 0) {
- $back = sizeof($_SESSION['navigation']->path)-2;
- $link = zen_href_link($_SESSION['navigation']->path[$back]['page'], zen_array_to_string($_SESSION['navigation']->path[$back]['get'], array('action')), $_SESSION['navigation']->path[$back]['mode']);
- } else {
- if (isset($_SERVER['HTTP_REFERER']) && preg_match("~^".HTTP_SERVER."~i", $_SERVER['HTTP_REFERER']) ) {
- //if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], str_replace(array('http://', 'https://'), '', HTTP_SERVER) ) ) {
- $link= $_SERVER['HTTP_REFERER'];
- } else {
- $link = zen_href_link(FILENAME_DEFAULT);
- }
- $_SESSION['navigation'] = new navigationHistory;
- }
- if ($link_only == true) {
- return $link;
- } else {
- return '<a href="' . $link . '" mce_href="' . $link . '">';
- }
- }
zen_random_select()
- // 由一个数据查询返回随机的一排数据
- function zen_random_select($query) {
- global $db;
- $random_product = '';
- $random_query = $db->Execute($query);
- $num_rows = $random_query->RecordCount();
- if ($num_rows > 1) {
- $random_row = zen_rand(0, ($num_rows - 1));
- $random_query->Move($random_row);
- }
- return $random_query;
- }
zen_trunc_string()
- // 切割一个字符串
- function zen_trunc_string($str = "", $len = 150, $more = 'true') {
- if ($str == "") return $str;
- if (is_array($str)) return $str;
- $str = trim($str);
- // 如果字符串小于指定的长度,那么返回这个字符串
- if (strlen($str) <= $len) return $str;
- // 否则得到这段文字的长度
- $str = substr($str, 0, $len);
- // backtrack to the end of a word
- if ($str != "") {
- // check to see if there are any spaces left
- if (!substr_count($str , " ")) {
- if ($more == 'true') $str .= "...";
- return $str;
- }
- // backtrack
- while(strlen($str) && ($str[strlen($str)-1] != " ")) {
- $str = substr($str, 0, -1);
- }
- $str = substr($str, 0, -1);
- if ($more == 'true') $str .= "...";
- if ($more != 'true' and $more != 'false') $str .= $more;
- }
- return $str;
- }
zen_get_box_id()
- // 设置当前边框的 id
- function zen_get_box_id($box_id) {
- while (strstr($box_id, '_')) $box_id = str_replace('_', '', $box_id);
- $box_id = str_replace('.php', '', $box_id);
- return $box_id;
- }
zen_get_buy_now_button()
- // 根据咨询价格或者已经售完,转换加入购物车按钮(比如一件商品已经售完,那么商品页面就不应该再出现“加入购物车”的按钮)
- function zen_get_buy_now_button($product_id, $link, $additional_link = false) {
- global $db;
- // 当所有其它设置被挂起的时候,才显示
- if (STORE_STATUS != '0') {
- return '<a href="' . zen_href_link(FILENAME_CONTACT_US) . '" mce_href="' . zen_href_link(FILENAME_CONTACT_US) . '">' . TEXT_SHOWCASE_ONLY . '</a>';
- }
- // 0 = 正常购物
- // 1 = 登陆才能购物
- // 2 = 可以浏览但是没有价格
- // 确定是否显示价格
- switch (true) {
- case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):
- // 用户必须登陆才能浏览价格
- $login_for_price = '<a href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '" mce_href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '">' . TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE . '</a>';
- return $login_for_price;
- break;
- case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):
- if (TEXT_LOGIN_FOR_PRICE_PRICE == '') {
- // 显示空白
- return TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE;
- } else {
- // 用户可以浏览但是没有价格
- $login_for_price = '<a href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '" mce_href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '">' . TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE . '</a>';
- }
- return $login_for_price;
- break;
- // 显示空白
- case (CUSTOMERS_APPROVAL == '3'):
- $login_for_price = TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM;
- return $login_for_price;
- break;
- case ((CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and CUSTOMERS_APPROVAL_AUTHORIZATION != '3') and $_SESSION['customer_id'] == ''):
- // 用户必须登陆才能浏览价格
- $login_for_price = TEXT_AUTHORIZATION_PENDING_BUTTON_REPLACE;
- return $login_for_price;
- break;
- case ((CUSTOMERS_APPROVAL_AUTHORIZATION == '3') and $_SESSION['customer_id'] == ''):
- // 用户必须登陆而且经过允许才能加入到购物车
- $login_for_price = '<a href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '" mce_href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '">' . TEXT_LOGIN_TO_SHOP_BUTTON_REPLACE . '</a>';
- return $login_for_price;
- break;
- case (CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and $_SESSION['customers_authorization'] > '0'):
- // 用户必须登陆才能浏览价格
- $login_for_price = TEXT_AUTHORIZATION_PENDING_BUTTON_REPLACE;
- return $login_for_price;
- break;
- default:
- // 正常程序
- break;
- }
- $button_check = $db->Execute("select product_is_call, products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");
- switch (true) {
- // 不能被加入到购物车
- case (zen_get_products_allow_add_to_cart($product_id) == 'N'):
- return $additional_link;
- break;
- case ($button_check->fields['product_is_call'] == '1'):
- $return_button = '<a href="' . zen_href_link(FILENAME_CONTACT_US) . '" mce_href="' . zen_href_link(FILENAME_CONTACT_US) . '">' . TEXT_CALL_FOR_PRICE . '</a>';
- break;
- case ($button_check->fields['products_quantity'] <= 0 and SHOW_PRODUCTS_SOLD_OUT_IMAGE == '1'):
- if ($_GET['main_page'] == zen_get_info_page($product_id)) {
- $return_button = zen_image_button(BUTTON_IMAGE_SOLD_OUT, BUTTON_SOLD_OUT_ALT);
- } else {
- $return_button = zen_image_button(BUTTON_IMAGE_SOLD_OUT_SMALL, BUTTON_SOLD_OUT_SMALL_ALT);
- }
- break;
- default:
- $return_button = $link;
- break;
- }
- if ($return_button != $link and $additional_link != false) {
- return $additional_link . '<br />' . $return_button;
- } else {
- return $return_button;
- }
- }
zen_get_shipping_enabled()
- // 激活邮费模块
- function zen_get_shipping_enabled($shipping_module) {
- global $PHP_SELF, $cart, $order;
- // 如果已经安装,那么后台总是为真
- if (strstr($PHP_SELF, FILENAME_MODULES)) {
- return true;
- }
- $check_cart_free = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');
- $check_cart_cnt = $_SESSION['cart']->count_contents();
- $check_cart_weight = $_SESSION['cart']->show_weight();
- switch(true) {
- // 如果已经安装,那么后台总是为真
- case (strstr($PHP_SELF, FILENAME_MODULES)):
- return true;
- break;
- // 当重量为 0,免邮费 - 激活免邮费 - ORDER_WEIGHT_ZERO_STATUS 必须打开
- case (ORDER_WEIGHT_ZERO_STATUS == '1' and ($check_cart_weight == 0 and $shipping_module == 'freeshipper')):
- return true;
- break;
- // 当重量为 0,免邮费 - Free Shipping when 0 weight - disable everyone - ORDER_WEIGHT_ZERO_STATUS must be on
- case (ORDER_WEIGHT_ZERO_STATUS == '1' and ($check_cart_weight == 0 and $shipping_module != 'freeshipper')):
- return false;
- break;
- case (($_SESSION['cart']->free_shipping_items() == $check_cart_cnt) and $shipping_module == 'freeshipper'):
- return true;
- break;
- case (($_SESSION['cart']->free_shipping_items() == $check_cart_cnt) and $shipping_module != 'freeshipper'):
- return false;
- break;
- // Always free shipping only true - enable freeshipper
- case (($check_cart_free == $check_cart_cnt) and $shipping_module == 'freeshipper'):
- return true;
- break;
- // Always free shipping only true - disable everyone
- case (($check_cart_free == $check_cart_cnt) and $shipping_module != 'freeshipper'):
- return false;
- break;
- // Always free shipping only is false - disable freeshipper
- case (($check_cart_free != $check_cart_cnt) and $shipping_module == 'freeshipper'):
- return false;
- break;
- default:
- return true;
- break;
- }
- }
zen_html_entity_decode()
- function zen_html_entity_decode($given_html, $quote_style = ENT_QUOTES) {
- $trans_table = array_flip(get_html_translation_table( HTML_SPECIALCHARS, $quote_style ));
- $trans_table['''] = "'";
- return ( strtr( $given_html, $trans_table ) );
- }
zen_decode_specialchars()
- //CLR 030228 Add function zen_decode_specialchars
- // Decode string encoded with htmlspecialchars()
- function zen_decode_specialchars($string){
- $string=str_replace('>', '>', $string);
- $string=str_replace('<', '<', $string);
- $string=str_replace(''', "'", $string);
- $string=str_replace('"', "/"", $string);
- $string=str_replace('&', '&', $string);
- return $string;
- }
zen_clean_html()
- // remove common HTML from text for display as paragraph
- function zen_clean_html($clean_it, $extraTags = '') {
- if (!is_array($extraTags)) $extraTags = array($extraTags);
- $clean_it = preg_replace('//r/', ' ', $clean_it);
- $clean_it = preg_replace('//t/', ' ', $clean_it);
- $clean_it = preg_replace('//n/', ' ', $clean_it);
- $clean_it= nl2br($clean_it);
- // update breaks with a space for text displays in all listings with descriptions
- while (strstr($clean_it, '<br>')) $clean_it = str_replace('<br>', ' ', $clean_it);
- while (strstr($clean_it, '<br />')) $clean_it = str_replace('<br />', ' ', $clean_it);
- while (strstr($clean_it, '<br/>')) $clean_it = str_replace('<br/>', ' ', $clean_it);
- while (strstr($clean_it, '<p>')) $clean_it = str_replace('<p>', ' ', $clean_it);
- while (strstr($clean_it, '</p>')) $clean_it = str_replace('</p>', ' ', $clean_it);
- // temporary fix more for reviews than anything else
- while (strstr($clean_it, '<span class="smallText">')) $clean_it = str_replace('<span class="smallText">', ' ', $clean_it);
- while (strstr($clean_it, '</span>')) $clean_it = str_replace('</span>', ' ', $clean_it);
- // clean general and specific tags:
- $taglist = array('strong','b','u','i','em');
- $taglist = array_merge($taglist, (is_array($extraTags) ? $extraTags : array($extraTags)));
- foreach ($taglist as $tofind) {
- if ($tofind != '') $clean_it = preg_replace("/<[///!]*?" . $tofind . "[^<>]*?>/si", ' ', $clean_it);
- }
- // remove any double-spaces created by cleanups:
- while (strstr($clean_it, ' ')) $clean_it = str_replace(' ', ' ', $clean_it);
- // remove other html code to prevent problems on display of text
- $clean_it = strip_tags($clean_it);
- return $clean_it;
- }
zen_get_module_directory()
- // find module directory
- // include template specific immediate /modules files
- // new_products, products_new_listing, featured_products, featured_products_listing, product_listing, specials_index, upcoming,
- // products_all_listing, products_discount_prices, also_purchased_products
- function zen_get_module_directory($check_file, $dir_only = 'false') {
- global $template_dir;
- $zv_filename = $check_file;
- if (!strstr($zv_filename, '.php')) $zv_filename .= '.php';
- if (file_exists(DIR_WS_MODULES . $template_dir . '/' . $zv_filename)) {
- $template_dir_select = $template_dir . '/';
- } else {
- $template_dir_select = '';
- }
- if ($dir_only == 'true') {
- return $template_dir_select;
- } else {
- return $template_dir_select . $zv_filename;
- }
- }
zen_get_file_directory()
- // find template or default file
- function zen_get_file_directory($check_directory, $check_file, $dir_only = 'false') {
- global $template_dir;
- $zv_filename = $check_file;
- if (!strstr($zv_filename, '.php')) $zv_filename .= '.php';
- if (file_exists($check_directory . $template_dir . '/' . $zv_filename)) {
- $zv_directory = $check_directory . $template_dir . '/';
- } else {
- $zv_directory = $check_directory;
- }
- if ($dir_only == 'true') {
- return $zv_directory;
- } else {
- return $zv_directory . $zv_filename;
- }
- }
zen_check_url_get_terms()
- // check to see if database stored GET terms are in the URL as $_GET parameters
- function zen_check_url_get_terms() {
- global $db;
- $zp_sql = "select * from " . TABLE_GET_TERMS_TO_FILTER;
- $zp_filter_terms = $db->Execute($zp_sql);
- $zp_result = false;
- while (!$zp_filter_terms->EOF) {
- if (isset($_GET[$zp_filter_terms->fields['get_term_name']]) && zen_not_null($_GET[$zp_filter_terms->fields['get_term_name']])) $zp_result = true;
- $zp_filter_terms->MoveNext();
- }
- return $zp_result;
- }
fmod_round()
- // replacement for fmod to manage values < 1
- function fmod_round($x, $y) {
- $x = strval($x);
- $y = strval($y);
- $zc_round = ($x*1000)/($y*1000);
- $zc_round_ceil = (int)($zc_round);
- $multiplier = $zc_round_ceil * $y;
- $results = abs(round($x - $multiplier, 6));
- return $results;
- }
zen_truncate_paragraph()
- // 返回被切割的段落
- function zen_truncate_paragraph($paragraph, $size = 100, $word = ' ') {
- $zv_paragraph = "";
- $word = explode(" ", $paragraph);
- $zv_total = count($word);
- if ($zv_total > $size) {
- for ($x=0; $x < $size; $x++) {
- $zv_paragraph = $zv_paragraph . $word[$x] . " ";
- }
- $zv_paragraph = trim($zv_paragraph);
- } else {
- $zv_paragraph = trim($paragraph);
- }
- return $zv_paragraph;
- }
zen_get_country_zones()
- /**
- * return an array with zones defined for the specified country
- */
- function zen_get_country_zones($country_id) {
- global $db;
- $zones_array = array();
- $zones = $db->Execute("select zone_id, zone_name
- from " . TABLE_ZONES . "
- where zone_country_id = '" . (int)$country_id . "'
- order by zone_name");
- while (!$zones->EOF) {
- $zones_array[] = array('id' => $zones->fields['zone_id'],
- 'text' => $zones->fields['zone_name']);
- $zones->MoveNext();
- }
- return $zones_array;
- }
zen_prepare_country_zones_pull_down()
- /**
- * return an array with country names and matching zones to be used in pulldown menus
- */
- function zen_prepare_country_zones_pull_down($country_id = '') {
- // preset the width of the drop-down for Netscape
- $pre = '';
- if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
- for ($i=0; $i<45; $i++) $pre .= ' ';
- }
- $zones = zen_get_country_zones($country_id);
- if (sizeof($zones) > 0) {
- $zones_select = array(array('id' => '', 'text' => PLEASE_SELECT));
- $zones = array_merge($zones_select, $zones);
- } else {
- $zones = array(array('id' => '', 'text' => TYPE_BELOW));
- // create dummy options for Netscape to preset the height of the drop-down
- if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
- for ($i=0; $i<9; $i++) {
- $zones[] = array('id' => '', 'text' => $pre);
- }
- }
- }
- return $zones;
- }
zen_js_zone_list()
- /**
- * supplies javascript to dynamically update the states/provinces list when the country is changed
- * TABLES: zones
- *
- * return string
- */
- function zen_js_zone_list($country, $form, $field) {
- global $db;
- $countries = $db->Execute("select distinct zone_country_id
- from " . TABLE_ZONES . "
- order by zone_country_id");
- $num_country = 1;
- $output_string = '';
- while (!$countries->EOF) {
- if ($num_country == 1) {
- $output_string .= ' if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "/n";
- } else {
- $output_string .= ' } else if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "/n";
- }
- $states = $db->Execute("select zone_name, zone_id
- from " . TABLE_ZONES . "
- where zone_country_id = '" . $countries->fields['zone_country_id'] . "'
- order by zone_name");
- $num_state = 1;
- while (!$states->EOF) {
- if ($num_state == '1') $output_string .= ' ' . $form . '.' . $field . '.options[0] = new Option("' . PLEASE_SELECT . '", "");' . "/n";
- $output_string .= ' ' . $form . '.' . $field . '.options[' . $num_state . '] = new Option("' . $states->fields['zone_name'] . '", "' . $states->fields['zone_id'] . '");' . "/n";
- $num_state++;
- $states->MoveNext();
- }
- $num_country++;
- $countries->MoveNext();
- $output_string .= ' hideStateField(' . $form . ');' . "/n" ;
- }
- $output_string .= ' } else {' . "/n" .
- ' ' . $form . '.' . $field . '.options[0] = new Option("' . TYPE_BELOW . '", "");' . "/n" .
- ' showStateField(' . $form . ');' . "/n" .
- ' }' . "/n";
- return $output_string;
- }
zen_date_diff()
- /*
- * 计算两个日期之间的天数
- */
- function zen_date_diff($date1, $date2) {
- // $date1 今天,或者任何一天
- // $date2 需要计算的日期
- $d1 = explode("-", $date1);
- $y1 = $d1[0];
- $m1 = $d1[1];
- $d1 = $d1[2];
- $d2 = explode("-", $date2);
- $y2 = $d2[0];
- $m2 = $d2[1];
- $d2 = $d2[2];
- $date1_set = mktime(0,0,0, $m1, $d1, $y1);
- $date2_set = mktime(0,0,0, $m2, $d2, $y2);
- return(round(($date2_set-$date1_set)/(60*60*24)));
- }
replace_accents()
- /**
- * strip out accented characters to reasonable approximations of english equivalents
- */
- function replace_accents($s) {
- $skipPreg = (defined('OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES') && OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES == 'TRUE') ? TRUE : FALSE;
- $s = htmlentities($s);
- if ($skipPreg == FALSE) {
- $s = preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/', '$1', $s);
- }
- $s = html_entity_decode($s);
- return $s;
- }
is__writeable()
- /**
- * function to override PHP's is_writable() which can occasionally be unreliable due to O/S and F/S differences
- * attempts to open the specified file for writing. Returns true if successful, false if not.
- * if a directory is specified, uses PHP's is_writable() anyway
- *
- * @var string
- * @return boolean
- */
- function is__writeable($filepath, $make_unwritable = true) {
- if (is_dir($filepath)) return is_writable($filepath);
- $fp = @fopen($filepath, 'a');
- if ($fp) {
- @fclose($fp);
- if ($make_unwritable) set_unwritable($filepath);
- $fp = @fopen($filepath, 'a');
- if ($fp) {
- @fclose($fp);
- return true;
- }
- }
- return false;
- }
set_unwritable()
- /**
- * 试图把指定的文件改成只读
- *
- * @参数:字符串
- * @返回值:布尔值
- */
- function set_unwritable($filepath) {
- return @chmod($filepath, 0444);
- }
charsetConvertWinToUtf8()
- /**
- * convert supplied string to UTF-8, dropping any symbols which cannot be translated easily
- * useful for submitting cleaned-up data to payment gateways or other external services, esp if the data was copy+pasted from windows docs via windows browser to store in database
- *
- * @param string $string
- */
- function charsetConvertWinToUtf8($string) {
- if (function_exists('iconv')) $string = iconv("Windows-1252", "ISO-8859-1//IGNORE", $string);
- $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
- return $string;
- }
charsetClean()
- /**
- * Convert supplied string to/from entities between charsets, to sanitize data from payment gateway
- * @param $string
- * @return string
- */
- function charsetClean($string) {
- if (CHARSET == 'UTF-8') return $string;
- if (function_exists('iconv')) $string = iconv("Windows-1252", CHARSET . "//IGNORE", $string);
- $string = htmlentities($string, ENT_QUOTES, 'UTF-8');
- $string = html_entity_decode($string, ENT_QUOTES, CHARSET);
- return $string;
- }
调用其它的函数文件
- // 和价格、数量相关的函数
- require(DIR_WS_FUNCTIONS . 'functions_prices.php');
- // 和税相关的函数
- require(DIR_WS_FUNCTIONS . 'functions_taxes.php');
- // 和优惠券相关的函数
- require(DIR_WS_FUNCTIONS . 'functions_gvcoupons.php');
- // 和商品目录、路径、下拉菜单相关的函数文件
- require(DIR_WS_FUNCTIONS . 'functions_categories.php');
- // 和客户、地址相关的函数文件customers and addresses
- require(DIR_WS_FUNCTIONS . 'functions_customers.php');
- // 查找信息相关函数
- require(DIR_WS_FUNCTIONS . 'functions_lookups.php');
转至:http://blog.csdn.net/klinghr/article/details/6174734