コード例 #1
0
 public function __construct($config = array())
 {
     $this->config = array_merge(cpConfig::get('TPL'), (array) $config);
     //参数配置
     $this->assign('cpTemplate', $this);
     $this->_replace = array('str' => array('search' => array(), 'replace' => array()), 'reg' => array('search' => array("/__[A-Z]+__/", "/{(\\\$[a-zA-Z_]\\w*(?:\\[[\\w\\.\"\\'\\[\\]\$]+\\])*)}/i", "/{include\\s*file=\"(.*)\"}/i"), 'replace' => array("<?php echo \$0; ?>", "<?php echo \$1; ?>", "<?php \$cpTemplate->display(\"\$1\"); ?>")));
 }
コード例 #2
0
ファイル: cpApp.class.php プロジェクト: JamesKid/teach
 public function __construct($config = array())
 {
     define('CP_VER', '2.0.2012.1203');
     //框架版本号,后两段表示发布日期
     define('CP_CORE_PATH', dirname(__FILE__));
     //当前文件所在的目录
     require CP_CORE_PATH . '/cpConfig.class.php';
     //加载默认配置
     $this->appConfig = array_merge(cpConfig::get('APP'), $config);
     //参数配置
     cpConfig::set('APP', $this->appConfig);
     defined('DEBUG') or define('DEBUG', cpConfig::get('DEBUG'));
     date_default_timezone_set(cpConfig::get('TIMEZONE'));
     if ($this->appConfig['DEBUG']) {
         ini_set("display_errors", 1);
         error_reporting(E_ALL ^ E_NOTICE);
         //除了notice提示,其他类型的错误都报告
     } else {
         ini_set("display_errors", 0);
         error_reporting(0);
         //把错误报告,全部屏蔽
     }
     spl_autoload_register(array($this, 'autoload'));
     //注册类的自动加载
     //加载常用函数库
     if (is_file(CP_CORE_PATH . '/../lib/common.function.php')) {
         require CP_CORE_PATH . '/../lib/common.function.php';
     }
     //加载扩展函数库
     if (is_file(CP_CORE_PATH . '/../ext/extend.php')) {
         require CP_CORE_PATH . '/../ext/extend.php';
     }
 }
コード例 #3
0
ファイル: cpModel.class.php プロジェクト: heYeCheng/dingling
 public function __construct($config = array())
 {
     $this->config = array_merge(cpConfig::get('DB'), $config);
     //参数配置
     $this->options['field'] = '*';
     //默认查询字段
     $this->pre = $this->config['DB_PREFIX'];
     //数据表前缀
     $this->connect();
 }
コード例 #4
0
ファイル: url_ext.php プロジェクト: JamesKid/teach
function url($module = '', $action = '', $param = array())
{
    $route = $module . '/' . $action;
    $module = empty($module) ? '' : '?m=' . $module;
    $action = empty($action) ? '' : '&a=' . $action;
    $params = empty($param) ? '' : '&' . http_build_query($param);
    $url = $_SERVER["SCRIPT_NAME"] . $module . $action . $params;
    $rewrite_rules = cpConfig::get('URL_REWRITE_RULE');
    if (!empty($rewrite_rules)) {
        static $urlArray = array();
        if (!isset($urlArray[$url])) {
            foreach ($rewrite_rules as $rule => $mapper) {
                $mapper = '/' . str_ireplace(array('/', '<a>', '<m>'), array('\\/', '(?<a>\\w+)', '(?<m>\\w+)'), $mapper) . '/i';
                if (preg_match($mapper, $route, $matchs)) {
                    list($controller, $action) = explode('/', $route);
                    $urlArray[$url] = str_ireplace(array('<a>', '<m>'), array($action, $controller), $rule);
                    if (!empty($param)) {
                        $_args = array();
                        foreach ($param as $argkey => $arg) {
                            $count = 0;
                            $urlArray[$url] = str_ireplace('<' . $argkey . '>', $arg, $urlArray[$url], $count);
                            if (!$count) {
                                $_args[$argkey] = $arg;
                            }
                        }
                        $urlArray[$url] = preg_replace('/<\\w+>/', '', $urlArray[$url]) . (!empty($_args) ? '?' . http_build_query($_args) : '');
                    }
                    if (0 !== stripos($urlArray[$url], 'http://')) {
                        $urlArray[$url] = 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/\\') . '/' . $urlArray[$url];
                    }
                    return $urlArray[$url];
                }
            }
        }
    }
    return $url;
}
コード例 #5
0
 function model($model)
 {
     static $model_obj = array();
     static $config = array();
     if (isset($model_obj[$model])) {
         return $model_obj[$model];
     }
     if (!isset($config['MODEL_PATH'])) {
         $config['MODEL_PATH'] = cpConfig::get('MODEL_PATH');
         $config['MODEL_SUFFIX'] = cpConfig::get('MODEL_SUFFIX');
         $suffix_arr = explode('.', $config['MODEL_SUFFIX'], 2);
         $config['MODEL_CLASS_SUFFIX'] = $suffix_arr[0];
     }
     if (file_exists($config['MODEL_PATH'] . $model . $config['MODEL_SUFFIX'])) {
         require_once $config['MODEL_PATH'] . $model . $config['MODEL_SUFFIX'];
         //加载模型文件
         $classname = $model . $config['MODEL_CLASS_SUFFIX'];
         if (class_exists($classname)) {
             return $model_obj[$model] = new $classname();
         }
     }
     return false;
 }
コード例 #6
0
ファイル: cpError.class.php プロジェクト: JamesKid/teach
    protected function showError()
    {
        //如果开启了日志记录,则写入日志
        if (cpConfig::get('LOG_ON')) {
            self::write($this->message);
        }
        $error_url = cpConfig::get('ERROR_URL');
        //错误页面重定向
        if ($error_url != '') {
            echo '<script language="javascript">
				if(self!=top){
				  parent.location.href="' . $error_url . '";
				} else {
				 window.location.href="' . $error_url . '";
				}
				</script>';
            exit;
        }
        if (defined('DEBUG') && false == DEBUG) {
            @header("HTTP/1.1 404 Not Found");
            exit;
        }
        if (!defined('__APP__')) {
            define('__APP__', '/');
        }
        if ($this->isAjax()) {
            $arr = array('status' => 0, 'message' => 'ERROR:' . $this->message . '<br>FILE:' . $this->errorFile . '<br>LINE:' . $this->errorLine . '<br>LEVEL:' . $this->errorLevel . '<br>TRACE:' . $this->trace);
            @header("Content-type:text/plain");
            echo json_encode($arr);
        } else {
            echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>错误提示!</title>
			<STYLE>
			BODY{FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; COLOR: #333; background:#fff; FONT-SIZE: 12px;padding:0px;margin:0px;}
			A{text-decoration:none;color:#3071BF}
			A:hover{text-decoration:underline;}
			.error_title{border-bottom:1px #eee solid;font-size:20px;line-height:28px; height:28px;font-weight:600}
			.error_box{border-left:3px solid #FC0;font-size:14px; line-height:22px; padding:6px 15px;background:#FFE}
			.error_tip{margin-top:15px;padding:6px;font-size:12px;padding-left:15px;background:#f7f7f7}
			</STYLE>
			</head>
			<body>
			<div style="margin:30px auto; width:800px;">
			<div class="error_title">错误提示</div>
			<div style="height:10px"></div>
			<div class="error_box">出错信息:' . $this->message . '</div>';
            //开启调试模式之后,显示详细信息
            if ($this->errorCode > 0 && $this->errorCode != 404 && cpConfig::get('DEBUG')) {
                echo '<div class="error_box">出错文件:' . $this->errorFile . '</div>
				<div class="error_box">错误行:' . $this->errorLine . '</div>
				<div class="error_box">错误级别:' . $this->errorLevel . '</div>
				<div class="error_box">Trace信息:<br>' . $this->trace . '</div>';
            }
            echo '
				<div class="error_tip">您可以选择 &nbsp;&nbsp;<a href="' . $_SERVER['PHP_SELF'] . '" title="重试">重试</a>&nbsp;&nbsp;<a href="javascript:history.back()" title="返回">返回</a>&nbsp;&nbsp;或者&nbsp;&nbsp;<a href="' . __APP__ . '" title="回到首页">回到首页</a> </div>
				</div>
				</body>
				</html>';
        }
        exit;
    }
コード例 #7
0
ファイル: cacheModel.class.php プロジェクト: JamesKid/teach
 public function clear_html($url)
 {
     $config = cpConfig::get('APP');
     cpHtmlCache::refresh($config['HTML_CACHE_PATH'], $url);
 }