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 335205 2014-11-21 04:23:53Z alan_k $
  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.     static 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_object($element->children[0]|| !is_a($element->children[0],'HTML_Template_Flexy_Element')) {
  58.                     // oh sh*t big problem!
  59.                     return HTML_Template_Flexy::staticRaiseError(
  60.                         __CLASS__ . '::setValue expected a Flexy Element as the child of a menuitem but got something else! '
  61.                             print_r($element,true)
  62.                         HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,
  63.                         HTML_TEMPLATE_FLEXY_ERROR_DIE);
  64.                 }
  65.                  
  66.                 
  67.                 // its setting the default value..
  68.                 // if the children havent been built we dont really care?
  69.                 // it will be done at the merge stage anyway..
  70.                 
  71.                 foreach(array_keys($element->children[0]->childrenas $i{
  72.                     $child &$element->children[0]->children[$i];
  73.                     
  74.                     if (is_string($child)) {
  75.                         continue;
  76.                     }
  77.                      
  78.                     
  79.                     // standard option value...
  80.                     //echo "testing {$child->attributes['value']} against ". print_r($value,true)."\n";
  81.                     // does the value exist and match..
  82.                     
  83.                     if (isset($child->attributes['value']
  84.                         && in_array((string) $child->attributes['value']$value)) 
  85.                     {
  86.                        // echo "MATCH!\n";
  87.                         $child->attributes['selected''true';
  88.                         continue;
  89.                     }
  90.                     
  91.                     // otherwise..
  92.                     $child->attributes['selected''false';
  93.                     
  94.                 }
  95.                  
  96.                 return;
  97.             
  98.             case 'textbox':
  99.                 $this->attributes['value'$value;
  100.                 return;
  101.                 
  102.             case 'checkbox':
  103.                 if (!isset($this->attributes['value'])) {
  104.                     return// should be an error condition really...
  105.                 }
  106.                 $this->attributes['checked'($value == $this->attributes['value']'true' 'false';
  107.                 return;
  108.                 
  109.         }
  110.             
  111.         
  112.     
  113.     
  114.     }
  115.     /**
  116.      * Utility function equivilant to HTML_Select - loadArray ** For xul:menulist.
  117.      * but using
  118.      * key=>value maps
  119.      * <option value="key">Value</option>
  120.      * Key=key (eg. both the same) maps to
  121.      *  
  122.      * 
  123.      *
  124.      * @param    HTML_Element   $from  override settings from another element.
  125.      * @param    HTML_Element   $noValue  ignore the key part of the array
  126.      * @access   public
  127.      */
  128.      
  129.     static function setOptions(&$element$array,$noValue=false{
  130.         if (!is_array($array)) {
  131.             $element->children = array();
  132.             return;
  133.         }
  134.         
  135.         
  136.         $tag '';
  137.         $namespace '';
  138.         if (false !== strpos($element->tag':')) {
  139.             
  140.             $bits explode(':',$element->tag);
  141.             $namespace $bits[0':';
  142.             $tag strtolower($bits[1]);
  143.             
  144.         }
  145.         if (!isset($element->children[0])) {
  146.             $element->children[0= new  HTML_Template_Flexy_Element('menupopup');
  147.         }
  148.         if (!is_object($element->children[0]||  !is_a($element->children[0],'HTML_Template_Flexy_Element')) {
  149.             // oh sh*t big problem!
  150.             return HTML_Template_Flexy::staticRaiseError(
  151.                 __CLASS__ . '::setValue expected a menupopup as the child of a menuitem?'
  152.                 HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,
  153.                 HTML_TEMPLATE_FLEXY_ERROR_DIE);
  154.         }
  155.         foreach($array as $k=>$v{
  156.             
  157.             $atts=array();
  158.             if (($k !== $v&& !$noValue{
  159.                 $atts = array('value'=>$k);
  160.             else {
  161.                 $atts = array('value'=>$v);
  162.             }
  163.             $atts['label'htmlspecialchars($v);
  164.             $atts['/'= true;
  165.             $add = new HTML_Template_Flexy_Element($namespace 'menuitem',$atts);
  166.             $element->children[0]->children[$add;
  167.         }
  168.        
  169.     }
  170.    
  171.      
  172.     
  173.     
  174.     
  175. // end class HTML_Template_Flexy_Element

Documentation generated on Mon, 11 Mar 2019 16:00:04 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.