Skip to content

Commit 37d5ec9

Browse files
committed
Merge pull request #6 from liu21st/master
merge
2 parents 31b3606 + cc5a1b5 commit 37d5ec9

File tree

11 files changed

+800
-819
lines changed

11 files changed

+800
-819
lines changed

Extend/Behavior/CheckLangBehavior.class.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,23 @@ private function checkLanguage() {
6565
define('LANG_SET',strtolower($langSet));
6666

6767
$group = '';
68-
$lang_path = (defined('GROUP_NAME') && C('APP_GROUP_MODE')==1) ? BASE_LIB_PATH.'Lang/'.LANG_SET.'/' : LANG_PATH.LANG_SET.'/';
69-
// 读取项目或者独立分组公共语言包
70-
if (is_file($lang_path.'common.php'))
71-
L(include $lang_path.'common.php');
72-
// 普通分组公共语言包
73-
if (defined('GROUP_NAME') && C('APP_GROUP_MODE')==0){
74-
if (is_file($lang_path.GROUP_NAME.'.php'))
75-
L(include $lang_path.GROUP_NAME.'.php');
76-
$group = GROUP_NAME.C('TMPL_FILE_DEPR');
68+
$path = (defined('GROUP_NAME') && C('APP_GROUP_MODE')==1) ? BASE_LIB_PATH.'Lang/'.LANG_SET.'/' : LANG_PATH.LANG_SET.'/';
69+
// 读取项目公共语言包
70+
if(is_file(LANG_PATH.LANG_SET.'/common.php'))
71+
L(include LANG_PATH.LANG_SET.'/common.php');
72+
// 读取分组公共语言包
73+
if(defined('GROUP_NAME')){
74+
if(C('APP_GROUP_MODE')==1){ // 独立分组
75+
$file = $path.'common.php';
76+
}else{ // 普通分组
77+
$file = $path.GROUP_NAME.'.php';
78+
$group = GROUP_NAME.C('TMPL_FILE_DEPR');
79+
}
80+
if(is_file($file))
81+
L(include $file);
7782
}
7883
// 读取当前模块语言包
79-
if (is_file($lang_path.$group.strtolower(MODULE_NAME).'.php'))
80-
L(include $lang_path.$group.strtolower(MODULE_NAME).'.php');
84+
if (is_file($path.$group.strtolower(MODULE_NAME).'.php'))
85+
L(include $path.$group.strtolower(MODULE_NAME).'.php');
8186
}
8287
}

Extend/Engine/Sae/Common/common.php

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,85 @@
1616
* @author liu21st <[email protected]>
1717
*/
1818

19+
/**
20+
* 获取输入参数 支持过滤和默认值
21+
* 使用方法:
22+
* <code>
23+
* I('id',0); 获取id参数 自动判断get或者post
24+
* I('post.name','','htmlspecialchars'); 获取$_POST['name']
25+
* I('get.'); 获取$_GET
26+
* </code>
27+
* @param string $name 变量的名称 支持指定类型
28+
* @param mixed $default 不存在的时候默认值
29+
* @param mixed $filter 参数过滤方法
30+
* @return mixed
31+
*/
32+
function I($name,$default='',$filter=null) {
33+
if(strpos($name,'.')) { // 指定参数来源
34+
list($method,$name) = explode('.',$name);
35+
}else{ // 默认为自动判断
36+
$method = 'param';
37+
}
38+
switch(strtolower($method)) {
39+
case 'get' : $input =& $_GET;break;
40+
case 'post' : $input =& $_POST;break;
41+
case 'put' : parse_str(file_get_contents('php://input'), $input);break;
42+
case 'param' :
43+
switch($_SERVER['REQUEST_METHOD']) {
44+
case 'POST':
45+
$input = $_POST;
46+
break;
47+
case 'PUT':
48+
parse_str(file_get_contents('php://input'), $input);
49+
break;
50+
default:
51+
$input = $_GET;
52+
}
53+
if(C('VAR_URL_PARAMS') && isset($_GET[C('VAR_URL_PARAMS')])){
54+
$input = array_merge($input,$_GET[C('VAR_URL_PARAMS')]);
55+
}
56+
break;
57+
case 'request' : $input =& $_REQUEST; break;
58+
case 'session' : $input =& $_SESSION; break;
59+
case 'cookie' : $input =& $_COOKIE; break;
60+
case 'server' : $input =& $_SERVER; break;
61+
case 'globals' : $input =& $GLOBALS; break;
62+
default:
63+
return NULL;
64+
}
65+
// 全局过滤
66+
// array_walk_recursive($input,'filter_exp');
67+
if(C('VAR_FILTERS')) {
68+
$_filters = explode(',',C('VAR_FILTERS'));
69+
foreach($_filters as $_filter){
70+
// 全局参数过滤
71+
array_walk_recursive($input,$_filter);
72+
}
73+
}
74+
if(empty($name)) { // 获取全部变量
75+
$data = $input;
76+
}elseif(isset($input[$name])) { // 取值操作
77+
$data = $input[$name];
78+
$filters = isset($filter)?$filter:C('DEFAULT_FILTER');
79+
if($filters) {
80+
$filters = explode(',',$filters);
81+
foreach($filters as $filter){
82+
if(function_exists($filter)) {
83+
$data = is_array($data)?array_map($filter,$data):$filter($data); // 参数过滤
84+
}else{
85+
$data = filter_var($data,is_int($filter)?$filter:filter_id($filter));
86+
if(false === $data) {
87+
return isset($default)?$default:NULL;
88+
}
89+
}
90+
}
91+
}
92+
}else{ // 变量默认值
93+
$data = isset($default)?$default:NULL;
94+
}
95+
return $data;
96+
}
97+
1998
/**
2099
* 记录和统计时间(微秒)和内存使用情况
21100
* 使用方法:
@@ -157,7 +236,7 @@ function file_exists_case($filename) {
157236
* @param string $class 类库命名空间字符串
158237
* @param string $baseUrl 起始路径
159238
* @param string $ext 导入的文件扩展名
160-
* @return boolen
239+
* @return boolean
161240
*/
162241
function import($class, $baseUrl = '', $ext='.class.php') {
163242
static $_file = array();
@@ -274,10 +353,16 @@ function D($name='',$layer='') {
274353
$name = C('DEFAULT_APP').'/'.$layer.'/'.$name;
275354
}
276355
if(isset($_model[$name])) return $_model[$name];
277-
import($name.$layer);
356+
$path = explode('/',$name);
357+
if(count($path)>3 && 1 == C('APP_GROUP_MODE')) { // 独立分组
358+
$baseUrl = $path[0]== '@' ? dirname(BASE_LIB_PATH) : APP_PATH.'../'.$path[0].'/'.C('APP_GROUP_PATH').'/';
359+
import($path[2].'/'.$path[1].'/'.$path[3].$layer,$baseUrl);
360+
}else{
361+
import($name.$layer);
362+
}
278363
$class = basename($name.$layer);
279364
if(class_exists($class)) {
280-
$model = new $class();
365+
$model = new $class(basename($name));
281366
}else {
282367
$model = new Model(basename($name));
283368
}
@@ -309,6 +394,7 @@ function M($name='', $tablePrefix='',$connection='') {
309394
* A函数用于实例化Action 格式:[项目://][分组/]模块
310395
* @param string $name Action资源地址
311396
* @param string $layer 控制层名称
397+
* @param boolean $common 是否公共目录
312398
* @return Action|false
313399
*/
314400
function A($name,$layer='',$common=false) {
@@ -320,15 +406,19 @@ function A($name,$layer='',$common=false) {
320406
$name = '@/'.$layer.'/'.$name;
321407
}
322408
if(isset($_action[$name])) return $_action[$name];
323-
if($common){ // 独立分组情况下 加载公共目录类库
409+
$path = explode('/',$name);
410+
if(count($path)>3 && 1 == C('APP_GROUP_MODE')) { // 独立分组
411+
$baseUrl = $path[0]== '@' ? dirname(BASE_LIB_PATH) : APP_PATH.'../'.$path[0].'/'.C('APP_GROUP_PATH').'/';
412+
import($path[2].'/'.$path[1].'/'.$path[3].$layer,$baseUrl);
413+
}elseif($common) { // 加载公共类库目录
324414
import(str_replace('@/','',$name).$layer,LIB_PATH);
325415
}else{
326-
import($name.$layer);
327-
}
416+
import($name.$layer);
417+
}
328418
$class = basename($name.$layer);
329419
if(class_exists($class,false)) {
330-
$action = new $class();
331-
$_action[$name] = $action;
420+
$action = new $class();
421+
$_action[$name] = $action;
332422
return $action;
333423
}else {
334424
return false;
@@ -505,8 +595,6 @@ function B($name, &$params=NULL) {
505595
}
506596
}
507597

508-
509-
510598
/**
511599
* 去除代码中的空白和注释
512600
* @param string $content 代码内容

Extend/Engine/Sae/Common/functions.php

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,10 @@ function halt($error) {
2929
$trace = debug_backtrace();
3030
$e['message'] = $error;
3131
$e['file'] = $trace[0]['file'];
32-
$e['class'] = isset($trace[0]['class'])?$trace[0]['class']:'';
33-
$e['function'] = isset($trace[0]['function'])?$trace[0]['function']:'';
3432
$e['line'] = $trace[0]['line'];
35-
$traceInfo = '';
36-
$time = date('y-m-d H:i:m');
37-
foreach ($trace as $t) {
38-
$traceInfo .= '[' . $time . '] ' . $t['file'] . ' (' . $t['line'] . ') ';
39-
$traceInfo .= $t['class'] . $t['type'] . $t['function'] . '(';
40-
$traceInfo .= implode(', ', $t['args']);
41-
$traceInfo .=')<br/>';
42-
}
43-
$e['trace'] = $traceInfo;
33+
ob_start();
34+
debug_print_backtrace();
35+
$e['trace'] = ob_get_clean();
4436
} else {
4537
$e = $error;
4638
}
@@ -70,7 +62,7 @@ function halt($error) {
7062
*/
7163
function throw_exception($msg, $type='ThinkException', $code=0) {
7264
if (class_exists($type, false))
73-
throw new $type($msg, $code, true);
65+
throw new $type($msg, $code);
7466
else
7567
halt($msg); // 异常类型不存在则输出错误信息字串
7668
}
@@ -265,7 +257,7 @@ function U($url='',$vars='',$suffix=true,$redirect=false,$domain=false) {
265257
}
266258
if(!empty($vars)) { // 添加参数
267259
foreach ($vars as $var => $val){
268-
if('' !== trim($val)) $url .= $depr . $var . $depr . $val;
260+
if('' !== trim($val)) $url .= $depr . $var . $depr . urlencode($val);
269261
}
270262
}
271263
if($suffix) {
@@ -295,11 +287,13 @@ function U($url='',$vars='',$suffix=true,$redirect=false,$domain=false) {
295287
* @param string $name Widget名称
296288
* @param array $data 传人的参数
297289
* @param boolean $return 是否返回内容
290+
* @param string $path Widget所在路径
298291
* @return void
299292
*/
300293
function W($name, $data=array(), $return=false) {
301294
$class = $name . 'Widget';
302-
require_cache(BASE_LIB_PATH . 'Widget/' . $class . '.class.php');
295+
$path = empty($path) ? BASE_LIB_PATH : $path;
296+
require_cache($path . 'Widget/' . $class . '.class.php');
303297
if (!class_exists($class))
304298
throw_exception(L('_CLASS_NOT_EXIST_') . ':' . $class);
305299
$widget = Think::instance($class);
@@ -365,13 +359,10 @@ function redirect($url, $time=0, $msg='') {
365359
}
366360
}
367361

368-
369362
/**
370-
* 全局缓存设置和读取
363+
* 缓存管理
371364
* @param string $name 缓存名称
372365
* @param mixed $value 缓存值
373-
* @param integer $expire 缓存有效期(秒)
374-
* @param string $type 缓存类型
375366
* @param array $options 缓存参数
376367
* @return mixed
377368
*/
@@ -394,17 +385,19 @@ function S($name,$value='',$options=null) {
394385
}elseif(is_null($value)) { // 删除缓存
395386
return $cache->rm($name);
396387
}else { // 缓存数据
397-
$expire = is_numeric($options)?$options:NULL;
388+
if(is_array($options)) {
389+
$expire = isset($options['expire'])?$options['expire']:NULL;
390+
}else{
391+
$expire = is_numeric($options)?$options:NULL;
392+
}
398393
return $cache->set($name, $value, $expire);
399394
}
400395
}
401-
402396
// S方法的别名 已经废除 不再建议使用
403397
function cache($name,$value='',$options=null){
404398
return S($name,$value,$options);
405399
}
406400

407-
408401
/**
409402
* 快速文件数据读取和保存 针对简单类型数据 字符串、数组
410403
* @param string $name 缓存名称
@@ -495,31 +488,47 @@ function to_guid_string($mix) {
495488
/**
496489
* XML编码
497490
* @param mixed $data 数据
498-
* @param string $encoding 数据编码
499491
* @param string $root 根节点名
492+
* @param string $item 数字索引的子节点名
493+
* @param string $attr 根节点属性
494+
* @param string $id 数字索引子节点key转换的属性名
495+
* @param string $encoding 数据编码
500496
* @return string
501497
*/
502-
function xml_encode($data, $encoding='utf-8', $root='think') {
503-
$xml = '<?xml version="1.0" encoding="' . $encoding . '"?>';
504-
$xml .= '<' . $root . '>';
505-
$xml .= data_to_xml($data);
506-
$xml .= '</' . $root . '>';
498+
function xml_encode($data, $root='think', $item='item', $attr='', $id='id', $encoding='utf-8') {
499+
if(is_array($attr)){
500+
$_attr = array();
501+
foreach ($attr as $key => $value) {
502+
$_attr[] = "{$key}=\"{$value}\"";
503+
}
504+
$attr = implode(' ', $_attr);
505+
}
506+
$attr = trim($attr);
507+
$attr = empty($attr) ? '' : " {$attr}";
508+
$xml = "<?xml version=\"1.0\" encoding=\"{$encoding}\"?>";
509+
$xml .= "<{$root}{$attr}>";
510+
$xml .= data_to_xml($data, $item, $id);
511+
$xml .= "</{$root}>";
507512
return $xml;
508513
}
509514

510515
/**
511516
* 数据XML编码
512-
* @param mixed $data 数据
517+
* @param mixed $data 数据
518+
* @param string $item 数字索引时的节点名称
519+
* @param string $id 数字索引key转换为的属性名
513520
* @return string
514521
*/
515-
function data_to_xml($data) {
516-
$xml = '';
522+
function data_to_xml($data, $item='item', $id='id') {
523+
$xml = $attr = '';
517524
foreach ($data as $key => $val) {
518-
is_numeric($key) && $key = "item id=\"$key\"";
519-
$xml .= "<$key>";
520-
$xml .= ( is_array($val) || is_object($val)) ? data_to_xml($val) : $val;
521-
list($key, ) = explode(' ', $key);
522-
$xml .= "</$key>";
525+
if(is_numeric($key)){
526+
$id && $attr = " {$id}=\"{$key}\"";
527+
$key = $item;
528+
}
529+
$xml .= "<{$key}{$attr}>";
530+
$xml .= (is_array($val) || is_object($val)) ? data_to_xml($val, $item, $id) : $val;
531+
$xml .= "</{$key}>";
523532
}
524533
return $xml;
525534
}
@@ -711,7 +720,7 @@ function load_ext_file() {
711720
* @return mixed
712721
*/
713722
function get_client_ip($type = 0) {
714-
$type = $type ? 1 : 0;
723+
$type = $type ? 1 : 0;
715724
static $ip = NULL;
716725
if ($ip !== NULL) return $ip[$type];
717726
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
@@ -762,4 +771,4 @@ function filter_exp(&$value){
762771
if (in_array(strtolower($value),array('exp','or'))){
763772
$value .= ' ';
764773
}
765-
}
774+
}

Extend/Engine/Sae/Common/runtime.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if(version_compare(PHP_VERSION,'5.2.0','<')) die('require PHP > 5.2.0 !');
2020

2121
// 版本信息
22-
define('THINK_VERSION', '3.1.2');
22+
define('THINK_VERSION', '3.1.3');
2323

2424
// 系统信息
2525
if(version_compare(PHP_VERSION,'5.4.0','<')) {
@@ -101,7 +101,7 @@ function load_runtime_file() {
101101
if(is_file($file)) require_cache($file);
102102
}
103103
//[sae] 加载系统类库别名定义
104-
//alias_import(include SAE_PATH.'Conf/alias.php');
104+
alias_import(include SAE_PATH.'Conf/alias.php');
105105
//[sae]在sae下不对目录结构进行检查
106106
if(APP_DEBUG){
107107
//[sae] 调试模式切换删除编译缓存
@@ -139,8 +139,8 @@ function build_runtime_cache($append='') {
139139
// 系统行为扩展文件统一编译
140140
$content .= build_tags_cache();
141141
//[sae] 编译SAE的alias
142-
//$alias = include SAE_PATH.'Conf/alias.php';
143-
//$content .= 'alias_import('.var_export($alias,true).');';
142+
$alias = include SAE_PATH.'Conf/alias.php';
143+
$content .= 'alias_import('.var_export($alias,true).');';
144144
// 编译框架默认语言包和配置参数
145145
$content .= $append."\nL(".var_export(L(),true).");C(".var_export(C(),true).');G(\'loadTime\');Think::Start();';
146146
//[sae] 生成编译缓存文件
@@ -167,4 +167,4 @@ function build_tags_cache() {
167167
// 记录加载文件时间
168168
G('loadTime');
169169
// 执行入口
170-
Think::Start();
170+
Think::Start();

0 commit comments

Comments
 (0)