示例#1
0
 /**
  *   actually it will only be used to apply the pre and post filters
  *
  *   @access     public
  *   @version    01/12/10
  *   @author     Alan Knowles <*****@*****.**>
  *   @param      string  $input      the string to filter
  *   @param      array   $prefix     the subset of methods to use.
  *   @return     string  the filtered string
  */
 function applyFilters($input, $prefix = "", $negate = FALSE)
 {
     $this->flexy->debug("APPLY FILTER {$prefix}<BR>");
     $filters = $this->options['filters'];
     $this->flexy->debug(serialize($filters) . "<BR>");
     foreach ($filters as $filtername) {
         $class = "HTML_Template_Flexy_Compiler_Regex_{$filtername}";
         require_once "HTML/Template/Flexy/Compiler/Regex/{$filtername}.php";
         if (!class_exists($class)) {
             return HTML_Template_Flexy::raiseError("Failed to load filter {$filter}", null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
         }
         if (!@$this->filter_objects[$class]) {
             $this->filter_objects[$class] = new $class();
             $this->filter_objects[$class]->_set_engine($this);
         }
         $filter =& $this->filter_objects[$class];
         $methods = get_class_methods($class);
         $this->flexy->debug("METHODS:");
         $this->flexy->debug(serialize($methods) . "<BR>");
         foreach ($methods as $method) {
             if ($method[0] == "_") {
                 continue;
                 // private
             }
             if ($method == $class) {
                 continue;
                 // constructor
             }
             $this->flexy->debug("TEST: {$negate} {$prefix} : {$method}");
             if ($negate && preg_match($prefix, $method)) {
                 continue;
             }
             if (!$negate && !preg_match($prefix, $method)) {
                 continue;
             }
             $this->flexy->debug("APPLYING {$filtername} {$method}<BR>");
             $input = $filter->{$method}($input);
         }
     }
     return $input;
 }
示例#2
0
 /**
  * reWriteURL - can using the config option 'url_rewrite'
  *  format "from:to,from:to"
  * only handle left rewrite. 
  * so 
  *  "/images:/myroot/images"
  * would change
  *   /images/xyz.gif to /myroot/images/xyz.gif
  *   /images/stylesheet/imagestyles.css to  /myroot/images/stylesheet/imagestyles.css
  *   note /imagestyles did not get altered.
  * will only work on strings (forget about doing /images/{someimage}
  *
  *
  * @param    string attribute to rewrite
  * @return   none
  * @access   public
  */
 function reWriteURL($which)
 {
     global $_HTML_TEMPLATE_FLEXY;
     if (!is_string($original = $this->element->getAttribute($which))) {
         return;
     }
     if ($original == '') {
         return;
     }
     if (empty($_HTML_TEMPLATE_FLEXY['currentOptions']['url_rewrite'])) {
         return;
     }
     $bits = explode(",", $_HTML_TEMPLATE_FLEXY['currentOptions']['url_rewrite']);
     $new = $original;
     foreach ($bits as $bit) {
         if (!strlen(trim($bit))) {
             continue;
         }
         $parts = explode(':', $bit);
         if (!isset($parts[1])) {
             return HTML_Template_Flexy::raiseError('HTML_Template_Flexy: url_rewrite syntax incorrect' . print_r(array($bits, $bits), true), null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
         }
         $new = preg_replace('#^' . $parts[0] . '#', $parts[1], $new);
     }
     if ($original == $new) {
         return;
     }
     $this->element->ucAttributes[$which] = '"' . $new . '"';
 }
示例#3
0
 /**
  * setErrors - sets the suffix of an element to a value..
  *  
  * HTML_Element_Factory::setErrors($elements,array('name','not long enough'));
  *
  * @depreciated  - this is really outside the scope of Factory - it should be 
  *                   seperated into a rendering toolkit of some kind.
  * @param   array    of HTML_Element's
  * @param    array   key(tag name) => error
  * @param    string sprintf error format..
  *
  * @return   array    Array of HTML_Elements 
  * @access   public
  */
 function &setErrors(&$ret, $set, $format = '<span class="error">%s</span>')
 {
     if (empty($ret) || !is_array($ret)) {
         $ret = array();
     }
     // check what you send this.. !!!
     if (!is_array($set)) {
         return HTML_Template_Flexy::raiseError('invalid arguments "$set" (should be an array) sent to HTML_Template_Flexy_Factory::setErrors', 0, HTML_TEMPLATE_FLEXY_ERROR_DIE);
     }
     foreach ($set as $k => $v) {
         if (!$v) {
             continue;
         }
         if (!isset($ret[$k])) {
             $ret[$k] = new HTML_Template_Flexy_Element();
         }
         $ret[$k]->suffix .= sprintf($format, $v);
     }
     return $ret;
 }
示例#4
0
 /**
  * Load the plugins, and lookup which one provides the required method 
  *
  * 
  * @param   string           Name
  *
  * @return   string|PEAR_Error   the class that provides it.
  * @access   private
  */
 function _loadPlugins($name)
 {
     // name can be:
     // ahref = maps to {class_prefix}_ahref::ahref
     $this->plugins = array();
     if (empty($this->plugins)) {
         foreach ($this->flexy->options['plugins'] as $cname => $file) {
             if (!is_int($cname)) {
                 include_once $file;
                 $this->plugins[$cname] = new $cname();
                 $this->plugins[$cname]->flexy =& $this->flexy;
                 continue;
             }
             $cname = $file;
             require_once 'HTML/Template/Flexy/Plugin/' . $cname . '.php';
             $class = "HTML_Template_Flexy_Plugin_{$cname}";
             $this->plugins[$class] = new $class();
             $this->plugins[$class]->flexy =& $this->flexy;
         }
     }
     foreach ($this->plugins as $class => $o) {
         //echo "checking :". get_class($o). ":: $name\n";
         if (is_callable(array($o, $name), true)) {
             return $class;
         }
     }
     return HTML_Template_Flexy::raiseError("could not find plugin with method: '{$name}'");
 }
示例#5
0
 /**
  * Handler for User defined functions in templates..
  * <flexy:function name="xxxxx">.... </flexy:block>  // equivilant to function xxxxx() { 
  * <flexy:function call="{xxxxx}">.... </flexy:block>  // equivilant to function {$xxxxx}() { 
  * <flexy:function call="xxxxx">.... </flexy:block>  // 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} &lt;{$element->tag}&gt;", 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));");
 }
示例#6
0
 /**
  *   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)
 {
     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/Standard/Tag.php';
         $this->tagHandlers[$namespace] =& HTML_Template_Flexy_Compiler_Standard_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);
 }
示例#7
0
 /**
  * The core tokenizing part - runs the tokenizer on the data,
  * and stores the results in $this->tokens[]
  *
  * @param   string               Data to tokenize
  * 
  * @return   none | PEAR::Error
  * @access   public|private
  * @see      see also methods.....
  */
 function tokenize($data)
 {
     require_once 'HTML/Template/Flexy/Tokenizer.php';
     $tokenizer =& HTML_Template_Flexy_Tokenizer::construct($data, $this->options);
     // initialize state - this trys to make sure that
     // you dont do to many elses etc.
     //echo "RUNNING TOKENIZER";
     // step one just tokenize it.
     $i = 1;
     while ($t = $tokenizer->yylex()) {
         if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) {
             return HTML_Template_Flexy::raiseError(array("HTML_Template_Flexy_Tree::Syntax error in File: %s (Line %s)\n" . "Tokenizer Error: %s\n" . "Context:\n\n%s\n\n >>>>>> %s\n", $this->options['filename'], $tokenizer->yyline, $tokenizer->error, htmlspecialchars(substr($tokenizer->yy_buffer, 0, $tokenizer->yy_buffer_end)), htmlspecialchars(substr($tokenizer->yy_buffer, $tokenizer->yy_buffer_end, 100))), HTML_TEMPLATE_FLEXY_ERROR_SYNTAX, HTML_TEMPLATE_FLEXY_ERROR_DIE);
         }
         if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) {
             continue;
         }
         if ($t->token == 'Php') {
             continue;
         }
         $i++;
         $this->tokens[$i] = $tokenizer->value;
         $this->tokens[$i]->id = $i;
         //print_r($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]);
     }
     //echo "BUILT TOKENS";
 }
示例#8
0
 /**
  *
  * Assign a token by reference.  This allows you change variable
  * values within the template and have those changes reflected back
  * at the calling logic script.  Works as with form 2 of assign().
  *
  * @access public
  *
  * @param string $name The template token-name for the reference.
  *
  * @param mixed &$ref The variable passed by-reference.
  *
  * @return bool|PEAR_Error Boolean true on success, or a PEAR_Error
  * on failure.
  *
  * @throws SAVANT_ERROR_ASSIGN_REF Unknown reason for error.
  *
  * @see assign()
  * @author Paul M. Jones <*****@*****.**>
  * @see assignObject()
  *
  */
 function assignRef($name, &$ref)
 {
     // look for the proper case: name and variable
     if (is_string($name) && isset($ref)) {
         if (isset($this->variables[$name])) {
             unset($this->variables[$name]);
         }
         //
         // assign the token as a reference
         $this->references[$name] =& $ref;
         // done!
         return true;
     }
     // final error catch
     return HTML_Template_Flexy::raiseError("invalid type sent to assignRef, " . print_r($name, true), HTML_TEMPLATE_FLEXY_ASSIGN_ERROR_INVALIDARGS);
 }
示例#9
0
 /**
  * do the stack lookup on the variable
  * this relates to flexy
  * t relates to the object being parsed.
  *
  * @return  string PHP variable 
  * @access   public
  */
 function findVar($string)
 {
     global $_HTML_TEMPLATE_FLEXY_TOKEN;
     if (!$string || $string == 't') {
         return '$t';
     }
     if ($string == 'this') {
         return '$this';
     }
     // accept global access on some string
     if (@$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globals'] && preg_match('/^(_POST|_GET|_REQUEST|_SESSION|_COOKIE|GLOBALS)\\[/', $string)) {
         return '$' . $string;
     }
     if (!@$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['privates'] && $string[0] == '_') {
         return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::Attempt to access private variable:' . " on line {$this->line} of {$GLOBALS['_HTML_TEMPLATE_FLEXY']['filename']}" . ", Use options[privates] to allow this.", HTML_TEMPLATE_FLEXY_ERROR_SYNTAX, HTML_TEMPLATE_FLEXY_ERROR_RETURN);
     }
     $lookup = $string;
     if ($p = strpos($string, '[')) {
         $lookup = substr($string, 0, $p);
     }
     for ($s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; $s > 0; $s--) {
         if (in_array($lookup, $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s])) {
             return '$' . $string;
         }
     }
     return '$t->' . $string;
 }
示例#10
0
 /**
  *   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);
 }
示例#11
0
 /**
  * calls HTML_Template_Flexy::raiseError() with the current file, line and tag
  * @param    string  Message to display
  * @param    type   (see HTML_Template_Flexy::raiseError())
  * @param    boolean  isFatal.
  * 
  * @access   private
  */
 function _raiseErrorWithPositionAndTag($message, $type = null, $fatal = HTML_TEMPLATE_FLEXY_ERROR_RETURN)
 {
     global $_HTML_TEMPLATE_FLEXY;
     $message = "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line}" . " in Tag &lt;{$this->element->tag}&gt;:<BR>\n" . $message;
     return HTML_Template_Flexy::raiseError($message, $type, $fatal);
 }
示例#12
0
 /**
  * Utility function equivilant to HTML_Select - loadArray ** For xul:menulist.
  * but using
  * key=>value maps
  * <option value="key">Value</option>
  * Key=key (eg. both the same) maps to
  *
  *
  *
  * @param    HTML_Element   $from  override settings from another element.
  * @param    HTML_Element   $noValue  ignore the key part of the array
  * @access   public
  */
 function setOptions(&$element, $array, $noValue = false)
 {
     if (!is_array($array)) {
         $element->children = array();
         return;
     }
     $tag = '';
     $namespace = '';
     if (false !== strpos($element->tag, ':')) {
         $bits = explode(':', $element->tag);
         $namespace = $bits[0] . ':';
         $tag = strtolower($bits[1]);
     }
     if (!isset($element->children[0])) {
         $element->children[0] = new HTML_Template_Flexy_Element('menupopup');
     }
     if (!is_a($element->children[0], 'HTML_Template_Flexy_Element')) {
         // oh sh*t big problem!
         return HTML_Template_Flexy::raiseError(__CLASS__ . '::setValue expected a menupopup as the child of a menuitem?', HTML_TEMPLATE_FLEXY_ERROR_SYNTAX, HTML_TEMPLATE_FLEXY_ERROR_DIE);
     }
     foreach ($array as $k => $v) {
         $atts = array();
         if ($k !== $v && !$noValue) {
             $atts = array('value' => $k);
         } else {
             $atts = array('value' => $v);
         }
         $atts['label'] = htmlspecialchars($v);
         $atts['/'] = true;
         $add = new HTML_Template_Flexy_Element($namespace . 'menuitem', $atts);
         $element->children[0]->children[] = $add;
     }
 }