📄 default.php
字号:
if (isset($this->_templates[$name])) { $html = str_replace('{label}', $nameLabel, $this->_templates[$name]); } else { $html = str_replace('{label}', $nameLabel, $this->_elementTemplate); } if ($required) { $html = str_replace('<!-- BEGIN required -->', '', $html); $html = str_replace('<!-- END required -->', '', $html); } else { $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/iU", '', $html); } if (isset($error)) { $html = str_replace('{error}', $error, $html); $html = str_replace('<!-- BEGIN error -->', '', $html); $html = str_replace('<!-- END error -->', '', $html); } else { $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->(\s|\S)*<!-- END error -->([ \t\n\r]*)?/iU", '', $html); } if (is_array($label)) { foreach($label as $key => $text) { $key = is_int($key)? $key + 2: $key; $html = str_replace("{label_{$key}}", $text, $html); $html = str_replace("<!-- BEGIN label_{$key} -->", '', $html); $html = str_replace("<!-- END label_{$key} -->", '', $html); } } if (strpos($html, '{label_')) { $html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/i', '', $html); } return $html; } // end func _prepareTemplate /** * Renders an element Html * Called when visiting an element * * @param object An HTML_QuickForm_element object being visited * @param bool Whether an element is required * @param string An error message associated with an element * @access public * @return void */ function renderElement(&$element, $required, $error) { if (!$this->_inGroup) { $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error); $this->_html .= str_replace('{element}', $element->toHtml(), $html); } elseif (!empty($this->_groupElementTemplate)) { $html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate); if ($required) { $html = str_replace('<!-- BEGIN required -->', '', $html); $html = str_replace('<!-- END required -->', '', $html); } else { $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/iU", '', $html); } $this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html); } else { $this->_groupElements[] = $element->toHtml(); } } // end func renderElement /** * Renders an hidden element * Called when visiting a hidden element * * @param object An HTML_QuickForm_hidden object being visited * @access public * @return void */ function renderHidden(&$element) { $this->_hiddenHtml .= $element->toHtml() . "\n"; } // end func renderHidden /** * Called when visiting a raw HTML/text pseudo-element * * @param object An HTML_QuickForm_html element being visited * @access public * @return void */ function renderHtml(&$data) { $this->_html .= $data->toHtml(); } // end func renderHtml /** * Called when visiting a group, before processing any group elements * * @param object An HTML_QuickForm_group object being visited * @param bool Whether a group is required * @param string An error message associated with a group * @access public * @return void */ function startGroup(&$group, $required, $error) { $name = $group->getName(); $this->_groupTemplate = $this->_prepareTemplate($name, $group->getLabel(), $required, $error); $this->_groupElementTemplate = empty($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name]; $this->_groupWrap = empty($this->_groupWraps[$name])? '': $this->_groupWraps[$name]; $this->_groupElements = array(); $this->_inGroup = true; } // end func startGroup /** * Called when visiting a group, after processing all group elements * * @param object An HTML_QuickForm_group object being visited * @access public * @return void */ function finishGroup(&$group) { $separator = $group->_separator; if (is_array($separator)) { $count = count($separator); $html = ''; for ($i = 0; $i < count($this->_groupElements); $i++) { $html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i]; } } else { if (is_null($separator)) { $separator = ' '; } $html = implode((string)$separator, $this->_groupElements); } if (!empty($this->_groupWrap)) { $html = str_replace('{content}', $html, $this->_groupWrap); } $this->_html .= str_replace('{element}', $html, $this->_groupTemplate); $this->_inGroup = false; } // end func finishGroup /** * Sets element template * * @param string The HTML surrounding an element * @param string (optional) Name of the element to apply template for * @access public * @return void */ function setElementTemplate($html, $element = null) { if (is_null($element)) { $this->_elementTemplate = $html; } else { $this->_templates[$element] = $html; } } // end func setElementTemplate /** * Sets template for a group wrapper * * This template is contained within a group-as-element template * set via setTemplate() and contains group's element templates, set * via setGroupElementTemplate() * * @param string The HTML surrounding group elements * @param string Name of the group to apply template for * @access public * @return void */ function setGroupTemplate($html, $group) { $this->_groupWraps[$group] = $html; } // end func setGroupTemplate /** * Sets element template for elements within a group * * @param string The HTML surrounding an element * @param string Name of the group to apply template for * @access public * @return void */ function setGroupElementTemplate($html, $group) { $this->_groupTemplates[$group] = $html; } // end func setGroupElementTemplate /** * Sets header template * * @param string The HTML surrounding the header * @access public * @return void */ function setHeaderTemplate($html) { $this->_headerTemplate = $html; } // end func setHeaderTemplate /** * Sets form template * * @param string The HTML surrounding the form tags * @access public * @return void */ function setFormTemplate($html) { $this->_formTemplate = $html; } // end func setFormTemplate /** * Sets the note indicating required fields template * * @param string The HTML surrounding the required note * @access public * @return void */ function setRequiredNoteTemplate($html) { $this->_requiredNoteTemplate = $html; } // end func setRequiredNoteTemplate /** * Clears all the HTML out of the templates that surround notes, elements, etc. * Useful when you want to use addData() to create a completely custom form look * * @access public * @return void */ function clearAllTemplates() { $this->setElementTemplate('{element}'); $this->setFormTemplate("\n\t<form{attributes}>{content}\n\t</form>\n"); $this->setRequiredNoteTemplate(''); $this->_templates = array(); } // end func clearAllTemplates} // end class HTML_QuickForm_Renderer_Default?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -