diff --git a/README.md b/README.md index 38ee679..dfb9fa8 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,12 @@ MVC分层架构,层次分明,扩展更灵活、维护更方便; ### 更新说明 -**最后更新:2020.09.28** +**最后更新:2021.02.28** + +v2.1.8 +- 修复若干BUG; +- 忧化核心代码; +- 增加些许常用功能; v2.0.7 diff --git a/app/web/Loader.php b/app/web/Loader.php index f2f8b11..e8b1682 100644 --- a/app/web/Loader.php +++ b/app/web/Loader.php @@ -1,37 +1,59 @@ 'app\web\model\User', + 'article' => 'app\web\model\Article', + 'page' => 'app\web\model\Page', + 'category' => 'app\web\model\Category', + 'tag' => 'app\web\model\Tag', + 'comment' => 'app\web\model\Comment', + + // pointer + 'article_pointer' => 'app\web\model\pointer\Article', + 'page_pointer' => 'app\web\model\pointer\Page', + 'category_pointer' => 'app\web\model\pointer\Category', + 'comment_pointer' => 'app\web\model\pointer\Comment', + 'user_pointer' => 'app\web\model\pointer\User', + + ]); + + isset($args['aliases']) && Theme::alias($args['aliases']); + + parent::__construct(); + + $prepares = [ + 10 => 'app\web\widget\Widget', + 20 => 'xenice\optimize\Optimize', + 30 => 'xenice\mail\Mail', + //40 => 'xenice\profession\Profession', + 50 => 'app\web\module\About', + 60 => 'app\web\ajax\Ajax', + ]; + + if(is_admin()){ + $prepares[70] = 'xenice\option\Option'; + take('enable_article_seo') && $prepares[80] = 'app\web\module\Seo'; + $prepares[90] = 'app\web\module\inner\Admin'; + } + else{ + $prepares[100] = 'app\web\module\inner\Guest'; + $prepares[110] = 'xenice\theme\Route'; + } + + Theme::prepare($prepares); + + isset($args['prepares']) && Theme::prepare($args['prepares']); + + Theme::execute(); + } } \ No newline at end of file diff --git a/app/web/controller/ArchiveController.php b/app/web/controller/ArchiveController.php index f991051..427f2e4 100644 --- a/app/web/controller/ArchiveController.php +++ b/app/web/controller/ArchiveController.php @@ -3,8 +3,6 @@ namespace app\web\controller; use xenice\theme\Controller; -use app\web\model\Category; -use app\web\model\Tag; class ArchiveController extends Controller { diff --git a/app/web/controller/CategoryController.php b/app/web/controller/CategoryController.php index bb7a6c7..13acbab 100644 --- a/app/web/controller/CategoryController.php +++ b/app/web/controller/CategoryController.php @@ -3,19 +3,16 @@ namespace app\web\controller; use xenice\theme\Controller; -use app\web\model\Category; -use app\web\model\Tag; class CategoryController extends Controller { - public function index() + public function index($view = 'index') { - $this->title = single_cat_title('', false) . ' - ' . get_bloginfo( 'name' ); $this->keywords = single_cat_title( '', false ); $this->description = category_description(); - $this->render(); + $this->render($view); } } \ No newline at end of file diff --git a/app/web/controller/HomeController.php b/app/web/controller/HomeController.php index 398ef95..5c9fdbe 100644 --- a/app/web/controller/HomeController.php +++ b/app/web/controller/HomeController.php @@ -3,8 +3,6 @@ namespace app\web\controller; use xenice\theme\Controller; -use app\web\model\Article; -//use app\web\model\Tag; class HomeController extends Controller { diff --git a/app/web/controller/PageController.php b/app/web/controller/PageController.php index d77da10..504c3b8 100644 --- a/app/web/controller/PageController.php +++ b/app/web/controller/PageController.php @@ -2,14 +2,14 @@ namespace app\web\controller; +use xenice\theme\Theme; use xenice\theme\Controller; -use app\web\model\Page; class PageController extends Controller { public function index() { $this->title = $this->page->title() . ' - ' . $this->option->info['name']; - $this->render(Page::template()); + $this->render(Theme::use('page')->template()); } } \ No newline at end of file diff --git a/app/web/controller/SingleController.php b/app/web/controller/SingleController.php index b6a2d29..ef21d94 100644 --- a/app/web/controller/SingleController.php +++ b/app/web/controller/SingleController.php @@ -4,18 +4,15 @@ use xenice\theme\Theme; use xenice\theme\Controller; -use app\web\model\Category; -use app\web\model\Article; -use app\web\model\User; class SingleController extends Controller { - public function index() + public function index($view = 'index') { Theme::bind('footer', [$this, 'footer']); add_action( 'wp_enqueue_scripts', [$this, 'scripts']); //add_action( 'wp_print_scripts', [$this, 'footer']); - $article = Article::instance(); + $article = Theme::use('article'); $article->setViews(); if(take('enable_article_seo') && $title = $article->get('title')) $this->title = $title; @@ -23,7 +20,7 @@ public function index() $this->title = $article->title() . ' - ' . $this->option->info['name']; $this->description = $article->description(); $this->keywords = $article->keywords(); - $this->render(); + $this->render($view); } public function scripts() @@ -46,17 +43,19 @@ public function scripts() if($cdn){ wp_enqueue_style('share-css', $cdn_url . '/social-share.js/1.0.16/css/share.min.css', [], '1.0.16'); - wp_enqueue_script('share-js', $cdn_url . '/social-share.js/1.0.16/js/social-share.min.js', [], '1.0.16', true); + wp_enqueue_script('share-js', $cdn_url . '/social-share.js/1.0.16/js/jquery.share.min.js', [], '1.0.16', true); } else{ wp_enqueue_style('share-css', STATIC_URL . '/lib/share/css/share.min.css', [], '1.0.16'); - wp_enqueue_script('share-js', STATIC_URL . '/lib/share/js/social-share.min.js', [], '1.0.16', true); + wp_enqueue_script('share-js', STATIC_URL . '/lib/share/js/jquery.share.min.js', [], '1.0.16', true); } } public function footer($footer) { - $footer .= ''; + if(take('enable_highlight')){ + $footer .= ''; + } return $footer; } } \ No newline at end of file diff --git a/app/web/model/Article.php b/app/web/model/Article.php index c09ee40..3a68726 100644 --- a/app/web/model/Article.php +++ b/app/web/model/Article.php @@ -13,10 +13,9 @@ public function __construct() { parent::__construct(); Theme::bind('article_date',[$this, 'alterDate']); - Theme::bind('article_thumbnail',[$this, 'alterThumbnail']); Theme::bind('article_comments',[$this, 'alterComments']); Theme::bind('article_views',[$this, 'alterViews']); - + take('first_image_thumbnail') && Theme::bind('article_thumbnail',[$this, 'alterThumbnail']); } public function alterDate($date) @@ -24,22 +23,6 @@ public function alterDate($date) return $this->since($date); } - public function alterThumbnail($src, $p) - { - if(!$src){ - preg_match_all( '/\/is', $p->row('post_content'), $matches, PREG_SET_ORDER ); - if(isset($matches[0][1])){ - return $matches[0][1]; - } - else{ - return STATIC_URL . '/images/thumbnail.png'; - } - } - else{ - return $src; - } - } - public function alterComments($count, $p) { $comments = $count . ' '; @@ -61,4 +44,20 @@ public function alterViews($count) return $count . ' ' . _t('view'); } } + + public function alterThumbnail($src, $p) + { + if(!$src){ + preg_match_all( '/\/is', $p->row('post_content'), $matches, PREG_SET_ORDER ); + if(isset($matches[0][1])){ + return $matches[0][1]; + } + else{ + return take('default_thumbnail'); + } + } + else{ + return $src; + } + } } \ No newline at end of file diff --git a/app/web/model/Page.php b/app/web/model/Page.php index 5ea6e61..905aa3a 100644 --- a/app/web/model/Page.php +++ b/app/web/model/Page.php @@ -6,8 +6,15 @@ class Page extends PageModel { - protected function template() + public function template() { return get_post_meta($this->id(),'_wp_page_template',true)?:'default'; } + + public function breadcrumb() + { + $str = ''._t('Home').''; + $str .= ''.$this->title().''; + return $str; + } } \ No newline at end of file diff --git a/app/web/model/pointer/Article.php b/app/web/model/pointer/Article.php index e9c6c7c..10a72b3 100644 --- a/app/web/model/pointer/Article.php +++ b/app/web/model/pointer/Article.php @@ -24,7 +24,10 @@ public function curl() public function category($field = 'name') { - return get_term($this->cid(), $this->taxonomy())->$field; + $obj = get_term($this->cid(), $this->taxonomy()); + if(!is_wp_error($obj)){ + return $obj->$field; + } } public function user($field = 'display_name') @@ -32,6 +35,11 @@ public function user($field = 'display_name') return get_the_author_meta( $field, $this->uid()); } + public function avatar($size = 32) + { + return get_avatar( $this->user('user_email'), $size, '', '', ['class'=>'rounded-circle']); + } + public function views() { return Theme::call('article_views', $this->get('views')?:0); @@ -48,7 +56,9 @@ public function description($limit = 180) if(!$excerpt){ $excerpt = $this->row('post_content'); } - $excerpt = preg_replace( "/\[.*?\].*?\[\/.*?\]/is", "", $excerpt); + $pattern = '\[(\[?)([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)'; + $excerpt = preg_replace("/$pattern/", '', $excerpt); + //$excerpt = preg_replace( "/\[.*?\].*?\[\/.*?\]/is", "", $excerpt); $excerpt = mb_strimwidth( strip_tags( $excerpt), 0, $limit, "..." ); return $excerpt; } @@ -85,7 +95,7 @@ public function thumbnail($type = 'full') if (has_post_thumbnail()){ $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->id()), $type); $src = $attachment[0]; - } + } return Theme::call('article_thumbnail', $src, $this); } diff --git a/app/web/about/About.php b/app/web/module/About.php similarity index 82% rename from app/web/about/About.php rename to app/web/module/About.php index 7fe9b94..73a1ec3 100644 --- a/app/web/about/About.php +++ b/app/web/module/About.php @@ -1,10 +1,10 @@ 'about', + 'pos'=>1000, 'name'=> _t('About'), 'title'=> _t('About the theme'), - 'desc'=> sprintf(_t('Thank you for using %s theme.'),THEME_NAME), + 'desc'=> sprintf(_t('Thank you for using %s theme.'),THEME_NAME), 'fields'=>[ [ 'id' => 'about_version', @@ -33,7 +34,7 @@ public function set($options) 'id' => 'about_official_website', 'type' => 'label', 'name' => _t('Official website'), - 'value' => 'http://www.xenice.com/', + 'value' => 'https://www.xenice.com/', ], ] ]; diff --git a/app/web/action/SeoAction.php b/app/web/module/Seo.php similarity index 95% rename from app/web/action/SeoAction.php rename to app/web/module/Seo.php index 42834e2..69fd12c 100644 --- a/app/web/action/SeoAction.php +++ b/app/web/module/Seo.php @@ -1,10 +1,8 @@ registerMenus(); $this->registerSidebars(); // Register theme languages files - - - add_action('init', [$this, 'enableSession']); + add_theme_support( 'post-thumbnails' ); add_image_size( 'index-thumbnail', 250, 250, true ); } + + public function scripts() + { + $scripts = $this->addScripts(); + + ksort($scripts['css']); + foreach($scripts['css'] as $arr){ + call_user_func_array('wp_enqueue_style', $arr); + } + + ksort($scripts['js']); + foreach($scripts['js'] as $arr){ + call_user_func_array('wp_enqueue_script', $arr); + } + } + + public function addScripts() + { + return ['css'=>[], 'js'=>[]]; + } public function login() { @@ -30,15 +48,6 @@ public function login() } } - - - public function enableSession() - { - if(!session_id()){ - session_start(); - } - } - private function registerMenus() { register_nav_menus([ diff --git a/app/web/action/GuestAction.php b/app/web/module/inner/Guest.php similarity index 51% rename from app/web/action/GuestAction.php rename to app/web/module/inner/Guest.php index f611355..80f1ed6 100644 --- a/app/web/action/GuestAction.php +++ b/app/web/module/inner/Guest.php @@ -1,62 +1,96 @@ loginScripts(); - Theme::bind('head', [$this, 'customColor']); + Theme::bind('head', [$this, 'head']); Theme::bind('footer', [$this, 'footer']); - add_action( 'wp_enqueue_scripts', [$this, 'scripts']); - add_filter('body_class',[$this, 'customClasses']); } - public function customColor($head) + public function head($head) { - $color = explode(' ', take('color')); - Theme::use('template')->color = $color; - list($a1, $a2, $b1, $b2, $b3, $b4) = $color; + $colors = explode(' ', take('color')); + Theme::use('template')->colors = $colors; + $head .= ''; return $head; } + public function customColor($colors) + { + list($a1, $a2, $b1, $b2, $b3, $b4) = $colors; + $styles = [ + 'a:hover'=>"{color:$a1;}", + '.breadcrumb a:hover'=>"{color:$a2;}", + '.btn-custom,.badge-custom'=>"{color:$b3!important;background-color:$b1;border-color:$b1;}", + '.btn-custom:hover,.badge-custom:hover'=>"{color:$b3;background-color:$b2;border-color:$b2}", + '.form-control:focus'=>"{border-color: $b4!important;}", + + '.navbar-nav .current-menu-item a'=>"{color:$a1}", + '.fa-search:hover'=>"{color:$a2;}", + '.user-login .nav-item .nav-link'=>"{color:$b4;}", + '.user-login .nav-item .active'=>"{color:$a2;}", + '.post-content a'=>"{color:$a1;}", + '.post-content a:hover'=>"{color:$b2;}", + '.rollbar .rollbar-item:hover'=>"{background-color: $b4;}", + + '.fa-weixin'=>"{color:#7BD172}", + '.fa-qq'=>"{color:#f67585}", + '.fa-weibo'=>"{color:#ff8d8d}", + ]; + return $styles; + } + public function scripts() { wp_dequeue_style( 'wp-block-library' ); wp_deregister_script( 'jquery' ); + parent::scripts(); + } + + public function addScripts() + { + $scripts = parent::addScripts(); + if(take('enable_cdn')){ $cdn_url = take('cdn_url'); - wp_enqueue_style( 'font-awesome', $cdn_url . '/font-awesome/4.7.0/css/font-awesome.min.css', [], '4.7.0'); - wp_enqueue_style( 'bootstrap-css', $cdn_url . '/twitter-bootstrap/4.4.1/css/bootstrap.min.css', [], '4.4.1'); + $scripts['css'][10] = ['font-awesome', $cdn_url . '/font-awesome/4.7.0/css/font-awesome.min.css', [], '4.7.0']; + $scripts['css'][20] = ['bootstrap-css', $cdn_url . '/twitter-bootstrap/4.4.1/css/bootstrap.min.css', [], '4.4.1']; - wp_enqueue_script( 'jquery', $cdn_url . '/jquery/3.2.1/jquery.min.js', [], '3.2.1',true); - wp_enqueue_script( 'popper', $cdn_url . '/popper.js/1.15.0/umd/popper.min.js', [], '1.15.0',true); - wp_enqueue_script( 'bootstrap-js', $cdn_url . '/twitter-bootstrap/4.4.1/js/bootstrap.min.js', [], '4.4.1',true); - wp_enqueue_script( 'gifffer', $cdn_url . '/gifffer/1.5.0/gifffer.min.js', [], '1.5.0',true); + $scripts['js'][10] = ['jquery', $cdn_url . '/jquery/3.2.1/jquery.min.js', [], '3.2.1',true]; + $scripts['js'][20] = ['popper', $cdn_url . '/popper.js/1.15.0/umd/popper.min.js', [], '1.15.0',true]; + $scripts['js'][30] = ['bootstrap-js', $cdn_url . '/twitter-bootstrap/4.4.1/js/bootstrap.min.js', [], '4.4.1',true]; + $scripts['js'][40] = ['gifffer', $cdn_url . '/gifffer/1.5.0/gifffer.min.js', [], '1.5.0',true]; } else{ - wp_enqueue_style( 'font-awesome', STATIC_URL . '/css/font-awesome.min.css', [], '4.7.0'); - wp_enqueue_style( 'bootstrap-css', STATIC_URL. '/lib/bootstrap/css/bootstrap.min.css', [], '4.4.1'); + $scripts['css'][30] = ['font-awesome', STATIC_URL . '/css/font-awesome.min.css', [], '4.7.0']; + $scripts['css'][40] = ['bootstrap-css', STATIC_URL. '/lib/bootstrap/css/bootstrap.min.css', [], '4.4.1']; - wp_enqueue_script( 'jquery', STATIC_URL. '/lib/jquery/jquery.min.js', [], '3.2.1',true); - wp_enqueue_script( 'popper', STATIC_URL. '/lib/popper/popper.min.js', [], '1.15.0',true); - wp_enqueue_script( 'bootstrap-js', STATIC_URL. '/lib/bootstrap/js/bootstrap.min.js', [], '4.4.1',true); - wp_enqueue_script( 'gifffer', STATIC_URL. '/lib/gifffer/gifffer.min.js', [], '1.5.0',true); + $scripts['js'][50] = ['jquery', STATIC_URL. '/lib/jquery/jquery.min.js', [], '3.2.1',true]; + $scripts['js'][60] = ['popper', STATIC_URL. '/lib/popper/popper.min.js', [], '1.15.0',true]; + $scripts['js'][70] = ['bootstrap-js', STATIC_URL. '/lib/bootstrap/js/bootstrap.min.js', [], '4.4.1',true]; + $scripts['js'][80] = ['gifffer', STATIC_URL. '/lib/gifffer/gifffer.min.js', [], '1.5.0',true]; } - wp_enqueue_style( 'style', STATIC_URL . '/css/style.css', [], THEME_VER); - wp_enqueue_script('lazyload', STATIC_URL . '/lib/lazyload/lazyload.min.js', [], '2.0.0', true); - wp_enqueue_script( 'xenice', STATIC_URL . '/js/xenice.js', [], THEME_VER,true); - wp_enqueue_script( 'login', STATIC_URL . '/js/login.js', [], THEME_VER,true); + $scripts['css'][50] = ['style', STATIC_URL . '/css/style.css', [], THEME_VER]; + $scripts['js'][90] = ['lazyload', STATIC_URL . '/lib/lazyload/lazyload.min.js', [], '2.0.0', true]; + $scripts['js'][100] = ['xenice', STATIC_URL . '/js/xenice.js', [], THEME_VER,true]; + $scripts['js'][110] = ['login', STATIC_URL . '/js/login.js', [], THEME_VER,true]; + return $scripts; } private function loginScripts() @@ -130,14 +164,4 @@ public function footer($footer) take('baidu_auto_push') && $footer .= take('baidu_auto_push'); return $footer; } - - function customClasses($classes) - { - $classes [] = take( 'color' ); - - if( take( 'full-content' ) ){ - $classes [] = 'full-content'; - } - return $classes; - } } \ No newline at end of file diff --git a/app/web/view/cards-thumbnail.php b/app/web/view/cards-thumbnail.php index e1a66c2..f50f1c5 100644 --- a/app/web/view/cards-thumbnail.php +++ b/app/web/view/cards-thumbnail.php @@ -3,7 +3,7 @@
- <?=$p->title()?> + <?=$p->title()?>

diff --git a/app/web/view/footer.php b/app/web/view/footer.php index 7790f4a..b98fcfc 100644 --- a/app/web/view/footer.php +++ b/app/web/view/footer.php @@ -1,17 +1,16 @@ diff --git a/app/web/view/header.php b/app/web/view/header.php index 4b48892..be9fece 100644 --- a/app/web/view/header.php +++ b/app/web/view/header.php @@ -15,7 +15,7 @@