feat(web/blog): remove draft

This commit is contained in:
Baoshuo Ren 2022-03-17 16:38:39 +08:00
parent 4c98089f53
commit 1bc7762be6
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
5 changed files with 13 additions and 44 deletions

View File

@ -69,7 +69,6 @@ CREATE TABLE `blogs` (
`zan` int(11) NOT NULL,
`is_hidden` tinyint(1) NOT NULL,
`type` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'B',
`is_draft` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -5,7 +5,7 @@
becomeMsgPage(UOJLocale::get('need login'));
}
$blogs_cond = "poster = '".UOJContext::userid()."' and is_draft = false";
$blogs_cond = "poster = '".UOJContext::userid()."'";
if (!UOJContext::hasBlogPermission()) {
$blogs_cond .= " and is_hidden = false";
}

View File

@ -12,8 +12,6 @@
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisBlog($blog)) {
become404Page();
}
} else {
$blog = DB::selectFirst("select * from blogs where poster = '".UOJContext::user()['username']."' and type = 'B' and is_draft = true");
}
$blog_editor = new UOJBlogEditor();
@ -35,7 +33,7 @@
'is_hidden' => true
);
}
if ($blog && !$blog['is_draft']) {
if ($blog) {
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
} else {
$blog_editor->blog_url = null;
@ -45,34 +43,20 @@
DB::update("update blogs set title = '".DB::escape($data['title'])."', content = '".DB::escape($data['content'])."', content_md = '".DB::escape($data['content_md'])."', is_hidden = {$data['is_hidden']} where id = {$id}");
}
function insertBlog($data) {
DB::insert("insert into blogs (title, content, content_md, poster, is_hidden, is_draft, post_time) values ('".DB::escape($data['title'])."', '".DB::escape($data['content'])."', '".DB::escape($data['content_md'])."', '".Auth::id()."', {$data['is_hidden']}, {$data['is_draft']}, now())");
DB::insert("insert into blogs (title, content, content_md, poster, is_hidden, post_time) values ('".DB::escape($data['title'])."', '".DB::escape($data['content'])."', '".DB::escape($data['content_md'])."', '".Auth::id()."', {$data['is_hidden']}, now())");
}
$blog_editor->save = function($data) {
global $blog;
$ret = array();
if ($blog) {
if ($blog['is_draft']) {
if ($data['is_hidden']) {
updateBlog($blog['id'], $data);
} else {
deleteBlog($blog['id']);
insertBlog(array_merge($data, array('is_draft' => 0)));
insertBlog($data);
$blog = array('id' => DB::insert_id(), 'tags' => array());
$ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}/write");
$ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
}
} else {
updateBlog($blog['id'], $data);
}
} else {
insertBlog(array_merge($data, array('is_draft' => $data['is_hidden'] ? 1 : 0)));
$blog = array('id' => DB::insert_id(), 'tags' => array());
if (!$data['is_hidden']) {
$ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}/write");
$ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
}
}
if ($data['tags'] !== $blog['tags']) {
DB::delete("delete from blogs_tags where blog_id = {$blog['id']}");
foreach ($data['tags'] as $tag) {

View File

@ -12,8 +12,6 @@
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisSlide($blog)) {
become404Page();
}
} else {
$blog = DB::selectFirst("select * from blogs where poster = '".UOJContext::user()['username']."' and type = 'S' and is_draft = true");
}
$blog_editor = new UOJBlogEditor();
@ -36,7 +34,7 @@
'is_hidden' => true
);
}
if ($blog && !$blog['is_draft']) {
if ($blog) {
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
} else {
$blog_editor->blog_url = null;
@ -46,28 +44,16 @@
DB::update("update blogs set title = '".DB::escape($data['title'])."', content = '".DB::escape($data['content'])."', content_md = '".DB::escape($data['content_md'])."', is_hidden = {$data['is_hidden']} where id = {$id}");
}
function insertSlide($data) {
DB::insert("insert into blogs (type, title, content, content_md, poster, is_hidden, is_draft, post_time) values ('S', '".DB::escape($data['title'])."', '".DB::escape($data['content'])."', '".DB::escape($data['content_md'])."', '".Auth::id()."', {$data['is_hidden']}, {$data['is_draft']}, now())");
DB::insert("insert into blogs (type, title, content, content_md, poster, is_hidden, post_time) values ('S', '".DB::escape($data['title'])."', '".DB::escape($data['content'])."', '".DB::escape($data['content_md'])."', '".Auth::id()."', {$data['is_hidden']}, now())");
}
$blog_editor->save = function($data) {
global $blog;
$ret = array();
if ($blog) {
if ($blog['is_draft']) {
if ($data['is_hidden']) {
updateBlog($blog['id'], $data);
} else {
deleteBlog($blog['id']);
insertSlide(array_merge($data, array('is_draft' => 0)));
$blog = array('id' => DB::insert_id(), 'tags' => array());
$ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/slide/{$blog['id']}/write");
$ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
}
} else {
updateBlog($blog['id'], $data);
}
} else {
insertSlide(array_merge($data, array('is_draft' => $data['is_hidden'] ? 1 : 0)));
insertSlide($data);
$blog = array('id' => DB::insert_id(), 'tags' => array());
}
if ($data['tags'] !== $blog['tags']) {

View File

@ -108,13 +108,13 @@ class UOJContext {
return false;
}
$blog = $args[0];
return $blog['poster'] == self::$data['user']['username'] && $blog['type'] == 'B' && $blog['is_draft'] == false;
return $blog['poster'] == self::$data['user']['username'] && $blog['type'] == 'B';
case 'isHisSlide':
if (!isset($args[0])) {
return false;
}
$blog = $args[0];
return $blog['poster'] == self::$data['user']['username'] && $blog['type'] == 'S' && $blog['is_draft'] == false;
return $blog['poster'] == self::$data['user']['username'] && $blog['type'] == 'S';
}
break;
}