mirror of
https://github.com/jkjoy/typecho-theme-farallon.git
synced 2026-06-27 20:34:30 +00:00
0.6.3
fix
This commit is contained in:
+47
-42
@@ -195,6 +195,53 @@ function notifyQQBot($comment) {
|
||||
}
|
||||
Typecho_Plugin::factory('Widget_Feedback')->finishComment = 'notifyQQBot';
|
||||
|
||||
/**
|
||||
* 图片灯箱
|
||||
*/
|
||||
class ImageStructureProcessor {
|
||||
public static function processContent($content, $widget) {
|
||||
if ($widget instanceof Widget_Archive) {
|
||||
// 使用 DOM 操作确保结构完整性
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'),
|
||||
LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
// 查找所有没有父 figure 的图片
|
||||
$images = $xpath->query("//img[not(ancestor::figure)]");
|
||||
|
||||
foreach ($images as $img) {
|
||||
// 创建容器元素
|
||||
$figure = $dom->createElement('figure');
|
||||
$figure->setAttribute('class', 'grap--figure');
|
||||
|
||||
// 创建链接元素用于lightbox
|
||||
$link = $dom->createElement('a');
|
||||
$link->setAttribute('href', $img->getAttribute('src'));
|
||||
$link->setAttribute('data-lightbox', 'image-set');
|
||||
$link->setAttribute('data-title', $img->getAttribute('alt'));
|
||||
|
||||
// 创建 figcaption
|
||||
$caption = $dom->createElement('figcaption', $img->getAttribute('alt'));
|
||||
$caption->setAttribute('class', 'imageCaption');
|
||||
|
||||
// 重组 DOM 结构
|
||||
$img->parentNode->replaceChild($figure, $img);
|
||||
$link->appendChild($img);
|
||||
$figure->appendChild($link);
|
||||
$figure->appendChild($caption);
|
||||
}
|
||||
|
||||
$content = $dom->saveHTML();
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
// 挂载到内容输出
|
||||
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('ImageStructureProcessor', 'processContent');
|
||||
|
||||
//获取文章卡片
|
||||
function get_article_info($atts) {
|
||||
$default_atts = array(
|
||||
@@ -388,49 +435,7 @@ function commentApprove($widget, $email = NULL)
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片灯箱
|
||||
*/
|
||||
class ImageStructureProcessor {
|
||||
public static function processContent($content, $widget) {
|
||||
if ($widget instanceof Widget_Archive) {
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'),
|
||||
LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
// 查找所有没有父 figure 的图片
|
||||
$images = $xpath->query("//img[not(ancestor::figure)]");
|
||||
|
||||
foreach ($images as $img) {
|
||||
// 创建容器元素
|
||||
$figure = $dom->createElement('figure');
|
||||
$figure->setAttribute('class', 'grap--figure');
|
||||
|
||||
// 为图片添加 viewimage 属性
|
||||
$img->setAttribute('data-viewimage', '');
|
||||
// 可选:添加额外属性用于分组
|
||||
$img->setAttribute('data-viewimage-group', 'post');
|
||||
|
||||
// 创建 figcaption
|
||||
$caption = $dom->createElement('figcaption', $img->getAttribute('alt'));
|
||||
$caption->setAttribute('class', 'imageCaption');
|
||||
|
||||
// 重组 DOM 结构
|
||||
$img->parentNode->replaceChild($figure, $img);
|
||||
$figure->appendChild($img);
|
||||
$figure->appendChild($caption);
|
||||
}
|
||||
|
||||
$content = $dom->saveHTML();
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
// 挂载到内容输出
|
||||
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('ImageStructureProcessor', 'processContent');
|
||||
|
||||
/** 获取评论者地址 */
|
||||
//function get_ip_location($ip) {
|
||||
|
||||
Reference in New Issue
Block a user