diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index ec27022..bd23cb0 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -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 */; diff --git a/web/app/controllers/subdomain/blog/archive.php b/web/app/controllers/subdomain/blog/archive.php index 59dc6ac..ce9da53 100644 --- a/web/app/controllers/subdomain/blog/archive.php +++ b/web/app/controllers/subdomain/blog/archive.php @@ -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"; } diff --git a/web/app/controllers/subdomain/blog/blog_write.php b/web/app/controllers/subdomain/blog/blog_write.php index 57bdd2b..f5e3db5 100644 --- a/web/app/controllers/subdomain/blog/blog_write.php +++ b/web/app/controllers/subdomain/blog/blog_write.php @@ -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,33 +43,19 @@ 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))); - $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); - } + updateBlog($blog['id'], $data); } else { - insertBlog(array_merge($data, array('is_draft' => $data['is_hidden'] ? 1 : 0))); + insertBlog($data); $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']}"); - } + $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']}"); diff --git a/web/app/controllers/subdomain/blog/slide_write.php b/web/app/controllers/subdomain/blog/slide_write.php index 34bec82..308b830 100644 --- a/web/app/controllers/subdomain/blog/slide_write.php +++ b/web/app/controllers/subdomain/blog/slide_write.php @@ -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); - } + 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']) { diff --git a/web/app/models/UOJContext.php b/web/app/models/UOJContext.php index a6c6915..e57654d 100644 --- a/web/app/models/UOJContext.php +++ b/web/app/models/UOJContext.php @@ -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; }