mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-25 23:48:42 +00:00
feat(web/blog): remove draft
This commit is contained in:
parent
4c98089f53
commit
1bc7762be6
@ -69,7 +69,6 @@ CREATE TABLE `blogs` (
|
|||||||
`zan` int(11) NOT NULL,
|
`zan` int(11) NOT NULL,
|
||||||
`is_hidden` tinyint(1) NOT NULL,
|
`is_hidden` tinyint(1) NOT NULL,
|
||||||
`type` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'B',
|
`type` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'B',
|
||||||
`is_draft` tinyint(1) NOT NULL DEFAULT '0',
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
becomeMsgPage(UOJLocale::get('need login'));
|
becomeMsgPage(UOJLocale::get('need login'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$blogs_cond = "poster = '".UOJContext::userid()."' and is_draft = false";
|
$blogs_cond = "poster = '".UOJContext::userid()."'";
|
||||||
if (!UOJContext::hasBlogPermission()) {
|
if (!UOJContext::hasBlogPermission()) {
|
||||||
$blogs_cond .= " and is_hidden = false";
|
$blogs_cond .= " and is_hidden = false";
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisBlog($blog)) {
|
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisBlog($blog)) {
|
||||||
become404Page();
|
become404Page();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$blog = DB::selectFirst("select * from blogs where poster = '".UOJContext::user()['username']."' and type = 'B' and is_draft = true");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$blog_editor = new UOJBlogEditor();
|
$blog_editor = new UOJBlogEditor();
|
||||||
@ -35,7 +33,7 @@
|
|||||||
'is_hidden' => true
|
'is_hidden' => true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($blog && !$blog['is_draft']) {
|
if ($blog) {
|
||||||
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
|
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
|
||||||
} else {
|
} else {
|
||||||
$blog_editor->blog_url = null;
|
$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}");
|
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) {
|
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) {
|
$blog_editor->save = function($data) {
|
||||||
global $blog;
|
global $blog;
|
||||||
$ret = array();
|
$ret = array();
|
||||||
if ($blog) {
|
if ($blog) {
|
||||||
if ($blog['is_draft']) {
|
|
||||||
if ($data['is_hidden']) {
|
|
||||||
updateBlog($blog['id'], $data);
|
updateBlog($blog['id'], $data);
|
||||||
} else {
|
} else {
|
||||||
deleteBlog($blog['id']);
|
insertBlog($data);
|
||||||
insertBlog(array_merge($data, array('is_draft' => 0)));
|
|
||||||
$blog = array('id' => DB::insert_id(), 'tags' => array());
|
$blog = array('id' => DB::insert_id(), 'tags' => array());
|
||||||
$ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}/write");
|
$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_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']) {
|
if ($data['tags'] !== $blog['tags']) {
|
||||||
DB::delete("delete from blogs_tags where blog_id = {$blog['id']}");
|
DB::delete("delete from blogs_tags where blog_id = {$blog['id']}");
|
||||||
foreach ($data['tags'] as $tag) {
|
foreach ($data['tags'] as $tag) {
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisSlide($blog)) {
|
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisSlide($blog)) {
|
||||||
become404Page();
|
become404Page();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$blog = DB::selectFirst("select * from blogs where poster = '".UOJContext::user()['username']."' and type = 'S' and is_draft = true");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$blog_editor = new UOJBlogEditor();
|
$blog_editor = new UOJBlogEditor();
|
||||||
@ -36,7 +34,7 @@
|
|||||||
'is_hidden' => true
|
'is_hidden' => true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($blog && !$blog['is_draft']) {
|
if ($blog) {
|
||||||
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
|
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
|
||||||
} else {
|
} else {
|
||||||
$blog_editor->blog_url = null;
|
$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}");
|
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) {
|
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) {
|
$blog_editor->save = function($data) {
|
||||||
global $blog;
|
global $blog;
|
||||||
$ret = array();
|
$ret = array();
|
||||||
if ($blog) {
|
if ($blog) {
|
||||||
if ($blog['is_draft']) {
|
|
||||||
if ($data['is_hidden']) {
|
|
||||||
updateBlog($blog['id'], $data);
|
updateBlog($blog['id'], $data);
|
||||||
} else {
|
} else {
|
||||||
deleteBlog($blog['id']);
|
insertSlide($data);
|
||||||
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)));
|
|
||||||
$blog = array('id' => DB::insert_id(), 'tags' => array());
|
$blog = array('id' => DB::insert_id(), 'tags' => array());
|
||||||
}
|
}
|
||||||
if ($data['tags'] !== $blog['tags']) {
|
if ($data['tags'] !== $blog['tags']) {
|
||||||
|
@ -108,13 +108,13 @@ class UOJContext {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$blog = $args[0];
|
$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':
|
case 'isHisSlide':
|
||||||
if (!isset($args[0])) {
|
if (!isset($args[0])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$blog = $args[0];
|
$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;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user