-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfunctions.php
More file actions
467 lines (456 loc) · 24.5 KB
/
Copy pathfunctions.php
File metadata and controls
467 lines (456 loc) · 24.5 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
<?php
use Utils\Helper;
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function themeConfig($form)
{
$v_time = '1.4.0';
$theme_url = '/' . str_replace(Helper::options()->siteUrl, "", Helper::options()->themeUrl);
echo <<<EOD
<style>
p {
margin: 15px 0 10px 0 !important;
}
span label {
margin-bottom: -5px;
}
.zmki_ht_about {
margin: 0;
}
span a, p a {
text-decoration: underline;
}
.zmki_ht_about a {
color: #147ed2;
}
.zmki_ht_about_mian {
width: 100%;
padding:0 0 0 20px ;
}
.zmki_ht_about_mian h2 {
color: #000;
margin: 0;
}
.btn {
color:#000;
padding: 0 10px;
border-radius: 4px;
background-color: whitesmoke;
box-shadow: 0 6px 7px -5px rgba(210, 210, 210, 0.6);
}
form.home {
margin-top: 15px;
float: none !important;
}
.zmki_aliico {
width: 20px;
float: initial;
height: 20px;
margin-bottom: -4px;
}
</style>
<link rel="stylesheet" href="$theme_url/css/fonts/font_1953461/iconfont.css">
<script src="$theme_url/css/fonts/font_1953461/iconfont.js"></script>
EOD;
//! 模板设置处理
$str1 = explode('/themes/', Helper::options()->themeUrl);
$str2 = explode('/', $str1[1]);
$name = $str2[0];
$db = Typecho_Db::get();
$sjdq = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:' . $name));
$ysj = $sjdq['value'];
if (isset($_POST['type'])) {
$tips = '';
if ($_POST["type"] == "备份模板设置数据") {
if ($db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:' . $name . 'bf'))) {
$update = $db->update('table.options')->rows(array('value' => $ysj))->where('name = ?', 'theme:' . $name . 'bf');
$db->query($update);
$tips = '备份已更新。';
} else {
if ($ysj) {
$insert = $db->insert('table.options')->rows(array('name' => 'theme:' . $name . 'bf', 'user' => '0', 'value' => $ysj));
$db->query($insert);
$tips = '备份完成。';
}
}
}
if ($_POST["type"] == "还原模板设置数据") {
if ($db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:' . $name . 'bf'))) {
$sjdub = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:' . $name . 'bf'));
$bsj = $sjdub['value'];
$update = $db->update('table.options')->rows(array('value' => $bsj))->where('name = ?', 'theme:' . $name);
$db->query($update);
$tips = '检测到模板备份数据,恢复完成。';
} else {
$tips = '没有模板备份数据,恢复不了哦!';
}
}
if ($_POST["type"] == "删除备份数据") {
if ($db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:' . $name . 'bf'))) {
$delete = $db->delete('table.options')->where('name = ?', 'theme:' . $name . 'bf');
$db->query($delete);
$tips = '删除成功。';
} else {
$tips = '不用删了!备份不存在!!!';
}
}
$optionsTheme = Helper::options()->adminUrl('options-theme.php', true);
echo <<<EOD
<div class="notify">
<p>$tips</p>
<p>请等待自动刷新!如果等不到请点击<a href="$optionsTheme">这里</a></p>
</div>
<script type="text/javascript">
window.setTimeout(() => {
location.href="$optionsTheme";
}, 2500);
</script>
EOD;
}
//! 页面内容
$nameBf = $name . 'bf';
$optionsGeneral = Helper::options()->adminUrl('options-general.php', true);
echo <<<EOD
<link href="$theme_url/css/bootstrap.css" rel="stylesheet">
<script src="$theme_url/js/jquery.min.js"></script>
<script src="$theme_url/js/bootstrap.min.js"></script>
<hr>
<p><strong><svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-project"></use></svg> WebStack 网址导航 Typecho 主题</strong></p>
<p><strong><svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-chicken"></use></svg> 主题版本号: </strong>$v_time<span class="new_version_span" style="margin-left:25px;"></span></p>
<p><button class="check_update_btn btn">检查更新</button></p>
<hr>
<ul id="myTab" class="nav nav-tabs">
<li class="active"><a href="#home" data-toggle="tab">备份与恢复</a></li>
<li><a href="#about" data-toggle="tab">关于主题</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
<form class="protected home col-mb-12" action="?$nameBf" method="post">
<input type="submit" name="type" class="btn btn-s" value="备份模板设置数据" />
<input type="submit" name="type" class="btn btn-s" value="还原模板设置数据" />
<input type="submit" name="type" class="btn btn-s" value="删除备份数据" />
</form>
</div>
<div class="tab-pane fade" id="about">
<div class="zmki_ht_about">
<div class="zmki_ht_about_mian">
<p>Github地址: <a href="https://github.com/LightAPIs/WebStackTypechoTheme" target="_blank">LightAPIs/WebStackTypechoTheme</a></p>
<p>WebStack_钻芒二开版项目地址: <a href="https://github.com/wclk/WebStack_ZMKI" target="_blank">wclk/WebStack_ZMKI</a></p>
<p>Webstack网址导航项目地址: <a href="https://github.com/WebStackPage/WebStackPage.github.io" target="_blank">WebStackPage/WebStackPage.github.io</a></p>
<p>本主题基于WebStack_钻芒二开版及原Webstack网址导航项目修改并免费开源发布。</p>
</div>
</div>
</div>
</div>
<hr>
<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-sound"></use></svg>
<span>自定义站点名称和后缀功能直接移步至<a href="$optionsGeneral">基本设置</a>即可</span>
<hr>
<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-set"></use></svg>
<b>提示:主题设置选择后回车可快捷保存</b>
<hr>
<script type="text/javascript">
const checkUpdateBtn = document.querySelector('.check_update_btn');
const newVersionSpan = document.querySelector('.new_version_span');
const curVersion = '$v_time';
if (checkUpdateBtn && newVersionSpan) {
checkUpdateBtn.addEventListener('click', e => {
e.stopPropagation();
fetch('https://api.github.com/repos/LightAPIs/WebStackTypechoTheme/releases/latest')
.then(res => res.json())
.then(json => {
const tagName = json.tag_name;
if (tagName && tagName.startsWith('v')) {
const tag = tagName.replace('v', '');
const cur = curVersion.split('.');
const next = tag.split('.');
if (cur.length >= 3 && next.length >= 3) {
let isUpdate = false;
for (let i = 2; i >= 0; i--) {
if (cur[i] < next[i]) {
isUpdate = true;
} else if (cur[i] > next[i]) {
isUpdate = false;
}
}
if (isUpdate) {
newVersionSpan.innerHTML = '<a href="https://github.com/LightAPIs/WebStackTypechoTheme/releases/latest" target="_blank">前往下载新板本:' + tag + '</a>';
} else {
newVersionSpan.textContent = '当前已是最新版本。'
}
} else {
newVersionSpan.textContent = '版本号格式不正确!'
}
} else {
newVersionSpan.textContent = '无法查询到版本号!'
}
})
.catch(_e => {
newVersionSpan.textContent = '检查更新出错!'
})
})
}
</script>
EOD;
// 左侧 logo
$Biglogo = new Typecho_Widget_Helper_Form_Element_Text('Biglogo', NULL, "/usr/themes/WebStack/images/logo@2x.png", _t('<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-star"></use></svg> LOGO 地址'), _t('主页左侧 logo 地址,尺寸 178*40'));
$form->addInput($Biglogo);
// favicon
$favicon = new Typecho_Widget_Helper_Form_Element_Text('favicon', NULL, "/usr/themes/WebStack/images/logo.png", _t('<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-edit"></use></svg> Favicon 地址'), _t('网站图标地址,ico, png, jpg 等图片格式均可,刷新浏览器缓存后生效'));
$form->addInput($favicon);
// 左侧菜单栏字体大小
$menu_title = new Typecho_Widget_Helper_Form_Element_Text('menu_title', NULL, '13', _t('<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-position"></use></svg> 左侧菜单栏字体大小'), _t('请输入字体大小,如 13,留空则默认为 13(13px)'));
$form->addInput($menu_title);
// PC端每行显示数量
$zmki_pcsl = new Typecho_Widget_Helper_Form_Element_Radio('zmki_pcsl', array('0' => _t('单栏'), '1' => _t('双栏'), '2' => _t('三栏'), '3' => _t('四栏'), '4' => _t('五栏'), '5' => _t('六栏'), '6' => _t('七栏'), '7' => _t('八栏')), '3', _t('<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-pc"></use></svg> PC 端栏目数量'), _t("PC 端每行显示数量的布局。默认四栏,为美观考虑推荐设置四到六栏<br>注意:如调整失效,请刷新请浏览器缓存"));
$form->addInput($zmki_pcsl);
// 手机端每行显示数量
$zmki_wapsl = new Typecho_Widget_Helper_Form_Element_Radio('zmki_wapsl', array('0' => _t('单栏'), '1' => _t('双栏'), '2' => _t('三栏')), '0', _t('<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-phone"></use></svg> 手机端栏目数量'), _t("手机端显示数量的布局。此功能可避免页面过于庸长,默认单栏,推荐双栏显示<br>注意:如调整失效,请刷新请浏览器缓存"));
$form->addInput($zmki_wapsl);
// 顶部模块
$zmki_top_main = new Typecho_Widget_Helper_Form_Element_Radio('zmki_top_main', array('0' => _t('禁用'), '1' => _t('启用')), '1', _t('<svg class="icon zmki_aliico" aria-hidden="true"><use xlink:href="#icon-prompt"></use></svg> <span style="color: #608cee; margin-right:0px;">顶部</span><span style="color: #fb5962;margin-right:0px;">多色</span><span style="color: #fbb359;margin-right:0px;">模块</span><span style="color: #53bf6b;margin-right:0px;">开关</span>'), _t("是否开启网站顶部四项多色小模块"));
$form->addInput($zmki_top_main);
// 顶部模块 蓝色 文字自定义
$zmki_top_main_one_name = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_one_name', NULL, '项目地址', _t('<span style="color: #608cee; margin-right:0px;">蓝色模块文字</span>'), _t('输入顶部蓝色模块内的文字,默认 项目地址'));
$form->addInput($zmki_top_main_one_name);
$zmki_top_main_one_icon = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_one_icon', NULL, 'fa fa-safari', _t('<span style="color: #608cee; margin-right:0px;">蓝色模块</span>图标'), _t('自定义蓝色模块内文字前的 Font Awesome 图标,图标帮助可查看:<a target="_blank" href="https://fontawesome.com/v4/icons/">Font Awesome Icons</a>,蓝色默认 fa fa-safari'));
$form->addInput($zmki_top_main_one_icon);
$zmki_top_main_one_url = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_one_url', NULL, 'https://github.com/LightAPIs/WebStackTypechoTheme', _t('<span style="color: #608cee; margin-right:0px;">蓝色模块</span>跳转链接'), _t('输入蓝色模块跳转的链接,'));
$form->addInput($zmki_top_main_one_url);
// 顶部模块 红色 文字自定义
$zmki_top_main_two_name = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_two_name', NULL, 'WebStack_钻芒二开版', _t('<span style="color: #fb5962; margin-right:0px;">红色模块文字</span>'), _t('输入顶部红色模块内的文字,默认 WebStack_钻芒二开版'));
$form->addInput($zmki_top_main_two_name);
$zmki_top_main_two_icon = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_two_icon', NULL, 'fa fa-star', _t('<span style="color: #fb5962; margin-right:0px;">红色模块</span>图标'), _t('自定义红色模块内文字前的 Font Awesome 图标,图标帮助可查看:<a target="_blank" href="https://fontawesome.com/v4/icons/">Font Awesome Icons</a>,红色默认 fa fa-star'));
$form->addInput($zmki_top_main_two_icon);
$zmki_top_main_two_url = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_two_url', NULL, 'https://github.com/wclk/WebStack_ZMKI', _t('<span style="color: #fb5962; margin-right:0px;">红色模块</span>跳转链接'), _t('输入红色模块跳转的链接,'));
$form->addInput($zmki_top_main_two_url);
// 顶部模块 黄色 文字自定义
$zmki_top_main_three_name = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_three_name', NULL, 'WebStack', _t('<span style="color: #fbb359; margin-right:0px;">黄色模块文字</span>'), _t('输入顶部黄色模块内的文字,默认 WebStack'));
$form->addInput($zmki_top_main_three_name);
$zmki_top_main_three_icon = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_three_icon', NULL, 'fa fa-registered', _t('<span style="color: #fbb359; margin-right:0px;">黄色模块</span>图标'), _t('自定义黄色模块内文字前的 Font Awesome 图标,图标帮助可查看:<a target="_blank" href="https://fontawesome.com/v4/icons/">Font Awesome Icons</a>,黄色默认 fa fa-registered'));
$form->addInput($zmki_top_main_three_icon);
$zmki_top_main_three_url = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_three_url', NULL, 'https://github.com/WebStackPage/WebStackPage.github.io', _t('<span style="color: #fbb359; margin-right:0px;">黄色模块</span>跳转链接'), _t('输入黄色模块跳转的链接,'));
$form->addInput($zmki_top_main_three_url);
// 顶部模块 绿色 文字自定义
$zmki_top_main_four_name = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_four_name', NULL, 'Typecho', _t('<span style="color: #53bf6b; margin-right:0px;">绿色模块文字</span>'), _t('输入顶部绿色模块内的文字,默认 Typecho'));
$form->addInput($zmki_top_main_four_name);
$zmki_top_main_four_icon = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_four_icon', NULL, 'fa fa-diamond', _t('<span style="color: #53bf6b; margin-right:0px;">绿色模块</span>图标'), _t('自定义绿色模块内文字前的 Font Awesome 图标,图标帮助可查看:<a target="_blank" href="https://fontawesome.com/v4/icons/">Font Awesome Icons</a>,绿色默认 fa fa-diamond'));
$form->addInput($zmki_top_main_four_icon);
$zmki_top_main_four_url = new Typecho_Widget_Helper_Form_Element_Text('zmki_top_main_four_url', NULL, 'https://typecho.org/', _t('<span style="color: #53bf6b; margin-right:0px;">绿色模块</span>跳转链接'), _t('输入绿色模块跳转的链接,'));
$form->addInput($zmki_top_main_four_url);
// 顶栏文字自定义
$zmki_name = new Typecho_Widget_Helper_Form_Element_Text('zmki_name', NULL, '后台管理', _t('顶栏文字'), _t('输入主页顶栏管理网址右侧自定义文字,默认 后台管理'));
$form->addInput($zmki_name);
// 顶栏链接自定义
$zmki_url = new Typecho_Widget_Helper_Form_Element_Text('zmki_url', NULL, '/admin/index.php', _t('顶栏链接'), _t('输入主页顶栏管理网址右侧文字的 url,默认 /admin/index.php'));
$form->addInput($zmki_url);
$zmki_links = new Typecho_Widget_Helper_Form_Element_Text('zmki_links', NULL, '/admin/manage-posts.php', _t('管理网址链接'), _t('默认 /admin/manage-posts.php'));
$form->addInput($zmki_links);
$Isabout = new Typecho_Widget_Helper_Form_Element_Text('Isabout', NULL, '/about.html', _t('关于我们 URL 链接'), _t('默认为 /about.html'));
$form->addInput($Isabout);
// 搜索功能
$isSearch = new Typecho_Widget_Helper_Form_Element_Radio('isSearch', array('0' => _t('禁用'), '1' => _t('启用')), '1', _t('搜索功能'), _t("是否在主页上启用搜索框"));
$form->addInput($isSearch);
// 搜索框内的清空按钮
$isSearchClean = new Typecho_Widget_Helper_Form_Element_Radio('isSearchClean', array('0' => _t('禁用'), '1' => _t('启用')), '0', _t('搜索框内容清空按钮'), _t('在搜索框内显示一个清空内容的按钮'));
$form->addInput($isSearchClean);
// 右侧浮动窗
$fk_zmki = new Typecho_Widget_Helper_Form_Element_Radio('fk_zmki', array('0' => _t('禁用'), '1' => _t('启用')), '1', _t('右侧浮动窗'), _t("是否显示右侧浮动窗,包含返回顶部按钮以及手机端的侧栏切换"));
$form->addInput($fk_zmki);
// 网站运行时间
$zmki_time_no = new Typecho_Widget_Helper_Form_Element_Radio('zmki_time_no', array('0' => _t('禁用'), '1' => _t('启用')), '1', _t('网站运行时间'), _t("选择开启即会在网站底部栏显示网站已运行时间。如开启请不要忘记设置下边的创建时间"));
$form->addInput($zmki_time_no);
// 网站创建时间
$zmki_time = new Typecho_Widget_Helper_Form_Element_Text('zmki_time', NULL, '7/1/2022 11:13:14', _t('网站创建时间'), _t('按格式填写创建时间,分别是月/日/年 时:分:秒。默认: 7/1/2022 11:13:14'));
$form->addInput($zmki_time);
}
//输出导航
function themeFields($layout)
{
$url = new Typecho_Widget_Helper_Form_Element_Text('url', NULL, NULL, _t('跳转链接'), _t('请输入跳转的 URL'));
$text = new Typecho_Widget_Helper_Form_Element_Text('text', NULL, NULL, _t('链接描述'), _t('请输入链接描述'));
$logo = new Typecho_Widget_Helper_Form_Element_Text('logo', NULL, NULL, _t('链接 Logo'), _t('请输入 Logo 的 URL'));
$layout->addItem($url);
$layout->addItem($text);
$layout->addItem($logo);
logoPreview();
}
function logoPreview() {
if (!isset($a)) {
static $a = 0;
if ($a == 0) {
$defaultTip = _t('请输入 Logo 的 URL');
$logoTitle = _t('填写 Logo');
$logoDes = _t('请在下方的输入框内输入要填写的 Logo 地址');
$okText = _t('确定');
$cancelText = _t('取消');
echo <<<EOD
<style>
.webstack-theme-preview-span {
float: right;
margin-right: 1%;
}
.webstack-theme-preview-image {
max-width: 54px;
max-height: 54px;
border-radius: 50%;
}
.webstack-wmd-prompt {
position: absolute;
top: 0px;
z-index: 1000;
opacity: 0.5;
height: 100%;
left: 0px;
width: 100%;
}
</style>
<script type="text/javascript">
function webstackImageHandler(imgDom, loadCallback, errorCallback) {
if (imgDom.complete) {
if (typeof loadCallback === 'function') {
loadCallback(imgDom);
}
} else {
imgDom.onload = function () {
if (typeof loadCallback === 'function') {
loadCallback(imgDom);
}
};
imgDom.onerror = function () {
if (typeof errorCallback === 'function') {
errorCallback();
}
};
}
}
function webstackCreateDialog(filename, url, okCallback, cancelCallback) {
const dialogDiv = document.createElement('div');
dialogDiv.className = 'wmd-prompt-dialog';
dialogDiv.setAttribute('role', 'dialog');
const textDiv = document.createElement('div');
textDiv.innerHTML = '<p><b>$logoTitle (' + filename + ')</b></p><p>$logoDes</p>';
const logoForm = document.createElement('form');
const textInput = document.createElement('input');
textInput.type = 'text';
textInput.value = url;
const okBtn = document.createElement('button');
okBtn.type = 'button';
okBtn.className = 'btn btn-s primary';
okBtn.textContent = '$okText';
okBtn.addEventListener('click', e => {
e.stopPropagation();
if (typeof okCallback === 'function') {
okCallback(textInput);
}
dialogDiv && dialogDiv.remove();
});
const cancelBtn = document.createElement('button');
cancelBtn.type = 'button';
cancelBtn.className = 'btn btn-s';
cancelBtn.textContent = '$cancelText';
cancelBtn.addEventListener('click', e => {
e.stopPropagation();
if (typeof cancelCallback === 'function') {
cancelCallback();
}
dialogDiv && dialogDiv.remove();
})
logoForm.appendChild(textInput);
logoForm.appendChild(okBtn);
logoForm.appendChild(cancelBtn);
dialogDiv.appendChild(textDiv);
dialogDiv.appendChild(logoForm);
return dialogDiv;
}
function webstackCreatePrompt() {
const prompt = document.createElement('div');
prompt.className = 'wmd-prompt-background webstack-wmd-prompt';
prompt.style.height = document.body.clientHeight + 'px';
return prompt;
}
window.onload = function() {
const logoInput = document.querySelector('input[name="fields[logo]"]');
if (logoInput) {
const defaultTip = "$defaultTip";
const previewSpan = document.createElement('span');
previewSpan.className = 'webstack-theme-preview-span';
const img = document.createElement('img');
img.className = 'webstack-theme-preview-image';
img.width = 54;
img.src = logoInput.value;
const p = logoInput.parentNode.querySelector('.description');
if (logoInput.value.length === 0) {
img.style.display = 'none';
} else {
webstackImageHandler(
img,
imgDom => {
p.textContent = '( ' + imgDom.naturalWidth + ' x ' + imgDom.naturalHeight + ' )';
},
() => {
img.style.display = 'none';
p.textContent = defaultTip;
}
);
}
previewSpan.appendChild(img);
logoInput.after(previewSpan);
logoInput.addEventListener('change', e => {
img.src = e.target.value;
if (e.target.value) {
img.style.display = 'block';
webstackImageHandler(
img,
imgDom => {
p.textContent = '( ' + imgDom.naturalWidth + ' x ' + imgDom.naturalHeight + ' )';
},
() => {
img.style.display = 'none';
p.textContent = defaultTip;
}
);
} else {
img.style.display = 'none';
p.textContent = defaultTip;
}
});
if (window.Typecho && window.Typecho.insertFileToEditor) {
window.Typecho.insertFileToEditor = function(file, url, _isImage) {
const prompt = webstackCreatePrompt();
const dialog = webstackCreateDialog(file, url, textInput => {
logoInput.value = textInput.value;
img.src = logoInput.value;
if (logoInput.value.length === 0) {
img.style.display = 'none';
p.textContent = defaultTip;
} else {
img.style.display = 'block';
webstackImageHandler(
img,
imgDom => {
p.textContent = '( ' + imgDom.naturalWidth + ' x ' + imgDom.naturalHeight + ' )';
},
() => {
img.style.display = 'none';
p.textContent = defaultTip;
}
);
}
prompt && prompt.remove();
}, () => {
prompt && prompt.remove();
});
setTimeout(() => {
document.body.appendChild(prompt);
document.body.appendChild(dialog);
}, 0);
}
}
}
};
</script>
EOD;
}
$a++;
}
}