forked from BadFishy/G
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
201 lines (184 loc) · 6.24 KB
/
functions.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
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
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function themeConfig($form) {
echo "<h2 style='color:RGB(182,177,150)'>主题G配置面板:</h2>";
$favicon = new Typecho_Widget_Helper_Form_Element_Text('favicon', NULL, NULL, _t('图标') , _t(''));
$form->addInput($favicon);
$bkimg = new Typecho_Widget_Helper_Form_Element_Text('bkimg', NULL, NULL, _t('背景图片') , _t('想要啥背景?'));
$form->addInput($bkimg);
$bkcolor = new Typecho_Widget_Helper_Form_Element_Text('bkcolor', NULL, NULL, _t('背景颜色') , _t('如果没有想要的背景就换成纯色吧'));
$form->addInput($bkcolor);
$beian = new Typecho_Widget_Helper_Form_Element_Text('beian', NULL, NULL, _t('备案号') , _t('没备案当我没说'));
$form->addInput($beian);
$builtTime = new Typecho_Widget_Helper_Form_Element_Text('builtTime', NULL, NULL, _t('运行时间') , _t('格式YYYY-MM-DD'));
$form->addInput($builtTime);
$animateTime = new Typecho_Widget_Helper_Form_Element_Text('animateTime', NULL, NULL, _t('动画过渡时间') , _t('格式 1s'));
$form->addInput($animateTime);
$enableIndexPage = new Typecho_Widget_Helper_Form_Element_Radio('enableIndexPage', array(
'1' => _t('cool') ,
'0' => _t('nope')
) , '0', _t('是否使用独立页面做首页') , _t('默认为关闭'));
$form->addInput($enableIndexPage);
$enableUpyun = new Typecho_Widget_Helper_Form_Element_Radio('enableUpyun', array(
'1' => _t('我是盟友') ,
'0' => _t('啥东西,不要')
) , '0', _t('又拍云联盟开关') , _t('默认为关闭'));
$form->addInput($enableUpyun);
$enableOpac = new Typecho_Widget_Helper_Form_Element_Radio('enableOpac', array(
'1' => _t('喜欢') ,
'0' => _t('不要,快瞎了')
) , '0', _t('半透明开关') , _t('默认为打开'));
$form->addInput($enableOpac);
$enableOneRow = new Typecho_Widget_Helper_Form_Element_Radio('enableOneRow', array(
'1' => _t('开启') ,
'0' => _t('关闭')
) , '0', _t('开启文章页双排显示') , _t('默认为打开'));
$form->addInput($enableOneRow);
}
require_once __DIR__ . '/lib/Parsedown.php';
require_once __DIR__ . '/lib/shortcode.php';
/**
* 网站运行时间
*
* @access public
* @param mixed $arg1
* @return array 返回类型
*/
function getBuildTime($builtTime) {
$site_create_time = strtotime($builtTime . ' 00:00:00');
$time = time() - $site_create_time;
if (is_numeric($time)) {
$value = array(
"years" => 0,
"days" => 0,
"hours" => 0,
"minutes" => 0,
"seconds" => 0,
);
if ($time >= 31556926) {
$value["years"] = floor($time / 31556926);
$time = ($time % 31556926);
}
if ($time >= 86400) {
$value["days"] = floor($time / 86400);
$time = ($time % 86400);
}
if ($time >= 3600) {
$value["hours"] = floor($time / 3600);
$time = ($time % 3600);
}
if ($time >= 60) {
$value["minutes"] = floor($time / 60);
$time = ($time % 60);
}
$value["seconds"] = floor($time);
echo '<span class="btime">' . $value['years'] . '年' . $value['days'] . '天</span>';
} else {
echo '';
}
}
/**
* 文章阅读次数
*
* @access public
* @param mixed
* @return
*/
function get_post_view($archive)
{
$cid = $archive->cid;
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) {
$db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;');
echo 0;
return;
}
$row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
if ($archive->is('single')) {
$views = Typecho_Cookie::get('extend_contents_views');
if(empty($views)){
$views = array();
}else{
$views = explode(',', $views);
}
if(!in_array($cid,$views)){
$db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid));
array_push($views, $cid);
$views = implode(',', $views);
Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie
}
}
echo $row['views'];
}
/**
* 通过id获取原始文章内容
*
* @access public
* @param mixed
* @return
*/
function GetOriginalContent($id){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('cid = ?',$id)
);
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val);
$content = $val['text'];
return $content;
}
}
/**
* 通过id获取文章信息
*
* @access public
* @param mixed
* @return
*/
function GetPostById($id){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('cid = ?',$id)
);
if($result){
$i=1;
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val);
$post_title = htmlspecialchars($val['title']);
$post_permalink = $val['permalink'];
$post_date = $val['created'];
$post_date = date('Y-m-d',$post_date);
echo '<div class="ArtinArt">
<h4><a href="'.$post_permalink.'">'.$post_title.'</a></h4>
<p class="clear"><span style="float:left">ID:'.$id.'</span><span style="float:right">'.$post_date.'</span></p>
</div>';
}
}
else{
return '<span>id无效QAQ</span>';
}
}
/**
* 文章内容解析(短代码,表情)
*
* @access public
* @param mixed
* @return
*/
function emotionContent($content,$url)
{
// //HyperDown解析
// $Parsedown = new Parsedown();
// $content = $Parsedown->text($content);
//表情解析
$fcontent = preg_replace('#\@\((.*?)\)#','<img src="'. $url .'/IMG/bq/$1.png" class="bq">',$content);
//感谢Maicong大佬的短代码解析QwQ
$fcontent = do_shortcode($fcontent);
//输出最终结果
echo $fcontent;
}