/** * 引用模板 * @param $template 模板 * @param $cacheTime 是否使用静态缓存,等于0时不使用,大于0时为缓存时间 * @param $cacheKey 静态缓存KEY */ public function display($template, $cacheTime = false, $cacheKey = false) { $path['template_c'] = $this->get_path($template, 'view_c'); $path['template'] = $this->get_path($template); //当缓存时间未设置时,将自动获取配置中的缓存时间 $cache = $cacheTime ? intval($cacheTime) : Config::template('view_cache_time'); $kVar = empty($cacheKey) ? null : $cacheKey; if (file_exists($path['template'])) { //如果已编译模板的不存在或者模板修改时间大于已编译模板的时间将重新编译 if (!file_exists($path['template_c']) || filemtime($path['template']) > filemtime($path['template_c'])) { $this->write($path['template_c'], $this->template_parse(file_get_contents($path['template']))); } if ($cache > 0 && Config::template('view_cache')) { if (!Cache::is_cache($this->get_temp_name($template, $cacheKey), Config::template('view_cache_dir'))) { self::cache_compile($path['template_c'], $cacheKey); debug::add('写入缓存\'<strong>' . $template . $kVar . '</strong>\'缓存时间:' . $cache . '秒。'); } elseif (Cache::time($this->get_temp_name($template, $cacheKey), Config::config('view_cache_dir')) + $cache > time() && filemtime($path['template']) < Cache::time($this->get_temp_name($template, $cacheKey), Config::config('view_cache_dir'))) { echo Cache::get($this->get_temp_name($template, $cacheKey), Config::config('view_cache_dir')); debug::add('读取缓存\'<strong>' . $template . '[' . $kVar . ']' . '</strong>缓存时间:' . $cache . '秒。'); } else { self::cache_compile($path['template_c'], $cacheKey); debug::add('更新缓存\'<strong>' . $template . '[' . $kVar . ']' . '</strong>缓存时间:' . $cache . '秒。'); } } else { foreach ($this->var as $k => $v) { ${$k} = $v; } include $path['template_c']; //echo htmlspecialchars($this->template_parse(file_get_contents($path['template']))); debug::add('使用模板\'<strong>' . $template . '</strong>\'未使用缓存。'); } } else { debug::add('模板<strong>' . $path['template'] . '</strong>不存在。'); } }
/** * 入口方法 * @param array $config 项目简单配置 */ public static function run($config) { //初始化设置 self::init(); //定义系统常量 self::define($config); //包含框架中的函数库文件 require FIREZP_PATH . 'common' . DIRECTORY_SEPARATOR . 'function.inc.php'; //加载所有配置 if (file_exists(APP_PATH . 'conf' . DIRECTORY_SEPARATOR . 'confing.inc.php')) { $appConfig = (require APP_PATH . 'conf' . DIRECTORY_SEPARATOR . 'confing.inc.php'); $sysConfig = array('page' => 8); //系统配置 $config = array_merge($sysConfig, $appConfig, $config); } C($config); //系统url self::initUrl(); //设置自动加载类 spl_autoload_register(array('self', 'autoload')); //设置包含目录(类所在的全部目录), PATH_SEPARATOR 分隔符号 Linux(:) Windows(;) $include_path = get_include_path(); //原基目录 $include_path .= PATH_SEPARATOR . FIREZP_PATH . "base/"; //框架中基类所在的目录 set_include_path($include_path); //调试开始 debug::debugbegin(); //项目结构化 appStruct::make(); //url解析 parseUrl::run(); //安全过滤 self::safe(); //开始session session_start(); //实例化控制器 $controllerFile = APP_PATH . "controller" . DIRECTORY_SEPARATOR . strtolower($_GET["c"]) . "Controller.php"; define('CONTROLLER', $_GET["c"]); define('ACTION', $_GET["a"]); if (file_exists($controllerFile)) { $controller = $_GET["c"] . "Controller"; $controllerObj = new $controller(); $action = $_GET["a"] . "Action"; if (method_exists($controllerObj, $action)) { $controllerObj->{$action}(); } else { debug::add($action . '方法不存在'); } } else { debug::add('控制器不存在'); } //输出调试信息 if (DEBUG == 1) { debug::debugend(); debug::show(); } }
function dump() { $args = func_get_args(); if (count($args) < 1) { debug::add('dump函数没有传入需要调试的参数'); } else { foreach ($args as $val) { echo '<div style="width:100%;text-align:left;padding-left:50px;"><pre>'; print_r($val); echo '</pre></div>'; } } }
public static function replace($pattern, $replace, $string) { $error = ''; $str = @preg_replace($pattern, $replace, $string) | $error; echo $error; if (debug::active()) { $error = error_get_last(); if (strstr($error['message'], 'preg_replace')) { $msg = str_replace('preg_replace() [<a href=\'function.preg-replace\'>function.preg-replace</a>]:', '', $error['message']); debug::add($msg . ' in ' . $pattern, 'ERROR'); } } return $str; }
/** * init attribs * * @acess protected */ function init() { parent::init(); if ($this->disabled === true) { $this->_init .= ' disabled="disabled"'; } if ($this->name != '') { $this->_init .= ' name="' . $this->name . '"'; } if ($this->tabindex != '') { $this->_init .= ' tabindex="' . $this->tabindex . '"'; } if ($this->value != '') { $this->_init .= ' value="' . $this->value . '"'; } $this->type = strtolower($this->type); switch ($this->type) { case 'submit': case 'reset': case 'button': $this->_init .= ' type="' . $this->type . '"'; break; default: $this->_init .= ' type="button"'; if (debug::active()) { debug::add('type ' . $this->type . ' not supported - type set to button', 'ERROR'); } break; } }
public function halt($message = '', $sql = '') { if (DEBUG == 1) { debug::add($message . ": <font color='green'>" . $sql . '</font>'); } else { debug::pause($message . ": <font color='green'>" . $sql . '</font>'); } }
function get_htmlobject_object($data) { if (isset($data['object']) && isset($data['object']['type']) && isset($data['object']['attrib']) && isset($data['object']['attrib']['name'])) { // set vars $object = strtolower($data['object']['type']); $attribs = $data['object']['attrib']; $name = $data['object']['attrib']['name']; // build object switch ($object) { case 'htmlobject_input': case 'htmlobject_select': case 'htmlobject_textarea': case 'htmlobject_button': $html = $this->make_htmlobject($object, $attribs); break; default: if (debug::active()) { debug::add($object . ' is not supported', 'ERROR'); } break; } // set request if (isset($this->request) && count($this->request) > 0) { $request = '$this->request' . $this->string_to_index($name); } // build return if (isset($request) && $request != '' && isset($html)) { // add request to object switch ($object) { case 'htmlobject_input': $html = $this->handle_htmlobject_input($html, $request); break; case 'htmlobject_select': $html = $this->handle_htmlobject_select($html, $request); break; case 'htmlobject_textarea': $html = $this->handle_htmlobject_textarea($html, $request); break; } return $html; } elseif (isset($html)) { return $html; } else { return ''; } } }
/** * 连贯操作执行的find查询操作 * @param string $field */ public function count() { $this->initSql(); $sql = "SELECT count(*) as count FROM {$this->pre}{$this->table} {$this->sql['where']} {$this->sql['group']} {$this->sql['having']} {$this->sql['order']} {$this->sql['limit']}"; $this->check_query($sql); debug::start(); $re = $this->_execute('fetch_first', $sql); debug::end(); debug::add("{$sql} [" . debug::spent() . "]", 1); if (!empty($re)) { return $re['count']; } return $re; }
function filter_request($arg) { if (is_string($arg)) { $str = ''; $arg = stripslashes($arg); if (is_array($this->request_filter)) { foreach ($this->request_filter as $reg) { $arg = regex::replace($reg['pattern'], $reg['replace'], $arg); } $str = $arg; } else { debug::add('no filter set - use set_request_filter()', 'NOTICE'); $str = $arg; } debug::add($arg . ' return ' . $str); return $str; } else { debug::add($arg . ' is not type string', 'ERROR'); } }