/** * * Factory method to create Tag Handlers * * $type = namespace eg. <flexy:toJavascript loads Flexy.php * the default is this... (eg. Tag) * * * @param string Namespace handler for element. * @param object HTML_Template_Flexy_Compiler * * * @return object tag compiler * @access public */ function &factory($type, &$compiler) { if (!$type) { $type = 'Tag'; } $class = 'HTML_Template_Flexy_Compiler_Flexy_' . $type; if (class_exists($class)) { $ret = new $class(); $ret->compiler =& $compiler; return $ret; } $filename = 'HTML/Template/Flexy/Compiler/Flexy/' . ucfirst(strtolower($type)) . '.php'; if (!HTML_Template_Flexy_Compiler_Flexy_Tag::fileExistsInPath($filename)) { return HTML_Template_Flexy_Compiler_Flexy_Tag::factory('Tag', $compiler); } // if we dont have a handler - just use the basic handler. if (!file_exists(dirname(__FILE__) . '/' . ucfirst(strtolower($type)) . '.php')) { $type = 'Tag'; } include_once 'HTML/Template/Flexy/Compiler/Flexy/' . ucfirst(strtolower($type)) . '.php'; $class = 'HTML_Template_Flexy_Compiler_Flexy_' . $type; if (!class_exists($class)) { return false; } return HTML_Template_Flexy_Compiler_Flexy_Tag::factory($type, $compiler); }
/** * HTML_Template_Flexy_Token_Tag toString * * @param object HTML_Template_Flexy_Token_Tag * * @return string string to build a template * @access public * @see toString* */ function toStringTag($element) { $original = $element->getAttribute('ALT'); // techncially only input type=(submit|button|input) alt=.. applies, but we may // as well translate any occurance... if (($element->tag == 'IMG' || $element->tag == 'INPUT') && is_string($original) && strlen($original)) { $this->addStringToGettext($original); $quote = $element->ucAttributes['ALT'][0]; $element->ucAttributes['ALT'] = $quote . $this->flexy->translateString($original) . $quote; } $original = $element->getAttribute('TITLE'); if (is_string($original) && strlen($original)) { $this->addStringToGettext($original); $quote = $element->ucAttributes['TITLE'][0]; $element->ucAttributes['TITLE'] = $quote . $this->flexy->translateString($original) . $quote; } if (strpos($element->tag, ':') === false) { $namespace = 'Tag'; } else { $bits = explode(':', $element->tag); $namespace = $bits[0]; } if ($namespace[0] == '/') { $namespace = substr($namespace, 1); } if (empty($this->tagHandlers[$namespace])) { require_once 'HTML/Template/Flexy/Compiler/Flexy/Tag.php'; $this->tagHandlers[$namespace] =& HTML_Template_Flexy_Compiler_Flexy_Tag::factory($namespace, $this); if (!$this->tagHandlers[$namespace]) { return HTML_Template_Flexy::staticRaiseError('HTML_Template_Flexy::failed to create Namespace Handler ' . $namespace . ' in file ' . $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'], HTML_TEMPLATE_FLEXY_ERROR_SYNTAX, HTML_TEMPLATE_FLEXY_ERROR_RETURN); } } return $this->tagHandlers[$namespace]->toString($element); }
/** * HTML_Template_Flexy_Token_Tag toString * * @param object HTML_Template_Flexy_Token_Tag * * @return string string to build a template * @access public * @see toString* */ function toStringTag($element) { $original = $element->getAttribute('ALT'); if ($element->tag == 'IMG' && is_string($original) && strlen($original)) { $this->addStringToGettext($original); $quote = $element->ucAttributes['ALT'][0]; $element->ucAttributes['ALT'] = $quote . $this->translateString($original) . $quote; } $original = $element->getAttribute('TITLE'); if ($element->tag == 'A' && is_string($original) && strlen($original)) { $this->addStringToGettext($original); $quote = $element->ucAttributes['TITLE'][0]; $element->ucAttributes['TITLE'] = $quote . $this->translateString($original) . $quote; } if (strpos($element->tag, ':') === false) { $namespace = 'Tag'; } else { $bits = explode(':', $element->tag); $namespace = $bits[0]; } if ($namespace[0] == '/') { $namespace = substr($namespace, 1); } if (empty($this->tagHandlers[$namespace])) { require_once 'HTML/Template/Flexy/Compiler/Flexy/Tag.php'; $this->tagHandlers[$namespace] =& HTML_Template_Flexy_Compiler_Flexy_Tag::factory($namespace, $this); if (!$this->tagHandlers[$namespace]) { return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::failed to create Namespace Handler ' . $namespace . ' in file ' . $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'], HTML_TEMPLATE_FLEXY_ERROR_SYNTAX, HTML_TEMPLATE_FLEXY_ERROR_RETURN); } } return $this->tagHandlers[$namespace]->toString($element); }