1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205:
<?php
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
/**
* The templates class that extends Smarty
*
* @copyright http://www.impresscms.org/ The ImpressCMS Project
* @license LICENSE.txt
* @category ICMS
* @package View
* @subpackage Templates
* @author modified by UnderDog <underdog@impresscms.org>
* @version SVN: $Id: Tpl.php 12313 2013-09-15 21:14:35Z skenow $
*/
if (!defined('SMARTY_DIR')) {
exit();
}
/**
* Base class: Smarty template engine
*/
require_once SMARTY_DIR . 'Smarty.class.php';
/**
* Template engine
*
* @category ICMS
* @package View
* @subpackage Templates
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright Copyright (c) 2000 XOOPS.org
*/
class icms_view_Tpl extends Smarty {
public $left_delimiter = '<{';
public $right_delimiter = '}>';
public $template_dir = ICMS_THEME_PATH;
public $cache_dir = ICMS_CACHE_PATH;
public $compile_dir = ICMS_COMPILE_PATH;
public function __construct() {
global $icmsConfig;
$this->compile_id = $icmsConfig['template_set'] . '-' . $icmsConfig['theme_set'];
$this->_compile_id = $this->compile_id;
$this->compile_check = ( $icmsConfig['theme_fromfile'] == 1 );
$this->plugins_dir = array(
SMARTY_DIR . 'icms_plugins',
SMARTY_DIR . 'plugins',
);
// For backwars compatibility...
if (file_exists(ICMS_ROOT_PATH . '/class/smarty/plugins')) {
$this->plugins_dir[] = ICMS_ROOT_PATH . '/class/smarty/plugins';
}
if (file_exists(ICMS_ROOT_PATH . '/class/smarty/xoops_plugins')) {
$this->plugins_dir[] = ICMS_ROOT_PATH . '/class/smarty/xoops_plugins';
}
if ($icmsConfig['debug_mode']) {
$this->debugging_ctrl = 'URL';
$groups = (is_object(icms::$user)) ? icms::$user->getGroups() : array(ICMS_GROUP_ANONYMOUS);
$moduleid = (isset($icmsModule) && is_object($icmsModule)) ? $icmsModule->getVar('mid') : 1;
$gperm_handler = icms::handler('icms_member_groupperm');
if ($icmsConfig['debug_mode'] == 3 && $gperm_handler->checkRight('enable_debug', $moduleid, $groups)) {
$this->debugging = true;
}
}
parent::__construct();
if (defined('_ADM_USE_RTL') && _ADM_USE_RTL) {
$this->assign('icms_rtl', true);
}
$this->assign(
array(
'icms_url' => ICMS_URL,
'icms_rootpath' => ICMS_ROOT_PATH,
'modules_url' => ICMS_MODULES_URL,
'modules_rootpath' => ICMS_MODULES_PATH,
'icms_langcode' => _LANGCODE,
'icms_langname' => $GLOBALS["icmsConfig"]["language"],
'icms_charset' => _CHARSET,
'icms_version' => ICMS_VERSION_NAME,
'icms_upload_url' => ICMS_UPLOAD_URL,
'xoops_url' => ICMS_URL,
'xoops_rootpath' => ICMS_ROOT_PATH,
'xoops_langcode' => _LANGCODE,
'xoops_charset' => _CHARSET,
'xoops_version' => ICMS_VERSION_NAME,
'xoops_upload_url' => ICMS_UPLOAD_URL
)
);
}
/**
* Renders output from template data
*
* @param string $data The template to render
* @param bool $display If rendered text should be output or returned
* @return string Rendered output if $display was false
**/
public function fetchFromData($tplSource, $display = false, $vars = null) {
if (!function_exists('smarty_function_eval')) {
require_once SMARTY_DIR . '/plugins/function.eval.php';
}
if (isset($vars)) {
$oldVars = $this->_tpl_vars;
$this->assign($vars);
$out = smarty_function_eval(array('var' => $tplSource), $this);
$this->_tpl_vars = $oldVars;
return $out;
}
return smarty_function_eval(array('var' => $tplSource), $this );
}
/**
* Touch the resource (file) which means get it to recompile the resource
*
* @param string $resourcename Resourcename to touch
* @return string $result Was the resource recompiled
**/
public function touch($resourceName) {
$isForced = $this->force_compile;
$this->force_compile = true;
$this->clear_cache($resourceName);
$result = $this->_compile_resource($resourceName, $this->_get_compile_path($resourceName));
$this->force_compile = $isForced;
return $result;
}
/**
* function to update compiled template file in templates_c folder
*
* The proper way to use this would be
* icms_view_Tpl::template_touch($tplid);
*
* @param string $tpl_id
* @return boolean
**/
static public function template_touch($tpl_id) {
$tplfile_handler =& icms::handler('icms_view_template_file');
$tplfile =& $tplfile_handler->get($tpl_id);
if (is_object($tplfile)) {
$file = $tplfile->getVar('tpl_file', 'n');
$tpl = new icms_view_Tpl();
return $tpl->touch("db:$file");
}
return false;
}
/**
* Clear the module cache
*
* The proper way to use this would be
* icms_view_Tpl::template_clear_module_cache($tplid);
*
* @param int $mid Module ID
* @return
**/
static public function template_clear_module_cache($mid) {
$icms_block_handler = icms::handler('icms_view_block');
$block_arr = $icms_block_handler->getByModule($mid);
$count = count($block_arr);
if ($count > 0) {
$xoopsTpl = new icms_view_Tpl();
$xoopsTpl->caching = 2;
for ($i = 0; $i < $count; $i++) {
if ($block_arr[$i]->getVar('template') != '') {
$xoopsTpl->clear_cache('db:'.$block_arr[$i]->getVar('template'), 'blk_'.$block_arr[$i]->getVar('bid'));
}
}
}
}
}