*/
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).
*
* 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 = '.', $group = '') // ~X2C
+ function HTML_Template_HIT($root = '.', $useIncludePath = false, $group = '') // ~X2C
{
- $this->__construct($root, $group);
+ $this->__construct($root, $useIncludePath, $group);
}
// -X2C
* Constructor.
*
* @param int $root Root directory where template files are.
- * @param int $group Group of templates to use (a subdirectory in root).
+ * @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 = '.', $group = '') // ~X2C
+ function __construct($root = '.', $useIncludePath = false, $group = '') // ~X2C
{
$this->root = $root;
- $this->setGroup($group);
+ $this->useIncludePath = $useIncludePath;
+ $this->pushGroup($group);
}
// -X2C
* @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 = '') // ~X2C
+ function parse($name, $vars = '', $val = '', $group = null) // ~X2C
{
- $group = end($this->group);
+ $group = is_null($group) ? end($this->group) : $group;
if ($group) {
$file = "{$this->root}/$group/$name.tpl.html";
} else {
}
if (!isset($this->cache[$file])) {
// FIXME - replace join(file()) with file_get_contents().
- $this->cache[$file] = join('', file($file));
+ $this->cache[$file] = join('', file($file, $this->useIncludePath));
}
- //if (!is_readable($file)) {
- // trigger_error("Can't read '$file'.");
- //}
if ($vars) {
if (is_string($vars)) {
$vars = array($vars => $val);
* Gets a parsed buffer.
*
* @param string $name Name of the parsed template to get.
- * @param bool $flush Flush buffer.
*
* @return string
* @access public
+ * @static
*/
- function getBuffer($name, $flush = true) // ~X2C
+ function getBuffer($name) // ~X2C
{
return @$this->buffer["{$this->group}/$name"];
}
/**
* Gets a parsed buffer and removes it.
*
- * @param int $name Name of the buffer to flush.
+ * @param string $name Name of the buffer to flush.
*
* @return void
* @access public
*/
- function popBuffer($name = '') // ~X2C
+ function popBuffer($name) // ~X2C
{
$return = @$this->buffer["{$this->group}/$name"];
unset($this->buffer["{$this->group}/$name"]);
* @return void
* @access public
*/
- function setGroup($group = '') // ~X2C
+ function pushGroup($group = '') // ~X2C
{
- if ($group) {
- $this->group[] = $group;
- } else {
- $this->group[] = '';
- }
+ $this->group[] = $group;
}
// -X2C
/**
* Removes the group from the groups stack and returns to the previous used group.
*
- * @return void
+ * @return string
+ * @access public
+ */
+ function popGroup() // ~X2C
+ {
+ return array_pop($this->group);
+ }
+ // -X2C
+
+ // +X2C Operation 159
+ /**
+ * 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 unsetGroup() // ~X2C
+ function exists($name, $group = null) // ~X2C
{
- array_pop($this->group);
+ $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