2016-07-18 16:39:37 +00:00
< ? php
requirePHPLib ( 'form' );
2022-03-17 04:00:03 +00:00
2022-10-08 06:10:14 +00:00
if ( ! Auth :: check () && UOJConfig :: $data [ 'switch' ][ 'force-login' ]) {
2022-10-06 12:28:43 +00:00
redirectToLogin ();
2022-03-17 04:00:03 +00:00
}
2022-10-08 06:10:14 +00:00
if ( ! isNormalUser ( $myUser ) && UOJConfig :: $data [ 'switch' ][ 'force-login' ]) {
become403Page ();
}
2016-07-18 16:39:37 +00:00
if ( ! UOJContext :: hasBlogPermission ()) {
become403Page ();
}
if ( isset ( $_GET [ 'id' ])) {
if ( ! validateUInt ( $_GET [ 'id' ]) || ! ( $blog = queryBlog ( $_GET [ 'id' ])) || ! UOJContext :: isHisBlog ( $blog )) {
become404Page ();
}
}
2022-10-07 05:17:33 +00:00
2022-10-16 12:37:31 +00:00
requireLib ( 'bootstrap5' );
2016-07-18 16:39:37 +00:00
$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' => queryBlogTags ( $blog [ 'id' ]),
'is_hidden' => $blog [ 'is_hidden' ]
);
} else {
$blog_editor -> cur_data = array (
2022-09-28 12:38:16 +00:00
'title' => $_GET [ 'title' ] ? : '新博客' ,
2016-07-18 16:39:37 +00:00
'content_md' => '' ,
'content' => '' ,
'tags' => array (),
2022-09-28 12:38:16 +00:00
'is_hidden' => isset ( $_GET [ 'is_hidden' ]) ? $_GET [ 'is_hidden' ] : true ,
2016-07-18 16:39:37 +00:00
);
}
2022-03-17 08:38:39 +00:00
if ( $blog ) {
style(web): change link location of blog functions
When using sub-directory blog, the 'blogof' not looks so good.
And, there are duplicate 'blog' characters, which making people uncomfortable.
So, for sub-directory blog, use 'blog' instead of 'blogof'.
'blog' is not as a sub folder or type anymore, use 'post' instead.
BREAKING CHANGE: Due to the conflict of 'blog' sub-directory, when go to blog post,
now should use 'blogs/{id}'; but when subdomain mode is on, you can still use 'blog'
to access these blog posts. 'blogof' is no longer used, and you need to inform users
that blog link is changed, to avoid the inaccessbility.
2019-07-12 04:13:30 +00:00
$blog_editor -> blog_url = HTML :: blog_url ( UOJContext :: user ()[ 'username' ], " /post/ { $blog [ 'id' ] } " );
2016-07-18 16:39:37 +00:00
} else {
$blog_editor -> blog_url = null ;
}
function updateBlog ( $id , $data ) {
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 ) {
2022-03-17 08:38:39 +00:00
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()) " );
2016-07-18 16:39:37 +00:00
}
$blog_editor -> save = function ( $data ) {
global $blog ;
$ret = array ();
if ( $blog ) {
2022-03-17 08:38:39 +00:00
updateBlog ( $blog [ 'id' ], $data );
2016-07-18 16:39:37 +00:00
} else {
2022-03-17 08:38:39 +00:00
insertBlog ( $data );
2016-07-18 16:39:37 +00:00
$blog = array ( 'id' => DB :: insert_id (), 'tags' => array ());
2022-03-17 08:38:39 +00:00
$ret [ 'blog_write_url' ] = HTML :: blog_url ( UOJContext :: user ()[ 'username' ], " /post/ { $blog [ 'id' ] } /write " );
2022-03-20 09:19:07 +00:00
$ret [ 'blog_url' ] = HTML :: blog_url ( UOJContext :: user ()[ 'username' ], " /post/ { $blog [ 'id' ] } " );
2016-07-18 16:39:37 +00:00
}
if ( $data [ 'tags' ] !== $blog [ 'tags' ]) {
DB :: delete ( " delete from blogs_tags where blog_id = { $blog [ 'id' ] } " );
foreach ( $data [ 'tags' ] as $tag ) {
DB :: insert ( " insert into blogs_tags (blog_id, tag) values ( { $blog [ 'id' ] } , ' " . DB :: escape ( $tag ) . " ') " );
}
}
return $ret ;
};
$blog_editor -> runAtServer ();
2022-09-18 04:58:35 +00:00
?>
2016-07-18 16:39:37 +00:00
< ? php echoUOJPageHeader ( '写博客' ) ?>
2022-10-16 12:37:31 +00:00
< div class = " card " >
< div class = " card-body " >
2016-07-18 16:39:37 +00:00
< ? php $blog_editor -> printHTML () ?>
2022-10-16 12:37:31 +00:00
</ div >
</ div >
<!-- 提示信息 -->
< div class = " card mt-3 " >
< div class = " card-body " >
< h2 class = " h4 card-title " > 提示 </ h2 >
< ol >
< li > 题解发布后还需要返回对应题目的题解页面 < b > 手动输入博客 ID </ b > 来将本文添加到题目的题解列表中(博客 ID 可以在右上角找到); </ li >
< li > 请勿引用不稳定的外部资源(如来自个人服务器的图片或文档等),以便备份及后期维护; </ li >
< li > 请勿在博文中直接插入大段 HTML 代码,这可能会破坏页面的显示,可以考虑使用 < a class = " text-decoration-none " href = " /html2markdown " target = " _blank " > 转换工具 </ a > 转换后再作修正; </ li >
< li > 图片上传推荐使用 < a class = " text-decoration-none " href = " /image_hosting " target = " _blank " > S2OJ 图床 </ a > ,以免后续产生外链图片大量失效的情况。 </ li >
</ ol >
< p class = " card-text " >
帮助: < a class = " text-decoration-none " href = " http://uoj.ac/blog/7 " > UOJ 博客使用教程 </ a > 。
</ p >
</ div >
</ div >
2016-07-18 16:39:37 +00:00
< ? php echoUOJPageFooter () ?>