예제 #1
0
 /**
  * 编译模板
  *
  * @access public
  * @param $tpl
  * @return path
  */
 public function template($tpl)
 {
     $tplarr = explode(':', $tpl);
     $tplarr = array_filter($tplarr);
     $tpla = !empty($tplarr) ? array_pop($tplarr) : C_ACTION;
     $tplc = !empty($tplarr) ? array_pop($tplarr) : C_CONTROLLER;
     $tplm = !empty($tplarr) ? array_pop($tplarr) : C_MODULE;
     //模板文件
     $tplPath = APP_MODULES_PATH . (!empty($tplm) ? $tplm . C_DS : '') . 'View';
     $this->_tmp_file_path = $tplPath . C_DS . $tplc . C_DS . $tpla . '.tpl.php';
     //编译后的文件
     $this->_com_file_path = APP_TPLCOM_PATH . ($tplm ? $tplm . '_' : '') . $tplc . '_' . $tpla . '.cache.php';
     $temp_time = is_file($this->_tmp_file_path) ? filemtime($this->_tmp_file_path) : 0;
     $com_time = is_file($this->_com_file_path) ? filemtime($this->_com_file_path) : 0;
     //模板不存在
     if (!$temp_time) {
         trigger_error('template file ' . $this->_tmp_file_path . ' not exists');
     }
     if ($temp_time > $com_time) {
         if (is_file($this->_tmp_file_path)) {
             if (($tmp_content = Super('Func')->readFile($this->_tmp_file_path)) === false) {
                 trigger_error('template file ' . $this->_tmp_file_path . ' failed to open');
             }
         } else {
             //模板不存在
             trigger_error('template file ' . $this->_tmp_file_path . ' not exists');
         }
         $com_content = $this->compile($tmp_content);
         Super('Func')->makeDir(dirname($this->_com_file_path));
         Super('Func')->writeFile($this->_com_file_path, $com_content);
     }
     return $this->_com_file_path;
 }
예제 #2
0
파일: Base.php 프로젝트: kungyu/camelphp
 /**
  * 构造方法
  *
  * @access public
  * @return void
  */
 public function __construct()
 {
     $s = Super();
     foreach ($s as $k => $v) {
         $this->{$k} = $v;
     }
 }
예제 #3
0
파일: Session.php 프로젝트: kungyu/camelphp
 /**
  * 初始化Session
  *
  * @access private
  * @return void
  */
 private function __setHandler()
 {
     ini_set('session.save_handler', 'files');
     $mtime = Super('Conf')->sessionGcMaxlifetime;
     $spath = Super('Conf')->sessionPath;
     $mtime && session_cache_expire(Super('Conf')->sessionGcMaxlifetime);
     $spath && session_save_path(Super('Conf')->sessionPath);
 }
예제 #4
0
 /**
  * 从文件读出缓存
  * 
  * @access private
  * @return mixed
  */
 private function _readCache()
 {
     $value = Super('Func')->readFile($this->_path);
     //读取文件失败 返回false
     if (empty($value)) {
         return false;
     }
     $value = str_replace("<?exit('Denied!')?>", '', $value);
     preg_match('/^(\\d+)DM\\/\\/\\-\\-\\>/is', $value, $match);
     $this->_life = isset($match[1]) ? $match[1] : 0;
     //缓存失效 删除过期缓存文件 返回false
     if ($this->_life < time()) {
         $this->_delCache();
         return false;
     }
     $replace = isset($match[0]) ? $match[0] : '';
     $value = str_replace($replace, '', $value);
     return unserialize($value);
 }
예제 #5
0
 /**
  * 获取配置文件中定义的模板常量
  * @access public
  * @param $key
  * @return mixed
  */
 public function tplConstant($key)
 {
     $value = Super('Conf')->tplConstant;
     return isset($value[$key]) ? $value[$key] : '';
 }
예제 #6
0
 /**
  * 自定义error
  *
  * @access public
  * @param $errno
  * @param $errstr
  * @param $errfile
  * @param $errline
  * @return die
  */
 public function errorDebug($errno, $errstr, $errfile, $errline)
 {
     $errlevel = 'ERROR';
     switch ($errno) {
         case E_NOTICE:
             $errlevel = 'E_NOTICE';
             break;
         case E_WARNING:
             $errlevel = 'E_WARNING';
             break;
         case E_USER_ERROR:
             $errlevel = 'E_USER_ERROR';
             break;
         case E_USER_WARNING:
             $errlevel = 'E_USER_WARNING';
             break;
         case E_USER_NOTICE:
             $errlevel = 'E_USER_NOTICE';
             break;
         case E_STRICT:
             $errlevel = 'E_STRICT';
             break;
         case E_COMPILE_WARNING:
             $errlevel = 'E_COMPILE_WARNING';
     }
     //record error log
     $errmessage = "{$errlevel} [ERRID:{$errno}] {$errstr} ( Line:{$errline} of '{$errfile}')";
     Super('Log')->record($errmessage, 'error');
     //判断是否输出错误信息
     $debug = Super('Conf')->debug;
     if (!$debug) {
         die('PHP Error');
     }
     $str = '<b>' . $errlevel . ':</b> [ID ' . $errno . '] <font style="color:#cc0000;font-size:18px">' . $errstr . '</font> ( Line: ' . $errline . ' of ' . $errfile . ' )<br/>';
     $backTrace = debug_backtrace();
     $this->debugInfo($str, $backTrace);
 }
예제 #7
0
파일: Model.php 프로젝트: kungyu/camelphp
 /**
  * 实例化项目模型文件
  * M('@.admin') 代表调用当前模块中Model目录中的./Modules/项目名/Model/adminModel.php模型
  *
  * @access public
  * @param $file
  * @param $ext
  * @return object
  */
 public function load($model)
 {
     static $_model = array();
     if (!isset($_model[$model])) {
         $modelArr = explode('.', $model);
         if (count($modelArr) > 1) {
             //当前项目Model
             if ($modelArr[0] == '@') {
                 $modelPath = APP_MODULES_PATH . C_MODULE . C_DS . 'Model' . C_DS . $modelArr[1] . 'Model.php';
                 $modelName = C_MODULE . '_' . $modelArr[1] . 'Model';
             } else {
                 $modelPath = APP_MODULES_PATH . $modelArr[0] . C_DS . 'Model' . C_DS . $modelArr[1] . 'Model.php';
                 $modelName = $modelArr[0] . '_' . $modelArr[1] . 'Model';
             }
             //引入父模型,若存在
             $parentPath = APP_PATH . C_DS . 'Model' . C_DS . $modelArr[1] . 'Model.php';
             Super('Func')->requireFile($parentPath);
         } else {
             $modelPath = APP_PATH . C_DS . 'Model' . C_DS . $model . 'Model.php';
             $modelName = $model . 'Model';
         }
         if (!Super('Func')->requireFile($modelPath)) {
             trigger_error(" Model file {$modelPath} dos not exists.");
         }
         if (!class_exists($modelName)) {
             trigger_error(" Model class {$modelName} dos not exists.");
         }
         $_model[$model] = new $modelName();
     }
     return $_model[$model];
 }
예제 #8
0
파일: Log.php 프로젝트: kungyu/camelphp
 /**
  * Mysql执行日志
  *
  * @access protected
  * @param $message
  * @param $file_path
  * @return void
  */
 protected static function _mysql($message, $file_path)
 {
     $data['time'] = date('Y/m/d H:i:s', time()) . ' - -';
     $data['ip'] = Super('Func')->ip();
     $data['SQL'] = $message;
     $datas = implode(' ', $data) . "\r\n";
     Super('Func')->writeFile($file_path, $datas, 'a');
 }
예제 #9
0
파일: View.php 프로젝트: kungyu/camelphp
 /**
  * 输出内容
  *
  * @access public
  * @param $content
  * @return echo
  */
 public function output($content)
 {
     header('Cache-control: private');
     header('X-Powered-By:Camelphp');
     header('Content-Type: text/html; charset=' . Super('Conf')->charset);
     echo $content;
 }
예제 #10
0
파일: Mysql.php 프로젝트: kungyu/camelphp
 /**
  * 根据POST获取数据
  *
  * @access protected
  * @return array
  */
 protected function _data()
 {
     $data = array();
     $fields = $this->_getFields();
     if (is_array($fields)) {
         foreach ($fields as $key => $val) {
             if (!Super('Post')->{$key}) {
                 $data[$key] = Super('Post')->{$key};
             }
         }
     }
     return $data;
 }
예제 #11
0
파일: Cookie.php 프로젝트: kungyu/camelphp
 /**
  * __set()
  *
  * @access public
  * @param $key
  * @param $value
  * @return void
  */
 public function __set($key, $value)
 {
     $config = Super('Conf')->cookieConfig;
     setcookie($key, $value, time() + $config['expire'], $config['path'], $config['domain']);
 }
예제 #12
0
파일: Cache.php 프로젝트: kungyu/camelphp
 /**
  * 实例化缓存扩展类
  *
  * @access private
  * @param $class
  * @return object
  */
 private function _init($class)
 {
     static $_cache = array();
     if (!isset($_cache[$class])) {
         $cacheConfig = $class . 'Config';
         $cfg = Super('Conf')->{$cacheConfig};
         $cacheClass = ucfirst($class);
         Super('Func')->import('Extend.Cache.' . $cacheClass);
         $className = 'CP_' . $cacheClass;
         if (!class_exists($className)) {
             trigger_error('Cache error: ' . $className . ' class not exists');
         }
         $_cache[$class] = new $className();
         $_cache[$class]->config($cfg);
     }
     return $_cache[$class];
 }
예제 #13
0
/**
 * 过滤字符串
 *
 * @param $path
 * @param $index
 * @return boolean
 */
function MakeDir($path, $index = true)
{
    return Super('Func')->makeDir($path, $index);
}
예제 #14
0
 /**
  * 连接数据库
  *
  * @access private
  * @return void
  */
 private function _conndb()
 {
     if (empty($this->_dblink)) {
         Super('Func')->import('Extend.Mysql.Mysql');
         $table = $this->_config['table'];
         $cfg = isset($this->_config['connect']) ? $this->_config['connect'] : Super('Conf')->mysqlConfig;
         $this->_dblink = new CP_Mysql($table, $cfg);
     }
 }
예제 #15
0
 /**
  * 传入参数 
  */
 public function config($cfg = '')
 {
     $this->_config = !empty($cfg) ? $cfg : Super('Conf')->memcacheConfig;
 }