mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-08 13:38:41 +00:00
feat(web): add a new way to access blog
We add a new way to access blog page. Now there are 3. The switch now uses number to choose the way. 1 is for subdomain and 3 is for subfolder. 2 is for separated blog domain with its subfolder. For example, mike's link is blog.xxx.xxx/mike. Blog list page link on navbar will change by domain mode.
This commit is contained in:
parent
0854940fe0
commit
2156cdffef
@ -52,6 +52,6 @@ return [
|
||||
],
|
||||
'switch' => [
|
||||
'web-analytics' => false,
|
||||
'blog-use-subdomain' => false
|
||||
'blog-domain-mode' => 3
|
||||
]
|
||||
];
|
||||
|
@ -2,16 +2,32 @@
|
||||
|
||||
call_user_func(function() { // to prevent variable scope leak
|
||||
|
||||
Route::pattern('id', '[1-9][0-9]{0,9}');
|
||||
Route::pattern('blog_username', '[a-zA-Z0-9_\-]{1,20}');
|
||||
|
||||
if (UOJConfig::$data['switch']['blog-use-subdomain']) {
|
||||
switch (UOJConfig::$data['switch']['blog-domain-mode']) {
|
||||
case 1:
|
||||
$domain = '{blog_username}.'.UOJConfig::$data['web']['blog']['host'];
|
||||
$prefix = '';
|
||||
} else {
|
||||
break;
|
||||
case 2:
|
||||
$domain = UOJConfig::$data['web']['blog']['host'];
|
||||
$prefix = '/{blog_username}';
|
||||
break;
|
||||
case 3:
|
||||
$domain = UOJConfig::$data['web']['main']['host'];
|
||||
$prefix = '/blog/{blog_username}';
|
||||
break;
|
||||
}
|
||||
|
||||
Route::group([
|
||||
'domain' => UOJConfig::$data['web']['blog']['host']
|
||||
], function() {
|
||||
Route::any("/", '/blogs.php');
|
||||
Route::any("/blogs/{id}", '/blog_show.php');
|
||||
Route::any("/post/{id}", '/blog_show.php');
|
||||
}
|
||||
);
|
||||
Route::group([
|
||||
'domain' => $domain,
|
||||
'onload' => function() {
|
||||
|
@ -43,15 +43,38 @@ class HTML {
|
||||
}
|
||||
|
||||
public static function blog_url($username, $uri) {
|
||||
$port = UOJConfig::$data['web']['blog']['port'] == 80 ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
if (UOJConfig::$data['switch']['blog-use-subdomain'])
|
||||
switch (UOJConfig::$data['switch']['blog-domain-mode']) {
|
||||
case 1:
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.blog_name_encode($username).'.'.UOJConfig::$data['web']['blog']['host'].$port;
|
||||
else
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port.'/blog/'.blog_name_encode($username);
|
||||
break;
|
||||
case 2:
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port.'/'.blog_name_encode($username);
|
||||
break;
|
||||
case 3:
|
||||
$port = ((UOJConfig::$data['web']['main']['protocol'] === "http" && UOJConfig::$data['web']['main']['port'] == 80) || (UOJConfig::$data['web']['main']['protocol'] === "https" && UOJConfig::$data['web']['main']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['main']['port']);
|
||||
$url = UOJConfig::$data['web']['main']['protocol'].'://'.UOJConfig::$data['web']['main']['host'].$port.'/blog/'.blog_name_encode($username);
|
||||
break;
|
||||
}
|
||||
$url .= $uri;
|
||||
$url = rtrim($url, '/');
|
||||
return HTML::escape($url);
|
||||
}
|
||||
public static function blog_list_url() {
|
||||
switch (UOJConfig::$data['switch']['blog-domain-mode']) {
|
||||
case 1:
|
||||
case 2:
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port;
|
||||
break;
|
||||
case 3:
|
||||
$port = ((UOJConfig::$data['web']['main']['protocol'] === "http" && UOJConfig::$data['web']['main']['port'] == 80) || (UOJConfig::$data['web']['main']['protocol'] === "https" && UOJConfig::$data['web']['main']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['main']['port']);
|
||||
$url = UOJConfig::$data['web']['main']['protocol'].'://'.UOJConfig::$data['web']['main']['host'].$port.'/blogs';
|
||||
break;
|
||||
}
|
||||
return HTML::escape(rtrim($url, '/'));
|
||||
}
|
||||
|
||||
public static function url($uri, $config = array()) {
|
||||
$config = array_merge(array(
|
||||
|
@ -39,7 +39,7 @@ Route::group([
|
||||
Route::any('/hack/{id}', '/hack.php');
|
||||
|
||||
Route::any('/blogs', '/blogs.php');
|
||||
if (UOJConfig::$data['switch']['blog-use-subdomain']) {
|
||||
if (UOJConfig::$data['switch']['blog-domain-mode'] != 3) {
|
||||
Route::any('/blog/{id}', '/blog_show.php');
|
||||
}
|
||||
Route::any('/blogs/{id}', '/blog_show.php');
|
||||
|
@ -20,4 +20,5 @@
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var uojBlogUrl = '<?= HTML::blog_url(UOJContext::userid(), '')?>';
|
||||
var zan_link = uojBlogUrl;
|
||||
</script>
|
@ -10,13 +10,16 @@
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/contests"><?= UOJLocale::get('contests') ?></a></li>
|
||||
<li><a href="/problems"><?= UOJLocale::get('problems') ?></a></li>
|
||||
<li><a href="/submissions"><?= UOJLocale::get('submissions') ?></a></li>
|
||||
<li><a href="/hacks"><?= UOJLocale::get('hacks') ?></a></li>
|
||||
<li><a href="/blogs"><?= UOJLocale::get('blogs') ?></a></li>
|
||||
<li><a href="/faq"><?= UOJLocale::get('help') ?></a></li>
|
||||
<li><a href="<?= HTML::url('/contests') ?>"><?= UOJLocale::get('contests') ?></a></li>
|
||||
<li><a href="<?= HTML::url('/problems') ?>"><?= UOJLocale::get('problems') ?></a></li>
|
||||
<li><a href="<?= HTML::url('/submissions') ?>"><?= UOJLocale::get('submissions') ?></a></li>
|
||||
<li><a href="<?= HTML::url('/hacks') ?>"><?= UOJLocale::get('hacks') ?></a></li>
|
||||
<li><a href="<?= HTML::blog_list_url() ?>"><?= UOJLocale::get('blogs') ?></a></li>
|
||||
<li><a href="<?= HTML::url('/faq') ?>"><?= UOJLocale::get('help') ?></a></li>
|
||||
</ul>
|
||||
</div><!--/.nav-collapse -->
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var zan_link = '';
|
||||
</script>
|
@ -295,7 +295,7 @@ $.fn.uoj_blog_tag = function() {
|
||||
function click_zan(zan_id, zan_type, zan_delta, node) {
|
||||
var loading_node = $('<div class="text-muted">loading...</div>');
|
||||
$(node).replaceWith(loading_node);
|
||||
$.post('/click-zan', {
|
||||
$.post(zan_link + '/click-zan', {
|
||||
id : zan_id,
|
||||
delta : zan_delta,
|
||||
type : zan_type
|
||||
|
Loading…
Reference in New Issue
Block a user