[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 functions_general.php
<?php /** * functions_general.php * General functions used throughout Zen Cart * * @package functions * @copyright Copyright 2003-2010 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: functions_general.php 16312 2010-05-22 08:13:42Z wilt $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } /** * Stop from parsing any further PHP code */ function zen_exit() { session_write_close(); exit(); }
/** * Redirect to another page or site * @param string The url to redirect to */ function zen_redirect($url, $httpResponseCode = '') { global $request_type; // Are we loading an SSL page? if ( (ENABLE_SSL == true) && ($request_type == 'SSL') ) { // yes, but a NONSSL url was supplied if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_CATALOG)) == HTTP_SERVER . DIR_WS_CATALOG) { // So, change it to SSL, based on site's configuration for SSL $url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($url, strlen(HTTP_SERVER . DIR_WS_CATALOG)); } }
// clean up URL before executing it while (strstr($url, '&&')) $url = str_replace('&&', '&', $url); while (strstr($url, '&&')) $url = str_replace('&&', '&', $url); // header locates should not have the & in the address it breaks things while (strstr($url, '&')) $url = str_replace('&', '&', $url);
/** * Parse the data used in the html tags to ensure the tags will not break. * Basically just an extension to the php strstr function * @param string The string to be parsed * @param string The needle to find */ // Parse the data used in the html tags to ensure the tags will not break function zen_parse_input_field_data($data, $parse) { return strtr(trim($data), $parse); }
/** * Returns a string with conversions for security. * @param string The string to be parsed * @param string contains a string to be translated, otherwise just quote is translated * @param boolean Do we run htmlspecialchars over the string */ 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); } } }
/** * Returns a string with conversions for security. * * Simply calls the zen_ouput_string function * with parameters that run htmlspecialchars over the string * and converts quotes to html entities * * @param string The string to be parsed */ function zen_output_string_protected($string) { return zen_output_string($string, false, true); }
/** * Returns a string with conversions for security. * * @param string The string to be parsed */
/** * Break a word in a string if it is longer than a specified length ($len) * * @param string The string to be broken up * @param int The maximum length allowed * @param string The character to use at the end of the broken line */ 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; }
/** * Return all HTTP GET variables, except those passed as a parameter * * The return is a urlencoded string * * @param mixed either a single or array of parameter names to be excluded from output */ // Return all HTTP GET variables, except those passed as a parameter function zen_get_all_get_params($exclude_array = '', $search_engine_safe = true) {
if (!is_array($exclude_array)) $exclude_array = array();
//// // Returns the clients browser function zen_browser_detect($component) { global $HTTP_USER_AGENT;
return stristr($HTTP_USER_AGENT, $component); }
//// // Wrapper function for round() function zen_round($value, $precision) { $value = round($value *pow(10,$precision),0); $value = $value/pow(10,$precision); return $value; }
//// // default filler is a 0 or pass filler to be used function zen_row_number_format($number, $filler='0') { if ( ($number < 10) && (substr($number, 0, 1) != '0') ) $number = $filler . $number;
return $number; }
// Output a raw date string in the selected locale date format // $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS function zen_date_long($raw_date) { if ( ($raw_date == '0001-01-01 00:00:00') || ($raw_date == '') ) return false;
//// // Output a raw date string in the selected locale date format // $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS // NOTE: Includes a workaround for dates before 01/01/1970 that fail on windows servers function zen_date_short($raw_date) { if ( ($raw_date == '0001-01-01 00:00:00') || empty($raw_date) ) return false;
// error on 1969 only allows for leap year if ($year != 1969 && @date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { return date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, $year)); } else { return preg_replace('/2037$/', $year, date(DATE_FORMAT, mktime($hour, $minute, $second, $month, $day, 2037))); } }
//// // Parse search string into indivual objects function zen_parse_search_string($search_str = '', &$objects) { // BOM by zen-cart.cn $search_str = trim(GBcase($search_str,"lower")); // EOM by zen-cart.cn
// Break up $search_str on whitespace; quoted string will be reconstructed later $pieces = preg_split('/[[:space:]]+/', $search_str); $objects = array(); $tmpstring = ''; $flag = '';
for ($j=0; $j<count($post_objects); $j++) { $objects[] = $post_objects[$j]; } } else { /* This means that the $piece is either the beginning or the end of a string. So, we'll slurp up the $pieces and stick them together until we get to the end of the string or run out of pieces. */
// Add this word to the $tmpstring, starting the $tmpstring $tmpstring = trim(preg_replace('/"/', ' ', $pieces[$k]));
// Check for one possible exception to the rule. That there is a single quoted word. if (substr($pieces[$k], -1 ) == '"') { // Turn the flag off for future iterations $flag = 'off';
$objects[] = trim($pieces[$k]);
for ($j=0; $j<count($post_objects); $j++) { $objects[] = $post_objects[$j]; }
unset($tmpstring);
// Stop looking for the end of the string and move onto the next word. continue; }
// Otherwise, turn on the flag to indicate no quotes have been found attached to this word in the string. $flag = 'on';
// Move on to the next word $k++;
// Keep reading until the end of the string as long as the $flag is on
// If the word doesn't end in double quotes, append it to the $tmpstring. if (substr($pieces[$k], -1) != '"') { // Tack this word onto the current string entity $tmpstring .= ' ' . $pieces[$k];
// Move on to the next word $k++; continue; } else { /* If the $piece ends in double quotes, strip the double quotes, tack the $piece onto the tail of the string, push the $tmpstring onto the $haves, kill the $tmpstring, turn the $flag "off", and return. */ $tmpstring .= ' ' . trim(preg_replace('/"/', ' ', $pieces[$k]));
// Push the $tmpstring onto the array of stuff to search for $objects[] = trim($tmpstring);
for ($j=0; $j<count($post_objects); $j++) { $objects[] = $post_objects[$j]; }
unset($tmpstring);
// Turn off the flag to exit the loop $flag = 'off'; } } } }
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; }
//// // Check if year is a 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; }
//// // Return table heading with sorting capabilities function zen_create_sort_heading($sortby, $colnum, $heading) { global $PHP_SELF;
//// // Return a product ID from a product ID with attributes function zen_get_prid($uprid) { $pieces = explode(':', $uprid);
return $pieces[0]; }
//// // Get the number of times a word/character is present in a string function zen_word_count($string, $needle) { $temp_array = preg_split('/'.$needle.'/', $string);
return sizeof($temp_array); }
//// function zen_count_modules($modules = '') { $count = 0;
//// // Checks to see if the currency code exists as a currency // TABLES: 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";
// nl2br() prior PHP 4.2.0 did not convert linefeeds on all OSs (it only converted \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); } }
//// 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; // if category is restricted(deny) and product in category 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); // echo '#'.$product_id . '#' . $allow_for_category; // echo '#'.$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; //should never get here } 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'; } } 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'; } }
//// function zen_db_input($string) { return addslashes($string); }
//// function zen_db_output($string) { return htmlspecialchars($string); }
// function to return field type // uses $tbl = table name, $fld = field name
function zen_field_type($tbl, $fld) { global $db; $rs = $db->MetaColumns($tbl); // BOM by zen-cart.cn $type = $rs[GBcase($fld,"upper")]->type; // EOM by zen-cart.cn return $type; }
// function to return field length // uses $tbl = table name, $fld = field name function zen_field_length($tbl, $fld) { global $db; $rs = $db->MetaColumns($tbl); $length = $rs[strtoupper($fld)]->max_length; return $length; }
//// // return the size and maxlength settings in the form size="blah" maxlength="blah" based on maximum size being 70 // uses $tbl = table name, $fld = field name // example: 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; }
//// // Set back button 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; }
//// // Return a random row from a database query 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; }
//// // Truncate a string function zen_trunc_string($str = "", $len = 150, $more = 'true') { if ($str == "") return $str; if (is_array($str)) return $str; $str = trim($str); // if it's les than the size given, then return it if (strlen($str) <= $len) return $str; // else get that size of text $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; }
//// // set current box 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; }
//// // Switch buy now button based on call for price sold out etc. function zen_get_buy_now_button($product_id, $link, $additional_link = false) { global $db;
// show case only superceeds all other settings if (STORE_STATUS != '0') { return '<a href="' . zen_href_link(FILENAME_CONTACT_US) . '">' . TEXT_SHOWCASE_ONLY . '</a>'; }
// 0 = normal shopping // 1 = Login to shop // 2 = Can browse but no prices // verify display of prices switch (true) { case (CUSTOMERS_APPROVAL == '1' and $_SESSION['customer_id'] == ''): // customer must be logged in to browse $login_for_price = '<a 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 == '') { // show room only return TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE; } else { // customer may browse but no prices $login_for_price = '<a href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL') . '">' . TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE . '</a>'; } return $login_for_price; break; // show room only 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'] == ''): // customer must be logged in to browse $login_for_price = TEXT_AUTHORIZATION_PENDING_BUTTON_REPLACE; return $login_for_price; break; case ((CUSTOMERS_APPROVAL_AUTHORIZATION == '3') and $_SESSION['customer_id'] == ''): // customer must be logged in and approved to add to cart $login_for_price = '<a 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'): // customer must be logged in to browse $login_for_price = TEXT_AUTHORIZATION_PENDING_BUTTON_REPLACE; return $login_for_price; break; default: // proceed normally break; }
$button_check = $db->Execute("select product_is_call, products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$product_id . "'"); switch (true) { // cannot be added to the cart 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) . '">' . 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; } }
//// // enable shipping function zen_get_shipping_enabled($shipping_module) { global $PHP_SELF, $cart, $order;
// for admin always true if installed if (strstr($PHP_SELF, FILENAME_MODULES)) { return true; }
//// //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; }
//// // remove common HTML from text for display as paragraph function zen_clean_html($clean_it, $extraTags = '') { if (!is_array($extraTags)) $extraTags = array($extraTags);
// 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; }
//// // 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';
// 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; }
/** * 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; }
/** * 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; }
/** * 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"; }
/** * 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; }
/** * 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; } /** * attempts to make the specified file read-only * * @var string * @return boolean */ function set_unwritable($filepath) { return @chmod($filepath, 0444); } /** * 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; }
/** * 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; }
///////////////////////////////////////////// //// // call additional function files // prices and quantities require(DIR_WS_FUNCTIONS . 'functions_prices.php'); // taxes require(DIR_WS_FUNCTIONS . 'functions_taxes.php'); // gv and coupons require(DIR_WS_FUNCTIONS . 'functions_gvcoupons.php'); // categories, paths, pulldowns require(DIR_WS_FUNCTIONS . 'functions_categories.php'); // customers and addresses require(DIR_WS_FUNCTIONS . 'functions_customers.php'); // lookup information require(DIR_WS_FUNCTIONS . 'functions_lookups.php'); //// /////////////////////////////////////////////