| // +----------------------------------------------------------------------+ // // $Id$ // // Handler code for the * * * * * @version $Id$ */ class HTML_Template_Flexy_Compiler_Standard_Flexy { /** * Parent Compiler for * * @var object HTML_Template_Flexy_Compiler * * @access public */ var $compiler; /** * The current element to parse.. * * @var object * @access public */ var $element; /** * toString - display tag, attributes, postfix and any code in attributes. * Relays into namspace::method to get results.. * * * @see parent::toString() */ function toString($element) { list($namespace,$method) = explode(':',$element->oTag); if (!strlen($method)) { return ''; } // things we dont handle... if (!method_exists($this,$method.'ToString')) { return ''; } return $this->{$method.'ToString'}($element); } /** * toJavascript handler * * * @see parent::toString() */ function toJavascriptToString($element) { $ret = $this->compiler->appendPhp( "require_once 'HTML/Javascript/Convert.php';"); $ret .= $this->compiler->appendHTML("\n"); return $ret; } /** * include handler * * * @see parent::toString() */ function includeToString($element) { // this is disabled by default... // we ignore modifier pre/suffix $arg = $element->getAttribute('SRC'); if (!$arg) { return $this->compiler->appendHTML("Flexy:Include without a src=filename"); } // ideally it would be nice to embed the results of one template into another. // however that would involve some complex test which would have to stat // the child templates anyway.. // compile the child template.... // output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php' return $this->compiler->appendPHP( "\n". "\$x = new HTML_Template_Flexy(\$this->options);\n". "\$x->compile('{$arg}');\n". "\$x->outputObject(\$t);\n" ); } /** * Convert flexy tokens to HTML_Template_Flexy_Elements. * * @param object token to convert into a element. * @return object HTML_Template_Flexy_Element * @access public */ function toElement($element) { return ''; } /** * Handler for User defined functions in templates.. * .... // equivilant to function xxxxx() { * .... // equivilant to function {$xxxxx}() { * .... // equivilant to function {$xxxxx}() { * * This will not handle nested blocks initially!! (and may cause even more problems with * if /foreach stuff..!! * * @param object token to convert into a element. * @access public */ function functionToString($element) { if ($arg = $element->getAttribute('NAME')) { // this is a really kludgy way of doing this!!! // hopefully the new Template Package will have a sweeter method.. $GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'] .= $this->compiler->appendPHP( "\nfunction _html_template_flexy_compiler_standard_flexy_{$arg}(\$t,\$this) {\n"). $element->compileChildren($this->compiler) . $this->compiler->appendPHP( "\n}\n"); return ''; } if (!isset($element->ucAttributes['CALL'])) { return HTML_Template_Flexy::raiseError( ' tag flexy:function needs an argument call or name'. " Error on Line {$element->line} <{$element->tag}>", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } // call is a stirng : nice and simple.. if (is_string($element->ucAttributes['CALL'])) { $arg = $element->getAttribute('CALL'); return $this->compiler->appendPHP( "if (function_exists('_html_template_flexy_compiler_standard_flexy_'.{$arg})) " . " _html_template_flexy_compiler_standard_flexy_{$arg}(\$t,\$this);"); } // we make a big assumption here.. - it should really be error checked.. // that the {xxx} element is item 1 in the list... $e=$element->ucAttributes['CALL'][1]; $add = $e->toVar($e->value); if (is_a($add,'PEAR_Error')) { return $add; } return $this->compiler->appendPHP( "if (function_exists('_html_template_flexy_compiler_standard_flexy_'.{$add})) ". "call_user_func_array('_html_template_flexy_compiler_standard_flexy_'.{$add},array(\$t,\$this));"); } }