Codice PHP:
    /**
     * return a reference to a registered object
     *
     * @param string $name
     * @return object
     */
    
function &get_registered_object($name) {
        if (!isset(
$this->_reg_objects[$name]))
        
$this->_trigger_fatal_error("'$name' is not a registered object");

        if (!
is_object($this->_reg_objects[$name][0]))
        
$this->_trigger_fatal_error("registered '$name' is not an object");

        return 
$this->_reg_objects[$name][0];
    }

    
/**
     * clear configuration values
     *
     * @param string $var
     */
    
function clear_config($var null)
    {
        if(!isset(
$var)) {
            
// clear all values
            
$this->_config = array(array('vars'  => array(),
                                         
'files' => array()));
        } else {
            unset(
$this->_config[0]['vars'][$var]);
        }
    }

    
/**
     * get filepath of requested plugin
     *
     * @param string $type
     * @param string $name
     * @return string|false
     */
    
function _get_plugin_filepath($type$name)
    {
        
$_params = array('type' => $type'name' => $name);
        require_once(
SMARTY_CORE_DIR 'core.assemble_plugin_filepath.php');
        return 
smarty_core_assemble_plugin_filepath($_params$this);
    }

   
/**
     * test if resource needs compiling
     *
     * @param string $resource_name
     * @param string $compile_path
     * @return boolean
     */
    
function _is_compiled($resource_name$compile_path)
    {
        if (!
$this->force_compile && file_exists($compile_path)) {
            if (!
$this->compile_check) {
                
// no need to check compiled file
                
return true;
            } else {
                
// get file source and timestamp
                
$_params = array('resource_name' => $resource_name'get_source'=>false);
                if (!
$this->_fetch_resource_info($_params)) {
                    return 
false;
                }
                if (
$_params['resource_timestamp'] <= filemtime($compile_path)) {
                    
// template not expired, no recompile
                    
return true;
                } else {
                    
// compile template
                    
return false;
                }
            }
        } else {
            
// compiled template does not exist, or forced compile
            
return false;
        }
    }

   
/**
     * compile the template
     *
     * @param string $resource_name
     * @param string $compile_path
     * @return boolean
     */
    
function _compile_resource($resource_name$compile_path)
    {

        
$_params = array('resource_name' => $resource_name);
        if (!
$this->_fetch_resource_info($_params)) {
            return 
false;
        }

        
$_source_content $_params['source_content'];
        
$_cache_include    substr($compile_path0, -4).'.inc';

        if (
$this->_compile_source($resource_name$_source_content$_compiled_content$_cache_include)) {
            
// if a _cache_serial was set, we also have to write an include-file:
            
if ($this->_cache_include_info) {
                require_once(
SMARTY_CORE_DIR 'core.write_compiled_include.php');
                
smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content'resource_name'=>$resource_name)),  $this);
            }

            
$_params = array('compile_path'=>$compile_path'compiled_content' => $_compiled_content);
            require_once(
SMARTY_CORE_DIR 'core.write_compiled_resource.php');
            
smarty_core_write_compiled_resource($_params$this);

            return 
true;
        } else {
            return 
false;
        }

    }

   
/**
     * compile the given source
     *
     * @param string $resource_name
     * @param string $source_content
     * @param string $compiled_content
     * @return boolean
     */
    
function _compile_source($resource_name, &$source_content, &$compiled_content$cache_include_path=null)
    {
        if (
file_exists(SMARTY_DIR $this->compiler_file)) {
            require_once(
SMARTY_DIR $this->compiler_file);
        } else {
            
// use include_path
            
require_once($this->compiler_file);
        }


        
$smarty_compiler = new $this->compiler_class;

        
$smarty_compiler->template_dir      $this->template_dir;
        
$smarty_compiler->compile_dir       $this->compile_dir;
        
$smarty_compiler->plugins_dir       $this->plugins_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->_version          $this->_version;
        
$smarty_compiler->security          $this->security;
        
$smarty_compiler->secure_dir        $this->secure_dir;
        
$smarty_compiler->security_settings $this->security_settings;
        
$smarty_compiler->trusted_dir       $this->trusted_dir;
        
$smarty_compiler->use_sub_dirs      $this->use_sub_dirs;
        
$smarty_compiler->_reg_objects      = &$this->_reg_objects;
        
$smarty_compiler->_plugins          = &$this->_plugins;
        
$smarty_compiler->_tpl_vars         = &$this->_tpl_vars;
        
$smarty_compiler->default_modifiers $this->default_modifiers;
        
$smarty_compiler->compile_id        $this->_compile_id;
        
$smarty_compiler->_config            $this->_config;
        
$smarty_compiler->request_use_auto_globals  $this->request_use_auto_globals;

        if (isset(
$cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {
            
$smarty_compiler->_cache_serial $this->_cache_serials[$cache_include_path];
        }
        
$smarty_compiler->_cache_include $cache_include_path;


        
$_results $smarty_compiler->_compile_file($resource_name$source_content$compiled_content);

        if (
$smarty_compiler->_cache_serial) {
            
$this->_cache_include_info = array(
                
'cache_serial'=>$smarty_compiler->_cache_serial
                
,'plugins_code'=>$smarty_compiler->_plugins_code
                
,'include_file_path' => $cache_include_path);

        } else {
            
$this->_cache_include_info null;

        }

        return 
$_results;
    }

    
/**
     * Get the compile path for this resource
     *
     * @param string $resource_name
     * @return string results of {@link _get_auto_filename()}
     */
    
function _get_compile_path($resource_name)
    {
        return 
$this->_get_auto_filename($this->compile_dir$resource_name,
                                         
$this->_compile_id) . '.php';
    }

    
/**
     * fetch the template info. Gets timestamp, and source
     * if get_source is true
     *
     * sets $source_content to the source of the template, and
     * $resource_timestamp to its time stamp
     * @param string $resource_name
     * @param string $source_content
     * @param integer $resource_timestamp
     * @param boolean $get_source
     * @param boolean $quiet
     * @return boolean
     */

    
function _fetch_resource_info(&$params)
    {
        if(!isset(
$params['get_source'])) { $params['get_source'] = true; }
        if(!isset(
$params['quiet'])) { $params['quiet'] = false; }

        
$_return false;
        
$_params = array('resource_name' => $params['resource_name']) ;
        if (isset(
$params['resource_base_path']))
            
$_params['resource_base_path'] = $params['resource_base_path'];
        else
            
$_params['resource_base_path'] = $this->template_dir;

        if (
$this->_parse_resource_name($_params)) {
            
$_resource_type $_params['resource_type'];
            
$_resource_name $_params['resource_name'];
            switch (
$_resource_type) {
                case 
'file':
                    if (
$params['get_source']) {
                        
$params['source_content'] = $this->_read_file($_resource_name);
                    }
                    
$params['resource_timestamp'] = filemtime($_resource_name);
                    
$_return is_file($_resource_name);
                    break;

                default:
                    
// call resource functions to fetch the template source and timestamp
                    
if ($params['get_source']) {
                        
$_source_return = isset($this->_plugins['resource'][$_resource_type]) &&
                            
call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],
                                                 array(
$_resource_name, &$params['source_content'], &$this));
                    } else {
                        
$_source_return true;
                    }

                    
$_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&
                        
call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],
                                             array(
$_resource_name, &$params['resource_timestamp'], &$this));

                    
$_return $_source_return && $_timestamp_return;
                    break;
            }
        }

        if (!
$_return) {
            
// see if we can get a template with the default template handler
            
if (!empty($this->default_template_handler_func)) {
                if (!
is_callable($this->default_template_handler_func)) {
                    
$this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
                } else {
                    
$_return call_user_func_array(
                        
$this->default_template_handler_func,
                        array(
$_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));
                }
            }
        }

        if (!
$_return) {
            if (!
$params['quiet']) {
                
$this->trigger_error('unable to read resource: "' $params['resource_name'] . '"');
            }
        } else if (
$_return && $this->security) {
            require_once(
SMARTY_CORE_DIR 'core.is_secure.php');
            if (!
smarty_core_is_secure($_params$this)) {
                if (!
$params['quiet'])
                    
$this->trigger_error('(secure mode) accessing "' $params['resource_name'] . '" is not allowed');
                
$params['source_content'] = null;
                
$params['resource_timestamp'] = null;
                return 
false;
            }
        }
        return 
$_return;
    }


    
/**
     * parse out the type and name from the resource
     *
     * @param string $resource_base_path
     * @param string $resource_name
     * @param string $resource_type
     * @param string $resource_name
     * @return boolean
     */

    
function _parse_resource_name(&$params)
    {

        
// split tpl_path by the first colon
        
$_resource_name_parts explode(':'$params['resource_name'], 2);

        if (
count($_resource_name_parts) == 1) {
            
// no resource type given
            
$params['resource_type'] = $this->default_resource_type;
            
$params['resource_name'] = $_resource_name_parts[0];
        } else {
            if(
strlen($_resource_name_parts[0]) == 1) {
                
// 1 char is not resource type, but part of filepath
                
$params['resource_type'] = $this->default_resource_type;
                
$params['resource_name'] = $params['resource_name'];
            } else {
                
$params['resource_type'] = $_resource_name_parts[0];
                
$params['resource_name'] = $_resource_name_parts[1];
            }
        }