Source for file class.Template.inc.php
Documentation is available at class.Template.inc.php
/**************************************************************************\
* eGroupWare API - Template class *
* (C) Copyright 1999-2000 NetUSE GmbH Kristian Koehntopp *
* ------------------------------------------------------------------------ *
* http://www.egroupware.org/ *
* ------------------------------------------------------------------------ *
* This program 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 *
\**************************************************************************/
/* $Id: class.Template.inc.php,v 1.5 2005/11/26 13:01:24 bigmichi1 Exp $ */
/* if set, echo assignments */
/* $file[handle] = 'filename'; */
/* relative filenames are relative to this pathname */
/* $varkeys[key] = 'key'; $varvals[key] = 'value'; */
/* 'remove' => remove undefined variables
* 'comment' => replace undefined variables with comments
* 'keep' => keep undefined variables
/* 'yes' => halt, 'report' => report error, continue, 'no' => ignore error quietly */
/* last error message is retained here */
/***************************************************************************/
* root: template directory.
* unknowns: how to handle unknown variables.
function Template($root =
'.', $unknowns =
'remove')
/* public: setroot(pathname $root)
* root: new template directory.
$this->halt("set_root: $root is not a directory.");
/* public: set_unknowns(enum $unknowns)
* unknowns: 'remove', 'comment', 'keep'
/* public: set_file(array $filelist)
* filelist: array of handle, filename pairs.
* public: set_file(string $handle, string $filename)
* handle: handle for a filename,
* filename: name of template file
function set_file($handle, $filename =
'')
$this->halt("set_file: For handle $handle filename is empty.");
while(list
($h, $f) =
each($handle))
/* public: set_block(string $parent, string $handle, string $name = '')
* extract the template $handle from $parent,
* place variable {$name} instead.
function set_block($parent, $handle, $name =
'')
$this->halt("subst: unable to load $parent.");
$reg =
"/<!--\s+BEGIN $handle\s+-->(.*)\n\s*<!--\s+END $handle\s+-->/sm";
/* public: set_var(array $values)
* values: array of variable name, value pairs.
* public: set_var(string $varname, string $value)
* varname: name of a variable that is to be defined
* value: value of that variable
function set_var($varname, $value =
'')
print
"scalar: set *$varname* to *$value*<br>\n";
while(list
($k, $v) =
each($varname))
print
"array: set *$k* to *$v*<br>\n";
/* public: subst(string $handle)
* handle: handle of template where variables are to be substituted.
$this->halt("subst: unable to load $handle.");
/* public: psubst(string $handle)
* handle: handle of template where variables are to be substituted.
print
$this->subst($handle);
/* public: parse(string $target, string $handle, boolean append)
* public: parse(string $target, array $handle, boolean append)
* target: handle of variable to generate
* handle: handle of template to substitute
* append: append to target handle
function parse($target, $handle, $append =
false)
$str =
$this->subst($handle);
while(list
($i, $h) =
each($handle))
function pparse($target, $handle, $append =
false)
print
$this->parse($target, $handle, $append);
/* This is short for finish parse */
function fp($target, $handle, $append =
False)
return $this->finish($this->parse($target, $handle, $append));
/* This is a short cut for print finish parse */
function pfp($target, $handle, $append =
False)
echo
$this->finish($this->parse($target, $handle, $append));
/* public: get_var(string varname)
* varname: name of variable.
* public: get_var(array varname)
* varname: array of variable names
while(list
($k, $v) =
each($varname))
/* public: get_undefined($handle)
* handle: handle of a template.
$this->halt("get_undefined: unable to load $handle.");
while(list
($k, $v) =
each($m))
/* public: finish(string $str)
$str =
preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template $handle: Variable \\1 undefined -->", $str);
/* public: p(string $varname)
* varname: name of variable to print.
/***************************************************************************/
/* private: filename($filename)
* filename: name to be completed.
function filename($filename,$root=
'',$time=
1)
if (substr($filename, 0, 1) !=
'/')
$new_filename =
$root.
'/'.
$filename;
$new_filename =
$filename;
$this->halt("filename: file $new_filename does not exist.");
$new_root =
str_replace($GLOBALS['egw_info']['server']['template_set'],'default',$root);
/* private: varname($varname)
* varname: name of a replacement variable to be protected.
/* private: loadfile(string $handle)
* handle: load file defined by handle, if it is not loaded yet.
if (isset
($this->varkeys[$handle]) and !empty($this->varvals[$handle]))
if (!isset
($this->file[$handle]))
$this->halt("loadfile: $handle is not a valid handle.");
$filename =
$this->file[$handle];
$this->halt("loadfile: While loading $handle, $filename does not exist or is empty.");
/***************************************************************************/
/* public: halt(string $msg)
* msg: error message to show.
/* public, override: haltmsg($msg)
* msg: error message to show.
printf("<b>Template Error:</b> %s<br>\n", $msg);
Documentation generated on Mon, 17 Nov 2008 01:10:26 +0100 by phpDocumentor 1.4.0