addInput($logoUrl); $icoUrl = new Typecho_Widget_Helper_Form_Element_Text('icoUrl', NULL, NULL, _t('站点 Favicon 地址')); $form->addInput($icoUrl); $sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL, NULL, _t('置顶文章cid'), _t('多篇文章以`|`符号隔开'), _t('会在首页展示置顶文章。')); $form->addInput($sticky); $travel = new Typecho_Widget_Helper_Form_Element_Text('travel', NULL, NULL, _t('travel分类 Mid'), _t('填写分类的mid'), _t('指定分类ID,用于足迹分类展示')); $form->addInput($travel); $memos = new Typecho_Widget_Helper_Form_Element_Text('memos', NULL, NULL, _t('说说分类 Mid'), _t('填写分类的mid'), _t('指定分类ID,用于说说分类展示')); $form->addInput($memos); $instagramurl = new Typecho_Widget_Helper_Form_Element_Text('instagramurl', NULL, 'https://Instagram.com/', _t('Instagram'), _t('会在个人信息显示')); $form->addInput($instagramurl); $telegramurl = new Typecho_Widget_Helper_Form_Element_Text('telegramurl', NULL, 'https://t.me/', _t('电报'), _t('会在个人信息显示')); $form->addInput($telegramurl); $githuburl = new Typecho_Widget_Helper_Form_Element_Text('githuburl', NULL, 'https://github.com/', _t('github'), _t('会在个人信息显示')); $form->addInput($githuburl); $twitterurl = new Typecho_Widget_Helper_Form_Element_Text('twitterurl', NULL, 'https://x.com/', _t('twitter'), _t('会在个人信息显示')); $form->addInput($twitterurl); $mastodonurl = new Typecho_Widget_Helper_Form_Element_Text('mastodonurl', NULL,'https://jiong.us/', _t('mastodon'), _t('会在个人信息显示')); $form->addInput($mastodonurl); $showProfile = new Typecho_Widget_Helper_Form_Element_Radio('showProfile', array('0'=> _t('否'), '1'=> _t('是')), '0', _t('是否在文章页面显示作者信息'), _t('选择“是”将在文章页面包含显示作者信息。')); $form->addInput($showProfile); $showcate = new Typecho_Widget_Helper_Form_Element_Radio('showcate', array('0'=> _t('否'), '1'=> _t('是')), '0', _t('是否在文章页面显示文章分类'), _t('选择“是”将在文章页面显示文章的分类信息。')); $form->addInput($showcate); $showrelated = new Typecho_Widget_Helper_Form_Element_Radio('showrelated', array('0'=> _t('否'), '1'=> _t('是')), '0', _t('是否显示相关文章'), _t('选择“是”将在文章页面显示相关文章。')); $form->addInput($showrelated); $showshare = new Typecho_Widget_Helper_Form_Element_Radio('showshare', array('0'=> _t('否'), '1'=> _t('是')), '0', _t('是否显示复制链接'), _t('选择“是”将在文章页面显示复制链接。')); $form->addInput($showshare); $showtime = new Typecho_Widget_Helper_Form_Element_Radio('showtime', array('0'=> _t('否'), '1'=> _t('是')), '0', _t('是否显示页面加载时间'), _t('选择“是”将在页脚显示加载时间。')); $form->addInput($showtime); $loadmore = new Typecho_Widget_Helper_Form_Element_Radio('loadmore', array('0'=> _t('加载更多'), '1'=> _t('页码模式')), '0', _t('加载文章列表方式'), _t('加载更多将在文章列表底部显示加载更多按钮')); $form->addInput($loadmore); $sitemapurl = new Typecho_Widget_Helper_Form_Element_Text('sitemapurl', NULL, NULL, _t('sitemap'), _t('会在页脚显示')); $form->addInput($sitemapurl); $cnavatar = new Typecho_Widget_Helper_Form_Element_Text('cnavatar', NULL, 'https://cravatar.cn/avatar/', _t('Gravatar镜像'), _t('默认https://cravatar.cn/avatar/,建议保持默认')); $form->addInput($cnavatar); $midimg = new Typecho_Widget_Helper_Form_Element_Text('midimg', NULL, '/img/', _t('填写分类图片路径,以"/"结尾'), _t('默认使用网站根目录下的img文件夹,也可以填写绝对或者CDN地址,自动匹配目录下以分类ID为文件名的mid.jpg格式的图片')); $form->addInput($midimg); $donate = new Typecho_Widget_Helper_Form_Element_Text('donate', NULL, 'https://blogcdn.loliko.cn/donate/wx.png', _t('赞赏二维码'), _t('不填写则不显示')); $form->addInput($donate); $twikoo = new Typecho_Widget_Helper_Form_Element_Textarea('twikoo', NULL, NULL, _t('引用第三方评论'), _t('不填写则不显示')); $form->addInput($twikoo); $addhead = new Typecho_Widget_Helper_Form_Element_Textarea('addhead', NULL, NULL, _t('添加head'), _t('支持HTML')); $form->addInput($addhead); $tongji = new Typecho_Widget_Helper_Form_Element_Textarea('tongji', NULL, NULL, _t('统计代码'), _t('支持HTML')); $form->addInput($tongji); } function saveThemeConfig($config) { // 可以在这里添加额外的验证或处理逻辑 return $config; } // 自定义字段 function themeFields($layout) { $summary= new Typecho_Widget_Helper_Form_Element_Textarea('summary', NULL, NULL, _t('文章摘要'), _t('自定义摘要')); $layout->addItem($summary); $cover= new Typecho_Widget_Helper_Form_Element_Text('cover', NULL, NULL, _t('文章封面'), _t('自定义文章封面')); $layout->addItem($cover); $douban= new Typecho_Widget_Helper_Form_Element_Text('douban', NULL, NULL, _t('豆瓣API'), _t('自定义页面豆瓣API')); $layout->addItem($douban); $neodb= new Typecho_Widget_Helper_Form_Element_Text('neodb', NULL, NULL, _t('NeoDB API'), _t('自定义页面NeoDB API')); $layout->addItem($neodb); $tooot= new Typecho_Widget_Helper_Form_Element_Text('tooot', NULL, NULL, _t('Mastodon API'), _t('自定义页面Mastodon API')); $layout->addItem($tooot); $memos= new Typecho_Widget_Helper_Form_Element_Text('memos', NULL, NULL, _t('Memos地址'), _t(' 自定义页面Memos地址')); $layout->addItem($memos); $memosID= new Typecho_Widget_Helper_Form_Element_Text('memosID', NULL, NULL, _t('Memos ID'), _t('自定义页面Memos ID')); $layout->addItem($memosID); $memosnum= new Typecho_Widget_Helper_Form_Element_Text('memosnum', NULL, NULL, _t('Memos数量'), _t('自定义页面Memos数量')); $layout->addItem($memosnum); } /* * 文章浏览数统计 */ 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']; } /** 头像镜像 */ $options = Typecho_Widget::widget('Widget_Options'); $gravatarPrefix = empty($options->cnavatar) ? 'https://cravatar.cn/avatar/' : $options->cnavatar; define('__TYPECHO_GRAVATAR_PREFIX__', $gravatarPrefix); /** * 页面加载时间 */ function timer_start() { global $timestart; $mtime = explode( ' ', microtime() ); $timestart = $mtime[1] + $mtime[0]; return true; } timer_start(); function timer_stop( $display = 0, $precision = 3 ) { global $timestart, $timeend; $mtime = explode( ' ', microtime() ); $timeend = $mtime[1] + $mtime[0]; $timetotal = number_format( $timeend - $timestart, $precision ); $r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s"; if ( $display ) { echo $r; } return $r; } /** * 获取文章第一张图片 */ function img_postthumb($cid) { $db = Typecho_Db::get(); $rs = $db->fetchRow($db->select('table.contents.text') ->from('table.contents') ->where('table.contents.cid=?', $cid) ->order('table.contents.cid', Typecho_Db::SORT_ASC) ->limit(1)); // 检查是否获取到结果 if (!$rs) { return ""; } preg_match_all("/https?:\/\/[^\s]*.(png|jpeg|jpg|gif|bmp|webp)/", $rs['text'], $thumbUrl); //通过正则式获取图片地址 // 检查是否匹配到图片URL if (count($thumbUrl[0]) > 0) { return $thumbUrl[0][0]; // 返回第一张图片的URL } else { return ""; // 没有匹配到图片URL,返回空字符串 } } //回复加上@ function getPermalinkFromCoid($coid) { $db = Typecho_Db::get(); $row = $db->fetchRow($db->select('author')->from('table.comments')->where('coid = ? AND status = ?', $coid, 'approved')); if (empty($row)) return ''; return '@'.$row['author'].''; } /** * 图片灯箱 */ class ImageStructureProcessor { public static function processContent($content, $widget) { // 首先检查内容是否为空 if (empty($content) || !is_string($content)) { return $content; } if ($widget instanceof Widget_Archive) { try { // 使用 DOM 操作确保结构完整性 $dom = new DOMDocument('1.0', 'UTF-8'); // 添加错误处理 libxml_use_internal_errors(true); // 添加基础 HTML 结构以确保正确解析 $content = '