diff --git a/usr/themes/default/functions.php b/usr/themes/default/functions.php index cae4eb02..d4d13225 100644 --- a/usr/themes/default/functions.php +++ b/usr/themes/default/functions.php @@ -15,9 +15,7 @@ function themeConfig($form) { $form->addInput($sidebarBlock->multiMode()); } -/* function themeFields($layout) { $logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点LOGO地址'), _t('在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO')); $layout->addItem($logoUrl); } -*/ diff --git a/var/Typecho/Widget/Helper/Form/Element.php b/var/Typecho/Widget/Helper/Form/Element.php index c4cb2a14..97e5c00a 100644 --- a/var/Typecho/Widget/Helper/Form/Element.php +++ b/var/Typecho/Widget/Helper/Form/Element.php @@ -38,14 +38,6 @@ abstract class Typecho_Widget_Helper_Form_Element extends Typecho_Widget_Helper_ */ protected $message; - /** - * 表单元素容器 - * - * @access protected - * @var Typecho_Widget_Helper_Layout - */ - protected $container; - /** * 多行输入 * @@ -62,6 +54,14 @@ abstract class Typecho_Widget_Helper_Form_Element extends Typecho_Widget_Helper_ */ protected static $uniqueId = 0; + /** + * 表单元素容器 + * + * @access public + * @var Typecho_Widget_Helper_Layout + */ + public $container; + /** * 输入栏 * @@ -70,6 +70,14 @@ abstract class Typecho_Widget_Helper_Form_Element extends Typecho_Widget_Helper_ */ public $input; + /** + * inputs + * + * @var array + * @access public + */ + public $inputs = array(); + /** * 表单标题 * diff --git a/var/Typecho/Widget/Helper/Form/Element/Checkbox.php b/var/Typecho/Widget/Helper/Form/Element/Checkbox.php index da083240..e2b8af59 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Checkbox.php +++ b/var/Typecho/Widget/Helper/Form/Element/Checkbox.php @@ -44,6 +44,7 @@ class Typecho_Widget_Helper_Form_Element_Checkbox extends Typecho_Widget_Helper_ $this->_options[$value] = new Typecho_Widget_Helper_Layout('input'); $item = $this->multiline(); $id = $this->name . '-' . $this->filterValue($value); + $this->inputs[] = $this->_options[$value]; $item->addItem($this->_options[$value]->setAttribute('name', $this->name . '[]') ->setAttribute('type', 'checkbox') diff --git a/var/Typecho/Widget/Helper/Form/Element/Hidden.php b/var/Typecho/Widget/Helper/Form/Element/Hidden.php index 87004e7f..889bc7e7 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Hidden.php +++ b/var/Typecho/Widget/Helper/Form/Element/Hidden.php @@ -46,6 +46,7 @@ class Typecho_Widget_Helper_Form_Element_Hidden extends Typecho_Widget_Helper_Fo { $input = new Typecho_Widget_Helper_Layout('input', array('name' => $name, 'type' => 'hidden')); $this->container($input); + $this->inputs[] = $input; return $input; } diff --git a/var/Typecho/Widget/Helper/Form/Element/Password.php b/var/Typecho/Widget/Helper/Form/Element/Password.php index 01f04178..811f28c8 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Password.php +++ b/var/Typecho/Widget/Helper/Form/Element/Password.php @@ -36,6 +36,7 @@ class Typecho_Widget_Helper_Form_Element_Password extends Typecho_Widget_Helper_ 'name' => $name, 'type' => 'password', 'class' => 'password')); $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId); $this->container($input); + $this->inputs[] = $input; return $input; } diff --git a/var/Typecho/Widget/Helper/Form/Element/Radio.php b/var/Typecho/Widget/Helper/Form/Element/Radio.php index 08211940..2b1a5396 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Radio.php +++ b/var/Typecho/Widget/Helper/Form/Element/Radio.php @@ -44,6 +44,7 @@ class Typecho_Widget_Helper_Form_Element_Radio extends Typecho_Widget_Helper_For $this->_options[$value] = new Typecho_Widget_Helper_Layout('input'); $item = $this->multiline(); $id = $this->name . '-' . $this->filterValue($value); + $this->inputs[] = $this->_options[$value]; $item->addItem($this->_options[$value]->setAttribute('name', $this->name) ->setAttribute('type', 'radio') diff --git a/var/Typecho/Widget/Helper/Form/Element/Select.php b/var/Typecho/Widget/Helper/Form/Element/Select.php index c2136c7b..f09e2f66 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Select.php +++ b/var/Typecho/Widget/Helper/Form/Element/Select.php @@ -44,6 +44,7 @@ class Typecho_Widget_Helper_Form_Element_Select extends Typecho_Widget_Helper_Fo $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'); diff --git a/var/Typecho/Widget/Helper/Form/Element/Submit.php b/var/Typecho/Widget/Helper/Form/Element/Submit.php index fd69f679..1d88f513 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Submit.php +++ b/var/Typecho/Widget/Helper/Form/Element/Submit.php @@ -35,6 +35,8 @@ class Typecho_Widget_Helper_Form_Element_Submit extends Typecho_Widget_Helper_Fo $this->setAttribute('class', 'typecho-option typecho-option-submit'); $input = new Typecho_Widget_Helper_Layout('button', array('type' => 'submit')); $this->container($input); + $this->inputs[] = $input; + return $input; } diff --git a/var/Typecho/Widget/Helper/Form/Element/Text.php b/var/Typecho/Widget/Helper/Form/Element/Text.php index a62c1bb6..df5b1e9c 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Text.php +++ b/var/Typecho/Widget/Helper/Form/Element/Text.php @@ -36,6 +36,7 @@ class Typecho_Widget_Helper_Form_Element_Text extends Typecho_Widget_Helper_Form 'name' => $name, 'type' => 'text', 'class' => 'text')); $this->container($input); $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId); + $this->inputs[] = $input; return $input; } diff --git a/var/Typecho/Widget/Helper/Form/Element/Textarea.php b/var/Typecho/Widget/Helper/Form/Element/Textarea.php index 72533987..43d0e497 100644 --- a/var/Typecho/Widget/Helper/Form/Element/Textarea.php +++ b/var/Typecho/Widget/Helper/Form/Element/Textarea.php @@ -35,6 +35,8 @@ class Typecho_Widget_Helper_Form_Element_Textarea extends Typecho_Widget_Helper_ $input = new Typecho_Widget_Helper_Layout('textarea', array('id' => $name . '-0-' . self::$uniqueId, 'name' => $name)); $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId); $this->container($input->setClose(false)); + $this->inputs[] = $input; + return $input; } diff --git a/var/Typecho/Widget/Helper/Layout.php b/var/Typecho/Widget/Helper/Layout.php index f78d4ed5..b90c081e 100644 --- a/var/Typecho/Widget/Helper/Layout.php +++ b/var/Typecho/Widget/Helper/Layout.php @@ -166,6 +166,16 @@ class Typecho_Widget_Helper_Layout { $this->_tagName = $tagName; } + + /** + * getTagName + * + * @param mixed $tagName + * @access public + * @return void + */ + public function getTagName($tagName) + {} /** * 设置表单属性 diff --git a/var/Widget/Abstract/Contents.php b/var/Widget/Abstract/Contents.php index 530b8cf9..0af9e2f6 100644 --- a/var/Widget/Abstract/Contents.php +++ b/var/Widget/Abstract/Contents.php @@ -432,15 +432,16 @@ class Widget_Abstract_Contents extends Widget_Abstract list ($type, $name) = explode(':', $name, 2); } - if (isset($exists[$name])) { - unset($exists[$name]); - } - $isFieldReadOnly = $this->pluginHandle(__CLASS__)->trigger($plugged)->isFieldReadOnly($name); if ($plugged && $isFieldReadOnly) { continue; } + if (isset($exists[$name])) { + unset($exists[$name]); + } + + $this->setField($name, $type, $value, $cid); } diff --git a/var/Widget/Contents/Post/Edit.php b/var/Widget/Contents/Post/Edit.php index 06cd3bea..9d2d2aeb 100644 --- a/var/Widget/Contents/Post/Edit.php +++ b/var/Widget/Contents/Post/Edit.php @@ -496,20 +496,31 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg if ($item instanceof Typecho_Widget_Helper_Form_Element) { $name = $item->input->getAttribute('name'); - if (preg_match("/^fields\[(.+)\]$/", $name, $matches)) { - $name = $matches[1]; - } else { - $item->input->setAttribute('name', 'fields[' . $name . ']'); - } - $isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents') ->trigger($plugged)->isFieldReadOnly($name); if ($plugged && $isFieldReadOnly) { - $item->input->setAttribute('readonly', 'readonly'); + 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}); - $defaultFields[$name] = array($item->label, $item->input); + + $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); } } @@ -532,6 +543,13 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg ->where('cid = ?', $this->cid)); foreach ($rows as $row) { + $isFieldReadOnly = $this->pluginHandle('Widget_Abstract_Contents') + ->trigger($plugged)->isFieldReadOnly($row['name']); + + if ($plugged && $isFieldReadOnly) { + continue; + } + if (!isset($defaultFields[$row['name']])) { $fields[] = $row; }