*
*/
function compileAll($dir = '',$regex='/.html$/')
{
require_once 'HTML/Template/Flexy/Compiler.php';
$c = new HTML_Template_Flexy_Compiler;
$c->compileAll($this,$dir,$regex);
}
/**
* Outputs an object as $t
*
* for example the using simpletags the object's variable $t->test
* would map to {test}
*
* @version 01/12/14
* @access public
* @author Alan Knowles
* @param object to output
* @param array HTML_Template_Flexy_Elements (or any object that implements toHtml())
* @return none
*/
function outputObject(&$t,$elements=array())
{
if (!is_array($elements)) {
return $this->raiseError(
'second Argument to HTML_Template_Flexy::outputObject() was an '.gettype($elements) . ', not an array',
HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS ,HTML_TEMPLATE_FLEXY_ERROR_DIE);
}
if (@$this->options['debug']) {
echo "output $this->compiledTemplate
";
}
// this may disappear later it's a Backwards Compatibility fudge to try
// and deal with the first stupid design decision to not use a second argument
// to the method.
if (count($this->elements) && !count($elements)) {
$elements = $this->elements;
}
// end depreciated code
$this->elements = $this->getElements();
// Overlay values from $elements to $this->elements (which is created from the template)
// Remove keys with no corresponding value.
foreach($elements as $k=>$v) {
// Remove key-value pair from $this->elements if hasn't a value in $elements.
if (!$v) {
unset($this->elements[$k]);
}
// Add key-value pair to $this->$elements if it's not there already.
if (!isset($this->elements[$k])) {
$this->elements[$k] = $v;
continue;
}
// Call the clever element merger - that understands form values and
// how to display them...
$this->elements[$k] = $this->elements[$k]->merge($v);
}
//echo ''; print_r(array($elements,$this->elements));
// we use PHP's error handler to hide errors in the template.
// use $options['strict'] - if you want to force declaration of
// all variables in the template
$_error_reporting = false;
if (!$this->options['strict']) {
$_error_reporting = error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
}
if (!is_readable($this->compiledTemplate)) {
return $this->raiseError( "Could not open the template: '{$this->compiledTemplate}'
".
"Please check the file permissions on the directory and file ",
HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_DIE);
}
// are we using the assign api!
if (isset($this->assign)) {
if (!$t) {
$t = (object) $this->assign->variables;
}
extract($this->assign->variables);
foreach(array_keys($this->assign->references) as $_k) {
$$_k = &$this->assign->references[$_k];
}
}
// used by Flexy Elements etc..
// note that we are using __ prefix, as this get's exposed to the running template..
$__old_engine = self::$activeEngine;
$this->initializeTranslator();
self::$activeEngine = $this;
//?? not needed?
$GLOBALS['_HTML_TEMPLATE_FLEXY']['options'] = $this->options;
// initialize the translator..
include($this->compiledTemplate);
self::$activeEngine = $__old_engine;
// Return the error handler to its previous state.
if ($_error_reporting !== false) {
error_reporting($_error_reporting);
}
}
/**
* Outputs an object as $t, buffers the result and returns it.
*
* See outputObject($t) for more details.
*
* @version 01/12/14
* @access public
* @author Alan Knowles
* @param object object to output as $t
* @return string - result
*/
function bufferedOutputObject($t,$elements=array())
{
ob_start();
$this->outputObject($t,$elements);
$data = ob_get_contents();
ob_end_clean();
return $data;
}
/**
* Private - file handler for output to file
*/
var $_bufferHandle = false;
/**
* Outputs result to a file
*
* See outputObject($t) for more details.
*
* @version 01/12/14
* @access public
* @author Alan Knowles
* @param object object to output as $t
*/
function outputObjectToFile(&$t,$elements=array(),$filename)
{
$this->_bufferHandle = fopen($filename, 'w');
ob_start(); // outer nesting..
ob_start( array($this, 'addToBuffer') , 4096, PHP_OUTPUT_HANDLER_STDFLAGS);
$this->outputObject($t,$elements);
ob_flush(); // send it???
///fwrite($this->_bufferHandle,@);
@ob_end_clean();
// not sure why, but this emits errors... when it should not!
@ob_end_clean();
fclose($this->_bufferHandle);
$this->_bufferHandle = false;
}
/**
* callback for outputObjectToFile
*
*/
function addToBuffer($buffer)
{
if (!$this->_bufferHandle) {
return false;
}
fwrite($this->_bufferHandle,$buffer);
return true;
}
/**
* static version which does new, compile and output all in one go.
*
* See outputObject($t) for more details.
*
* @version 01/12/14
* @access public
* @author Alan Knowles
* @param object object to output as $t
* @param filename of template
* @return string - result
*/
function &staticQuickTemplate($file,&$t)
{
$template = new HTML_Template_Flexy;
$template->compile($file);
$template->outputObject($t);
}
/**
* if debugging is on, print the debug info to the screen
*
* @access public
* @author Alan Knowles
* @param string $string output to display
* @return none
*/
function debug($string)
{
if (isset($this) && HTML_Template_Flexy_is_a($this,'HTML_Template_Flexy')) {
if (!$this->options['debug']) {
return;
}
} else if (empty($GLOBALS['_HTML_TEMPLATE_FLEXY']['debug'])) {
return;
}
echo "FLEXY DEBUG: $string
";
}
/**
* @depreciated
* See element->merge
*
* @access public
*/
function mergeElement($original,$new)
{
// Clone objects is possible to avoid creating references between elements
// no original - return new
if (!$original) {
return clone($new);
}
return $original->merge($new);
}
/**
* Get an array of elements from the template
*
* All