diff --git a/404.php b/404.php new file mode 100644 index 0000000..90ba0e4 --- /dev/null +++ b/404.php @@ -0,0 +1,53 @@ +need('includes/header.php'); +?> + +
'; //评论允许使用的标签
+ Helper::options()->commentsMarkdown = true; //启用评论可使用MarkDown语法
+ Helper::options()->commentsCheckReferer = false; //关闭检查评论来源URL与文章链接是否一致判断(否则会无法评论)
+ Helper::options()->commentsPageBreak = true; //是否开启评论分页
+ Helper::options()->commentsPageSize = 5; //评论每页显示条数
+ Helper::options()->commentsPageDisplay = 'first'; //默认显示第一页
+ Helper::options()->commentsOrder = 'DESC'; //将较新的评论展示在第一页
+
+ /* AJAX获取评论者Gravatar头像 */
+ if(isset($_GET["action"]) == 'ajax_avatar_get' && 'GET' == $_SERVER['REQUEST_METHOD'] ) {
+ $host = 'https://cdn.v2ex.com/gravatar/';
+ $email = strtolower($_GET['email']);
+ $hash = md5($email);
+ $qq = str_replace('@qq.com','',$email);
+ $sjtx = 'mm';
+ if(strstr($email,"qq.com") && is_numeric($qq) && strlen($qq) < 11 && strlen($qq) > 4) {
+ $avatar = 'https://q.qlogo.cn/g?b=qq&nk='.$qq.'&s=640';
+ }else{
+ $avatar = $host.$hash.'?d='.$sjtx;
+ }
+ echo $avatar;
+ die();
+ }else{
+ return;
+ }
+}
+
+/* 文章阅读次数(含Cookie) */
+function PostView($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);
+ }
+ }
+ return $row['views'];
+}
+
+/* 文章or页面高级设置 */
+function PSetting($type) {
+ $setting = Typecho_Widget::widget("Widget_Archive")->fields->PSetting;
+ if (json_decode($setting) == null) {
+ $output = null;
+ } else {
+ $data = json_decode($setting, true);
+ $output = $data[''.$type.''];
+ }
+ return $output;
+}
+
+/* 随机封面图 */
+function randPic() {
+ $setting = Helper::options()->randimg;
+ $rand = rand(0,99); //防止只获取一张图
+ if ($setting == 'api.ohmyga.cn') {
+ $output = 'https://api.ohmyga.cn/wallpaper/?source=sina&rand='.$rand;
+ }elseif ($setting == 'local') {
+ $openfile = glob(Helper::options()->themeFile(getTheme(), "random/*.jpg"), GLOB_BRACE);
+ $img = array_rand($openfile);
+ preg_match('/\/random\/(.*).jpg/', $openfile[$img], $out);
+ $output = Helper::options()->siteUrl.'usr/themes/'.getTheme().'/random/'.$out[1].'.jpg';
+ }
+ return $output;
+}
+
+/* 获取主题名称 */
+function getTheme() {
+ static $themeName = NULL;
+ if ($themeName === NULL) {
+ $db = Typecho_Db::get();
+ $query = $db->select('value')->from('table.options')->where('name = ?', 'theme');
+ $result = $db->fetchAll($query);
+ $themeName = $result[0]["value"];
+ }
+ return $themeName;
+}
+
+/* 主题检查更新链接 */
+function updateURL() {
+ if (extension_loaded('openssl')) {
+ $url = 'https://api.ohmyga.cc/';
+ }else{
+ $url = 'http://nossl.api.ohmyga.cc/';
+ }
+ return $url;
+}
+
+/* 主题检查更新&获取公告 */
+function themeUpdate($type) {
+ $get_new_ver = file_get_contents(updateURL().'themes/update/?site='.$_SERVER['HTTP_HOST'].'&v='.CASTLE_VERSION.'&n='.THEME_NAME);
+ $array = json_decode($get_new_ver, true);
+
+ if ($type == 'GetNewVer') {
+ $output = $array['version'];
+ }elseif ($type == 'check') {
+ $output = $array['message'];
+ }elseif ($type == 'announcement') {
+ $output = $array['announcement'];
+ }
+
+ return $output;
+}
+
+/* 主题版本 */
+function themeVer($type) {
+ if ($type == 'current') {
+ $ver = CASTLE_VERSION;
+ }elseif ($type == 'new'){
+ $ver = themeUpdate('GetNewVer');
+ }
+ return $ver;
+}
+
+/* 读取语言配置文件 */
+function lang($type, $name){
+ $file = Helper::options()->lang;
+ $json_string = file_get_contents($file, true);
+ $data = json_decode($json_string, true);
+ $output = $data['0'][''.$type.''][''.$name.''];
+ return $output;
+}
+
+/* 获取主题静态文件引用源 */
+function themeResource($content) {
+ $setting = 'local';
+
+ if ($setting == 'local') {
+ $output = Helper::options()->themeUrl.'/'.$content;
+ }elseif ($setting == 'jsdelivr') {
+ $output = 'https://cdn.jsdelivr.net/gh/ohmyga233/'.THEME_NAME.'@'.themeVer('current').'/'.$content;
+ }
+
+ return $output;
+}
+
+/* 获取Gravatr头像 */
+function gravatar($email, $size){
+ $urlSetting = 'https://'.Helper::options()->gravatar_url.'/';
+ if (!empty($urlSetting)) {
+ $url = $urlSetting;
+ }else{
+ $url = 'https://cdn.v2ex.com/gravatar/';
+ }
+
+ $host = $url;
+ $hash = md5(strtolower($email));
+ $output = $host.$hash.'?s='.$size;
+
+ return $output;
+}
+
+/* 获取站点头像 */
+function siteHeadimg($type, $moe=NULL) {
+ $setting = Helper::options()->headimg;
+
+ if ($type == 'ico') {
+ if (!empty($setting)) {
+ $headimg = $setting;
+ }else{
+ $headimg = themeResource('others/img/headimg.png');
+ }
+ }elseif ($type == 'pauthor') {
+ if (!empty($setting)) {
+ $headimg = $setting;
+ }else{
+ $headimg = gravatar($moe->author->mail, '100');
+ }
+ }
+ return $headimg;
+}
+
+/* 获取评论者头像 */
+function userHeadimg($moe=NULL) {
+ $host = Helper::options()->gravatar_url;
+ $hash = md5(strtolower($moe->mail));
+ $email = strtolower($moe->mail);
+ $qq = str_replace('@qq.com','',$email);
+ if(strstr($email,"qq.com") && is_numeric($qq) && strlen($qq) < 11 && strlen($qq) > 4) {
+ $avatar = 'https://q.qlogo.cn/g?b=qq&nk='.$qq.'&s=640';
+ }else{
+ $avatar = 'https://'.$host.'/'.$hash.'?s=640';
+ }
+
+ return $avatar;
+}
+
+/* 显示上一篇 */
+function thePrev($widget, $default = NULL) {
+ $db = Typecho_Db::get();
+ $sql = $db->select()->from('table.contents')
+ ->where('table.contents.created < ?', $widget->created)
+ ->where('table.contents.status = ?', 'publish')
+ ->where('table.contents.type = ?', $widget->type)
+ ->where('table.contents.password IS NULL')
+ ->order('table.contents.created', Typecho_Db::SORT_DESC)
+ ->limit(1);
+ $content = $db->fetchRow($sql);
+ if ($content) {
+ $content = $widget->filter($content);
+ $link = '
+
+
+ arrow_back
+ '.lang('post', 'prev').'
+ '.$content['title'].'
+
+ ';
+ echo $link;
+ } else {
+ echo $default;
+ }
+}
+
+/* 显示下一篇 */
+function theNext($widget, $default = NULL) {
+ $db = Typecho_Db::get();
+ $sql = $db->select()->from('table.contents')
+ ->where('table.contents.created > ?', $widget->created)
+ ->where('table.contents.status = ?', 'publish')
+ ->where('table.contents.type = ?', $widget->type)
+ ->where('table.contents.password IS NULL')
+ ->order('table.contents.created', Typecho_Db::SORT_ASC)
+ ->limit(1);
+ $content = $db->fetchRow($sql);
+ if ($content) {
+ $content = $widget->filter($content);
+ $link = '
+
+
+ arrow_forward
+ '.lang('post', 'next').'
+ '.$content['title'].'
+
+ ';
+ echo $link;
+ } else {
+ echo $default;
+ }
+}
+
+function DrawerMenu() {
+ $data = Helper::options()->sidebar;
+ if (!empty($data)) {
+ $json = json_decode($data, true);
+ foreach($json as $i) {
+ if ($i['type'] == '0') {
+ echo '
+ '.$i['icon'].'
+ '.$i['name'].'
+ ';
+ }elseif ($i['type'] == '1') {
+ echo '
+
+ '.$i['icon'].'
+ '.$i['name'].'
+ keyboard_arrow_down
+
+ ';
+ Typecho_Widget::widget('Widget_Contents_Post_Date', 'type=month&format=F Y')->parse('{date}');
+ echo '
+ ';
+ }elseif ($i['type'] == '2') {
+ echo '
+
+ '.$i['icon'].'
+ '.$i['name'].'
+ keyboard_arrow_down
+
+ ';
+ Typecho_Widget::widget('Widget_Metas_Category_List')->parse('{name} {count}');
+ echo '
+ ';
+ }elseif ($i['type'] == '3') {
+ Typecho_Widget::widget('Widget_Contents_Page_List')->to($pages);
+ echo '
+
+ '.$i['icon'].'
+ '.$i['name'].'
+ keyboard_arrow_down
+
+ ';
+ while($pages->next()){
+ echo ''.$pages->title.'';
+ }
+ echo '
+ ';
+ }elseif ($i['type'] == '4') {
+ echo '
+
+ '.$i['icon'].'
+ '.$i['name'].'
+ keyboard_arrow_down
+
+ ';
+ foreach($i['list'] as $ii){ echo ''.$ii['name'].''; }
+ echo '
+ ';
+ }elseif ($i['type'] == '5') {
+ echo '';
+ }elseif ($i['type'] == '6') {
+ echo '
+ rss_feed
+ RSS订阅
+ ';
+ }elseif ($i['type'] == '7') {
+ Typecho_Widget::widget('Widget_Stat')->to($stat);
+ if ($i['tes'] == '1') {
+ echo '
+ '.lang('sidebar', 'postAllNumber').'
+
+
+
+ ';
+ }elseif ($i['tes'] == '2') {
+ echo '
+ '.lang('sidebar', 'pageAllNumber').'
+
+
+
+ ';
+ }elseif ($i['tes'] == '3') {
+ echo '
+ '.lang('sidebar', 'categoriesAllNumber').'
+
+
+
+ ';
+ }elseif ($i['tes'] == '4') {
+ echo '
+ '.lang('sidebar', 'commentAllNumber').'
+
+
+
+ ';
+ }
+ }
+ }
+ }
+}
+
+/* 解析底部社交信息 */
+function FooterSocial() {
+ $data = Helper::options()->social;
+ if (!empty($data)) {
+ $json = json_decode($data, true);
+ foreach($json as $i) {
+ echo '';
+ }
+ }
+}
+
+/* 文章or独立页分享*/
+function Pshare($t,$moe=NULL) {
+ $wzimg = '';
+ if ($t == 'post'){
+ $Pt = 'post';
+ }elseif($t == 'page'){
+ $Pt = 'page';
+ }
+ $qq = '
+
+ '.lang($Pt,'shareQQ').'
+
+ ';
+
+ $weibo = '
+
+ '.lang($Pt,'shareWB').'
+
+ ';
+
+ $facebook = '
+
+ '.lang($Pt,'shareFB').'
+
+ ';
+
+ $twitter = '
+
+ '.lang($Pt,'shareTW').'
+
+ ';
+ return $qq.$weibo.$twitter.$facebook;
+}
+
+/* Original Author 熊猫小A (https://blog.imalan.cn/) */
+/* 解析表情、灯箱,获取第一管理员邮箱、名称 */
+class Castle {
+ public static function getAdminScreenName(){
+ $db = Typecho_Db::get();
+ $name = $db->fetchRow($db->select()->from('table.users')->where('uid = ?', 1))['screenName'];
+ return $name;
+ }
+
+ public static function getAdminMail(){
+ $db = Typecho_Db::get();
+ $mail = $db->fetchRow($db->select()->from('table.users')->where('uid = ?', 1))['mail'];
+ return $mail;
+}
+
+ static public function parseAll($content,$parseBoard=false){
+ $new = self::parseBiaoQing(self::parseFancyBox(self::parseRuby($content)));
+ if($parseBoard){
+ return self::parseBoard($new);
+ }else{
+ return $new;
+ }
+ }
+
+ static public function parseBiaoQing($content){
+ $content = preg_replace_callback('/\:\s*(a|bishi|bugaoxing|guai|haha|han|hehe|heixian|huaji|huanxin|jingku|jingya|landeli|lei|mianqiang|nidongde|pen|shuijiao|suanshuang|taikaixin|tushe|wabi|weiqu|what|what|wuzuixiao|xiaoguai|xiaohonglian|xiaoniao|xiaoyan|xili|yamaidei|yinxian|yiwen|zhenbang|aixin|xinsui|bianbian|caihong|damuzhi|dangao|dengpao|honglingjin|lazhu|liwu|meigui|OK|shafa|shouzhi|taiyang|xingxingyueliang|yaowan|yinyue)\s*\:/is',
+ array('Castle', 'parsePaopaoBiaoqingCallback'), $content);
+ $content = preg_replace_callback('/\:\s*(huaji1|huaji2|huaji3|huaji4|huaji5|huaji6|huaji7|huaji8|huaji9|huaji10|huaji11|huaji12|huaji13|huaji14|huaji15|huaji16|huaji17|huaji18|huaji19|huaji20|huaji21|huaji22)\s*\:/is',
+ array('Castle', 'parseHuajibiaoqingCallback'), $content);
+ return $content;
+ }
+
+ private static function parsePaopaoBiaoqingCallback($match){
+ return '';
+ }
+
+ private static function parseHuajibiaoqingCallback($match){
+ return '';
+ }
+
+ static public function parseFancyBox($content){
+ $reg = '//s';
+ $rp = '';
+ $new = preg_replace($reg,$rp,$content);
+ return $new;
+}
+
+ static public function parseRuby($string){
+ $reg='/\{\{(.*?):(.*?)\}\}/s';
+ $rp='${1}';
+ $new=preg_replace($reg,$rp,$string);
+ return $new;
+ }
+}
+
+/* 获取浏览器信息 */
+function getBrowser($agent) {
+ if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'ie');
+ $icon = 'icon-IE';
+ }elseif (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'firefox');
+ $icon = 'icon-firefox';
+ }elseif (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'aoyou');
+ $icon = 'icon-Aoyou_Browser';
+ }elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $agent, $regs)) {
+ $name = lang('ua', 'sougou');
+ $icon = 'icon-Sougou_Browser';
+ }elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) {
+ $name = lang('ua', '360');
+ $icon = 'icon-360_Browser';
+ }elseif (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'edge');
+ $icon = 'icon-edge';
+ }elseif (preg_match('/QQ/i', $agent, $regs)||preg_match('/QQBrowser\/([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'qq');
+ $icon = 'icon-QQBrowser';
+ }elseif (preg_match('/UC/i', $agent)) {
+ $name = lang('ua', 'uc');
+ $icon = 'icon-UC_Browser';
+ }elseif (preg_match('/UBrowser/i', $agent, $regs)) {
+ $name = lang('ua', 'ub');
+ $icon = 'icon-UC_Browser';
+ }elseif (preg_match('/MicroMesseng/i', $agent, $regs)) {
+ $name = lang('ua', 'wechat');
+ $icon = 'icon-wechat';
+ }elseif (preg_match('/WeiBo/i', $agent, $regs)) {
+ $name = lang('ua', 'weibo');
+ $icon = 'icon-weibo';
+ }elseif (preg_match('/BIDU/i', $agent, $regs)) {
+ $name = lang('ua', 'baidu');
+ $icon = 'icon-Baidu_Browser';
+ }elseif (preg_match('/LBBROWSER/i', $agent, $regs)) {
+ $name = lang('ua', 'lb');
+ $icon = 'icon-LBBROWSER';
+ }elseif (preg_match('/TheWorld/i', $agent, $regs)) {
+ $name = lang('ua', 'tw');
+ $icon = 'icon-TheWorld_Browser';
+ }elseif (preg_match('/XiaoMi/i', $agent, $regs)) {
+ $name = lang('ua', 'xiaomi');
+ $icon = 'icon-xiaomi';
+ }elseif (preg_match('/2345Explorer/i', $agent, $regs)) {
+ $name = lang('ua', '2345');
+ $icon = 'icon-2345_Browser';
+ }elseif (preg_match('/YaBrowser/i', $agent, $regs)) {
+ $name = lang('ua', 'yandex');
+ $icon = 'icon-Yandex_Browser';
+ }elseif (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'opera');
+ $icon = 'icon-Opera_Browser';
+ }elseif (preg_match('/Thunder/i', $agent, $regs)) {
+ $name = lang('ua', 'xunlie');
+ $icon = 'icon-xunlei';
+ }elseif (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'chrome');
+ $icon = 'icon-chrome';
+ }elseif (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
+ $name = lang('ua', 'safari');
+ $icon = 'icon-safari';
+ }else{
+ $name = lang('ua', 'other');
+ $icon = 'icon-Browser';
+ }
+ echo '';
+}
+
+/* 获取操作系统 */
+function getOs($agent) {
+ if (preg_match('/win/i', $agent)) {
+ if (preg_match('/nt 5.1/i', $agent)) {
+ $name = lang('os', 'windows xp');
+ $icon = 'icon-windows_old';
+ }elseif (preg_match('/nt 6.0/i', $agent)) {
+ $name = lang('os', 'windows vista');
+ $icon = 'icon-windows_old';
+ }elseif (preg_match('/nt 6.1/i', $agent)) {
+ $name = lang('os', 'windows 7');
+ $icon = 'icon-windows_old';
+ }elseif (preg_match('/nt 6.2/i', $agent)) {
+ $name = lang('os', 'windows 8');
+ $icon = 'icon-windows';
+ }elseif (preg_match('/nt 6.3/i', $agent)) {
+ $name = lang('os', 'windows 8.1');
+ $icon = 'icon-windows';
+ }elseif (preg_match('/nt 10.0/i', $agent)) {
+ $name = lang('os', 'windows 10');
+ $icon = 'icon-windows';
+ }else{
+ $name = lang('os', 'windows xp');
+ $icon = 'icon-windows';
+ }
+ }elseif (preg_match('/android/i', $agent)) {
+ if (preg_match('/android 5/i', $agent)) {
+ $name = lang('os', 'android l');
+ $icon = 'icon-android';
+ }elseif (preg_match('/android 6/i', $agent)) {
+ $name = lang('os', 'android m');
+ $icon = 'icon-android';
+ }elseif (preg_match('/android 7/i', $agent)) {
+ $name = lang('os', 'android n');
+ $icon = 'icon-android';
+ }elseif (preg_match('/android 8/i', $agent)) {
+ $name = lang('os', 'android o');
+ $icon = 'icon-android';
+ }elseif (preg_match('/android 9/i', $agent)) {
+ $name = lang('os', 'android p');
+ $icon = 'icon-android';
+ }else{
+ $name = lang('os', 'android');
+ $icon = 'icon-android';
+ }
+ }elseif (preg_match('/linux/i', $agent)) {
+ $name = lang('os', 'linux');
+ $icon = 'icon-linux';
+ }elseif (preg_match('/iPhone/i', $agent)) {
+ $name = lang('os', 'iphone');
+ $icon = 'icon-ios';
+ }elseif (preg_match('/iPad/i', $agent)) {
+ $name = lang('os', 'ipad');
+ $icon = 'icon-ios';
+ }elseif (preg_match('/mac/i', $agent)) {
+ $name = lang('os', 'mac os');
+ $icon = 'icon-osx';
+ }else{
+ $name = lang('os', 'other');
+ $icon = 'icon-os';
+ }
+ echo '';
+}
\ No newline at end of file
diff --git a/includes/comments.php b/includes/comments.php
new file mode 100644
index 0000000..627d39b
--- /dev/null
+++ b/includes/comments.php
@@ -0,0 +1,123 @@
+authorId) {
+ if ($comments->authorId == $comments->ownerId) {
+ $commentClass .= '';
+ } else {
+ $commentClass .= '';
+ }
+ }
+ $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent';
+ $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent';
+?>
+
+
+
+
+
+ date(lang('comment', 'time')); ?>
+ reply(''); ?>
+
+ content); ?>
+
+
+
+
+ children){ $comments->threadedComments($options); }?>
+
+
+
+comments()->to($comments); ?>
+ allow('comment')): ?>
+
+
+
+ user->hasLogin()): ?>
+
+
+ user->screenName(); ?>
+
+
+
+
+
+
+
+
+
+ user->hasLogin()){}else{ echo ''; } ?>
+ cancelReply(''); ?>
+
+
+
+
+
+
+
+
+
+
+ speaker_notes_off
+
+
+
+
+
+
+
+ mode_comment
+ commentsNum(_t(lang('comment', 'NoComment')), _t(lang('comment', 'OnlyOneComment')), _t(lang('comment', 'AllCommentNumber'))); ?>
+
+
+have()){ $comments->listComments(); }?>
+
+ pageNav('<<', '>>', 1, '···', array('wrapTag' => 'div', 'wrapClass' => 'moe-comments-nav mdui-card moe-card-t mdui-card-content', 'itemTag' => 'li', 'currentClass' => 'mdui-shadow-3 current',)); ?>
+
+allow('comment')){$this->need("includes/owo.php");}else{} ?>
+
\ No newline at end of file
diff --git a/includes/footer.php b/includes/footer.php
new file mode 100644
index 0000000..621663f
--- /dev/null
+++ b/includes/footer.php
@@ -0,0 +1,79 @@
+
+
+
+
+
+options->tjcode): ?>
+
+ options->tjcode(); ?>
+
+
+
+
+
+
+
+
+
+ footer(''); ?>
+