/** * 在容器里增加元素 * * @access public * @param Typecho_Widget_Helper_Layout $item 表单元素 * @return $this */ public function container(Typecho_Widget_Helper_Layout $item) { /** 创建表单容器 */ if (empty($this->container)) { $this->container = new Typecho_Widget_Helper_Layout('li'); $this->addItem($this->container); } $this->container->addItem($item); return $this; }
/** * 初始化当前输入项 * * @access public * @param string $name 表单元素名称 * @param array $options 选择项 * @return Typecho_Widget_Helper_Layout */ public function input($name = NULL, array $options = NULL) { $input = new Typecho_Widget_Helper_Layout('select'); $this->container($input->setAttribute('name', $name)->setAttribute('id', $name . '-0-' . self::$uniqueId)); $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId); foreach ($options as $value => $label) { $this->_options[$value] = new Typecho_Widget_Helper_Layout('option'); $input->addItem($this->_options[$value]->setAttribute('value', $value)->html($label)); } return $input; }
/** * 增加元素(重载) * * @access public * @param Typecho_Widget_Helper_Layout $item 表单元素 * @return Typecho_Widget_Helper_Layout */ public function addItem(Typecho_Widget_Helper_Layout $item) { if ($item instanceof Typecho_Widget_Helper_Form_Submit) { $this->addItem($item); } else { parent::addItem($item); } return $this; }
/** * getDefaultFieldItems * * @access public * @return array */ public function getDefaultFieldItems() { $defaultFields = array(); $configFile = $this->options->themeFile($this->options->theme, 'functions.php'); $layout = new Typecho_Widget_Helper_Layout(); $fields = new Typecho_Config(); if ($this->have()) { $fields = $this->fields; } $this->pluginHandle()->getDefaultFieldItems($layout); if (file_exists($configFile)) { require_once $configFile; if (function_exists('themeFields')) { themeFields($layout); } if (function_exists($this->themeCustomFieldsHook)) { call_user_func($this->themeCustomFieldsHook, $layout); } } $items = $layout->getItems(); foreach ($items as $item) { if ($item instanceof Typecho_Widget_Helper_Form_Element) { $name = $item->input->getAttribute('name'); $isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents')->trigger($plugged)->isFieldReadOnly($name); if ($plugged && $isFieldReadOnly) { continue; } if (preg_match("/^fields\\[(.+)\\]\$/", $name, $matches)) { $name = $matches[1]; } else { foreach ($item->inputs as $input) { $input->setAttribute('name', 'fields[' . $name . ']'); } } $item->value($fields->{$name}); $elements = $item->container->getItems(); array_shift($elements); $div = new Typecho_Widget_Helper_Layout('div'); foreach ($elements as $el) { $div->addItem($el); } $defaultFields[$name] = array($item->label, $div); } } return $defaultFields; }
/** * 增加到某布局元素集合中 * * @access public * @param Typecho_Widget_Helper_Layout $parent 布局对象 * @return Typecho_Widget_Helper_Layout */ public function appendTo(Typecho_Widget_Helper_Layout $parent) { $parent->addItem($this); return $this; }
public function input($name = NULL, array $options = NULL) { $input = new Typecho_Widget_Helper_Layout('select', array('onchange' => 'select_theme_change(this);')); $this->container($input->setAttribute('name', $name)->setAttribute('id', $name . '-0-' . self::$uniqueId)); $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId); $this->inputs[] = $input; foreach ($options as $value => $label) { $this->_options[$value] = new Typecho_Widget_Helper_Layout('option'); $input->addItem($this->_options[$value]->setAttribute('value', $value)->html($label)); if (DomainTheme_Plugin::$TEMP_THEME_NAME == $value) { $this->_options[$value]->setAttribute('selected', 'selected'); } } return $input; }