forked from xiaopanglian/icefox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
313 lines (279 loc) · 10.3 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
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
<?php
use Typecho\Common;
use Widget\Options;
use Widget\Notice;
if (!defined('__TYPECHO_ROOT_DIR__'))
exit;
//icefox 核心包
include_once 'core/core.php';
function themeConfig($form)
{
?>
<link rel="stylesheet" href="/usr/themes/icefox/assets/admin.css">
<div>
<div class="admin-title">Icefox主题后台配置(v1.6.8)</div>
<div>
<div>
<?php
$backgroundImageUrl = new Typecho_Widget_Helper_Form_Element_Text(
'backgroundImageUrl',
null,
null,
_t('站点顶部背景图'),
_t('在这里填入一个图片 URL 地址, 以在站点顶部显示该图片')
);
$form->addInput($backgroundImageUrl);
$userAvatarUrl = new Typecho_Widget_Helper_Form_Element_Text(
'userAvatarUrl',
null,
null,
_t('用户头像'),
_t('在这里填入一个图片 URL 地址')
);
$form->addInput($userAvatarUrl);
$topPost = new Typecho_Widget_Helper_Form_Element_Text(
"topPost",
null,
null,
"置顶文章",
"格式:文章的ID || 文章的ID || 文章的ID (中间使用 || 分隔)"
);
$form->addInput($topPost);
$beian = new Typecho_Widget_Helper_Form_Element_Text(
"beian",
null,
null,
"备案号",
"例如:京ICP备00000001号"
);
$form->addInput($beian);
$autoPlayVideo = new Typecho_Widget_Helper_Form_Element_Radio(
'autoPlayVideo',
[
'yes' => _t("是"),
'no' => _t("否")
],
'yes',
_t('是否默认播放视频')
);
$form->addInput($autoPlayVideo);
$autoMutedPlayVideo = new Typecho_Widget_Helper_Form_Element_Radio(
'autoMutedPlayVideo',
[
'yes' => _t("是"),
'no' => _t("否")
],
'yes',
_t('是否默认静音播放视频')
);
$form->addInput($autoMutedPlayVideo);
$neteasyCloudMusic = new Typecho_Widget_Helper_Form_Element_Text(
'neteasyCloudMusic',
null,
null,
_t('网易云音乐歌单地址'),
_t('网页顶部播放器播放,目前只支持网易云音乐')
);
$form->addInput($neteasyCloudMusic);
$friendLinks = new Typecho_Widget_Helper_Form_Element_Textarea(
"friendLinks",
null,
null,
"友情链接",
"使用||分隔,每一行一个友情链接。格式如下<br>logo || 名称 || 链接"
);
$form->addInput($friendLinks);
$script = new Typecho_Widget_Helper_Form_Element_Textarea(
"script",
null,
null,
"全局自定义JavaScript",
"不用添加script标签"
);
$form->addInput($script);
$css = new Typecho_Widget_Helper_Form_Element_Textarea(
"css",
null,
null,
"全局自定义CSS",
"不用添加style标签"
);
$form->addInput($css);
?>
</div>
</div>
</div>
<?php
// backupThemeData();
}
function themeFields($layout)
{
$friendVideo = new Typecho_Widget_Helper_Form_Element_Textarea(
'friend_video',
null,
null,
_t('朋友圈视频'),
_t('<span>在这里填入朋友圈视频地址</span>')
);
$layout->addItem($friendVideo);
$friendPicture = new Typecho_Widget_Helper_Form_Element_Textarea(
'friend_pictures',
null,
null,
_t('朋友圈图片'),
_t('<span style="color:red;">不推荐,最好直接把图片添加在文章内容里面</span><br><span>在这里填入朋友圈图片,最多9张,使用英文逗号隔开(注:如果填了朋友圈视频,则优先视频)</span>')
);
$layout->addItem($friendPicture);
$position = new Typecho_Widget_Helper_Form_Element_Text(
'position',
null,
null,
_t('发布定位'),
_t('<span>在这里填定位名称(例:成都市·天府广场)</span>')
);
$layout->addItem($position);
$isAdvertise = new Typecho_Widget_Helper_Form_Element_Radio(
"isAdvertise",
[
"1" => _t("是"),
"0" => _t("不是"),
],
"0",
_t("是否是广告"),
_t('<span>默认不是</span>')
);
$layout->addItem($isAdvertise);
$music = new Typecho_Widget_Helper_Form_Element_Textarea(
'music',
null,
null,
_t('插入音乐'),
_t('格式如下:<br>歌曲名称 || 专辑名称 || 播放地址 || 音乐图片')
);
$layout->addItem($music);
// $canComment = new Typecho_Widget_Helper_Form_Element_Radio(
// "canComment",
// [
// "1" => _t("允许"),
// "0" => _t("不允许"),
// ],
// "1",
// _t("是否允许评论"),
// _t('<span style="color:red;">默认允许评论</span>')
// );
// $layout->addItem($canComment);
}
/**
* 备份主题数据
* @return void
*/
function backupThemeData()
{
$name = "icefox";
$db = Typecho_Db::get();
if (isset($_POST["type"])) {
if ($_POST["type"] == "创建备份") {
$value = $db->fetchRow(
$db
->select()
->from("table.options")
->where("name = ?", "theme:" . $name)
)["value"];
if (
$db->fetchRow(
$db
->select()
->from("table.options")
->where("name = ?", "theme:" . $name . "_backup")
)
) {
$db->query(
$db
->update("table.options")
->rows(["value" => $value])
->where("name = ?", "theme:" . $name . "_backup")
);
Notice::alloc()->set("备份更新成功", "success");
Options::alloc()->response->redirect(Common::url("options-theme.php", Options::alloc()->adminUrl));
?>
<?php
} else {
?>
<?php if ($value) {
$db->query(
$db
->insert("table.options")
->rows(["name" => "theme:" . $name . "_backup", "user" => "0", "value" => $value])
);
Notice::alloc()->set("备份成功", "success");
Options::alloc()->response->redirect(Common::url("options-theme.php", Options::alloc()->adminUrl));
?>
<?php
}
}
}
if ($_POST["type"] == "还原备份") {
if (
$db->fetchRow(
$db
->select()
->from("table.options")
->where("name = ?", "theme:" . $name . "_backup")
)
) {
$_value = $db->fetchRow(
$db
->select()
->from("table.options")
->where("name = ?", "theme:" . $name . "_backup")
)["value"];
$db->query(
$db
->update("table.options")
->rows(["value" => $_value])
->where("name = ?", "theme:" . $name)
);
Notice::alloc()->set("备份还原成功", "success");
Options::alloc()->response->redirect(Common::url("options-theme.php", Options::alloc()->adminUrl));
?>
<?php
} else {
Notice::alloc()->set("无备份数据,请先创建备份", "error");
Options::alloc()->response->redirect(Common::url("options-theme.php", Options::alloc()->adminUrl));
?>
<?php
} ?>
<?php
}
?>
<?php if ($_POST["type"] == "删除备份") {
if (
$db->fetchRow(
$db
->select()
->from("table.options")
->where("name = ?", "theme:" . $name . "_backup")
)
) {
$db->query($db->delete("table.options")->where("name = ?", "theme:" . $name . "_backup"));
Notice::alloc()->set("删除备份成功", "success");
Options::alloc()->response->redirect(Common::url("options-theme.php", Options::alloc()->adminUrl));
?>
<?php
} else {
Notice::alloc()->set("无备份数据,无法删除", "success");
Options::alloc()->response->redirect(Common::url("options-theme.php", Options::alloc()->adminUrl));
?>
<?php
} ?>
<?php
} ?>
<?php
}
?>
</form>
<?php echo '<br/><div class="message error">请先点击右下角的保存设置按钮,创建备份!<br/><br/><form class="backup" action="?calm_backup" method="post">
<input type="submit" name="type" class="btn primary" value="创建备份" />
<input type="submit" name="type" class="btn primary" value="还原备份" />
<input type="submit" name="type" class="btn primary" value="删除备份" /></form></div>';
}