belongsToUserBlog() || UOJResponse::page404(); UOJBlog::info('type') == 'B' || UOJResponse::page404(); $blog = UOJBlog::info(); $blog['content'] = UOJBlog::cur()->queryContent()['content']; $blog['content_md'] = UOJBlog::cur()->queryContent()['content_md']; } $blog_editor = new UOJBlogEditor(); $blog_editor->name = 'blog'; if ($blog) { $blog_editor->cur_data = array( 'title' => $blog['title'], 'content_md' => $blog['content_md'], 'content' => $blog['content'], 'tags' => UOJBlog::cur()->queryTags(), 'is_hidden' => $blog['is_hidden'] ); } else { $blog_editor->cur_data = array( 'title' => $_GET['title'] ?: '新博客', 'content_md' => '', 'content' => '', 'tags' => [], 'is_hidden' => isset($_GET['is_hidden']) ? $_GET['is_hidden'] : true, ); } if ($blog) { $blog_editor->blog_url = HTML::blog_url(UOJUserBlog::id(), "/post/{$blog['id']}"); } else { $blog_editor->blog_url = null; } function updateBlog($id, $data) { DB::update([ "update blogs", "set", [ "title" => $data['title'], "content" => $data['content'], "content_md" => $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, post_time, active_time)", "values", DB::tuple([ $data['title'], $data['content'], $data['content_md'], UOJUserBlog::id(), $data['is_hidden'], DB::now(), DB::now() ]) ]); } $blog_editor->save = function ($data) { global $blog; $ret = []; if ($blog) { updateBlog($blog['id'], $data); } else { insertBlog($data); $blog_id = DB::insert_id(); (new UOJBlog(['id' => $blog_id, 'type' => 'B']))->setAsCur(); $ret['blog_id'] = $blog_id; $ret['blog_write_url'] = UOJBlog::cur()->getUriForWrite(); $ret['blog_url'] = UOJBlog::cur()->getBlogUri(); } UOJBlog::cur()->updateTags($data['tags']); return $ret; }; $blog_editor->runAtServer(); ?>
帮助:UOJ 博客使用教程。