This commit is contained in:
joyqi
2013-11-25 11:41:31 +08:00
parent fa55695621
commit b68e261a62
8 changed files with 28 additions and 22 deletions
+2 -2
View File
@@ -3,7 +3,7 @@
$fields = isset($post) ? $post->getFieldItems() : $page->getFieldItems();
$defaultFields = isset($post) ? $post->getDefaultFieldItems() : $post->getDefaultFieldItems();
?>
<section id="custom-field" class="typecho-post-option fold">
<section id="custom-field" class="typecho-post-option<?php if (empty($defaultFields) && empty($fields)): ?> fold<?php endif; ?>">
<label id="custom-field-expand" class="typecho-label"><?php _e('自定义字段'); ?></label>
<table class="typecho-list-table mono">
<colgroup>
@@ -29,7 +29,7 @@ $defaultFields = isset($post) ? $post->getDefaultFieldItems() : $post->getDefaul
<option value="float"<?php if ('float' == $field['type']): ?> selected<?php endif; ?>><?php _e('小数'); ?></option>
</select>
</td>
<td><textarea name="fieldValues[]" class="text-s w-100" rows="2"><?php echo htmlspecialchars($field['value']); ?></textarea></td>
<td><textarea name="fieldValues[]" class="text-s w-100" rows="2"><?php echo htmlspecialchars($field[$field['type'] . '_value']); ?></textarea></td>
<td>
<button type="button" class="btn-xs"><?php _e('删除'); ?></button>
</td>
+1 -1
View File
@@ -7,7 +7,7 @@
$(document).ready(function () {
var textarea = $('#text'),
toolbar = $('<div class="editor" id="wmd-button-bar" />').insertBefore(textarea.parent())
preview = $('<div id="wmd-preview" />').insertBefore('.submit');
preview = $('<div id="wmd-preview" />').insertAfter('#upload-panel');
var options = {};
+2 -2
View File
@@ -126,12 +126,12 @@ $(document).ready(function() {
}), savedData = null;
// 自动保存
<?php if ($options->autoSave): ?>
<?php if ($options->autoSave): ?>
var locked = false,
formAction = form.attr('action'),
idInput = $('input[name=cid]'),
cid = idInput.val(),
autoSave = $('#auto-save-message'),
autoSave = $('<span id="auto-save-message" class="left"></span>').prependTo('.submit'),
autoSaveOnce = !!cid,
lastSaveTime = null;
-1
View File
@@ -42,7 +42,6 @@ Typecho_Widget::widget('Widget_Contents_Page_Edit')->to($page);
<?php Typecho_Plugin::factory('admin/write-page.php')->content($page); ?>
<p class="submit clearfix">
<span id="auto-save-message" class="left"></span>
<span class="right">
<input type="hidden" name="cid" value="<?php $page->cid(); ?>" />
<button type="submit" name="do" value="save" id="btn-save"><?php _e('保存草稿'); ?></button>
+5 -4
View File
@@ -46,13 +46,10 @@ Typecho_Widget::widget('Widget_Contents_Post_Edit')->to($post);
<a href="###" class="current">撰写</a>
<a href="###">预览</a>
</div> -->
<?php include 'custom-fields.php'; ?>
<?php include 'file-upload.php'; ?>
<?php Typecho_Plugin::factory('admin/write-post.php')->content($post); ?>
<p class="submit clearfix">
<span id="auto-save-message" class="left"></span>
<span class="right">
<input type="hidden" name="cid" value="<?php $post->cid(); ?>" />
<button type="submit" name="do" value="save" id="btn-save"><?php _e('保存草稿'); ?></button>
@@ -62,6 +59,10 @@ Typecho_Widget::widget('Widget_Contents_Post_Edit')->to($post);
<?php endif; ?>
</span>
</p>
<?php include 'file-upload.php'; ?>
<?php Typecho_Plugin::factory('admin/write-post.php')->content($post); ?>
</div>
<div class="col-mb-12 col-tb-3" role="complementary">
<section class="typecho-post-option" role="application">
+2 -1
View File
@@ -15,8 +15,9 @@ 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);
}
*/
+15 -10
View File
@@ -88,7 +88,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
->where('cid = ?', $this->cid));
foreach ($rows as $row) {
$fields[$row['name']] = $fields[$fields['type'] . '_value'];
$fields[$row['name']] = $row[$row['type'] . '_value'];
}
return new Typecho_Config($fields);
@@ -426,13 +426,14 @@ class Widget_Abstract_Contents extends Widget_Abstract
public function applyFields(array $fields, $cid)
{
$exists = array_flip(Typecho_Common::arrayFlatten($this->db->fetchAll($this->db->select('name')
->from('table.contents')->where('cid = ?', $cid)), 'name'));
->from('table.fields')->where('cid = ?', $cid)), 'name'));
foreach ($fields as $name => $value) {
$type = 'str';
if (is_array($value) && 2 == count($value)) {
list($type, $value) = $value;
$type = $value[0];
$value = $value[1];
} else if (strpos($name, ':') > 0) {
list ($type, $name) = explode(':', $name, 2);
}
@@ -450,7 +451,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
}
foreach ($exists as $name => $value) {
$this->db->query($this->db->delete('table.contents')
$this->db->query($this->db->delete('table.fields')
->where('cid = ? AND name = ?', $cid, $name));
}
}
@@ -467,11 +468,15 @@ class Widget_Abstract_Contents extends Widget_Abstract
*/
public function setField($name, $type, $value, $cid)
{
$exist = $this->db->fetchRow($this->db->select('cid')->from('table.contents')
if (empty($name) || !in_array($type, array('str', 'int', 'float'))) {
return false;
}
$exist = $this->db->fetchRow($this->db->select('cid')->from('table.fields')
->where('cid = ? AND name = ?', $cid, $name));
if (empty($exist)) {
return $this->db->query($this->db->insert('table.contents')
return $this->db->query($this->db->insert('table.fields')
->rows(array(
'cid' => $cid,
'name' => $name,
@@ -481,7 +486,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
'float_value' => 'float' == $type ? floatval($value) : 0
)));
} else {
return $this->db->query($this->db->update('table.contents')
return $this->db->query($this->db->update('table.fields')
->rows(array(
'type' => $type,
'str_value' => 'str' == $type ? $value : NULL,
@@ -503,12 +508,12 @@ class Widget_Abstract_Contents extends Widget_Abstract
*/
public function incrIntField($name, $value, $cid)
{
$exist = $this->db->fetchRow($this->db->select('type')->from('table.contents')
$exist = $this->db->fetchRow($this->db->select('type')->from('table.fields')
->where('cid = ? AND name = ?', $cid, $name));
$value = intval($value);
if (empty($exist)) {
return $this->db->query($this->db->insert('table.contents')
return $this->db->query($this->db->insert('table.fields')
->rows(array(
'cid' => $cid,
'name' => $name,
@@ -527,7 +532,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
$struct['type'] = 'int';
}
return $this->db->query($this->db->update('table.contents')
return $this->db->query($this->db->update('table.fields')
->rows($struct)
->expression('int_value', 'int_value ' . ($value >= 0 ? '+' : '') . $value)
->where('cid = ? AND name = ?', $cid, $name));
+1 -1
View File
@@ -533,7 +533,7 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
foreach ($rows as $row) {
if (!isset($defaultFields[$row['name']])) {
$fields[$row['name']] = $fields[$fields['type'] . '_value'];
$fields[] = $row;
}
}
}