2001-02-10 22:46:40 +00:00
|
|
|
<?php
|
2000-08-08 17:05:38 +00:00
|
|
|
/*
|
2001-02-01 21:39:29 +00:00
|
|
|
* Project: Smarty: the PHP compiling template engine
|
|
|
|
|
* File: Smarty.class.php
|
|
|
|
|
* Author: Monte Ohrt <monte@ispi.net>
|
2001-04-25 15:49:51 +00:00
|
|
|
* Andrei Zmievski <andrei@php.net>
|
2000-11-17 21:47:41 +00:00
|
|
|
*
|
2001-05-16 19:53:43 +00:00
|
|
|
* Version: 1.4.1
|
2001-01-25 23:07:36 +00:00
|
|
|
* Copyright: 2001 ispi of Lincoln, Inc.
|
2001-02-01 21:39:29 +00:00
|
|
|
*
|
2001-02-08 14:48:51 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-01-18 20:41:43 +00:00
|
|
|
*
|
2001-02-08 14:48:51 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2001-01-18 20:41:43 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-02-08 14:48:51 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-01-18 20:41:43 +00:00
|
|
|
*
|
2001-02-08 14:48:51 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-18 20:41:43 +00:00
|
|
|
*
|
2001-04-11 18:35:17 +00:00
|
|
|
* For questions, help, comments, discussion, etc., please join the
|
|
|
|
|
* Smarty mailing list. Send a blank e-mail to smarty-subscribe@lists.ispi.net
|
|
|
|
|
*
|
2001-01-18 20:41:43 +00:00
|
|
|
* You may contact the authors of Smarty by e-mail at:
|
|
|
|
|
* monte@ispi.net
|
2001-04-25 15:49:51 +00:00
|
|
|
* andrei@php.net
|
2001-01-18 20:41:43 +00:00
|
|
|
*
|
|
|
|
|
* Or, write to:
|
|
|
|
|
* Monte Ohrt
|
|
|
|
|
* CTO, ispi
|
|
|
|
|
* 237 S. 70th suite 220
|
|
|
|
|
* Lincoln, NE 68510
|
|
|
|
|
*
|
|
|
|
|
* The latest version of Smarty can be obtained from:
|
2001-01-30 17:45:53 +00:00
|
|
|
* http://www.phpinsider.com/
|
2000-08-08 17:05:38 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2001-05-09 13:42:40 +00:00
|
|
|
require_once dirname(__FILE__) . '/Smarty.addons.php';
|
2000-08-08 17:05:38 +00:00
|
|
|
|
2001-02-26 16:33:30 +00:00
|
|
|
define("SMARTY_PHP_PASSTHRU",0);
|
|
|
|
|
define("SMARTY_PHP_QUOTE",1);
|
|
|
|
|
define("SMARTY_PHP_REMOVE",2);
|
|
|
|
|
define("SMARTY_PHP_ALLOW",3);
|
2001-02-20 21:20:08 +00:00
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
class Smarty
|
|
|
|
|
{
|
|
|
|
|
|
2001-04-11 18:35:17 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/* BEGIN SMARTY CONFIGURATION SECTION */
|
|
|
|
|
/* Set the following config variables to your liking. */
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
2001-02-01 21:39:29 +00:00
|
|
|
// public vars
|
2001-02-06 21:17:37 +00:00
|
|
|
var $template_dir = './templates'; // name of directory for templates
|
|
|
|
|
var $compile_dir = './templates_c'; // name of directory for compiled templates
|
|
|
|
|
var $config_dir = './configs'; // directory where config files are located
|
2001-02-01 21:43:04 +00:00
|
|
|
|
2001-04-26 22:07:06 +00:00
|
|
|
var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
|
2001-04-24 15:16:14 +00:00
|
|
|
); // variables from the GLOBALS array
|
|
|
|
|
// that are implicitly assigned
|
|
|
|
|
// to all templates
|
|
|
|
|
var $undefined = null; // undefined variables in $global_assign will be
|
|
|
|
|
// created with this value
|
2001-02-01 21:39:29 +00:00
|
|
|
var $compile_check = true; // whether to check for compiling step or not:
|
2001-01-31 22:42:05 +00:00
|
|
|
// This is generally set to false once the
|
|
|
|
|
// application is entered into production and
|
|
|
|
|
// initially compiled. Leave set to true
|
2001-02-05 21:10:20 +00:00
|
|
|
// during development. true/false default true.
|
2001-01-31 22:42:05 +00:00
|
|
|
|
2001-02-01 21:39:29 +00:00
|
|
|
var $force_compile = false; // force templates to compile every time.
|
2001-04-11 18:35:17 +00:00
|
|
|
// if caching is on, a cached file will
|
2001-02-05 21:10:20 +00:00
|
|
|
// override compile_check and force_compile.
|
|
|
|
|
// true/false. default false.
|
2001-04-11 18:35:17 +00:00
|
|
|
|
2001-02-01 21:43:04 +00:00
|
|
|
var $caching = false; // whether to use caching or not. true/false
|
2001-02-06 21:17:37 +00:00
|
|
|
var $cache_dir = './cache'; // name of directory for template cache
|
2001-02-01 21:39:29 +00:00
|
|
|
var $cache_lifetime = 3600; // number of seconds cached content will persist.
|
2001-01-31 22:42:05 +00:00
|
|
|
// 0 = never expires. default is one hour (3600)
|
2001-04-24 15:16:14 +00:00
|
|
|
var $insert_tag_check = true; // if you have caching turned on and you
|
|
|
|
|
// don't use {insert} tags anywhere
|
|
|
|
|
// in your templates, set this to false.
|
|
|
|
|
// this will tell Smarty not to look for
|
|
|
|
|
// insert tags and speed up cached page
|
|
|
|
|
// fetches.
|
2001-02-05 21:10:20 +00:00
|
|
|
|
2001-04-12 16:16:24 +00:00
|
|
|
var $tpl_file_ext = '.tpl'; // template file extention
|
|
|
|
|
|
2001-04-11 18:35:17 +00:00
|
|
|
var $php_handling = SMARTY_PHP_PASSTHRU;
|
|
|
|
|
// how smarty handles php tags in the templates
|
2001-02-26 16:33:30 +00:00
|
|
|
// possible values:
|
|
|
|
|
// SMARTY_PHP_PASSTHRU -> echo tags as is
|
|
|
|
|
// SMARTY_PHP_QUOTE -> escape tags as entities
|
|
|
|
|
// SMARTY_PHP_REMOVE -> remove php tags
|
|
|
|
|
// SMARTY_PHP_ALLOW -> execute php tags
|
|
|
|
|
// default: SMARTY_PHP_PASSTHRU
|
2000-08-08 17:05:38 +00:00
|
|
|
|
2001-02-06 21:17:37 +00:00
|
|
|
var $left_delimiter = '{'; // template tag delimiters.
|
|
|
|
|
var $right_delimiter = '}';
|
2001-03-01 23:00:06 +00:00
|
|
|
|
2001-04-24 16:43:05 +00:00
|
|
|
var $compiler_funcs = array(
|
|
|
|
|
);
|
|
|
|
|
|
2001-02-26 16:33:30 +00:00
|
|
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
2001-03-01 15:32:56 +00:00
|
|
|
'html_select_date' => 'smarty_func_html_select_date',
|
2001-03-10 20:39:16 +00:00
|
|
|
'html_select_time' => 'smarty_func_html_select_time',
|
2001-03-02 17:02:44 +00:00
|
|
|
'math' => 'smarty_func_math',
|
2001-05-09 14:06:59 +00:00
|
|
|
'fetch' => 'smarty_func_fetch',
|
|
|
|
|
'counter' => 'smarty_func_counter'
|
2001-02-26 16:33:30 +00:00
|
|
|
);
|
|
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
var $custom_mods = array( 'lower' => 'strtolower',
|
|
|
|
|
'upper' => 'strtoupper',
|
|
|
|
|
'capitalize' => 'ucwords',
|
|
|
|
|
'escape' => 'smarty_mod_escape',
|
|
|
|
|
'truncate' => 'smarty_mod_truncate',
|
|
|
|
|
'spacify' => 'smarty_mod_spacify',
|
|
|
|
|
'date_format' => 'smarty_mod_date_format',
|
|
|
|
|
'string_format' => 'smarty_mod_string_format',
|
|
|
|
|
'replace' => 'smarty_mod_replace',
|
|
|
|
|
'strip_tags' => 'smarty_mod_strip_tags',
|
|
|
|
|
'default' => 'smarty_mod_default',
|
|
|
|
|
'count_characters' => 'smarty_mod_count_characters',
|
|
|
|
|
'count_words' => 'smarty_mod_count_words',
|
|
|
|
|
'count_sentences' => 'smarty_mod_count_sentences',
|
|
|
|
|
'count_paragraphs' => 'smarty_mod_count_paragraphs'
|
2001-02-26 16:33:30 +00:00
|
|
|
);
|
2001-03-23 17:52:50 +00:00
|
|
|
|
2001-05-16 19:53:43 +00:00
|
|
|
var $version = '1.4.1'; // Smarty version number
|
2001-04-24 15:29:33 +00:00
|
|
|
var $show_info_header = false; // display HTML info header at top of page output
|
2001-03-01 23:00:06 +00:00
|
|
|
|
2001-04-12 21:00:47 +00:00
|
|
|
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
|
|
|
|
|
// Smarty to compile templates
|
2001-04-24 16:43:05 +00:00
|
|
|
var $resource_funcs = array(); // what functions resource handlers are mapped to
|
2001-04-26 22:07:06 +00:00
|
|
|
var $prefilter_funcs = array(); // what functions templates are prefiltered through
|
2001-04-24 16:43:05 +00:00
|
|
|
// before being compiled
|
2001-04-12 21:00:47 +00:00
|
|
|
|
2001-04-11 18:35:17 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/* END SMARTY CONFIGURATION SECTION */
|
|
|
|
|
/* There should be no need to touch anything below this line. */
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
2001-02-01 21:39:29 +00:00
|
|
|
// internal vars
|
|
|
|
|
var $_error_msg = false; // error messages. true/false
|
2001-04-24 15:16:14 +00:00
|
|
|
var $_tpl_vars = array(); // where assigned template vars are kept
|
2001-03-03 15:41:52 +00:00
|
|
|
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
2001-02-01 21:39:29 +00:00
|
|
|
|
2001-04-26 22:07:06 +00:00
|
|
|
|
2000-11-22 16:23:19 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: Smarty
|
|
|
|
|
Purpose: Constructor
|
2000-11-22 16:23:19 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function Smarty()
|
|
|
|
|
{
|
2001-04-24 15:16:14 +00:00
|
|
|
foreach ($this->global_assign as $key => $var_name) {
|
|
|
|
|
if (is_array($var_name)) {
|
|
|
|
|
foreach ($var_name as $var) {
|
|
|
|
|
if (isset($GLOBALS[$key][$var])) {
|
|
|
|
|
$this->assign($var, $GLOBALS[$key][$var]);
|
|
|
|
|
} else {
|
|
|
|
|
$this->assign($var, $this->undefined);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (isset($GLOBALS[$var_name])) {
|
|
|
|
|
$this->assign($var_name, $GLOBALS[$var_name]);
|
|
|
|
|
} else {
|
|
|
|
|
$this->assign($var_name, $this->undefined);
|
|
|
|
|
}
|
2001-03-02 18:07:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
2000-11-22 16:23:19 +00:00
|
|
|
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: assign()
|
|
|
|
|
Purpose: assigns values to template variables
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function assign($tpl_var, $value = NULL)
|
|
|
|
|
{
|
|
|
|
|
if (is_array($tpl_var)){
|
|
|
|
|
foreach ($tpl_var as $key => $val) {
|
|
|
|
|
if (!empty($key))
|
|
|
|
|
$this->_tpl_vars[$key] = $val;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!empty($tpl_var) && isset($value))
|
|
|
|
|
$this->_tpl_vars[$tpl_var] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-21 15:21:16 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: append
|
|
|
|
|
Purpose: appens values to template variables
|
2000-11-21 15:21:16 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function append($tpl_var, $value = NULL)
|
|
|
|
|
{
|
|
|
|
|
if (is_array($tpl_var)) {
|
|
|
|
|
foreach ($tpl_var as $key => $val) {
|
|
|
|
|
if (!empty($key)) {
|
|
|
|
|
if (!is_array($this->_tpl_vars[$key]))
|
|
|
|
|
settype($this->_tpl_vars[$key], 'array');
|
|
|
|
|
$this->_tpl_vars[$key][] = $val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!empty($tpl_var) && isset($value)) {
|
|
|
|
|
if (!is_array($this->_tpl_vars[$tpl_var]))
|
|
|
|
|
settype($this->_tpl_vars[$tpl_var], 'array');
|
|
|
|
|
$this->_tpl_vars[$tpl_var][] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-11-21 15:21:16 +00:00
|
|
|
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: clear_assign()
|
|
|
|
|
Purpose: clear the given assigned template variable.
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function clear_assign($tpl_var)
|
|
|
|
|
{
|
2001-04-12 20:53:21 +00:00
|
|
|
if (is_array($tpl_var))
|
|
|
|
|
foreach ($tpl_var as $curr_var)
|
2001-02-08 14:18:25 +00:00
|
|
|
unset($this->_tpl_vars[$curr_var]);
|
|
|
|
|
else
|
|
|
|
|
unset($this->_tpl_vars[$tpl_var]);
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
2000-08-08 17:05:38 +00:00
|
|
|
|
2001-02-02 16:55:55 +00:00
|
|
|
|
|
|
|
|
/*======================================================================*\
|
2001-02-07 20:55:39 +00:00
|
|
|
Function: register_function
|
2001-02-02 16:55:55 +00:00
|
|
|
Purpose: Registers custom function to be used in templates
|
|
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function register_function($function, $function_impl)
|
2001-02-02 16:55:55 +00:00
|
|
|
{
|
|
|
|
|
$this->custom_funcs[$function] = $function_impl;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-02 17:02:44 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: unregister_function
|
|
|
|
|
Purpose: Unregisters custom function
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function unregister_function($function)
|
|
|
|
|
{
|
|
|
|
|
unset($this->custom_funcs[$function]);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-24 16:43:05 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: register_compiler_function
|
|
|
|
|
Purpose: Registers compiler function
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function register_compiler_function($function, $function_impl)
|
|
|
|
|
{
|
|
|
|
|
$this->compiler_funcs[$function] = $function_impl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: unregister_compiler_function
|
|
|
|
|
Purpose: Unregisters compiler function
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function unregister_compiler_function($function)
|
|
|
|
|
{
|
|
|
|
|
unset($this->compiler_funcs[$function]);
|
|
|
|
|
}
|
2001-03-02 17:02:44 +00:00
|
|
|
|
2001-02-02 16:55:55 +00:00
|
|
|
/*======================================================================*\
|
2001-02-07 20:55:39 +00:00
|
|
|
Function: register_modifier
|
2001-02-02 16:55:55 +00:00
|
|
|
Purpose: Registers modifier to be used in templates
|
|
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function register_modifier($modifier, $modifier_impl)
|
2001-02-02 16:55:55 +00:00
|
|
|
{
|
|
|
|
|
$this->custom_mods[$modifier] = $modifier_impl;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-02 17:02:44 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: unregister_modifier
|
|
|
|
|
Purpose: Unregisters modifier
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function unregister_modifier($modifier)
|
|
|
|
|
{
|
|
|
|
|
unset($this->custom_mods[$modifier]);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-19 16:18:17 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: register_resource
|
|
|
|
|
Purpose: Registers a resource to fetch a template
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function register_resource($name, $function_name)
|
|
|
|
|
{
|
2001-04-24 16:43:05 +00:00
|
|
|
$this->resource_funcs[$name] = $function_name;
|
2001-04-19 16:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: unregister_resource
|
|
|
|
|
Purpose: Unregisters a resource
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function unregister_resource($name)
|
|
|
|
|
{
|
2001-04-24 16:43:05 +00:00
|
|
|
unset($this->resource_funcs[$name]);
|
2001-04-19 16:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2001-04-19 21:08:17 +00:00
|
|
|
/*======================================================================*\
|
2001-04-26 17:27:40 +00:00
|
|
|
Function: register_prefilter
|
|
|
|
|
Purpose: Registers a prefilter function to apply
|
2001-04-19 21:08:17 +00:00
|
|
|
to a template before compiling
|
|
|
|
|
\*======================================================================*/
|
2001-04-26 17:27:40 +00:00
|
|
|
function register_prefilter($function_name)
|
2001-04-19 21:08:17 +00:00
|
|
|
{
|
2001-04-26 17:27:40 +00:00
|
|
|
$this->prefilter_funcs[] = $function_name;
|
2001-04-19 21:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
2001-04-26 17:27:40 +00:00
|
|
|
Function: unregister_prefilter
|
|
|
|
|
Purpose: Unregisters a prefilter
|
2001-04-19 21:08:17 +00:00
|
|
|
\*======================================================================*/
|
2001-04-26 17:27:40 +00:00
|
|
|
function unregister_prefilter($function_name)
|
2001-04-19 21:08:17 +00:00
|
|
|
{
|
|
|
|
|
$tmp_array = array();
|
2001-04-26 17:27:40 +00:00
|
|
|
foreach($this->prefilter_funcs as $curr_func) {
|
2001-04-19 21:08:17 +00:00
|
|
|
if($curr_func != $function_name) {
|
|
|
|
|
$tmp_array[] = $curr_func;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-26 17:27:40 +00:00
|
|
|
$this->prefilter_funcs = $tmp_array;
|
2001-04-19 21:08:17 +00:00
|
|
|
}
|
2001-02-02 16:55:55 +00:00
|
|
|
|
2001-02-01 21:09:17 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: clear_cache()
|
2001-02-07 20:55:39 +00:00
|
|
|
Purpose: clear cached content for the given template and cache id
|
2001-02-01 21:09:17 +00:00
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function clear_cache($tpl_file, $cache_id = null)
|
2001-02-01 21:39:29 +00:00
|
|
|
{
|
2001-02-06 21:17:37 +00:00
|
|
|
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
|
2001-02-07 20:55:39 +00:00
|
|
|
$cache_dir = $this->cache_dir.'/'.$cache_tpl_md5;
|
|
|
|
|
|
|
|
|
|
if (!is_dir($cache_dir))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (isset($cache_id)) {
|
|
|
|
|
$cache_id_md5 = md5($cache_id);
|
|
|
|
|
$cache_id_dir = substr($cache_id_md5, 0, 2);
|
|
|
|
|
$cache_file = "$cache_dir/$cache_id_dir/{$cache_tpl_md5}_$cache_id_md5.cache";
|
|
|
|
|
return (bool)(is_file($cache_file) && unlink($cache_file));
|
|
|
|
|
} else
|
|
|
|
|
return $this->_clear_tpl_cache_dir($cache_tpl_md5);
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-02-01 20:21:02 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: clear_all_cache()
|
2001-02-06 21:17:37 +00:00
|
|
|
Purpose: clear the entire contents of cache (all templates)
|
2001-02-01 20:21:02 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function clear_all_cache()
|
|
|
|
|
{
|
2001-02-06 21:17:37 +00:00
|
|
|
if (!is_dir($this->cache_dir))
|
2001-02-01 21:39:29 +00:00
|
|
|
return false;
|
|
|
|
|
|
2001-02-06 21:17:37 +00:00
|
|
|
$dir_handle = opendir($this->cache_dir);
|
|
|
|
|
while ($curr_dir = readdir($dir_handle)) {
|
|
|
|
|
if ($curr_dir == '.' || $curr_dir == '..' ||
|
|
|
|
|
!is_dir($this->cache_dir.'/'.$curr_dir))
|
2001-02-01 21:39:29 +00:00
|
|
|
continue;
|
2001-02-06 21:17:37 +00:00
|
|
|
|
|
|
|
|
$this->_clear_tpl_cache_dir($curr_dir);
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
2001-02-06 21:17:37 +00:00
|
|
|
closedir($dir_handle);
|
|
|
|
|
|
2001-02-07 20:55:39 +00:00
|
|
|
return true;
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
2001-02-05 21:10:20 +00:00
|
|
|
|
2001-02-07 20:55:39 +00:00
|
|
|
|
2001-02-05 21:10:20 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: is_cached()
|
|
|
|
|
Purpose: test to see if valid cache exists for this template
|
|
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function is_cached($tpl_file, $cache_id = null)
|
2001-02-05 21:10:20 +00:00
|
|
|
{
|
2001-02-07 23:08:00 +00:00
|
|
|
if (!$this->caching)
|
|
|
|
|
return false;
|
|
|
|
|
|
2001-02-07 20:55:39 +00:00
|
|
|
// cache name = template path + cache_id
|
2001-02-06 21:17:37 +00:00
|
|
|
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
|
2001-02-07 20:55:39 +00:00
|
|
|
$cache_id_md5 = md5($cache_id);
|
|
|
|
|
$cache_id_dir = substr($cache_id_md5, 0, 2);
|
|
|
|
|
$cache_file = $this->cache_dir."/$cache_tpl_md5/$cache_id_dir/{$cache_tpl_md5}_$cache_id_md5.cache";
|
2001-02-06 21:17:37 +00:00
|
|
|
|
|
|
|
|
if (file_exists($cache_file) &&
|
|
|
|
|
($this->cache_lifetime == 0 ||
|
|
|
|
|
(time() - filemtime($cache_file) <= $this->cache_lifetime)))
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
2001-02-05 21:10:20 +00:00
|
|
|
|
|
|
|
|
}
|
2001-02-01 21:39:29 +00:00
|
|
|
|
2001-02-05 21:10:20 +00:00
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: clear_all_assign()
|
|
|
|
|
Purpose: clear all the assigned template variables.
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function clear_all_assign()
|
|
|
|
|
{
|
|
|
|
|
$this->_tpl_vars = array();
|
|
|
|
|
}
|
2000-08-08 17:05:38 +00:00
|
|
|
|
2001-04-26 17:27:40 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: clear_compile_dir()
|
|
|
|
|
Purpose: clears compiled version of specified template resource,
|
|
|
|
|
or all compiled template files if one is not specified.
|
2001-04-26 22:07:06 +00:00
|
|
|
This function is for advanced use only, not normally needed.
|
2001-04-26 17:27:40 +00:00
|
|
|
\*======================================================================*/
|
2001-04-26 22:07:06 +00:00
|
|
|
function clear_compile_dir($tpl_file = null)
|
2001-04-26 17:27:40 +00:00
|
|
|
{
|
|
|
|
|
if (!is_dir($this->compile_dir))
|
|
|
|
|
return false;
|
|
|
|
|
|
2001-04-26 22:07:06 +00:00
|
|
|
if (isset($tpl_file)) {
|
2001-04-26 17:27:40 +00:00
|
|
|
// remove compiled template file if it exists
|
|
|
|
|
$tpl_file = urlencode($tpl_file).'.php';
|
2001-04-26 22:07:06 +00:00
|
|
|
if (file_exists($this->compile_dir.'/'.$tpl_file)) {
|
|
|
|
|
unlink($this->compile_dir.'/'.$tpl_file);
|
2001-04-26 17:27:40 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// remove everything in $compile_dir
|
|
|
|
|
$dir_handle = opendir($this->compile_dir);
|
|
|
|
|
while ($curr_file = readdir($dir_handle)) {
|
|
|
|
|
if ($curr_file == '.' || $curr_dir == '..' ||
|
2001-04-26 22:07:06 +00:00
|
|
|
!is_file($this->compile_dir.'/'.$curr_file)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2001-04-26 17:27:40 +00:00
|
|
|
unlink($this->compile_dir.'/'.$curr_file);
|
|
|
|
|
}
|
|
|
|
|
closedir($dir_handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2000-11-21 15:21:16 +00:00
|
|
|
|
|
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: get_template_vars
|
|
|
|
|
Purpose: Returns an array containing template variables
|
2000-11-21 15:21:16 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function &get_template_vars()
|
|
|
|
|
{
|
|
|
|
|
return $this->_tpl_vars;
|
|
|
|
|
}
|
2000-11-21 15:21:16 +00:00
|
|
|
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: display()
|
|
|
|
|
Purpose: executes & displays the template results
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function display($tpl_file, $cache_id = null)
|
2001-02-01 21:39:29 +00:00
|
|
|
{
|
2001-02-07 20:55:39 +00:00
|
|
|
$this->fetch($tpl_file, $cache_id, true);
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: fetch()
|
|
|
|
|
Purpose: executes & returns or displays the template results
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function fetch($tpl_file, $cache_id = null, $display = false)
|
2001-02-01 21:39:29 +00:00
|
|
|
{
|
2001-02-06 21:17:37 +00:00
|
|
|
global $HTTP_SERVER_VARS;
|
2001-02-01 21:39:29 +00:00
|
|
|
|
2001-02-06 21:17:37 +00:00
|
|
|
if ($this->caching) {
|
2001-02-07 20:55:39 +00:00
|
|
|
// cache name = template path + cache_id
|
2001-02-06 21:17:37 +00:00
|
|
|
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
|
2001-02-07 20:55:39 +00:00
|
|
|
$cache_id_md5 = md5($cache_id);
|
|
|
|
|
$cache_id_dir = substr($cache_id_md5, 0, 2);
|
|
|
|
|
$cache_file = $this->cache_dir."/$cache_tpl_md5/$cache_id_dir/{$cache_tpl_md5}_$cache_id_md5.cache";
|
2001-02-05 21:10:20 +00:00
|
|
|
|
2001-02-06 21:17:37 +00:00
|
|
|
if (file_exists($cache_file) &&
|
|
|
|
|
($this->cache_lifetime == 0 ||
|
|
|
|
|
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
|
|
|
|
$results = $this->_read_file($cache_file);
|
2001-04-24 15:16:14 +00:00
|
|
|
if($this->insert_tag_check) {
|
2001-04-13 20:08:32 +00:00
|
|
|
$results = $this->_process_cached_inserts($results);
|
|
|
|
|
}
|
2001-02-06 21:17:37 +00:00
|
|
|
if ($display) {
|
|
|
|
|
echo $results;
|
|
|
|
|
return;
|
2001-04-19 21:08:17 +00:00
|
|
|
} else {
|
2001-02-06 21:17:37 +00:00
|
|
|
return $results;
|
2001-04-19 21:08:17 +00:00
|
|
|
}
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
2001-01-30 21:54:59 +00:00
|
|
|
|
2001-01-31 22:42:05 +00:00
|
|
|
extract($this->_tpl_vars);
|
|
|
|
|
|
2001-04-19 21:08:17 +00:00
|
|
|
if ($this->show_info_header) {
|
2001-04-11 18:35:17 +00:00
|
|
|
$info_header = '<!-- Smarty '.$this->version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
|
2001-04-19 21:08:17 +00:00
|
|
|
} else {
|
|
|
|
|
$info_header = "";
|
|
|
|
|
}
|
2001-03-23 17:52:50 +00:00
|
|
|
|
2001-01-31 22:42:05 +00:00
|
|
|
// if we just need to display the results, don't perform output
|
2001-02-06 22:17:51 +00:00
|
|
|
// buffering - for speed
|
2001-03-23 17:52:50 +00:00
|
|
|
if ($display && !$this->caching) {
|
|
|
|
|
echo $info_header;
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_process_template($tpl_file, $compile_path);
|
2001-04-11 18:35:17 +00:00
|
|
|
include($compile_path);
|
2001-04-19 21:08:17 +00:00
|
|
|
} else {
|
2001-01-31 22:42:05 +00:00
|
|
|
ob_start();
|
2001-03-23 17:52:50 +00:00
|
|
|
echo $info_header;
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_process_template($tpl_file, $compile_path);
|
2001-04-11 18:35:17 +00:00
|
|
|
include($compile_path);
|
2001-01-31 22:42:05 +00:00
|
|
|
$results = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-12 20:53:21 +00:00
|
|
|
if ($this->caching) {
|
2001-02-05 21:10:20 +00:00
|
|
|
$this->_write_file($cache_file, $results, true);
|
2001-02-01 21:39:29 +00:00
|
|
|
$results = $this->_process_cached_inserts($results);
|
|
|
|
|
}
|
2001-03-23 17:52:50 +00:00
|
|
|
|
2001-01-31 22:42:05 +00:00
|
|
|
if ($display) {
|
2001-04-12 20:53:21 +00:00
|
|
|
if (isset($results)) { echo $results; }
|
2001-01-31 22:42:05 +00:00
|
|
|
return;
|
2001-03-02 18:07:51 +00:00
|
|
|
} else {
|
2001-04-12 20:53:21 +00:00
|
|
|
if (isset($results)) { return $results; }
|
2001-03-02 18:07:51 +00:00
|
|
|
}
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
2001-04-11 18:35:17 +00:00
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _process_template()
|
|
|
|
|
Purpose:
|
|
|
|
|
\*======================================================================*/
|
2001-04-12 20:14:30 +00:00
|
|
|
function _process_template($tpl_file, &$compile_path)
|
2001-04-11 18:35:17 +00:00
|
|
|
{
|
|
|
|
|
// get path to where compiled template is (to be) saved
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_fetch_compile_path($tpl_file, $compile_path);
|
|
|
|
|
|
2001-04-11 18:35:17 +00:00
|
|
|
// test if template needs to be compiled
|
2001-04-12 20:14:30 +00:00
|
|
|
if (!$this->force_compile && $this->_compiled_template_exists($compile_path)) {
|
|
|
|
|
if (!$this->compile_check) {
|
2001-04-11 18:35:17 +00:00
|
|
|
// no need to check if the template needs recompiled
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// get template source and timestamp
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_fetch_template_source($tpl_file, $template_source, $template_timestamp);
|
|
|
|
|
if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) {
|
2001-04-11 18:35:17 +00:00
|
|
|
// template not expired, no recompile
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2001-04-12 20:14:30 +00:00
|
|
|
// compile template
|
|
|
|
|
$this->_compile_template($tpl_file, $template_source, $template_compiled);
|
|
|
|
|
$this->_write_compiled_template($compile_path, $template_compiled);
|
2001-04-11 18:35:17 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// compiled template does not exist, or forced compile
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_fetch_template_source($tpl_file, $template_source, $template_timestamp);
|
|
|
|
|
$this->_compile_template($tpl_file, $template_source, $template_compiled);
|
|
|
|
|
$this->_write_compiled_template($compile_path, $template_compiled);
|
2001-04-11 18:35:17 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-01 21:39:29 +00:00
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-04-11 18:35:17 +00:00
|
|
|
Function: _fetch_compile_path()
|
|
|
|
|
Purpose: fetch the path to save the comiled template
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-04-12 20:14:30 +00:00
|
|
|
function _fetch_compile_path($tpl_file, &$compile_path)
|
2001-02-01 21:39:29 +00:00
|
|
|
{
|
2001-04-24 15:16:14 +00:00
|
|
|
// everything is in $compile_dir
|
|
|
|
|
$compile_path = $this->compile_dir.'/'.urlencode($tpl_file).'.php';
|
2001-04-11 18:35:17 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _compiled_template_exists
|
|
|
|
|
Purpose:
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function _compiled_template_exists($include_path)
|
|
|
|
|
{
|
2001-04-24 15:16:14 +00:00
|
|
|
// everything is in $compile_dir
|
2001-04-11 18:35:17 +00:00
|
|
|
return file_exists($include_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _fetch_compiled_template_timestamp
|
|
|
|
|
Purpose:
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function _fetch_compiled_template_timestamp($include_path)
|
|
|
|
|
{
|
2001-04-24 15:16:14 +00:00
|
|
|
// everything is in $compile_dir
|
2001-04-11 18:35:17 +00:00
|
|
|
return filemtime($include_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _write_compiled_template
|
|
|
|
|
Purpose:
|
|
|
|
|
\*======================================================================*/
|
2001-04-12 20:14:30 +00:00
|
|
|
function _write_compiled_template($compile_path, $template_compiled)
|
2001-04-11 18:35:17 +00:00
|
|
|
{
|
2001-04-24 15:16:14 +00:00
|
|
|
// we save everything into $compile_dir
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_write_file($compile_path, $template_compiled);
|
2001-04-11 18:35:17 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _fetch_template_source()
|
|
|
|
|
Purpose: fetch the template source and timestamp
|
|
|
|
|
\*======================================================================*/
|
2001-04-12 20:14:30 +00:00
|
|
|
function _fetch_template_source($tpl_path, &$template_source, &$template_timestamp)
|
2001-05-02 14:31:35 +00:00
|
|
|
{
|
2001-04-11 18:35:17 +00:00
|
|
|
// split tpl_path by the first colon
|
2001-04-12 20:14:30 +00:00
|
|
|
$tpl_path_parts = explode(':', $tpl_path, 2);
|
2001-04-11 18:35:17 +00:00
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
if (count($tpl_path_parts) == 1) {
|
2001-04-12 19:56:38 +00:00
|
|
|
// no resource type, treat as type "file"
|
2001-04-12 20:14:30 +00:00
|
|
|
$resource_type = 'file';
|
|
|
|
|
$resource_name = $tpl_path_parts[0];
|
2001-04-11 18:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
$resource_type = $tpl_path_parts[0];
|
2001-04-12 20:14:30 +00:00
|
|
|
$resource_name = $tpl_path_parts[1];
|
|
|
|
|
}
|
2001-04-11 18:35:17 +00:00
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
switch ($resource_type) {
|
|
|
|
|
case 'file':
|
2001-04-30 14:08:00 +00:00
|
|
|
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/",$resource_name)) {
|
2001-04-12 19:56:38 +00:00
|
|
|
// relative pathname to $template_dir
|
2001-04-12 20:14:30 +00:00
|
|
|
$resource_name = $this->template_dir.'/'.$resource_name;
|
2001-04-12 19:56:38 +00:00
|
|
|
}
|
2001-04-12 20:14:30 +00:00
|
|
|
if (file_exists($resource_name)) {
|
|
|
|
|
$template_source = $this->_read_file($resource_name);
|
|
|
|
|
$template_timestamp = filemtime($resource_name);
|
2001-04-11 18:35:17 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
2001-05-02 14:31:35 +00:00
|
|
|
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
|
2001-04-11 18:35:17 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2001-04-26 22:07:06 +00:00
|
|
|
if (isset($this->resource_funcs[$resource_type])) {
|
2001-04-24 16:43:05 +00:00
|
|
|
$funcname = $this->resource_funcs[$resource_type];
|
2001-04-26 22:07:06 +00:00
|
|
|
if (function_exists($funcname)) {
|
2001-04-19 16:18:17 +00:00
|
|
|
// call the function to fetch the template
|
2001-04-26 22:07:06 +00:00
|
|
|
$funcname($resource_name, $template_source, $template_timestamp);
|
2001-04-19 16:18:17 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
2001-05-09 14:06:59 +00:00
|
|
|
$this->_trigger_error_msg("resource function: \"$funcname\" does not exist for resource type: \"$resource_type\".");
|
2001-04-26 22:07:06 +00:00
|
|
|
return false;
|
2001-04-19 16:18:17 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->_trigger_error_msg("unknown resource type: \"$resource_type\". Register this resource first.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2001-04-11 18:35:17 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
return true;
|
2001-04-11 18:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _compile_template()
|
|
|
|
|
Purpose: called to compile the templates
|
|
|
|
|
\*======================================================================*/
|
2001-04-12 20:14:30 +00:00
|
|
|
function _compile_template($tpl_file, $template_source, &$template_compiled)
|
2001-04-11 18:35:17 +00:00
|
|
|
{
|
2001-05-18 13:32:13 +00:00
|
|
|
include_once dirname(__FILE__) . '/' . $this->compiler_class . '.class.php';
|
2001-04-11 18:35:17 +00:00
|
|
|
|
2001-04-12 21:00:47 +00:00
|
|
|
$smarty_compiler = new $this->compiler_class;
|
2001-04-11 18:35:17 +00:00
|
|
|
|
2001-04-12 21:00:47 +00:00
|
|
|
$smarty_compiler->template_dir = $this->template_dir;
|
|
|
|
|
$smarty_compiler->compile_dir = $this->compile_dir;
|
|
|
|
|
$smarty_compiler->config_dir = $this->config_dir;
|
|
|
|
|
$smarty_compiler->force_compile = $this->force_compile;
|
|
|
|
|
$smarty_compiler->caching = $this->caching;
|
|
|
|
|
$smarty_compiler->php_handling = $this->php_handling;
|
|
|
|
|
$smarty_compiler->left_delimiter = $this->left_delimiter;
|
|
|
|
|
$smarty_compiler->right_delimiter = $this->right_delimiter;
|
|
|
|
|
$smarty_compiler->custom_funcs = $this->custom_funcs;
|
|
|
|
|
$smarty_compiler->custom_mods = $this->custom_mods;
|
|
|
|
|
$smarty_compiler->version = $this->version;
|
2001-04-26 17:27:40 +00:00
|
|
|
$smarty_compiler->prefilter_funcs = $this->prefilter_funcs;
|
2001-04-24 16:43:05 +00:00
|
|
|
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
2001-04-11 18:35:17 +00:00
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
|
2001-04-11 18:35:17 +00:00
|
|
|
return true;
|
|
|
|
|
else {
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_trigger_error_msg($smarty_compiler->_error_msg);
|
2001-03-02 21:38:42 +00:00
|
|
|
return false;
|
2001-04-11 18:35:17 +00:00
|
|
|
}
|
2001-02-01 21:39:29 +00:00
|
|
|
}
|
2000-11-27 17:39:40 +00:00
|
|
|
|
2001-04-11 18:35:17 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _smarty_include()
|
|
|
|
|
Purpose: called for included templates
|
|
|
|
|
\*======================================================================*/
|
2001-04-28 16:52:27 +00:00
|
|
|
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars,
|
|
|
|
|
&$_smarty_config_parent)
|
2001-04-11 18:35:17 +00:00
|
|
|
{
|
2001-04-30 16:07:55 +00:00
|
|
|
$_smarty_config = $_smarty_config_parent;
|
2001-04-28 16:52:27 +00:00
|
|
|
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
2001-04-30 14:13:47 +00:00
|
|
|
extract($this->_tpl_vars);
|
2001-04-30 16:07:55 +00:00
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_process_template($_smarty_include_tpl_file, $compile_path);
|
2001-04-11 18:35:17 +00:00
|
|
|
include($compile_path);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-02 23:13:01 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _process_cached_inserts
|
|
|
|
|
Purpose: Replace cached inserts with the actual results
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function _process_cached_inserts($results)
|
|
|
|
|
{
|
|
|
|
|
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
|
|
|
|
|
$results, $match);
|
|
|
|
|
list($cached_inserts, $insert_args) = $match;
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($cached_inserts); $i++) {
|
2001-03-03 15:41:52 +00:00
|
|
|
|
2001-03-02 23:13:01 +00:00
|
|
|
$args = unserialize($insert_args[$i]);
|
2001-03-03 15:41:52 +00:00
|
|
|
|
2001-03-02 23:13:01 +00:00
|
|
|
$name = $args['name'];
|
|
|
|
|
unset($args['name']);
|
|
|
|
|
|
|
|
|
|
$function_name = 'insert_' . $name;
|
|
|
|
|
$replace = $function_name($args);
|
|
|
|
|
|
|
|
|
|
$results = str_replace($cached_inserts[$i], $replace, $results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-27 17:39:40 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: _dequote
|
|
|
|
|
Purpose: Remove starting and ending quotes from the string
|
2000-11-27 17:39:40 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function _dequote($string)
|
|
|
|
|
{
|
|
|
|
|
if (($string{0} == "'" || $string{0} == '"') &&
|
|
|
|
|
$string{strlen($string)-1} == $string{0})
|
|
|
|
|
return substr($string, 1, -1);
|
|
|
|
|
else
|
|
|
|
|
return $string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: _read_file()
|
|
|
|
|
Purpose: read in a file
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-01 21:39:29 +00:00
|
|
|
function _read_file($filename)
|
2001-02-07 23:08:00 +00:00
|
|
|
|
2001-02-01 21:39:29 +00:00
|
|
|
{
|
2001-02-06 21:17:37 +00:00
|
|
|
if (!($fd = fopen($filename, 'r'))) {
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_trigger_error_msg("problem reading '$filename.'");
|
2001-02-01 21:39:29 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2001-02-07 23:08:00 +00:00
|
|
|
flock($fd, LOCK_SH);
|
2001-02-01 21:39:29 +00:00
|
|
|
$contents = fread($fd, filesize($filename));
|
|
|
|
|
fclose($fd);
|
|
|
|
|
return $contents;
|
|
|
|
|
}
|
2000-08-08 17:05:38 +00:00
|
|
|
|
|
|
|
|
/*======================================================================*\
|
2001-02-01 21:39:29 +00:00
|
|
|
Function: _write_file()
|
|
|
|
|
Purpose: write out a file
|
2000-08-08 17:05:38 +00:00
|
|
|
\*======================================================================*/
|
2001-02-06 21:17:37 +00:00
|
|
|
function _write_file($filename, $contents, $create_dirs = false)
|
2001-02-01 21:39:29 +00:00
|
|
|
{
|
2001-04-12 20:14:30 +00:00
|
|
|
if ($create_dirs)
|
2001-02-06 21:17:37 +00:00
|
|
|
$this->_create_dir_structure(dirname($filename));
|
2001-02-05 21:10:20 +00:00
|
|
|
|
2001-05-09 13:27:55 +00:00
|
|
|
if (!($fd = fopen($filename, 'w'))) {
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_trigger_error_msg("problem writing '$filename.'");
|
2001-02-01 21:39:29 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2001-05-09 14:06:59 +00:00
|
|
|
|
|
|
|
|
// flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?),
|
|
|
|
|
// so we'll not use it at all in windows.
|
|
|
|
|
|
|
|
|
|
if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) {
|
2001-04-11 18:35:17 +00:00
|
|
|
fwrite( $fd, $contents );
|
|
|
|
|
fclose($fd);
|
2001-04-12 20:14:30 +00:00
|
|
|
chmod($filename,0644);
|
2001-04-11 18:35:17 +00:00
|
|
|
}
|
2001-02-07 23:08:00 +00:00
|
|
|
|
2001-02-01 21:39:29 +00:00
|
|
|
return true;
|
2001-02-05 21:10:20 +00:00
|
|
|
}
|
2001-02-06 21:17:37 +00:00
|
|
|
|
|
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _clear_tpl_cache_dir
|
2001-02-07 20:55:39 +00:00
|
|
|
Purpose: Clear the specified template cache
|
2001-02-06 21:17:37 +00:00
|
|
|
\*======================================================================*/
|
2001-02-07 20:55:39 +00:00
|
|
|
function _clear_tpl_cache_dir($cache_tpl_md5)
|
2001-02-06 21:17:37 +00:00
|
|
|
{
|
2001-02-07 20:55:39 +00:00
|
|
|
$cache_dir = $this->cache_dir.'/'.$cache_tpl_md5;
|
2001-02-06 21:17:37 +00:00
|
|
|
|
|
|
|
|
if (!is_dir($cache_dir))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
$dir_handle = opendir($cache_dir);
|
|
|
|
|
while ($curr_dir = readdir($dir_handle)) {
|
|
|
|
|
$cache_path_dir = $cache_dir.'/'.$curr_dir;
|
|
|
|
|
if ($curr_dir == '.' || $curr_dir == '..' ||
|
|
|
|
|
!is_dir($cache_path_dir))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
$dir_handle2 = opendir($cache_path_dir);
|
|
|
|
|
while ($curr_file = readdir($dir_handle2)) {
|
|
|
|
|
if ($curr_file == '.' || $curr_file == '..')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
$cache_file = $cache_path_dir.'/'.$curr_file;
|
|
|
|
|
if (is_file($cache_file))
|
|
|
|
|
unlink($cache_file);
|
|
|
|
|
}
|
|
|
|
|
closedir($dir_handle2);
|
|
|
|
|
@rmdir($cache_path_dir);
|
|
|
|
|
}
|
|
|
|
|
closedir($dir_handle);
|
|
|
|
|
@rmdir($cache_dir);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-02 23:13:01 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _create_dir_structure
|
|
|
|
|
Purpose: create full directory structure
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function _create_dir_structure($dir)
|
|
|
|
|
{
|
|
|
|
|
if (!file_exists($dir)) {
|
|
|
|
|
$dir_parts = preg_split('!/+!', $dir, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
|
$new_dir = ($dir{0} == '/') ? '/' : '';
|
|
|
|
|
foreach ($dir_parts as $dir_part) {
|
|
|
|
|
$new_dir .= $dir_part;
|
2001-04-11 18:35:17 +00:00
|
|
|
if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) {
|
2001-04-12 20:14:30 +00:00
|
|
|
$this->_trigger_error_msg("problem creating directory \"$dir\"");
|
2001-03-02 23:13:01 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$new_dir .= '/';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-01 15:32:56 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: quote_replace
|
|
|
|
|
Purpose: Quote subpattern references
|
|
|
|
|
\*======================================================================*/
|
|
|
|
|
function quote_replace($string)
|
|
|
|
|
{
|
|
|
|
|
return preg_replace('![\\$]\d!', '\\\\\\0', $string);
|
|
|
|
|
}
|
2001-02-06 21:17:37 +00:00
|
|
|
|
2001-04-12 20:14:30 +00:00
|
|
|
|
2001-04-11 18:35:17 +00:00
|
|
|
/*======================================================================*\
|
|
|
|
|
Function: _trigger_error_msg
|
|
|
|
|
Purpose: trigger Smarty error
|
|
|
|
|
\*======================================================================*/
|
2001-04-12 20:14:30 +00:00
|
|
|
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
|
2001-04-11 18:35:17 +00:00
|
|
|
{
|
2001-04-12 21:00:47 +00:00
|
|
|
trigger_error("Smarty error: $error_msg", $error_type);
|
2001-04-11 18:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
2001-02-01 21:39:29 +00:00
|
|
|
/* vim: set expandtab: */
|
|
|
|
|
|
2000-08-08 17:05:38 +00:00
|
|
|
?>
|