📄 element.php
字号:
// does the value exist and match.. if (isset($child->attributes['value']) && in_array((string) $child->attributes['value'], $value)) { $this->children[$i]->children[$ii]->attributes['selected'] = isset($this->attributes['flexy:xhtml']) ? 'selected' : true; continue; } if (isset($child->attributes['value']) && isset($this->children[$i]->children[$ii]->attributes['selected'])) { unset($this->children[$i]->children[$ii]->attributes['selected']); continue; } // value doesnt exst.. if (isset($this->children[$i]->children[$ii]->attributes['selected'])) { unset($this->children[$i]->children[$ii]->attributes['selected']); continue; } } continue; } // 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)) { $this->children[$i]->attributes['selected'] = isset($this->attributes['flexy:xhtml']) ? 'selected' : true;; continue; } // no value attribute try and use the contents. if (!isset($child->attributes['value']) && is_string($child->children[0]) && in_array((string) $child->children[0], $value)) { $this->children[$i]->attributes['selected'] = isset($this->attributes['flexy:xhtml']) ? 'selected' : true; continue; } if (isset($child->attributes['value']) && isset($this->children[$i]->attributes['selected'])) { //echo "clearing selected\n"; unset($this->children[$i]->attributes['selected']); continue; } // value doesnt exst.. if (isset($this->children[$i]->attributes['selected'])) { //echo "clearing selected\n"; unset($this->children[$i]->attributes['selected']); continue; } } return; case 'textarea': $this->children = array(htmlspecialchars($value)); return; case '': // dummy objects. $this->value = $value; return; // XUL elements case 'menulist': require_once 'HTML/Template/Flexy/Element/Xul.php'; HTML_Template_Flexy_Element_Xul::setValue($this,$value); return ; default: if (is_array($value)) { return; } $this->value = $value; } } /** * Utility function equivilant to HTML_Select - loadArray ** * but using * key=>value maps * <option value="key">Value</option> * Key=key (eg. both the same) maps to * <option>key</option> * and label = array(key=>value) maps to * <optgroup label="label"> <option value="key">value</option></optgroup> * * $element->setOptions(array('a'=>'xxx','b'=>'yyy')); * or * $element->setOptions(array('a','b','c','d'),true); * * *. * @param HTML_Element $from override settings from another element. * @param HTML_Element $noValue ignore the key part of the array * @access public */ function setOptions($array,$noValue=false) { if (!is_array($array)) { $this->children = array(); return; } $tag = strtolower($this->tag); $namespace = ''; if (false !== strpos($this->tag, ':')) { $bits = explode(':',$this->tag); $namespace = $bits[0] . ':'; $tag = strtolower($bits[1]); } // if we have specified a xultag!!? if (strlen($tag) && ($tag != 'select')) { require_once 'HTML/Template/Flexy/Element/Xul.php'; return HTML_Template_Flexy_Element_Xul::setOptions($this,$array,$noValue); } foreach($array as $k=>$v) { if (is_array($v)) { // optgroup $child = new HTML_Template_Flexy_Element($namespace . 'optgroup',array('label'=>$k)); foreach($v as $kk=>$vv) { $atts=array(); if (($kk != $vv) && !$noValue) { $atts = array('value'=>$kk); } $add = new HTML_Template_Flexy_Element($namespace . 'option',$atts); $add->children = array(htmlspecialchars($vv)); $child->children[] = $add; } $this->children[] = $child; continue; } $atts=array(); if (($k !== $v) && !$noValue) { $atts = array('value'=>$k); } else { $atts = array('value'=>$v); } $add = new HTML_Template_Flexy_Element($namespace . 'option',$atts); $add->children = array(htmlspecialchars($v)); $this->children[] = $add; } } /** * Sets the HTML attributes * @param mixed $attributes Either a typical HTML attribute string or an associative array * @access public */ function setAttributes($attributes) { $attrs= $this->parseAttributes($attributes); if (!is_array($attrs)) { return false; } foreach ($attrs as $key => $value) { $this->attributes[$key] = $value; } } // end func updateAttributes /** * Removes an attributes * * @param string $attr Attribute name * @since 1.4 * @access public * @return void * @throws */ function removeAttributes($attrs) { if (is_string($attrs)) { $attrs = array($attrs); } foreach ($attrs as $attr) { if (isset($this->attributes[strtolower($attr)])) { $this->attributes[strtolower($attr)] = false; } } } //end func removeAttribute /** * Output HTML and children * * @access public * @param object $overlay = merge data from object. * @return string * @abstract */ function toHtml($overlay=false) { //echo "BEFORE<PRE>";print_R($this); $ret = $this; if ($overlay !== false) { $ret = HTML_Template_Flexy::mergeElement($this,$overlay); } if ($ret->override !== false) { return $ret->override; } $prefix = $ret->prefix; if (is_object($prefix)) { $prefix = $prefix->toHtml(); } $suffix = $ret->suffix; if (is_object($suffix)) { $suffix = $suffix->toHtml(); } //echo "AFTER<PRE>";print_R($ret); $tag = $this->tag; if (strpos($tag,':') !== false) { $bits = explode(':',$tag); $tag = $bits[1]; } // tags that never should have closers $close = "</{$ret->tag}>"; if (in_array(strtoupper($tag),array("INPUT","IMG"))) { $close = ''; } if (isset($this->attributes['/'])) { $close = ''; } $close .= $suffix ; return "{$prefix}<{$ret->tag}".$ret->attributesToHTML() . '>'.$ret->childrenToHTML() .$close; } // end func toHtml /** * Output Open Tag and any children and not Child tag (designed for use with <form + hidden elements> * * @access public * @param object $overlay = merge data from object. * @return string * @abstract */ function toHtmlnoClose($overlay=false) { $ret = $this; if ($ret->override !== false) { return $ret->override; } if ($overlay !== false) { $ret = HTML_Template_Flexy::mergeElement($this,$overlay); } return "<{$ret->tag}".$ret->attributesToHTML() . '>' . $ret->childrenToHTML(); } // end func toHtml /** * Output HTML and children * * @access public * @return string * @abstract */ function childrenToHtml() { $ret = ''; foreach($this->children as $child) { if (!is_object($child)) { $ret .= $child; continue; } $ret .= $child->toHtml(); } return $ret; } // end func toHtml } // end class HTML_Template_Flexy_Element
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -