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.
This commit is contained in:
Masco Skray 2019-07-12 12:13:30 +08:00
parent 46c8644a6e
commit 0854940fe0
13 changed files with 31 additions and 27 deletions

View File

@ -3,5 +3,5 @@
become404Page(); become404Page();
} }
redirectTo(HTML::blog_url($blog['poster'], $_SERVER["REQUEST_URI"])); redirectTo(HTML::blog_url($blog['poster'], '/post/'.$_GET['id']));
?> ?>

View File

@ -23,7 +23,7 @@ EOD;
<div class="pull-right"> <div class="pull-right">
<div class="btn-group"> <div class="btn-group">
<a href="<?= HTML::blog_url(Auth::id(), '/') ?>" class="btn btn-default btn-sm">我的博客首页</a> <a href="<?= HTML::blog_url(Auth::id(), '/') ?>" class="btn btn-default btn-sm">我的博客首页</a>
<a href="<?= HTML::blog_url(Auth::id(), '/blog/new/write')?>" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit"></span> 写新博客</a> <a href="<?= HTML::blog_url(Auth::id(), '/post/new/write')?>" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit"></span> 写新博客</a>
</div> </div>
</div> </div>
<?php endif ?> <?php endif ?>

View File

@ -543,7 +543,7 @@ EOD;
</div> </div>
<div class="list-group"> <div class="list-group">
<?php foreach ($contest['extra_config']['links'] as $link) { ?> <?php foreach ($contest['extra_config']['links'] as $link) { ?>
<a href="/blog/<?=$link[1]?>" class="list-group-item"><?=$link[0]?></a> <a href="/blogs/<?=$link[1]?>" class="list-group-item"><?=$link[0]?></a>
<?php } ?> <?php } ?>
</div> </div>
</div> </div>

View File

@ -25,7 +25,7 @@
} }
?> ?>
<tr> <tr>
<td><a href="/blog/<?= $blog['id'] ?>"><?= $blog['title'] ?></a><?= $new_tag ?></td> <td><a href="/blogs/<?= $blog['id'] ?>"><?= $blog['title'] ?></a><?= $new_tag ?></td>
<td>by <?= getUserLink($blog['poster']) ?></td> <td>by <?= getUserLink($blog['poster']) ?></td>
<td><small><?= $blog['post_time'] ?></small></td> <td><small><?= $blog['post_time'] ?></small></td>
</tr> </tr>

View File

@ -34,7 +34,7 @@
<div class="col-md-3"> <div class="col-md-3">
<?php if (UOJContext::hasBlogPermission()): ?> <?php if (UOJContext::hasBlogPermission()): ?>
<div class="btn-group btn-group-justified"> <div class="btn-group btn-group-justified">
<a href="<?=HTML::blog_url(UOJContext::userid(), '/blog/new/write')?>" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新博客</a> <a href="<?=HTML::blog_url(UOJContext::userid(), '/post/new/write')?>" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新博客</a>
<a href="<?=HTML::blog_url(UOJContext::userid(), '/slide/new/write')?>" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新幻灯片</a> <a href="<?=HTML::blog_url(UOJContext::userid(), '/slide/new/write')?>" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> 写新幻灯片</a>
</div> </div>
<?php endif ?> <?php endif ?>

View File

@ -29,7 +29,7 @@
global $myUser, $blog, $comment_form; global $myUser, $blog, $comment_form;
$comment = HTML::escape($_POST['comment']); $comment = HTML::escape($_POST['comment']);
list($comment, $referrers) = uojHandleAtSign($comment, "/blog/{$blog['id']}"); list($comment, $referrers) = uojHandleAtSign($comment, "/post/{$blog['id']}");
$esc_comment = DB::escape($comment); $esc_comment = DB::escape($comment);
DB::insert("insert into blogs_comments (poster, blog_id, content, reply_id, post_time, zan) values ('{$myUser['username']}', '{$blog['id']}', '$esc_comment', 0, now(), 0)"); DB::insert("insert into blogs_comments (poster, blog_id, content, reply_id, post_time, zan) values ('{$myUser['username']}', '{$blog['id']}', '$esc_comment', 0, now(), 0)");
@ -92,7 +92,7 @@
global $myUser, $blog, $reply_form; global $myUser, $blog, $reply_form;
$comment = HTML::escape($_POST['reply_comment']); $comment = HTML::escape($_POST['reply_comment']);
list($comment, $referrers) = uojHandleAtSign($comment, "/blog/{$blog['id']}"); list($comment, $referrers) = uojHandleAtSign($comment, "/post/{$blog['id']}");
$reply_id = $_POST['reply_id']; $reply_id = $_POST['reply_id'];

View File

@ -32,7 +32,7 @@
); );
} }
if ($blog && !$blog['is_draft']) { if ($blog && !$blog['is_draft']) {
$blog_editor->blog_url = "/blog/{$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;
} }
@ -55,8 +55,8 @@
deleteBlog($blog['id']); deleteBlog($blog['id']);
insertBlog(array_merge($data, array('is_draft' => 0))); 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'], "/blog/{$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'], "/blog/{$blog['id']}"); $ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
} }
} else { } else {
updateBlog($blog['id'], $data); updateBlog($blog['id'], $data);
@ -65,8 +65,8 @@
insertBlog(array_merge($data, array('is_draft' => $data['is_hidden'] ? 1 : 0))); insertBlog(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['is_hidden']) { if (!$data['is_hidden']) {
$ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/blog/{$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'], "/blog/{$blog['id']}"); $ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
} }
} }
if ($data['tags'] !== $blog['tags']) { if ($data['tags'] !== $blog['tags']) {

View File

@ -9,7 +9,7 @@ call_user_func(function() { // to prevent variable scope leak
$prefix = ''; $prefix = '';
} else { } else {
$domain = UOJConfig::$data['web']['blog']['host']; $domain = UOJConfig::$data['web']['blog']['host'];
$prefix = '/blogof/{blog_username}'; $prefix = '/blog/{blog_username}';
} }
Route::group([ Route::group([
@ -22,11 +22,11 @@ call_user_func(function() { // to prevent variable scope leak
Route::any("$prefix/archive", '/subdomain/blog/archive.php'); Route::any("$prefix/archive", '/subdomain/blog/archive.php');
Route::any("$prefix/aboutme", '/subdomain/blog/aboutme.php'); Route::any("$prefix/aboutme", '/subdomain/blog/aboutme.php');
Route::any("$prefix/click-zan", '/click_zan.php'); Route::any("$prefix/click-zan", '/click_zan.php');
Route::any("$prefix/blog/{id}", '/subdomain/blog/blog.php'); Route::any("$prefix/post/{id}", '/subdomain/blog/blog.php');
Route::any("$prefix/slide/{id}", '/subdomain/blog/slide.php'); Route::any("$prefix/slide/{id}", '/subdomain/blog/slide.php');
Route::any("$prefix/blog/(?:{id}|new)/write", '/subdomain/blog/blog_write.php'); Route::any("$prefix/post/(?:{id}|new)/write", '/subdomain/blog/blog_write.php');
Route::any("$prefix/slide/(?:{id}|new)/write", '/subdomain/blog/slide_write.php'); Route::any("$prefix/slide/(?:{id}|new)/write", '/subdomain/blog/slide_write.php');
Route::any("$prefix/blog/{id}/delete", '/subdomain/blog/blog_delete.php'); Route::any("$prefix/post/{id}/delete", '/subdomain/blog/blog_delete.php');
} }
); );

View File

@ -33,7 +33,7 @@
); );
} }
if ($blog && !$blog['is_draft']) { if ($blog && !$blog['is_draft']) {
$blog_editor->blog_url = "/blog/{$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;
} }
@ -57,7 +57,7 @@
insertSlide(array_merge($data, array('is_draft' => 0))); insertSlide(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'], "/slide/{$blog['id']}/write"); $ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/slide/{$blog['id']}/write");
$ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/blog/{$blog['id']}"); $ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
} }
} else { } else {
updateBlog($blog['id'], $data); updateBlog($blog['id'], $data);

View File

@ -104,7 +104,7 @@ function getContestProblemLink($problem, $contest_id, $problem_title = '!title_o
} }
function getBlogLink($id) { function getBlogLink($id) {
if (validateUInt($id) && $blog = queryBlog($id)) { if (validateUInt($id) && $blog = queryBlog($id)) {
return '<a href="/blog/'.$id.'">'.$blog['title'].'</a>'; return '<a href="/blogs/'.$id.'">'.$blog['title'].'</a>';
} }
} }
function getClickZanBlock($type, $id, $cnt, $val = null) { function getClickZanBlock($type, $id, $cnt, $val = null) {

View File

@ -47,7 +47,7 @@ class HTML {
if (UOJConfig::$data['switch']['blog-use-subdomain']) if (UOJConfig::$data['switch']['blog-use-subdomain'])
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.blog_name_encode($username).'.'.UOJConfig::$data['web']['blog']['host'].$port; $url = UOJConfig::$data['web']['blog']['protocol'].'://'.blog_name_encode($username).'.'.UOJConfig::$data['web']['blog']['host'].$port;
else else
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port.'/blogof/'.blog_name_encode($username); $url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port.'/blog/'.blog_name_encode($username);
$url .= $uri; $url .= $uri;
$url = rtrim($url, '/'); $url = rtrim($url, '/');
return HTML::escape($url); return HTML::escape($url);

View File

@ -39,7 +39,11 @@ Route::group([
Route::any('/hack/{id}', '/hack.php'); Route::any('/hack/{id}', '/hack.php');
Route::any('/blogs', '/blogs.php'); Route::any('/blogs', '/blogs.php');
Route::any('/blog/{id}', '/blog_show.php'); if (UOJConfig::$data['switch']['blog-use-subdomain']) {
Route::any('/blog/{id}', '/blog_show.php');
}
Route::any('/blogs/{id}', '/blog_show.php');
Route::any('/post/{id}', '/blog_show.php');
Route::any('/announcements', '/announcements.php'); Route::any('/announcements', '/announcements.php');

View File

@ -2,7 +2,7 @@
if ($is_preview) { if ($is_preview) {
$readmore_pos = strpos($blog['content'], '<!-- readmore -->'); $readmore_pos = strpos($blog['content'], '<!-- readmore -->');
if ($readmore_pos !== false) { if ($readmore_pos !== false) {
$content = substr($blog['content'], 0, $readmore_pos).'<p><a href="'.HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id']).'">阅读更多……</a></p>'; $content = substr($blog['content'], 0, $readmore_pos).'<p><a href="'.HTML::blog_url(UOJContext::userid(), '/post/'.$blog['id']).'">阅读更多……</a></p>';
} else { } else {
$content = $blog['content']; $content = $blog['content'];
} }
@ -12,14 +12,14 @@
$extra_text = $blog['is_hidden'] ? '<span class="text-muted">[已隐藏]</span> ' : ''; $extra_text = $blog['is_hidden'] ? '<span class="text-muted">[已隐藏]</span> ' : '';
$blog_type = $blog['type'] == 'B' ? 'blog' : 'slide'; $blog_type = $blog['type'] == 'B' ? 'post' : 'slide';
?> ?>
<h2><?= $extra_text ?><a class="header-a" href="<?= HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id']) ?>"><?= $blog['title'] ?></a></h2> <h2><?= $extra_text ?><a class="header-a" href="<?= HTML::blog_url(UOJContext::userid(), '/post/'.$blog['id']) ?>"><?= $blog['title'] ?></a></h2>
<div><?= $blog['post_time'] ?> <strong>By</strong> <?= getUserLink($blog['poster']) ?></div> <div><?= $blog['post_time'] ?> <strong>By</strong> <?= getUserLink($blog['poster']) ?></div>
<?php if (!$show_title_only): ?> <?php if (!$show_title_only): ?>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<?php if ($blog_type == 'blog'): ?> <?php if ($blog_type == 'post'): ?>
<article><?= $content ?></article> <article><?= $content ?></article>
<?php elseif ($blog_type == 'slide'): ?> <?php elseif ($blog_type == 'slide'): ?>
<article> <article>
@ -40,11 +40,11 @@
<?php endforeach ?> <?php endforeach ?>
</li> </li>
<?php if ($is_preview): ?> <?php if ($is_preview): ?>
<li><a href="<?= HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id']) ?>">阅读全文</a></li> <li><a href="<?= HTML::blog_url(UOJContext::userid(), '/post/'.$blog['id']) ?>">阅读全文</a></li>
<?php endif ?> <?php endif ?>
<?php if (Auth::check() && (isSuperUser(Auth::user()) || Auth::id() == $blog['poster'])): ?> <?php if (Auth::check() && (isSuperUser(Auth::user()) || Auth::id() == $blog['poster'])): ?>
<li><a href="<?=HTML::blog_url(UOJContext::userid(), '/'.$blog_type.'/'.$blog['id'].'/write')?>">修改</a></li> <li><a href="<?=HTML::blog_url(UOJContext::userid(), '/'.$blog_type.'/'.$blog['id'].'/write')?>">修改</a></li>
<li><a href="<?=HTML::blog_url(UOJContext::userid(), '/blog/'.$blog['id'].'/delete')?>">删除</a></li> <li><a href="<?=HTML::blog_url(UOJContext::userid(), '/post/'.$blog['id'].'/delete')?>">删除</a></li>
<?php endif ?> <?php endif ?>
<li><?= getClickZanBlock('B', $blog['id'], $blog['zan']) ?></li> <li><?= getClickZanBlock('B', $blog['id'], $blog['zan']) ?></li>
</ul> </ul>