add Markdown support for site announcement

This commit is contained in:
printempw 2016-12-28 12:53:13 +08:00
parent 886b15de87
commit f31bd85445
6 changed files with 60 additions and 5 deletions

View File

@ -23,6 +23,8 @@ class CheckSessionUserValid
if ($user && $user->getToken() == session('token')) {
// push user instance to repository
app('users')->set($user->uid, $user);
// bind current user to container
app()->instance('user.current', $user);
} else {
// remove sessions & cookies
delete_sessions();

View File

@ -202,6 +202,16 @@ if (! function_exists('bs_custom_copyright')) {
}
}
if (! function_exists('bs_announcement')) {
function bs_announcement()
{
$parser = new Parsedown();
return $parser->text(option('announcement'));
}
}
if (! function_exists('bs_nickname')) {
function bs_nickname(\App\Models\User $user)

View File

@ -8,7 +8,8 @@
"gregwar/captcha": "^1.1",
"devitek/yaml-translation": "^2.0",
"filp/whoops": "^2.1",
"swiggles/memcache": "^2.0"
"swiggles/memcache": "^2.0",
"erusev/parsedown": "^1.6"
},
"require-dev": {
"fzaninotto/faker": "~1.4",

46
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "3f60d4698fec917a5fee5854b1ce5fed",
"content-hash": "1440843c226635c446993c00027c50ac",
"hash": "ff0e4c4559e77429c861ab50fedc8687",
"content-hash": "a2a5139be6747c19447f7f1feb023e1c",
"packages": [
{
"name": "classpreloader/classpreloader",
@ -199,6 +199,48 @@
],
"time": "2015-11-06 14:35:42"
},
{
"name": "erusev/parsedown",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "20ff8bbb57205368b4b42d094642a3e52dac85fb"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/erusev/parsedown/20ff8bbb57205368b4b42d094642a3e52dac85fb.zip",
"reference": "20ff8bbb57205368b4b42d094642a3e52dac85fb",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Parsedown": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "Parser for Markdown.",
"homepage": "http://parsedown.org",
"keywords": [
"markdown",
"parser"
],
"time": "2016-11-02 15:56:58"
},
{
"name": "filp/whoops",
"version": "2.1.4",

View File

@ -37,7 +37,7 @@
} ?>
<textarea name="announcement" class="form-control" rows="3">{{ option('announcement') }}</textarea>
<p class="description">站点公告内容不会被转义,因此您可以使用 HTML 进行排版</p>
<p class="description">可使用 Markdown 进行排版</p>
</div><!-- /.box-body -->
<div class="box-footer">

View File

@ -92,7 +92,7 @@
<h3 class="box-title">{{ trans('user.announcement') }}</h3>
</div><!-- /.box-header -->
<div class="box-body">
{!! nl2br(option('announcement')) !!}
{!! bs_announcement() !!}
</div><!-- /.box-body -->
</div>
</div>