|<\/div>$/i', '', $content);
-
+ $content = preg_replace('/^
|<\/div>$/i', '', $content);
// 清理 libxml 错误
- libxml_clear_errors();
-
+ libxml_clear_errors();
} catch (Exception $e) {
// 记录错误但返回原始内容
error_log('Image processing error: ' . $e->getMessage());
return $content;
}
- }
-
+ }
return $content;
}
}
-
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = function($content, $widget) {
return ImageStructureProcessor::processContent($content, $widget);
};
@@ -276,18 +265,15 @@ Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = function($conte
function get_article_summary($post) {
// 首先尝试从自定义字段获取摘要
$db = Typecho_Db::get();
-
// 查询自定义字段表
$row = $db->fetchRow($db->select()
->from('table.fields')
->where('cid = ?', $post['cid'])
- ->where('name = ?', 'summary'));
-
+ ->where('name = ?', 'summary'));
// 如果找到自定义摘要字段
if ($row && !empty($row['str_value'])) {
return $row['str_value'];
- }
-
+ }
// 如果没有自定义摘要,截取文章内容
// 去除HTML标签
$text = strip_tags($post['text']);
@@ -295,46 +281,34 @@ function get_article_summary($post) {
// 截取指定长度的摘要
return Typecho_Common::subStr($text, 0, 100, '...');
}
-
// 在原函数中使用
function get_article_info($atts) {
$default_atts = array(
'id' => '',
- 'url' => ''
);
$atts = array_merge($default_atts, $atts);
$db = Typecho_Db::get();
-
- // 根据 ID 或 URL 获取文章
+ // 根据 ID获取文章
if (!empty($atts['id'])) {
$post = $db->fetchRow($db->select()->from('table.contents')
->where('cid = ?', $atts['id'])
->limit(1));
- } elseif (!empty($atts['url'])) {
- $post = $db->fetchRow($db->select()->from('table.contents')
- ->where('permalink = ?', $atts['url'])
- ->limit(1));
} else {
- return '请提供文章ID或URL';
+ return '请提供文章ID';
}
-
if (!$post) {
return '未找到文章';
}
-
// 将文章数据推送到抽象内容小部件中
$post = Typecho_Widget::widget('Widget_Abstract_Contents')->push($post);
-
// 获取摘要
$summary = get_article_summary($post);
-
// 获取缩略图
$default_thumbnail = Helper::options()->themeUrl . '/assets/images/nopic.svg';
$imageToDisplay = img_postthumb($post['cid']);
if (empty($imageToDisplay)) {
$imageToDisplay = $default_thumbnail;
}
-
// 构建输出
$output = '
';
-
return $output;
}
// 创建一个新的类来处理内容过滤
@@ -353,16 +326,13 @@ class ContentFilter
{
// 首先运行之前的过滤器结果
$content = empty($lastResult) ? $content : $lastResult;
-
// 然后处理我们的文章短代码
$content = preg_replace_callback('/\[article\s+([^\]]+)\]/', function($matches) {
$atts = self::parse_atts($matches[1]);
return get_article_info($atts);
}, $content);
-
return $content;
}
-
// 解析短代码属性
private static function parse_atts($text) {
$atts = array();
@@ -385,10 +355,8 @@ class ContentFilter
return $atts;
}
}
-
// 注册钩子
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('ContentFilter', 'filterContent');
-
// 编辑器按钮类
class EditorButton {
public static function render()
@@ -406,13 +374,10 @@ $(document).ready(function() {
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var value = textarea.value;
-
textarea.value = value.substring(0, start) + text + value.substring(end);
-
// 将光标移动到插入的文本之后
textarea.setSelectionRange(start + text.length, start + text.length);
textarea.focus();
-
// 触发change事件,确保编辑器更新
$('#text').trigger('change');
}
@@ -422,7 +387,6 @@ $(document).ready(function() {
EOF;
}
}
-
// 注册编辑器按钮钩子
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('EditorButton', 'render');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('EditorButton', 'render');
@@ -491,10 +455,9 @@ function commentApprove($widget, $email = NULL)
// $result['userLevel'] = '博友';
// $result['bgColor'] = '#21b9bb';
// $userDesc = '🔗'.$linkSql[0]['description'].'
✌️'.$userDesc;
- // }
-
+ // }
$result['userDesc'] = $userDesc;
$result['commentNum'] = $commentNum;
}
return $result;
-}
+}
\ No newline at end of file