diff --git a/app/Http/Web/Controllers/Controller.php b/app/Http/Web/Controllers/Controller.php index 891b449d..104dd831 100644 --- a/app/Http/Web/Controllers/Controller.php +++ b/app/Http/Web/Controllers/Controller.php @@ -4,16 +4,34 @@ namespace App\Http\Web\Controllers; use App\Caches\NavTreeList as NavTreeListCache; use App\Caches\Setting as SettingCache; +use App\Library\Seo as SiteSeo; use App\Services\Auth\Web as WebAuth; use App\Traits\Response as ResponseTrait; use App\Traits\Security as SecurityTrait; use Phalcon\Mvc\Dispatcher; +use Yansongda\Supports\Collection; class Controller extends \Phalcon\Mvc\Controller { - protected $siteSettings; - protected $navList; + /** + * @var SiteSeo + */ + protected $seo; + + /** + * @var Collection + */ + protected $site; + + /** + * @var Collection + */ + protected $nav; + + /** + * @var Collection + */ protected $authUser; use ResponseTrait, SecurityTrait; @@ -27,8 +45,9 @@ class Controller extends \Phalcon\Mvc\Controller $this->checkRateLimit(); - $this->siteSettings = $this->getSiteSettings(); - $this->navList = $this->getNavList(); + $this->seo = $this->getSiteSeo(); + $this->site = $this->getSiteSettings(); + $this->nav = $this->getNavList(); $this->authUser = $this->getAuthUser(); return true; @@ -36,10 +55,12 @@ class Controller extends \Phalcon\Mvc\Controller public function initialize() { + $this->seo->setTitle($this->site->title); + + $this->view->setVar('seo', $this->seo); + $this->view->setVar('site', $this->site); + $this->view->setVar('nav', $this->nav); $this->view->setVar('auth_user', $this->authUser); - $this->view->setVar('site_settings', $this->siteSettings); - $this->view->setVar('top_nav_list', $this->navList->top); - $this->view->setVar('btm_nav_list', $this->navList->bottom); } protected function getAuthUser() @@ -66,4 +87,9 @@ class Controller extends \Phalcon\Mvc\Controller return $cache->get('site'); } + protected function getSiteSeo() + { + return new SiteSeo(); + } + } diff --git a/app/Http/Web/Controllers/IndexController.php b/app/Http/Web/Controllers/IndexController.php index 3e2e6eb7..816d0724 100644 --- a/app/Http/Web/Controllers/IndexController.php +++ b/app/Http/Web/Controllers/IndexController.php @@ -10,6 +10,9 @@ class IndexController extends Controller */ public function indexAction() { + $this->seo->setKeywords($this->site->keywords); + $this->seo->setDescription($this->site->description); + } diff --git a/app/Http/Web/Views/error/show400.volt b/app/Http/Web/Views/error/show400.volt index 8c8c6597..11e82ff6 100644 --- a/app/Http/Web/Views/error/show400.volt +++ b/app/Http/Web/Views/error/show400.volt @@ -1,5 +1,3 @@ -{{ flashSession.output() }} -
diff --git a/app/Http/Web/Views/error/show401.volt b/app/Http/Web/Views/error/show401.volt index 29fc21d9..2ab4991d 100644 --- a/app/Http/Web/Views/error/show401.volt +++ b/app/Http/Web/Views/error/show401.volt @@ -1,5 +1,3 @@ -{{ flashSession.output() }} -
diff --git a/app/Http/Web/Views/error/show403.volt b/app/Http/Web/Views/error/show403.volt index 01d8620a..283347cd 100644 --- a/app/Http/Web/Views/error/show403.volt +++ b/app/Http/Web/Views/error/show403.volt @@ -1,5 +1,3 @@ -{{ flashSession.output() }} -
diff --git a/app/Http/Web/Views/error/show404.volt b/app/Http/Web/Views/error/show404.volt index de69a356..e97ed0ef 100644 --- a/app/Http/Web/Views/error/show404.volt +++ b/app/Http/Web/Views/error/show404.volt @@ -1,5 +1,3 @@ -{{ flashSession.output() }} -
diff --git a/app/Http/Web/Views/error/show500.volt b/app/Http/Web/Views/error/show500.volt index 89df2944..32f351d9 100644 --- a/app/Http/Web/Views/error/show500.volt +++ b/app/Http/Web/Views/error/show500.volt @@ -1,5 +1,3 @@ -{{ flashSession.output() }} -
diff --git a/app/Http/Web/Views/error/show503.volt b/app/Http/Web/Views/error/show503.volt index daf294ae..638c452d 100644 --- a/app/Http/Web/Views/error/show503.volt +++ b/app/Http/Web/Views/error/show503.volt @@ -1,5 +1,3 @@ -{{ flashSession.output() }} -
diff --git a/app/Http/Web/Views/index.volt b/app/Http/Web/Views/index.volt deleted file mode 100644 index f240b92b..00000000 --- a/app/Http/Web/Views/index.volt +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - {{ site_settings.title }} - {{ icon_link("favicon.ico") }} - {{ css_link("lib/layui/css/layui.css") }} - {{ js_include("lib/layui/layui.js") }} - - -{{ content() }} - - \ No newline at end of file diff --git a/app/Http/Web/Views/index/error404.volt b/app/Http/Web/Views/index/error404.volt deleted file mode 100644 index db06848d..00000000 --- a/app/Http/Web/Views/index/error404.volt +++ /dev/null @@ -1,5 +0,0 @@ - - -

I am home error404 page

diff --git a/app/Http/Web/Views/index/index.volt b/app/Http/Web/Views/index/index.volt index f9343108..3cf49c6a 100644 --- a/app/Http/Web/Views/index/index.volt +++ b/app/Http/Web/Views/index/index.volt @@ -1 +1,21 @@ - \ No newline at end of file +{% extends "templates/base.volt" %} + +{% block content %} + +{% endblock %} + +{% block inline_css %} + +{% endblock %} + +{% block inline_js %} + +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/layouts/error.volt b/app/Http/Web/Views/layouts/error.volt index 368d9e33..5868a3ab 100644 --- a/app/Http/Web/Views/layouts/error.volt +++ b/app/Http/Web/Views/layouts/error.volt @@ -6,10 +6,9 @@ 出错啦 {{ icon_link("favicon.ico") }} {{ css_link("lib/layui/css/layui.css") }} - {{ css_link("web/css/style.css") }} - {{ js_include("lib/layui/layui.js") }} + {{ css_link("web/css/error.css") }} - + {{ content() }} \ No newline at end of file diff --git a/app/Http/Web/Views/templates/base.volt b/app/Http/Web/Views/templates/base.volt new file mode 100644 index 00000000..2ae9fc46 --- /dev/null +++ b/app/Http/Web/Views/templates/base.volt @@ -0,0 +1,21 @@ + + + + + + + + {{ seo.getTitle() }} + {{ icon_link("favicon.ico") }} + {{ css_link("lib/layui/css/layui.css") }} + {{ css_link("web/css/style.css") }} + {% block header_css %}{% endblock %} + {% block inline_css %}{% endblock %} + + +{% block content %}{% endblock %} +{{ js_include("lib/layui/layui.js") }} +{% block footer_js %}{% endblock %} +{% block inline_js %}{% endblock %} + + \ No newline at end of file diff --git a/app/Library/Seo.php b/app/Library/Seo.php new file mode 100644 index 00000000..f7092c89 --- /dev/null +++ b/app/Library/Seo.php @@ -0,0 +1,78 @@ +title = $title; + } + + public function setKeywords($keywords) + { + $this->keywords = $keywords; + } + + public function setDescription($description) + { + $this->description = $description; + } + + public function setTitleSeparator($titleSeparator) + { + $this->titleSeparator = $titleSeparator; + } + + public function appendTitle($text) + { + $this->title = $this->title . $this->titleSeparator . $text; + } + + public function prependTitle($text) + { + $this->title = $text . $this->titleSeparator . $this->title; + } + + public function getTitle() + { + return $this->title; + } + + public function getKeywords() + { + return $this->keywords; + } + + public function getDescription() + { + return $this->description; + } + + public function getTitleSeparator() + { + return $this->titleSeparator; + } + +} diff --git a/app/Providers/Seo.php b/app/Providers/Seo.php new file mode 100644 index 00000000..624573d5 --- /dev/null +++ b/app/Providers/Seo.php @@ -0,0 +1,19 @@ +di->setShared($this->serviceName, function () { + return new AppSeo(); + }); + } + +} \ No newline at end of file diff --git a/app/Providers/Volt.php b/app/Providers/Volt.php index 6a1c5177..b56127a4 100644 --- a/app/Providers/Volt.php +++ b/app/Providers/Volt.php @@ -22,6 +22,10 @@ class Volt extends Provider $compiler = $volt->getCompiler(); + $compiler->addFunction('static_url', function ($resolvedArgs) { + return 'kg_static_url(' . $resolvedArgs . ')'; + }); + $compiler->addFunction('icon_link', function ($resolvedArgs) { return 'kg_icon_link(' . $resolvedArgs . ')'; }); diff --git a/public/static/admin/css/style.css b/public/static/admin/css/style.css index 6b211633..07511011 100644 --- a/public/static/admin/css/style.css +++ b/public/static/admin/css/style.css @@ -38,34 +38,6 @@ color: green; } -.kg-tips { - margin-top: 30px; - text-align: center; -} - -.kg-tips .layui-icon-face-surprised { - display: inline-block; - font-size: 200px; - color: #393D49; -} - -.kg-tips .layui-text { - width: 500px; - margin: 30px auto; - padding-top: 20px; - border-top: 5px solid #009688; -} - -.kg-tips h1 { - font-size: 100px; - line-height: 100px; - color: #009688; -} - -.kg-tips .layui-text span { - display: inline-block; -} - .kg-side-menu-bar { position: absolute; top: 0; diff --git a/public/static/web/css/error.css b/public/static/web/css/error.css new file mode 100644 index 00000000..a696277c --- /dev/null +++ b/public/static/web/css/error.css @@ -0,0 +1,27 @@ +.kg-tips { + margin-top: 30px; + text-align: center; +} + +.kg-tips .layui-icon-face-surprised { + display: inline-block; + font-size: 200px; + color: #393D49; +} + +.kg-tips .layui-text { + width: 500px; + margin: 30px auto; + padding-top: 20px; + border-top: 5px solid #009688; +} + +.kg-tips h1 { + font-size: 100px; + line-height: 100px; + color: #009688; +} + +.kg-tips .layui-text span { + display: inline-block; +} \ No newline at end of file diff --git a/public/static/web/css/style.css b/public/static/web/css/style.css index a696277c..e69de29b 100644 --- a/public/static/web/css/style.css +++ b/public/static/web/css/style.css @@ -1,27 +0,0 @@ -.kg-tips { - margin-top: 30px; - text-align: center; -} - -.kg-tips .layui-icon-face-surprised { - display: inline-block; - font-size: 200px; - color: #393D49; -} - -.kg-tips .layui-text { - width: 500px; - margin: 30px auto; - padding-top: 20px; - border-top: 5px solid #009688; -} - -.kg-tips h1 { - font-size: 100px; - line-height: 100px; - color: #009688; -} - -.kg-tips .layui-text span { - display: inline-block; -} \ No newline at end of file