Source for file Xul.php
Documentation is available at Xul.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Alan Knowles <alan@akbkhome.com> |
// +----------------------------------------------------------------------+
// $Id: Xul.php 335205 2014-11-21 04:23:53Z alan_k $
* Extension HTML Element builder and render to provide features for Xul
* All methods are static, and expect the first argument to be a HTML_Template_Flexy_Element
* @author Alan Knowles <alan@akbkhome.com>
class HTML_Template_Flexy_Element_Xul {
* Utility function to set values for common tag types.
* @param HTML_Template_Flexy_Element $element override settings from another element.
* @param mixed $value value to use.
static function setValue (&$element,$value) {
// store the value in all situations
$element->value = $value;
if (strpos($tag,':') !== false ) {
// is the first childa menupopup
if (!isset ($element->children [0 ])) {
$element->children [0 ] = HTML_Template_Flexy_Element ('menupopup');
if (!is_object($element->children [0 ]) || !is_a($element->children [0 ],'HTML_Template_Flexy_Element')) {
return HTML_Template_Flexy ::staticRaiseError (
__CLASS__ . '::setValue expected a Flexy Element as the child of a menuitem but got something else! '.
// its setting the default value..
// if the children havent been built we dont really care?
// it will be done at the merge stage anyway..
foreach(array_keys($element->children [0 ]->children ) as $i) {
$child = &$element->children [0 ]->children [$i];
// standard option value...
//echo "testing {$child->attributes['value']} against ". print_r($value,true)."\n";
// does the value exist and match..
if (isset ($child->attributes ['value'])
&& in_array((string) $child->attributes ['value'], $value))
$child->attributes ['selected'] = 'true';
$child->attributes ['selected'] = 'false';
$this->attributes['value'] = $value;
if (!isset ($this->attributes['value'])) {
return; // should be an error condition really...
$this->attributes['checked'] = ($value == $this->attributes['value']) ? 'true' : 'false';
* Utility function equivilant to HTML_Select - loadArray ** For xul:menulist.
* <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
static function setOptions (&$element, $array,$noValue=false ) {
$element->children = array ();
if (false !== strpos($element->tag , ':')) {
$bits = explode(':',$element->tag );
$namespace = $bits[0 ] . ':';
if (!isset ($element->children [0 ])) {
$element->children [0 ] = new HTML_Template_Flexy_Element ('menupopup');
if (!is_object($element->children [0 ]) || !is_a($element->children [0 ],'HTML_Template_Flexy_Element')) {
return HTML_Template_Flexy ::staticRaiseError (
__CLASS__ . '::setValue expected a menupopup as the child of a menuitem?',
foreach($array as $k=> $v) {
if (($k !== $v) && !$noValue) {
$atts = array ('value'=> $k);
$atts = array ('value'=> $v);
$add = new HTML_Template_Flexy_Element ($namespace . 'menuitem',$atts);
$element->children [0 ]->children [] = $add;
} // 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.
|