';
+ $output .= '';
+ $output .= '' . htmlspecialchars($summary) . '
';
+ $output .= '
';
+
+ return $output;
+}
+// 创建一个新的类来处理内容过滤
+class ContentFilter
+{
+ public static function filterContent($content, $widget, $lastResult)
+ {
+ // 先做github短代码和链接替换
+ $content = preg_replace_callback('/\[github=([\w\-\.]+\/[\w\-\.]+)\]/i', function($matches) {
+ $repo = htmlspecialchars($matches[1]);
+ return '' . $body . '
';
+ },
+ $content
+ );
+ // download下载短代码
+ $content = preg_replace_callback(
+ '/\[download\s+file=(?:\'([^\']*)\'|\"([^\"]*)\")\s+size=(?:\'([^\']*)\'|\"([^\"]*)\")\](.*?)\[\/download\]/is',
+ function($matches) {
+ $file = $matches[1] !== '' ? $matches[1] : $matches[2];
+ $size = $matches[3] !== '' ? $matches[3] : $matches[4];
+ $url = $matches[5];
+ return ''
+ . "
文件名称:" . htmlspecialchars($file) . "
"
+ . "
文件大小:" . htmlspecialchars($size) . "
"
+ . "
下载声明:本站部分资源来自于网络收集,若侵犯了你的隐私或版权,请及时联系我们删除有关信息。
"
+ . "
";
+ },
+ $content
+ );
+ // 回复可见短代码
+ $content = preg_replace_callback(
+ '/\[reply\](.*?)\[\/reply\]/is',
+ function($matches) use ($widget) {
+ $show = false;
+ // 仅在文章页生效
+ if ($widget instanceof Widget_Archive && $widget->is('single')) {
+ $user = Typecho_Widget::widget('Widget_User');
+ $db = Typecho_Db::get();
+ if ($user->hasLogin) {
+ // 登录用户,判断是否有通过审核的评论
+ $hasComment = $db->fetchRow($db->select()->from('table.comments')
+ ->where('cid = ?', $widget->cid)
+ ->where('mail = ?', $user->mail)
+ ->where('status = ?', 'approved')
+ );
+ if ($hasComment) $show = true;
+ } else {
+ // 未登录,判断IP
+ $hasComment = $db->fetchRow($db->select()->from('table.comments')
+ ->where('cid = ?', $widget->cid)
+ ->where('status = ?', 'approved')
+ ->where('ip = ?', $widget->request->getIp())
+ );
+ if ($hasComment) $show = true;
+ }
+ }
+ if ($show) {
+ return '' . $matches[1] . '
';
+ } else {
+ return "