-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
118 lines (118 loc) · 7.17 KB
/
Copy pathpost.php
File metadata and controls
118 lines (118 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
// 确保$cover变量存在
if (!isset($cover)) {
$cover = '';
if ($this->is('post') || $this->is('page')) {
if (!empty($this->fields->thumb)) {$cover = $this->fields->thumb;
} elseif ($this->options->autoFetchCover && preg_match('/<img.*?src="(.*?)"/', $this->content, $matches)) {$cover = $matches[1];} else {$cover = $this->options->defaultCover ? $this->options->defaultCover : $this->options->themeUrl . '/img/default-cover.webp';}
}
}
$this->need('header.php');
if (!empty($this->options->Breadcrumbs) && in_array('Postshow', $this->options->Breadcrumbs)): ?>
<?php
// 简化的面包屑导航实现
$categoryName = '未分类';
$categoryPermalink = '';
// 尝试获取第一个分类
if (isset($this->categories) && count($this->categories) > 0) {
$firstCategory = reset($this->categories);
$categoryName = $firstCategory['name'];
$categoryPermalink = $firstCategory['permalink'];
}
?>
<div class="breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a href="<?php $this->options->siteUrl(); ?>" itemprop="item"><span itemprop="name">首页</span></a>
<meta itemprop="position" content="1" />
</span> »
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<?php if (!empty($categoryPermalink)): ?>
<a href="<?php echo $categoryPermalink; ?>" itemprop="item"><span itemprop="name"><?php echo $categoryName; ?></span></a>
<?php else: ?>
<span itemprop="name"><?php echo $categoryName; ?></span>
<?php endif; ?>
<meta itemprop="position" content="2" />
</span> »
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<span itemprop="name"><?php echo !empty($this->options->Breadcrumbs) && in_array('Text', $this->options->Breadcrumbs) ? '正文' : $this->title; ?></span>
<meta itemprop="position" content="3" />
</span>
</div>
<?php endif; ?>
<article class="post<?php if ($this->options->PjaxOption && $this->hidden): ?> protected<?php endif; ?>" itemscope itemtype="https://schema.org/Article">
<meta itemprop="image" content="<?php echo $cover; ?>" />
<div itemprop="author" itemscope itemtype="https://schema.org/Person">
<meta itemprop="name" content="<?php $this->author(); ?>" />
<meta itemprop="url" content="<?php $this->author->permalink(); ?>" />
</div>
<h1 class="post-title" itemprop="headline"><a href="<?php $this->permalink() ?>" itemprop="url"><?php $this->title() ?></a></h1>
<ul class="post-meta">
<li itemprop="datePublished" content="<?php $this->date('c'); ?>"><?php $this->date(); ?></li>
<li><?php $this->category(','); ?></li>
<li><a href="<?php $this->permalink() ?>#comments" itemprop="commentCount"><?php $this->commentsNum('暂无评论', '%d 条评论'); ?></a></li>
<li><?php Postviews($this); ?></li>
<li>最后更新:<span itemprop="dateModified" content="<?php echo date('c', $this->modified); ?>"><?php echo date('Y-m-d', $this->modified); ?></span></li>
</ul>
<!-- 回复可见开始 此处注释的为原版内容:?php $this->content(); ?>-->
<div class="post-content" itemprop="articleBody">
<?php
$content = $this->content;
if (strpos($content, '[hidden]') !== false) {
$content = preg_replace_callback('/(```[\s\S]*?```|`[^`]+`|<code[\s\S]*?<\/code>|<pre[\s\S]*?<\/pre>)/', function($matches) {
return str_replace(array('[hidden]', '[/hidden]'), array('[hidden]', '[/hidden]'), $matches[0]);}, $content);
if (strpos($content, '[hidden]') !== false) {$hasPermission = false;
if ($this->user->hasLogin()) {$hasPermission = true;} else {$mail = $this->remember('mail', true);
if ($mail) {
$db = Typecho_Db::get();
$result = $db->fetchRow($db->select('coid')->from('table.comments')->where('cid = ?', $this->cid)->where('mail = ?', $mail)->where('status = ?', 'approved')->limit(1));
if ($result) {$hasPermission = true;}}}
if ($hasPermission) {$content = preg_replace("/\[hidden\](.*?)\[\/hidden\]/sm", '<div class="reply2view">$1</div>', $content);
} else {$content = preg_replace("/\[hidden\](.*?)\[\/hidden\]/sm", '<div class="reply2view">此处内容需要评论回复后方可阅读</div>', $content);}}
}
// 文章过期提醒
if ($this->options->ExpireNotice) {
$expireDays = intval($this->options->ExpireNoticeDays) ?: 180;
$modifiedTime = $this->modified;
$currentTime = time();
$daysSinceModified = ($currentTime - $modifiedTime) / 86400;
if ($daysSinceModified > $expireDays) {echo '<div class="expire-notice" style="background:#f8f9fa;border-left:2px solid #6c757d;padding:6px 10px;margin-bottom:12px;border-radius:4px;"><p style="margin:0;">⚠️ 本文已超过 ' . $expireDays . ' 天未更新,部分内容可能具有时效性,请注意核实最新情况。</p></div>';}
}
// 表格响应式容器
$content = preg_replace('/<table[^>]*>/', '<div class="table-container">$0', $content);
$content = preg_replace('/<\/table>/', '</table></div>', $content);
echo $content;
?>
</div>
<!-- 回复可见结束(审核通过) -->
<!-- 文章底部广告开始 -->
<?php if (isset($this->options->GoogleAdClient) && $this->options->GoogleAdClient && isset($this->options->GoogleAdSlotPost) && $this->options->GoogleAdSlotPost): ?>
<div id="gg-post-foot"<?php if (isset($this->options->GoogleAdPostStyle) && $this->options->GoogleAdPostStyle): ?> style="<?php $this->options->GoogleAdPostStyle(); ?>"<?php endif; ?>>
<?php $this->options->GoogleAdSlotPost(); ?>
</div>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
<?php endif; ?>
<!-- 文章底部广告结束 -->
<?php if ($this->options->WeChat || $this->options->Alipay): ?>
<p class="rewards">打赏: <?php if ($this->options->WeChat): ?>
<a><img src="<?php $this->options->WeChat(); ?>" alt="微信收款二维码" />微信</a><?php endif; if ($this->options->WeChat && $this->options->Alipay): ?>, <?php endif; if ($this->options->Alipay): ?>
<a><img src="<?php $this->options->Alipay(); ?>" alt="支付宝收款二维码" />支付宝</a><?php endif; ?>
</p>
<?php endif; ?>
<p class="tags">标签: <?php $this->tags(', ', true, 'none'); ?></p>
<?php if ($this->options->LicenseInfo !== '0'): ?>
<div class="license-box">
<p>最后更新于 <?php echo date('Y-m-d', $this->modified); ?> 「部分内容存在时效性,如有失效请留言反馈」</p>
<p>除注明外为 <?php $this->options->title(); ?> 原创文章,转载请注明出处。</p>
<p><?php echo $this->options->LicenseInfo ? $this->options->LicenseInfo : '本作品采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license nofollow">知识共享署名-相同方式共享 4.0 国际许可协议</a> 进行许可。' ?></p>
<p>本文链接:<a href="<?php $this->permalink(); ?>" rel="noopener"><?php $this->permalink(); ?></a></p>
</div>
<?php endif; ?>
</article>
<?php $this->need('comments.php'); ?>
<ul class="post-near">
<li>上一篇: <?php $this->thePrev('%s','没有了'); ?></li>
<li>下一篇: <?php $this->theNext('%s','没有了'); ?></li>
</ul>
</main>
<?php if (!$this->options->OneCOL): $this->need('sidebar.php'); endif; ?>
<?php $this->need('footer.php'); ?>