public function parse(&$f_pszViewType = null, $f_arrContext = array())
 {
     $page = $GLOBALS['page'];
     $szSnippetPath = PROJECT_SNIPPETS . '/' . $this->implementation_id . '.php';
     $bOutput = false;
     if ($page === $this) {
         $bOutput = true;
         header('Content-Type: ' . $this->content_type);
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->modified_time) . ' GMT', true);
         /*$bValidCache = isset($_SERVER['HTTP_IF_NONE_MATCH']) && md5_file($szSnippetPath) == $_SERVER['HTTP_IF_NONE_MATCH'];
         		header('Cache-Control: max-age=3600');
         		header('Etag: '.md5_file($szSnippetPath));
         		header('Expires: '.gmdate('D, d M Y H:i:s', strtotime('+7 days', $this->modified_time)).' GMT');*/
     }
     $tpl = new SmartyTpl($page, $this, 'snippets');
     if (is_array($f_arrContext)) {
         foreach ($f_arrContext as $k => $v) {
             $tpl->assign($k, $v);
         }
     }
     $szOutput = $tpl->fetch($szSnippetPath);
     if (!$bOutput) {
         return $szOutput;
     }
     echo $szOutput;
 }
Esempio n. 2
0
 /**
  * 更新页面缓存(纯静态和smarty缓存)
  * @author	肖飞
  * @param	int		$id					记录ID数或者单页数组的KEY
  * @param	int		$type_id			栏目类型ID 便于清除列表页的缓存
  * @param	array		$arrMOutput	输出到smartyd的数组
  * @return	void
  */
 public function updateCache($id, $type_id = 1, $arrMOutput = array())
 {
     global $arrGWeb, $arrGCache;
     if ($arrGWeb['file_static']) {
         //生成静态页面
         $intID = intval($id);
         $strDir = ceil($intID / $arrGCache['cache_filenum']);
         if (empty($intID)) {
             //单页栏目
             $intID = $id;
             $strCacheFile = $arrGCache['cache_root'] . '/' . $id . $arrGWeb['file_suffix'];
             @unlink($arrGCache['cache_root'] . '/' . $id . 'tw' . $arrGWeb['file_suffix']);
         } else {
             //其他栏目
             $strCacheFile = $arrGCache['cache_root'] . '-' . $strDir . '/' . $intID . $arrGWeb['file_suffix'];
             @unlink($arrGCache['cache_root'] . '-' . $strDir . '/' . $intID . 'tw' . $arrGWeb['file_suffix']);
         }
         $objCache = new cache($strCacheFile, $arrGCache['cache_time']);
         $objCache->cache_start();
         $strContents = @file_get_contents('http://' . $_SERVER["HTTP_HOST"] . $arrGWeb['WEB_ROOT_pre'] . '/' . $arrGWeb['module_id'] . '/detail.php?id=' . $intID);
         if ($strContents) {
             echo $strContents;
         }
         $objCache->cache_end(false);
     }
     if ($arrGWeb['URL_static']) {
         //更新smarty缓存
         $objSmarty = new SmartyTpl();
         if (empty($arrMOutput['template_dir'])) {
             $objSmarty->setTemplateDir($this->arrGSmarty['template_dir']);
         } else {
             $objSmarty->setTemplateDir($arrMOutput['template_dir']);
         }
         $objSmarty->setCompileDir($this->arrGSmarty['compile_dir']);
         $objSmarty->setCacheDir($this->arrGSmarty['cache_dir']);
         $objSmarty->plugins_dir = $this->arrGSmarty['plugins_dir'];
         $arrMOutput['smarty_debug'] = '';
         $arrMOutput['smarty_debug'] ? $objSmarty->compile_check = true : '';
         $arrMOutput['smarty_debug'] ? $objSmarty->debugging = true : '';
         $objSmarty->caching = $this->arrGSmarty['caching'];
         if ($objSmarty->caching) {
             $objSmarty->cache_lifetime = isset($this->arrGSmarty['cache_lifetime']) ? $this->arrGSmarty['cache_lifetime'] : 3600;
             $objSmarty->cache_modified_check = isset($this->arrGSmarty['cache_modified_check']) ? $this->arrGSmarty['cache_modified_check'] : false;
         }
         if (!empty($arrMOutput['smarty_assign'])) {
             while (list($key, $value) = each($arrMOutput['smarty_assign'])) {
                 $objSmarty->assign($key, $value);
             }
         }
         if ($_SESSION['langset'] == 'zh_tw') {
             $objSmarty->autoload_filters = array('output' => array('langset'));
         }
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/');
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/index.php');
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/');
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/index.php');
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/list/');
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/list.php');
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/list/type_id-' . $type_id . $arrGWeb['file_suffix']);
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/list.php/type_id-' . $type_id . $arrGWeb['file_suffix']);
         $objSmarty->clearCache($arrMOutput['template_file'], $_SESSION['langset'] . '/' . $arrGWeb['module_id'] . '/list.php?type_id=' . $type_id);
     }
     if ($arrGWeb['PDO_CACHE']) {
         if (!empty($this->arrGPdoDB['PDO_CACHE_ROOT'])) {
             check::delTreeDirs($this->arrGPdoDB['PDO_CACHE_ROOT']);
         }
     }
 }
 public final function parseView($f_objView)
 {
     $tpl = new SmartyTpl($this, $this, 'views');
     $tpl->display(PROJECT_VIEWS . '/' . $f_objView->id . '.php');
 }