zen cart 函数大全

以下函数出自 /includes/functions/functions_general.php 文件

  1. charsetClean()
  2. charsetConvertWinToUtf8()
  3. fmod_round()
  4. is_product_valid()
  5. is__writeable()
  6. replace_accents()
  7. set_unwritable()
  8. validate_for_category()
  9. validate_for_product()

  10. zen_array_to_string()

  11. zen_back_link()
  12. zen_break_string()
  13. zen_browser_detect()

  14. zen_check_url_get_terms()
  15. zen_checkdate()
  16. zen_clean_html()
  17. zen_convert_linefeeds()
  18. zen_count_modules()
  19. zen_count_payment_modules()
  20. zen_count_shipping_modules()
  21. zen_create_random_value()
  22. zen_create_sort_heading()
  23. zen_currency_exists()

  24. zen_date_diff()
  25. zen_date_long()
  26. zen_date_short()
  27. zen_db_input()
  28. zen_db_output()
  29. zen_db_prepare_input()
  30. zen_db_perform()
  31. zen_decode_specialchars()

  32. zen_exit()

  33. zen_field_type()
  34. zen_field_length()

  35. zen_get_all_get_params()
  36. zen_get_box_id()
  37. zen_get_buy_now_button()
  38. zen_get_country_zones()
  39. zen_get_file_directory()
  40. zen_get_ip_address()
  41. zen_get_module_directory()
  42. zen_get_prid()
  43. zen_get_shipping_enabled()
  44. zen_get_top_level_domain()
  45. zen_get_uprid()
  46. zen_get_uprid_OLD()

  47. zen_html_entity_decode()

  48. zen_is_leap_year()

  49. zen_js_zone_list()

  50. zen_not_null()

  51. zen_output_string()
  52. zen_output_string_protected()

  53. zen_parse_input_field_data()
  54. zen_parse_search_string()
  55. zen_prepare_country_zones_pull_down()

  56. zen_rand()
  57. zen_random_select()
  58. zen_redirect()
  59. zen_round()
  60. zen_row_number_format()

  61. zen_sanitize_string()
  62. zen_set_field_length()
  63. zen_setcookie()
  64. zen_string_to_int()

  65. zen_trunc_string()
  66. zen_truncate_paragraph()

  67. zen_word_count()

  68. 调用其它的函数文件

zen_exit()

  1. /** 
  2.  * 停止解析任何 PHP 代码 
  3. */  
  4.   function zen_exit() {  
  5.    session_write_close();  
  6.    exit();  
  7.   }  

zen_redirect()

  1. /** 
  2.  * 重新定向到另外的页面或者网站 
  3.  * @参数为字符串,需要重新定向到的 url 
  4. */  
  5.   function zen_redirect($url$httpResponseCode = '') {  
  6.     global $request_type;  
  7.     // 我们正在加载一个 SSL 页面吗?  
  8.     if ( (ENABLE_SSL == true) && ($request_type == 'SSL') ) {  
  9.       // 是的,但是服务器只提供 NONSSL url 支持  
  10.       if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_CATALOG)) == HTTP_SERVER . DIR_WS_CATALOG) {  
  11.         // 所以,在网站 SSL 的配置基础之上,把它改成 SSL  
  12.         $url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($urlstrlen(HTTP_SERVER . DIR_WS_CATALOG));  
  13.       }  
  14.     }  
  15.   // 在执行之前清理 URL  
  16.     while (strstr($url'&&')) $url = str_replace('&&''&'$url);  
  17.     while (strstr($url'&&')) $url = str_replace('&&''&'$url);  
  18.     // 头文件的地址不应该有 &,它会坏事  
  19.     while (strstr($url'&')) $url = str_replace('&''&'$url);  
  20.     if ($httpResponseCode == '') {  
  21.       header('Location: ' . $url);  
  22.       session_write_close();  
  23.     } else {  
  24.       header('Location: ' . $url, TRUE, (int)$httpResponseCode);  
  25.       session_write_close();  
  26.     }  
  27.     exit();  
  28.   }  

zen_parse_input_field_data()

  1. /** 
  2.  * 解析使用 html 标签的数据,确保标签不会断开 
  3.  * 基本上来说,这只是 PHP strstr 函数的一个扩展 
  4.  * @参数:字符串,需要被解析的字符串 
  5.  * @参数:字符串,需要在其中搜索的字符串 
  6. */  
  7. // 解析使用 html 标签的数据,确保其中的标签不会断开  
  8.   function zen_parse_input_field_data($data$parse) {  
  9.     return strtr(trim($data), $parse);  
  10.   }  

zen_output_string()

  1. /** 
  2.  * 返回一个出于安全考虑而转换的字符串 
  3.  * @参数:字符串,需要被解析的字符串 
  4.  * @参数:字符串,需要被转换的字符串,否则只有引号被转换 
  5.  * @参数:布尔值,是否需要对字符串实施 htmlspecialchars 操作 
  6. */  
  7.   function zen_output_string($string$translate = false, $protected = false) {  
  8.     if ($protected == true) {  
  9.       return htmlspecialchars($string);  
  10.     } else {  
  11.       if ($translate == false) {  
  12.         return zen_parse_input_field_data($stringarray('"' => '"'));  
  13.       } else {  
  14.         return zen_parse_input_field_data($string$translate);  
  15.       }  
  16.     }  
  17.   }  

zen_output_string_protected()

  1. /** 
  2.  * 返回一个出于安全考虑而转换的字符串 
  3.  * 
  4.  * 简单的调用 zen_ouput_string 函数 
  5.  * 带有将对字符串实施 htmlspecialchars 操作的参数 
  6.  * 然后将引号转换成 html entities 
  7.  * 
  8.  * @参数:字符串,将被解析的字符串 
  9. */  
  10.   function zen_output_string_protected($string) {  
  11.     return zen_output_string($string, false, true);  
  12.   }  

zen_sanitize_string()

  1. /** 
  2.  * 返回一个出于安全考虑而转换的字符串 
  3.  * 
  4.  * @参数:字符串,将被解析的字符串 
  5. */  
  6.   function zen_sanitize_string($string) {  
  7.     $string = preg_replace('/ +/'' '$string);  
  8.     return preg_replace("/[<>]/"'_'$string);  
  9.   }  

zen_break_string()

  1. /** 
  2.  * 如果一个字符串超过指定长度,将其中的字符分断 
  3.  * 
  4.  * @参数:字符串,需要被分断的字符串 
  5.  * @参数:整型,允许的最大长度 
  6.  * @参数:字符串,在分断结尾处将要使用的符号 
  7. */  
  8.   function zen_break_string($string$len$break_char = '-') {  
  9.     $l = 0;  
  10.     $output = '';  
  11.     for ($i=0, $n=strlen($string); $i<$n$i++) {  
  12.       $char = substr($string$i, 1);  
  13.       if ($char != ' ') {  
  14.         $l++;  
  15.       } else {  
  16.         $l = 0;  
  17.       }  
  18.       if ($l > $len) {  
  19.         $l = 1;  
  20.         $output .= $break_char;  
  21.       }  
  22.       $output .= $char;  
  23.     }  
  24.     return $output;  
  25.   }  

zen_get_all_get_params()

  1. /** 
  2.  * 返回全部的 HTTP GET 变量,参数所代表的 GET 变量除外 
  3.  * 
  4.  * 返回的是一个 urlencoded 字符串 
  5.  * 
  6.  * @参数:混合型,既可以是一个参数名字也可以是一个参数数组,这些参数代表的 GET 参数名字将不会被输出 
  7. */  
  8. // 返回全部的 HTTP GET 变量,参数所代表的 GET 变量除外  
  9.   function zen_get_all_get_params($exclude_array = ''$search_engine_safe = true) {  
  10.     if (!is_array($exclude_array)) $exclude_array = array();  
  11.     $get_url = '';  
  12.     if (is_array($_GET) && (sizeof($_GET) > 0)) {  
  13.       reset($_GET);  
  14.       while (list($key$value) = each($_GET)) {  
  15.         if ( (strlen($value) > 0) && ($key != 'main_page') && ($key != zen_session_name()) && ($key != 'error') && (!in_array($key$exclude_array)) && ($key != 'x') && ($key != 'y') ) {  
  16.           if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {  
  17. //    die ('here');  
  18.             $get_url .= $key . '/' . rawurlencode(stripslashes($value)) . '/';  
  19.           } else {  
  20.             $get_url .= zen_sanitize_string($key) . '=' . rawurlencode(stripslashes($value)) . '&';  
  21.           }  
  22.         }  
  23.       }  
  24.     }  
  25.     while (strstr($get_url'&&')) $get_url = str_replace('&&''&'$get_url);  
  26.     while (strstr($get_url'&amp;&amp;')) $get_url = str_replace('&amp;&amp;''&amp;'$get_url);  
  27.     return $get_url;  
  28.   }  

zen_browser_detect()

  1. /** 
  2.  * 返回客户端的浏览器类型 
  3. */  
  4.   function zen_browser_detect($component) {  
  5.     global $HTTP_USER_AGENT;  
  6.     return stristr($HTTP_USER_AGENT$component);  
  7.   }  

zen_round()

  1. /** 
  2.  * round() 函数的扩展 
  3. */  
  4.   function zen_round($value$precision) {  
  5.     $value =  round($value * pow(10, $precision), 0);  
  6.     $value = $value / pow(10, $precision);  
  7.     return $value;  
  8.   }  

zen_row_number_format()

  1. /** 
  2.  * 默认以0填充一个数字,或者传递一个将要使用的填充符号,比如1,将会输出01 
  3. */  
  4.   function zen_row_number_format($number$filler='0') {  
  5.     if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = $filler . $number;  
  6.     return $number;  
  7.   }  

zen_date_long()

  1. /** 
  2.  * 输出以本地化时间格式化的日期字符串 
  3.  * $raw_date 应该是这种格式: YYYY-MM-DD HH:MM:SS 
  4. */  
  5.   function zen_date_long($raw_date) {  
  6.     if ( ($raw_date == '0001-01-01 00:00:00') || ($raw_date == '') ) return false;  
  7.     $year = (int)substr($raw_date, 0, 4);  
  8.     $month = (int)substr($raw_date, 5, 2);  
  9.     $day = (int)substr($raw_date, 8, 2);  
  10.     $hour = (int)substr($raw_date, 11, 2);  
  11.     $minute = (int)substr($raw_date, 14, 2);  
  12.     $second = (int)substr($raw_date, 17, 2);  
  13.     return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));  
  14.   }  

zen_date_short()

  1. /** 
  2.  * 输出指定本地化日期格式的日期字符串 
  3.  * $raw_date 应该是这种格式:YYYY-MM-DD HH:MM:SS 
  4.  * 注意:包括了一个应急方案,在 windows 服务器上对 01/01/1970 之前日期解析失败 
  5. */  
  6.   function zen_date_short($raw_date) {  
  7.     if ( ($raw_date == '0001-01-01 00:00:00') || emptyempty($raw_date) ) return false;  
  8.     $year = substr($raw_date, 0, 4);  
  9.     $month = (int)substr($raw_date, 5, 2);  
  10.     $day = (int)substr($raw_date, 8, 2);  
  11.     $hour = (int)substr($raw_date, 11, 2);  
  12.     $minute = (int)substr($raw_date, 14, 2);  
  13.     $second = (int)substr($raw_date, 17, 2);  
  14. // 发生在1969年的错误  
  15.     if ($year != 1969 && @date('Y'mktime($hour$minute$second$month$day$year)) == $year) {  
  16.       return date(DATE_FORMAT, mktime($hour$minute$second$month$day$year));  
  17.     } else {  
  18.       return preg_replace('/2037$/'$yeardate(DATE_FORMAT, mktime($hour$minute$second$month$day, 2037)));  
  19.     }  
  20.   }  

zen_parse_search_string()

  1. /** 
  2.  * 将搜索字符串传递给各个对象 
  3. */  
  4.   function zen_parse_search_string($search_str = '', &$objects) {  
  5.     $search_str = trim(strtolower($search_str)); // 将传递过来的参数转成小写,同时去掉首尾多余空格  
  6. // 将 $search_str 按照空格断开,被引用的字符串将会在后面被重新组装  
  7.     $pieces = preg_split('/[[:space:]]+/'$search_str);  
  8.     $objects = array();  
  9.     $tmpstring = '';  
  10.     $flag = '';  
  11.     for ($k=0; $k<count($pieces); $k++) {  
  12.       while (substr($pieces[$k], 0, 1) == '(') {  
  13.         $objects[] = '(';  
  14.         if (strlen($pieces[$k]) > 1) {  
  15.           $pieces[$k] = substr($pieces[$k], 1);  
  16.         } else {  
  17.           $pieces[$k] = '';  
  18.         }  
  19.       }  
  20.       $post_objects = array();  
  21.       while (substr($pieces[$k], -1) == ')')  {  
  22.         $post_objects[] = ')';  
  23.         if (strlen($pieces[$k]) > 1) {  
  24.           $pieces[$k] = substr($pieces[$k], 0, -1);  
  25.         } else {  
  26.           $pieces[$k] = '';  
  27.         }  
  28.       }  
  29. // 检测各个单词  
  30.       if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) {  
  31.         $objects[] = trim($pieces[$k]);  
  32.         for ($j=0; $j<count($post_objects); $j++) {  
  33.           $objects[] = $post_objects[$j];  
  34.         }  
  35.       } else {  
  36. /*  
  37.  * 这将意味着,$piece 有可能是一个字符串的最开始,或者最末尾 
  38.  * 所以,我们吃掉 $pieces,同时把它们粘在一起, 
  39.  * 直到我们到达字符串的最末尾或者片断全部出尽为止 
  40. */  
  41. // 将这个单词添加到 $tmpstring,开始操作 $tmpstring  
  42.         $tmpstring = trim(preg_replace('/"/'' '$pieces[$k]));  
  43. // 检查这个规则的一个可能的意外,当只是一个单独的引用单词的时候  
  44.         if (substr($pieces[$k], -1 ) == '"') {  
  45. // 关闭之后的迭代  
  46.           $flag = 'off';  
  47.           $objects[] = trim($pieces[$k]);  
  48.           for ($j=0; $j<count($post_objects); $j++) {  
  49.             $objects[] = $post_objects[$j];  
  50.           }  
  51.           unset($tmpstring);  
  52. // 停止查找字符串的最末尾,同时移向下一个单词  
  53.           continue;  
  54.         }  
  55. // 否则,指示在字符串没有找到被添加引用  
  56.         $flag = 'on';  
  57. // 移动到下一个单词  
  58.         $k++;  
  59. // 继续读取字符串的末尾,直到 $flag 被打开  
  60.         while ( ($flag == 'on') && ($k < count($pieces)) ) {  
  61.           while (substr($pieces[$k], -1) == ')') {  
  62.             $post_objects[] = ')';  
  63.             if (strlen($pieces[$k]) > 1) {  
  64.               $pieces[$k] = substr($pieces[$k], 0, -1);  
  65.             } else {  
  66.               $pieces[$k] = '';  
  67.             }  
  68.           }  
  69. // 如果单词不是以双引号结束,把它添加到 $tmpstring  
  70.           if (substr($pieces[$k], -1) != '"') {  
  71. // 把这个单词添加到当前字符串  
  72.             $tmpstring .= ' ' . $pieces[$k];  
  73. // 移动到下一个单词  
  74.             $k++;  
  75.             continue;  
  76.           } else {  
  77. /*  
  78.  * 如果 $piece 以双引号结尾,去掉双引号,把 $piece 添加到字符串的末尾, 
  79.  * 把 $tmpstring 加入到 $haves,杀掉 $tmpstring,关闭 $flag,然后返回 
  80. */  
  81.             $tmpstring .= ' ' . trim(preg_replace('/"/'' '$pieces[$k]));  
  82. // 把 $tmpstring 添加到将被搜索的数组  
  83.             $objects[] = trim($tmpstring);  
  84.             for ($j=0; $j<count($post_objects); $j++) {  
  85.               $objects[] = $post_objects[$j];  
  86.             }  
  87.             unset($tmpstring);  
  88. // 关闭 flag,然后退出循环  
  89.             $flag = 'off';  
  90.           }  
  91.         }  
  92.       }  
  93.     }  
  94. // 如果需要的话,添加默认的逻辑操作符  
  95.     $temp = array();  
  96.     for($i=0; $i<(count($objects)-1); $i++) {  
  97.       $temp[] = $objects[$i];  
  98.       if ( ($objects[$i] != 'and') &&  
  99.            ($objects[$i] != 'or') &&  
  100.            ($objects[$i] != '(') &&  
  101.            ($objects[$i+1] != 'and') &&  
  102.            ($objects[$i+1] != 'or') &&  
  103.            ($objects[$i+1] != ')') ) {  
  104.         $temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR;  
  105.       }  
  106.     }  
  107.     $temp[] = $objects[$i];  
  108.     $objects = $temp;  
  109.     $keyword_count = 0;  
  110.     $operator_count = 0;  
  111.     $balance = 0;  
  112.     for($i=0; $i<count($objects); $i++) {  
  113.       if ($objects[$i] == '('$balance --;  
  114.       if ($objects[$i] == ')'$balance ++;  
  115.       if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) {  
  116.         $operator_count ++;  
  117.       } elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {  
  118.         $keyword_count ++;  
  119.       }  
  120.     }  
  121.     if ( ($operator_count < $keyword_count) && ($balance == 0) ) {  
  122.       return true;  
  123.     } else {  
  124.       return false;  
  125.     }  
  126.   }  

zen_checkdate()

  1. function zen_checkdate($date_to_check$format_string, &$date_array) {  
  2.   $separator_idx = -1;  
  3.   $separators = array('-'' ''/''.');  
  4.   $month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');  
  5.   $no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);  
  6.   $format_string = strtolower($format_string);  
  7.   if (strlen($date_to_check) != strlen($format_string)) {  
  8.     return false;  
  9.   }  
  10.   $size = sizeof($separators);  
  11.   for ($i=0; $i<$size$i++) {  
  12.     $pos_separator = strpos($date_to_check$separators[$i]);  
  13.     if ($pos_separator != false) {  
  14.       $date_separator_idx = $i;  
  15.       break;  
  16.     }  
  17.   }  
  18.   for ($i=0; $i<$size$i++) {  
  19.     $pos_separator = strpos($format_string$separators[$i]);  
  20.     if ($pos_separator != false) {  
  21.       $format_separator_idx = $i;  
  22.       break;  
  23.     }  
  24.   }  
  25.   if ($date_separator_idx != $format_separator_idx) {  
  26.     return false;  
  27.   }  
  28.   if ($date_separator_idx != -1) {  
  29.     $format_string_array = explode$separators[$date_separator_idx], $format_string );  
  30.     if (sizeof($format_string_array) != 3) {  
  31.       return false;  
  32.     }  
  33.     $date_to_check_array = explode$separators[$date_separator_idx], $date_to_check );  
  34.     if (sizeof($date_to_check_array) != 3) {  
  35.       return false;  
  36.     }  
  37.     $size = sizeof($format_string_array);  
  38.     for ($i=0; $i<$size$i++) {  
  39.       if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm'$month = $date_to_check_array[$i];  
  40.       if ($format_string_array[$i] == 'dd'$day = $date_to_check_array[$i];  
  41.       if ( ($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa') ) $year = $date_to_check_array[$i];  
  42.     }  
  43.   } else {  
  44.     if (strlen($format_string) == 8 || strlen($format_string) == 9) {  
  45.       $pos_month = strpos($format_string'mmm');  
  46.       if ($pos_month != false) {  
  47.         $month = substr$date_to_check$pos_month, 3 );  
  48.         $size = sizeof($month_abbr);  
  49.         for ($i=0; $i<$size$i++) {  
  50.           if ($month == $month_abbr[$i]) {  
  51.             $month = $i;  
  52.             break;  
  53.           }  
  54.         }  
  55.       } else {  
  56.         $month = substr($date_to_checkstrpos($format_string'mm'), 2);  
  57.       }  
  58.     } else {  
  59.       return false;  
  60.     }  
  61.     $day = substr($date_to_checkstrpos($format_string'dd'), 2);  
  62.     $year = substr($date_to_checkstrpos($format_string'yyyy'), 4);  
  63.   }  
  64.   if (strlen($year) != 4) {  
  65.     return false;  
  66.   }  
  67.   if (!settype($year'integer') || !settype($month'integer') || !settype($day'integer')) {  
  68.     return false;  
  69.   }  
  70.   if ($month > 12 || $month < 1) {  
  71.     return false;  
  72.   }  
  73.   if ($day < 1) {  
  74.     return false;  
  75.   }  
  76.   if (zen_is_leap_year($year)) {  
  77.     $no_of_days[1] = 29;  
  78.   }  
  79.   if ($day > $no_of_days[$month - 1]) {  
  80.     return false;  
  81.   }  
  82.   $date_array = array($year$month$day);  
  83.   return true;  
  84. }  

zen_is_leap_year()

  1. /** 
  2.  * 检查一个年份是否闰年 
  3. */  
  4.   function zen_is_leap_year($year) {  
  5.     if ($year % 100 == 0) {  
  6.       if ($year % 400 == 0) return true;  
  7.     } else {  
  8.       if (($year % 4) == 0) return true;  
  9.     }  
  10.     return false;  
  11.   }  

zen_create_sort_heading()

  1.   
  2. // 返回数据库表的头部,同时带有分类功能  
  3.   function zen_create_sort_heading($sortby$colnum$heading) {  
  4.     global $PHP_SELF;  
  5.     $sort_prefix = '';  
  6.     $sort_suffix = '';  
  7.     if ($sortby) {  
  8.       $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">' ;  
  9.       $sort_suffix = (substr($sortby, 0, 1) == $colnum ? (substr($sortby, 1, 1) == 'a' ? PRODUCT_LIST_SORT_ORDER_ASCENDING : PRODUCT_LIST_SORT_ORDER_DESCENDING) : '') . '</a>';  
  10.     }  
  11.     return $sort_prefix . $heading . $sort_suffix;  
  12.   }  

zen_get_uprid_OLD()

  1.   
  2. // 返回一件商品的 ID,同时带有该商品的属性  
  3. //(这个是旧的函数,已经被下面的 zen_get_uprid() 函数所取代)  
  4. /* 
  5.   function zen_get_uprid_OLD($prid, $params) { 
  6.     $uprid = $prid; 
  7.     if ( (is_array($params)) && (!strstr($prid, '{')) ) { 
  8.       while (list($option, $value) = each($params)) { 
  9.         $uprid = $uprid . '{' . $option . '}' . $value; 
  10.       } 
  11.     } 
  12.     return $uprid; 
  13.   } 
  14. */  

zen_get_uprid()

  1.   
  2. // 返回一件商品的 ID,同时带有该商品的属性  
  3.   function zen_get_uprid($prid$params) {  
  4. //print_r($params);  
  5.     $uprid = $prid;  
  6.     if ( (is_array($params)) && (!strstr($prid':')) ) {  
  7.       while (list($option$value) = each($params)) {  
  8.         if (is_array($value)) {  
  9.           while (list($opt$val) = each($value)) {  
  10.             $uprid = $uprid . '{' . $option . '}' . trim($opt);  
  11.           }  
  12.         } else {  
  13.         //CLR 030714 Add processing around $value. This is needed for text attributes.  
  14.             $uprid = $uprid . '{' . $option . '}' . trim($value);  
  15.         }  
  16.       }      //CLR 030228 Add else stmt to process product ids passed in by other routines.  
  17.       $md_uprid = '';  
  18.       $md_uprid = md5($uprid);  
  19.       return $prid . ':' . $md_uprid;  
  20.     } else {  
  21.       return $prid;  
  22.     }  
  23.   }  

zen_get_prid()

  1.   
  2. // 从一个带有商品属性的商品 ID 返回一件商品的 ID  
  3.   function zen_get_prid($uprid) {  
  4.     $pieces = explode(':'$uprid);  
  5.     return $pieces[0];  
  6.   }  

zen_word_count()

  1.   
  2. // 得到一个单词或者字母在一个字符串中出现的次数  
  3.   function zen_word_count($string$needle) {  
  4.     $temp_array = preg_split('/'.$needle.'/'$string);  
  5.     return sizeof($temp_array);  
  6.   }  

zen_count_modules()

  1.   
  2.   function zen_count_modules($modules = '') {  
  3.     $count = 0;  
  4.     if (emptyempty($modules)) return $count;  
  5.     $modules_array = preg_split('/;/'$modules);  
  6.     for ($i=0, $n=sizeof($modules_array); $i<$n$i++) {  
  7.       $class = substr($modules_array[$i], 0, strrpos($modules_array[$i], '.'));  
  8.       if (is_object($GLOBALS[$class])) {  
  9.         if ($GLOBALS[$class]->enabled) {  
  10.           $count++;  
  11.         }  
  12.       }  
  13.     }  
  14.     return $count;  
  15.   }  

zen_count_payment_modules()

  1. function zen_count_payment_modules() {  
  2.   return zen_count_modules(MODULE_PAYMENT_INSTALLED);  
  3. }  

zen_count_shipping_modules()

  1. function zen_count_shipping_modules() {  
  2.   return zen_count_modules(MODULE_SHIPPING_INSTALLED);  
  3. }  

zen_create_random_value()

  1. function zen_create_random_value($length$type = 'mixed') {  
  2.   if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;  
  3.   $rand_value = '';  
  4.   while (strlen($rand_value) < $length) {  
  5.     if ($type == 'digits') {  
  6.       $char = zen_rand(0,9);  
  7.     } else {  
  8.       $char = chr(zen_rand(0,255));  
  9.     }  
  10.     if ($type == 'mixed') {  
  11.       if (preg_match('/^[a-z0-9]$/i'$char)) $rand_value .= $char;  
  12.     } elseif ($type == 'chars') {  
  13.       if (preg_match('/^[a-z]$/i'$char)) $rand_value .= $char;  
  14.     } elseif ($type == 'digits') {  
  15.       if (preg_match('/^[0-9]$/'$char)) $rand_value .= $char;  
  16.     }  
  17.   }  
  18.   return $rand_value;  
  19. }  

zen_array_to_string()

  1.   
  2.   function zen_array_to_string($array$exclude = ''$equals = '='$separator = '&') {  
  3.     if (!is_array($exclude)) $exclude = array();  
  4.     if (!is_array($array)) $array = array();  
  5.     $get_string = '';  
  6.     if (sizeof($array) > 0) {  
  7.       while (list($key$value) = each($array)) {  
  8.         if ( (!in_array($key$exclude)) && ($key != 'x') && ($key != 'y') ) {  
  9.           $get_string .= $key . $equals . $value . $separator;  
  10.         }  
  11.       }  
  12.       $remove_chars = strlen($separator);  
  13.       $get_string = substr($get_string, 0, -$remove_chars);  
  14.     }  
  15.     return $get_string;  
  16.   }  

zen_not_null()

  1. function zen_not_null($value) {  
  2.   if (is_array($value)) {  
  3.     if (sizeof($value) > 0) {  
  4.       return true;  
  5.     } else {  
  6.       return false;  
  7.     }  
  8.   } elseifis_a$value'queryFactoryResult' ) ) {  
  9.     if (sizeof($value->result) > 0) {  
  10.       return true;  
  11.     } else {  
  12.       return false;  
  13.     }  
  14.   } else {  
  15.     if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {  
  16.       return true;  
  17.     } else {  
  18.       return false;  
  19.     }  
  20.   }  
  21. }  

zen_currency_exists()

  1.   
  2. // 检查货币代号是否已经存在  
  3. // 数据库表: currencies  
  4.   function zen_currency_exists($code$getFirstDefault = false) {  
  5.     global $db;  
  6.     $code = zen_db_prepare_input($code);  
  7.     $currency_code = "select code  
  8.                       from " . TABLE_CURRENCIES . "  
  9.                       where code = '" . zen_db_input($code) . "' LIMIT 1";  
  10.     $currency_first = "select code  
  11.                       from " . TABLE_CURRENCIES . "  
  12.                       order by value ASC LIMIT 1";  
  13.     $currency = $db->Execute(($getFirstDefault == false) ? $currency_code : $currency_first);  
  14.     if ($currency->RecordCount()) {  
  15.       return strtoupper($currency->fields['code']);  
  16.     } else {  
  17.       return false;  
  18.     }  
  19.   }  

zen_string_to_int()

  1. function zen_string_to_int($string) {  
  2.   return (int)$string;  
  3. }  

zen_rand()

  1.   
  2. // 返回一个随机数值  
  3.   function zen_rand($min = null, $max = null) {  
  4.     static $seeded;  
  5.     if (!isset($seeded)) {  
  6.       mt_srand((double)microtime()*1000000);  
  7.       $seeded = true;  
  8.     }  
  9.     if (isset($min) && isset($max)) {  
  10.       if ($min >= $max) {  
  11.         return $min;  
  12.       } else {  
  13.         return mt_rand($min$max);  
  14.       }  
  15.     } else {  
  16.       return mt_rand();  
  17.     }  
  18.   }  

zen_get_top_level_domain()

  1.   
  2.   function zen_get_top_level_domain($url) {  
  3.     if (strpos($url'://')) {  
  4.       $url = parse_url($url);  
  5.       $url = $url['host'];  
  6.     }  
  7. //输出 $url;  
  8.     $domain_array = explode('.'$url);  
  9.     $domain_size = sizeof($domain_array);  
  10.     if ($domain_size > 1) {  
  11.       if (SESSION_USE_FQDN == 'True'return $url;  
  12.       if (is_numeric($domain_array[$domain_size-2]) && is_numeric($domain_array[$domain_size-1])) {  
  13.         return false;  
  14.       } else {  
  15.         $tld = "";  
  16.         foreach ($domain_array as $dPart)  
  17.         {  
  18.           if ($dPart != "www"$tld = $tld . "." . $dPart;  
  19.         }  
  20.         return substr($tld, 1);  
  21.       }  
  22.     } else {  
  23.       return false;  
  24.     }  
  25.   }  

zen_setcookie()

  1.   
  2.   function zen_setcookie($name$value = ''$expire = 0, $path = '/'$domain = ''$secure = 0) {  
  3.     setcookie($name$value$expire$path$domain$secure);  
  4.   }  

zen_get_ip_address()

  1.   
  2.   function zen_get_ip_address() {  
  3.     if (isset($_SERVER)) {  
  4.       if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
  5.         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
  6.       } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {  
  7.         $ip = $_SERVER['HTTP_CLIENT_IP'];  
  8.       } else {  
  9.         $ip = $_SERVER['REMOTE_ADDR'];  
  10.       }  
  11.     } else {  
  12.       if (getenv('HTTP_X_FORWARDED_FOR')) {  
  13.         $ip = getenv('HTTP_X_FORWARDED_FOR');  
  14.       } elseif (getenv('HTTP_CLIENT_IP')) {  
  15.         $ip = getenv('HTTP_CLIENT_IP');  
  16.       } else {  
  17.         $ip = getenv('REMOTE_ADDR');  
  18.       }  
  19.     }  
  20.     return $ip;  
  21.   }  

zen_convert_linefeeds()

  1. // PHP 4.2.0 之前版本的 nl2br() 函数不会在所有的操作系统上转换换行(它只转换 /n)  
  2.   function zen_convert_linefeeds($from$to$string) {  
  3.     if ((PHP_VERSION < "4.0.5") && is_array($from)) {  
  4.       return preg_replace('/(' . implode('|'$from) . ')/'$to$string);  
  5.     } else {  
  6.       return str_replace($from$to$string);  
  7.     }  
  8.   }  

is_product_valid()

  1. // 检查某件商品是否适用优惠券??  
  2.   function is_product_valid($product_id$coupon_id) {  
  3.     global $db;  
  4.     $coupons_query = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "  
  5.                       WHERE coupon_id = '" . (int)$coupon_id . "'  
  6.                       ORDER BY coupon_restrict ASC";  
  7.     $coupons = $db->Execute($coupons_query);  
  8.     $product_query = "SELECT products_model FROM " . TABLE_PRODUCTS . "  
  9.                       WHERE products_id = '" . (int)$product_id . "'";  
  10.     $product = $db->Execute($product_query);  
  11.     if (preg_match('/^GIFT/'$product->fields['products_model'])) {  
  12.       return false;  
  13.     }  
  14. // modified to manage restrictions better - leave commented for now  
  15.     if ($coupons->RecordCount() == 0) return true;  
  16.     if ($coupons->RecordCount() == 1) {  
  17. // If product is restricted(deny) and is same as tested prodcut deny  
  18.       if (($coupons->fields['product_id'] != 0) && $coupons->fields['product_id'] == (int)$product_id && $coupons->fields['coupon_restrict']=='Y'return false;  
  19. // If product is not restricted(allow) and is not same as tested prodcut deny  
  20.       if (($coupons->fields['product_id'] != 0) && $coupons->fields['product_id'] != (int)$product_id && $coupons->fields['coupon_restrict']=='N'return false;  
  21. // 如果分类目录是 restricted(deny) 那么商品应该在不允许使用优惠券的分类目录中  
  22.       if (($coupons->fields['category_id'] !=0) && (zen_product_in_category($product_id$coupons->fields['category_id'])) && ($coupons->fields['coupon_restrict']=='Y')) return false;  
  23. // if category is not restricted(allow) and product not in category deny  
  24.       if (($coupons->fields['category_id'] !=0) && (!zen_product_in_category($product_id$coupons->fields['category_id'])) && ($coupons->fields['coupon_restrict']=='N')) return false;  
  25.       return true;  
  26.     }  
  27.     $allow_for_category = validate_for_category($product_id$coupon_id);  
  28.     $allow_for_product = validate_for_product($product_id$coupon_id);  
  29. // 输出 '#'.$product_id . '#' . $allow_for_category;  
  30. // 输出 '#'.$product_id . '#' . $allow_for_product;  
  31.     if ($allow_for_category == 'none') {  
  32.       if ($allow_for_product === 'none'return true;  
  33.       if ($allow_for_product === true) return true;  
  34.       if ($allow_for_product === false) return false;  
  35.     }  
  36.     if ($allow_for_category === true) {  
  37.       if ($allow_for_product === 'none'return true;  
  38.       if ($allow_for_product === true) return true;  
  39.       if ($allow_for_product === false) return false;  
  40.     }  
  41.     if ($allow_for_category === false) {  
  42.       if ($allow_for_product === 'none'return false;  
  43.       if ($allow_for_product === true) return true;  
  44.       if ($allow_for_product === false) return false;  
  45.     }  
  46.     return false; // 应该永远不会到这里  
  47.   }  

validate_for_category()

  1. function validate_for_category($product_id$coupon_id) {  
  2.   global $db;  
  3.   $retVal = 'none';  
  4.   $productCatPath = zen_get_product_path($product_id);  
  5.   $catPathArray = array_reverse(explode('_'$productCatPath));  
  6.   $sql = "SELECT count(*) AS total  
  7.           FROM " . TABLE_COUPON_RESTRICT . "  
  8.           WHERE category_id = -1  
  9.           AND coupon_restrict = 'Y'  
  10.           AND coupon_id = " . (int)$coupon_id . " LIMIT 1";  
  11.   $checkQuery = $db->execute($sql);  
  12.   foreach ($catPathArray as $catPath) {  
  13.     $sql = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "  
  14.             WHERE category_id = " . (int)$catPath . "  
  15.             AND coupon_id = " . (int)$coupon_id;  
  16.     $result = $db->execute($sql);  
  17.     if ($result->recordCount() > 0 && $result->fields['coupon_restrict'] == 'N'return true;  
  18.     if ($result->recordCount() > 0 && $result->fields['coupon_restrict'] == 'Y'return false;  
  19.   }  
  20.   if ($checkQuery->fields['total'] > 0) {  
  21.     return false;  
  22.   } else {  
  23.     return 'none';  
  24.   }  
  25. }  

validate_for_product()

  1. function validate_for_product($product_id$coupon_id) {  
  2.   global $db;  
  3.   $sql = "SELECT * FROM " . TABLE_COUPON_RESTRICT . "  
  4.           WHERE product_id = " . (int)$product_id . "  
  5.           AND coupon_id = " . (int)$coupon_id . " LIMIT 1";  
  6.   $result = $db->execute($sql);  
  7.   if ($result->recordCount() > 0) {  
  8.     if ($result->fields['coupon_restrict'] == 'N'return true;  
  9.     if ($result->fields['coupon_restrict'] == 'Y'return false;  
  10.   } else {  
  11.     return 'none';  
  12.   }  
  13. }  

zen_db_input()

  1.   
  2.   function zen_db_input($string) {  
  3.     return addslashes($string);  
  4.   }  

zen_db_prepare_input()

  1.   
  2.   function zen_db_prepare_input($string) {  
  3.     if (is_string($string)) {  
  4.       return trim(zen_sanitize_string(stripslashes($string)));  
  5.     } elseif (is_array($string)) {  
  6.       reset($string);  
  7.       while (list($key$value) = each($string)) {  
  8.         $string[$key] = zen_db_prepare_input($value);  
  9.       }  
  10.       return $string;  
  11.     } else {  
  12.       return $string;  
  13.     }  
  14.   }  

zen_db_perform()

  1.   
  2.   function zen_db_perform($table$data$action = 'insert'$parameters = ''$link = 'db_link') {  
  3.     global $db;  
  4.     reset($data);  
  5.     if (strtolower($action) == 'insert') {  
  6.       $query = 'INSERT INTO ' . $table . ' (';  
  7.       while (list($columns, ) = each($data)) {  
  8.         $query .= $columns . ', ';  
  9.       }  
  10.       $query = substr($query, 0, -2) . ') VALUES (';  
  11.       reset($data);  
  12.       while (list(, $value) = each($data)) {  
  13.         switch ((string)$value) {  
  14.           case 'now()':  
  15.             $query .= 'now(), ';  
  16.             break;  
  17.           case 'null':  
  18.             $query .= 'null, ';  
  19.             break;  
  20.           default:  
  21.             $query .= '/'' . zen_db_input($value) . '/', ';  
  22.             break;  
  23.         }  
  24.       }  
  25.       $query = substr($query, 0, -2) . ')';  
  26.     } elseif (strtolower($action) == 'update') {  
  27.       $query = 'UPDATE ' . $table . ' SET ';  
  28.       while (list($columns$value) = each($data)) {  
  29.         switch ((string)$value) {  
  30.           case 'now()':  
  31.             $query .= $columns . ' = now(), ';  
  32.             break;  
  33.           case 'null':  
  34.             $query .= $columns .= ' = null, ';  
  35.             break;  
  36.           default:  
  37.             $query .= $columns . ' = /'' . zen_db_input($value) . '/', ';  
  38.             break;  
  39.         }  
  40.       }  
  41.       $query = substr($query, 0, -2) . ' WHERE ' . $parameters;  
  42.     }  
  43.     return $db->Execute($query);  
  44.   }  

zen_db_output()

  1.   
  2.   function zen_db_output($string) {  
  3.     return htmlspecialchars($string);  
  4.   }  

zen_field_type()

  1. // 返回字段类型  
  2. // $tbl = 数据表名, $fld = 字段名  
  3.   function zen_field_type($tbl$fld) {  
  4.     global $db;  
  5.     $rs = $db->MetaColumns($tbl);  
  6.     $type = $rs[strtoupper($fld)]->type;  
  7.     return $type;  
  8.   }  

zen_field_length()

  1. // 返回字段长度  
  2. // $tbl = 数据表名, $fld = 字段名  
  3.   function zen_field_length($tbl$fld) {  
  4.     global $db;  
  5.     $rs = $db->MetaColumns($tbl);  
  6.     $length = $rs[strtoupper($fld)]->max_length;  
  7.     return $length;  
  8.   }  

zen_set_field_length()

  1.   
  2. // 返回表单设置中的 size 和 maxlength 属性,默认的最大 size 是 70  
  3. // 使用 $tbl = 数据库表的名字, $fld = 字段名  
  4. // 举例: zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')  
  5.   function zen_set_field_length($tbl$fld$max=70) {  
  6.     $field_length= zen_field_length($tbl$fld);  
  7.     switch (true) {  
  8.       case ($field_length > $max):  
  9.         $length'size = "' . ($max+1) . '" maxlength= "' . $field_length . '"';  
  10.         break;  
  11.       default:  
  12.         $length'size = "' . ($field_length+1) . '" maxlength = "' . $field_length . '"';  
  13.         break;  
  14.     }  
  15.     return $length;  
  16.   }  

zen_back_link()

  1.   
  2. // 设置返回键(就是返回之前页面的那个按钮)  
  3.   function zen_back_link($link_only = false) {  
  4.     if (sizeof($_SESSION['navigation']->path)-2 >= 0) {  
  5.       $back = sizeof($_SESSION['navigation']->path)-2;  
  6.       $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']);  
  7.     } else {  
  8.       if (isset($_SERVER['HTTP_REFERER']) && preg_match("~^".HTTP_SERVER."~i"$_SERVER['HTTP_REFERER']) ) {  
  9.       //if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], str_replace(array('http://', 'https://'), '', HTTP_SERVER) ) ) {  
  10.         $link$_SERVER['HTTP_REFERER'];  
  11.       } else {  
  12.         $link = zen_href_link(FILENAME_DEFAULT);  
  13.       }  
  14.       $_SESSION['navigation'] = new navigationHistory;  
  15.     }  
  16.     if ($link_only == true) {  
  17.       return $link;  
  18.     } else {  
  19.       return '<a href="' . $link . '" mce_href="' . $link . '">';  
  20.     }  
  21.   }  

zen_random_select()

  1.   
  2. // 由一个数据查询返回随机的一排数据  
  3.   function zen_random_select($query) {  
  4.     global $db;  
  5.     $random_product = '';  
  6.     $random_query = $db->Execute($query);  
  7.     $num_rows = $random_query->RecordCount();  
  8.     if ($num_rows > 1) {  
  9.       $random_row = zen_rand(0, ($num_rows - 1));  
  10.       $random_query->Move($random_row);  
  11.     }  
  12.     return $random_query;  
  13.   }  

zen_trunc_string()

  1.   
  2. // 切割一个字符串  
  3.   function zen_trunc_string($str = ""$len = 150, $more = 'true') {  
  4.     if ($str == ""return $str;  
  5.     if (is_array($str)) return $str;  
  6.     $str = trim($str);  
  7.     // 如果字符串小于指定的长度,那么返回这个字符串  
  8.     if (strlen($str) <= $lenreturn $str;  
  9.     // 否则得到这段文字的长度  
  10.     $str = substr($str, 0, $len);  
  11.     // backtrack to the end of a word  
  12.     if ($str != "") {  
  13.       // check to see if there are any spaces left  
  14.       if (!substr_count($str , " ")) {  
  15.         if ($more == 'true'$str .= "...";  
  16.         return $str;  
  17.       }  
  18.       // backtrack  
  19.       while(strlen($str) && ($str[strlen($str)-1] != " ")) {  
  20.         $str = substr($str, 0, -1);  
  21.       }  
  22.       $str = substr($str, 0, -1);  
  23.       if ($more == 'true'$str .= "...";  
  24.       if ($more != 'true' and $more != 'false'$str .= $more;  
  25.     }  
  26.     return $str;  
  27.   }  

zen_get_box_id()

  1.   
  2. // 设置当前边框的 id  
  3.   function zen_get_box_id($box_id) {  
  4.     while (strstr($box_id'_')) $box_id = str_replace('_'''$box_id);  
  5.     $box_id = str_replace('.php'''$box_id);  
  6.     return $box_id;  
  7.   }  

zen_get_buy_now_button()

  1.   
  2. // 根据咨询价格或者已经售完,转换加入购物车按钮(比如一件商品已经售完,那么商品页面就不应该再出现“加入购物车”的按钮)  
  3.   function zen_get_buy_now_button($product_id$link$additional_link = false) {  
  4.     global $db;  
  5. // 当所有其它设置被挂起的时候,才显示  
  6.     if (STORE_STATUS != '0') {  
  7.       return '<a href="' . zen_href_link(FILENAME_CONTACT_US) . '" mce_href="' . zen_href_link(FILENAME_CONTACT_US) . '">' .  TEXT_SHOWCASE_ONLY . '</a>';  
  8.     }  
  9. // 0 = 正常购物  
  10. // 1 = 登陆才能购物  
  11. // 2 = 可以浏览但是没有价格  
  12.     // 确定是否显示价格  
  13.       switch (true) {  
  14.         case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''):  
  15.         // 用户必须登陆才能浏览价格  
  16.         $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>';  
  17.         return $login_for_price;  
  18.         break;  
  19.         case (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == ''):  
  20.         if (TEXT_LOGIN_FOR_PRICE_PRICE == '') {  
  21.           // 显示空白  
  22.           return TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE;  
  23.         } else {  
  24.           // 用户可以浏览但是没有价格  
  25.           $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>';  
  26.         }  
  27.         return $login_for_price;  
  28.         break;  
  29.         // 显示空白  
  30.         case (CUSTOMERS_APPROVAL == '3'):  
  31.           $login_for_price = TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM;  
  32.           return $login_for_price;  
  33.         break;  
  34.         case ((CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and CUSTOMERS_APPROVAL_AUTHORIZATION != '3'and $_SESSION['customer_id'] == ''):  
  35.         // 用户必须登陆才能浏览价格  
  36.         $login_for_price = TEXT_AUTHORIZATION_PENDING_BUTTON_REPLACE;  
  37.         return $login_for_price;  
  38.         break;  
  39.         case ((CUSTOMERS_APPROVAL_AUTHORIZATION == '3'and $_SESSION['customer_id'] == ''):  
  40.         // 用户必须登陆而且经过允许才能加入到购物车  
  41.         $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>';  
  42.         return $login_for_price;  
  43.         break;  
  44.         case (CUSTOMERS_APPROVAL_AUTHORIZATION != '0' and $_SESSION['customers_authorization'] > '0'):  
  45.         // 用户必须登陆才能浏览价格  
  46.         $login_for_price = TEXT_AUTHORIZATION_PENDING_BUTTON_REPLACE;  
  47.         return $login_for_price;  
  48.         break;  
  49.         default:  
  50.         // 正常程序  
  51.         break;  
  52.       }  
  53.     $button_check = $db->Execute("select product_is_call, products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'");  
  54.     switch (true) {  
  55. // 不能被加入到购物车  
  56.     case (zen_get_products_allow_add_to_cart($product_id) == 'N'):  
  57.       return $additional_link;  
  58.       break;  
  59.     case ($button_check->fields['product_is_call'] == '1'):  
  60.       $return_button = '<a href="' . zen_href_link(FILENAME_CONTACT_US) . '" mce_href="' . zen_href_link(FILENAME_CONTACT_US) . '">' . TEXT_CALL_FOR_PRICE . '</a>';  
  61.       break;  
  62.     case ($button_check->fields['products_quantity'] <= 0 and SHOW_PRODUCTS_SOLD_OUT_IMAGE == '1'):  
  63.       if ($_GET['main_page'] == zen_get_info_page($product_id)) {  
  64.         $return_button = zen_image_button(BUTTON_IMAGE_SOLD_OUT, BUTTON_SOLD_OUT_ALT);  
  65.       } else {  
  66.         $return_button = zen_image_button(BUTTON_IMAGE_SOLD_OUT_SMALL, BUTTON_SOLD_OUT_SMALL_ALT);  
  67.       }  
  68.       break;  
  69.     default:  
  70.       $return_button = $link;  
  71.       break;  
  72.     }  
  73.     if ($return_button != $link and $additional_link != false) {  
  74.       return $additional_link . '<br />' . $return_button;  
  75.     } else {  
  76.       return $return_button;  
  77.     }  
  78.   }  

zen_get_shipping_enabled()

  1.   
  2. // 激活邮费模块  
  3.   function zen_get_shipping_enabled($shipping_module) {  
  4.     global $PHP_SELF$cart$order;  
  5.     // 如果已经安装,那么后台总是为真  
  6.     if (strstr($PHP_SELF, FILENAME_MODULES)) {  
  7.       return true;  
  8.     }  
  9.     $check_cart_free = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1');  
  10.     $check_cart_cnt = $_SESSION['cart']->count_contents();  
  11.     $check_cart_weight = $_SESSION['cart']->show_weight();  
  12.     switch(true) {  
  13.       // 如果已经安装,那么后台总是为真  
  14.       case (strstr($PHP_SELF, FILENAME_MODULES)):  
  15.         return true;  
  16.         break;  
  17.       // 当重量为 0,免邮费 - 激活免邮费 - ORDER_WEIGHT_ZERO_STATUS 必须打开  
  18.       case (ORDER_WEIGHT_ZERO_STATUS == '1' and ($check_cart_weight == 0 and $shipping_module == 'freeshipper')):  
  19.         return true;  
  20.         break;  
  21.       // 当重量为 0,免邮费 - Free Shipping when 0 weight - disable everyone - ORDER_WEIGHT_ZERO_STATUS must be on  
  22.       case (ORDER_WEIGHT_ZERO_STATUS == '1' and ($check_cart_weight == 0 and $shipping_module != 'freeshipper')):  
  23.         return false;  
  24.         break;  
  25.       case (($_SESSION['cart']->free_shipping_items() == $check_cart_cntand $shipping_module == 'freeshipper'):  
  26.         return true;  
  27.         break;  
  28.       case (($_SESSION['cart']->free_shipping_items() == $check_cart_cntand $shipping_module != 'freeshipper'):  
  29.         return false;  
  30.         break;  
  31.       // Always free shipping only true - enable freeshipper  
  32.       case (($check_cart_free == $check_cart_cntand $shipping_module == 'freeshipper'):  
  33.         return true;  
  34.         break;  
  35.       // Always free shipping only true - disable everyone  
  36.       case (($check_cart_free == $check_cart_cntand $shipping_module != 'freeshipper'):  
  37.         return false;  
  38.         break;  
  39.       // Always free shipping only is false - disable freeshipper  
  40.       case (($check_cart_free != $check_cart_cntand $shipping_module == 'freeshipper'):  
  41.         return false;  
  42.         break;  
  43.       default:  
  44.         return true;  
  45.         break;  
  46.     }  
  47.   }  

zen_html_entity_decode()

  1.   
  2.   function zen_html_entity_decode($given_html$quote_style = ENT_QUOTES) {  
  3.     $trans_table = array_flip(get_html_translation_table( HTML_SPECIALCHARS, $quote_style ));  
  4.     $trans_table['''] = "'";  
  5.     return ( strtr$given_html$trans_table ) );  
  6.   }  

zen_decode_specialchars()

  1.   
  2. //CLR 030228 Add function zen_decode_specialchars  
  3. // Decode string encoded with htmlspecialchars()  
  4.   function zen_decode_specialchars($string){  
  5.     $string=str_replace('>''>'$string);  
  6.     $string=str_replace('<''<'$string);  
  7.     $string=str_replace(''', "'", $string);  
  8.     $string=str_replace('"', "/""$string);  
  9.     $string=str_replace('&amp;''&'$string);  
  10.     return $string;  
  11.   }  

zen_clean_html()

  1.   
  2. // remove common HTML from text for display as paragraph  
  3.   function zen_clean_html($clean_it$extraTags = '') {  
  4.     if (!is_array($extraTags)) $extraTags = array($extraTags);  
  5.     $clean_it = preg_replace('//r/'' '$clean_it);  
  6.     $clean_it = preg_replace('//t/'' '$clean_it);  
  7.     $clean_it = preg_replace('//n/'' '$clean_it);  
  8.     $clean_itnl2br($clean_it);  
  9. // update breaks with a space for text displays in all listings with descriptions  
  10.     while (strstr($clean_it'<br>'))   $clean_it = str_replace('<br>',   ' '$clean_it);  
  11.     while (strstr($clean_it'<br />')) $clean_it = str_replace('<br />'' '$clean_it);  
  12.     while (strstr($clean_it'<br/>'))  $clean_it = str_replace('<br/>',  ' '$clean_it);  
  13.     while (strstr($clean_it'<p>'))    $clean_it = str_replace('<p>',    ' '$clean_it);  
  14.     while (strstr($clean_it'</p>'))   $clean_it = str_replace('</p>',   ' '$clean_it);  
  15. // temporary fix more for reviews than anything else  
  16.     while (strstr($clean_it'<span class="smallText">')) $clean_it = str_replace('<span class="smallText">'' '$clean_it);  
  17.     while (strstr($clean_it'</span>')) $clean_it = str_replace('</span>'' '$clean_it);  
  18. // clean general and specific tags:  
  19.     $taglist = array('strong','b','u','i','em');  
  20.     $taglist = array_merge($taglist, (is_array($extraTags) ? $extraTags : array($extraTags)));  
  21.     foreach ($taglist as $tofind) {  
  22.       if ($tofind != ''$clean_it = preg_replace("/<[///!]*?" . $tofind . "[^<>]*?>/si"' '$clean_it);  
  23.     }  
  24. // remove any double-spaces created by cleanups:  
  25.     while (strstr($clean_it'  ')) $clean_it = str_replace('  '' '$clean_it);  
  26. // remove other html code to prevent problems on display of text  
  27.     $clean_it = strip_tags($clean_it);  
  28.     return $clean_it;  
  29.   }  

zen_get_module_directory()

  1.   
  2. // find module directory  
  3. // include template specific immediate /modules files  
  4. // new_products, products_new_listing, featured_products, featured_products_listing, product_listing, specials_index, upcoming,  
  5. // products_all_listing, products_discount_prices, also_purchased_products  
  6.   function zen_get_module_directory($check_file$dir_only = 'false') {  
  7.     global $template_dir;  
  8.     $zv_filename = $check_file;  
  9.     if (!strstr($zv_filename'.php')) $zv_filename .= '.php';  
  10.     if (file_exists(DIR_WS_MODULES . $template_dir . '/' . $zv_filename)) {  
  11.       $template_dir_select = $template_dir . '/';  
  12.     } else {  
  13.       $template_dir_select = '';  
  14.     }  
  15.     if ($dir_only == 'true') {  
  16.       return $template_dir_select;  
  17.     } else {  
  18.       return $template_dir_select . $zv_filename;  
  19.     }  
  20.   }  

zen_get_file_directory()

  1.   
  2. // find template or default file  
  3.   function zen_get_file_directory($check_directory$check_file$dir_only = 'false') {  
  4.     global $template_dir;  
  5.     $zv_filename = $check_file;  
  6.     if (!strstr($zv_filename'.php')) $zv_filename .= '.php';  
  7.     if (file_exists($check_directory . $template_dir . '/' . $zv_filename)) {  
  8.       $zv_directory = $check_directory . $template_dir . '/';  
  9.     } else {  
  10.       $zv_directory = $check_directory;  
  11.     }  
  12.     if ($dir_only == 'true') {  
  13.       return $zv_directory;  
  14.     } else {  
  15.       return $zv_directory . $zv_filename;  
  16.     }  
  17.   }  

zen_check_url_get_terms()

  1. // check to see if database stored GET terms are in the URL as $_GET parameters  
  2.   function zen_check_url_get_terms() {  
  3.     global $db;  
  4.     $zp_sql = "select * from " . TABLE_GET_TERMS_TO_FILTER;  
  5.     $zp_filter_terms = $db->Execute($zp_sql);  
  6.     $zp_result = false;  
  7.     while (!$zp_filter_terms->EOF) {  
  8.       if (isset($_GET[$zp_filter_terms->fields['get_term_name']]) && zen_not_null($_GET[$zp_filter_terms->fields['get_term_name']])) $zp_result = true;  
  9.       $zp_filter_terms->MoveNext();  
  10.     }  
  11.     return $zp_result;  
  12.   }  

fmod_round()

  1. // replacement for fmod to manage values < 1  
  2.   function fmod_round($x$y) {  
  3.     $x = strval($x);  
  4.     $y = strval($y);  
  5.     $zc_round = ($x*1000)/($y*1000);  
  6.     $zc_round_ceil = (int)($zc_round);  
  7.     $multiplier = $zc_round_ceil * $y;  
  8.     $results = abs(round($x - $multiplier, 6));  
  9.      return $results;  
  10.   }  

zen_truncate_paragraph()

  1.   
  2. // 返回被切割的段落  
  3.   function zen_truncate_paragraph($paragraph$size = 100, $word = ' ') {  
  4.     $zv_paragraph = "";  
  5.     $word = explode(" "$paragraph);  
  6.     $zv_total = count($word);  
  7.     if ($zv_total > $size) {  
  8.       for ($x=0; $x < $size$x++) {  
  9.         $zv_paragraph = $zv_paragraph . $word[$x] . " ";  
  10.       }  
  11.       $zv_paragraph = trim($zv_paragraph);  
  12.     } else {  
  13.       $zv_paragraph = trim($paragraph);  
  14.     }  
  15.     return $zv_paragraph;  
  16.   }  

zen_get_country_zones()

  1. /** 
  2.  * return an array with zones defined for the specified country 
  3.  */  
  4.   function zen_get_country_zones($country_id) {  
  5.     global $db;  
  6.     $zones_array = array();  
  7.     $zones = $db->Execute("select zone_id, zone_name  
  8.                            from " . TABLE_ZONES . "  
  9.                            where zone_country_id = '" . (int)$country_id . "'  
  10.                            order by zone_name");  
  11.     while (!$zones->EOF) {  
  12.       $zones_array[] = array('id' => $zones->fields['zone_id'],  
  13.                              'text' => $zones->fields['zone_name']);  
  14.       $zones->MoveNext();  
  15.     }  
  16.     return $zones_array;  
  17.   }  

zen_prepare_country_zones_pull_down()

  1. /** 
  2.  * return an array with country names and matching zones to be used in pulldown menus 
  3.  */  
  4.   function zen_prepare_country_zones_pull_down($country_id = '') {  
  5. // preset the width of the drop-down for Netscape  
  6.     $pre = '';  
  7.     if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {  
  8.       for ($i=0; $i<45; $i++) $pre .= ' ';  
  9.     }  
  10.     $zones = zen_get_country_zones($country_id);  
  11.     if (sizeof($zones) > 0) {  
  12.       $zones_select = array(array('id' => '''text' => PLEASE_SELECT));  
  13.       $zones = array_merge($zones_select$zones);  
  14.     } else {  
  15.       $zones = array(array('id' => '''text' => TYPE_BELOW));  
  16. // create dummy options for Netscape to preset the height of the drop-down  
  17.       if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {  
  18.         for ($i=0; $i<9; $i++) {  
  19.           $zones[] = array('id' => '''text' => $pre);  
  20.         }  
  21.       }  
  22.     }  
  23.     return $zones;  
  24.   }  

zen_js_zone_list()

  1. /** 
  2.  * supplies javascript to dynamically update the states/provinces list when the country is changed 
  3.  * TABLES: zones 
  4.  * 
  5.  * return string 
  6.  */  
  7.   function zen_js_zone_list($country$form$field) {  
  8.     global $db;  
  9.     $countries = $db->Execute("select distinct zone_country_id  
  10.                                from " . TABLE_ZONES . "  
  11.                                order by zone_country_id");  
  12.     $num_country = 1;  
  13.     $output_string = '';  
  14.     while (!$countries->EOF) {  
  15.       if ($num_country == 1) {  
  16.         $output_string .= '  if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "/n";  
  17.       } else {  
  18.         $output_string .= '  } else if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "/n";  
  19.       }  
  20.       $states = $db->Execute("select zone_name, zone_id  
  21.                               from " . TABLE_ZONES . "  
  22.                               where zone_country_id = '" . $countries->fields['zone_country_id'] . "'  
  23.                               order by zone_name");  
  24.       $num_state = 1;  
  25.       while (!$states->EOF) {  
  26.         if ($num_state == '1'$output_string .= '    ' . $form . '.' . $field . '.options[0] = new Option("' . PLEASE_SELECT . '", "");' . "/n";  
  27.         $output_string .= '    ' . $form . '.' . $field . '.options[' . $num_state . '] = new Option("' . $states->fields['zone_name'] . '", "' . $states->fields['zone_id'] . '");' . "/n";  
  28.         $num_state++;  
  29.         $states->MoveNext();  
  30.       }  
  31.       $num_country++;  
  32.       $countries->MoveNext();  
  33.       $output_string .= '    hideStateField(' . $form . ');' . "/n" ;  
  34.     }  
  35.     $output_string .= '  } else {' . "/n" .  
  36.                       '    ' . $form . '.' . $field . '.options[0] = new Option("' . TYPE_BELOW . '", "");' . "/n" .  
  37.                       '    showStateField(' . $form . ');' . "/n" .  
  38.                       '  }' . "/n";  
  39.     return $output_string;  
  40.   }  

zen_date_diff()

  1. /* 
  2.  * 计算两个日期之间的天数 
  3. */  
  4.   function zen_date_diff($date1$date2) {  
  5.   // $date1  今天,或者任何一天  
  6.   // $date2  需要计算的日期  
  7.     $d1 = explode("-"$date1);  
  8.     $y1 = $d1[0];  
  9.     $m1 = $d1[1];  
  10.     $d1 = $d1[2];  
  11.     $d2 = explode("-"$date2);  
  12.     $y2 = $d2[0];  
  13.     $m2 = $d2[1];  
  14.     $d2 = $d2[2];  
  15.     $date1_set = mktime(0,0,0, $m1$d1$y1);  
  16.     $date2_set = mktime(0,0,0, $m2$d2$y2);  
  17.     return(round(($date2_set-$date1_set)/(60*60*24)));  
  18.   }  

replace_accents()

  1. /** 
  2.  * strip out accented characters to reasonable approximations of english equivalents 
  3.  */  
  4.   function replace_accents($s) {  
  5.     $skipPreg = (defined('OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES') && OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES == 'TRUE') ? TRUE : FALSE;  
  6.     $s = htmlentities($s);  
  7.     if ($skipPreg == FALSE) {  
  8.       $s = preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/''$1'$s);  
  9.     }  
  10.     $s = html_entity_decode($s);  
  11.     return $s;  
  12.   }  

is__writeable()

  1. /** 
  2.  * function to override PHP's is_writable() which can occasionally be unreliable due to O/S and F/S differences 
  3.  * attempts to open the specified file for writing. Returns true if successful, false if not. 
  4.  * if a directory is specified, uses PHP's is_writable() anyway 
  5.  * 
  6.  * @var string 
  7.  * @return boolean 
  8.  */  
  9.   function is__writeable($filepath$make_unwritable = true) {  
  10.     if (is_dir($filepath)) return is_writable($filepath);  
  11.     $fp = @fopen($filepath'a');  
  12.     if ($fp) {  
  13.       @fclose($fp);  
  14.       if ($make_unwritable) set_unwritable($filepath);  
  15.       $fp = @fopen($filepath'a');  
  16.       if ($fp) {  
  17.         @fclose($fp);  
  18.         return true;  
  19.       }  
  20.     }  
  21.     return false;  
  22.   }  

set_unwritable()

  1. /** 
  2.  * 试图把指定的文件改成只读 
  3.  * 
  4.  * @参数:字符串 
  5.  * @返回值:布尔值 
  6.  */  
  7.   function set_unwritable($filepath) {  
  8.     return @chmod($filepath, 0444);  
  9.   }  

charsetConvertWinToUtf8()

  1. /** 
  2.  * convert supplied string to UTF-8, dropping any symbols which cannot be translated easily 
  3.  * 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 
  4.  * 
  5.  * @param string $string 
  6.  */  
  7.   function charsetConvertWinToUtf8($string) {  
  8.     if (function_exists('iconv')) $string = iconv("Windows-1252""ISO-8859-1//IGNORE"$string);  
  9.     $string = htmlentities($string, ENT_QUOTES, 'UTF-8');  
  10.     return $string;  
  11.   }  

charsetClean()

  1. /** 
  2.  * Convert supplied string to/from entities between charsets, to sanitize data from payment gateway 
  3.  * @param $string 
  4.  * @return string 
  5.  */  
  6.   function charsetClean($string) {  
  7.     if (CHARSET == 'UTF-8'return $string;  
  8.     if (function_exists('iconv')) $string = iconv("Windows-1252", CHARSET . "//IGNORE"$string);  
  9.     $string = htmlentities($string, ENT_QUOTES, 'UTF-8');  
  10.     $string = html_entity_decode($string, ENT_QUOTES, CHARSET);  
  11.     return $string;  
  12.   }  

调用其它的函数文件

  1. // 和价格、数量相关的函数  
  2.   require(DIR_WS_FUNCTIONS . 'functions_prices.php');  
  3. // 和税相关的函数  
  4.   require(DIR_WS_FUNCTIONS . 'functions_taxes.php');  
  5. // 和优惠券相关的函数  
  6.   require(DIR_WS_FUNCTIONS . 'functions_gvcoupons.php');  
  7. // 和商品目录、路径、下拉菜单相关的函数文件  
  8.   require(DIR_WS_FUNCTIONS . 'functions_categories.php');  
  9. // 和客户、地址相关的函数文件customers and addresses  
  10.   require(DIR_WS_FUNCTIONS . 'functions_customers.php');  
  11. // 查找信息相关函数  
  12.   require(DIR_WS_FUNCTIONS . 'functions_lookups.php');  

转至:http://blog.csdn.net/klinghr/article/details/6174734

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值