public function initialize()
 {
     //获取站点配置
     if (!isset($_SERVER['QUERY_STRING'])) {
         $_SERVER['QUERY_STRING'] = '';
     }
     $setting = model('setting')->where('siteid', 1)->getOne();
     $data['SEO'] = array();
     $data['SEO']['title'] = $setting['title'];
     $data['SEO']['keywords'] = $setting['keywords'];
     $data['SEO']['description'] = $setting['description'];
     $template = $setting['template'];
     //站点配置中的前台模板
     $data['page'] = isset($_GET['page']) ? $_GET['page'] : 1;
     $this->assign($data);
     unset($setting);
     Config::set(array('cache' => 1), 'database');
     Config::template();
     //载入模板配置,防止将所有的配置替换
     //==配置模板风格和静态缓存生存时间
     Config::set(array('view_name' => $template, 'template_parse' => 'template_parse', 'view_cache' => Config::cms('view_cache'), 'leftDelim' => Config::cms('tpl_leftDelim'), 'rightDelim' => Config::cms('tpl_rightDelim')), 'template');
     Loader::func('gouwanmei');
     //error_reporting(1);
     Config::set(array('debug' => 0), 'config');
 }
 public function Cache($key)
 {
     $last_modified_time = Cache::time($key, Config::template('view_cache_dir'));
     $etag = md5($key);
     header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified_time) . " GMT");
     //==设置默认缓存时间
     header('Cache-Control: max-age=' . Config::cms('html_cache_time'));
     header("Etag: {$etag}");
     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time || isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
         header("HTTP/1.1 304 Not Modified");
         exit;
     }
 }
Example #3
0
File: navi.php Project: 4otaku/draw
	public function postprocess () {

		$query = $this->data['query'];
		$module = $this->data['module'];		
		unset ($this->data['query'], $this->data['module']);

		$this->data['pages'] = array();		
		
		$this->data['base'] = $this->get_base($module, $query);

		$radius = max(1, (int) Config::template('navi_radius'));
		$low_end = max($this->data['curr_page'] - $radius, 2);
		$high_end = min($this->data['curr_page'] + $radius, $this->data['pagecount'] - 1);

		for ($i = 1; $i <= $this->data['pagecount']; $i++) {

			$inside = ($i <= $high_end && $i >= $low_end);

			if ($i == 1 || $inside || $i == $this->data['pagecount']) {
				if ($i == $this->data['curr_page']) {
					$this->data['pages'][$i] = array('type' => 'active');
				} else {
					$this->data['pages'][$i] = array('type' => 'enabled');
				}

				if ($i == 1) {
					$this->data['pages'][$i]['url'] = $this->data['base'];
				} else {
					$this->data['pages'][$i]['url'] = $this->data['base'].'page/'.$i.'/';
				}
			} else {
				$this->data['pages'][$i] = array('type' => 'skip');
				if ($i > $high_end) {
					$i = $this->data['pagecount'] - 1;
				} else {
					$i = $low_end - 1;
				}
			}
		}

		if ($this->data['curr_page'] == 2) {
			$this->data['backward'] = $this->data['base'];
		} elseif ($this->data['curr_page'] > 2) {
			$this->data['backward'] = $this->data['base'].'page/'.($this->data['curr_page'] - 1).'/';
		}

		if ($this->data['curr_page'] < $this->data['pagecount']) {
			$this->data['forward'] = $this->data['base'].'page/'.($this->data['curr_page'] + 1).'/';
		}
	}
Example #4
0
	public function postprocess () {

		if (!empty($this->data['meta']) && is_array($this->data['meta'])) {
			
			$singluar = Config::template('singular');
			$plural = Config::template('plural');			
			
			$this->data['base'] = '/'.$this->data['item_type'].'/';
			$this->data['base'] .= $this->data['area'] == 'main'? '' : $this->data['area'].'/';

			$this->data['meta_header'] = array();

			foreach ($this->data['meta'] as $type => $items) {
				
				if (count($items) < 2 && array_key_exists($type, $singluar)) {
					$this->data['meta_header'][$type] = $singluar[$type];
					
				} elseif (array_key_exists($type, $plural)) {
					$this->data['meta_header'][$type] = $plural[$type];
				}

				if ($type == 'tag') {
					foreach ($items as $tag) {
						if (!empty($tag['variants'])) {
							$this->data['have_tag_variants'] = true;
							break;
						}
					}
				}
			}
		}

		if (!empty($this->data['date'])) {
						
			$this->data['date'] = Database::date_to_unix($this->data['date']);
			
			$this->data['precise_date'] = Transform_String::rudate($this->data['date'], true);
			$this->data['date'] = Transform_String::rudate($this->data['date']);
		}
	}
/**
 * CMS 标签编译
 * @param $str
 * @return mixed
 */
function template_parse($str)
{
    $leftDelim = Config::template('leftDelim');
    $rightDelim = Config::template('rightDelim');
    //获取父级栏目信息
    $str = preg_replace_callback('/' . $leftDelim . '\\$\\_CAT\\[(.*)\\]\\[parent\\]\\[(.*)\\]' . $rightDelim . '/U', function ($match) {
        if (preg_match('/\\$([a-zA-Z0-9_]*)\\.([a-zA-Z0-9_]*)/', $match[1], $res)) {
            return "<?php \$cat = Module('content')->categoryParent(\${$res['1']}['{$res['2']}']); if(!empty(\$cat)){ ?>{\$cat[{$match['2']}]}<?php } unset(\$cat); ?>";
            // exit;
        } else {
            return "<?php \$cat = Module('content')->categoryParent({$match['1']}); if(!empty(\$cat)){ ?>{\$cat[{$match['2']}]}<?php } unset(\$cat); ?>";
        }
    }, $str);
    //获取栏目信息
    $str = preg_replace_callback('/' . $leftDelim . '\\$\\_CAT\\[(.*)\\]\\[(.*)\\]' . $rightDelim . '/U', function ($match) {
        if (preg_match('/\\$([a-zA-Z0-9_]*)\\.([a-zA-Z0-9_]*)/', $match[1], $res)) {
            return "<?php \$cat = Module('content')->category(\${$res['1']}['{$res['2']}']); if(!empty(\$cat)){ ?>{\$cat[{$match['2']}]}<?php } unset(\$cat); ?>";
            // exit;
        } else {
            return "<?php \$cat = Module('content')->category({$match['1']}); if(!empty(\$cat)){ ?>{\$cat[{$match['2']}]}<?php } unset(\$cat); ?>";
        }
    }, $str);
    return $str;
}
Example #6
0
 /**
  * @param $type 要清理的缓存存放的空间
  */
 public function flush_cache($type)
 {
     //可以以后再加
     $cachetype = array('db', 'view_c', 'admin', 'cms');
     if ($type == 'db') {
         echo '正在清理数据库缓存。。。。。。<br>';
         ob_flush();
         flush();
         echo (cache::flush(Config::database('cache_dir')) ? '后台数据库缓存清理完成。' : '后台数据库缓存清理失败!') . '<br>';
         ob_flush();
         flush();
     } else {
         if ($type == 'view_c') {
             echo '正在清理后台模板缓存。。。。。。<br>';
             ob_flush();
             flush();
             echo (cache::flush(Config::template('view_c_dir')) ? '后台数据库缓存清理完成。' : '后台数据库缓存清理失败!') . '<br>';
             ob_flush();
             flush();
             echo '正在清理前台缓存。。。。。。<br/>';
             ob_flush();
             flush();
             echo (cache::flush(Config::cms('cms_app_name')) ? '前台缓存清理完成。' : '前台缓存清理失败!') . '<br>';
             ob_flush();
             flush();
         } else {
             if ($type == 'admin') {
                 echo '正在清理后台缓存。。。。。。<br>';
                 ob_flush();
                 flush();
                 echo (cache::flush('admin') ? '后台缓存清理完成。' : '后台缓存清理失败!') . '<br>';
                 ob_flush();
                 flush();
             } else {
                 if ($type == 'all') {
                     foreach ($cachetype as $type) {
                         $this->flush_cache($type);
                     }
                     echo '缓存清理完毕!';
                 }
             }
         }
     }
 }
Example #7
0
<?php

/**
 * 视图引入变量
 * 定义为$var,视图中可以使用
 * 在视图中需要的变量在这里添加
 */
return array('app_dir' => Config::config('app_dir'), 'app_entry' => $_SERVER['SCRIPT_NAME'], 'core_dir' => Config::config('coe_dir'), 'public_path' => Config::template('public_path'), 'css_path' => Config::template('css_path'), 'js_path' => Config::template('js_path'), 'img_path' => Config::template('img_path'));
Example #8
0
<?php

/**
 * Created by PhpStorm.
 * User: Alexandr
 * Date: 31.01.16
 * Time: 10:19
 */
if (isset($_GET['route'])) {
    $temp = explode('/', $_GET['route']);
    if ($temp[0] == 'admin') {
        $_GET['module'] = "admin";
        Config::$template = 'admin';
        //if(!isset($_GET['module'])){
        //$_GET['module'] = 'home';
        //}
        unset($temp[0]);
    }
    foreach ($temp as $k => $v) {
        if ($k == 0) {
            $_GET['module'] = $v;
        } elseif ($k == 1) {
            $_GET['page'] = $v;
        } else {
            $_GET['key' . ($k - 1)] = $v;
        }
    }
    unset($_GET['route']);
}
if (!isset($_GET['module']) || $_GET['module'] == "") {
    $_GET['module'] = "main";
Example #9
0
 private function includePicsScript()
 {
     if ($this->have_pics_script == 0) {
         $this->have_pics_script = 1;
         return '<script type="text/javascript" src="' . Config::template('public_path') . 'kindeditor/pics.js"></script>';
     }
 }
Example #10
0
 /**
  * 编译保存静态缓存
  * @param string $template 模板(已经编译好的)
  * @param string $cacheKey 缓存密钥
  */
 private function cache_compile($template, $cacheKey)
 {
     ob_start();
     foreach ($this->var as $k => $v) {
         ${$k} = $v;
     }
     @(include $this->get_path($template));
     $content = ob_get_contents();
     ob_end_clean();
     echo $content;
     $t = date("Y-m-d H:i:s");
     return Cache::set($this->get_temp_name($template, $cacheKey), $content, Config::template('view_cache_dir'));
 }