--- /dev/null
+<?php
+// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
+// +--------------------------------------------------------------------+
+// | BIFE - Buil It FastEr |
+// +--------------------------------------------------------------------+
+// | This file is part of BIFE. |
+// | |
+// | BIFE is free software; you can redistribute it and/or modify it |
+// | under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation; either version 2 of the License, or |
+// | (at your option) any later version. |
+// | |
+// | BIFE is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with Hooks; if not, write to the Free Software Foundation, |
+// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
+// +--------------------------------------------------------------------+
+// | Created: Wed Jun 17 19:03:14 2003 |
+// | Authors: Leandro Lucarella <luca@lugmen.org.ar> |
+// +--------------------------------------------------------------------+
+//
+// $Id$
+//
+
+// +X2C Class 130 :HIT
+/**
+ * Hooks vs IT Template Engine.
+Hooks vs IT (HIT) is a simple template implementation, based on hooks and IT template systems.
+ *
+ * @package HTML_Template
+ * @access public
+ */
+class HTML_Template_HIT {
+ /**
+ * 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).
+ *
+ * @var string $group
+ * @access protected
+ */
+ var $group = '';
+
+ /**
+ * Templates cache.
+ *
+ * @var array $cache
+ * @access protected
+ */
+ var $cache = array();
+
+ /**
+ * Parsed templates buffer.
+ *
+ * @var array $buffer
+ * @access protected
+ */
+ var $buffer = array();
+
+ // ~X2C
+
+ // +X2C Operation 136
+ /**
+ * Constructor.
+ *
+ * @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
+ */
+ function HTML_Template_HIT($root = '.', $useIncludePath = false, $group = '') // ~X2C
+ {
+ $this->__construct($root, $useIncludePath, $group);
+ }
+ // -X2C
+
+ // +X2C Operation 137
+ /**
+ * 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).
+ *
+ * @return void
+ * @access public
+ */
+ function __construct($root = '.', $useIncludePath = false, $group = '') // ~X2C
+ {
+ $this->root = $root;
+ $this->useIncludePath = $useIncludePath;
+ $this->pushGroup($group);
+ }
+ // -X2C
+
+ // +X2C Operation 138
+ /**
+ * Parse a template returning the results.
+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
+ */
+ function parse($name, $vars = '', $val = '', $group = null) // ~X2C
+ {
+ $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])) {
+ // FIXME - replace join(file()) with file_get_contents().
+ $this->cache[$file] = join('', file($file, $this->useIncludePath));
+ }
+ if ($vars) {
+ if (is_string($vars)) {
+ $vars = array($vars => $val);
+ }
+ foreach ($vars as $key => $val) {
+ $keys[] = '{' . $key . '}';
+ $vals[] = $val;
+ }
+ return str_replace($keys, $vals, $this->cache[$file]);
+ } else {
+ return $this->cache[$file];
+ }
+ }
+ // -X2C
+
+ // +X2C Operation 144
+ /**
+ * 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 = '') // ~X2C
+ {
+ @$this->buffer["{$this->group}/$name"] .= $this->parse($name, $vars, $val);
+ }
+ // -X2C
+
+ // +X2C Operation 145
+ /**
+ * Gets a parsed buffer.
+ *
+ * @param string $name Name of the parsed template to get.
+ *
+ * @return string
+ * @access public
+ */
+ function getBuffer($name) // ~X2C
+ {
+ return @$this->buffer["{$this->group}/$name"];
+ }
+ // -X2C
+
+ // +X2C Operation 146
+ /**
+ * Gets a parsed buffer and removes it.
+ *
+ * @param string $name Name of the buffer to flush.
+ *
+ * @return void
+ * @access public
+ */
+ function popBuffer($name) // ~X2C
+ {
+ $return = @$this->buffer["{$this->group}/$name"];
+ unset($this->buffer["{$this->group}/$name"]);
+ return $return;
+ }
+ // -X2C
+
+ // +X2C Operation 139
+ /**
+ * Sets the group to use and add it to the groups stack.
+ *
+ * @param string $group Group to use.
+ *
+ * @return void
+ * @access public
+ */
+ function pushGroup($group = '') // ~X2C
+ {
+ $this->group[] = $group;
+ }
+ // -X2C
+
+ // +X2C Operation 140
+ /**
+ * Removes the group from the groups stack and returns to the previous used group.
+ *
+ * @return string
+ * @access public
+ */
+ function popGroup() // ~X2C
+ {
+ return array_pop($this->group);
+ }
+ // -X2C
+
+ // +X2C Operation 159
+ /**
+ * 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
+ */
+ function exists($name, $group = null) // ~X2C
+ {
+ $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 (!$this->useIncludePath) {
+ return is_readable($file);
+ } else {
+ $include_path = array_unique(preg_split('/[:;]/', ini_get('include_path')));
+ foreach ($include_path as $path) {
+ if (is_readable("$path/$file")) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ // -X2C
+
+} // -X2C Class :HIT
+
+?>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<XMI xmlns:UML="org.omg/standards/UML" verified="false" timestamp="" xmi.version="1.2" >
+ <XMI.header>
+ <XMI.documentation>
+ <XMI.exporter>umbrello uml modeller http://uml.sf.net</XMI.exporter>
+ <XMI.exporterVersion>1.1</XMI.exporterVersion>
+ </XMI.documentation>
+ <XMI.model xmi.name="hit" href="/home/luca/website/www/test/bife/hit/hit.xmi" />
+ <XMI.metamodel xmi.name="UML" href="UML.xml" xmi.version="1.3" />
+ </XMI.header>
+ <XMI.content>
+ <docsettings viewid="132" documentation="Parse XML data getting widgets." uniqueid="159" />
+ <umlobjects>
+ <UML:Class stereotype="" package="HTML/Template" xmi.id="130" abstract="0" documentation="Hooks vs IT Template Engine.
+
+Hooks vs IT (HIT) is a simple template implementation, based on hooks and IT template systems." name="HIT" static="0" scope="200" >
+ <UML:Operation stereotype="" package="" xmi.id="136" type="void" abstract="0" documentation="Constructor." name="HTML_Template_HIT" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="'.'" type="string" abstract="0" documentation="Root directory where template files are." name="root" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="3" value="false" type="bool" abstract="0" documentation="If it's true, it looks for template files in PHP's include_path." name="useIncludePath" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="4" value="''" type="string" abstract="0" documentation="Group of templates to use (a subdirectory in root)." name="group" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="137" type="void" abstract="0" documentation="Constructor." name="__construct" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="'.'" type="int" abstract="0" documentation="Root directory where template files are." name="root" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="3" value="false" type="false" abstract="0" documentation="If it's true, it looks for template files in PHP's include_path." name="useIncludePath" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="4" value="''" type="string" abstract="0" documentation="Group of templates to use (a subdirectory in root)." name="group" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="138" type="string" abstract="0" documentation="Parse a template returning the results.
+
+If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). If is a string, {$vars} is replaced with $val." name="parse" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="string" abstract="0" documentation="Name of template to parse." name="name" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="2" value="''" type="mixed" abstract="0" documentation="Variables to replace in the template." name="vars" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="3" value="''" type="string" abstract="0" documentation="If $vars is a string, the value to replace for $vars." name="val" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="4" value="null" type="mixed" abstract="0" documentation="Group to use to parse this template. Null to use the current group." name="group" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="144" type="void" abstract="0" documentation="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." name="parseBuffered" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="string" abstract="0" documentation="Name of template to parse." name="name" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="2" value="''" type="mixed" abstract="0" documentation="Variables to replace in the template." name="vars" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="3" value="''" type="string" abstract="0" documentation="If $vars is a string, the value to replace for $vars." name="val" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="145" type="string" abstract="0" documentation="Gets a parsed buffer." name="getBuffer" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="string" abstract="0" documentation="Name of the parsed template to get." name="name" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="146" type="void" abstract="0" documentation="Gets a parsed buffer and removes it." name="popBuffer" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="string" abstract="0" documentation="Name of the buffer to flush." name="name" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="139" type="void" abstract="0" documentation="Sets the group to use and add it to the groups stack." name="pushGroup" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="''" type="string" abstract="0" documentation="Group to use." name="group" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="140" type="string" abstract="0" documentation="Removes the group from the groups stack and returns to the previous used group." name="popGroup" static="0" scope="200" />
+ <UML:Operation stereotype="" package="" xmi.id="159" type="bool" abstract="0" documentation="Tells if a template exists.
+
+True if the template $name exists in $group (or the current group)." name="exists" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="string" abstract="0" documentation="Name of the template." name="name" static="0" scope="200" />
+ <UML:Parameter stereotype="" package="" xmi.id="2" value="null" type="mixed" abstract="0" documentation="Template's group. If it's null it uses the current group." name="group" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Attribute stereotype="" package="" xmi.id="133" value="'.'" type="string" abstract="0" documentation="Root directory where template files are." name="root" static="0" scope="200" />
+ <UML:Attribute stereotype="" package="" xmi.id="158" value="false" type="bool" abstract="0" documentation="If it's true, it looks for template files in PHP's include_path." name="useIncludePath" static="0" scope="200" />
+ <UML:Attribute stereotype="" package="" xmi.id="134" value="''" type="string" abstract="0" documentation="Group of templates to use (a subdirectory in root)." name="group" static="0" scope="202" />
+ <UML:Attribute stereotype="" package="" xmi.id="135" value="array()" type="array" abstract="0" documentation="Templates cache." name="cache" static="0" scope="202" />
+ <UML:Attribute stereotype="" package="" xmi.id="147" value="array()" type="array" abstract="0" documentation="Parsed templates buffer." name="buffer" static="0" scope="202" />
+ </UML:Class>
+ </umlobjects>
+ <diagrams>
+ <diagram snapgrid="1" showattsig="1" fillcolor="#ffffc0" showgrid="1" showopsig="0" usefillcolor="1" snapx="10" snapy="10" showatts="1" xmi.id="132" documentation="" type="402" showops="1" showpackage="1" name="HIT Classes" localid="30000" showstereotype="0" showscope="1" font="Helvetica,9,-1,5,50,0,0,0,0,0" linecolor="#ff0000" >
+ <widgets>
+ <UML:ConceptWidget usesdiagramfillcolour="0" width="195" showattsigs="601" usesdiagramusefillcolour="0" x="30" linecolour="#ff0000" y="30" showopsigs="600" usesdiagramlinecolour="0" fillcolour="#ffffc0" height="225" usefillcolor="1" showattributes="1" xmi.id="130" showoperations="1" showpackage="1" showscope="1" showstereotype="0" font="Helvetica,9,-1,5,50,0,0,0,0,0" />
+ </widgets>
+ <messages/>
+ <associations/>
+ </diagram>
+ </diagrams>
+ <listview>
+ <listitem open="1" type="800" id="-1" label="Views" >
+ <listitem open="1" type="801" id="-1" label="Logical View" >
+ <listitem open="1" type="803" id="-1" label="HIT" >
+ <listitem open="0" type="813" id="130" label="HIT" >
+ <listitem open="0" type="815" id="136" label="HTML_Template_HIT" />
+ <listitem open="0" type="815" id="137" label="__construct" />
+ <listitem open="0" type="814" id="147" label="buffer" />
+ <listitem open="0" type="814" id="135" label="cache" />
+ <listitem open="0" type="815" id="159" label="exists" />
+ <listitem open="0" type="815" id="145" label="getBuffer" />
+ <listitem open="0" type="814" id="134" label="group" />
+ <listitem open="0" type="815" id="138" label="parse" />
+ <listitem open="0" type="815" id="144" label="parseBuffered" />
+ <listitem open="0" type="815" id="146" label="popBuffer" />
+ <listitem open="0" type="815" id="140" label="popGroup" />
+ <listitem open="0" type="815" id="139" label="pushGroup" />
+ <listitem open="0" type="814" id="133" label="root" />
+ <listitem open="0" type="814" id="158" label="useIncludePath" />
+ </listitem>
+ <listitem open="1" type="807" id="132" label="HIT Classes" />
+ </listitem>
+ </listitem>
+ <listitem open="1" type="802" id="-1" label="Use Case View" />
+ </listitem>
+ </listview>
+ </XMI.content>
+</XMI>