C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\xoops\html\class\template.php


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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
// $Id: template.php,v 1.21.6.16 2005/07/22 18:22:58 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                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                                                //
// ------------------------------------------------------------------------- //

if (!defined('SMARTY_DIR')) {
    exit();
}
/**
 * Base class: Smarty template engine
 */
require_once SMARTY_DIR.'Smarty.class.php';

/**
 * Template engine
 *
 * @package        kernel
 * @subpackage    core
 *
 * @author        Kazumi Ono     <onokazu@xoops.org>
 * @copyright    (c) 2000-2003 The Xoops Project - www.xoops.org
 */
class XoopsTpl extends Smarty
{

    
/**
     * Allow update of template files from the themes/ directory?
     * This should be set to false on an active site to increase performance
     */
    
var $_canUpdateFromFile false;

    
/**
     * Constructor
     **/
    
function XoopsTpl()
    {
        global 
$xoopsConfig;
        
$this->Smarty();
        
$this->compile_id null;
        if (
$xoopsConfig['theme_fromfile'] == 1) {
            
$this->_canUpdateFromFile true;
            
$this->compile_check true;
        } else {
            
$this->_canUpdateFromFile false;
            
$this->compile_check false;
        }
        
$this->left_delimiter =  '<{';
        
$this->right_delimiter =  '}>';
        
$this->template_dir XOOPS_THEME_PATH;
        
$this->cache_dir XOOPS_CACHE_PATH;
        
$this->compile_dir XOOPS_COMPILE_PATH;
        
$this->plugins_dir = array(XOOPS_ROOT_PATH.'/class/smarty/plugins');
        
$this->default_template_handler_func 'xoops_template_create';

        
// Added by goghs on 11-26 to deal with safe mode
        //if (ini_get('safe_mode') == "1") {
        
$this->use_sub_dirs false;
        
//} else {
        //    $this->use_sub_dirs = true;
        //}
        // END
    
}

    
/**
     * Set the directory for templates
     * 
     * @param   string  $dirname    Directory path without a trailing slash
     **/
    
function xoops_setTemplateDir($dirname)
    {
        
$this->template_dir $dirname;
    }

    
/**
     * Get the active template directory
     * 
     * @return  string
     **/
    
function xoops_getTemplateDir()
    {
        return 
$this->template_dir;
    }

    
/**
     * Set debugging mode
     * 
     * @param   boolean     $flag
     **/
    
function xoops_setDebugging($flag=false)
    {
        
$this->debugging is_bool($flag) ? $flag false;
    }

    
/**
     * Set caching
     * 
     * @param   integer     $num
     **/
    
function xoops_setCaching($num=0)
    {
        
$this->caching = (int)$num;
    }

    
/**
     * Set cache lifetime
     * 
     * @param   integer     $num    Cache lifetime
     **/
    
function xoops_setCacheTime($num=0)
    {
        
$num = (int)$num;
        if (
$num <= 0) {
            
$this->caching 0;
        } else {
            
$this->cache_lifetime $num;
        }
    }

    
/**
     * Set directory for compiled template files
     * 
     * @param   string  $dirname    Full directory path without a trailing slash
     **/
    
function xoops_setCompileDir($dirname)
    {
        
$this->compile_dir $dirname;
    }

    
/**
     * Set the directory for cached template files
     * 
     * @param   string  $dirname    Full directory path without a trailing slash
     **/
    
function xoops_setCacheDir($dirname)
    {
        
$this->cache_dir $dirname;
    }

    
/**
     * Render output from template data
     * 
     * @param   string  $data
     * @return  string  Rendered output  
     **/
    
function xoops_fetchFromData(&$data)
    {
        
$dummyfile XOOPS_CACHE_PATH.'/dummy_'.time();
        
$fp fopen($dummyfile'w');
        
fwrite($fp$data);
        
fclose($fp);
        
$fetched $this->fetch('file:'.$dummyfile);
        
unlink($dummyfile);
        
$this->clear_compiled_tpl('file:'.$dummyfile);
        return 
$fetched;
    }

    
/**
     * 
     **/
    
function xoops_canUpdateFromFile()
    {
        return 
$this->_canUpdateFromFile;
    }
    
    
/**
     * Get caching
     * 
     * @return int
     **/
    
function xoops_getCaching()
    {
        return 
$this->caching;
    }
}

/**
 * Smarty default template handler function
 * 
 * @param $resource_type
 * @param $resource_name
 * @param $template_source
 * @param $template_timestamp
 * @param $smarty_obj
 * @return  bool
 **/
function xoops_template_create ($resource_type$resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
{
    if ( 
$resource_type == 'db' ) {
        
$file_handler =& xoops_gethandler('tplfile');
        
$tpl =& $file_handler->find('default'nullnullnull$resource_nametrue);
        if (
count($tpl) > && is_object($tpl[0])) {
            
$template_source $tpl[0]->getSource();
            
$template_timestamp $tpl[0]->getLastModified();
            return 
true;
        }
    } else {
    }
    return 
false;
}

/**
 * function to update compiled template file in templates_c folder
 * 
 * @param   string  $tpl_id
 * @param   boolean $clear_old
 * @return  boolean
 **/
function xoops_template_touch($tplfile$clear_old true)
{
    
$tpl = new XoopsTpl();
    
$tpl->force_compile true;
    if ( 
is_object($tplfile) ) {
        
$file $tplfile->getVar('tpl_file');
        if (
$clear_old) {
            
$tpl->clear_cache('db:'.$file);
            
$tpl->clear_compiled_tpl('db:'.$file);
        }
        
$tpl->fetch('db:'.$file);
        return 
true;
    }
    return 
false;
}

/**
 * Clear the module cache
 * 
 * @param   int $mid    Module ID
 * @return 
 **/
function xoops_template_clear_module_cache($mid)
{
    
$block_handler =& xoops_gethandler('block');
    
//note this uses backwards parameters for backwards compatibility - change that!
    
$block_arr =& $block_handler->getByModule($midtruefalse);
    if (
count($block_arr) > 0) {
        
$instance_handler =& xoops_gethandler('blockinstance');
        
$instances =& $instance_handler->getObjects(new Criteria('bid'"(".implode(','array_keys($block_arr)).")""IN"));
        
$count count($instances);
        if (
$count 0) {
            
$xoopsTpl = new XoopsTpl();
            
$xoopsTpl->xoops_setCaching(2);
            for (
$i 0$i $count$i++) {
                if (
$block_arr[$instances[$i]->getVar('bid')]->getVar('template') != '') {
                    
$xoopsTpl->clear_cache('db:'.$block_arr[$instances[$i]->getVar('bid')]->getVar('template'), 'blk_'.$instances[$i]->getVar('instanceid'));
                }
            }
        }
    }
}
?>