From a89037ba58dc9a3e4152eb5732949d9187f404c9 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 30 Jul 2004 05:50:10 +0000 Subject: [PATCH] =?utf8?q?Se=20arregla=20la=20'interfaz'=20MLIB=5FTpl:=20?= =?utf8?q?=20=20*=20Se=20pasa=20documentaci=C3=B3n=20a=20ingl=C3=A9s.=20?= =?utf8?q?=20=20*=20Se=20eliminan=20m=C3=A9todos=20getFileName()=20y=20get?= =?utf8?q?FileContents().=20=20=20*=20Se=20agregan=20m=C3=A9todos=20de=20m?= =?utf8?q?anejo=20de=20grupos=20[xxxGroup()]=20y=20exists().=20=20=20*=20S?= =?utf8?q?e=20agrega=20par=C3=A1metro=20de=20grupo=20a=20parse().=20=20=20?= =?utf8?q?*=20Se=20ponen=20comentarios=20compatibles=20con=20doxygen.=20?= =?utf8?q?=20=20*=20Se=20agregan=20TODOs.=20Se=20arregla=20MLIB=5FTpl=5FHI?= =?utf8?q?T:=20=20=20*=20Se=20renombra=20el=20constructor=20para=20que=20c?= =?utf8?q?oincida=20con=20el=20nombre=20de=20la=20clase.=20=20=20*=20Se=20?= =?utf8?q?eliminan=20buffers=20y=20cache.=20=20=20*=20Se=20arregla=20el=20?= =?utf8?q?m=C3=A9todo=20getFilename().=20=20=20*=20Se=20usa=20el=20m=C3=A9?= =?utf8?q?todo=20getFilename()=20donde=20corresponde.=20=20=20*=20Se=20agr?= =?utf8?q?ega=20require=5Fonce.=20=20=20*=20Se=20limpian=20comentarios=20d?= =?utf8?q?e=20doxygen.=20=20=20*=20Se=20agrega=20m=C3=A9todo=20getGroup().?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/MLIB/Tpl.php | 80 ++++++++++++----- lib/MLIB/Tpl/HIT.php | 209 +++++++++++++------------------------------ 2 files changed, 121 insertions(+), 168 deletions(-) diff --git a/lib/MLIB/Tpl.php b/lib/MLIB/Tpl.php index e1f82c6..e0c3c39 100644 --- a/lib/MLIB/Tpl.php +++ b/lib/MLIB/Tpl.php @@ -18,59 +18,95 @@ You should have received a copy of the GNU Lesser General Public License; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -Creado: jue jul 29 09:42:56 ART 2004 -Autor: Martín Marrese - m_marrese@argentina.com +Created: jue jul 29 09:42:56 ART 2004 +Authors: Martín Marrese + Leandro Lucarella ------------------------------------------------------------------------------- $Id$ -----------------------------------------------------------------------------*/ /** - * Clase dummy / interfaz para los templates de mlib. - * Establece los parametros para el contructor y los parametros del metodo - * parse. + * Templates interface for mlib. + * This interface define the basic behavoir of all the template implementations + * in mlib. It has 4 method which are the only ones you should use when drawing + * your components. + * + * @todo Add a global example using all the methods. + * @author Leandro Lucarella + * @author Martín Marrese + * @since 1.0 */ -class MLIB_Tpl { +class /* interface */ MLIB_Tpl { /** * Returns a parsed template. + * This function parses a template $name in the $group (or the current group + * if it's null), replacing the variables specified by $vars. $vars can be a + * string (in which case it's replaced by the value $val) or an asociative + * array, where the keys are the variables to replace and the values are the + * text to put in the place of the variable. * * @param string $name Name of template to parse. * @param mixed $vars Variables to replace in the template. * @param string $val If $vars is a string, the value to replace * for $vars. * - * @access public - * @return mixed + * @return The parsed template $name (in $group) with its $vars replaced. + * @todo Add an example. */ - function parse($name, $vars = '', $val = '') + function parse($name, $vars = '', $val = '', $group = null) { - trigger_error('Not implemented!', E_USER_WARNING); + trigger_error('Not implemented!', E_USER_ERROR); } /** - * Returns the template file name based on the blockname + * Sets the group to use and add it to the groups stack. * - * @param string $block BlockName. + * @param group Group to use (and add to the groups stack). + * @todo Add an example. + */ + function pushGroup($group = '') + { + trigger_error('Not implemented!', E_USER_ERROR); + } + + /** + * Removes the current group from the groups stack and returns it. + * + * @return Last used group. + * @todo Add an example. + */ + function popGroup() { + trigger_error('Not implemented!', E_USER_ERROR); + } + + /** + * Returns the current group from the groups stack. * - * @access public - * @return mixed + * @return Current group. + * @todo Add an example. */ - function getFileName($block) + function getGroup() { - trigger_error('Not implemented!', E_USER_WARNING); + return end($this->group); } /** - * Returns the template file content. + * Tells if a template exists. + * True if the template $name exists in $group (or the current group if + * $group is null) * - * @param string $file Filename. + * @param name Name of the template. + * @param group Template's group. If it's null it uses the current group. * - * @access public - * @return mixed + * @return true if template $name exists in $group, false if not. + * @todo Add an example. */ - function getFileContent($filename) + function exists($name, $group = null) { - trigger_error('Not implemented!', E_USER_WARNING); + trigger_error('Not implemented!', E_USER_ERROR); } + } + ?> \ No newline at end of file diff --git a/lib/MLIB/Tpl/HIT.php b/lib/MLIB/Tpl/HIT.php index 02e63e4..cabb319 100644 --- a/lib/MLIB/Tpl/HIT.php +++ b/lib/MLIB/Tpl/HIT.php @@ -18,74 +18,52 @@ You should have received a copy of the GNU Lesser General Public License; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -Creado: Wed Jun 17 19:03:14 2003 -Autor: Leandro Lucarella +Created: Wed Jun 17 19:03:14 2003 +Authors: Leandro Lucarella ------------------------------------------------------------------------------- $Id$ -----------------------------------------------------------------------------*/ +require_once 'MLIB/Tpl.php'; + /** * Hooks vs IT Template Engine. * Hooks vs IT (HIT) is a simple template implementation, based on hooks and IT * template systems. - * This class was originally created as a part of BIFE. - * Implements HIT + GHIT + BHIT, which includes groups of templates and buffers. * - * @access public + * @note This class was originally created as a part of BIFE. + * @author Leandro Lucarella + * @todo Add a global example and an explanation of the directory structure to + * use, etc. */ -class MLIB_Tpl_HIT extends MLIB_Tpl +class MLIB_Tpl_HIT extends /* implements */ MLIB_Tpl { /** * Root directory where template files are. - * - * @var string $root - * @access public */ var $root = '.'; /** * If it's true, it looks for template files in PHP's include_path. - * - * @var bool $useIncludePath - * @access public */ var $useIncludePath = false; /** - * Group of templates to use (a subdirectory in root). + * Group of templates to use. + * In this implementation is a subdirectory in $root. * - * @var string $group - * @access protected + * @protected */ var $group = ''; - /** - * Templates cache. - * - * @var array $cache - * @access protected - */ - var $cache = array(); - - /** - * Parsed templates buffer. - * - * @var array $buffer - * @access protected - */ - var $buffer = array(); - /** * Constructor. + * For PHP4 backward compatibility. * - * @param string $root Root directory where template files are. - * @param bool $useIncludePath If it's true, it looks for template files in PHP's include_path. - * @param string $group Group of templates to use (a subdirectory in root). - * - * @return void - * @access public + * @copydoc __construct() + * @see __construct() */ - function HTML_Template_HIT($root = '.', $useIncludePath = false, $group = '') + function MLIB_Tpl_HIT($root = '.', $useIncludePath = false, $group = '') { $this->__construct($root, $useIncludePath, $group); } @@ -93,16 +71,17 @@ class MLIB_Tpl_HIT extends MLIB_Tpl /** * Constructor. * - * @param int $root Root directory where template files are. - * @param false $useIncludePath If it's true, it looks for template files in PHP's include_path. - * @param string $group Group of templates to use (a subdirectory in root). + * @param root Root directory where template files are. + * @param useIncludePath If it's true, it looks for template files in + * PHP's include_path. + * @param group Group of templates to use (a subdirectory in + * root in this implementation). * - * @return void - * @access public + * @todo Add an example. */ function __construct($root = '.', $useIncludePath = false, $group = '') { - $this->root = $root; + $this->root = $root; $this->useIncludePath = $useIncludePath; $this->pushGroup($group); } @@ -112,25 +91,12 @@ class MLIB_Tpl_HIT extends MLIB_Tpl * If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). * If is a string, {$vars} is replaced with $val. * - * @param string $name Name of template to parse. - * @param mixed $vars Variables to replace in the template. - * @param string $val If $vars is a string, the value to replace for $vars. - * @param mixed $group Group to use to parse this template. Null to use the current group. - * - * @return string - * @access public + * @copydoc MLIB_Tpl::parse() + * @todo Add an example. */ function parse($name, $vars = '', $val = '', $group = null) { - $group = is_null($group) ? end($this->group) : $group; - if ($group) { - $file = "{$this->root}/$group/$name.tpl.html"; - } else { - $file = "{$this->root}/$name.tpl.html"; - } - if (!isset($this->cache[$file])) { - $this->cache[$file] = $this->getFileContent($file); - } + $tpl = $this->getFileContent($this->getFilename($name, $group)); if ($vars) { if (is_string($vars)) { $vars = array($vars => $val); @@ -139,100 +105,42 @@ class MLIB_Tpl_HIT extends MLIB_Tpl $keys[] = '{' . $key . '}'; $vals[] = $val; } - return str_replace($keys, $vals, $this->cache[$file]); + return str_replace($keys, $vals, $tpl); } else { - return $this->cache[$file]; + return $tpl; } } /** - * Parse a template adding the results to the buffer. - * Parse a template appending the results to an internal buffer. - * If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). - * If is a string, {$vars} is replaced with $val. - * - * @param string $name Name of template to parse. - * @param mixed $vars Variables to replace in the template. - * @param string $val If $vars is a string, the value to replace for $vars. - * - * @return void - * @access public - */ - function parseBuffered($name, $vars = '', $val = '') - { - @$this->buffer["{$this->group}/$name"] .= $this->parse($name, $vars, $val); - } - - /** - * Gets a parsed buffer. - * - * @param string $name Name of the parsed template to get. - * - * @return string - * @access public - */ - function getBuffer($name) - { - return @$this->buffer["{$this->group}/$name"]; - } - - /** - * Gets a parsed buffer and removes it. - * - * @param string $name Name of the buffer to flush. - * - * @return void - * @access public + * @copydoc MLIB_Tpl::pushGroup() */ - function popBuffer($name) + function pushGroup($group = '') { - $return = @$this->buffer["{$this->group}/$name"]; - unset($this->buffer["{$this->group}/$name"]); - return $return; + $this->group[] = $group; } /** - * Sets the group to use and add it to the groups stack. - * - * @param string $group Group to use. - * - * @return void - * @access public + * @copydoc MLIB_Tpl::popGroup() */ - function pushGroup($group = '') + function popGroup() { - $this->group[] = $group; + return array_pop($this->group); } /** - * Removes the group from the groups stack and returns to the previous used group. - * - * @return string - * @access public + * @copydoc MLIB_Tpl::getGroup() */ - function popGroup() + function getGroup() { - return array_pop($this->group); + return end($this->group); } /** - * Tells if a template exists. - * True if the template $name exists in $group (or the current group). - * - * @param string $name Name of the template. - * @param mixed $group Template's group. If it's null it uses the current group. - * - * @return bool - * @access public + * @copydoc MLIB_Tpl::exists() */ function exists($name, $group = null) { - $group = is_null($group) ? end($this->group) : $group; - if ($group) { - $file = "{$this->root}/$group/$name.tpl.html"; - } else { - $file = "{$this->root}/$name.tpl.html"; - } + $tpl = $this->getFileContent($this->getFilename($name, $group)); if (!$this->useIncludePath) { return is_readable($file); } else { @@ -246,35 +154,44 @@ class MLIB_Tpl_HIT extends MLIB_Tpl } } - - //Agregados debido a la nueva dependencia con MLIB_Tpl' - /** - * Returns the template file name based on the blockname + * Returns the template filename. + * Returns the template filename based on the $name and the $group of the + * template. If $group is null it uses the current group in the groups + * stack. * - * @param string $group BlockName. + * @param name Tempate's name. + * @param group Group where to look for the template. * - * @access public - * @return mixed + * @protected + * @return Filename. */ - function getFileName($group) + function getFilename($name, $group = null) { - //TODO Revisar esto porque asi solo me devuelve el nombre de los - //templates que esten en la barra. - return "{$this->root}/$group.tpl.html"; + $group = is_null($group) ? end($this->group) : $group; + if ($group) { + $file = "{$this->root}/$group/$name.tpl.html"; + } else { + $file = "{$this->root}/$name.tpl.html"; + } + return $file; } /** - * Returns the template file content. + * Returns the contents of a file as a string. + * It uses useIncludePath to search (or not) for the file in the PHP's + * include_path. * - * @param string $file Filename. + * @param filename Filename. * - * @access public - * @return mixed + * @protected + * @return File contents as a string. */ function getFileContent($filename) { return file_get_contents($filename, $this->useIncludePath); } + } + ?> -- 2.43.0