Version 0.9
===========
+ - Finish HTML_Template_HIT.
+ - Separate Album funtionality function from renderer (BIFE_Album).
+ - Use new hooks libs.
+
+Version 0.10
+============
+
Makefile:
- Make a way to put all classes in a package together in a single file to
avoid overhead in require_once calls.
<XMI.exporter>umbrello uml modeller http://uml.sf.net</XMI.exporter>
<XMI.exporterVersion>1.1</XMI.exporterVersion>
</XMI.documentation>
- <XMI.model xmi.name="bife" href="/home/luca/website/www/test/bife_estable/doc/bife.xmi" />
+ <XMI.model xmi.name="bife" href="/home/luca/website/www/test/bife/doc/bife.xmi" />
<XMI.metamodel xmi.name="UML" href="UML.xml" xmi.version="1.3" />
</XMI.header>
<XMI.content>
<UML:Attribute stereotype="" package="" xmi.id="125" value="array()" type="array" abstract="0" documentation="Attribute list." name="attrs" static="0" scope="202" />
</UML:Class>
<UML:Class stereotype="" package="BIFE" xmi.id="5" abstract="1" documentation="Base container widget class." name="Container" static="0" scope="200" >
- <UML:Operation stereotype="" package="" xmi.id="48" type="void" abstract="0" documentation="Constructor." name="BIFE_Container" static="0" scope="200" />
- <UML:Operation stereotype="" package="" xmi.id="50" type="void" abstract="0" documentation="Constructor." name="__construct" static="0" scope="200" />
+ <UML:Operation stereotype="" package="" xmi.id="48" type="void" abstract="0" documentation="Constructor." name="BIFE_Container" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="array" abstract="0" documentation="Attributes." name="attrs" static="0" scope="200" />
+ </UML:Operation>
+ <UML:Operation stereotype="" package="" xmi.id="50" type="void" abstract="0" documentation="Constructor." name="__construct" static="0" scope="200" >
+ <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="array" abstract="0" documentation="Attributes." name="attrs" static="0" scope="200" />
+ </UML:Operation>
<UML:Operation stereotype="" package="" xmi.id="6" type="void" abstract="0" documentation="Adds contents to the container." name="addContents" static="0" scope="200" >
<UML:Parameter stereotype="" package="" xmi.id="1" value="" type="&mixed" abstract="0" documentation="Contents to add to the container." name="contents" static="0" scope="200" />
</UML:Operation>
--- /dev/null
+<?
+// 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: mié jun 18 01:05:57 ART 2003 |
+// | Authors: Leandro Lucarella <luca@lugmen.org.ar> |
+// +--------------------------------------------------------------------+
+//
+// $Id$
+//
+
+// This is a simple test and example of HTML_Template_HIT
+
+$tmp = ini_get('include_path');
+ini_set('include_path', "../src:$tmp");
+unset($tmp);
+umask('002');
+
+require_once 'HTML/Template/HIT.php';
+
+$hit =& new HTML_Template_HIT('hooks');
+
+$rows = '';
+for ($i = 0; $i < 20; $i++) {
+ $cells = '';
+ for ($j = 0; $j < 20; $j++) {
+ $cells .= $hit->parse('cell', array('CELL' => "$i,$j"));
+ }
+ $rows .= $hit->parse('row', array('ROW' => $cells, 'CACA' => 'fea'));
+}
+echo $hit->parse('body', array('ROWS' => $rows, 'TITLE' => 'HOLA MUNDO!!!'));
+
+?>
--- /dev/null
+<HTML>
+ <HEAD>
+ <TITLE>{TITLE}</TITLE>
+ </HEAD>
+ <BODY>
+ <TABLE border="1" cellpadding="5">
+ {ROWS}
+ </TABLE>
+ </BODY>
+</HTML>
--- /dev/null
+<TD>{CELL}</TD>
--- /dev/null
+<TR>{ROW}</TR>
$tmp = ini_get('include_path');
ini_set('include_path', "../src:$tmp");
unset($tmp);
+umask('002');
-require_once 'HTML/Template/Sigma.php';
+require_once 'HTML/Template/HIT.php';
+#require_once 'HTML/Template/Sigma.php';
require_once 'BIFE/Parser.php';
require_once 'BIFE/Copy.php';
require_once 'BIFE/Page.php';
$file = isset($_REQUEST['BIFE']) ? $_REQUEST['BIFE'] : 'index.xbf';
-$template =& new HTML_Template_Sigma('templates', 'compiled_templates');
-$template->setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
+$template =& new HTML_Template_HIT('templates');
+#$template =& new HTML_Template_Sigma('templates', 'compiled_templates');
+#$template->setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
$parser =& new BIFE_Parser('BIFE_Copy');
$page =& $parser->parseFile($file);
--- /dev/null
+<H3 class="album">{DESC}</H3>
+<DIV class="center">
+ <TABLE class="album">
+ <TBODY>
+ {CONTENTS}
+ </TBODY>
+ </TABLE>
+</DIV>
--- /dev/null
+<TD align="center" valign="middle">
+ {CONTENTS}
+</TD>
--- /dev/null
+<A href="{URL}"><IMG alt="{DESC}" src="{THUMB}"></A>
--- /dev/null
+<TR>
+ {CONTENTS}
+</TR>
+++ /dev/null
-<H3 class="album">{DESC}</H3>
-<DIV class="center">
- <TABLE class="album">
- <TBODY>
- <!-- BEGIN ROW -->
- <TR>
- <!-- BEGIN ITEM -->
- <TD align="center" valign="middle">
- <A href="{URL}"><IMG alt="{DESC}" src="{THUMB}"></A>
- </TD>
- <!-- END ITEM -->
- <!-- BEGIN EMPTY -->
- <TD align="center" valign="middle">
- VACÍO
- </TD>
- <!-- END EMPTY -->
- </TR>
- <!-- END ROW -->
- </TBODY>
- </TABLE>
-</DIV>
+++ /dev/null
-<IMG class="albumphoto" alt="{DESC}" src="{PHOTO}"/>
-<DIV class="albumphoto">{DESC}</DIV>
*/
function render(&$template) // ~X2C
{
- $template->loadTemplateFile('bife_album.html');
+ $template->group = 'album';
$root = $this->attrs['DIR'];
$list = $this->getList();
$tot = count($list);
$rows = ceil($tot / $this->attrs['COLUMNS']);
+ $html_rows = '';
for ($row = 0; $row < $rows; $row++) {
+ $html_cells = '';
for ($col = 0; $col < $this->attrs['COLUMNS']; $col++) {
$cur = $row * $this->attrs['COLUMNS'] + $col;
if ($photo = @$list[$cur]) {
// FIXME - Si no se pudo crear el thumb, devuelve null
// (ver si se agrega otro template para indicar error
// o algo asi).
- $photo['URL'] = $this->attrs['LINK-URL'] . '?BIFE_ALBUM_FILE=' .
- urlencode($photo['FILE']);
+ $photo['URL'] = $this->attrs['LINK-URL'] .
+ '?BIFE_ALBUM_FILE=' . urlencode($photo['FILE']);
if ($this->attrs['LINK-BIFE']) {
- $photo['URL'] .= '&BIFE=' . urlencode($this->attrs['LINK-BIFE']);
+ $photo['URL'] .= '&BIFE=' .
+ urlencode($this->attrs['LINK-BIFE']);
}
- $template->setVariable($photo);
- $template->parse('ITEM');
+ $html_cell = $template->parse('item', $photo);
} else {
- $template->touchBlock('EMPTY');
- $template->parse('EMPTY');
+ $html_cell = $template->parse('empty');
}
+ $html_cells .= $template->parse('cell', 'CONTENTS', $html_cell);
}
- $template->parse('ROW');
+ $html_rows .= $template->parse('row', 'CONTENTS', $html_cells);
}
- $template->setVariable('DESC', $this->getDescription());
- return $template->get();
+ return $template->parse(
+ 'body',
+ array('DESC' => $this->getDescription(), 'CONTENTS' => $html_rows));
}
// -X2C
if (is_readable("$root/$file") and in_array($ext, $exts)) {
$thumb = $this->getThumbFilename("$root/$file");
$return[] = array(
- 'FILE' => "$root/$name",
+ 'FILE' => "$root/$file",
'DESC' => $name,
'THUMB' => is_readable($thumb) ? $thumb : null,
);
*/
function render(&$template) // ~X2C
{
- $template->loadTemplateFile('bife_albumphoto.html');
- $template->setVariable($this->attrs);
- return $template->get();
+ $template->group = 'album';
+ return $template->parse('photo', $this->attrs);
}
// -X2C
/**
* Constructor.
*
+ * @param array $attrs Attributes.
+ *
* @return void
* @access public
*/
- function BIFE_Container() // ~X2C
+ function BIFE_Container($attrs) // ~X2C
{
- $this->__construct();
+ $this->__construct($attrs);
}
// -X2C
/**
* Constructor.
*
+ * @param array $attrs Attributes.
+ *
* @return void
* @access public
*/
- function __construct() // ~X2C
+ function __construct($attrs) // ~X2C
{
+ parent::__construct($attrs);
$this->contents = array();
}
// -X2C
*/
function render(&$template) // ~X2C
{
- $contents = parent::render($template);
- $template->loadTemplateFile(get_class($this).'.html');
- $template->setVariable($this->attrs);
- $template->setVariable('CONTENTS', $contents);
- return $template->get();
+ $this->attrs['CONTENTS'] = parent::render($template);
+ $template->group = '';
+ return $template->parse(get_class($this), $this->attrs);
}
// -X2C
*/
function render(&$template) // ~X2C
{
- $contents = parent::render($template);
- $template->loadTemplateFile('bife_page.html');
- $template->setVariable($this->attrs);
- $template->setVariable('CONTENTS', $contents);
- return $template->get();
+ $this->attrs['CONTENTS'] = parent::render($template);
+ $template->group = '';
+ return $template->parse('bife_page', $this->attrs);
}
// -X2C
} // -X2C Class :Parser
-?>
\ No newline at end of file
+?>
} // -X2C Class :Root
-?>
\ No newline at end of file
+?>
--- /dev/null
+<?
+
+// TODO
+// * Add to UML diagram and make xmi2code generate the code.
+// * Add option to use include_path on file search.
+
+class HTML_Template_HIT {
+ var $root;
+ var $group;
+ var $cache;
+ function HTML_Template_HIT($root = '.', $group = '') {
+ $this->root = $root;
+ $this->group = $group;
+ $this->cache = array();
+ }
+ function parse($name, $vars = null, $val = null) {
+ if ($this->group) {
+ $file = "{$this->root}/{$this->group}/$name.tpl.html";
+ } else {
+ $file = "{$this->root}/$name.tpl.html";
+ }
+ if (!isset($this->cache[$file])) {
+ $this->cache[$file] = join('', file($file));
+ }
+ //if (!is_readable($file)) {
+ // trigger_error("Can't read '$file'.");
+ //}
+ 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];
+ }
+ }
+}
+
+?>