This commit is contained in:
浪子 2025-03-14 20:06:28 +08:00
parent 458fad51bb
commit 579f92c720
3 changed files with 68 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -388,6 +388,50 @@ 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) {
// $apiUrl = "https://www.nazo.run/ip/{$ip}";

View File

@ -116,9 +116,7 @@ foreach ($normalPosts as $normalPost) {
</a>
</h2>
<div class="description">
<!-- 本功能实现 借助插件 AIsummary 实现 -->
<?php
// 判断是否存在自定义字段summary并输出否则输出自动生成的摘要
<?php
if($this->fields->summary){
echo $this->fields->summary;
} else {
@ -158,10 +156,13 @@ foreach ($normalPosts as $normalPost) {
$firstImage = img_postthumb($this->cid);
$cover = $this->fields->cover;
$imageToDisplay = !empty($cover) ? $cover : $firstImage;
if($imageToDisplay): ?>
<img src="<?php echo $imageToDisplay; ?>" alt="文章图片" class="cover"/>
if($imageToDisplay):
?>
<a href="<?php $this->permalink() ?>" class="cover--link">
<img src="<?php echo $imageToDisplay; ?>" alt="<?php $this->title() ?>" class="cover" itemprop="image"/>
</a>
<?php endif; ?>
</article>
</article>
<?php endwhile; ?>
<?php
$this->pageNav(