示例#1
0
文件: File.php 项目: kevinwan/xf
 /**
  * 删除文件或目录
  * @access public
  * @param string $var 文件或目录路径
  * @return bool
  */
 public static function del($var)
 {
     if (empty($var)) {
         return;
     }
     if (is_file($var)) {
         unlink($var);
     }
     if (is_dir($var)) {
         $handle = opendir($var);
         while (false !== ($myFile = readdir($handle))) {
             if ($myFile != '.' && $myFile != '..') {
                 $myFile = $var . DIRECTORY_SEPARATOR . $myFile;
                 if (is_dir($myFile)) {
                     XF_File::del($myFile);
                 } else {
                     @unlink($myFile);
                 }
             }
         }
         closedir($handle);
         @rmdir($var);
     }
     unset($var);
     return true;
 }
示例#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;
 }