示例#1
0
文件: Functions.php 项目: kevinwan/xf
 /**
  * 写入日志
  * @access public
  * @param string $message 内容
  * @return void
  */
 public static function log($message)
 {
     if (!is_scalar($message) && $message == '') {
         return;
     }
     $file = TEMP_PATH . '/Logs/' . date('Y-m-d') . '.log';
     XF_File::write($file, '[' . date('H:i:s') . '] ' . $message, 'a+');
 }
示例#2
0
文件: Abstract.php 项目: kevinwan/xf
 /**
  * 渲染布局模板文件
  * @access public
  * @return string
  */
 public function render()
 {
     $content = isset($this->_data['$layoutContent']) ? $this->_data['$layoutContent'] : '';
     //布局模板起始路径
     $layoutTemplatePath = APPLICATION_PATH . '/layouts/scripts/';
     if (!is_file($layoutTemplatePath . $this->_tpl)) {
         return $content;
     }
     //检测缓存
     if ($this->_cache_time > 0) {
         $request = XF_Controller_Request_Http::getInstance();
         $file = TEMP_PATH . '/Cache/LayoutScripts/';
         $pathinfo = pathinfo($this->_tpl);
         //检测布局缓存类型,定位正确的路径
         if ($this->_cache_is_private) {
             $file .= 'Private/' . $request->getModule() . '/' . $request->getController() . '/' . $request->getAction() . '/' . $pathinfo['basename'];
         } else {
             $file .= 'Public/' . $pathinfo['basename'];
         }
         XF_File::mkdirs(pathinfo($file, PATHINFO_DIRNAME));
         if (is_file($file)) {
             //布局缓存是否过期
             if (time() > filemtime($file) + $this->_cache_time * 60) {
                 //缓存失效时执行用户的初始化操作init()
                 $this->_init();
                 XF_File::del($file);
                 $this->_flag = false;
                 $content = $this->_getObContent($layoutTemplatePath . $this->_tpl);
                 XF_File::write($file, $content);
             }
             $this->_flag = true;
             return $this->_getObContent($file);
         } else {
             $this->_init();
             $this->_flag = false;
             $content = $this->_getObContent($layoutTemplatePath . $this->_tpl);
             XF_File::write($file, $content);
             $this->_flag = true;
             return $this->_getObContent($file);
         }
     } else {
         //不采用缓存时获取最终输出的HTML内容
         $this->_init();
         $this->_flag = true;
         return $this->_getObContent($layoutTemplatePath . $this->_tpl);
     }
     return $content;
 }