-
-
Notifications
You must be signed in to change notification settings - Fork 422
Expand file tree
/
Copy pathexhibition.php
More file actions
517 lines (478 loc) · 22.7 KB
/
Copy pathexhibition.php
File metadata and controls
517 lines (478 loc) · 22.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<?php
$exhibition = iro_opt('exhibition');
$exhibition = is_array($exhibition) ? $exhibition : [];
// 获取组件配置
$components = iro_opt("capsule_components",[]);
$components = is_array($components) ? $components : [];
// 如果组件为空且没有展示内容,则提前退出
if (empty($components) && empty($exhibition)) {
// 没有任何内容要显示,可以直接返回空白
echo '</div>'; // 关闭可能存在的父容器
return;
}
// 预定义组件数组,仅在需要时填充内容
$square_cards = [];
$site_stats = []; // 只在需要时获取站点统计
// 检查是否至少有一个组件被启用
$has_valid_components = !empty($components);
// 仅当有组件需要显示时才获取站点统计信息
if ($has_valid_components) {
$site_stats = get_site_stats();
// 动态填充需要使用的组件
if (in_array('post_count', $components)) {
$square_cards['post_count'] = [
'icon' => 'fa-regular fa-file-lines',
'label' => __('Content Count', 'sakurairo'),
'value' => number_format($site_stats['post_count']) . ' ' . __('posts', 'sakurairo'),
'enabled' => true
];
}
if (in_array('comment_count', $components)) {
$square_cards['comment_count'] = [
'icon' => 'fa-regular fa-comment',
'label' => __('Comment Count', 'sakurairo'),
'value' => number_format($site_stats['comment_count']) . ' ' . __('comments', 'sakurairo'),
'enabled' => true
];
}
if (in_array('view_count', $components)) {
$square_cards['view_count'] = [
'icon' => 'fa-regular fa-eye',
'label' => __('Visitor Count', 'sakurairo'),
'value' => number_format($site_stats['visitor_count']) . ' ' . __('visits', 'sakurairo'),
'enabled' => true
];
}
if (in_array('link_count', $components)) {
$square_cards['link_count'] = [
'icon' => 'fa-solid fa-link',
'label' => __('Link Count', 'sakurairo'),
'value' => number_format($site_stats['link_count']) . ' ' . __('links', 'sakurairo'),
'enabled' => true
];
}
if (in_array('author_count', $components)) {
$square_cards['author_count'] = [
'icon' => 'fa-solid fa-users',
'label' => __('Author Count', 'sakurairo'),
'value' => number_format($site_stats['author_count']) . ' ' . __('authors', 'sakurairo'),
'enabled' => true
];
}
if (in_array('total_words', $components)) {
$square_cards['total_words'] = [
'icon' => 'fa-solid fa-font',
'label' => __('Total Words', 'sakurairo'),
'value' => number_format($site_stats['total_words']) . ' ' . __('words', 'sakurairo'),
'enabled' => true
];
}
if (in_array('blog_days', $components)) {
$square_cards['blog_days'] = [
'icon' => 'fa-solid fa-calendar-days',
'label' => __('Blog Running', 'sakurairo'),
'value' => number_format($site_stats['blog_days']) . ' ' . __('days', 'sakurairo'),
'enabled' => true
];
}
if (in_array('admin_online', $components)) {
$square_cards['admin_online'] = [
'icon' => 'fa-solid fa-user-clock',
'label' => __('Last Online', 'sakurairo'),
'value' => format_time_diff($site_stats['admin_last_online_diff']),
'enabled' => true
];
}
if (in_array('announcement', $components)) {
$square_cards['announcement'] = [
'icon' => 'fa-solid fa-bullhorn',
'label' => iro_opt('stat_announcement_text', __('Latest Announcement', 'sakurairo')),
'value' => '',
'enabled' => true
];
}
if (in_array('random_link', $components)) {
$square_cards['random_link'] = [
'enabled' => true
];
}
}
// 判断博客运行天数徽章级别
function get_blog_days_medal($days) {
$thresholds = [
'gold' => 1500,
'silver' => 500,
'bronze' => 100
];
if ($days >= $thresholds['gold']) {
return [
'type' => 'gold',
'label' => __('Gold Blogger','sakurairo'),
'current' => $days,
'next' => null,
'progress' => 100,
'threshold' => $thresholds['gold'],
'achievement' => __('The string of creation has vibrated the membrane, each resonance weaving the warp and weft of spacetime thoughts.','sakurairo')
];
}
if ($days >= $thresholds['silver']) {
$progress = min(100, ($days - $thresholds['silver']) / ($thresholds['gold'] - $thresholds['silver']) * 100);
return [
'type' => 'silver',
'label' => __('Silver Blogger','sakurairo'),
'current' => $days,
'next' => $thresholds['gold'],
'progress' => $progress,
'threshold' => $thresholds['silver'],
'achievement' => __('The wheel of creation has engaged the gears, each component calibrating the temporal precision of your blog.','sakurairo'),
'next_level' => sprintf(__('%s more days to next level','sakurairo'), number_format($thresholds['gold'] - $days))
];
}
if ($days >= $thresholds['bronze']) {
$progress = min(100, ($days - $thresholds['bronze']) / ($thresholds['silver'] - $thresholds['bronze']) * 100);
return [
'type' => 'bronze',
'label' => __('Bronze Blogger','sakurairo'),
'current' => $days,
'next' => $thresholds['silver'],
'progress' => $progress,
'threshold' => $thresholds['bronze'],
'achievement' => __('The ship of creation has set sail, each wave carving the depth markers of your blog\'s journey.','sakurairo'),
'next_level' => sprintf(__('%s more days to next level','sakurairo'), number_format($thresholds['silver'] - $days))
];
}
return null;
}
// 判断访客数量徽章级别
function get_visitor_count_medal($visits) {
$thresholds = [
'gold' => 40000,
'silver' => 15000,
'bronze' => 5000
];
if ($visits >= $thresholds['gold']) {
return [
'type' => 'gold',
'label' => __('Gold Popularity','sakurairo'),
'current' => $visits,
'next' => null,
'progress' => 100,
'threshold' => $thresholds['gold'],
'achievement' => __('You have planted a garden of wisdom, its fragrance now discovered by distant butterflies.','sakurairo')
];
}
if ($visits >= $thresholds['silver']) {
$progress = min(100, ($visits - $thresholds['silver']) / ($thresholds['gold'] - $thresholds['silver']) * 100);
return [
'type' => 'silver',
'label' => __('Silver Popularity','sakurairo'),
'current' => $visits,
'next' => $thresholds['gold'],
'progress' => $progress,
'threshold' => $thresholds['silver'],
'achievement' => __('You have illuminated the star chart of reading, each piece of writing flowing through the galaxy.','sakurairo'),
'next_level' => sprintf(__('%s more visits to next level','sakurairo'), number_format($thresholds['gold'] - $visits))
];
}
if ($visits >= $thresholds['bronze']) {
$progress = min(100, ($visits - $thresholds['bronze']) / ($thresholds['silver'] - $thresholds['bronze']) * 100);
return [
'type' => 'bronze',
'label' => __('Bronze Popularity','sakurairo'),
'current' => $visits,
'next' => $thresholds['silver'],
'progress' => $progress,
'threshold' => $thresholds['bronze'],
'achievement' => __('You have built a harbor of knowledge, the ripples of thought continuously spreading.','sakurairo'),
'next_level' => sprintf(__('%s more visits to next level','sakurairo'), number_format($thresholds['silver'] - $visits))
];
}
return null;
}
// 判断友情链接数量徽章级别
function get_link_count_medal($links) {
$thresholds = [
'gold' => 80,
'silver' => 40,
'bronze' => 20
];
if ($links >= $thresholds['gold']) {
return [
'type' => 'gold',
'label' => __('Gold Friendship','sakurairo'),
'current' => $links,
'next' => null,
'progress' => 100,
'threshold' => $thresholds['gold'],
'achievement' => __('The world of friendship has no boundaries, the starry river will mark your position.','sakurairo')
];
}
if ($links >= $thresholds['silver']) {
$progress = min(100, ($links - $thresholds['silver']) / ($thresholds['gold'] - $thresholds['silver']) * 100);
return [
'type' => 'silver',
'label' => __('Silver Friendship','sakurairo'),
'current' => $links,
'next' => $thresholds['gold'],
'progress' => $progress,
'threshold' => $thresholds['silver'],
'achievement' => __('The network of friendship has been laid out, each resonance will eventually echo.','sakurairo'),
'next_level' => sprintf(__('%s more links to next level','sakurairo'), number_format($thresholds['gold'] - $links))
];
}
if ($links >= $thresholds['bronze']) {
$progress = min(100, ($links - $thresholds['bronze']) / ($thresholds['silver'] - $thresholds['bronze']) * 100);
return [
'type' => 'bronze',
'label' => __('Bronze Friendship','sakurairo'),
'current' => $links,
'next' => $thresholds['silver'],
'progress' => $progress,
'threshold' => $thresholds['bronze'],
'achievement' => __('The journey of making friends has just begun, each encounter marks a new chapter.','sakurairo'),
'next_level' => sprintf(__('%s more links to next level','sakurairo'), number_format($thresholds['silver'] - $links))
];
}
return null;
}
// 判断文章总字数徽章级别
function get_words_count_medal($words) {
$thresholds = [
'gold' => 50000,
'silver' => 10000,
'bronze' => 2000
];
if ($words >= $thresholds['gold']) {
return [
'type' => 'gold',
'label' => __('Gold Author','sakurairo'),
'current' => $words,
'next' => null,
'progress' => 100,
'threshold' => $thresholds['gold'],
'achievement' => __('The power of words has blossomed in your hands, rich creations have gathered into an ocean.','sakurairo')
];
}
if ($words >= $thresholds['silver']) {
$progress = min(100, ($words - $thresholds['silver']) / ($thresholds['gold'] - $thresholds['silver']) * 100);
return [
'type' => 'silver',
'label' => __('Silver Author','sakurairo'),
'current' => $words,
'next' => $thresholds['gold'],
'progress' => $progress,
'threshold' => $thresholds['silver'],
'achievement' => __('You have woven an extensive web of thoughts, the streams of inspiration are rushing into rivers.','sakurairo'),
'next_level' => sprintf(__('%s more words to next level','sakurairo'), number_format($thresholds['gold'] - $words))
];
}
if ($words >= $thresholds['bronze']) {
$progress = min(100, ($words - $thresholds['bronze']) / ($thresholds['silver'] - $thresholds['bronze']) * 100);
return [
'type' => 'bronze',
'label' => __('Bronze Author','sakurairo'),
'current' => $words,
'next' => $thresholds['silver'],
'progress' => $progress,
'threshold' => $thresholds['bronze'],
'achievement' => __('Sparks of words dance at your fingertips, as the faint light of thoughts quietly illuminates.','sakurairo'),
'next_level' => sprintf(__('%s more words to next level','sakurairo'), number_format($thresholds['silver'] - $words))
];
}
return null;
}
// 统计徽章信息
$medal_levels = [];
// 只有启用了相关组件且启用了徽章胶囊功能时才计算徽章
$show_medal_capsules = iro_opt('show_medal_capsules', true);
$need_medals = $show_medal_capsules && (
in_array('blog_days', $components) ||
in_array('view_count', $components) ||
in_array('link_count', $components) ||
in_array('total_words', $components)
);
// 只有当需要显示徽章时才计算徽章级别
if ($need_medals) {
if (in_array('blog_days', $components)) {
$m = get_blog_days_medal($site_stats['blog_days']);
if ($m) $medal_levels['blog_days'] = $m;
}
if (in_array('view_count', $components)) {
$m = get_visitor_count_medal($site_stats['visitor_count']);
if ($m) $medal_levels['view_count'] = $m;
}
if (in_array('link_count', $components)) {
$m = get_link_count_medal($site_stats['link_count']);
if ($m) $medal_levels['link_count'] = $m;
}
if (in_array('total_words', $components)) {
$m = get_words_count_medal($site_stats['total_words']);
if ($m) $medal_levels['total_words'] = $m;
}
}
?>
<div class="exhibition-area-container">
<h1 class="fes-title">
<i class="<?php echo esc_attr(iro_opt('exhibition_area_icon', 'fa-solid fa-laptop')); ?>" aria-hidden="true"></i> <?php echo esc_html(iro_opt('exhibition_area_title', '展示')); ?>
</h1>
<!-- Bento布局容器 -->
<div class="bento-grid">
<!-- 胶囊 -->
<?php if (!empty($components) && !empty($square_cards)): ?>
<div class="stat-capsules-container">
<?php
// 优化:只迭代存在于square_cards中的组件
foreach($components as $component):
if (!isset($square_cards[$component])) {
continue; // 跳过不存在的组件
}
switch ($component):
case 'post_count':
case 'comment_count':
case 'author_count':
case 'admin_online':
?>
<div class="stat-capsule">
<i class="<?php echo esc_attr($square_cards[$component]['icon']); ?>"></i>
<div class="capsule-content">
<span class="capsule-label"><?php echo esc_html($square_cards[$component]['label']); ?></span>
<span class="capsule-value"><?php echo esc_html($square_cards[$component]['value']); ?></span>
</div>
</div>
<?php
break;
case 'view_count':
case 'link_count':
case 'total_words':
case 'blog_days':
// 如果有对应徽章,就渲染徽章,否则渲染普通卡片
if (isset($medal_levels[$component])):
$medal = $medal_levels[$component]; ?>
<div class="stat-capsule medal-capsule <?php echo esc_attr($medal['type']); ?>"
data-medal-type="<?php echo esc_attr($component); ?>"
data-medal-level="<?php echo esc_attr($medal['type']); ?>"
<?php if (isset($medal['achievement'])) : ?>
data-achievement="<?php echo esc_attr($medal['achievement']); ?>"
<?php endif; ?>
<?php if (isset($medal['next_level'])) : ?>
data-next-level="<?php echo esc_attr($medal['next_level']); ?>"
<?php endif; ?>
<?php if (isset($medal['progress'])) : ?>
data-progress="<?php echo esc_attr($medal['progress']); ?>"
<?php endif; ?>>
<div class="medal-particles-container">
<div class="medal-particles"></div>
</div>
<i class="fa-solid fa-medal"></i>
<div class="capsule-content">
<span class="capsule-label"><?php echo esc_html($medal['label']); ?></span>
<span class="capsule-value">
<?php echo esc_html($square_cards[$component]['value']); ?>
</span>
</div>
<div class="medal-info-tooltip">
<div class="medal-achievement">
<?php echo isset($medal['achievement']) ? esc_html($medal['achievement']) : ''; ?>
</div>
<?php if (isset($medal['next_level'])) : ?>
<div class="medal-next-level">
<?php echo esc_html($medal['next_level']); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php else: ?>
<div class="stat-capsule">
<i class="<?php echo esc_attr($square_cards[$component]['icon']); ?>"></i>
<div class="capsule-content">
<span class="capsule-label"><?php echo esc_html($square_cards[$component]['label']); ?></span>
<span class="capsule-value"><?php echo esc_html($square_cards[$component]['value']); ?></span>
</div>
</div>
<?php endif;
break;
case 'random_link':
if (isset($site_stats['random_link']) && !empty($site_stats['random_link'])):
$rl = $site_stats['random_link'];
$img = isset($rl->link_image) && !empty($rl->link_image) ? $rl->link_image :
'https://weavatar.com/avatar/?s=80&d=mm&r=g'; ?>
<div class="stat-capsule link-capsule">
<div class="link-avatar"><img src="<?php echo esc_url($img); ?>" /></div>
<div class="link-info">
<a href="<?php echo esc_url($rl->link_url); ?>" target="_blank">
<?php echo esc_html($rl->link_name); ?>
</a>
<span class="link-description"><?php _e('Meet my friend!','sakurairo'); ?></span>
</div>
</div>
<?php endif;
break;
case 'announcement':
// 优化:只有当标签存在时才处理
if (isset($square_cards['announcement']) && isset($square_cards['announcement']['label'])):
$text = $square_cards['announcement']['label'];
// 强制两行显示
$lines = preg_split('/<br\s*\/?>|\n/',$text,2);
if (count($lines)<2) {
$len = mb_strlen($lines[0]);
$half = ceil($len/2);
$first = mb_substr($lines[0],0,$half);
$second= mb_substr($lines[0],$half);
} else {
list($first,$second) = $lines;
} ?>
<div class="stat-capsule announcement-capsule">
<i class="<?php echo esc_attr($square_cards['announcement']['icon']); ?>"></i>
<div class="capsule-content">
<span class="announcement-line first-line"><?php echo esc_html($first); ?></span>
<span class="announcement-line second-line"><?php echo esc_html($second); ?></span>
</div>
</div>
<?php endif;
break;
endswitch;
endforeach; ?>
</div>
<?php endif; ?>
<!-- 展示卡片 -->
<?php
if (!empty($exhibition)) :
// 默认图片路径缓存,避免重复调用iro_opt
$default_img_base = null;
foreach ($exhibition as $item) :
// 跳过非数组项
if (!is_array($item)) {
continue;
}
// 使用更高效的数组访问方式
$link = $item['link'] ?? '#';
$title = $item['title'] ?? '';
$description = $item['description'] ?? '';
$img = $item['img'] ?? '';
// 如果没有图片,使用默认图片
if (empty($img)) {
if ($default_img_base === null) {
$default_img_base = iro_opt('vision_resource_basepath', 'https://s.nmxc.ltd/sakurairo_vision/@3.0/');
}
$img = $default_img_base . 'series/exhibition1.webp';
}
?>
<div class="bento-item bento-medium">
<div class="card-title-wrapper">
<h3 class="bento-card-title"><?php echo esc_html($title); ?></h3>
</div>
<a href="<?php echo esc_url($link); ?>" target="_blank" rel="external nofollow" class="card-link">
<div class="card-image">
<img src="<?php echo esc_url($img); ?>" alt="<?php echo esc_attr($title); ?>" loading="lazy">
</div>
<div class="card-info">
<?php if (!empty($description)) : ?>
<p class="card-description"><?php echo esc_html($description); ?></p>
<?php endif; ?>
</div>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>