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 <m_marrese@argentina.com>
+ Leandro Lucarella <luca@llucax.hn.org>
-------------------------------------------------------------------------------
$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 <luca@llucax.hn.org>
+ * @author Martín Marrese <m_marrese@argentina.com>
+ * @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
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 <luca@lugmen.org.ar>
+Created: Wed Jun 17 19:03:14 2003
+Authors: Leandro Lucarella <luca@lugmen.org.ar>
-------------------------------------------------------------------------------
$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 <luca@llucax.hn.org>
+ * @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);
}
/**
* 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);
}
* 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);
$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 {
}
}
-
- //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);
}
+
}
+
?>