fix tags saving
This commit is contained in:
@@ -215,6 +215,7 @@ $(document).ready(function() {
|
||||
<?php if ($options->autoSave): ?>
|
||||
// 自动保存
|
||||
let saveTimer = null;
|
||||
let stopAutoSave = false;
|
||||
|
||||
form.on('datachange', function () {
|
||||
changed = true;
|
||||
@@ -225,8 +226,12 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
saveTimer = setTimeout(function () {
|
||||
Typecho.savePost();
|
||||
!stopAutoSave && Typecho.savePost();
|
||||
}, 3000);
|
||||
}).on('submit', function () {
|
||||
stopAutoSave = true;
|
||||
}).on('submitted', function () {
|
||||
stopAutoSave = false;
|
||||
});
|
||||
<?php else: ?>
|
||||
form.on('datachange', function () {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Widget\Base;
|
||||
|
||||
use Typecho\Common;
|
||||
use Typecho\Db\Exception;
|
||||
use Typecho\Db\Query;
|
||||
use Typecho\Router;
|
||||
@@ -144,6 +145,47 @@ class Metas extends Base implements QueryInterface, RowFilterInterface, PrimaryK
|
||||
return $this->db->query($this->db->insert('table.metas')->rows($rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据tag获取ID
|
||||
*
|
||||
* @param mixed $inputTags 标签名
|
||||
* @return array|int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function scanTags($inputTags)
|
||||
{
|
||||
$tags = is_array($inputTags) ? $inputTags : [$inputTags];
|
||||
$result = [];
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if (empty($tag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = $this->db->fetchRow($this->select()
|
||||
->where('type = ?', 'tag')
|
||||
->where('name = ?', $tag)->limit(1));
|
||||
|
||||
if ($row) {
|
||||
$result[] = $row['mid'];
|
||||
} else {
|
||||
$slug = Common::slugName($tag);
|
||||
|
||||
if ($slug) {
|
||||
$result[] = $this->insert([
|
||||
'name' => $tag,
|
||||
'slug' => $slug,
|
||||
'type' => 'tag',
|
||||
'count' => 0,
|
||||
'order' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return is_array($inputTags) ? $result : current($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 锚点id
|
||||
*
|
||||
|
||||
@@ -404,46 +404,4 @@ class Edit extends Metas implements ActionInterface
|
||||
$this->on($this->request->is('do=refresh'))->refreshTag();
|
||||
$this->response->redirect($this->options->adminUrl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据tag获取ID
|
||||
*
|
||||
* @param mixed $inputTags 标签名
|
||||
* @return array|int
|
||||
* @throws Exception
|
||||
*/
|
||||
private function scanTags($inputTags)
|
||||
{
|
||||
$tags = is_array($inputTags) ? $inputTags : [$inputTags];
|
||||
$result = [];
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if (empty($tag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = $this->db->fetchRow($this->select()
|
||||
->where('type = ?', 'tag')
|
||||
->where('name = ?', $tag)->limit(1));
|
||||
|
||||
if ($row) {
|
||||
$result[] = $row['mid'];
|
||||
} else {
|
||||
$slug = Common::slugName($tag);
|
||||
|
||||
if ($slug) {
|
||||
$result[] = $this->insert([
|
||||
'name' => $tag,
|
||||
'slug' => $slug,
|
||||
'type' => 'tag',
|
||||
'count' => 0,
|
||||
'order' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return is_array($inputTags) ? $result : current($result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user