-
Notifications
You must be signed in to change notification settings - Fork 60
/
functions.php
216 lines (184 loc) · 10.1 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function themeInit($archive) {
Helper::options()->commentsAntiSpam = false;
if ($archive->is('single')) {
$archive->content = createCatalog($archive->content);
}
}
function themeConfig($form) {
$logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl',NULL,"https://avatar.mixcm.com/github/nexmoe",'博客头像','在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO<br>可使用QQ头像链接作为LOGO https://avatar.mixcm.com/qq/(这里填QQ)');
$form->addInput ($logoUrl);
$background = new Typecho_Widget_Helper_Form_Element_Text('background',NULL,'https://cdn.jsdelivr.net/gh/nexmoe/nexmoe.github.io@latest/images/cover/compress/5c3aec85a4343.jpg','博客默认封面图','在这里填入一个图片URL地址, 给博客添加一个默认封面图');
$form->addInput ($background);
$widget = new Typecho_Widget_Helper_Form_Element_Textarea('widget',NULL,'category,tagcloud,archive','侧边栏部件','侧边栏部件,用英文的 “,” 隔开,按先后排序,可选值 category,tagcloud,archive,social,search');
$form->addInput ($widget);
$bilibili = new Typecho_Widget_Helper_Form_Element_Text('bilibili', NULL, NULL, _t('哔哩哔哩地址'), _t('社交按钮部件-哔哩哔哩'));
$form->addInput($bilibili);
$github = new Typecho_Widget_Helper_Form_Element_Text('github', NULL, NULL, _t('github地址'), _t('社交按钮部件-github'));
$form->addInput($github);
$zhihu = new Typecho_Widget_Helper_Form_Element_Text('zhihu', NULL, NULL, _t('知乎地址'), _t('社交按钮部件-知乎'));
$form->addInput($zhihu);
$telegram = new Typecho_Widget_Helper_Form_Element_Text('telegram', NULL, NULL, _t('telegram地址'), _t('社交按钮部件-telegram'));
$form->addInput($telegram);
$twitter = new Typecho_Widget_Helper_Form_Element_Text('twitter', NULL, NULL, _t('推特地址'), _t('社交按钮部件-推特'));
$form->addInput($twitter);
$steam = new Typecho_Widget_Helper_Form_Element_Text('steam', NULL, NULL, _t('steam地址'), _t('社交按钮部件-steam'));
$form->addInput($steam);
$game = new Typecho_Widget_Helper_Form_Element_Text('game', NULL, NULL, _t('游戏ID'), _t('社交按钮部件-游戏ID'));
$form->addInput($game);
$function = new Typecho_Widget_Helper_Form_Element_Checkbox('function',
array('fancybox' => '灯箱功能',
'SmoothScroll' => '平滑滚动',
'enableMathjax' => '全局启用Mathjax'),
array('fancybox', 'SmoothScroll'), '功能开关');
$form->addInput($function->multiMode());
$mdui_css = new Typecho_Widget_Helper_Form_Element_Text('mdui_css',NULL,'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/mdui.min.css','CDN > mdui > CSS',NULL);
$form->addInput ($mdui_css);
$mdui_js = new Typecho_Widget_Helper_Form_Element_Text('mdui_js',NULL,'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/mdui.min.js','CDN > mdui > JS',NULL);
$form->addInput ($mdui_js);
$jquery_js = new Typecho_Widget_Helper_Form_Element_Text('jquery_js',NULL,'https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js','CDN > jquery > JS',NULL);
$form->addInput ($jquery_js);
$fancybox_css = new Typecho_Widget_Helper_Form_Element_Text('fancybox_css',NULL,'https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.css','CDN > fancybox > CSS',NULL);
$form->addInput ($fancybox_css);
$fancybox_js = new Typecho_Widget_Helper_Form_Element_Text('fancybox_js',NULL,'https://cdn.jsdelivr.net/gh/fancyapps/[email protected]/dist/jquery.fancybox.min.js','CDN > fancybox > JS',NULL);
$form->addInput ($fancybox_js);
$SmoothScroll_js = new Typecho_Widget_Helper_Form_Element_Text('SmoothScroll_js',NULL,'https://cdn.jsdelivr.net/npm/[email protected]/SmoothScroll.min.js','CDN > SmoothScroll > JS',NULL);
$form->addInput ($SmoothScroll_js);
$lazysizes_js = new Typecho_Widget_Helper_Form_Element_Text('lazysizes_js',NULL,'https://cdn.jsdelivr.net/npm/[email protected]/lazysizes.min.js','CDN > lazysizes > JS',NULL);
$form->addInput ($lazysizes_js);
$highlight_css = new Typecho_Widget_Helper_Form_Element_Text('highlight_css',NULL,'https://cdn.jsdelivr.net/npm/[email protected]/styles/atom-one-dark.css','CDN > highlight > CSS',NULL);
$form->addInput ($highlight_css);
$highlight_js = new Typecho_Widget_Helper_Form_Element_Text('highlight_js',NULL,'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js','CDN > highlight > JS',NULL);
$form->addInput ($highlight_js);
$tongji=new Typecho_Widget_Helper_Form_Element_Textarea('tongji',NULL,'<script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src = "https://hm.baidu.com/hm.js?41b04999ee3d67f2acc9ce741045e68d";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm, s);})();</script><script data-ad-client="ca-pub-2058306854838448" async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>','统计代码','为你的网站添加统计代码');
$form->addInput ($tongji);
}
function themeFields($layout) {
$Cover = new Typecho_Widget_Helper_Form_Element_Textarea('Cover', NULL, NULL, '自定义缩略图', '输入缩略图地址');
$layout->addItem($Cover);
$math = new Typecho_Widget_Helper_Form_Element_Textarea('math', NULL, NULL, '单独控制Mathjax', '输入Yes启用,No禁用,否则跟随全局');
$layout->addItem($math);
}
function createCatalog($obj) {
$obj = preg_replace_callback('/<h([1-6])(.*?)>(.*?)<\/h\1>/i', function ($obj) {
global $catalog;
global $catalog_count;
$catalog_count++;
$catalog[] = array('text' => trim(strip_tags($obj[3])), 'depth' => $obj[1], 'count' => $catalog_count);
return '<h'.$obj[1].$obj[2].'>'.$obj[3].'</h'.$obj[1].'>';
}, $obj);
return $obj;
}
function getCatalog() {
global $catalog;
$index = '';
if ($catalog) {
$index = '<ul>' . "\n";
$prev_depth = '';
$to_depth = 0;
foreach ($catalog as $catalog_item) {
$catalog_depth = $catalog_item['depth'];
if ($prev_depth) {
if ($catalog_depth == $prev_depth) {
$index .= '</li>' . "\n";
} elseif ($catalog_depth > $prev_depth) {
$to_depth++;
$index .= '<ul>' . "\n";
} else {
$to_depth2 = ($to_depth > ($prev_depth - $catalog_depth)) ? ($prev_depth - $catalog_depth) : $to_depth;
if ($to_depth2) {
for ($i = 0; $i < $to_depth2; $i++) {
$index .= '</li>' . "\n" . '</ul>' . "\n";
$to_depth--;
}
}
$index .= '</li>';
}
}
$index .= '<li><a href="#'. $catalog_item['text'] .'">' . $catalog_item['text'] . '</a>';
$prev_depth = $catalog_item['depth'];
}
for ($i = 0; $i <= $to_depth; $i++) {
$index .= '</li>' . "\n" . '</ul>' . "\n";
}
}
echo $index;
}
function artCount ($cid) {
$db = Typecho_Db::get ();
$rs = $db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
$text = preg_replace("/[^\x{4e00}-\x{9fa5}]/u","",$rs['text']);
echo mb_strlen($text,'UTF-8');
}
function post_view ($archive) {
$cid = $archive->cid ;
$db = Typecho_Db::get ();
$prefix = $db->getPrefix ();
if (!array_key_exists('viewsNum',$db->fetchRow ($db->select ()->from ('table.contents')))) {
$db->query ('ALTER TABLE `'.$prefix.'contents` ADD `viewsNum` INT(10) DEFAULT 0;');
echo 0;
return ;
}
$row = $db->fetchRow ($db->select ('viewsNum')->from ('table.contents')->where ('cid = ?',$cid));
if ($archive->is ('single')) {
$views = Typecho_Cookie::get ('extend_contents_viewsNum');
if (empty($views)) {
$views = array ();
} else {
$views = explode(',',$views);
}
if (!in_array($cid,$views)) {
$db->query ($db->update ('table.contents')->rows (array ('viewsNum' => (int)$row['viewsNum']+1))->where ('cid = ?',$cid));
array_push($views,$cid);
$views = implode(',',$views);
Typecho_Cookie::set ('extend_contents_viewsNum',$views);
//记录查看cookie
}
}
echo $row['viewsNum'];
}
function comment_at($coid) {
$db = Typecho_Db::get();
$prow = $db->fetchRow($db->select('parent')
->from('table.comments')
->where('coid = ? AND status = ?', $coid, 'approved'));
$parent = $prow['parent'];
if ($parent != "0") {
$arow = $db->fetchRow($db->select('author')
->from('table.comments')
->where('coid = ? AND status = ?', $parent, 'approved'));
$author = $arow['author'];
$href = '<a class="at" href="#comment-'.$parent.'">回复 '.$author.':</a> ';
echo $href;
} else {
echo '';
}
}
function cid_info ($cid,$biao) {
$db = Typecho_Db::get ();
$rs = $db->fetchRow ($db->select ('table.contents.'.$biao)->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
return $rs[$biao];
}
/**
* 获取标签数目
* https://github.com/typecho/typecho/blob/master/var/Widget/Stat.php
* @return integer
*/
function tagsNum() {
$db = Typecho_Db::get ();
return $db->fetchobject($db->select(array('COUNT(mid)' => 'num'))
->from('table.metas')
->where('table.metas.type = ?', 'tag'))->num;
}
/**
* 获取模板信息
* 可选值 package,author,version,link
* http://docs.qqdie.com/#/post/常用模板函数?id=获取模板版本号
* @return string
*/
function getThemeInfo($key) {
$info = Typecho_Plugin::parseInfo(__DIR__ . '/index.php');
return $info[$key];
}
?>