/**
* Compiles a template file. Uses the file scheme to location the source,
* instantiates the code_writer and root_compiler_component (as the root) component then
* instantiates the source_file_parser to parse the template.
* Creates the initialize and render functions in the compiled template.
*
* @see root_compiler_component
* @see code_writer
* @see source_file_parser
* @param string $ name of source template
* @return void
*/
function compile_template_file($filename, $resolve_path = true)
{
    global $tag_dictionary;
    if ($resolve_path) {
        if (!($sourcefile = resolve_template_source_file_name($filename))) {
            error('template file not found', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('file' => $filename));
        }
    } else {
        $sourcefile = $filename;
    }
    $destfile = resolve_template_compiled_file_name($sourcefile, TMPL_INCLUDE);
    if (empty($sourcefile)) {
        error('MISSINGFILE2', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('srcfile' => $filename));
    }
    $code =& new codewriter();
    $code->set_function_prefix(md5($destfile));
    $tree =& new root_compiler_component();
    $tree->source_file = $sourcefile;
    $sfp =& new source_file_parser($sourcefile, $tag_dictionary);
    $sfp->parse($tree);
    $tree->prepare();
    $render_function = $code->begin_function('(&$dataspace)');
    $tree->generate($code);
    $code->end_function();
    $construct_function = $code->begin_function('(&$dataspace)');
    $tree->generate_constructor($code);
    $code->end_function();
    $code->write_php('$GLOBALS[\'template_render\'][$this->codefile] = \'' . $render_function . '\';');
    $code->write_php('$GLOBALS[\'template_construct\'][$this->codefile] = \'' . $construct_function . '\';');
    write_template_file($destfile, $code->get_code());
}
 /**
  * Constructs template
  * 
  * @param string $ name of (source) template file (relative or full path)
  * @access public 
  */
 function template($file, $resolve_path = true)
 {
     $this->file = $file;
     if ($resolve_path) {
         if (!($srcfile = resolve_template_source_file_name($file))) {
             error('template file not found', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('file' => $file));
         }
     } else {
         $srcfile = $file;
     }
     $this->codefile = resolve_template_compiled_file_name($srcfile, TMPL_INCLUDE);
     if (!isset($GLOBALS['template_render'][$this->codefile])) {
         if (get_ini_option('config.ini', 'templates', 'force_compile')) {
             compile_template_file($file, $resolve_path);
         }
         if (!file_exists($this->codefile)) {
             compile_template_file($file, $resolve_path);
         }
         $errorlevel = error_reporting();
         error_reporting($errorlevel & ~E_WARNING);
         $parse_error = (include_once $this->codefile);
         error_reporting($errorlevel);
     }
     $this->render_function = $GLOBALS['template_render'][$this->codefile];
     $func = $GLOBALS['template_construct'][$this->codefile];
     $func($this);
 }
/**
* Compiles a var file and calls write_template_file
*/
function compile_var_file($filename)
{
    $destfile = resolve_template_compiled_file_name($filename, TMPL_IMPORT);
    if (!($sourcefile = resolve_template_source_file_name($filename))) {
        error('MISSINGFILE2', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('srcfile' => $filename));
    }
    $text = serialize(parse_var_file($sourcefile));
    write_template_file($destfile, $text);
}
 /**
  * Constructs template
  * 
  * @param string $ name of (source) template file (relative or full path)
  * @access public 
  */
 function template($file)
 {
     $this->file = $file;
     $srcfile = resolve_template_source_file_name($file, TMPL_INCLUDE);
     $this->codefile = resolve_template_compiled_file_name($srcfile, TMPL_INCLUDE);
     if (!isset($GLOBALS['template_render'][$this->codefile])) {
         if (get_ini_option('config.ini', 'templates', 'force_compile')) {
             compile_template_file($file);
         }
         if (!file_exists($this->codefile)) {
             compile_template_file($file);
         }
         $errorlevel = error_reporting();
         error_reporting($errorlevel & ~E_WARNING);
         $parse_error = (include_once $this->codefile);
         error_reporting($errorlevel);
     }
     $this->render_function = $GLOBALS['template_render'][$this->codefile];
     $func = $GLOBALS['template_construct'][$this->codefile];
     $func($this);
 }