ecmall mysql.php_ecmall框架核心ecmall.php文件详解

//转发至对应的Action

//空白方法,未添加功能.

$app->destruct();

}

}

class Object

{

var $_errors = array();

var $_errnum = 0;

function __construct()

{

$this->Object();

}

function Object()

{

#TODO

}

function _error($msg, $obj = '')

{

if(is_array($msg))

{

$this->_errors =

array_merge($this->_errors, $msg);

$this->_errnum += count($msg);

}

else

{

$this->_errors[] = compact('msg', 'obj');

$this->_errnum++;

}

}

function has_error()

{

return $this->_errnum;

}

function get_error()

{

return $this->_errors;

}

}

class Lang

{

function &get($key = '')

{

$vkey = $key ? strtokey("{$key}", '$GLOBALS[\'__ECLANG__\']') :

'$GLOBALS[\'__ECLANG__\']';

$tmp = eval_r('if(isset(' . $vkey . '))return ' . $vkey . ';else{

return $key; }');

return $tmp;

}

function load($lang_file)

{

static $loaded = array();

$old_lang = $new_lang = array();

$file_md5 = md5($lang_file);

if (!isset($loaded[$file_md5]))

{

$new_lang = Lang::fetch($lang_file);

$loaded[$file_md5] = $lang_file;

}

else

{

return;

}

$old_lang =& $GLOBALS['__ECLANG__'];

if (is_array($old_lang))

{

$new_lang = array_merge($old_lang, $new_lang);

}

$GLOBALS['__ECLANG__'] = $new_lang;

}

function fetch($lang_file)

{

return include($lang_file);

}

}

function lang_file($file)

{

return ROOT_PATH . '/languages/' . LANG . '/' . $file .

'.lang.php';

}

class Conf

{

function load($conf)

{

$old_conf = isset($GLOBALS['ECMALL_CONFIG']) ?

$GLOBALS['ECMALL_CONFIG'] : array();

if (is_string($conf))

{

$conf = include($conf);

}

if (is_array($old_conf))

{

$GLOBALS['ECMALL_CONFIG'] = array_merge($old_conf, $conf);

}

else

{

$GLOBALS['ECMALL_CONFIG'] = $conf;

}

}

function get($key = '')

{

$vkey = $key ? strtokey("{$key}", '$GLOBALS[\'ECMALL_CONFIG\']') :

'$GLOBALS[\'ECMALL_CONFIG\']';

return eval_r('if(isset(' . $vkey . '))return ' . $vkey . ';else{

return null; }');

}

}

function &v($is_new = false, $engine =

'default')

{

include_once(ROOT_PATH . '/eccore/view/template.php');

if ($is_new)

{

return new ecsTemplate();

}

else

{

static $v = null;

if ($v === null)

{

switch ($engine)

{

case 'default':

$v = new ecsTemplate();

break;

}

}

return $v;

}

}

function &m($model_name, $params = array(), $is_new

= false)

{

static $models = array();

$model_hash = md5($model_name . var_export($params, true));

if ($is_new || !isset($models[$model_hash]))

{

$model_file = ROOT_PATH . '/includes/models/' . $model_name .

'.model.php';

if (!is_file($model_file))

{

return false;

}

include_once($model_file);

$model_name = ucfirst($model_name) . 'Model';

if ($is_new)

{

return new $model_name($params, db());

}

$models[$model_hash] = new $model_name($params, db());

}

return $models[$model_hash];

}

function &bm($model_name, $params = array(),

$is_new = false)

{

static $models = array();

$model_hash = md5($model_name . var_export($params, true));

if ($is_new || !isset($models[$model_hash]))

{

$model_file = ROOT_PATH . '/includes/models/' . $model_name .

'.model.php';

if (!is_file($model_file))

{

return false;

}

include_once($model_file);

$model_name = ucfirst($model_name) . 'BModel';

if ($is_new)

{

return new $model_name($params, db());

}

$models[$model_hash] = new $model_name($params, db());

}

return $models[$model_hash];

}

function c(&$app)

{

$GLOBALS['ECMALL_APP'] =& $app;

}

function &cc()

{

return $GLOBALS['ECMALL_APP'];

}

function import()

{

$c = func_get_args();

if (empty($c))

{

return;

}

array_walk($c, create_function('$item, $key',

'include_once(ROOT_PATH . \'/includes/libraries/\' . $item .

\'.php\');'));

}

function strtokey($str, $owner = '')

{

if (!$str)

{

return '';

}

if ($owner)

{

return $owner . '[\'' . str_replace('.', '\'][\'', $str) .

'\']';

}

else

{

$parts = explode('.', $str);

$owner = '$' . $parts[0];

unset($parts[0]);

return strtokey(implode('.', $parts), $owner);

}

}

function trace($var)

{

static $i = 0;

echo $i, '.', var_dump($var), '

/>';

$i++;

}

function dump($arr)

{

$args = func_get_args();

call_user_func_array('rdump', $args);

}

function rdump($arr)

{

echo '

';

array_walk(func_get_args(),

create_function('&$item, $key',

'print_r($item);'));

echo '

';

exit();

}

function vdump($arr)

{

echo '

';

array_walk(func_get_args(),

create_function('&$item, $key',

'var_dump($item);'));

echo '

';

exit();

}

function &db()

{

include_once(ROOT_PATH . '/eccore/model/mysql.php');

static $db = null;

if ($db === null)

{

$cfg = parse_url(DB_CONFIG);

if ($cfg['scheme'] == 'mysql')

{

if (empty($cfg['pass']))

{

$cfg['pass'] = '';

}

else

{

$cfg['pass'] = urldecode($cfg['pass']);

}

$cfg ['user'] = urldecode($cfg['user']);

if (empty($cfg['path']))

{

trigger_error('Invalid database name.', E_USER_ERROR);

}

else

{

$cfg['path'] = str_replace('/', '', $cfg['path']);

}

$charset = (CHARSET == 'utf-8') ? 'utf8' : CHARSET;

$db = new cls_mysql();

$db->cache_dir = ROOT_PATH.

'/temp/query_caches/';

$db->connect($cfg['host']. ':' .$cfg['port'],

$cfg['user'],

$cfg['pass'], $cfg['path'], $charset);

}

else

{

trigger_error('Unkown database type.', E_USER_ERROR);

}

}

return $db;

}

function get_domain()

{

$protocol = (isset($_SERVER['HTTPS'])

&& (strtolower($_SERVER['HTTPS'])

!= 'off')) ? 'https://' : 'http://';

if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))

{

$host = $_SERVER['HTTP_X_FORWARDED_HOST'];

}

elseif (isset($_SERVER['HTTP_HOST']))

{

$host = $_SERVER['HTTP_HOST'];

}

else

{

if (isset($_SERVER['SERVER_PORT']))

{

$port = ':' . $_SERVER['SERVER_PORT'];

if ((':80' == $port && 'http://' ==

$protocol) || (':443' == $port &&

'https://' == $protocol))

{

$port = '';

}

}

else

{

$port = '';

}

if (isset($_SERVER['SERVER_NAME']))

{

$host = $_SERVER['SERVER_NAME'] . $port;

}

elseif (isset($_SERVER['SERVER_ADDR']))

{

$host = $_SERVER['SERVER_ADDR'] . $port;

}

}

return $protocol . $host;

}

function site_url()

{

return get_domain() . substr(PHP_SELF, 0, strrpos(PHP_SELF,

'/'));

}

function sub_str($string, $length = 0, $append = true)

{

if(strlen($string) <= $length) {

return $string;

}

$string = str_replace(array('&', '"',

'<', '>'),

array('&', '"', '

'>'), $string);

$strcut = '';

if(strtolower(CHARSET) == 'utf-8') {

$n = $tn = $noc = 0;

while($n < strlen($string)) {

$t = ord($string[$n]);

if($t == 9 || $t == 10 || (32 <= $t

&& $t <= 126))

{

$tn = 1; $n++; $noc++;

} elseif(194 <= $t

&& $t <= 223)

{

$tn = 2; $n += 2; $noc += 2;

} elseif(224 <= $t

&& $t < 239) {

$tn = 3; $n += 3; $noc += 2;

} elseif(240 <= $t

&& $t <= 247)

{

$tn = 4; $n += 4; $noc += 2;

} elseif(248 <= $t

&& $t <= 251)

{

$tn = 5; $n += 5; $noc += 2;

} elseif($t == 252 || $t == 253) {

$tn = 6; $n += 6; $noc += 2;

} else {

$n++;

}

if($noc >= $length) {

break;

}

}

if($noc > $length) {

$n -= $tn;

}

$strcut = substr($string, 0, $n);

} else {

for($i = 0; $i < $length; $i++) {

$strcut .= ord($string[$i]) > 127 ?

$string[$i].$string[++$i] : $string[$i];

}

}

$strcut = str_replace(array('&', '"',

''), array('&',

'"', '<', '>'),

$strcut);

if ($append && $string !=

$strcut)

{

$strcut .= '...';

}

return $strcut;

}

function real_ip()

{

static $realip = NULL;

if ($realip !== NULL)

{

return $realip;

}

if (isset($_SERVER))

{

if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))

{

$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);

foreach ($arr AS $ip)

{

$ip = trim($ip);

if ($ip != 'unknown')

{

$realip = $ip;

break;

}

}

}

elseif (isset($_SERVER['HTTP_CLIENT_IP']))

{

$realip = $_SERVER['HTTP_CLIENT_IP'];

}

else

{

if (isset($_SERVER['REMOTE_ADDR']))

{

$realip = $_SERVER['REMOTE_ADDR'];

}

else

{

$realip = '0.0.0.0';

}

}

}

else

{

if (getenv('HTTP_X_FORWARDED_FOR'))

{

$realip = getenv('HTTP_X_FORWARDED_FOR');

}

elseif (getenv('HTTP_CLIENT_IP'))

{

$realip = getenv('HTTP_CLIENT_IP');

}

else

{

$realip = getenv('REMOTE_ADDR');

}

}

preg_match("/[\d\.]{7,15}/", $realip, $onlineip);

$realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';

return $realip;

}

function is_email($user_email)

{

$chars =

"/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,5}\$/i";

if (strpos($user_email, '@') !== false

&& strpos($user_email, '.') !==

false)

{

if (preg_match($chars, $user_email))

{

return true;

}

else

{

return false;

}

}

else

{

return false;

}

}

function is_time($time)

{

$pattern =

'/[\d]{4}-[\d]{1,2}-[\d]{1,2}\s[\d]{1,2}:[\d]{1,2}:[\d]{1,2}/';

return preg_match($pattern, $time);

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值