HTML_Template_Flexy
[ class tree: HTML_Template_Flexy ] [ index: HTML_Template_Flexy ] [ all elements ]

Source for file Xul.php

Documentation is available at Xul.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Alan Knowles <alan@akbkhome.com>                             |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Xul.php,v 1.4 2004/08/17 03:50:27 alan_k Exp $
  20.  
  21. /**
  22.  * Extension HTML Element builder and render to provide features for Xul
  23.  *
  24.  * All methods are static, and expect the first argument to be a HTML_Template_Flexy_Element
  25.  *
  26.  * @author      Alan Knowles <alan@akbkhome.com>
  27.  */
  28. class HTML_Template_Flexy_Element_Xul {
  29.  
  30.     
  31.     /**
  32.      * Utility function to set values for common tag types.
  33.      * @param    HTML_Template_Flexy_Element   $element  override settings from another element.
  34.      * @param    mixed   $value  value to use.
  35.      * @access   public
  36.      */
  37.      
  38.     function setValue(&$element,$value{
  39.         // store the value in all situations
  40.         $element->value = $value;
  41.         $tag $element->tag;
  42.         if (strpos($tag,':'!==  false{
  43.             $bits explode(':',$tag);
  44.             $tag $bits[1];
  45.         }
  46.         switch ($tag{
  47.             case 'menulist':
  48.                 
  49.                 if (!is_array($value)) {
  50.                     $value = array($value);
  51.                 }
  52.                 
  53.                 // is the first childa  menupopup
  54.                 if (!isset($element->children[0])) {
  55.                     $element->children[0= HTML_Template_Flexy_Element('menupopup');
  56.                 }
  57.                 if (!is_a($element->children[0],'HTML_Template_Flexy_Element')) {
  58.                     // oh sh*t big problem!
  59.                     return HTML_Template_Flexy::raiseError(
  60.                         __CLASS__ . '::setValue expected a menupopup as the child of a menuitem?'
  61.                         HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,
  62.                         HTML_TEMPLATE_FLEXY_ERROR_DIE);
  63.                 }
  64.                  
  65.                 
  66.                 // its setting the default value..
  67.                 // if the children havent been built we dont really care?
  68.                 // it will be done at the merge stage anyway..
  69.                 
  70.                 foreach(array_keys($element->children[0]->childrenas $i{
  71.                     $child &$element->children[0]->children[$i];
  72.                     
  73.                     if (is_string($child)) {
  74.                         continue;
  75.                     }
  76.                      
  77.                     
  78.                     // standard option value...
  79.                     //echo "testing {$child->attributes['value']} against ". print_r($value,true)."\n";
  80.                     // does the value exist and match..
  81.                     
  82.                     if (isset($child->attributes['value']
  83.                         && in_array((string) $child->attributes['value']$value)) 
  84.                     {
  85.                        // echo "MATCH!\n";
  86.                         $child->attributes['selected''true';
  87.                         continue;
  88.                     }
  89.                     
  90.                     // otherwise..
  91.                     $child->attributes['selected''false';
  92.                     
  93.                 }
  94.                  
  95.                 return;
  96.              
  97.         }
  98.             
  99.         
  100.     
  101.     
  102.     }
  103.     /**
  104.      * Utility function equivilant to HTML_Select - loadArray ** For xul:menulist.
  105.      * but using
  106.      * key=>value maps
  107.      * <option value="key">Value</option>
  108.      * Key=key (eg. both the same) maps to
  109.      *  
  110.      * 
  111.      *
  112.      * @param    HTML_Element   $from  override settings from another element.
  113.      * @param    HTML_Element   $noValue  ignore the key part of the array
  114.      * @access   public
  115.      */
  116.      
  117.     function setOptions(&$element$array,$noValue=false{
  118.         if (!is_array($array)) {
  119.             $element->children = array();
  120.             return;
  121.         }
  122.         
  123.         
  124.         $tag '';
  125.         $namespace '';
  126.         if (false !== strpos($element->tag':')) {
  127.             
  128.             $bits explode(':',$element->tag);
  129.             $namespace $bits[0':';
  130.             $tag strtolower($bits[1]);
  131.             
  132.         }
  133.         if (!isset($element->children[0])) {
  134.             $element->children[0= new  HTML_Template_Flexy_Element('menupopup');
  135.         }
  136.         if (!is_a($element->children[0],'HTML_Template_Flexy_Element')) {
  137.             // oh sh*t big problem!
  138.             return HTML_Template_Flexy::raiseError(
  139.                 __CLASS__ . '::setValue expected a menupopup as the child of a menuitem?'
  140.                 HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,
  141.                 HTML_TEMPLATE_FLEXY_ERROR_DIE);
  142.         }
  143.         foreach($array as $k=>$v{
  144.             
  145.             $atts=array();
  146.             if (($k !== $v&& !$noValue{
  147.                 $atts = array('value'=>$k);
  148.             else {
  149.                 $atts = array('value'=>$v);
  150.             }
  151.             $atts['label'htmlspecialchars($v);
  152.             $atts['/'= true;
  153.             $add = new HTML_Template_Flexy_Element($namespace 'menuitem',$atts);
  154.             $element->children[0]->children[$add;
  155.         }
  156.        
  157.     }
  158.    
  159.      
  160.     
  161.     
  162.     
  163. // end class HTML_Template_Flexy_Element

Documentation generated on Mon, 11 Mar 2019 14:17:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.