⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 general.php

📁 全新且完善的强大网上商店系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:

function tep_get_product_path($products_id) {
    global $db , $table_products , $table_products_to_categories;
		$cPath = '';
    $category_query = $db->query("select categories_id from $table_products  where products_id = '" . (int)$products_id . "' and products_status = '1' limit 1");
    if ($db->num_rows($category_query)) {
      $category = $db->fetch_array($category_query);

      $categories = array();
      tep_get_parent_categories($categories, $category['categories_id']);

      $categories = array_reverse($categories);

      $cPath = implode('_', $categories);

      if (tep_not_null($cPath)) $cPath .= '_';
      $cPath .= $category['categories_id'];
    }
    return $cPath;
}

function tep_get_uprid($prid, $params) {
    $uprid = $prid;
    if ( (is_array($params)) && (!strstr($prid, '{')) ) {
      while (list($option, $value) = each($params)) {
        $uprid = $uprid . '{' . $option . '}' . $value;
      }
    }

    return $uprid;
}

function tep_get_prid($uprid) {
    $pieces = explode('{', $uprid);
    return $pieces[0];
}

function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
    global $soobic;
		if (SEND_EMAILS != 'true') return false;
    require_once($soobic.'includes/classes/mime.php');
    require_once($soobic.'includes/classes/email.php');
		$message = new email(array('X-Mailer: Soobic! Mailer'));

    $text = strip_tags($email_text);
    if (EMAIL_USE_HTML == 'true') {
        $message->add_html($email_text, $text);
    } else {
        $message->add_text($text);
    }
    $message->build_message();
    $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
}

function tep_has_product_attributes($products_id) {
    global $db ,$table_products_attributes;
		$attributes_query = $db->query("select count(*) as count from $table_products_attributes where products_id = '" . (int)$products_id . "'");
    $attributes = $db->fetch_array($attributes_query);

    if ($attributes['count'] > 0) {
        return true;
    } else {
        return false;
    }
}

function tep_word_count($string, $needle) {
    $temp_array = split($needle, $string);
    return sizeof($temp_array);
}

function tep_count_modules($modules = '') {
    $count = 0;
    if (empty($modules)) return $count;
    $modules_array = 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;
}

function tep_count_payment_modules() {
    return tep_count_modules(MODULE_PAYMENT_INSTALLED);
}

function tep_count_shipping_modules() {
    return tep_count_modules(MODULE_SHIPPING_INSTALLED);
}

function tep_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 = tep_rand(0,9);
       } else {
          $char = chr(tep_rand(0,255));
       }
       if ($type == 'mixed') {
          if (eregi('^[a-z0-9]$', $char)) $rand_value .= $char;
       } elseif ($type == 'chars') {
          if (eregi('^[a-z]$', $char)) $rand_value .= $char;
       } elseif ($type == 'digits') {
          if (ereg('^[0-9]$', $char)) $rand_value .= $char;
       }
    }
    return $rand_value;
}

function tep_array_to_string($array, $exclude = '', $equals = '=', $separator = '&') {
    if (!is_array($exclude)) $exclude = 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;
}

function tep_not_null($value) {
    if (is_array($value)) {
      if (sizeof($value) > 0) {
        return true;
      } else {
        return false;
      }
    } else {
      if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
        return true;
      } else {
        return false;
      }
    }
}

function tep_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
    if (strpos($value, '.')) {
      $loop = true;
      while ($loop) {
        if (substr($value, -1) == '0') {
          $value = substr($value, 0, -1);
        } else {
          $loop = false;
          if (substr($value, -1) == '.') {
            $value = substr($value, 0, -1);
          }
        }
      }
    }
    if ($padding > 0) {
      if ($decimal_pos = strpos($value, '.')) {
        $decimals = strlen(substr($value, ($decimal_pos+1)));
        for ($i=$decimals; $i<$padding; $i++) {
          $value .= '0';
        }
      } else {
        $value .= '.';
        for ($i=0; $i<$padding; $i++) {
          $value .= '0';
        }
      }
    }
    return $value;
}

function tep_currency_exists($code) {
    global $db,$table_currencies;
 		$code = tep_db_prepare_input($code);
    $currency_code = $db->query("select currencies_id from $table_currencies where code = '$code'");
    if ($db->num_rows($currency_code)) {
      return $code;
    } else {
      return false;
    }
}

function tep_string_to_int($string) {
    return (int)$string;
}

function tep_parse_category_path($cPath) {
    $cPath_array = array_map('tep_string_to_int', explode('_', $cPath));
    $tmp_array = array();
    $n = sizeof($cPath_array);
    for ($i=0; $i<$n; $i++) {
      if (!in_array($cPath_array[$i], $tmp_array)) {
        $tmp_array[] = $cPath_array[$i];
      }
    }
    return $tmp_array;
}
function tep_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();
    }
}

function tep_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) {
    setcookie($name, $value, $expire, $path, (tep_not_null($domain) ? $domain : ''), $secure);
}

function tep_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;
}

function tep_count_customer_orders($id = '', $check_session = true) {
    global $customer_id,$db,$table_orders;
    if (is_numeric($id) == false) {
      if (tep_session_is_registered('customer_id')) {
        $id = $customer_id;
      } else {
        return 0;
      }
    }
    if ($check_session == true) {
      if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) {
        return 0;
      }
    }
    $orders_check_query = $db->query("select count(*) as total from $table_orders where customers_id = '" . (int)$id . "'");
    $orders_check = $db->fetch_array($orders_check_query);
    return $orders_check['total'];
}

function tep_count_customer_address_book_entries($id = '', $check_session = true) {
    global $customer_id, $db, $table_address_book;
    if (is_numeric($id) == false) {
        if (tep_session_is_registered('customer_id')) {
            $id = $customer_id;
        } else {
            return 0;
        }
    }
    if ($check_session == true) {
        if ( (tep_session_is_registered('customer_id') == false) || ($id != $customer_id) ) {
            return 0;
        }
    }
    $addresses_query = $db->query("select count(*) as total from $table_address_book where customers_id = '" . (int)$id . "'");
    $addresses = $db->fetch_array($addresses_query);
    return $addresses['total'];
}

function tep_convert_linefeeds($from, $to, $string) {
    if ((PHP_VERSION < "4.0.5") && is_array($from)) {
      return ereg_replace('(' . implode('|', $from) . ')', $to, $string);
    } else {
      return str_replace($from, $to, $string);
    }
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -