Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xenice committed Feb 28, 2021
1 parent 0ed120b commit 5aa2613
Show file tree
Hide file tree
Showing 108 changed files with 3,547 additions and 1,604 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ MVC分层架构,层次分明,扩展更灵活、维护更方便;

### 更新说明

**最后更新:2020.09.28**
**最后更新:2021.02.28**

v2.1.8
- 修复若干BUG;
- 忧化核心代码;
- 增加些许常用功能;

v2.0.7

Expand Down
76 changes: 49 additions & 27 deletions app/web/Loader.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
<?php
namespace app\web;

use xenice\theme\Route;
use xenice\option\Option;
use xenice\optimize\Optimize;
use xenice\mail\Mail;
use app\web\widget\Widget;
use app\web\action\SeoAction;
use app\web\action\AdminAction;
use app\web\action\GuestAction;
use app\web\ajax\Ajax;
use app\web\about\About;
use xenice\theme\Theme;

class Loader extends \xenice\theme\Loader
{
public function __construct()
public function __construct($args = [])
{
parent::__construct();
Widget::instance();
Optimize::instance();
Mail::instance();
About::instance();
Ajax::instance();
if(is_admin()){
Option::instance();
take('enable_article_seo') && SeoAction::instance();
AdminAction::instance();

}
else{
GuestAction::instance();
Route::instance();
}
Theme::alias([
// model
'user' => '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();

}

}
2 changes: 0 additions & 2 deletions app/web/controller/ArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 2 additions & 5 deletions app/web/controller/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
2 changes: 0 additions & 2 deletions app/web/controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions app/web/controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
17 changes: 8 additions & 9 deletions app/web/controller/SingleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@

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;
else
$this->title = $article->title() . ' - ' . $this->option->info['name'];
$this->description = $article->description();
$this->keywords = $article->keywords();
$this->render();
$this->render($view);
}

public function scripts()
Expand All @@ -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 .= '<script>hljs.initHighlightingOnLoad();hljs.initLineNumbersOnLoad();</script>';
if(take('enable_highlight')){
$footer .= '<script>hljs.initHighlightingOnLoad();hljs.initLineNumbersOnLoad();</script>';
}
return $footer;
}
}
35 changes: 17 additions & 18 deletions app/web/model/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,16 @@ 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)
{
return $this->since($date);
}

public function alterThumbnail($src, $p)
{
if(!$src){
preg_match_all( '/\<img.+?src="(.+?)".*?\/>/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 . ' ';
Expand All @@ -61,4 +44,20 @@ public function alterViews($count)
return $count . ' ' . _t('view');
}
}

public function alterThumbnail($src, $p)
{
if(!$src){
preg_match_all( '/\<img.+?src="(.+?)".*?\/>/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;
}
}
}
9 changes: 8 additions & 1 deletion app/web/model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<a class="breadcrumb-item" href="'. home_url() .'">'._t('Home').'</a>';
$str .= '<a class="breadcrumb-item" href="'. $this->url() .'">'.$this->title().'</a>';
return $str;
}
}
16 changes: 13 additions & 3 deletions app/web/model/pointer/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ 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')
{
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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions app/web/about/About.php → app/web/module/About.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace app\web\about;
namespace app\web\module;

use xenice\theme\Base;
use xenice\theme\Theme;

class About extends Base
class About
{
public function __construct()
{
Expand All @@ -19,9 +19,10 @@ public function set($options)
$defaults = [];
$defaults[] = [
'id'=>'about',
'pos'=>1000,
'name'=> _t('About'),
'title'=> _t('About the theme'),
'desc'=> sprintf(_t('Thank you for using <a href="http://www.xenice.com/" target="_blank">%s</a> theme.'),THEME_NAME),
'desc'=> sprintf(_t('Thank you for using <a href="https://www.xenice.com/" target="_blank">%s</a> theme.'),THEME_NAME),
'fields'=>[
[
'id' => 'about_version',
Expand All @@ -33,7 +34,7 @@ public function set($options)
'id' => 'about_official_website',
'type' => 'label',
'name' => _t('Official website'),
'value' => '<a href="http://www.xenice.com/" target="_blank">http://www.xenice.com/</a>',
'value' => '<a href="https://www.xenice.com/" target="_blank">https://www.xenice.com/</a>',
],
]
];
Expand Down
6 changes: 2 additions & 4 deletions app/web/action/SeoAction.php → app/web/module/Seo.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

namespace app\web\action;
namespace app\web\module;

use xenice\theme\Action;

class SeoAction extends Action
class Seo
{
public function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace app\web\action;
namespace app\web\module\inner;

class AdminAction extends GlobalAction
class Admin extends Base
{
public function __construct()
{
Expand Down
Loading

0 comments on commit 5aa2613

Please sign in to comment.