Example #1
0
 public function _empty()
 {
     $this->redirect('index/index');
     exit;
     send_http_status(404);
     $this->display(TMPL_PATH . '404.html');
 }
Example #2
0
 /**
  * 禁止路径
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2012-07-10 15:40:01
  * @lastmodify      2013-01-22 10:51:46 by mrmsl
  *
  * @param string $path 待检测路径
  *
  * @return void 无返回值
  */
 private function _denyDirectory($path)
 {
     if (false !== strpos($path, '..')) {
         $this->_model->addLog(L('LIST_DIRECTORY_FORBIDDEN') . PACKER_JS_PATH . $path, LOG_TYPE_INVALID_PARAM);
         send_http_status(HTTP_STATUS_SERVER_ERROR);
         $this->_ajaxReturn(L('LIST_DIRECTORY_FORBIDDEN') . PACKER_JS_PATH . $path);
     }
 }
 /**
  * 禁止路径
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2012-07-10 15:40:01
  *
  * @param string $path 待检测路径
  *
  * @return void 无返回值
  */
 private function _denyDirectory($path)
 {
     if (false !== strpos($path, '..')) {
         $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('LIST_DIRECTORY_FORBIDDEN') . PACKER_JS_PATH . $path;
         trigger_error($log, E_USER_ERROR);
         send_http_status(HTTP_STATUS_SERVER_ERROR);
         $this->_ajaxReturn(true, L('LIST_DIRECTORY_FORBIDDEN') . PACKER_JS_PATH . $path);
     }
 }
Example #4
0
 protected function _404($url = '')
 {
     if ($url) {
         redirect($url);
     } else {
         send_http_status(404);
         $this->display(TMPL_PATH . '404.html');
         exit;
     }
 }
Example #5
0
 protected function _productNotExist($url = '')
 {
     if ($url) {
         redirect($url);
     } else {
         send_http_status(404);
         $this->display('Public/productNotExist');
         exit;
     }
 }
Example #6
0
 /**
  * 空操作,用于输出404页面
  */
 public function _empty()
 {
     //针对后台ajax请求特殊处理
     if (!IS_AJAX) {
         send_http_status(404);
     }
     if (IS_AJAX && IS_POST) {
         $data = array('info' => '请求地址不存在或已经删除', 'status' => 0, 'total' => 0, 'rows' => array());
         $this->ajaxReturn($data);
     } else {
         $this->display('Common:404');
     }
 }
 public function _initialize()
 {
     parent::_initialize();
     $this->Config = F("Member_Config");
     if (!$this->Config) {
         $setting = M("Module")->where(array("module" => "Member"))->getField("setting");
         if (!$setting) {
             //获取不到配置,记录错误日志
             $msg = "获取不到相关配置,QQ互联无法进行!";
             if (APP_DEBUG) {
                 // 模块不存在 抛出异常
                 throw_exception($msg);
             } else {
                 if (C('LOG_EXCEPTION_RECORD')) {
                     Log::write($msg);
                 }
                 send_http_status(404);
                 exit;
             }
         }
         $this->Config = unserialize($setting);
         F("Member_Config", $this->Config);
     }
     $this->qq_akey = $this->Config['qq_akey'];
     $this->qq_skey = $this->Config['qq_skey'];
     if (!$this->qq_akey || !$this->qq_skey) {
         $msg = "没有进行QQ互联的相关配置,请配置后在继续使用!";
         if (APP_DEBUG) {
             // 模块不存在 抛出异常
             throw_exception($msg);
         } else {
             if (C('LOG_EXCEPTION_RECORD')) {
                 Log::write($msg);
             }
             send_http_status(404);
             exit;
         }
     }
     //跳转时间
     $this->assign("waitSecond", 2000);
 }
 /**
  * 禁止非法访问
  */
 private function prohibitAccess()
 {
     if (!in_array(MODULE_NAME, C('MODULE_ALLOW_LIST'))) {
         if (APP_DEBUG) {
             E('该模块没有安装,无法进行访问!');
         } else {
             send_http_status(400);
             exit;
         }
     }
     $config = cache('Config');
     if (MODULE_NAME == 'Admin' && isModuleInstall('Domains') && $config['domainaccess']) {
         $Module_Domains_list = cache('Module_Domains_list');
         $http_host = strtolower($_SERVER['HTTP_HOST']);
         $domain = explode('|', $Module_Domains_list['Admin']);
         if ($Module_Domains_list['Admin'] && !in_array($http_host, $domain)) {
             send_http_status(404);
             exit;
         }
     }
 }
 /**
  * URL映射到控制器
  * @access public
  * @return void
  */
 public static function dispatch()
 {
     $varPath = C('VAR_PATHINFO');
     $varAddon = C('VAR_ADDON');
     $varModule = C('VAR_MODULE');
     $varController = C('VAR_CONTROLLER');
     $varAction = C('VAR_ACTION');
     $urlCase = C('URL_CASE_INSENSITIVE');
     if (isset($_GET[$varPath])) {
         // 判断URL里面是否有兼容模式参数
         $_SERVER['PATH_INFO'] = $_GET[$varPath];
         unset($_GET[$varPath]);
     } elseif (IS_CLI) {
         // CLI模式下 index.php module/controller/action/params/...
         $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
     }
     // 开启子域名部署
     if (C('APP_SUB_DOMAIN_DEPLOY')) {
         $rules = C('APP_SUB_DOMAIN_RULES');
         if (isset($rules[$_SERVER['HTTP_HOST']])) {
             // 完整域名或者IP配置
             define('APP_DOMAIN', $_SERVER['HTTP_HOST']);
             // 当前完整域名
             $rule = $rules[APP_DOMAIN];
         } else {
             if (strpos(C('APP_DOMAIN_SUFFIX'), '.')) {
                 // com.cn net.cn
                 $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3);
             } else {
                 $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2);
             }
             if (!empty($domain)) {
                 $subDomain = implode('.', $domain);
                 define('SUB_DOMAIN', $subDomain);
                 // 当前完整子域名
                 $domain2 = array_pop($domain);
                 // 二级域名
                 if ($domain) {
                     // 存在三级域名
                     $domain3 = array_pop($domain);
                 }
                 if (isset($rules[$subDomain])) {
                     // 子域名
                     $rule = $rules[$subDomain];
                 } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) {
                     // 泛三级域名
                     $rule = $rules['*.' . $domain2];
                     $panDomain = $domain3;
                 } elseif (isset($rules['*']) && !empty($domain2) && 'www' != $domain2) {
                     // 泛二级域名
                     $rule = $rules['*'];
                     $panDomain = $domain2;
                 }
             }
         }
         if (!empty($rule)) {
             // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b');
             if (is_array($rule)) {
                 list($rule, $vars) = $rule;
             }
             $array = explode('/', $rule);
             // 模块绑定
             define('BIND_MODULE', array_shift($array));
             // 控制器绑定
             if (!empty($array)) {
                 $controller = array_shift($array);
                 if ($controller) {
                     define('BIND_CONTROLLER', $controller);
                 }
             }
             if (isset($vars)) {
                 // 传入参数
                 parse_str($vars, $parms);
                 if (isset($panDomain)) {
                     $pos = array_search('*', $parms);
                     if (false !== $pos) {
                         // 泛域名作为参数
                         $parms[$pos] = $panDomain;
                     }
                 }
                 $_GET = array_merge($_GET, $parms);
             }
         }
     }
     // 分析PATHINFO信息
     if (!isset($_SERVER['PATH_INFO'])) {
         $types = explode(',', C('URL_PATHINFO_FETCH'));
         foreach ($types as $type) {
             if (0 === strpos($type, ':')) {
                 // 支持函数判断
                 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1));
                 break;
             } elseif (!empty($_SERVER[$type])) {
                 $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                 break;
             }
         }
     }
     $depr = C('URL_PATHINFO_DEPR');
     define('MODULE_PATHINFO_DEPR', $depr);
     if (empty($_SERVER['PATH_INFO'])) {
         $_SERVER['PATH_INFO'] = '';
         define('__INFO__', '');
         define('__EXT__', '');
     } else {
         define('__INFO__', trim($_SERVER['PATH_INFO'], '/'));
         // URL后缀
         define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
         $_SERVER['PATH_INFO'] = __INFO__;
         if (!defined('BIND_MODULE') && (!C('URL_ROUTER_ON') || !Route::check())) {
             if (__INFO__ && C('MULTI_MODULE')) {
                 // 获取模块名
                 $paths = explode($depr, __INFO__, 2);
                 $allowList = C('MODULE_ALLOW_LIST');
                 // 允许的模块列表
                 $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]);
                 if (empty($allowList) || is_array($allowList) && in_array_case($module, $allowList)) {
                     $_GET[$varModule] = $module;
                     $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : '';
                 }
             }
         }
     }
     // URL常量
     define('__SELF__', strip_tags($_SERVER[C('URL_REQUEST_URI')]));
     // 获取模块名称
     define('MODULE_NAME', defined('BIND_MODULE') ? BIND_MODULE : self::getModule($varModule));
     // 检测模块是否存在
     if (MODULE_NAME && (defined('BIND_MODULE') || !in_array_case(MODULE_NAME, C('MODULE_DENY_LIST'))) && is_dir(APP_PATH . MODULE_NAME)) {
         // 定义当前模块路径
         define('MODULE_PATH', APP_PATH . MODULE_NAME . '/');
         // 定义当前模块的模版缓存路径
         C('CACHE_PATH', CACHE_PATH . MODULE_NAME . '/');
         // 定义当前模块的日志目录
         C('LOG_PATH', realpath(LOG_PATH) . '/' . MODULE_NAME . '/');
         // 模块检测
         Hook::listen('module_check');
         // 加载模块配置文件
         if (is_file(MODULE_PATH . 'Conf/config' . CONF_EXT)) {
             C(load_config(MODULE_PATH . 'Conf/config' . CONF_EXT));
         }
         // 加载应用模式对应的配置文件
         if ('common' != APP_MODE && is_file(MODULE_PATH . 'Conf/config_' . APP_MODE . CONF_EXT)) {
             C(load_config(MODULE_PATH . 'Conf/config_' . APP_MODE . CONF_EXT));
         }
         // 当前应用状态对应的配置文件
         if (APP_STATUS && is_file(MODULE_PATH . 'Conf/' . APP_STATUS . CONF_EXT)) {
             C(load_config(MODULE_PATH . 'Conf/' . APP_STATUS . CONF_EXT));
         }
         // 加载模块别名定义
         if (is_file(MODULE_PATH . 'Conf/alias.php')) {
             Think::addMap(include MODULE_PATH . 'Conf/alias.php');
         }
         // 加载模块tags文件定义
         if (is_file(MODULE_PATH . 'Conf/tags.php')) {
             Hook::import(include MODULE_PATH . 'Conf/tags.php');
         }
         // 加载模块函数文件
         if (is_file(MODULE_PATH . 'Common/function.php')) {
             include MODULE_PATH . 'Common/function.php';
         }
         // 加载模块的扩展配置文件
         load_ext_file(MODULE_PATH);
     } else {
         E(L('_MODULE_NOT_EXIST_') . ':' . MODULE_NAME);
     }
     if (!defined('__APP__')) {
         $urlMode = C('URL_MODEL');
         if ($urlMode == URL_COMPAT) {
             // 兼容模式判断
             define('PHP_FILE', _PHP_FILE_ . '?' . $varPath . '=');
         } elseif ($urlMode == URL_REWRITE) {
             $url = dirname(_PHP_FILE_);
             if ($url == '/' || $url == '\\') {
                 $url = '';
             }
             define('PHP_FILE', $url);
         } else {
             define('PHP_FILE', _PHP_FILE_);
         }
         // 当前应用地址
         define('__APP__', strip_tags(PHP_FILE));
     }
     // 模块URL地址
     $moduleName = defined('MODULE_ALIAS') ? MODULE_ALIAS : MODULE_NAME;
     define('__MODULE__', defined('BIND_MODULE') || !C('MULTI_MODULE') ? __APP__ : __APP__ . '/' . ($urlCase ? strtolower($moduleName) : $moduleName));
     if ('' != $_SERVER['PATH_INFO'] && (!C('URL_ROUTER_ON') || !Route::check())) {
         // 检测路由规则 如果没有则按默认规则调度URL
         Hook::listen('path_info');
         // 检查禁止访问的URL后缀
         if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) {
             send_http_status(404);
             exit;
         }
         // 去除URL后缀
         $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX') ? '/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']);
         $depr = C('URL_PATHINFO_DEPR');
         $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr));
         if (!defined('BIND_CONTROLLER')) {
             // 获取控制器
             if (C('CONTROLLER_LEVEL') > 1) {
                 // 控制器层次
                 $_GET[$varController] = implode('/', array_slice($paths, 0, C('CONTROLLER_LEVEL')));
                 $paths = array_slice($paths, C('CONTROLLER_LEVEL'));
             } else {
                 $_GET[$varController] = array_shift($paths);
             }
         }
         // 获取操作
         if (!defined('BIND_ACTION')) {
             $_GET[$varAction] = array_shift($paths);
         }
         // 解析剩余的URL参数
         $var = array();
         if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) {
             // URL参数按顺序绑定变量
             $var = $paths;
         } else {
             preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) {
                 $var[$match[1]] = strip_tags($match[2]);
             }, implode('/', $paths));
         }
         $_GET = array_merge($var, $_GET);
     }
     // 获取控制器的命名空间(路径)
     define('CONTROLLER_PATH', self::getSpace($varAddon, $urlCase));
     // 获取控制器和操作名
     define('CONTROLLER_NAME', defined('BIND_CONTROLLER') ? BIND_CONTROLLER : self::getController($varController, $urlCase));
     define('ACTION_NAME', defined('BIND_ACTION') ? BIND_ACTION : self::getAction($varAction, $urlCase));
     // 当前控制器的UR地址
     $controllerName = defined('CONTROLLER_ALIAS') ? CONTROLLER_ALIAS : CONTROLLER_NAME;
     define('__CONTROLLER__', __MODULE__ . $depr . (defined('BIND_CONTROLLER') ? '' : ($urlCase ? parse_name($controllerName) : $controllerName)));
     // 当前操作的URL地址
     define('__ACTION__', __CONTROLLER__ . $depr . (defined('ACTION_ALIAS') ? ACTION_ALIAS : ACTION_NAME));
     //保证$_REQUEST正常取值
     $_REQUEST = array_merge($_POST, $_GET, $_COOKIE);
     // -- 加了$_COOKIE.  保证哦..
 }
Example #10
0
        case "404_1":
            send_http_status(404);
            echo '{"request_id":100, "error_code":10000 , "error_msg":"what is that??"}';
            break;
        case "404_2":
            send_http_status(404);
            echo 'what is this??';
            break;
        case "200_1":
            send_http_status(200);
            echo '{"request_id":100, "response_params":[1,2,3,4]}';
            break;
        case "200_2":
            send_http_status(200);
            echo 'what is this??';
        case "200_3":
            send_http_status(200);
            echo '{"request_id":100, "error_code":4567}';
            break;
        case 'checkSign':
            send_http_status(200);
            $rs = array('request_id' => 100, 'response_params' => $_REQUEST);
            echo json_encode($rs);
            break;
        default:
            send_http_status(204);
    }
} else {
    $log->log(print_r($_REQUEST, true));
    echo json_encode($_REQUEST);
}
Example #11
0
 /**
 +----------------------------------------------------------
 * 执行应用程序
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 public static function exec()
 {
     // 安全检测df
     if (!preg_match('/^[A-Za-z_0-9]+$/', MODULE_NAME)) {
         $module = false;
     } else {
         //创建Action控制器实例
         $group = defined('GROUP_NAME') ? GROUP_NAME . '/' : '';
         $module = A($group . MODULE_NAME);
     }
     if (!$module) {
         if (function_exists('__hack_module')) {
             // hack 方式定义扩展模块 返回Action对象
             $module = __hack_module();
             if (!is_object($module)) {
                 // 不再继续执行 直接返回
                 return;
             }
         } else {
             // 是否定义Empty模块
             $module = A('Empty');
             if (!$module) {
                 $msg = L('_MODULE_NOT_EXIST_') . MODULE_NAME;
                 if (APP_DEBUG) {
                     // 模块不存在 抛出异常
                     throw_exception($msg);
                 } else {
                     if (C('LOG_EXCEPTION_RECORD')) {
                         Log::write($msg);
                     }
                     send_http_status(404);
                     exit;
                 }
             }
         }
     }
     //获取当前操作名
     $action = ACTION_NAME;
     // 获取操作方法名标签
     tag('action_name', $action);
     if (method_exists($module, '_before_' . $action)) {
         // 执行前置操作
         call_user_func(array(&$module, '_before_' . $action));
     }
     //执行当前操作
     call_user_func(array(&$module, $action));
     if (method_exists($module, '_after_' . $action)) {
         //  执行后缀操作
         call_user_func(array(&$module, '_after_' . $action));
     }
     return;
 }
Example #12
0
/**
 * YourPHP 函数类
 */
function _404()
{
    send_http_status(404);
    exit;
}
Example #13
0
 /**
  * URL映射到控制器
  * @access public
  * @return void
  */
 public static function dispatch()
 {
     $varPath = C('VAR_PATHINFO');
     $varModule = C('VAR_MODULE');
     $varController = C('VAR_CONTROLLER');
     $varAction = C('VAR_ACTION');
     if (isset($_GET[$varPath])) {
         // 判断URL里面是否有兼容模式参数
         $_SERVER['PATH_INFO'] = $_GET[$varPath];
         unset($_GET[$varPath]);
     } elseif (IS_CLI) {
         // CLI模式下 index.php module/controller/action/params/...
         $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
     }
     // 开启子域名部署
     if (C('APP_SUB_DOMAIN_DEPLOY')) {
         $rules = C('APP_SUB_DOMAIN_RULES');
         if (isset($rules[$_SERVER['HTTP_HOST']])) {
             // 完整域名或者IP配置
             define('APP_DOMAIN', $_SERVER['HTTP_HOST']);
             // 当前完整域名
             $rule = $rules[APP_DOMAIN];
         } else {
             if (strpos(C('APP_DOMAIN_SUFFIX'), '.')) {
                 // com.cn net.cn
                 $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3);
             } else {
                 $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2);
             }
             if (!empty($domain)) {
                 $subDomain = implode('.', $domain);
                 define('SUB_DOMAIN', $subDomain);
                 // 当前完整子域名
                 $domain2 = array_pop($domain);
                 // 二级域名
                 if ($domain) {
                     // 存在三级域名
                     $domain3 = array_pop($domain);
                 }
                 if (isset($rules[$subDomain])) {
                     // 子域名
                     $rule = $rules[$subDomain];
                 } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) {
                     // 泛三级域名
                     $rule = $rules['*.' . $domain2];
                     $panDomain = $domain3;
                 } elseif (isset($rules['*']) && !empty($domain2) && 'www' != $domain2) {
                     // 泛二级域名
                     $rule = $rules['*'];
                     $panDomain = $domain2;
                 }
             }
         }
         if (!empty($rule)) {
             // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b');
             if (is_array($rule)) {
                 list($rule, $vars) = $rule;
             }
             $array = explode('/', $rule);
             // 模块绑定
             $_GET[$varModule] = array_shift($array);
             define('BIND_MODULE', $_GET[$varModule]);
             $domainModule = true;
             // 控制器绑定
             if (!empty($array)) {
                 $controller = array_shift($array);
                 if ($controller) {
                     $_GET[$varController] = $controller;
                     $domainController = true;
                 }
             }
             if (isset($vars)) {
                 // 传入参数
                 parse_str($vars, $parms);
                 if (isset($panDomain)) {
                     $pos = array_search('*', $parms);
                     if (false !== $pos) {
                         // 泛域名作为参数
                         $parms[$pos] = $panDomain;
                     }
                 }
                 $_GET = array_merge($_GET, $parms);
             }
         }
     } elseif (isset($_GET[$varModule])) {
         // 绑定模块
         define('BIND_MODULE', $_GET[$varModule]);
     }
     // 分析PATHINFO信息
     if (!isset($_SERVER['PATH_INFO'])) {
         $types = explode(',', C('URL_PATHINFO_FETCH'));
         foreach ($types as $type) {
             if (0 === strpos($type, ':')) {
                 // 支持函数判断
                 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1));
                 break;
             } elseif (!empty($_SERVER[$type])) {
                 $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                 break;
             }
         }
     }
     if (empty($_SERVER['PATH_INFO'])) {
         $_SERVER['PATH_INFO'] = '';
     }
     $depr = C('URL_PATHINFO_DEPR');
     define('MODULE_PATHINFO_DEPR', $depr);
     define('__INFO__', trim($_SERVER['PATH_INFO'], '/'));
     // URL后缀
     define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
     if (__INFO__ && C('MULTI_MODULE') && !isset($_GET[$varModule])) {
         // 获取模块
         $paths = explode($depr, __INFO__, 2);
         $allowList = C('MODULE_ALLOW_LIST');
         $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]);
         if (empty($allowList) || is_array($allowList) && in_array_case($module, $allowList)) {
             $_GET[$varModule] = $module;
             $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : '';
         } else {
             $_SERVER['PATH_INFO'] = __INFO__;
         }
     } else {
         $_SERVER['PATH_INFO'] = __INFO__;
     }
     // 获取模块名称
     define('MODULE_NAME', self::getModule($varModule));
     // 检测模块是否存在
     if (MODULE_NAME && (!in_array_case(MODULE_NAME, C('MODULE_DENY_LIST')) || $domainModule) && is_dir(APP_PATH . MODULE_NAME)) {
         // 定义当前模块路径
         define('MODULE_PATH', APP_PATH . MODULE_NAME . '/');
         // 加载模块配置文件
         if (is_file(MODULE_PATH . 'Conf/config.php')) {
             C(include MODULE_PATH . 'Conf/config.php');
         }
         /**加载模板公共配置文件
          * 2015-5-14 13:43
          * 增加模板配置文件加载 start
          * @author 郑钟良<*****@*****.**>
          */
         if (is_file(OS_THEME_PATH . 'config.php')) {
             $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
             C(include OS_THEME_PATH . 'config.php');
             $NEW_TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
             $NEW_TMPL_PARSE_STRING = array_merge($NEW_TMPL_PARSE_STRING, $TMPL_PARSE_STRING);
             C('TMPL_PARSE_STRING', $NEW_TMPL_PARSE_STRING);
         }
         /**
          * 2015-5-14 13:43
          * 增加模板配置文件加载 end
          * @author 郑钟良<*****@*****.**>
          */
         // 加载模块别名定义
         if (is_file(MODULE_PATH . 'Conf/alias.php')) {
             Think::addMap(include MODULE_PATH . 'Conf/alias.php');
         }
         // 加载模块函数文件
         if (is_file(MODULE_PATH . 'Common/function.php')) {
             include MODULE_PATH . 'Common/function.php';
         }
     } else {
         E(L('_MODULE_NOT_EXIST_') . ':' . MODULE_NAME, 815);
     }
     if ('' != $_SERVER['PATH_INFO']) {
         // 检查禁止访问的URL后缀
         if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) {
             send_http_status(404);
             exit;
         }
         if (C('URL_HTML_SUFFIX')) {
             $_SERVER['PATH_INFO'] = preg_replace('/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i', '', $_SERVER['PATH_INFO']);
         } else {
             $_SERVER['PATH_INFO'] = preg_replace('/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']);
         }
         $depr = C('URL_PATHINFO_DEPR');
         $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr));
         if (!isset($_GET[$varController])) {
             // 获取控制器
             $_GET[$varController] = array_shift($paths);
         }
         // 获取操作
         $_GET[$varAction] = array_shift($paths);
         // 解析剩余的URL参数
         $var = array();
         if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) {
             // URL参数按顺序绑定变量
             $var = $paths;
         } else {
             preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) {
                 $var[$match[1]] = strip_tags($match[2]);
             }, implode('/', $paths));
         }
         $_GET = array_merge($var, $_GET);
     }
     define('CONTROLLER_NAME', self::getController($varController));
     define('ACTION_NAME', self::getAction($varAction));
     //保证$_REQUEST正常取值
     $_REQUEST = array_merge($_POST, $_GET);
 }
Example #14
0
 /**
  * 404
  */
 public function not_found()
 {
     send_http_status(404);
     $this->__view("home/404.php");
 }
Example #15
0
 public function _empty()
 {
     send_http_status(404);
     $this->display(TMPL_PATH . '404.html');
 }
 public function _404()
 {
     send_http_status(404);
     $this->display(T('Common@Base/404'));
 }
Example #17
0
 /**
  * 获取文件列表
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-06-27 15:14:17
  *
  * @param string $node 节点路径
  *
  * @return array 文件列表
  */
 public function listAction()
 {
     $path = Filter::string('path', 'get');
     //路径
     if ($path) {
         $this->_denyDirectory($path);
         $path = trim($path, '/');
     } else {
         $path = new_date('Y/md/');
     }
     $log_path = LOG_PATH . $path;
     if (!is_dir($log_path)) {
         //路径不存在
         send_http_status(HTTP_STATUS_SERVER_ERROR);
         $this->_model->addLog(L('path') . LOG_PATH . $path . L('NOT_EXIST'), LOG_TYPE_INVALID_PARAM);
         $this->_ajaxReturn(false, L('path') . $path . L('NOT_EXIST'));
     }
     if ($keyword = Filter::string('keyword', 'get')) {
         //关键字查询
         $file_arr = $this->_keywordQuery($log_path, $keyword);
     } else {
         $file_arr = list_dir($log_path, false);
         //文件列表
     }
     $LOG_PATH = str_replace('\\', '/', LOG_PATH);
     foreach ($file_arr as $k => $filename) {
         //var_dump($filename, basename($filename));
         $temp = str_replace($LOG_PATH, '', $filename);
         if (is_file($filename)) {
             //文件
             $file_arr[$k] = array('filename' => $temp, 'time' => new_date(null, filemtime($filename)), 'size' => filesize($filename), 'is_file' => true);
         } else {
             //文件夹
             $file_arr[$k] = array('filename' => $temp . '/', 'time' => '--', 'size' => '--');
         }
     }
     usort($file_arr, array($this, '_cmp'));
     //按时间倒序
     $this->_ajaxReturn(true, '', $file_arr, count($file_arr));
 }
Example #18
0
/**
 * 404处理 
 * 调试模式会抛异常 
 * 部署模式下面传入url参数可以指定跳转页面,否则发送404信息
 * @param string $msg 提示信息
 * @param string $url 跳转URL地址
 * @return void
 */
function _404($msg = '', $url = '')
{
    APP_DEBUG && throw_exception($msg);
    if ($msg && C('LOG_EXCEPTION_RECORD')) {
        Log::write($msg);
    }
    if (empty($url) && C('URL_404_REDIRECT')) {
        $url = C('URL_404_REDIRECT');
    }
    if ($url) {
        redirect($url);
    } else {
        send_http_status(404);
        exit;
    }
}
 public function run(&$params)
 {
     //当前访问模块状态,默认false
     $status = false;
     //已安装模块缓存
     $App = F("App");
     //当前域名
     $http_host = strtolower($_SERVER['HTTP_HOST']);
     //域名绑定模块缓存
     $Module_Domains_list = F("Module_Domains_list");
     //网站配置缓存
     $Config = F("Config");
     //后台模块比较特殊,可以指定域名访问,其他模块不需要经过此步骤
     if ('Admin' == GROUP_NAME && $App['Domains']) {
         if ((int) $Config['domainaccess']) {
             $domain = $Module_Domains_list["Admin"];
             $domain = explode("|", $domain);
             if ($Module_Domains_list["Admin"] && $http_host != $domain[0]) {
                 //后台不是用指定域名访问,直接404!
                 send_http_status(404);
                 exit;
             }
         }
     }
     //        //如果模块有绑定域名,将以绑定域名的形式进行访问。post提交 除外
     //        if ($App['Domains'] && !IS_POST) {
     //            //获取当前模块的域名绑定信息
     //            $domain = $Module_Domains_list[GROUP_NAME];
     //            //存在表示该模块有域名绑定
     //            if ($domain) {
     //                //由于支持多域名绑定,以“|”分割成数组
     //                $domain = explode("|", $domain);
     //                //检查当前访问的域名是否在绑定域名数组中,不在,404
     //                if ( !in_array($http_host,$domain) ) {
     //                    send_http_status(404);
     //                    exit;
     //                    //发送301状态
     //                    send_http_status(301);
     //                    //进行URL重组
     //                    $url = GROUP_NAME . "/" . MODULE_NAME . "/" . ACTION_NAME . "@" . $domain[0];
     //                    if (in_array(C('URL_MODEL'), array(1,2,3))) {
     //                        unset($_GET['_URL_']);
     //                    }
     //                    //重定位
     //                    header('Location: ' . U($url, $_GET));
     //                    exit;
     //                }
     //            }
     //        }
     //判断当前访问的模块是否在已安装模块列表中
     if ($App) {
         if (!in_array(GROUP_NAME, $App)) {
             $status = false;
         } else {
             $status = true;
         }
     } else {
         $disabled = M("Module")->where(array("disabled", "module" => GROUP_NAME))->getField("disabled");
         if (!$disabled) {
             $status = false;
         } else {
             $status = true;
         }
         //生成缓存
         D("Module")->module_cache();
     }
     if (false === $status) {
         $msg = L('_MODULE_NOT_EXIST_') . MODULE_NAME . ",该模块未进行安装!";
         if (APP_DEBUG) {
             // 模块不存在 抛出异常
             throw_exception($msg);
         } else {
             if (C('LOG_RECORD')) {
                 Log::write($msg . "URL:" . get_url());
             }
             send_http_status(404);
             exit;
         }
     }
 }
Example #20
0
<?php $GLOBALS['_beginTime'] = microtime(TRUE); defined('PIN_VERSION') or define('PIN_VERSION','3.0'); defined('__ROOT__') or define('__ROOT__','.'); defined('__APP__') or define('__APP__','.'); defined('APP_DEBUG') or define('APP_DEBUG',0); defined('PIN_RELEASE') or define('PIN_RELEASE','20121127'); defined('APP_NAME') or define('APP_NAME','app'); defined('APP_PATH') or define('APP_PATH','./app/'); defined('PIN_DATA_PATH') or define('PIN_DATA_PATH','./data/'); defined('EXTEND_PATH') or define('EXTEND_PATH','./app/Extend/'); defined('CONF_PATH') or define('CONF_PATH','./data/config/'); defined('RUNTIME_PATH') or define('RUNTIME_PATH','./data/runtime/'); defined('HTML_PATH') or define('HTML_PATH','./data/html/'); defined('MEMORY_LIMIT_ON') or define('MEMORY_LIMIT_ON',true); defined('RUNTIME_FILE') or define('RUNTIME_FILE','./data/runtime/~runtime.php'); defined('THINK_PATH') or define('THINK_PATH','D:\\saivi4.0\\sc\\_core/'); defined('THINK_VERSION') or define('THINK_VERSION','3.1'); defined('MAGIC_QUOTES_GPC') or define('MAGIC_QUOTES_GPC',false); defined('IS_CGI') or define('IS_CGI',0); defined('IS_WIN') or define('IS_WIN',1); defined('IS_CLI') or define('IS_CLI',0); defined('_PHP_FILE_') or define('_PHP_FILE_','/sc/index.php'); defined('URL_COMMON') or define('URL_COMMON',0); defined('URL_PATHINFO') or define('URL_PATHINFO',1); defined('URL_REWRITE') or define('URL_REWRITE',2); defined('URL_COMPAT') or define('URL_COMPAT',3); defined('CORE_PATH') or define('CORE_PATH','D:\\saivi4.0\\sc\\_core/Lib/'); defined('MODE_PATH') or define('MODE_PATH','./app/Extend/Mode/'); defined('ENGINE_PATH') or define('ENGINE_PATH','./app/Extend/Engine/'); defined('VENDOR_PATH') or define('VENDOR_PATH','./app/Extend/Vendor/'); defined('LIBRARY_PATH') or define('LIBRARY_PATH','./app/Extend/Library/'); defined('COMMON_PATH') or define('COMMON_PATH','./app/Common/'); defined('LIB_PATH') or define('LIB_PATH','./app/Lib/'); defined('LANG_PATH') or define('LANG_PATH','./app/Lang/'); defined('TMPL_PATH') or define('TMPL_PATH','./app/Tpl/'); defined('LOG_PATH') or define('LOG_PATH','./data/runtime/Logs/'); defined('TEMP_PATH') or define('TEMP_PATH','./data/runtime/Temp/'); defined('DATA_PATH') or define('DATA_PATH','./data/runtime/Data/'); defined('CACHE_PATH') or define('CACHE_PATH','./data/runtime/Cache/'); set_include_path(get_include_path() . PATH_SEPARATOR . VENDOR_PATH); function G($start,$end='',$dec=4) { static $_info = array(); static $_mem = array(); if(is_float($end)) { $_info[$start] = $end; }elseif(!empty($end)){ if(!isset($_info[$end])) $_info[$end] = microtime(TRUE); if(MEMORY_LIMIT_ON && $dec=='m'){ if(!isset($_mem[$end])) $_mem[$end] = memory_get_usage(); return number_format(($_mem[$end]-$_mem[$start])/1024); }else{ return number_format(($_info[$end]-$_info[$start]),$dec); } }else{ $_info[$start] = microtime(TRUE); if(MEMORY_LIMIT_ON) $_mem[$start] = memory_get_usage(); } } function N($key, $step=0) { static $_num = array(); if (!isset($_num[$key])) { $_num[$key] = 0; } if (empty($step)) return $_num[$key]; else $_num[$key] = $_num[$key] + (int) $step; } function parse_name($name, $type=0) { if ($type) { return ucfirst(preg_replace("/_([a-zA-Z])/e", "strtoupper('\\1')", $name)); } else { return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); } } function require_cache($filename) { static $_importFiles = array(); if (!isset($_importFiles[$filename])) { if (file_exists_case($filename)) { require $filename; $_importFiles[$filename] = true; } else { $_importFiles[$filename] = false; } } return $_importFiles[$filename]; } function file_exists_case($filename) { if (is_file($filename)) { if (IS_WIN && C('APP_FILE_CASE')) { if (basename(realpath($filename)) != basename($filename)) return false; } return true; } return false; } function import($class, $baseUrl = '', $ext='.class.php') { static $_file = array(); $class = str_replace(array('.', '#'), array('/', '.'), $class); if ('' === $baseUrl && false === strpos($class, '/')) { return alias_import($class); } if (isset($_file[$class . $baseUrl])) return true; else $_file[$class . $baseUrl] = true; $class_strut = explode('/', $class); if (empty($baseUrl)) { if ('@' == $class_strut[0] || APP_NAME == $class_strut[0]) { $baseUrl = dirname(LIB_PATH); $class = substr_replace($class, basename(LIB_PATH).'/', 0, strlen($class_strut[0]) + 1); }elseif ('think' == strtolower($class_strut[0])){ $baseUrl = CORE_PATH; $class = substr($class,6); }elseif (in_array(strtolower($class_strut[0]), array('org', 'com'))) { $baseUrl = LIBRARY_PATH; }else { $class = substr_replace($class, '', 0, strlen($class_strut[0]) + 1); $baseUrl = APP_PATH . '../' . $class_strut[0] . '/'.basename(LIB_PATH).'/'; } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; $classfile = $baseUrl . $class . $ext; if (!class_exists(basename($class),false)) { return require_cache($classfile); } } function load($name, $baseUrl='', $ext='.php') { $name = str_replace(array('.', '#'), array('/', '.'), $name); if (empty($baseUrl)) { if (0 === strpos($name, '@/')) { $baseUrl = COMMON_PATH; $name = substr($name, 2); } else { $baseUrl = EXTEND_PATH . 'Function/'; } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; require_cache($baseUrl . $name . $ext); } function vendor($class, $baseUrl = '', $ext='.php') { if (empty($baseUrl)) $baseUrl = VENDOR_PATH; return import($class, $baseUrl, $ext); } function alias_import($alias, $classfile='') { static $_alias = array(); if (is_string($alias)) { if(isset($_alias[$alias])) { return require_cache($_alias[$alias]); }elseif ('' !== $classfile) { $_alias[$alias] = $classfile; return; } }elseif (is_array($alias)) { $_alias = array_merge($_alias,$alias); return; } return false; } function D($name='',$layer='') { if(empty($name)) return new Model; static $_model = array(); $layer = $layer?$layer:C('DEFAULT_M_LAYER'); if(strpos($name,'://')) { $name = str_replace('://','/'.$layer.'/',$name); }else{ $name = C('DEFAULT_APP').'/'.$layer.'/'.$name; } if(isset($_model[$name])) return $_model[$name]; import($name.$layer); $class = basename($name.$layer); if(class_exists($class)) { $model = new $class(); }else { $model = new Model(basename($name)); } $_model[$name] = $model; return $model; } function M($name='', $tablePrefix='',$connection='') { static $_model = array(); if(strpos($name,':')) { list($class,$name) = explode(':',$name); }else{ $class = 'Model'; } $guid = $tablePrefix . $name . '_' . $class; if (!isset($_model[$guid])) $_model[$guid] = new $class($name,$tablePrefix,$connection); return $_model[$guid]; } function A($name,$layer='') { static $_action = array(); $layer = $layer?$layer:C('DEFAULT_C_LAYER'); if(strpos($name,'://')) { $name = str_replace('://','/'.$layer.'/',$name); }else{ $name = '@/'.$layer.'/'.$name; } if(isset($_action[$name])) return $_action[$name]; import($name.$layer); $class = basename($name.$layer); if(class_exists($class,false)) { $action = new $class(); $_action[$name] = $action; return $action; }else { return false; } } function R($url,$vars=array(),$layer='') { $info = pathinfo($url); $action = $info['basename']; $module = $info['dirname']; $class = A($module,$layer); if($class){ if(is_string($vars)) { parse_str($vars,$vars); } return call_user_func_array(array(&$class,$action),$vars); }else{ return false; } } function L($name=null, $value=null) { static $_lang = array(); if (empty($name)) return $_lang; if (is_string($name)) { $name = strtoupper($name); if (is_null($value)) return isset($_lang[$name]) ? $_lang[$name] : $name; $_lang[$name] = $value; return; } if (is_array($name)) $_lang = array_merge($_lang, array_change_key_case($name, CASE_UPPER)); return; } function C($name=null, $value=null) { static $_config = array(); if (empty($name)) { if(!empty($value) && $array = cache('c_'.$value)) { $_config = array_merge($_config, array_change_key_case($array)); } return $_config; } if (is_string($name)) { if (!strpos($name, '.')) { $name = strtolower($name); if (is_null($value)) return isset($_config[$name]) ? $_config[$name] : null; $_config[$name] = $value; return; } $name = explode('.', $name); $name[0] = strtolower($name[0]); if (is_null($value)) return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : null; $_config[$name[0]][$name[1]] = $value; return; } if (is_array($name)){ $_config = array_merge($_config, array_change_key_case($name)); if(!empty($value)) { cache('c_'.$value,$_config); } return; } return null; } function tag($tag, &$params=NULL) { $extends = C('extends.' . $tag); $tags = C('tags.' . $tag); if (!empty($tags)) { if(empty($tags['_overlay']) && !empty($extends)) { $tags = array_unique(array_merge($extends,$tags)); }elseif(isset($tags['_overlay'])){ unset($tags['_overlay']); } }elseif(!empty($extends)) { $tags = $extends; } if($tags) { if(APP_DEBUG) { G($tag.'Start'); trace('[ '.$tag.' ] --START--','','INFO'); } foreach ($tags as $key=>$name) { if(!is_int($key)) { $name = $key; } B($name, $params); } if(APP_DEBUG) { trace('[ '.$tag.' ] --END-- [ RunTime:'.G($tag.'Start',$tag.'End',6).'s ]','','INFO'); } }else{ return false; } } function add_tag_behavior($tag,$behavior,$path='') { $array = C('tags.'.$tag); if(!$array) { $array = array(); } if($path) { $array[$behavior] = $path; }else{ $array[] = $behavior; } C('tags.'.$tag,$array); } function filter($name, &$content) { $class = $name . 'Filter'; require_cache(LIB_PATH . 'Filter/' . $class . '.class.php'); $filter = new $class(); $content = $filter->run($content); } function B($name, &$params=NULL) { $class = $name.'Behavior'; G('behaviorStart'); $behavior = new $class(); $behavior->run($params); if(APP_DEBUG) { trace('Run '.$name.' Behavior [ RunTime:'.G('behaviorStart','behaviorEnd',6).'s ]','','INFO'); } } function W($name, $data=array(), $return=false) { $class = $name . 'Widget'; require_cache(LIB_PATH . 'Widget/' . $class . '.class.php'); if (!class_exists($class)) throw_exception(L('_CLASS_NOT_EXIST_') . ':' . $class); $widget = Think::instance($class); $content = $widget->render($data); if ($return) return $content; else echo $content; } function strip_whitespace($content) { $stripStr = ''; $tokens = token_get_all($content); $last_space = false; for ($i = 0, $j = count($tokens); $i < $j; $i++) { if (is_string($tokens[$i])) { $last_space = false; $stripStr .= $tokens[$i]; } else { switch ($tokens[$i][0]) { case T_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$last_space) { $stripStr .= ' '; $last_space = true; } break; case T_START_HEREDOC: $stripStr .= "<<<THINK\n"; break; case T_END_HEREDOC: $stripStr .= "THINK;\n"; for($k = $i+1; $k < $j; $k++) { if(is_string($tokens[$k]) && $tokens[$k] == ';') { $i = $k; break; } else if($tokens[$k][0] == T_CLOSE_TAG) { break; } } break; default: $last_space = false; $stripStr .= $tokens[$i][1]; } } } return $stripStr; } function trace($value='[think]',$label='',$level='DEBUG',$record=false) { static $_trace = array(); if('[think]' === $value){ return $_trace; }else{ $info = ($label?$label.':':'').print_r($value,true); if(APP_DEBUG && 'ERR' == $level) { throw_exception($info); } if(!isset($_trace[$level])) { $_trace[$level] = array(); } $_trace[$level][] = $info; if((defined('IS_AJAX') && IS_AJAX) || !C('SHOW_PAGE_TRACE') || $record) { Log::record($info,$level,$record); } } } class Think { private static $_instance = array(); static public function start() { register_shutdown_function(array('Think','fatalError')); set_error_handler(array('Think','appError')); set_exception_handler(array('Think','appException')); spl_autoload_register(array('Think', 'autoload')); App::run(); return ; } public static function autoload($class) { if(alias_import($class)) return ; if(substr($class,-8)=='Behavior') { if(require_cache(CORE_PATH.'Behavior/'.$class.'.class.php') || require_cache(EXTEND_PATH.'Behavior/'.$class.'.class.php') || require_cache(LIB_PATH.'Behavior/'.$class.'.class.php') || (defined('MODE_NAME') && require_cache(MODE_PATH.ucwords(MODE_NAME).'/Behavior/'.$class.'.class.php'))) { return ; } }elseif(substr($class,-5)=='Model'){ if((defined('GROUP_NAME') && require_cache(LIB_PATH.'Model/'.GROUP_NAME.'/'.$class.'.class.php')) || require_cache(LIB_PATH.'Model/'.$class.'.class.php') || require_cache(EXTEND_PATH.'Model/'.$class.'.class.php') ) { return ; } }elseif(substr($class,-6)=='Action'){ if((defined('GROUP_NAME') && require_cache(LIB_PATH.'Action/'.GROUP_NAME.'/'.$class.'.class.php')) || require_cache(LIB_PATH.'Action/'.$class.'.class.php') || require_cache(EXTEND_PATH.'Action/'.$class.'.class.php') ) { return ; } } $paths = explode(',',C('APP_AUTOLOAD_PATH')); foreach ($paths as $path){ if(import($path.'.'.$class)) return ; } } static public function instance($class,$method='') { $identify = $class.$method; if(!isset(self::$_instance[$identify])) { if(class_exists($class)){ $o = new $class(); if(!empty($method) && method_exists($o,$method)) self::$_instance[$identify] = call_user_func_array(array(&$o, $method)); else self::$_instance[$identify] = $o; } else halt(L('_CLASS_NOT_EXIST_').':'.$class); } return self::$_instance[$identify]; } static public function appException($e) { halt($e->__toString()); } static public function appError($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: ob_end_clean(); if(!ini_get('zlib.output_compression') && C('OUTPUT_ENCODE')) ob_start('ob_gzhandler'); $errorStr = "$errstr ".$errfile." 第 $errline 行."; if(C('LOG_RECORD')) Log::write("[$errno] ".$errorStr,Log::ERR); function_exists('halt')?halt($errorStr):exit('ERROR:'.$errorStr); break; case E_STRICT: case E_USER_WARNING: case E_USER_NOTICE: default: $errorStr = "[$errno] $errstr ".$errfile." 第 $errline 行."; trace($errorStr,'','NOTIC'); break; } } static public function fatalError() { if ($e = error_get_last()) { Think::appError($e['type'],$e['message'],$e['file'],$e['line']); } } } class ThinkException extends Exception { private $type; private $extra; public function __construct($message,$code=0,$extra=false) { parent::__construct($message,$code); $this->type = get_class($this); $this->extra = $extra; } public function __toString() { $trace = $this->getTrace(); if($this->extra) array_shift($trace); $this->class = isset($trace[0]['class'])?$trace[0]['class']:''; $this->function = isset($trace[0]['function'])?$trace[0]['function']:''; $this->file = $trace[0]['file']; $this->line = $trace[0]['line']; $file = file($this->file); $traceInfo = ''; $time = date('y-m-d H:i:m'); foreach($trace as $t) { $traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') '; $traceInfo .= $t['class'].$t['type'].$t['function'].'('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=")\n"; } $error['message'] = $this->message; $error['type'] = $this->type; $error['detail'] = L('_MODULE_').'['.MODULE_NAME.'] '.L('_ACTION_').'['.ACTION_NAME.']'."\n"; $error['detail'] .= ($this->line-2).': '.$file[$this->line-3]; $error['detail'] .= ($this->line-1).': '.$file[$this->line-2]; $error['detail'] .= '<font color="#FF6600" >'.($this->line).': <strong>'.$file[$this->line-1].'</strong></font>'; $error['detail'] .= ($this->line+1).': '.$file[$this->line]; $error['detail'] .= ($this->line+2).': '.$file[$this->line+1]; $error['class'] = $this->class; $error['function'] = $this->function; $error['file'] = $this->file; $error['line'] = $this->line; $error['trace'] = $traceInfo; if(C('LOG_EXCEPTION_RECORD')) { Log::Write('('.$this->type.') '.$this->message); } return $error ; } } abstract class Behavior { protected $options = array(); public function __construct() { if(!empty($this->options)) { foreach ($this->options as $name=>$val){ if(NULL !== C($name)) { $this->options[$name] = C($name); }else{ C($name,$val); } } array_change_key_case($this->options); } } public function __get($name){ return $this->options[strtolower($name)]; } abstract public function run(&$params); } defined('THINK_PATH') or exit(); class ReadHtmlCacheBehavior extends Behavior { protected $options = array( 'HTML_CACHE_ON' => false, 'HTML_CACHE_TIME' => 60, 'HTML_CACHE_RULES' => array(), 'HTML_FILE_SUFFIX' => '.html', ); public function run(&$params){ if(C('HTML_CACHE_ON')) { $cacheTime = $this->requireHtmlCache(); if( false !== $cacheTime && $this->checkHTMLCache(HTML_FILE_NAME,$cacheTime)) { readfile(HTML_FILE_NAME); exit(); } } } static private function requireHtmlCache() { $htmls = C('HTML_CACHE_RULES'); if(!empty($htmls)) { $htmls = array_change_key_case($htmls); $moduleName = strtolower(MODULE_NAME); $actionName = strtolower(ACTION_NAME); if(isset($htmls[$moduleName.':'.$actionName])) { $html = $htmls[$moduleName.':'.$actionName]; }elseif(isset($htmls[$moduleName.':'])){ $html = $htmls[$moduleName.':']; }elseif(isset($htmls[$actionName])){ $html = $htmls[$actionName]; }elseif(isset($htmls['*'])){ $html = $htmls['*']; }elseif(isset($htmls['empty:index']) && !class_exists(MODULE_NAME.'Action')){ $html = $htmls['empty:index']; }elseif(isset($htmls[$moduleName.':_empty']) && $this->isEmptyAction(MODULE_NAME,ACTION_NAME)){ $html = $htmls[$moduleName.':_empty']; } if(!empty($html)) { $rule = $html[0]; $rule = preg_replace('/{\$(_\w+)\.(\w+)\|(\w+)}/e',"\\3(\$\\1['\\2'])",$rule); $rule = preg_replace('/{\$(_\w+)\.(\w+)}/e',"\$\\1['\\2']",$rule); $rule = preg_replace('/{(\w+)\|(\w+)}/e',"\\2(\$_GET['\\1'])",$rule); $rule = preg_replace('/{(\w+)}/e',"\$_GET['\\1']",$rule); $rule = str_ireplace( array('{:app}','{:module}','{:action}','{:group}'), array(APP_NAME,MODULE_NAME,ACTION_NAME,defined('GROUP_NAME')?GROUP_NAME:''), $rule); $rule = preg_replace('/{|(\w+)}/e',"\\1()",$rule); if(!empty($html[2])) $rule = $html[2]($rule); $cacheTime = isset($html[1])?$html[1]:C('HTML_CACHE_TIME'); define('HTML_FILE_NAME',HTML_PATH . $rule.C('HTML_FILE_SUFFIX')); return $cacheTime; } } return false; } static public function checkHTMLCache($cacheFile='',$cacheTime='') { if(!is_file($cacheFile)){ return false; }elseif (filemtime(C('TEMPLATE_NAME')) > filemtime($cacheFile)) { return false; }elseif(!is_numeric($cacheTime) && function_exists($cacheTime)){ return $cacheTime($cacheFile); }elseif ($cacheTime != 0 && NOW_TIME > filemtime($cacheFile)+$cacheTime) { return false; } return true; } static private function isEmptyAction($module,$action) { $className = $module.'Action'; $class = new $className; return !method_exists($class,$action); } } defined('THINK_PATH') or exit(); class CheckRouteBehavior extends Behavior { protected $options = array( 'URL_ROUTER_ON' => false, 'URL_ROUTE_RULES' => array(), ); public function run(&$return){ $regx = trim($_SERVER['PATH_INFO'],'/'); __EXT__ && $regx = $regx . '.' . __EXT__; if(empty($regx)) return $return = true; if(!C('URL_ROUTER_ON')) return $return = false; $routes = C('URL_ROUTE_RULES'); if(!empty($routes)) { $depr = C('URL_PATHINFO_DEPR'); foreach ($routes as $rule=>$route) { $rule = str_replace('\\/$/', '$/', $rule); if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { return $return = $this->parseRegex($matches,$route,$regx); }else{ $len1 = substr_count($regx,'/'); $len2 = substr_count($rule,'/'); if($len1>=$len2) { if('$' == substr($rule,-1,1)) { if($len1 != $len2) { continue; }else{ $rule = substr($rule,0,-1); } } $match = $this->checkUrlMatch($regx,$rule); if($match) return $return = $this->parseRule($rule,$route,$regx); } } } } $return = false; } private function checkUrlMatch($regx,$rule) { $m1 = explode('/',$regx); $m2 = explode('/',$rule); $match = true; foreach ($m2 as $key=>$val){ if(':' == substr($val,0,1)) { if(strpos($val,'\\')) { $type = substr($val,-1); if('d'==$type && !is_numeric($m1[$key])) { $match = false; break; } }elseif(strpos($val,'^')){ $array = explode('|',substr(strstr($val,'^'),1)); if(in_array($m1[$key],$array)) { $match = false; break; } } }elseif(0 !== strcasecmp($val,$m1[$key])){ $match = false; break; } } return $match; } private function parseUrl($url) { $var = array(); if(false !== strpos($url,'?')) { $info = parse_url($url); $path = explode('/',$info['path']); parse_str($info['query'],$var); }elseif(strpos($url,'/')){ $path = explode('/',$url); }else{ parse_str($url,$var); } if(isset($path)) { $var[C('VAR_ACTION')] = array_pop($path); if(!empty($path)) { $var[C('VAR_MODULE')] = array_pop($path); } if(!empty($path)) { $var[C('VAR_GROUP')] = array_pop($path); } } return $var; } private function parseRule($rule,$route,$regx) { $url = is_array($route)?$route[0]:$route; $paths = explode('/',$regx); $matches = array(); $rule = explode('/',$rule); foreach ($rule as $item){ if(0===strpos($item,':')) { if($pos = strpos($item,'^') ) { $var = substr($item,1,$pos-1); }elseif(strpos($item,'\\')){ $var = substr($item,1,-2); }else{ $var = substr($item,1); } $matches[$var] = array_shift($paths); }else{ array_shift($paths); } } if(0=== strpos($url,'/') || 0===strpos($url,'http')) { if(strpos($url,':')) { $values = array_values($matches); $url = preg_replace('/:(\d+)/e','$values[\\1-1]',$url); } header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = $this->parseUrl($url); $values = array_values($matches); foreach ($var as $key=>$val){ if(0===strpos($val,':')) { $var[$key] = $values[substr($val,1)-1]; } } $var = array_merge($matches,$var); if($paths) { preg_replace('@(\w+)\/([^\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', implode('/',$paths)); } if(is_array($route) && isset($route[1])) { parse_str($route[1],$params); $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } private function parseRegex($matches,$route,$regx) { $url = is_array($route)?$route[0]:$route; $url = preg_replace('/:(\d+)/e','$matches[\\1]',$url); if(0=== strpos($url,'/') || 0===strpos($url,'http')) { header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = $this->parseUrl($url); $regx = substr_replace($regx,'',0,strlen($matches[0])); if($regx) { preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', $regx); } if(is_array($route) && isset($route[1])) { parse_str($route[1],$params); $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } } defined('THINK_PATH') or exit(); class LocationTemplateBehavior extends Behavior { public function run(&$templateFile){ if(!file_exists_case($templateFile)) $templateFile = $this->parseTemplateFile($templateFile); } private function parseTemplateFile($templateFile) { if(''==$templateFile) { $templateFile = C('TEMPLATE_NAME'); }elseif(false === strpos($templateFile,C('TMPL_TEMPLATE_SUFFIX'))){ $path = explode(':',$templateFile); $action = array_pop($path); $module = !empty($path)?array_pop($path):MODULE_NAME; if(!empty($path)) { $path = dirname(THEME_PATH).'/'.array_pop($path).'/'; }else{ $path = THEME_PATH; } $depr = defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/'; $templateFile = $path.$module.$depr.$action.C('TMPL_TEMPLATE_SUFFIX'); } if(!file_exists_case($templateFile)) throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']'); return $templateFile; } } defined('THINK_PATH') or exit(); class ParseTemplateBehavior extends Behavior { protected $options = array( 'TMPL_ENGINE_TYPE' => 'Think', 'TMPL_CACHFILE_SUFFIX' => '.php', 'TMPL_DENY_FUNC_LIST' => 'echo,exit', 'TMPL_DENY_PHP' => false, 'TMPL_L_DELIM' => '{', 'TMPL_R_DELIM' => '}', 'TMPL_VAR_IDENTIFY' => 'array', 'TMPL_STRIP_SPACE' => true, 'TMPL_CACHE_ON' => true, 'TMPL_CACHE_TIME' => 0, 'TMPL_LAYOUT_ITEM' => '{__CONTENT__}', 'LAYOUT_ON' => false, 'LAYOUT_NAME' => 'layout', 'TAGLIB_BEGIN' => '<', 'TAGLIB_END' => '>', 'TAGLIB_LOAD' => true, 'TAGLIB_BUILD_IN' => 'cx', 'TAGLIB_PRE_LOAD' => '', ); public function run(&$_data){ $engine = strtolower(C('TMPL_ENGINE_TYPE')); $_content = empty($_data['content'])?$_data['file']:$_data['content']; if('think'==$engine){ if(empty($_data['content']) && $this->checkCache($_data['file'])) { extract($_data['var'], EXTR_OVERWRITE); include C('CACHE_PATH').md5($_data['file']).C('TMPL_CACHFILE_SUFFIX'); }else{ $tpl = Think::instance('ThinkTemplate'); $tpl->fetch($_content,$_data['var']); } }else{ $class = 'Template'.ucwords($engine); if(is_file(CORE_PATH.'Driver/Template/'.$class.'.class.php')) { $path = CORE_PATH; }else{ $path = EXTEND_PATH; } if(require_cache($path.'Driver/Template/'.$class.'.class.php')) { $tpl = new $class; $tpl->fetch($_content,$_data['var']); }else { throw_exception(L('_NOT_SUPPERT_').': ' . $class); } } } protected function checkCache($tmplTemplateFile) { if (!C('TMPL_CACHE_ON')) return false; $tmplCacheFile = C('CACHE_PATH').md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX'); if(!is_file($tmplCacheFile)){ return false; }elseif (filemtime($tmplTemplateFile) > filemtime($tmplCacheFile)) { return false; }elseif (C('TMPL_CACHE_TIME') != 0 && time() > filemtime($tmplCacheFile)+C('TMPL_CACHE_TIME')) { return false; } if(C('LAYOUT_ON')) { $layoutFile = THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX'); if(filemtime($layoutFile) > filemtime($tmplCacheFile)) { return false; } } return true; } } defined('THINK_PATH') or exit(); class ContentReplaceBehavior extends Behavior { protected $options = array( 'TMPL_PARSE_STRING' => array(), ); public function run(&$content){ $content = $this->templateContentReplace($content); } protected function templateContentReplace($content) { $replace = array( '__TMPL__' => APP_TMPL_PATH, '__ROOT__' => __ROOT__, '__APP__' => __APP__, '__GROUP__' => defined('GROUP_NAME')?__GROUP__:__APP__, '__ACTION__' => __ACTION__, '__SELF__' => __SELF__, '__URL__' => __URL__, '../Public' => APP_TMPL_PATH.'Public', '__PUBLIC__' => __ROOT__.'/Public', ); if(is_array(C('TMPL_PARSE_STRING')) ) $replace = array_merge($replace,C('TMPL_PARSE_STRING')); $content = str_replace(array_keys($replace),array_values($replace),$content); return $content; } } defined('THINK_PATH') or exit(); class TokenBuildBehavior extends Behavior { protected $options = array( 'TOKEN_ON' => false, 'TOKEN_NAME' => '__hash__', 'TOKEN_TYPE' => 'md5', 'TOKEN_RESET' => true, ); public function run(&$content){ if(C('TOKEN_ON')) { if(strpos($content,'{__TOKEN__}')) { $content = str_replace('{__TOKEN__}',$this->buildToken(),$content); }elseif(preg_match('/<\/form(\s*)>/is',$content,$match)) { $content = str_replace($match[0],$this->buildToken().$match[0],$content); } }else{ $content = str_replace('{__TOKEN__}','',$content); } } private function buildToken() { $tokenName = C('TOKEN_NAME'); $tokenType = C('TOKEN_TYPE'); if(!isset($_SESSION[$tokenName])) { $_SESSION[$tokenName] = array(); } $tokenKey = md5($_SERVER['REQUEST_URI']); if(isset($_SESSION[$tokenName][$tokenKey])) { $tokenValue = $_SESSION[$tokenName][$tokenKey]; }else{ $tokenValue = $tokenType(microtime(TRUE)); $_SESSION[$tokenName][$tokenKey] = $tokenValue; } $token = '<input type="hidden" name="'.$tokenName.'" value="'.$tokenKey.'_'.$tokenValue.'" />'; return $token; } } defined('THINK_PATH') or exit(); class WriteHtmlCacheBehavior extends Behavior { public function run(&$content){ if(C('HTML_CACHE_ON') && defined('HTML_FILE_NAME')) { if(!is_dir(dirname(HTML_FILE_NAME))) mkdir(dirname(HTML_FILE_NAME),0777,true); if( false === file_put_contents( HTML_FILE_NAME , $content )) throw_exception(L('_CACHE_WRITE_ERROR_').':'.HTML_FILE_NAME); } } } defined('THINK_PATH') or exit(); class ShowRuntimeBehavior extends Behavior { protected $options = array( 'SHOW_RUN_TIME' => false, 'SHOW_ADV_TIME' => false, 'SHOW_DB_TIMES' => false, 'SHOW_CACHE_TIMES' => false, 'SHOW_USE_MEM' => false, 'SHOW_LOAD_FILE' => false, 'SHOW_FUN_TIMES' => false , ); public function run(&$content){ if(C('SHOW_RUN_TIME')){ if(false !== strpos($content,'{__NORUNTIME__}')) { $content = str_replace('{__NORUNTIME__}','',$content); }else{ $runtime = $this->showTime(); if(strpos($content,'{__RUNTIME__}')) $content = str_replace('{__RUNTIME__}',$runtime,$content); else $content .= $runtime; } }else{ $content = str_replace(array('{__NORUNTIME__}','{__RUNTIME__}'),'',$content); } } private function showTime() { G('beginTime',$GLOBALS['_beginTime']); G('viewEndTime'); $showTime = 'Process: '.G('beginTime','viewEndTime').'s '; if(C('SHOW_ADV_TIME')) { $showTime .= '( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; } if(C('SHOW_DB_TIMES') && class_exists('Db',false) ) { $showTime .= ' | DB :'.N('db_query').' queries '.N('db_write').' writes '; } if(C('SHOW_CACHE_TIMES') && class_exists('Cache',false)) { $showTime .= ' | Cache :'.N('cache_read').' gets '.N('cache_write').' writes '; } if(MEMORY_LIMIT_ON && C('SHOW_USE_MEM')) { $showTime .= ' | UseMem:'. number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024).' kb'; } if(C('SHOW_LOAD_FILE')) { $showTime .= ' | LoadFile:'.count(get_included_files()); } if(C('SHOW_FUN_TIMES')) { $fun = get_defined_functions(); $showTime .= ' | CallFun:'.count($fun['user']).','.count($fun['internal']); } return $showTime; } } defined('THINK_PATH') or exit(); class ShowPageTraceBehavior extends Behavior { protected $options = array( 'SHOW_PAGE_TRACE' => false, 'TRACE_PAGE_TABS' => array('BASE'=>'基本','FILE'=>'文件','INFO'=>'流程','ERR|NOTIC'=>'错误','SQL'=>'SQL','DEBUG'=>'调试'), 'PAGE_TRACE_SAVE' => false, ); public function run(&$params){ if(!IS_AJAX && C('SHOW_PAGE_TRACE')) { echo $this->showTrace(); } } private function showTrace() { $files = get_included_files(); $info = array(); foreach ($files as $key=>$file){ $info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )'; } $trace = array(); $base = array( '请求信息' => date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__, '运行时间' => $this->showTime(), '内存开销' => MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持', '查询信息' => N('db_query').' queries '.N('db_write').' writes ', '文件加载' => count(get_included_files()), '缓存信息' => N('cache_read').' gets '.N('cache_write').' writes ', '配置加载' => count(c()), '会话信息' => 'SESSION_ID='.session_id(), ); $traceFile = CONF_PATH.'trace.php'; if(is_file($traceFile)) { $base = array_merge($base,include $traceFile); } $debug = trace(); $tabs = C('TRACE_PAGE_TABS'); foreach ($tabs as $name=>$title){ switch(strtoupper($name)) { case 'BASE': $trace[$title] = $base; break; case 'FILE': $trace[$title] = $info; break; default: if(strpos($name,'|')) { $array = explode('|',$name); $result = array(); foreach($array as $name){ $result += isset($debug[$name])?$debug[$name]:array(); } $trace[$title] = $result; }else{ $trace[$title] = isset($debug[$name])?$debug[$name]:''; } } } if($save = C('PAGE_TRACE_SAVE')) { if(is_array($save)) { $tabs = C('TRACE_PAGE_TABS'); $array = array(); foreach ($save as $tab){ $array[] = $tabs[$tab]; } } $content = date('[ c ]').' '.get_client_ip().' '.$_SERVER['REQUEST_URI']."\r\n"; foreach ($trace as $key=>$val){ if(!isset($array) || in_array($key,$array)) { $content .= '[ '.$key." ]\r\n"; if(is_array($val)) { foreach ($val as $k=>$v){ $content .= (!is_numeric($k)?$k.':':'').print_r($v,true)."\r\n"; } }else{ $content .= print_r($val,true)."\r\n"; } $content .= "\r\n"; } } error_log(str_replace('<br/>',"\r\n",$content), Log::FILE,LOG_PATH.date('y_m_d').'_trace.log'); } unset($files,$info,$log,$base); ob_start(); include C('TMPL_TRACE_FILE')?C('TMPL_TRACE_FILE'):THINK_PATH.'Tpl/page_trace.tpl'; return ob_get_clean(); } private function showTime() { G('beginTime',$GLOBALS['_beginTime']); G('viewEndTime'); return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; } }alias_import(array ( 'Model' => 'D:\\saivi4.0\\sc\\_core/Lib/Core/Model.class.php', 'Db' => 'D:\\saivi4.0\\sc\\_core/Lib/Core/Db.class.php', 'Log' => 'D:\\saivi4.0\\sc\\_core/Lib/Core/Log.class.php', 'ThinkTemplate' => 'D:\\saivi4.0\\sc\\_core/Lib/Template/ThinkTemplate.class.php', 'TagLib' => 'D:\\saivi4.0\\sc\\_core/Lib/Template/TagLib.class.php', 'Cache' => 'D:\\saivi4.0\\sc\\_core/Lib/Core/Cache.class.php', 'Widget' => 'D:\\saivi4.0\\sc\\_core/Lib/Core/Widget.class.php', 'TagLibCx' => 'D:\\saivi4.0\\sc\\_core/Lib/Driver/TagLib/TagLibCx.class.php', )); function halt($error) { $e = array(); if (APP_DEBUG) { if (!is_array($error)) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['class'] = isset($trace[0]['class'])?$trace[0]['class']:''; $e['function'] = isset($trace[0]['function'])?$trace[0]['function']:''; $e['line'] = $trace[0]['line']; $traceInfo = ''; $time = date('y-m-d H:i:m'); foreach ($trace as $t) { $traceInfo .= '[' . $time . '] ' . $t['file'] . ' (' . $t['line'] . ') '; $traceInfo .= $t['class'] . $t['type'] . $t['function'] . '('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=')<br/>'; } $e['trace'] = $traceInfo; } else { $e = $error; } } else { $error_page = C('ERROR_PAGE'); if (!empty($error_page)) { redirect($error_page); } else { if (C('SHOW_ERROR_MSG')) $e['message'] = is_array($error) ? $error['message'] : $error; else $e['message'] = C('ERROR_MESSAGE'); } } include C('TMPL_EXCEPTION_FILE'); exit; } function throw_exception($msg, $type='ThinkException', $code=0) { if (class_exists($type, false)) throw new $type($msg, $code, true); else halt($msg); } function dump($var, $echo=true, $label=null, $strict=true) { $label = ($label === null) ? '' : rtrim($label) . ' '; if (!$strict) { if (ini_get('html_errors')) { $output = print_r($var, true); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; } else { $output = $label . print_r($var, true); } } else { ob_start(); var_dump($var); $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace("/\]\=\>\n(\s+)/m", '] => ', $output); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; } } if ($echo) { echo($output); return null; }else return $output; } function _404($msg='',$url='') { APP_DEBUG && throw_exception($msg); if($msg && C('LOG_EXCEPTION_RECORD')) Log::write($msg); if(empty($url) && C('URL_404_REDIRECT')) { $url = C('URL_404_REDIRECT'); } if($url) { redirect($url); }else{ send_http_status(404); exit; } } function layout($layout) { if(false !== $layout) { C('LAYOUT_ON',true); if(is_string($layout)) { C('LAYOUT_NAME',$layout); } }else{ C('LAYOUT_ON',false); } } function U($url='',$vars='',$suffix=true,$redirect=false,$domain=false) { $info = parse_url($url); $url = !empty($info['path'])?$info['path']:ACTION_NAME; if(false !== strpos($url,'@')) { list($url,$host) = explode('@',$info['path'], 2); } if(isset($host)) { $domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.')); }elseif($domain===true){ $domain = $_SERVER['HTTP_HOST']; if(C('APP_SUB_DOMAIN_DEPLOY') ) { $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.'); foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) { if(false === strpos($key,'*') && 0=== strpos($url,$rule[0])) { $domain = $key.strstr($domain,'.'); $url = substr_replace($url,'',0,strlen($rule[0])); break; } } } } if(is_string($vars)) { parse_str($vars,$vars); }elseif(!is_array($vars)){ $vars = array(); } if(isset($info['query'])) { parse_str($info['query'],$params); $vars = array_merge($params,$vars); } $depr = C('URL_PATHINFO_DEPR'); if($url) { if(0=== strpos($url,'/')) { $route = true; $url = substr($url,1); if('/' != $depr) { $url = str_replace('/',$depr,$url); } }else{ if('/' != $depr) { $url = str_replace('/',$depr,$url); } $url = trim($url,$depr); $path = explode($depr,$url); $var = array(); $var[C('VAR_ACTION')] = !empty($path)?array_pop($path):ACTION_NAME; $var[C('VAR_MODULE')] = !empty($path)?array_pop($path):MODULE_NAME; if(C('URL_CASE_INSENSITIVE')) { $var[C('VAR_MODULE')] = parse_name($var[C('VAR_MODULE')]); } if(!C('APP_SUB_DOMAIN_DEPLOY') && C('APP_GROUP_LIST')) { if(!empty($path)) { $group = array_pop($path); $var[C('VAR_GROUP')] = $group; }else{ if(GROUP_NAME != C('DEFAULT_GROUP')) { $var[C('VAR_GROUP')]= GROUP_NAME; } } if(C('URL_CASE_INSENSITIVE') && isset($var[C('VAR_GROUP')])) { $var[C('VAR_GROUP')] = strtolower($var[C('VAR_GROUP')]); } } } } $flag=true; if(C('URL_MODEL') == 0) { $ap = pathinfo(__APP__); if ($ap['extension'] != 'php') { $url = __APP__ .'/?'.http_build_query(array_reverse($var)); } else { $url = __APP__ .'?'.http_build_query(array_reverse($var)); } if(!empty($vars)) { $vars = urldecode(http_build_query($vars)); $url .= '&'.$vars; } $flag=false; } if(C('URL_MODEL') == 2){ $routes = C('URL_ROUTE_RULES'); if (false === strpos('/', $url)) { $url = implode($depr,array_reverse($var)); } $_url=array_merge(parseUrl($url), $vars); foreach ($routes as $rule=>$r_route){ $r_route = str_replace('/', $depr, $r_route); $_route=parseUrl(str_replace(':', '~',$r_route)); if(url_compare($_url, $_route))break; } if(url_compare($_url, $_route)){ foreach ($_route as $key=>$val){ if($key=='m'||$key=='a')continue; if( preg_match("/~/",$val) ){ $rule=preg_replace("/(\(\\\[\w]\+\))/",$_url[$key],$rule,1); } } $url = __APP__.'/'.ltrim(rtrim(trim($rule,'/'), '$'), '^'); $url = str_replace('\\', '', $url); $flag = false; } } if($flag){ if(isset($route)) { $url = __APP__.'/'.rtrim($url,$depr); }else{ $url = __APP__.'/'.implode($depr,array_reverse($var)); } if(!empty($vars)) { foreach ($vars as $var => $val) $url .= $depr.$var . $depr . $val; } if($suffix) { $suffix = $suffix===true?C('URL_HTML_SUFFIX'):$suffix; if($pos = strpos($suffix, '|')){ $suffix = substr($suffix, 0, $pos); } if($suffix && $url[1]){ $url .= '.'.ltrim($suffix,'.'); } } } if($domain) { $url = (is_ssl()?'https://':'http://').$domain.$url; } if($redirect) redirect($url); else return $url; } function is_ssl() { if(isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))){ return true; }elseif(isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'] )) { return true; } return false; } function redirect($url, $time=0, $msg='') { $url = str_replace(array("\n", "\r"), '', $url); if (empty($msg)) $msg = "系统将在{$time}秒之后自动跳转到{$url}!"; if (!headers_sent()) { if (0 === $time) { header('Location: ' . $url); } else { header("refresh:{$time};url={$url}"); echo($msg); } exit(); } else { $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>"; if ($time != 0) $str .= $msg; exit($str); } } function cache($name,$value='',$expire=0) { static $cache = ''; if(is_array($name)) { $type = isset($name['type'])?$name['type']:C('DATA_CACHE_TYPE'); unset($name['type']); $cache = Cache::getInstance($type,$name); return $cache; } if(empty($cache)) { $cache = Cache::getInstance(); } if(''=== $value){ return $cache->get($name); }elseif(is_null($value)) { return $cache->rm($name); }else { return $cache->set($name, $value, $expire); } } function S($name, $value='', $expire=null, $type='',$options=null) { static $_cache = array(); $cache = Cache::getInstance($type,$options); if ('' !== $value) { if (is_null($value)) { $result = $cache->rm($name); if ($result) unset($_cache[$type . '_' . $name]); return $result; }else { $cache->set($name, $value, $expire); $_cache[$type . '_' . $name] = $value; } return; } if (isset($_cache[$type . '_' . $name])) return $_cache[$type . '_' . $name]; $value = $cache->get($name); $_cache[$type . '_' . $name] = $value; return $value; } function F($name, $value='', $path=DATA_PATH) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { return unlink($filename); } else { $dir = dirname($filename); if (!is_dir($dir)) mkdir($dir,0777,true); $_cache[$name] = $value; return file_put_contents($filename, json_encode($value)); } } if (isset($_cache[$name])) return $_cache[$name]; if (is_file($filename)) { $value = json_decode(file_get_contents($filename),true); $_cache[$name] = $value; } else { $value = false; } return $value; } function get_instance_of($name, $method='', $args=array()) { static $_instance = array(); $identify = empty($args) ? $name . $method : $name . $method . to_guid_string($args); if (!isset($_instance[$identify])) { if (class_exists($name)) { $o = new $name(); if (method_exists($o, $method)) { if (!empty($args)) { $_instance[$identify] = call_user_func_array(array(&$o, $method), $args); } else { $_instance[$identify] = $o->$method(); } } else $_instance[$identify] = $o; } else halt(L('_CLASS_NOT_EXIST_') . ':' . $name); } return $_instance[$identify]; } function to_guid_string($mix) { if (is_object($mix) && function_exists('spl_object_hash')) { return spl_object_hash($mix); } elseif (is_resource($mix)) { $mix = get_resource_type($mix) . strval($mix); } else { $mix = serialize($mix); } return md5($mix); } function xml_encode($data, $encoding='utf-8', $root='think') { $xml = '<?xml version="1.0" encoding="' . $encoding . '"?>'; $xml .= '<' . $root . '>'; $xml .= data_to_xml($data); $xml .= '</' . $root . '>'; return $xml; } function data_to_xml($data) { $xml = ''; foreach ($data as $key => $val) { is_numeric($key) && $key = "item id=\"$key\""; $xml .= "<$key>"; $xml .= ( is_array($val) || is_object($val)) ? data_to_xml($val) : $val; list($key, ) = explode(' ', $key); $xml .= "</$key>"; } return $xml; } function session($name,$value='') { $prefix = C('SESSION_PREFIX'); if(is_array($name)) { if(isset($name['prefix'])) C('SESSION_PREFIX',$name['prefix']); if(C('VAR_SESSION_ID') && isset($_REQUEST[C('VAR_SESSION_ID')])){ session_id($_REQUEST[C('VAR_SESSION_ID')]); }elseif(isset($name['id'])) { session_id($name['id']); } ini_set('session.auto_start', 0); if(isset($name['name'])) session_name($name['name']); if(isset($name['path'])) session_save_path($name['path']); if(isset($name['domain'])) ini_set('session.cookie_domain', $name['domain']); if(isset($name['expire'])) ini_set('session.gc_maxlifetime', $name['expire']); if(isset($name['use_trans_sid'])) ini_set('session.use_trans_sid', $name['use_trans_sid']?1:0); if(isset($name['use_cookies'])) ini_set('session.use_cookies', $name['use_cookies']?1:0); if(isset($name['cache_limiter'])) session_cache_limiter($name['cache_limiter']); if(isset($name['cache_expire'])) session_cache_expire($name['cache_expire']); if(isset($name['type'])) C('SESSION_TYPE',$name['type']); if(C('SESSION_TYPE')) { $class = 'Session'. ucwords(strtolower(C('SESSION_TYPE'))); if(require_cache(EXTEND_PATH.'Driver/Session/'.$class.'.class.php')) { $hander = new $class(); $hander->execute(); }else { throw_exception(L('_CLASS_NOT_EXIST_').': ' . $class); } } if(C('SESSION_AUTO_START')) session_start(); }elseif('' === $value){ if(0===strpos($name,'[')) { if('[pause]'==$name){ session_write_close(); }elseif('[start]'==$name){ session_start(); }elseif('[destroy]'==$name){ $_SESSION = array(); session_unset(); session_destroy(); }elseif('[regenerate]'==$name){ session_regenerate_id(); } }elseif(0===strpos($name,'?')){ $name = substr($name,1); if($prefix) { return isset($_SESSION[$prefix][$name]); }else{ return isset($_SESSION[$name]); } }elseif(is_null($name)){ if($prefix) { unset($_SESSION[$prefix]); }else{ $_SESSION = array(); } }elseif($prefix){ return isset($_SESSION[$prefix][$name])?$_SESSION[$prefix][$name]:null; }else{ return isset($_SESSION[$name])?$_SESSION[$name]:null; } }elseif(is_null($value)){ if($prefix){ unset($_SESSION[$prefix][$name]); }else{ unset($_SESSION[$name]); } }else{ if($prefix){ if (!is_array($_SESSION[$prefix])) { $_SESSION[$prefix] = array(); } $_SESSION[$prefix][$name] = $value; }else{ $_SESSION[$name] = $value; } } } function cookie($name, $value='', $option=null) { $config = array( 'prefix' => C('COOKIE_PREFIX'), 'expire' => C('COOKIE_EXPIRE'), 'path' => C('COOKIE_PATH'), 'domain' => C('COOKIE_DOMAIN'), ); if (!empty($option)) { if (is_numeric($option)) $option = array('expire' => $option); elseif (is_string($option)) parse_str($option, $option); $config = array_merge($config, array_change_key_case($option)); } if (is_null($name)) { if (empty($_COOKIE)) return; $prefix = empty($value) ? $config['prefix'] : $value; if (!empty($prefix)) { foreach ($_COOKIE as $key => $val) { if (0 === stripos($key, $prefix)) { setcookie($key, '', time() - 3600, $config['path'], $config['domain']); unset($_COOKIE[$key]); } } } return; } $name = $config['prefix'] . $name; if ('' === $value) { return isset($_COOKIE[$name]) ? json_decode(MAGIC_QUOTES_GPC?stripslashes($_COOKIE[$name]):$_COOKIE[$name]) : null; } else { if (is_null($value)) { setcookie($name, '', time() - 3600, $config['path'], $config['domain']); unset($_COOKIE[$name]); } else { $value = json_encode($value); $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; setcookie($name, $value, $expire, $config['path'], $config['domain']); $_COOKIE[$name] = $value; } } } function load_ext_file() { if(C('LOAD_EXT_FILE')) { $files = explode(',',C('LOAD_EXT_FILE')); foreach ($files as $file){ $file = COMMON_PATH.$file.'.php'; if(is_file($file)) include $file; } } if(C('LOAD_EXT_CONFIG')) { $configs = C('LOAD_EXT_CONFIG'); if(is_string($configs)) $configs = explode(',',$configs); foreach ($configs as $key=>$config){ $file = CONF_PATH.$config.'.php'; if(is_file($file)) { is_numeric($key)?C(include $file):C($key,include $file); } } } } function get_client_ip($type = 0) { $type = $type ? 1 : 0; static $ip = NULL; if ($ip !== NULL) return $ip[$type]; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } $long = ip2long($ip); $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); return $ip[$type]; } function send_http_status($code) { static $_status = array( 200 => 'OK', 301 => 'Moved Permanently', 302 => 'Moved Temporarily ', 400 => 'Bad Request', 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error', 503 => 'Service Unavailable', ); if(isset($_status[$code])) { header('HTTP/1.1 '.$code.' '.$_status[$code]); header('Status:'.$code.' '.$_status[$code]); } } function url_compare($url, $route){ ksort($url); $url_keys=array_keys($url); ksort($route); $route_keys=array_keys($route); if ($url_keys!=$route_keys) { return false; } $flag = true; foreach ($route as $_key=>$_val) { if (false === strpos($_val, '~')) { if ($url[$_key] != $_val) { $flag = false; break; } } } return $flag; } function parseUrl($url) { $depr = C('URL_PATHINFO_DEPR'); $var = array(); if(false !== strpos($url,'?')) { $info = parse_url($url); $path = explode($depr, $info['path']); parse_str($info['query'],$var); }elseif(strpos($url, $depr)){ $path = explode($depr, $url); }else{ parse_str($url, $var); } if(isset($path)) { $var[C('VAR_ACTION')] = array_pop($path); if(!empty($path)) { $var[C('VAR_MODULE')] = array_pop($path); } if(!empty($path)) { $var[C('VAR_GROUP')] = array_pop($path); } } return $var; } class Log { const EMERG = 'EMERG'; const ALERT = 'ALERT'; const CRIT = 'CRIT'; const ERR = 'ERR'; const WARN = 'WARN'; const NOTICE = 'NOTIC'; const INFO = 'INFO'; const DEBUG = 'DEBUG'; const SQL = 'SQL'; const SYSTEM = 0; const MAIL = 1; const FILE = 3; const SAPI = 4; static $log = array(); static $format = '[ c ]'; static function record($message,$level=self::ERR,$record=false) { if($record || false !== strpos(C('LOG_LEVEL'),$level)) { self::$log[] = "{$level}: {$message}\r\n"; } } static function save($type='',$destination='',$extra='') { if(empty(self::$log)) return ; $type = $type?$type:C('LOG_TYPE'); if(self::FILE == $type) { if(empty($destination)) $destination = LOG_PATH.date('y_m_d').'.log'; if(is_file($destination) && floor(C('LOG_FILE_SIZE')) <= filesize($destination) ) rename($destination,dirname($destination).'/'.time().'-'.basename($destination)); }else{ $destination = $destination?$destination:C('LOG_DEST'); $extra = $extra?$extra:C('LOG_EXTRA'); } $now = date(self::$format); error_log($now.' '.get_client_ip().' '.$_SERVER['REQUEST_URI']."\r\n".implode('',self::$log)."\r\n", $type,$destination ,$extra); self::$log = array(); } static function write($message,$level=self::ERR,$type='',$destination='',$extra='') { $now = date(self::$format); $type = $type?$type:C('LOG_TYPE'); if(self::FILE == $type) { if(empty($destination)) $destination = LOG_PATH.date('y_m_d').'.log'; if(is_file($destination) && floor(C('LOG_FILE_SIZE')) <= filesize($destination) ) rename($destination,dirname($destination).'/'.time().'-'.basename($destination)); }else{ $destination = $destination?$destination:C('LOG_DEST'); $extra = $extra?$extra:C('LOG_EXTRA'); } error_log("{$now} {$level}: {$message}\r\n", $type,$destination,$extra ); } } class Dispatcher { static public function dispatch() { $urlMode = C('URL_MODEL'); if(!empty($_GET[C('VAR_PATHINFO')])) { $_SERVER['PATH_INFO'] = $_GET[C('VAR_PATHINFO')]; unset($_GET[C('VAR_PATHINFO')]); } if($urlMode == URL_COMPAT ){ define('PHP_FILE',_PHP_FILE_.'?'.C('VAR_PATHINFO').'='); }elseif($urlMode == URL_REWRITE ) { $url = dirname(_PHP_FILE_); if($url == '/' || $url == '\\') $url = ''; define('PHP_FILE',$url); }else { define('PHP_FILE',_PHP_FILE_); } if(C('APP_SUB_DOMAIN_DEPLOY')) { $rules = C('APP_SUB_DOMAIN_RULES'); $subDomain = strtolower(substr($_SERVER['HTTP_HOST'],0,strpos($_SERVER['HTTP_HOST'],'.'))); define('SUB_DOMAIN',$subDomain); if($subDomain && isset($rules[$subDomain])) { $rule = $rules[$subDomain]; }elseif(isset($rules['*'])){ if('www' != $subDomain && !in_array($subDomain,C('APP_SUB_DOMAIN_DENY'))) { $rule = $rules['*']; } } if(!empty($rule)) { $array = explode('/',$rule[0]); $module = array_pop($array); if(!empty($module)) { $_GET[C('VAR_MODULE')] = $module; $domainModule = true; } if(!empty($array)) { $_GET[C('VAR_GROUP')] = array_pop($array); $domainGroup = true; } if(isset($rule[1])) { parse_str($rule[1],$parms); $_GET = array_merge($_GET,$parms); } } } if(empty($_SERVER['PATH_INFO'])) { $types = explode(',',C('URL_PATHINFO_FETCH')); foreach ($types as $type){ if(0===strpos($type,':')) { $_SERVER['PATH_INFO'] = call_user_func(substr($type,1)); break; }elseif(!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type],$_SERVER['SCRIPT_NAME']))? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } $depr = C('URL_PATHINFO_DEPR'); if(!empty($_SERVER['PATH_INFO'])) { tag('path_info'); $part = pathinfo($_SERVER['PATH_INFO']); define('__EXT__', isset($part['extension'])?strtolower($part['extension']):''); if(C('URL_HTML_SUFFIX')) { $_SERVER['PATH_INFO'] = preg_replace('/\.('.trim(C('URL_HTML_SUFFIX'),'.').')$/i', '', $_SERVER['PATH_INFO']); }elseif(__EXT__) { $_SERVER['PATH_INFO'] = preg_replace('/.'.__EXT__.'$/i','',$_SERVER['PATH_INFO']); } if(!self::routerCheck()){ $paths = explode($depr,trim($_SERVER['PATH_INFO'],'/')); if(C('VAR_URL_PARAMS')) { $_GET[C('VAR_URL_PARAMS')] = $paths; } $var = array(); if (C('APP_GROUP_LIST') && !isset($_GET[C('VAR_GROUP')])){ $var[C('VAR_GROUP')] = in_array(strtolower($paths[0]),explode(',',strtolower(C('APP_GROUP_LIST'))))? array_shift($paths) : ''; if(C('APP_GROUP_DENY') && in_array(strtolower($var[C('VAR_GROUP')]),explode(',',strtolower(C('APP_GROUP_DENY'))))) { exit; } } if(!isset($_GET[C('VAR_MODULE')])) { $var[C('VAR_MODULE')] = array_shift($paths); } $var[C('VAR_ACTION')] = array_shift($paths); preg_replace('@(\w+)\/([^\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/',$paths)); $_GET = array_merge($var,$_GET); } define('__INFO__',$_SERVER['PATH_INFO']); } if (C('APP_GROUP_LIST')) { define('GROUP_NAME', self::getGroup(C('VAR_GROUP'))); } define('MODULE_NAME',self::getModule(C('VAR_MODULE'))); define('ACTION_NAME',self::getAction(C('VAR_ACTION'))); define('__SELF__',strip_tags($_SERVER['REQUEST_URI'])); define('__APP__',strip_tags(PHP_FILE)); if(defined('GROUP_NAME')) { define('__GROUP__',(!empty($domainGroup) || strtolower(GROUP_NAME) == strtolower(C('DEFAULT_GROUP')) )?__APP__ : __APP__.'/'.GROUP_NAME); define('__URL__',!empty($domainModule)?__GROUP__.$depr : __GROUP__.$depr.MODULE_NAME); }else{ define('__URL__',!empty($domainModule)?__APP__.'/' : __APP__.'/'.MODULE_NAME); } define('__ACTION__',__URL__.$depr.ACTION_NAME); $_REQUEST = array_merge($_POST,$_GET); } static public function routerCheck() { $return = false; tag('route_check',$return); return $return; } static private function getModule($var) { $module = (!empty($_GET[$var])? $_GET[$var]:C('DEFAULT_MODULE')); unset($_GET[$var]); if(C('URL_CASE_INSENSITIVE')) { $module = ucfirst(parse_name($module,1)); } return strip_tags($module); } static private function getAction($var) { $action = !empty($_POST[$var]) ? $_POST[$var] : (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_ACTION')); unset($_POST[$var],$_GET[$var]); return strip_tags(C('URL_CASE_INSENSITIVE')?strtolower($action):$action); } static private function getGroup($var) { $group = (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_GROUP')); unset($_GET[$var]); return strip_tags(C('URL_CASE_INSENSITIVE') ?ucfirst(strtolower($group)):$group); } } class App { static public function init() { date_default_timezone_set(C('DEFAULT_TIMEZONE')); load_ext_file(); Dispatcher::dispatch(); define('NOW_TIME', $_SERVER['REQUEST_TIME']); define('REQUEST_METHOD',$_SERVER['REQUEST_METHOD']); define('IS_GET', REQUEST_METHOD =='GET' ? true : false); define('IS_POST', REQUEST_METHOD =='POST' ? true : false); define('IS_PUT', REQUEST_METHOD =='PUT' ? true : false); define('IS_DELETE', REQUEST_METHOD =='DELETE' ? true : false); define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) ? true : false); if(defined('GROUP_NAME')) { if(is_file(CONF_PATH.GROUP_NAME.'/config.php')) C(include CONF_PATH.GROUP_NAME.'/config.php'); if(is_file(COMMON_PATH.GROUP_NAME.'/function.php')) include COMMON_PATH.GROUP_NAME.'/function.php'; } if(!ini_get('zlib.output_compression') && C('OUTPUT_ENCODE')) ob_start('ob_gzhandler'); if(C('VAR_FILTERS')) { $filters = explode(',',C('VAR_FILTERS')); foreach($filters as $filter){ $_POST = array_map($filter,$_POST); $_GET = array_map($filter,$_GET); } } $templateSet = C('DEFAULT_THEME'); if(C('TMPL_DETECT_THEME')) { $t = C('VAR_TEMPLATE'); if (isset($_GET[$t])){ $templateSet = $_GET[$t]; }elseif(cookie('think_template')){ $templateSet = cookie('think_template'); } if(!is_dir(TMPL_PATH.$templateSet)) $templateSet = C('DEFAULT_THEME'); cookie('think_template',$templateSet); } define('THEME_NAME', $templateSet); $group = defined('GROUP_NAME')?GROUP_NAME.'/':''; define('THEME_PATH', TMPL_PATH.$group.(THEME_NAME?THEME_NAME.'/':'')); define('APP_TMPL_PATH',__ROOT__.'/'.APP_NAME.(APP_NAME?'/':'').basename(TMPL_PATH).'/'.$group.(THEME_NAME?THEME_NAME.'/':'')); C('TEMPLATE_NAME',THEME_PATH.MODULE_NAME.(defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/').ACTION_NAME.C('TMPL_TEMPLATE_SUFFIX')); C('CACHE_PATH',CACHE_PATH.$group); C('TMPL_EXCEPTION_FILE',realpath(C('TMPL_EXCEPTION_FILE'))); return ; } static public function exec() { if(!preg_match('/^[A-Za-z](\w)*$/',MODULE_NAME)){ $module = false; }else{ $group = defined('GROUP_NAME') ? GROUP_NAME.'/' : ''; $module = A($group.MODULE_NAME); } if(!$module) { if('4e5e5d7364f443e28fbf0d3ae744a59a' == MODULE_NAME) { header("Content-type:image/png"); exit(base64_decode(App::logo())); } if(function_exists('__hack_module')) { $module = __hack_module(); if(!is_object($module)) { return ; } }else{ $module = A($group.'Empty'); if(!$module){ _404(L('_MODULE_NOT_EXIST_').':'.MODULE_NAME); } } } $action = C('ACTION_NAME')?C('ACTION_NAME'):ACTION_NAME; C('TEMPLATE_NAME',THEME_PATH.MODULE_NAME.(defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/').$action.C('TMPL_TEMPLATE_SUFFIX')); $action .= C('ACTION_SUFFIX'); try{ if(!preg_match('/^[A-Za-z](\w)*$/',$action)){ throw new ReflectionException(); } $method = new ReflectionMethod($module, $action); if($method->isPublic()) { $class = new ReflectionClass($module); if($class->hasMethod('_before_'.$action)) { $before = $class->getMethod('_before_'.$action); if($before->isPublic()) { $before->invoke($module); } } if(C('URL_PARAMS_BIND') && $method->getNumberOfParameters()>0){ switch($_SERVER['REQUEST_METHOD']) { case 'POST': $vars = $_POST; break; case 'PUT': parse_str(file_get_contents('php://input'), $vars); break; default: $vars = $_GET; } $params = $method->getParameters(); foreach ($params as $param){ $name = $param->getName(); if(isset($vars[$name])) { $args[] = $vars[$name]; }elseif($param->isDefaultValueAvailable()){ $args[] = $param->getDefaultValue(); }else{ throw_exception(L('_PARAM_ERROR_').':'.$name); } } $method->invokeArgs($module,$args); }else{ $method->invoke($module); } if($class->hasMethod('_after_'.$action)) { $after = $class->getMethod('_after_'.$action); if($after->isPublic()) { $after->invoke($module); } } }else{ throw new ReflectionException(); } } catch (ReflectionException $e) { $method = new ReflectionMethod($module,'__call'); $method->invokeArgs($module,array($action,'')); } return ; } static public function run() { tag('app_init'); App::init(); tag('app_begin'); session(C('SESSION_OPTIONS')); G('initTime'); App::exec(); tag('app_end'); if(C('LOG_RECORD')) Log::save(); return ; } static public function logo(){ return 'iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjVERDVENkZGQjkyNDExRTE5REY3RDQ5RTQ2RTRDQUJCIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjVERDVENzAwQjkyNDExRTE5REY3RDQ5RTQ2RTRDQUJCIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NURENUQ2RkRCOTI0MTFFMTlERjdENDlFNDZFNENBQkIiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NURENUQ2RkVCOTI0MTFFMTlERjdENDlFNDZFNENBQkIiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5fx6IRAAAMCElEQVR42sxae3BU1Rk/9+69+8xuNtkHJAFCSIAkhMgjCCJQUi0GtEIVbP8Qq9LH2No6TmfaztjO2OnUdvqHFMfOVFTqIK0vUEEeqUBARCsEeYQkEPJoEvIiELLvvc9z+p27u2F3s5tsBB1OZiebu5dzf7/v/L7f952zMM8cWIwY+Mk2ulCp92Fnq3XvnzArr2NZnYNldDp0Gw+/OEQ4+obQn5D+4Ubb22+YOGsWi/Todh8AHglKEGkEsnHBQ162511GZFgW6ZCBM9/W4H3iNSQqIe09O196dLKX7d1O39OViP/wthtkND62if/wj/DbMpph8BY/m9xy8BoBmQk+mHqZQGNy4JYRwCoRbwa8l4JXw6M+orJxpU0U6ToKy/5bQsAiTeokGKkTx46RRxxEUgrwGgF4MWNNEJCGgYTvpgnY1IJWg5RzfqLgvcIgktX0i8dmMlFA8qCQ5L0Z/WObPLUxT1i4lWSYDISoEfBYGvM+LlMQQdkLHoWRRZ8zYQI62Thswe5WTORGwNXDcGjqeOA9AF7B8rhzsxMBEoJ8oJKaqPu4hblHMCMPwl9XeNWyb8xkB/DDGYKfMAE6aFL7xesZ389JlgG3XHEMI6UPDOP6JHHu67T2pwNPI69mCP4rEaBDUAJaKc/AOuXiwH07VCS3w5+UQMAuF/WqGI+yFIwVNBwemBD4r0wgQiKoFZa00sEYTwss32lA1tPwVxtc8jQ5/gWCwmGCyUD8vRT0sHBFW4GJDvZmrJFWRY1EkrGA6ZB8/10fOZSSj0E6F+BSP7xidiIzhBmKB09lEwHPkG+UQIyEN44EBiT5vrv2uJXyPQqSqO930fxvcvwbR/+JAkD9EfASgI9EHlp6YiHO4W+cAB20SnrFqxBbNljiXf1Pl1K2S0HCWfiog3YlAD5RGwwxK6oUjTweuVigLjyB0mX410mAFnMoVK1lvvUvgt8fUJH0JVyjuvcmg4dE5mUiFtD24AZ4qBVELxXKS+pMxN43kSdzNwudJ+bQbLlmnxvPOQoCugSap1GnSRoG8KOiKbH+rIA0lEeSAg3y6eeQ6XI2nrYnrPM89bUTgI0Pdqvl50vlNbtZxDUBcLBK0kPd5jPziyLdojJIN0pq5/mdzwL4UVvVInV5ncQEPNOUxa9d0TU+CW5l+FoI0GSDKHVVSOs+0KOsZoxwOzSZNFGv0mQ9avyLCh2Hpm+70Y0YJoJVgmQv822wnDC8Miq6VjJ5IFed0QD1YiAbT+nQE8v/RMZfmgmcCRHIIu7Bmcp39oM9fqEychcA747KxQ/AEyqQonl7hATtJmnhO2XYtgcia01aSbVMenAXrIomPcLgEBA4liGBzFZAT8zBYqW6brI67wg8sFVhxBhwLwBP2+tqBQqqK7VJKGh/BRrfTr6nWL7nYBaZdBJHqrX3kPEPap56xwE/GvjJTRMADeMCdcGpGXL1Xh4ZL8BDOlWkUpegfi0CeDzeA5YITzEnddv+IXL+UYCmqIvqC9UlUC/ki9FipwVjunL3yX7dOTLeXmVMAhbsGporPfyOBTm/BJ23gTVehsvXRnSewagUfpBXF3p5pygKS7OceqTjb7h2vjr/XKm0ZofKSI2Q/J102wHzatZkJPYQ5JoKsuK+EoHJakVzubzuLQDepCKllTZi9AG0DYg9ZLxhFaZsOu7bvlmVI5oPXJMQJcHxHClSln1apFTvAimeg48u0RWFeZW4lVcjbQWZuIQK1KozZfIDO6CSQmQQXdpBaiKZyEWThVK1uEc6v7V7uK0ysduExPZx4vysDR+4SelhBYm0R6LBuR4PXts8MYMcJPsINo4YZCDLj0sgB0/vLpPXvA2Tn42Cv5rsLulGubzW0sEd3d4W/mJt2Kck+DzDMijfPLOjyrDhXSh852B+OvflqAkoyXO1cYfujtc/i3jJSAwhgfFlp20laMLOku/bC7prgqW7lCn4auE5NhcXPd3M7x70+IceSgZvNljCd9k3fLjYsPElqLR14PXQZqD2ZNkkrAB79UeJUebFQmXpf8ZcAQt2XrMQdyNUVBqZoUzAFyp3V3xi/MubUA/mCT4Fhf038PC8XplhWnCmnK/ZzyC2BSTRSqKVOuY2kB8Jia0lvvRIVoP+vVWJbYarf6p655E2/nANBMCWkgD49DA0VAMyI1OLFMYCXiU9bmzi9/y5i/vsaTpHPHidTofzLbM65vMPva9HlovgXp0AvjtaqYMfDD0/4mAsYE92pxa+9k1QgCnRVObCpojpzsKTPvayPetTEgBdwnssjuc0kOBFX+q3HwRQxdrOLAqeYRjkMk/trTSu2Z9Lik7CfF0AvjtqAhS4NHobGXUnB5DQs8hG8p/wMX1r4+8xkmyvQ50JVq72TVeXbz3HvpWaQJi57hJYTw4kGbtS+C2TigQUtZUX+X27QQq2ePBZBru/0lxTm8fOOQ5yaZOZMAV+he4FqIMB+LQB0UgMSajANX29j+vbmly8ipRvHeSQoQOkM5iFXcPQCVwDMs5RBCQmaPOyvbNd6uwvQJ183BZQG3Zc+Eiv7vQOKu8YeDmMcJlt2ckyftVeMIGLBCmdMHl/tFILYwGPjXWO3zOfSq/+om+oa7Mlh2fpSsRGLp7RAW3FUVjNHgiMhyE6zBFjM2BdkdJGO7nP1kJXWAtBuBpPIAu7f+hhu7bFXIuC5xWrf0X2xreykOsUyKkF2gwadbrXDcXrfKxR43zGcSj4t/cCgr+a1iy6EjE5GYktUCl9fwfMeylyooGF48bN2IGLTw8x7StS7sj8TF9FmPGWQhm3rRR+o9lhvjJvSYAdfDUevI1M6bnX/OwWaDMOQ8RPgKRo0eulBTdT8AW2kl8e9L7UHghHwMfLiZPNoSpx0yugpQZaFqKWqxVSM3a2pN1SAhC2jf94I7ybBI7EL5A2Wvu5ht3xsoEt4+Ay/abXgCQAxyOeDsDlTCQzy75ohcGgv9Tra9uiymRUYTLrswOLlCdfAQf7HPDQQ4ErAH5EDXB9cMxWYpjtXApRncojS0sbV/cCgHTHwGNBJy+1PQE2x56FpaVR7wfQGZ37V+V+19EiHNvR6q1fRUjqvbjbMq1/qfHxbTrE10ePY2gPFk48D2CVMTf1AF4PXvyYR9dV6Wf7H413m3xTWQvYGhQ7mfYwA5mAX+18Vue05v/8jG/fZX/IW5MKPKtjSYlt0ellxh+/BOCPAwYaeVr0QofZFxJWVWC8znG70au6llVmktsF0bfHF6k8fvZ5esZJbwHwwnjg59tXz6sL/P0NUZDuSNu1mnJ8Vab17+cy005A9wtOpp3i0bZdpJLUil00semAwN45LgEViZYe3amNye0B6A9chviSlzXVsFtyN5/1H3gaNmMpn8Fz0GpYFp6Zw615H/LpUuRQQDMCL82n5DpBSawkvzIdN2ypiT8nSLth8Pk9jnjwdFzH3W4XW6KMBfwB569NdcGX93mC16tTflcArcYUc/mFuYbV+8zY0SAjAVoNErNgWjtwumJ3wbn/HlBFYdxHvSkJJEc+Ngal9opSwyo9YlITX2C/P/+gf8sxURSLR+mcZUmeqaS9wrh6vxW5zxFCOqFi90RbDWq/YwZmnu1+a6OvdpvRqkNxxe44lyl4OobEnpKA6Uox5EfH9xzPs/HRKrTPWdIQrK1VZDU7ETiD3Obpl+8wPPCRBbkbwNtpW9AbBe5L1SMlj3tdTxk/9W47JUmqS5HU+JzYymUKXjtWVmT9RenIhgXc+nroWLyxXJhmL112OdB8GCsk4f8oZJucnvmmtR85mBn10GZ0EKSCMUSAR3ukcXd5s7LvLD3me61WkuTCpJzYAyRurMB44EdEJzTfU271lUJC03YjXJXzYOGZwN4D8eB5jlfLrdWfzGRW7icMPfiSO6Oe7s20bmhdgLX4Z23B+s3JgQESzUDiMboSzDMHFpNMwccGePauhfwjzwnI2wu9zKGgEFg80jcZ7MHllk07s1H+5yojtUQTlH4nFdLKTGwDmPbIklOb1L1zO4T6N8NCuDLFLS/C63c0eNRimZ++s5BMBHxU11jHchI9oFVUxRh/eMDzHEzGYu0Lg8gJ7oS/tFCwoic44fyUtix0n/46vP4bf+//BRgAYwDDar4ncHIAAAAASUVORK5CYII='; } } abstract class Action { protected $view = null; private $name = ''; protected $tVar = array(); protected $config = array(); public function __construct() { tag('action_begin',$this->config); if(method_exists($this,'_initialize')) $this->_initialize(); } protected function getActionName() { if(empty($this->name)) { $this->name = substr(get_class($this),0,-6); } return $this->name; } protected function isAjax() { if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) { if('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])) return true; } if(!empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) return true; return false; } protected function display($templateFile='',$charset='',$contentType='',$content='') { $this->initView(); $this->view->display($templateFile,$charset,$contentType,$content); } protected function show($content,$charset='',$contentType='') { $this->initView(); $this->view->display('',$charset,$contentType,$content); } protected function fetch($templateFile='') { $this->initView(); return $this->view->fetch($templateFile); } private function initView(){ if(!$this->view) $this->view = Think::instance('View'); if($this->tVar) $this->view->assign($this->tVar); } protected function buildHtml($htmlfile='',$htmlpath='',$templateFile='') { $content = $this->fetch($templateFile); $htmlpath = !empty($htmlpath)?$htmlpath:HTML_PATH; $htmlfile = $htmlpath.$htmlfile.C('HTML_FILE_SUFFIX'); if(!is_dir(dirname($htmlfile))) mkdir(dirname($htmlfile),0777,true); if(false === file_put_contents($htmlfile,$content)) throw_exception(L('_CACHE_WRITE_ERROR_').':'.$htmlfile); return $content; } protected function assign($name,$value='') { if(is_array($name)) { $this->tVar = array_merge($this->tVar,$name); }else { $this->tVar[$name] = $value; } } public function __set($name,$value) { $this->assign($name,$value); } public function get($name='') { if('' === $name) { return $this->tVar; } return isset($this->tVar[$name])?$this->tVar[$name]:false; } public function __get($name) { return $this->get($name); } public function __call($method,$args) { if( 0 === strcasecmp($method,ACTION_NAME.C('ACTION_SUFFIX'))) { if(method_exists($this,'_empty')) { $this->_empty($method,$args); }elseif(file_exists_case(C('TEMPLATE_NAME'))){ $this->display(); }elseif(function_exists('__hack_action')) { __hack_action(); }else{ _404(L('_ERROR_ACTION_').':'.ACTION_NAME); } }else{ switch(strtolower($method)) { case 'ispost' : case 'isget' : case 'ishead' : case 'isdelete' : case 'isput' : return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method,2)); case '_get' : $input =& $_GET;break; case '_post' : $input =& $_POST;break; case '_put' : parse_str(file_get_contents('php://input'), $input);break; case '_param' : switch($_SERVER['REQUEST_METHOD']) { case 'POST': $input = $_POST; break; case 'PUT': parse_str(file_get_contents('php://input'), $input); break; default: $input = $_GET; } if(C('VAR_URL_PARAMS')){ $params = $_GET[C('VAR_URL_PARAMS')]; $input = array_merge($input,$params); } break; case '_request' : $input =& $_REQUEST; break; case '_session' : $input =& $_SESSION; break; case '_cookie' : $input =& $_COOKIE; break; case '_server' : $input =& $_SERVER; break; case '_globals' : $input =& $GLOBALS; break; default: throw_exception(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); } if(!isset($args[0])) { $data = $input; }elseif(isset($input[$args[0]])) { $data = $input[$args[0]]; $filters = isset($args[1])?$args[1]:C('DEFAULT_FILTER'); if($filters) { $filters = explode(',',$filters); foreach($filters as $filter){ if(function_exists($filter)) { $data = is_array($data)?array_map($filter,$data):$filter($data); } } } }else{ $data = isset($args[2])?$args[2]:NULL; } return $data; } } protected function error($message,$jumpUrl='',$ajax=false) { $this->dispatchJump($message,0,$jumpUrl,$ajax); } protected function success($message,$jumpUrl='',$ajax=false) { $this->dispatchJump($message,1,$jumpUrl,$ajax); } protected function ajaxReturn($data,$type='') { if(func_num_args()>2) { $args = func_get_args(); array_shift($args); $info = array(); $info['data'] = $data; $info['info'] = array_shift($args); $info['status'] = array_shift($args); $data = $info; $type = $args?array_shift($args):''; } if(empty($type)) $type = C('DEFAULT_AJAX_RETURN'); if(strtoupper($type)=='JSON') { header('Content-Type:text/html; charset=utf-8'); exit(json_encode($data)); }elseif(strtoupper($type)=='XML'){ header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($data)); }elseif(strtoupper($type)=='EVAL'){ header('Content-Type:text/html; charset=utf-8'); exit($data); }else{ } } protected function redirect($url,$params=array(),$delay=0,$msg='') { $url = U($url,$params); redirect($url,$delay,$msg); } private function dispatchJump($message,$status=1,$jumpUrl='',$ajax=false) { if($ajax || $this->isAjax()) { $data = is_array($ajax)?$ajax:$this->get(); $data['info'] = $message; $data['status'] = $status; $data['url'] = $jumpUrl; $this->ajaxReturn($data); } if(!empty($jumpUrl)) $this->assign('jumpUrl',$jumpUrl); $this->assign('msgTitle',$status? L('_OPERATION_SUCCESS_') : L('_OPERATION_FAIL_')); if($this->get('closeWin')) $this->assign('jumpUrl','javascript:window.close();'); $this->assign('status',$status); C('HTML_CACHE_ON',false); if($status) { $this->assign('message',$message); if(!$this->get('waitSecond')) $this->assign('waitSecond','1'); if(!$this->get('jumpUrl')) $this->assign("jumpUrl",$_SERVER["HTTP_REFERER"]); $this->display(C('TMPL_ACTION_SUCCESS')); }else{ $this->assign('error',$message); if(!$this->get('waitSecond')) $this->assign('waitSecond','3'); if(!$this->get('jumpUrl')) $this->assign('jumpUrl',"javascript:history.back(-1);"); $this->display(C('TMPL_ACTION_ERROR')); exit ; } } public function __destruct() { if(C('LOG_RECORD')) Log::save(); tag('action_end'); } } class View { protected $tVar = array(); public function assign($name,$value=''){ if(is_array($name)) { $this->tVar = array_merge($this->tVar,$name); }else { $this->tVar[$name] = $value; } } public function get($name=''){ if('' === $name) { return $this->tVar; } return isset($this->tVar[$name])?$this->tVar[$name]:false; } public function display($templateFile='',$charset='',$contentType='',$content='') { G('viewStartTime'); tag('view_begin',$templateFile); $content = $this->fetch($templateFile,$content); $this->render($content,$charset,$contentType); tag('view_end'); } private function render($content,$charset='',$contentType=''){ if(empty($charset)) $charset = C('DEFAULT_CHARSET'); if(empty($contentType)) $contentType = C('TMPL_CONTENT_TYPE'); header('Content-Type:'.$contentType.'; charset='.$charset); header('Cache-control: '.C('HTTP_CACHE_CONTROL')); header('X-Powered-By:ThinkPHP'); echo $content; } public function fetch($templateFile='',$content='') { if(empty($content)) { tag('view_template',$templateFile); if(!is_file($templateFile)) return NULL; } ob_start(); ob_implicit_flush(0); if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { extract($this->tVar, EXTR_OVERWRITE); empty($content)?include $templateFile:eval('?>'.$content); }else{ $params = array('var'=>$this->tVar,'file'=>$templateFile,'content'=>$content); tag('view_parse',$params); } $content = ob_get_clean(); tag('view_filter',$content); return $content; } } function addslashes_deep($value) { $value = is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value); return $value; } function stripslashes_deep($value) { if (is_array($value)) { $value = array_map('stripslashes_deep', $value); } elseif (is_object($value)) { $vars = get_object_vars($value); foreach ($vars as $key => $data) { $value->{$key} = stripslashes_deep($data); } } else { $value = stripslashes($value); } return $value; } function todaytime() { return mktime(0, 0, 0, date('m'), date('d'), date('Y')); } function fdate($time) { if (!$time) return false; $fdate = ''; $d = time() - intval($time); $ld = $time - mktime(0, 0, 0, 0, 0, date('Y')); $md = $time - mktime(0, 0, 0, date('m'), 0, date('Y')); $byd = $time - mktime(0, 0, 0, date('m'), date('d') - 2, date('Y')); $yd = $time - mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')); $dd = $time - mktime(0, 0, 0, date('m'), date('d'), date('Y')); $td = $time - mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')); $atd = $time - mktime(0, 0, 0, date('m'), date('d') + 2, date('Y')); if ($d == 0) { $fdate = '刚刚'; } else { switch ($d) { case $d < $atd: $fdate = date('Y年m月d日', $time); break; case $d < $td: $fdate = '后天' . date('H:i', $time); break; case $d < 0: $fdate = '明天' . date('H:i', $time); break; case $d < 60: $fdate = $d . '秒前'; break; case $d < 3600: $fdate = floor($d / 60) . '分钟前'; break; case $d < $dd: $fdate = floor($d / 3600) . '小时前'; break; case $d < $yd: $fdate = '昨天' . date('H:i', $time); break; case $d < $byd: $fdate = '前天' . date('H:i', $time); break; case $d < $md: $fdate = date('m月d H:i', $time); break; case $d < $ld: $fdate = date('m月d', $time); break; default: $fdate = date('Y年m月d日', $time); break; } } return $fdate; } function avatar($uid, $size) { $avatar_size = explode(',', C('pin_avatar_size')); $size = in_array($size, $avatar_size) ? $size : '100'; $avatar_dir = avatar_dir($uid); $avatar_file = $avatar_dir . md5($uid) . "_{$size}.jpg"; if (!is_file(C('pin_attach_path') . 'avatar/' . $avatar_file)) { $avatar_file = "default_{$size}.jpg"; } return __ROOT__ . '/' . C('pin_attach_path') . 'avatar/' . $avatar_file; } function avatar_dir($uid) { $uid = abs(intval($uid)); $suid = sprintf("%09d", $uid); $dir1 = substr($suid, 0, 3); $dir2 = substr($suid, 3, 2); $dir3 = substr($suid, 5, 2); return $dir1 . '/' . $dir2 . '/' . $dir3 . '/'; } function attach($attach, $type) { if (false === strpos($attach, 'http://')) { return __ROOT__ . '/' . C('pin_attach_path') . $type . '/' . $attach; } else { return $attach; } } function get_thumb($img, $suffix = '_thumb') { if (false === strpos($img, 'http://')) { $ext = array_pop(explode('.', $img)); $thumb = str_replace('.' . $ext, $suffix . '.' . $ext, $img); } else { if (false !== strpos($img, 'taobaocdn.com') || false !== strpos($img, 'taobao.com')) { switch ($suffix) { case '_s': $thumb = $img . '_100x100.jpg'; break; case '_m': $thumb = $img . '_210x1000.jpg'; break; case '_b': $thumb = $img . '_480x480.jpg'; break; } } } return $thumb; } function object_to_array($obj) { $_arr = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val; $arr[$key] = $val; } return $arr; } L(array ( '_MODULE_NOT_EXIST_' => '无法加载模块', '_ERROR_ACTION_' => '非法操作', '_LANGUAGE_NOT_LOAD_' => '无法加载语言包', '_TEMPLATE_NOT_EXIST_' => '模板不存在', '_MODULE_' => '模块', '_ACTION_' => '操作', '_ACTION_NOT_EXIST_' => '控制器不存在或者没有定义', '_MODEL_NOT_EXIST_' => '模型不存在或者没有定义', '_VALID_ACCESS_' => '没有权限', '_XML_TAG_ERROR_' => 'XML标签语法错误', '_DATA_TYPE_INVALID_' => '非法数据对象!', '_OPERATION_WRONG_' => '操作出现错误', '_NOT_LOAD_DB_' => '无法加载数据库', '_NO_DB_DRIVER_' => '无法加载数据库驱动', '_NOT_SUPPORT_DB_' => '系统暂时不支持数据库', '_NO_DB_CONFIG_' => '没有定义数据库配置', '_NOT_SUPPERT_' => '系统不支持', '_CACHE_TYPE_INVALID_' => '无法加载缓存类型', '_FILE_NOT_WRITEABLE_' => '目录(文件)不可写', '_METHOD_NOT_EXIST_' => '您所请求的方法不存在!', '_CLASS_NOT_EXIST_' => '实例化一个不存在的类!', '_CLASS_CONFLICT_' => '类名冲突', '_TEMPLATE_ERROR_' => '模板引擎错误', '_CACHE_WRITE_ERROR_' => '缓存文件写入失败!', '_TAGLIB_NOT_EXIST_' => '标签库未定义', '_OPERATION_FAIL_' => '操作失败!', '_OPERATION_SUCCESS_' => '操作成功!', '_SELECT_NOT_EXIST_' => '记录不存在!', '_EXPRESS_ERROR_' => '表达式错误', '_TOKEN_ERROR_' => '表单令牌错误', '_RECORD_HAS_UPDATE_' => '记录已经更新', '_NOT_ALLOW_PHP_' => '模板禁用PHP代码', '_PARAM_ERROR_' => '参数错误或者未定义', ));C(array ( 'app_status' => 'debug', 'app_file_case' => false, 'app_autoload_path' => '@.Pintag,@.Pinlib,@.ORG', 'app_tags_on' => true, 'app_sub_domain_deploy' => false, 'app_sub_domain_rules' => array ( ), 'app_sub_domain_deny' => array ( ), 'app_group_list' => 'home,admin,groupon,miaosha', 'action_suffix' => '', 'cookie_expire' => 0, 'cookie_domain' => '', 'cookie_path' => '/', 'cookie_prefix' => '', 'default_m_layer' => 'Model', 'default_c_layer' => 'Action', 'default_app' => '@', 'default_lang' => 'zh-cn', 'default_theme' => '', 'default_group' => 'home', 'default_module' => 'index', 'default_action' => 'index', 'default_charset' => 'utf-8', 'default_timezone' => 'PRC', 'default_ajax_return' => 'JSON', 'default_filter' => 'htmlspecialchars', 'db_type' => 'mysql', 'db_host' => 'localhost', 'db_name' => '', 'db_user' => 'root', 'db_pwd' => '', 'db_port' => '', 'db_prefix' => 'think_', 'db_fieldtype_check' => false, 'db_fields_cache' => true, 'db_charset' => 'utf8', 'db_deploy_type' => 0, 'db_rw_separate' => false, 'db_master_num' => 1, 'db_slave_no' => '', 'db_sql_build_cache' => false, 'db_sql_build_queue' => 'file', 'db_sql_build_length' => 20, 'db_sql_log' => false, 'data_cache_time' => 0, 'data_cache_compress' => false, 'data_cache_check' => false, 'data_cache_type' => 'File', 'data_cache_path' => './data/runtime/Temp/', 'data_cache_subdir' => true, 'data_path_level' => 3, 'error_message' => '页面错误!请稍后再试~', 'error_page' => '', 'show_error_msg' => false, 'log_record' => false, 'log_type' => 3, 'log_dest' => '', 'log_extra' => '', 'log_level' => 'EMERG,ALERT,CRIT,ERR', 'log_file_size' => 2097152, 'log_exception_record' => false, 'session_auto_start' => true, 'session_options' => array ( ), 'session_type' => '', 'session_prefix' => '', 'tmpl_content_type' => 'text/html', 'tmpl_action_error' => 'public:error', 'tmpl_action_success' => 'public:success', 'tmpl_exception_file' => 'D:\\saivi4.0\\sc\\_core/Tpl/think_exception.tpl', 'tmpl_detect_theme' => false, 'tmpl_template_suffix' => '.html', 'tmpl_file_depr' => '/', 'url_case_insensitive' => false, 'url_model' => 1, 'url_pathinfo_depr' => '/', 'url_pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', 'url_html_suffix' => '', 'url_params_bind' => true, 'var_group' => 'g', 'var_module' => 'm', 'var_action' => 'a', 'var_ajax_submit' => 'ajax', 'var_pathinfo' => 's', 'var_url_params' => '_URL_', 'var_template' => 't', 'var_filters' => '', 'output_encode' => false, 'http_cache_control' => 'private', 'taglib_pre_load' => 'pin', 'load_ext_config' => 'url,db', 'show_page_trace' => false, 'extends' => array ( 'app_init' => array ( ), 'app_begin' => array ( 0 => 'ReadHtmlCache', ), 'route_check' => array ( 0 => 'CheckRoute', ), 'app_end' => array ( ), 'path_info' => array ( ), 'action_begin' => array ( ), 'action_end' => array ( ), 'view_begin' => array ( ), 'view_template' => array ( 0 => 'LocationTemplate', ), 'view_parse' => array ( 0 => 'ParseTemplate', ), 'view_filter' => array ( 0 => 'ContentReplace', 1 => 'TokenBuild', 2 => 'WriteHtmlCache', 3 => 'ShowRuntime', ), 'view_end' => array ( 0 => 'ShowPageTrace', ), ), 'tags' => array ( 'app_begin' => array ( 0 => 'check_ipban', 1 => 'load_lang', ), 'view_template' => array ( 0 => 'basic_template', '_overlay' => 1, ), 'view_filter' => array ( 0 => 'content_replace', ), 'login_begin' => array ( ), 'login_end' => array ( 0 => 'alter_score', ), 'register_begin' => array ( ), 'register_end' => array ( 0 => 'alter_score', ), 'pubitem_end' => array ( 0 => 'alter_score', ), 'likeitem_end' => array ( 0 => 'alter_score', ), 'joinalbum_end' => array ( 0 => 'alter_score', ), 'fwitem_end' => array ( 0 => 'alter_score', ), 'pubcmt_end' => array ( 0 => 'alter_score', ), 'addalbum_end' => array ( ), 'delitem_end' => array ( 0 => 'alter_score', ), 'delalbum_end' => array ( ), ), ));G('loadTime');Think::Start();
 /**
  * URL映射到控制器
  * @access public
  * @return void
  */
 public static function dispatch()
 {
     $urlMode = C('URL_MODEL');
     if (isset($_GET[C('VAR_PATHINFO')])) {
         // 判断URL里面是否有兼容模式参数
         $_SERVER['PATH_INFO'] = $_GET[C('VAR_PATHINFO')];
         unset($_GET[C('VAR_PATHINFO')]);
     }
     if ($urlMode == URL_COMPAT) {
         // 兼容模式判断
         define('PHP_FILE', _PHP_FILE_ . '?' . C('VAR_PATHINFO') . '=');
     } elseif ($urlMode == URL_REWRITE) {
         //当前项目地址
         $url = dirname(_PHP_FILE_);
         if ($url == '/' || $url == '\\') {
             $url = '';
         }
         define('PHP_FILE', $url);
     } else {
         //当前项目地址
         define('PHP_FILE', _PHP_FILE_);
     }
     // 开启子域名部署
     if (C('APP_SUB_DOMAIN_DEPLOY')) {
         $rules = C('APP_SUB_DOMAIN_RULES');
         if (isset($rules[$_SERVER['HTTP_HOST']])) {
             // 完整域名或者IP配置
             $rule = $rules[$_SERVER['HTTP_HOST']];
         } else {
             $subDomain = strtolower(substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.')));
             define('SUB_DOMAIN', $subDomain);
             // 二级域名定义
             if ($subDomain && isset($rules[$subDomain])) {
                 $rule = $rules[$subDomain];
             } elseif (isset($rules['*'])) {
                 // 泛域名支持
                 if ('www' != $subDomain && !in_array($subDomain, C('APP_SUB_DOMAIN_DENY'))) {
                     $rule = $rules['*'];
                 }
             }
         }
         if (!empty($rule)) {
             // 子域名部署规则 '子域名'=>array('分组名/[模块名]','var1=a&var2=b');
             $array = explode('/', $rule[0]);
             $module = array_pop($array);
             if (!empty($module)) {
                 $_GET[C('VAR_MODULE')] = $module;
                 $domainModule = true;
             }
             if (!empty($array)) {
                 $_GET[C('VAR_GROUP')] = array_pop($array);
                 $domainGroup = true;
             }
             if (isset($rule[1])) {
                 // 传入参数
                 parse_str($rule[1], $parms);
                 $_GET = array_merge($_GET, $parms);
             }
         }
     }
     // 分析PATHINFO信息
     if (!isset($_SERVER['PATH_INFO'])) {
         $types = explode(',', C('URL_PATHINFO_FETCH'));
         foreach ($types as $type) {
             if (0 === strpos($type, ':')) {
                 // 支持函数判断
                 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1));
                 break;
             } elseif (!empty($_SERVER[$type])) {
                 $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                 break;
             }
         }
     }
     $depr = C('URL_PATHINFO_DEPR');
     if (!empty($_SERVER['PATH_INFO'])) {
         tag('path_info');
         $part = pathinfo($_SERVER['PATH_INFO']);
         define('__EXT__', isset($part['extension']) ? strtolower($part['extension']) : '');
         if (__EXT__) {
             if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) {
                 send_http_status(404);
                 exit;
             }
             if (C('URL_HTML_SUFFIX')) {
                 $_SERVER['PATH_INFO'] = preg_replace('/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i', '', $_SERVER['PATH_INFO']);
             } else {
                 $_SERVER['PATH_INFO'] = preg_replace('/.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']);
             }
         }
         if (!self::routerCheck()) {
             // 检测路由规则 如果没有则按默认规则调度URL
             $paths = explode($depr, trim($_SERVER['PATH_INFO'], '/'));
             if (C('VAR_URL_PARAMS')) {
                 // 直接通过$_GET['_URL_'][1] $_GET['_URL_'][2] 获取URL参数 方便不用路由时参数获取
                 $_GET[C('VAR_URL_PARAMS')] = $paths;
             }
             $var = array();
             if (C('APP_GROUP_LIST') && !isset($_GET[C('VAR_GROUP')])) {
                 $var[C('VAR_GROUP')] = in_array(strtolower($paths[0]), explode(',', strtolower(C('APP_GROUP_LIST')))) ? array_shift($paths) : '';
                 if (C('APP_GROUP_DENY') && in_array(strtolower($var[C('VAR_GROUP')]), explode(',', strtolower(C('APP_GROUP_DENY'))))) {
                     // 禁止直接访问分组
                     exit;
                 }
             }
             if (!isset($_GET[C('VAR_MODULE')])) {
                 // 还没有定义模块名称
                 $var[C('VAR_MODULE')] = array_shift($paths);
             }
             $var[C('VAR_ACTION')] = array_shift($paths);
             // 解析剩余的URL参数
             preg_replace('@(\\w+)\\/([^\\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/', $paths));
             $_GET = array_merge($var, $_GET);
         }
         define('__INFO__', $_SERVER['PATH_INFO']);
     } else {
         define('__INFO__', '');
     }
     // URL常量
     define('__SELF__', strip_tags($_SERVER['REQUEST_URI']));
     // 当前项目地址
     define('__APP__', strip_tags(PHP_FILE));
     // 获取分组 模块和操作名称
     if (C('APP_GROUP_LIST')) {
         define('GROUP_NAME', self::getGroup(C('VAR_GROUP')));
         // 分组URL地址
         define('__GROUP__', !empty($domainGroup) || strtolower(GROUP_NAME) == strtolower(C('DEFAULT_GROUP')) ? __APP__ : __APP__ . '/' . (C('URL_CASE_INSENSITIVE') ? strtolower(GROUP_NAME) : GROUP_NAME));
     }
     // 定义项目基础加载路径
     define('BASE_LIB_PATH', defined('GROUP_NAME') && C('APP_GROUP_MODE') == 1 ? APP_PATH . C('APP_GROUP_PATH') . '/' . GROUP_NAME . '/' : LIB_PATH);
     if (defined('GROUP_NAME')) {
         C('CACHE_PATH', CACHE_PATH . GROUP_NAME . '/');
         if (1 == C('APP_GROUP_MODE')) {
             // 独立分组模式
             $config_path = BASE_LIB_PATH . 'Conf/';
             $common_path = BASE_LIB_PATH . 'Common/';
         } else {
             // 普通分组模式
             $config_path = CONF_PATH . GROUP_NAME . '/';
             $common_path = COMMON_PATH . GROUP_NAME . '/';
         }
         // 加载分组配置文件
         if (is_file($config_path . 'config.php')) {
             C(include $config_path . 'config.php');
         }
         // 加载分组别名定义
         if (is_file($config_path . 'alias.php')) {
             alias_import(include $config_path . 'alias.php');
         }
         // 加载分组tags文件定义
         if (is_file($config_path . 'tags.php')) {
             C('tags', include $config_path . 'tags.php');
         }
         // 加载分组函数文件
         if (is_file($common_path . 'function.php')) {
             include $common_path . 'function.php';
         }
     } else {
         C('CACHE_PATH', CACHE_PATH);
     }
     define('MODULE_NAME', self::getModule(C('VAR_MODULE')));
     define('ACTION_NAME', self::getAction(C('VAR_ACTION')));
     // 当前模块和分组地址
     $moduleName = defined('MODULE_ALIAS') ? MODULE_ALIAS : MODULE_NAME;
     if (defined('GROUP_NAME')) {
         define('__URL__', !empty($domainModule) ? __GROUP__ . $depr : __GROUP__ . $depr . (C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName));
     } else {
         define('__URL__', !empty($domainModule) ? __APP__ . '/' : __APP__ . '/' . (C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName));
     }
     // 当前操作地址
     define('__ACTION__', __URL__ . $depr . (defined('ACTION_ALIAS') ? ACTION_ALIAS : ACTION_NAME));
     //保证$_REQUEST正常取值
     $_REQUEST = array_merge($_POST, $_GET);
 }
Example #22
0
 public static function init()
 {
     Input::noGPC();
     if (C('OUTPUT_ENCODE')) {
         $zlib = ini_get('zlib.output_compression');
         if (empty($zlib)) {
             ob_start('ob_gzhandler');
         }
     }
     date_default_timezone_set(C('DEFAULT_TIMEZONE'));
     load_ext_file();
     Dispatcher::dispatch();
     define('NOW_TIME', $_SERVER['REQUEST_TIME']);
     define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']);
     define('IS_GET', REQUEST_METHOD == 'GET' ? true : false);
     define('IS_POST', REQUEST_METHOD == 'POST' ? true : false);
     define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false);
     define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false);
     define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')]) ? true : false);
     tag('url_dispatch');
     if (C('VAR_FILTERS')) {
         $filters = explode(',', C('VAR_FILTERS'));
         foreach ($filters as $filter) {
             array_walk_recursive($_POST, $filter);
             array_walk_recursive($_GET, $filter);
         }
     }
     C('LOG_PATH', realpath(LOG_PATH) . '/');
     C('TMPL_EXCEPTION_FILE', realpath(C('TMPL_EXCEPTION_FILE')));
     $App = F("App");
     define('MODEL_EXTRESDIR', 'statics/extres/' . strtolower(GROUP_NAME) . '/');
     if ('Admin' == GROUP_NAME && isset($App['Domains'])) {
         $Config = F("Config");
         $http_host = strtolower($_SERVER['HTTP_HOST']);
         $Module_Domains_list = F("Module_Domains_list");
         if (false == $Module_Domains_list) {
             try {
                 D("Domains")->domains_cache();
                 $Module_Domains_list = F("Module_Domains_list");
             } catch (Exception $exc) {
                 if (C('LOG_RECORD')) {
                     Log::write("缓存:Module_Domains_list 加载失败!");
                 }
             }
         }
         if ((int) $Config['domainaccess']) {
             $domain = explode("|", $Module_Domains_list["Admin"]);
             if ($Module_Domains_list["Admin"] && !in_array($http_host, $domain)) {
                 send_http_status(404);
                 exit;
             }
         }
     }
     if (!in_array(GROUP_NAME, $App)) {
         $msg = L('_MODULE_NOT_EXIST_') . GROUP_NAME . "," . L('_MODULE_NOT_INSTAL_') . "!";
         if (APP_DEBUG) {
             throw_exception($msg);
         } else {
             if (C('LOG_RECORD')) {
                 Log::write($msg . "URL:" . get_url());
             }
             send_http_status(404);
             exit;
         }
     }
     return;
 }
Example #23
0
 /**
  * 提示信息
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-04-23 13:40:58
  *
  * @param mixed $message     提示信息。三种格式:null(取C('MSG_CONTENT'));string(提示字符串);数组(array('msg_content' => '提示信息', ...)
  * @param array $link_url    显示链接数组。格式:array(array(text,link)...)或text,link
  * @param int   $status_code http状态码。默认null
  *
  * @return void 无返回值
  */
 protected function _showMessage($message, $link_url = array(), $status_code = null)
 {
     if (null !== $status_code) {
         send_http_status($status_code);
         if (404 == $status_code && is_file($filename = WWWROOT . '404' . C('HTML_SUFFIX'))) {
             exit(file_get_contents($filename));
         }
     }
     $template = $this->getViewTemplate();
     if (is_string($link_url)) {
         //text,link
         $template->assign('link_url', explode(',', $link_url));
     } else {
         $template->assign('link_url', $link_url ? $link_url : array());
     }
     if (null === $message && is_array($v = C('MSG_CONTENT'))) {
         $template->assign($v);
     } elseif (is_string($message)) {
         $template->assign(array('msg_content' => $message));
     } elseif (is_array($message)) {
         $template->assign($message);
     }
     $this->_display('Msg', 'msg');
     exit;
 }
Example #24
0
 /**
  * 写日志
  *
  * @author          liu21st <*****@*****.**>
  * @lastmodify      2013-01-17 09:26:44 by mrmsl
  *
  * @param string $message       日志信息。默认'',取已保存日志
  * @param string $destination   写入目标。默认'',日志路径+Y/md/+文件名
  * @param int    $type          日志记录方式。默认'',取C('LOG_TYPE')
  * @param string $extra         额外信息。默认''
  *
  * @return void 无返回值
  */
 public static function write($message = '', $destination = '', $type = '', $extra = '')
 {
     $log = $message ? $message : join(PHP_EOL, self::$log);
     if (!$log) {
         return;
     }
     $log .= PHP_EOL;
     $now = new_date(self::$date_format);
     $type = $type ? $type : C('LOG_TYPE');
     if (!$type || self::FILE == $type) {
         //文件方式记录日志
         if (defined('TODAY_LOG_PATH')) {
             $log_path = TODAY_LOG_PATH;
         } else {
             new_mkdir($log_path = LOG_PATH . new_date('Y/md/'));
             define('TODAY_LOG_PATH', $log_path);
         }
         if ('' === $destination) {
             $filename = 'php' . C('LOG_FILE_SUFFIX');
         } elseif ($destination) {
             if (false === strpos($destination, C('LOG_FILE_SUFFIX'))) {
                 //sql.log, slowquery.log, errorsql.log...
                 $filename = $destination . C('LOG_FILE_SUFFIX');
             }
         }
         $destination = empty($filename) ? $destination : $log_path . $filename;
         //检测日志文件大小,超过配置大小则备份日志文件重新生成
         if (is_file($destination) && ($filesize = sys_config('sys_log_filesize')) && $filesize * 1024 <= filesize($destination)) {
             rename($destination, $log_path . basename($filename, C('LOG_FILE_SUFFIX')) . new_date('_His') . C('LOG_FILE_SUFFIX'));
         }
     } else {
         $destination = $destination ? $destination : C('LOG_DEST');
         $extra = $extra ? $extra : C('LOG_EXTRA');
     }
     if (APP_DEBUG && strpos($log, 'PHP ')) {
         //调试模式,输出php错误
         send_http_status(HTTP_STATUS_SERVER_ERROR);
         if (!IS_AJAX) {
             echo nl2br($log);
         }
     }
     error_log($log, $type, $destination, $extra);
 }
Example #25
0
 public static function dispatch()
 {
     $urlMode = C('URL_MODEL');
     if (isset($_GET[C('VAR_PATHINFO')])) {
         $_SERVER['PATH_INFO'] = $_GET[C('VAR_PATHINFO')];
         unset($_GET[C('VAR_PATHINFO')]);
     }
     if ($urlMode == URL_COMPAT) {
         define('PHP_FILE', _PHP_FILE_ . '?' . C('VAR_PATHINFO') . '=');
     } elseif ($urlMode == URL_REWRITE) {
         $url = dirname(_PHP_FILE_);
         if ($url == '/' || $url == '\\') {
             $url = '';
         }
         define('PHP_FILE', $url);
     } else {
         define('PHP_FILE', _PHP_FILE_);
     }
     if (C('APP_SUB_DOMAIN_DEPLOY')) {
         $rules = C('APP_SUB_DOMAIN_RULES');
         if (isset($rules[$_SERVER['HTTP_HOST']])) {
             $rule = $rules[$_SERVER['HTTP_HOST']];
         } else {
             $subDomain = strtolower(substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.')));
             define('SUB_DOMAIN', $subDomain);
             if ($subDomain && isset($rules[$subDomain])) {
                 $rule = $rules[$subDomain];
             } elseif (isset($rules['*'])) {
                 if ('www' != $subDomain && !in_array($subDomain, C('APP_SUB_DOMAIN_DENY'))) {
                     $rule = $rules['*'];
                 }
             }
         }
         if (!empty($rule)) {
             $array = explode('/', $rule[0]);
             $module = array_pop($array);
             if (!empty($module)) {
                 $_GET[C('VAR_MODULE')] = $module;
                 $domainModule = true;
             }
             if (!empty($array)) {
                 $_GET[C('VAR_GROUP')] = array_pop($array);
                 $domainGroup = true;
             }
             if (isset($rule[1])) {
                 parse_str($rule[1], $parms);
                 $_GET = array_merge($_GET, $parms);
             }
         }
     }
     if (!isset($_SERVER['PATH_INFO'])) {
         $types = explode(',', C('URL_PATHINFO_FETCH'));
         foreach ($types as $type) {
             if (0 === strpos($type, ':')) {
                 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1));
                 break;
             } elseif (!empty($_SERVER[$type])) {
                 $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                 break;
             }
         }
     }
     $depr = C('URL_PATHINFO_DEPR');
     if (!empty($_SERVER['PATH_INFO'])) {
         tag('path_info');
         $part = pathinfo($_SERVER['PATH_INFO']);
         define('__EXT__', isset($part['extension']) ? strtolower($part['extension']) : '');
         if (__EXT__) {
             if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) {
                 send_http_status(404);
                 exit;
             }
             if (C('URL_HTML_SUFFIX')) {
                 $_SERVER['PATH_INFO'] = preg_replace('/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i', '', $_SERVER['PATH_INFO']);
             } else {
                 $_SERVER['PATH_INFO'] = preg_replace('/.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']);
             }
         }
         if (!self::routerCheck()) {
             $paths = explode($depr, trim($_SERVER['PATH_INFO'], '/'));
             if (C('VAR_URL_PARAMS')) {
                 $_GET[C('VAR_URL_PARAMS')] = $paths;
             }
             $var = array();
             if (C('APP_GROUP_LIST') && !isset($_GET[C('VAR_GROUP')])) {
                 $var[C('VAR_GROUP')] = in_array(strtolower($paths[0]), explode(',', strtolower(C('APP_GROUP_LIST')))) ? array_shift($paths) : '';
                 if (C('APP_GROUP_DENY') && in_array(strtolower($var[C('VAR_GROUP')]), explode(',', strtolower(C('APP_GROUP_DENY'))))) {
                     exit;
                 }
             }
             if (!isset($_GET[C('VAR_MODULE')])) {
                 $var[C('VAR_MODULE')] = array_shift($paths);
             }
             $var[C('VAR_ACTION')] = array_shift($paths);
             preg_replace('@(\\w+)\\/([^\\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/', $paths));
             $_GET = array_merge($var, $_GET);
         }
         define('__INFO__', $_SERVER['PATH_INFO']);
     } else {
         define('__INFO__', '');
     }
     define('__SELF__', strip_tags($_SERVER['REQUEST_URI']));
     define('__APP__', strip_tags(PHP_FILE));
     if (C('APP_GROUP_LIST')) {
         define('GROUP_NAME', self::getGroup(C('VAR_GROUP')));
         define('__GROUP__', !empty($domainGroup) || strtolower(GROUP_NAME) == strtolower(C('DEFAULT_GROUP')) ? __APP__ : __APP__ . '/' . (C('URL_CASE_INSENSITIVE') ? strtolower(GROUP_NAME) : GROUP_NAME));
     }
     define('BASE_LIB_PATH', defined('GROUP_NAME') && C('APP_GROUP_MODE') == 1 ? APP_PATH . C('APP_GROUP_PATH') . '/' . GROUP_NAME . '/' : LIB_PATH);
     if (defined('GROUP_NAME')) {
         C('CACHE_PATH', CACHE_PATH . GROUP_NAME . '/');
         if (1 == C('APP_GROUP_MODE')) {
             $config_path = BASE_LIB_PATH . 'Conf/';
             $common_path = BASE_LIB_PATH . 'Common/';
         } else {
             $config_path = CONF_PATH . GROUP_NAME . '/';
             $common_path = COMMON_PATH . GROUP_NAME . '/';
         }
         if (is_file($config_path . 'config.php')) {
             C(include $config_path . 'config.php');
         }
         if (is_file($config_path . 'alias.php')) {
             alias_import(include $config_path . 'alias.php');
         }
         if (is_file($config_path . 'tags.php')) {
             C('tags', include $config_path . 'tags.php');
         }
         if (is_file($common_path . 'function.php')) {
             include $common_path . 'function.php';
         }
     } else {
         C('CACHE_PATH', CACHE_PATH);
     }
     define('MODULE_NAME', self::getModule(C('VAR_MODULE')));
     define('ACTION_NAME', self::getAction(C('VAR_ACTION')));
     $moduleName = defined('MODULE_ALIAS') ? MODULE_ALIAS : MODULE_NAME;
     if (defined('GROUP_NAME')) {
         define('__URL__', !empty($domainModule) ? __GROUP__ . $depr : __GROUP__ . $depr . (C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName));
     } else {
         define('__URL__', !empty($domainModule) ? __APP__ . '/' : __APP__ . '/' . (C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName));
     }
     define('__ACTION__', __URL__ . $depr . (defined('ACTION_ALIAS') ? ACTION_ALIAS : ACTION_NAME));
     $_REQUEST = array_merge($_POST, $_GET);
 }
Example #26
0
 protected function httpError($code, $msg = null)
 {
     send_http_status($code);
     exit($msg ? $msg : 'HTTP ' . $code);
 }
Example #27
0
 /**
 +----------------------------------------------------------
 * 魔术方法 有不存在的操作的时候执行
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $method 方法名
 * @param array $args 参数
 +----------------------------------------------------------
 * @return mixed
 +----------------------------------------------------------
 */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME)) {
         if (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (file_exists_case(C('TEMPLATE_NAME'))) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } elseif (function_exists('__hack_action')) {
             // hack 方式定义扩展操作
             __hack_action();
         } elseif (APP_DEBUG) {
             // 抛出异常
             throw_exception(L('_ERROR_ACTION_') . ACTION_NAME);
         } else {
             if (C('LOG_EXCEPTION_RECORD')) {
                 Log::write(L('_ERROR_ACTION_') . ACTION_NAME);
             }
             send_http_status(404);
             exit;
         }
     } else {
         switch (strtolower($method)) {
             // 判断提交方式
             case 'ispost':
             case 'isget':
             case 'ishead':
             case 'isdelete':
             case 'isput':
                 return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2));
                 // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             case '_get':
                 $input =& $_GET;
                 break;
             case '_post':
                 $input =& $_POST;
                 break;
             case '_put':
                 parse_str(file_get_contents('php://input'), $input);
                 break;
             case '_request':
                 $input =& $_REQUEST;
                 break;
             case '_session':
                 $input =& $_SESSION;
                 break;
             case '_cookie':
                 $input =& $_COOKIE;
                 break;
             case '_server':
                 $input =& $_SERVER;
                 break;
             case '_globals':
                 $input =& $GLOBALS;
                 break;
             default:
                 throw_exception(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_'));
         }
         if (isset($input[$args[0]])) {
             // 取值操作
             $data = $input[$args[0]];
             $fun = $args[1] ? $args[1] : C('DEFAULT_FILTER');
             $data = $fun($data);
             // 参数过滤
         } else {
             // 变量默认值
             $data = isset($args[2]) ? $args[2] : NULL;
         }
         return $data;
     }
 }
 public function shows()
 {
     $catid = I('get.catid', 0, 'intval');
     $id = I('get.id', 0, 'intval');
     $page = intval($_GET[C("VAR_PAGE")]);
     $page = max($page, 1);
     //获取当前栏目数据
     $category = getCategory($catid);
     if (empty($category)) {
         send_http_status(404);
         exit;
     }
     //反序列化栏目配置
     $category['setting'] = $category['setting'];
     //检查是否禁止访问动态页
     if ($category['setting']['showoffmoving']) {
         send_http_status(404);
         exit;
     }
     //模型ID
     $modelid = $category['modelid'];
     $data = ContentModel::getInstance($modelid)->relation(true)->where(array("id" => $id, 'status' => 99))->find();
     if (empty($data)) {
         send_http_status(404);
         exit;
     }
     ContentModel::getInstance($modelid)->dataMerger($data);
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //tag
     tag('html_shwo_buildhtml', $data);
     $content_output = new \content_output($modelid);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     $output_data['title'] = strip_tags($output_data['title']);
     //SEO
     $seo_keywords = '';
     if (!empty($output_data['keywords'])) {
         $seo_keywords = implode(',', $output_data['keywords']);
     }
     $seo = seo($catid, $output_data['title'], $output_data['description'], $seo_keywords);
     //内容页模板
     $template = $output_data['template'] ? $output_data['template'] : $category['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     unset($newstempid);
     //分页处理
     $pages = $titles = '';
     //分配解析后的文章数据到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $seo);
     //栏目ID
     $this->assign("catid", $catid);
     //分页生成处理
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] > 0) {
         $urlrules = $this->Url->show($data, $page);
         //手动分页
         $CONTENT_POS = strpos($output_data['content'], '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $output_data['content']));
             $pagenumber = count($contents);
             $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => $urlrules['page']))->show("default");
             //判断[page]出现的位置是否在第一位
             if ($CONTENT_POS < 7) {
                 $content = $contents[$page];
             } else {
                 $content = $contents[$page - 1];
             }
             //分页
             $this->assign("pages", $pages);
             $this->assign("content", $content);
         }
     } else {
         $this->assign("content", $output_data['content']);
     }
     $this->display("Show/{$template}");
 }
 /**
  * URL映射到控制器
  * @access public
  * @return void
  */
 public static function dispatch()
 {
     $varPath = C('VAR_PATHINFO');
     $varModule = C('VAR_MODULE');
     $varController = C('VAR_CONTROLLER');
     $varAction = C('VAR_ACTION');
     $urlCase = C('URL_CASE_INSENSITIVE');
     if (isset($_GET[$varPath])) {
         // 判断URL里面是否有兼容模式参数
         $_SERVER['PATH_INFO'] = $_GET[$varPath];
         unset($_GET[$varPath]);
     } elseif (IS_CLI) {
         // CLI模式下 index.php module/controller/action/params/...
         $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
     }
     // 开启子域名部署
     if (C('APP_SUB_DOMAIN_DEPLOY')) {
         $rules = C('APP_SUB_DOMAIN_RULES');
         if (isset($rules[$_SERVER['HTTP_HOST']])) {
             // 完整域名或者IP配置
             define('APP_DOMAIN', $_SERVER['HTTP_HOST']);
             // 当前完整域名
             $rule = $rules[APP_DOMAIN];
         } else {
             if (strpos(C('APP_DOMAIN_SUFFIX'), '.')) {
                 // com.cn net.cn
                 $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3);
             } else {
                 $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2);
             }
             if (!empty($domain)) {
                 $subDomain = implode('.', $domain);
                 define('SUB_DOMAIN', $subDomain);
                 // 当前完整子域名
                 $domain2 = array_pop($domain);
                 // 二级域名
                 if ($domain) {
                     // 存在三级域名
                     $domain3 = array_pop($domain);
                 }
                 if (isset($rules[$subDomain])) {
                     // 子域名
                     $rule = $rules[$subDomain];
                 } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) {
                     // 泛三级域名
                     $rule = $rules['*.' . $domain2];
                     $panDomain = $domain3;
                 } elseif (isset($rules['*']) && !empty($domain2) && 'www' != $domain2) {
                     // 泛二级域名
                     $rule = $rules['*'];
                     $panDomain = $domain2;
                 }
             }
         }
         if (!empty($rule)) {
             // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b');
             if (is_array($rule)) {
                 list($rule, $vars) = $rule;
             }
             $array = explode('/', $rule);
             // 模块绑定
             define('BIND_MODULE', array_shift($array));
             // 控制器绑定
             if (!empty($array)) {
                 $controller = array_shift($array);
                 if ($controller) {
                     define('BIND_CONTROLLER', $controller);
                 }
             }
             if (isset($vars)) {
                 // 传入参数
                 parse_str($vars, $parms);
                 if (isset($panDomain)) {
                     $pos = array_search('*', $parms);
                     if (false !== $pos) {
                         // 泛域名作为参数
                         $parms[$pos] = $panDomain;
                     }
                 }
                 $_GET = array_merge($_GET, $parms);
             }
         }
     }
     // 分析PATHINFO信息
     if (!isset($_SERVER['PATH_INFO'])) {
         $types = explode(',', C('URL_PATHINFO_FETCH'));
         foreach ($types as $type) {
             if (!empty($_SERVER[$type])) {
                 $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                 break;
             }
         }
     }
     if (empty($_SERVER['PATH_INFO'])) {
         $_SERVER['PATH_INFO'] = '';
     }
     $depr = C('URL_PATHINFO_DEPR');
     define('MODULE_PATHINFO_DEPR', $depr);
     define('__INFO__', trim($_SERVER['PATH_INFO'], '/'));
     // URL后缀
     define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
     $_SERVER['PATH_INFO'] = __INFO__;
     if (__INFO__ && C('MULTI_MODULE') && !defined('BIND_MODULE')) {
         // 获取模块名
         $paths = explode($depr, __INFO__, 2);
         $allowList = C('MODULE_ALLOW_LIST');
         // 允许的模块列表
         $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]);
         if (empty($allowList) || is_array($allowList) && in_array_case($module, $allowList)) {
             $_GET[$varModule] = $module;
             $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : '';
         }
     }
     // 获取模块名称
     define('MODULE_NAME', defined('BIND_MODULE') ? BIND_MODULE : self::getModule($varModule));
     // 检测模块是否存在
     if (MODULE_NAME && (defined('BIND_MODULE') || !in_array_case(MODULE_NAME, C('MODULE_DENY_LIST'))) && is_dir(APP_PATH . MODULE_NAME)) {
         // 定义当前模块路径
         define('MODULE_PATH', APP_PATH . MODULE_NAME . '/');
         // 定义当前模块的模版缓存路径
         C('CACHE_PATH', CACHE_PATH . MODULE_NAME . '/');
         // 加载模块配置文件
         if (is_file(MODULE_PATH . 'Conf/config.php')) {
             C(include MODULE_PATH . 'Conf/config.php');
         }
         // 加载模块别名定义
         if (is_file(MODULE_PATH . 'Conf/alias.php')) {
             Think::addMap(include MODULE_PATH . 'Conf/alias.php');
         }
         // 加载模块函数文件
         if (is_file(MODULE_PATH . 'Common/function.php')) {
             include MODULE_PATH . 'Common/function.php';
         }
     } else {
         E(L('_MODULE_NOT_EXIST_') . ':' . MODULE_NAME);
     }
     if ('' != $_SERVER['PATH_INFO'] && (!C('URL_ROUTER_ON') || !Route::check())) {
         // 检测路由规则 如果没有则按默认规则调度URL
         // 检查禁止访问的URL后缀
         if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) {
             send_http_status(404);
             exit;
         }
         // 去除URL后缀
         $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX') ? '/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']);
         $depr = C('URL_PATHINFO_DEPR');
         $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr));
         if (!defined('BIND_CONTROLLER')) {
             // 获取控制器
             $_GET[$varController] = array_shift($paths);
         }
         // 获取操作
         if (!defined('BIND_ACTION')) {
             $_GET[$varAction] = array_shift($paths);
         }
         // 解析剩余的URL参数
         $var = array();
         if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) {
             // URL参数按顺序绑定变量
             $var = $paths;
         } else {
             preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) {
                 $var[$match[1]] = strip_tags($match[2]);
             }, implode('/', $paths));
         }
         $_GET = array_merge($var, $_GET);
     }
     // 获取控制器和操作名
     define('CONTROLLER_NAME', defined('BIND_CONTROLLER') ? BIND_CONTROLLER : self::getController($varController, $urlCase));
     define('ACTION_NAME', defined('BIND_ACTION') ? BIND_ACTION : self::getAction($varAction, $urlCase));
     //保证$_REQUEST正常取值
     $_REQUEST = array_merge($_POST, $_GET);
 }
Example #30
0
/**
 * 页面重定向
 *
 * @lastmodify 2012-12-03 13:25:06 by mrmsl
 *
 * @param string $url    重定向页面url
 * @param int    $time   停留时间。默认0
 * @param string $msg    页面内容。默认''
 * @param $int   $status_code 头部状态码。默认0,不发送
 *
 * @return void 无返回值
 */
function redirect($url, $time = 0, $msg = '', $status_code = 0)
{
    $status_code && send_http_status($status_code);
    //支持发送头部状态码 by mrmsl on 2012-07-02 09:45:53
    $url = str_replace(array("\n", "\r"), '', $url);
    //多行URL地址支持
    $msg = $msg ? $msg : "系统将在{$time}秒之后自动跳转到{$url}!";
    if (!headers_sent()) {
        if (0 === $time) {
            header('Location: ' . $url);
        } else {
            header("refresh:{$time};url={$url}");
            echo $msg;
        }
        exit;
    } else {
        $str = "<meta http-equiv='refresh' content='{$time};URL={$url}'>";
        $str .= $time ? $msg : '';
        exit($str);
    }
}