-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.php
More file actions
388 lines (351 loc) · 15.7 KB
/
Copy pathpage.php
File metadata and controls
388 lines (351 loc) · 15.7 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
/**
* ikaiCMS - 单页
*
* PHP 8.0+
*/
declare(strict_types=1);
require_once __DIR__ . '/includes/init.php';
HtmlCache::start(600);
$channelId = getInt('id');
$slug = get('slug');
$parentSlug = get('parent');
// 通过slug或id获取栏目
if ($slug) {
$channel = getChannelBySlug($slug);
// 如果有父级slug,验证父子关系
if ($channel && $parentSlug) {
$parent = getChannelBySlug($parentSlug);
if (!$parent || $channel['parent_id'] != $parent['id']) {
$channel = null; // 父子关系不匹配
}
}
// 如果找不到栏目,但有parent参数,可能是内容详情页
if (!$channel && $parentSlug) {
// 检查是否为内容slug
$parentChannel = getChannelBySlug($parentSlug);
if ($parentChannel) {
$contentItem = contentModel()->findWhere(['slug' => $slug, 'channel_id' => $parentChannel['id'], 'status' => 1]);
if ($contentItem) {
// 直接加载详情页(避免重定向)
$_GET['id'] = $contentItem['id'];
include __DIR__ . '/detail.php';
exit;
}
}
}
$channelId = $channel ? (int)$channel['id'] : 0;
} elseif ($channelId > 0) {
$channel = getChannel($channelId);
} else {
$channel = null;
}
if (!$channel || $channel['status'] != 1) {
header('HTTP/1.1 404 Not Found');
exit('ページが見つかりません');
}
// 如果不是单页类型且不是相册类型,直接加载列表页(避免重定向循环)
if ($channel['type'] !== 'page' && $channel['type'] !== 'album' && !defined('LOADING_FROM_PAGE')) {
define('LOADING_FROM_LIST', true);
$_GET['id'] = $channelId;
$_GET['slug'] = $channel['slug'] ?? '';
include __DIR__ . '/list.php';
exit;
}
// 如果是相册类型,获取相册数据
$albumData = null;
$albumPhotos = [];
if ($channel['type'] === 'album' && $channel['album_id'] > 0) {
$albumData = albumModel()->findWhere(['id' => (int)$channel['album_id'], 'status' => 1]);
if ($albumData) {
$albumPhotos = albumPhotoModel()->where(['album_id' => (int)$albumData['id'], 'status' => 1]);
}
}
// 页面跳转逻辑
$redirectType = $channel['redirect_type'] ?? 'auto';
if ($redirectType === 'url' && !empty($channel['redirect_url'])) {
// 指定地址跳转(仅允许站内路径或本站域名)
$redirectUrl = $channel['redirect_url'];
if (!str_starts_with($redirectUrl, '/') && !str_starts_with($redirectUrl, SITE_URL)) {
$redirectUrl = '/';
}
header('Location: ' . $redirectUrl);
exit;
} elseif ($redirectType === 'auto') {
// 自动跳转到第一个子栏目(默认行为)
$children = channelModel()->getByParent($channelId, true);
$firstChild = $children[0] ?? null;
if ($firstChild) {
header('Location: ' . channelUrl($firstChild));
exit;
}
}
// redirectType === 'none' 时不跳转,显示自身内容
// 单页内容直接从栏目表读取
$content = null;
if (!empty($channel['content'])) {
$content = [
'title' => $channel['name'],
'cover' => $channel['image'] ?? '',
'content' => $channel['content'],
'images' => null,
];
} else {
// 向后兼容:如果栏目表没内容,回退到 contents 表
$content = contentModel()->getFirstByChannel($channelId);
}
// 页面信息
$pageTitle = $channel['seo_title'] ?: $channel['name'];
$pageKeywords = $channel['seo_keywords'] ?: config('site_keywords');
$pageDescription = $channel['seo_description'] ?: config('site_description');
$currentChannelId = $channelId;
// 获取侧边栏栏目(同级栏目或子栏目,不限制is_nav)
$sidebarChannels = [];
$sidebarTitle = $channel['name'];
if ($channel['parent_id'] > 0) {
// 子栏目:获取父栏目 + 兄弟栏目
$parentChannel = getChannel((int)$channel['parent_id']);
if ($parentChannel) {
$sidebarTitle = $parentChannel['name'];
$children = getChannels((int)$channel['parent_id'], false);
// 父栏目自身有内容时,加到侧边栏开头
if ($parentChannel['redirect_type'] === 'none') {
array_unshift($children, $parentChannel);
}
$sidebarChannels = $children;
}
} else {
// 顶级栏目:自身(有内容时)+ 子栏目
$children = getChannels($channelId, false);
if ($channel['redirect_type'] === 'none' && !empty($children)) {
array_unshift($children, $channel);
}
$sidebarChannels = $children;
}
// 获取导航
$navChannels = getNavChannels();
// SEO: OpenGraph & canonical
$siteUrl = rtrim(config('site_url', SITE_URL), '/');
$canonicalUrl = $siteUrl . channelUrl($channel);
if (!empty($channel['image'])) {
$ogImage = $channel['image'];
}
$jsonLd = [
'@context' => 'https://schema.org',
'@type' => 'WebPage',
'name' => $pageTitle,
'description' => $pageDescription,
'url' => $canonicalUrl,
];
// 引入头部
require_once theme_path('layouts/header.php');
?>
<?php
// 准备面包屑数据
$breadcrumbs = [];
$tempChannel = $channel;
while ($tempChannel) {
array_unshift($breadcrumbs, $tempChannel);
if ($tempChannel['parent_id'] > 0) {
$tempChannel = getChannel((int)$tempChannel['parent_id']);
} else {
$tempChannel = null;
}
}
?>
<!-- Page header -->
<?php
$breadcrumbItems = [];
foreach ($breadcrumbs as $bc) {
$breadcrumbItems[] = ['name' => $bc['name'], 'url' => channelUrl($bc)];
}
require theme_path('partials/page-hero.php');
?>
<section class="py-12">
<div class="container mx-auto px-4">
<div class="flex flex-wrap lg:flex-nowrap gap-8">
<!-- Main content area -->
<div class="w-full <?php echo !empty($sidebarChannels) ? 'lg:flex-1' : ''; ?>">
<?php if ($channel['type'] === 'album'): ?>
<!-- Album type display -->
<?php if (($content && $content['content']) || ($albumData && $albumData['description'])): ?>
<div class="bg-white rounded-lg shadow p-6 mb-6">
<?php if ($content && $content['content']): ?>
<div class="prose prose-lg max-w-none">
<?php echo parseShortcodes($content['content']); ?>
</div>
<?php elseif ($albumData && $albumData['description']): ?>
<p class="text-gray-600"><?php echo e($albumData['description']); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if (!empty($albumPhotos)): ?>
<div class="bg-white rounded-lg shadow p-6">
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<?php foreach ($albumPhotos as $photo): ?>
<div class="group">
<a href="<?php echo e($photo['image']); ?>"
data-lightbox="album"
data-title="<?php echo e($photo['title']); ?>"
class="block aspect-square rounded-lg overflow-hidden bg-gray-100">
<img loading="lazy" src="<?php echo e(thumbnail($photo['image'], 'medium')); ?>"
alt="<?php echo e($photo['title']); ?>"
class="w-full h-full object-cover group-hover:scale-110 transition duration-300">
</a>
<?php if ($photo['title']): ?>
<p class="text-center text-sm text-gray-600 mt-2"><?php echo e($photo['title']); ?></p>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php else: ?>
<div class="bg-white rounded-lg shadow p-8 text-center text-gray-500">
画像がありません
</div>
<?php endif; ?>
<?php elseif ($content): ?>
<!-- Page type display -->
<article class="bg-white rounded-lg shadow p-6 md:p-8">
<?php if ($content['cover']): ?>
<div class="mb-6">
<img loading="lazy" src="<?php echo e($content['cover']); ?>" alt="<?php echo e($content['title']); ?>"
class="w-full rounded-lg">
</div>
<?php endif; ?>
<div class="prose prose-lg max-w-none">
<?php echo parseShortcodes($content['content']); ?>
</div>
<!-- Image album -->
<?php if ($content['images']): ?>
<?php $images = json_decode($content['images'], true) ?: []; ?>
<?php if (!empty($images)): ?>
<div class="mt-8 pt-8 border-t">
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<?php foreach ($images as $image): ?>
<a href="<?php echo e($image); ?>" target="_blank" class="block aspect-square rounded overflow-hidden">
<img loading="lazy" src="<?php echo e($image); ?>" class="w-full h-full object-cover hover:scale-110 transition duration-300">
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
</article>
<?php else: ?>
<div class="bg-white rounded-lg shadow p-8 text-center text-gray-500">
<?php echo __('no_content'); ?>
</div>
<?php endif; ?>
</div>
<!-- Sidebar navigation -->
<?php if (!empty($sidebarChannels)): ?>
<div class="w-full lg:w-64">
<div class="bg-white rounded-lg shadow">
<div class="px-4 py-3 border-b font-bold text-dark bg-primary text-white rounded-t-lg">
<?php echo e($sidebarTitle); ?>
</div>
<div class="divide-y">
<?php foreach ($sidebarChannels as $sub): ?>
<a href="<?php echo channelUrl($sub); ?>"
class="block px-4 py-3 hover:bg-gray-50 transition <?php echo (int)$sub['id'] === $channelId ? 'text-primary bg-blue-50 font-medium' : 'text-gray-700 hover:text-primary'; ?>">
<?php echo e($sub['name']); ?>
</a>
<?php endforeach; ?>
</div>
</div>
<!-- Contact info -->
<div class="bg-white rounded-lg shadow mt-6">
<div class="px-4 py-3 border-b font-bold text-dark"><?php echo __('footer_contact'); ?></div>
<div class="p-4 space-y-3 text-sm">
<?php if ($phone = config('contact_phone')): ?>
<div class="flex items-center gap-2">
<svg class="w-4 h-4 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
</svg>
<span><?php echo e($phone); ?></span>
</div>
<?php endif; ?>
<?php if ($email = config('contact_email')): ?>
<div class="flex items-center gap-2">
<svg class="w-4 h-4 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
</svg>
<span><?php echo e($email); ?></span>
</div>
<?php endif; ?>
<?php if ($address = config('contact_address')): ?>
<div class="flex items-start gap-2">
<svg class="w-4 h-4 text-primary mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
</svg>
<span><?php echo e($address); ?></span>
</div>
<?php endif; ?>
<?php if ($hours = config('contact_hours')): ?>
<div class="flex items-center gap-2">
<svg class="w-4 h-4 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span><?php echo e($hours); ?></span>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; /* sidebarChannels */ ?>
</div>
</div>
</section>
<?php if ($channel['type'] === 'album' && !empty($albumPhotos)): ?>
<!-- Lightbox -->
<div id="lightbox" class="lightbox-overlay" onclick="closeLightbox(event)">
<div class="lightbox-content">
<span class="lightbox-close" onclick="closeLightbox()">×</span>
<span class="lightbox-nav lightbox-prev" onclick="prevImage(event)">‹</span>
<img id="lightbox-img" src="" alt="">
<span class="lightbox-nav lightbox-next" onclick="nextImage(event)">›</span>
<div class="lightbox-title" id="lightbox-title"></div>
</div>
</div>
<script>
const images = <?php echo json_encode(array_map(function($p) { return ['src' => $p['image'], 'title' => $p['title']]; }, $albumPhotos)); ?>;
let currentIndex = 0;
document.querySelectorAll('[data-lightbox="album"]').forEach((el, idx) => {
el.addEventListener('click', (e) => {
e.preventDefault();
currentIndex = idx;
showImage();
document.getElementById('lightbox').classList.add('active');
document.body.style.overflow = 'hidden';
});
});
function showImage() {
document.getElementById('lightbox-img').src = images[currentIndex].src;
document.getElementById('lightbox-title').textContent = images[currentIndex].title || '';
}
function closeLightbox(e) {
if (!e || e.target.id === 'lightbox') {
document.getElementById('lightbox').classList.remove('active');
document.body.style.overflow = '';
}
}
function prevImage(e) {
e.stopPropagation();
currentIndex = (currentIndex - 1 + images.length) % images.length;
showImage();
}
function nextImage(e) {
e.stopPropagation();
currentIndex = (currentIndex + 1) % images.length;
showImage();
}
document.addEventListener('keydown', (e) => {
if (!document.getElementById('lightbox').classList.contains('active')) return;
if (e.key === 'Escape') closeLightbox();
if (e.key === 'ArrowLeft') prevImage(e);
if (e.key === 'ArrowRight') nextImage(e);
});
</script>
<?php endif; ?>
<?php require_once theme_path('layouts/footer.php'); ?>