This commit is contained in:
浪子 2024-07-26 15:57:19 +08:00
parent 92cf4296f2
commit acb3f7e9e5
1 changed files with 13 additions and 11 deletions

View File

@ -564,14 +564,15 @@ function get_article_info($atts) {
return $output; return $output;
} }
// 创建一个新的类来处理内容过滤
class ContentFilter
{
public static function filterContent($content, $widget, $lastResult)
{
// 首先运行之前的过滤器结果
$content = empty($lastResult) ? $content : $lastResult;
// 注册短代码 // 然后处理我们的文章短代码
function register_shortcodes() {
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('ContentProcessor', 'process');
}
class ContentProcessor {
public static function process($content, $widget, $lastResult) {
$content = preg_replace_callback('/\[article\s+([^\]]+)\]/', function($matches) { $content = preg_replace_callback('/\[article\s+([^\]]+)\]/', function($matches) {
$atts = self::parse_atts($matches[1]); $atts = self::parse_atts($matches[1]);
return get_article_info($atts); return get_article_info($atts);
@ -603,9 +604,10 @@ class ContentProcessor {
} }
} }
register_shortcodes(); // 注册钩子
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('ContentFilter', 'filterContent');
//在编辑器中添加插入文章引用的按钮
// 编辑器按钮类
class EditorButton { class EditorButton {
public static function render() public static function render()
{ {
@ -639,6 +641,6 @@ EOF;
} }
} }
// 注册钩子 // 注册编辑器按钮钩子
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('EditorButton', 'render'); Typecho_Plugin::factory('admin/write-post.php')->bottom = array('EditorButton', 'render');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('EditorButton', 'render'); Typecho_Plugin::factory('admin/write-page.php')->bottom = array('EditorButton', 'render');