Example #1
0
 public function __construct()
 {
     if (FALSE == $GLOBALS['G_DY']['view']['enabled']) {
         return FALSE;
     }
     if (FALSE != $GLOBALS['G_DY']['view']['auto_ob_start']) {
         ob_start();
     }
     $this->engine = syClass($GLOBALS['G_DY']['view']['engine_name'], null, $GLOBALS['G_DY']['view']['engine_path']);
     if ($GLOBALS['G_DY']['view']['config'] && is_array($GLOBALS['G_DY']['view']['config'])) {
         $engine_vars = get_class_vars(get_class($this->engine));
         foreach ($GLOBALS['G_DY']['view']['config'] as $key => $value) {
             if (array_key_exists($key, $engine_vars)) {
                 $this->engine->{$key} = $value;
             }
         }
     }
     if (!empty($GLOBALS['G_DY']['sp_app_id']) && isset($this->engine->compile_id)) {
         $this->engine->compile_id = $GLOBALS['G_DY']['sp_app_id'];
     }
     if (empty($this->engine->no_compile_dir) && (!is_dir($this->engine->compile_dir) || !is_writable($this->engine->compile_dir))) {
         __mkdirs($this->engine->compile_dir);
     }
     spAddViewFunction('spUrl', array('syView', '__template_spUrl'));
 }
Example #2
0
 /**
  * 构造函数,进行模板引擎的实例化操作
  */
 public function __construct()
 {
     if (FALSE == $GLOBALS['G_Fei']['view']['enabled']) {
         return FALSE;
     }
     if (FALSE != $GLOBALS['G_Fei']['view']['auto_ob_start']) {
         ob_start();
     }
     $this->engine = FeiClass($GLOBALS['G_Fei']['view']['engine_name'], NULL, $GLOBALS['G_Fei']['view']['engine_path']);
     if ($GLOBALS['G_Fei']['view']['config'] && is_array($GLOBALS['G_Fei']['view']['config'])) {
         $engine_vars = get_class_vars(get_class($this->engine));
         foreach ($GLOBALS['G_Fei']['view']['config'] as $key => $value) {
             if (array_key_exists($key, $engine_vars)) {
                 $this->engine->{$key} = $value;
             }
         }
     }
     if (!empty($GLOBALS['G_Fei']['Fei_app_id']) && isset($this->engine->compile_id)) {
         $this->engine->compile_id = $GLOBALS['G_Fei']['Fei_app_id'];
     }
     // 检查编译目录是否可写
     if (empty($this->engine->no_compile_dir) && (!is_dir($this->engine->compile_dir) || !is_writable($this->engine->compile_dir))) {
         __mkdirs($this->engine->compile_dir);
     }
     FeiAddViewFunction('Copyright', array('TemplateParse', '__template_Copyright'));
     FeiAddViewFunction('Title', array('TemplateParse', '__template_Title'));
     FeiAddViewFunction('Keywords', array('TemplateParse', '__template_Keywords'));
     FeiAddViewFunction('Description', array('TemplateParse', '__template_Description'));
     FeiAddViewFunction('Author', array('TemplateParse', '__template_Author'));
     FeiAddViewFunction('Category', array('TemplateParse', '__template_Category'));
     $this->site = FeiClass('model_site')->find();
     $this->contact = FeiClass('model_contact')->find();
 }
Example #3
0
 private function write($log, $severityLevel)
 {
     $destination = rtrim($this->LOG_FILE_PATH, "\\/") . '/';
     __mkdirs($destination);
     $backfix = '.log';
     $destination .= $this->LOG_FILE_PREFIX . $severityLevel;
     if (is_file($destination . $backfix) && floor($this->LOG_FILE_SIZE) <= filesize($destination . $backfix)) {
         rename($destination . $backfix, dirname($destination) . '/' . basename($destination) . '.' . time() . $backfix);
     }
     $handle = fopen($destination . $backfix, "at+");
     fwrite($handle, $log);
     fclose($handle);
 }
Example #4
0
 public function display($tplname)
 {
     //$tplname=str_replace('..','',$tplname);
     if (is_readable(realpath($this->template_dir . '/' . $tplname))) {
         $tplpath = realpath($this->template_dir . '/' . $tplname);
         //}elseif(is_readable(APP_PATH.'/'.$tplname)){
         //$tplpath = APP_PATH.'/'.$tplname;
     } else {
         $this->template_err('无法找到模板 ' . $tplname);
     }
     $templateverify = stripos($tplpath, realpath($this->template_dir));
     if ($templateverify === false || $templateverify !== 0) {
         $this->template_err('路径超出模板文件夹');
     }
     $this->template_err_tpl = $tplname;
     extract($this->_vars);
     if (syExt("view_admin") == 'admin' || $tplname == $GLOBALS['WWW'] . 'include/uploads.php') {
         $template_tpl = $tplpath;
     } else {
         $cache_time = syExt("cache_time");
         if ($cache_time > 0) {
             $this->sycache = 'syCache(' . $cache_time . ')->';
         }
         $template_tpl = str_replace('/', '_', $tplname);
         $template_tpl = str_replace('.html', '.php', $template_tpl);
         $template_tpl = realpath($this->template_tpl) . '/' . $template_tpl;
         if (syExt("cache_auto") == 1 || !is_readable($template_tpl) || filemtime($tplpath) > filemtime($template_tpl)) {
             if (!is_dir($GLOBALS['G_DY']['view']['config']['template_tpl'] . '/')) {
                 __mkdirs($GLOBALS['G_DY']['view']['config']['template_tpl'] . '/');
             }
             $fp_tp = @fopen($tplpath, "r");
             $fp_txt = @fread($fp_tp, filesize($tplpath));
             @fclose($fp_tp);
             $fp_txt = $this->template_html($fp_txt);
             $fpt_tpl = @fopen($template_tpl, "w");
             @fwrite($fpt_tpl, $fp_txt);
             @fclose($fpt_tpl);
             if (is_readable($template_tpl) !== true) {
                 $this->template_err('无法找到模板缓存,请刷新后重试,或者检查系统文件夹权限');
             }
         }
     }
     $enable_gzip = syExt('enable_gzip');
     if ($enable_gzip == 1) {
         global $__template_compression_level;
         $__template_compression_level = syExt('enable_gzip_level');
         ob_start('template_ob_gzip');
     }
     include $template_tpl;
 }
Example #5
0
/**
 * __mkdirs
 *
 * 循环建立目录的辅助函数
 *
 * @param dir    目录路径
 * @param mode    文件权限
 */
function __mkdirs($dir, $mode = 0777)
{
    if (!is_dir($dir)) {
        __mkdirs(dirname($dir), $mode);
        return @mkdir($dir, $mode);
    }
    return true;
}
Example #6
0
 /**
  * 生成单个静态页面
  * @param Feiurl         FeiUrl的参数
  * @param alias_url      生成HTML文件的名称,如果不设置alias_url,将使用年月日生成目录及随机数为文件名的形式生成HTML文件。
  * @param update_mode    更新模式,默认2为同时更新列表及文件
  *                       0是仅更新列表
  *                       1是仅更新文件
  */
 public function make($Feiurl, $alias_url = NULL, $update_mode = 2)
 {
     if (1 == FeiAccess('r', 'Fei_html_making')) {
         $this->Feiurls[] = array($Feiurl, $alias_url);
         return;
     }
     @(list($controller, $action, $args, $anchor) = $Feiurl);
     if ($url_item = FeiHtml::getUrl($controller, $action, $args, $anchor, TRUE)) {
         @(list($baseuri, $realfile) = $url_item);
         $update_mode = 1;
     } else {
         $file_root_name = '' == $GLOBALS['G_Fei']['html']['file_root_name'] ? '' : $GLOBALS['G_Fei']['html']['file_root_name'] . '/';
         if (NULL == $alias_url) {
             $filedir = $file_root_name . date('Y/n/d') . '/';
             $filename = substr(time(), 3, 10) . substr(mt_rand(100000, substr(time(), 3, 10)), 4) . ".html";
         } else {
             $filedir = $file_root_name . dirname($alias_url) . '/';
             $filename = basename($alias_url);
         }
         $baseuri = rtrim(dirname($GLOBALS['G_Fei']['url']["url_path_base"]), '/\\') . "/" . $filedir . $filename;
         $realfile = APP_PATH . "/" . $filedir . $filename;
     }
     if (0 == $update_mode or 2 == $update_mode) {
         FeiHtml::setUrl($Feiurl, $baseuri, $realfile);
     }
     if (1 == $update_mode or 2 == $update_mode) {
         $remoteurl = 'http://' . $_SERVER["SERVER_NAME"] . ':' . $_SERVER['SERVER_PORT'] . '/' . ltrim(FeiUrl($controller, $action, $args, $anchor, TRUE), '/\\');
         $cachedata = file_get_contents($remoteurl);
         if (FALSE === $cachedata) {
             $cachedata = $this->curl_get_file_contents($remoteurl);
             if (FALSE === $cachedata) {
                 FeiError("无法从网络获取页面数据,请检查:<br />1. FeiUrl生成地址是否正确!<a href='{$remoteurl}' target='_blank'>点击这里测试</a>。<br />2. 设置php.ini的allow_url_fopen为On。<br />3. 检查是否防火墙阻止了APACHE/PHP访问网络。<br />4. 建议安装CURL函数库。");
             }
         }
         __mkdirs(dirname($realfile));
         file_put_contents($realfile, $cachedata);
     }
 }
Example #7
0
/**
 * spAccess 数据缓存及存取程序
 * 
 * @param method    数据存取模式,取值"w"为存入数据,取值"r"读取数据,取值"c"为删除数据
 * @param name    标识数据的名称
 * @param value    存入的值,在读取数据和删除数据的模式下均为NULL
 * @param life_time    变量的生存时间,默认为永久保存
 */
function spAccess($method, $name, $value = NULL, $life_time = -1)
{
    // 使用function_access扩展点
    if ($launch = spLaunch("function_access", array('method' => $method, 'name' => $name, 'value' => $value, 'life_time' => $life_time), TRUE)) {
        return $launch;
    }
    // 准备缓存目录和缓存文件名称,缓存文件名称为$name的MD5值,文件后缀为php
    if (!is_dir($GLOBALS['G_SP']['sp_cache'])) {
        __mkdirs($GLOBALS['G_SP']['sp_cache']);
    }
    $sfile = $GLOBALS['G_SP']['sp_cache'] . '/' . $GLOBALS['G_SP']['sp_app_id'] . md5($name) . ".php";
    // 对$method进行判断,分别进行读写删的操作
    if ('w' == $method) {
        // 写数据,在$life_time为-1的时候,将增大$life_time值以令$life_time不过期
        $life_time = -1 == $life_time ? '300000000' : $life_time;
        // 准备存入缓存文件的数据,缓存文件使用PHP的die();函数以便保证内容安全,
        $value = '<?php die();?>' . (time() + $life_time) . serialize($value);
        // 数据被序列化后保存
        return file_put_contents($sfile, $value);
    } elseif ('c' == $method) {
        // 清除数据,直接移除改缓存文件
        return @unlink($sfile);
    } else {
        // 读数据,检查文件是否可读,同时将去除缓存数据前部的内容以返回
        if (!is_readable($sfile)) {
            return FALSE;
        }
        $arg_data = file_get_contents($sfile);
        // 获取文件保存的$life_time,检查缓存是否过期
        if (substr($arg_data, 14, 10) < time()) {
            @unlink($sfile);
            // 过期则移除缓存文件,返回FALSE
            return FALSE;
        }
        return unserialize(substr($arg_data, 24));
        // 数据反序列化后返回
    }
}