forked from Dreamer-Paul/Single
-
Notifications
You must be signed in to change notification settings - Fork 2
/
single.php
93 lines (84 loc) · 2.94 KB
/
single.php
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
<?php
class Single {
static $name = "Single";
static $version = "2.1";
static $author = "", $authorCache = "";
// 更新检测
static function update(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.paugram.com/update/?name=" . self::$name . "¤t=" . self::$version . "&site=" . $_SERVER['HTTP_HOST']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$update = curl_exec($ch);
$update = json_decode($update, true);
curl_close($ch);
if(isset($update["name"])) self::$name = $update["name"];
?>
<style>.dreamer-paul{ text-align:center; margin:1em 0; } .dreamer-paul > *{ margin:0 0 1rem } .buttons a{ background:#467b96; color:#fff; border-radius:4px; padding:.5em .75em; display:inline-block }</style>
<div class="dreamer-paul">
<h2><?php echo self::$name . " (" . self::$version . ")" ?></h2>
<p>By: <a href='https://github.com/Dreamer-Paul'>Dreamer-Paul</a></p>
<p class="buttons">
<?php if(isset($update['docs'])): ?>
<a href="<?php echo $update['docs'] ?>">项目介绍</a>
<?php endif; ?>
<?php if(isset($update['link'])): ?>
<a href="<?php echo $update['link'] ?>">更新日志</a>
<?php endif; ?>
</p>
<?php if(isset($update['text'])): ?>
<p><?php echo $update['text'] ?></p>
<?php endif; ?>
<?php if(isset($update['message'])): ?>
<p><?php echo $update['message'] ?></p>
<?php endif; ?>
</div>
<?php
}
// 夜间模式
static function is_night($hastrees) {
if(isset($_COOKIE["night"])){
if($hastrees){
echo $_COOKIE["night"] == "true" ? ' class="dark-theme has-trees"' : 'class="has-trees"';
}else{
echo $_COOKIE["night"] == "true" ? ' class="dark-theme"' : '';
}
}
else if(Typecho_Widget::widget('Widget_Options') -> night_mode == 2){
if($hastrees){
echo ' class="dark-theme has-trees"';
}else{
echo ' class="dark-theme"';
}
}
}
// 时间转换
static function tran_time($ts){
$dur = time() - $ts;
if($dur < 0){
return $ts;
}
else if($dur < 60){
return $dur . " 秒前";
}
else if($dur < 3600){
return floor($dur / 60) . " 分钟前";
}
else if($dur < 86400){
return floor($dur / 3600) . " 小时前";
}
else if($dur < 604800){
return floor($dur / 86400) . " 天前";
}
else if($dur < 2592000){
return floor($dur / 604800) . " 周前";
}
else if($dur < 31557600){
return floor($dur / 2592000) . " 个月前";
}
else{
return date("Y.m.d", $ts);
}
}
}