From 4901b642cd90a9124a4ca5732210707caa030290 Mon Sep 17 00:00:00 2001 From: BigCoke233 Date: Fri, 10 Jul 2020 22:58:49 +0800 Subject: =?UTF-8?q?:zap:=20Perf:=20=E5=85=BC=E5=AE=B9=20typecho=20?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=8F=8D=E5=9E=83=E5=9C=BE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions.php | 93 ++------------------------------------------------- includes/comments.php | 19 +++++------ includes/footer.php | 4 +-- includes/head.php | 4 +-- includes/header.php | 4 +-- libs/Comments.php | 51 ++++++++++++++++++++++++++++ libs/Contents.php | 92 ++++++++++++++++++++++++++++++++++++-------------- libs/Utils.php | 31 +++++++++++++++++ 8 files changed, 166 insertions(+), 132 deletions(-) create mode 100644 libs/Comments.php diff --git a/functions.php b/functions.php index 7b52301..e9e6d79 100644 --- a/functions.php +++ b/functions.php @@ -18,7 +18,7 @@ Typecho_Plugin::factory('admin/write-page.php')->bottom = array('Utils', 'addBut */ function themeInit($archive) { if ($archive->hidden) header('HTTP/1.1 200 OK');//暴力解决访问加密文章会被 pjax 刷新页面的问题 - Helper::options()->commentsAntiSpam = false;//关闭反垃圾 + //Helper::options()->commentsAntiSpam = false; 关闭反垃圾 Helper::options()->commentsHTMLTagAllowed = ' '; Helper::options()->commentsMaxNestingLevels = '9999';//最大嵌套层数 Helper::options()->commentsPageDisplay = 'first';//强制评论第一页 @@ -46,93 +46,4 @@ function themeFields(Typecho_Widget_Helper_Layout $layout) { function themeVersion() { $info = Typecho_Plugin::parseInfo(__DIR__ . '/index.php'); return $info['version']; -} - -/** - * 统计文章浏览数 - * from:http://docs.qqdie.com/ - */ -function get_post_view($archive) { - $cid = $archive->cid; - $db = Typecho_Db::get(); - $prefix = $db->getPrefix(); - if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { - $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;'); - echo 0; - return; - } - $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid)); - if ($archive->is('single')) { - $views = Typecho_Cookie::get('extend_contents_views'); - if(empty($views)){ - $views = array(); - }else{ - $views = explode(',', $views); - } -if(!in_array($cid,$views)){ - $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); -array_push($views, $cid); - $views = implode(',', $views); - Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie - } - } - echo $row['views']; -} -/** - * 自动生成引用 - */ -function generate_require($files,$type,$cdn,$custom) { - if ($cdn=='1'){ - $path = 'https://cdn.jsdelivr.net/gh/BigCoke233/miracles@'.themeVersion()."/assets/"; - } - elseif ($cdn=='2'){ - $path = 'https://raw.githack.com/BigCoke233/miracles/master/assets/'; - } - elseif ($cdn=='4'){ - $path = 'https://rawcdn.githack.com/BigCoke233/miracles/master/assets/'; - } - elseif ($cdn=='5'){ - $path = 'https://cdn.9jojo.cn/Miracles/'.themeVersion().'/'; - } - elseif ($cdn=='3'){ - $path = $custom; - }else{ - $path = Helper::options()->themeUrl("","Miracles/assets"); - } - foreach ($files as $file) { - if ($type == "js"){ - echo ""; - } - elseif ($type == "css"){ - echo ""; - } - } -} - -/** - * 获取上级评论人 - */ - function getCommentHF($coid){ - $db = Typecho_Db::get(); - $prow = $db->fetchRow($db->select('parent') - ->from('table.comments') - ->where('coid = ? AND status = ?', $coid, 'approved')); - $parent = $prow['parent']; - if ($parent != "0") { - $arow = $db->fetchRow($db->select('text','author','status') - ->from('table.comments') - ->where('coid = ?', $parent)); - $author = $arow['author']; - $status = $arow['status']; - if($author){ - if($status=='approved'){ - $href = '@'.$author.'';; - }else if($status=='waiting'){ - $href = '评论审核中···'; - } - } - echo $href; - } else { - echo ""; - } - } \ No newline at end of file +} \ No newline at end of file diff --git a/includes/comments.php b/includes/comments.php index 1b5ace5..b414021 100644 --- a/includes/comments.php +++ b/includes/comments.php @@ -28,7 +28,7 @@ echo $commentClass; reply(''); ?> - coid); echo Contents::parseEmo($comments->content); ?> + coid); echo Contents::parseEmo($comments->content); ?>

author; ?> @@ -63,8 +63,8 @@ echo $commentClass; 'dateFormat' => 'Y-m-d H:i' )); ?>

- pageNav('', ''); ?> -
+ pageNav('', ''); ?> + @@ -103,11 +103,10 @@ echo $commentClass; - -
- - - + +
+ - - \ No newline at end of file + + options->commentsAntiSpam) { Comments::AntiSpam($this); } ?> \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php index 64f8c7c..e9e0c08 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -24,7 +24,7 @@ options->customCDN): $custom=$this->options->customCDN; else: $custom=Helper::options()->themeUrl("","Miracles"); endif; - generate_require($js_files,"js",$this->options->CDN,$custom); + Utils::addRequires($js_files,"js",$this->options->CDN,$custom); ?> '; + if ($comment->options->switch && in_array('html', $comment->options->switch)) { echo ''; } + } + + /** + * 获取上级评论人 + */ + public static function getCommentHF($coid){ + $db = Typecho_Db::get(); + $prow = $db->fetchRow($db->select('parent') + ->from('table.comments') + ->where('coid = ? AND status = ?', $coid, 'approved')); + $parent = $prow['parent']; + if ($parent != "0") { + $arow = $db->fetchRow($db->select('text','author','status') + ->from('table.comments') + ->where('coid = ?', $parent)); + $author = $arow['author']; + $status = $arow['status']; + if($author){ + if($status=='approved'){ + $href = '@'.$author.'';; + }else if($status=='waiting'){ + $href = '评论审核中···'; + } + } + echo $href; + } else { + echo ""; + } + } +} \ No newline at end of file diff --git a/libs/Contents.php b/libs/Contents.php index b424add..bad09a9 100644 --- a/libs/Contents.php +++ b/libs/Contents.php @@ -1,6 +1,17 @@ -'.$matchs[3].''; } + /* == 其他内容 == */ + /** * 解析自定义导航栏 */ @@ -278,8 +291,7 @@ class Contents * @param string $table 表名, 支持 contents, comments, metas, users * @return Widget_Abstract */ - public static function widgetById($table, $pkId) - { + public static function widgetById($table, $pkId) { $table = ucfirst($table); if (!in_array($table, array('Contents', 'Comments', 'Metas', 'Users'))) { return NULL; @@ -304,8 +316,7 @@ class Contents /** * 输出完备的标题 */ - public static function title(Widget_Archive $archive) - { + public static function title(Widget_Archive $archive) { $archive->archiveTitle(array( 'category' => '分类 %s 下的文章', 'search' => '包含关键字 %s 的文章', @@ -315,26 +326,57 @@ class Contents Helper::options()->title(); } - /** - * 内容归档 - */ - public static function archives($widget) { - $db = Typecho_Db::get(); - $rows = $db->fetchAll($db->select() - ->from('table.contents') - ->order('table.contents.created', Typecho_Db::SORT_DESC) - ->where('table.contents.type = ?', 'post') - ->where('table.contents.status = ?', 'publish')); + /** + * 内容归档 + */ + public static function archives($widget) { + $db = Typecho_Db::get(); + $rows = $db->fetchAll($db->select() + ->from('table.contents') + ->order('table.contents.created', Typecho_Db::SORT_DESC) + ->where('table.contents.type = ?', 'post') + ->where('table.contents.status = ?', 'publish')); - $stat = array(); - foreach ($rows as $row) { - $row = $widget->filter($row); - $arr = array( - 'title' => $row['title'], - 'permalink' => $row['permalink']); - - $stat[date('Y', $row['created'])][$row['created']] = $arr; + $stat = array(); + foreach ($rows as $row) { + $row = $widget->filter($row); + $arr = array( + 'title' => $row['title'], + 'permalink' => $row['permalink'] + ); + $stat[date('Y', $row['created'])][$row['created']] = $arr; + } + return $stat; + } + + /** + * 统计文章浏览数 + * from:http://docs.qqdie.com/ + */ + public static function postViews($archive) { + $cid = $archive->cid; + $db = Typecho_Db::get(); + $prefix = $db->getPrefix(); + if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { + $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;'); + echo 0; + return; + } + $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid)); + if ($archive->is('single')) { + $views = Typecho_Cookie::get('extend_contents_views'); + if(empty($views)){ + $views = array(); + }else{ + $views = explode(',', $views); + } + if(!in_array($cid,$views)){ + $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); + array_push($views, $cid); + $views = implode(',', $views); + Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie + } + } + echo $row['views']; } - return $stat; - } } \ No newline at end of file diff --git a/libs/Utils.php b/libs/Utils.php index ab3cb9a..69ebe60 100644 --- a/libs/Utils.php +++ b/libs/Utils.php @@ -109,4 +109,35 @@ class Utils } }'; } + + /** + * 自动生成引用 + */ + function addRequires($files,$type,$cdn,$custom) { + if ($cdn=='1'){ + $path = 'https://cdn.jsdelivr.net/gh/BigCoke233/miracles@'.themeVersion()."/assets/"; + } + elseif ($cdn=='2'){ + $path = 'https://raw.githack.com/BigCoke233/miracles/master/assets/'; + } + elseif ($cdn=='4'){ + $path = 'https://rawcdn.githack.com/BigCoke233/miracles/master/assets/'; + } + elseif ($cdn=='5'){ + $path = 'https://cdn.9jojo.cn/Miracles/'.themeVersion().'/'; + } + elseif ($cdn=='3'){ + $path = $custom; + }else{ + $path = Helper::options()->themeUrl("","Miracles/assets"); + } + foreach ($files as $file) { + if ($type == "js"){ + echo ""; + } + elseif ($type == "css"){ + echo ""; + } + } + } } \ No newline at end of file -- cgit v1.2.3