Skip to content

Commit a9963e5

Browse files
committed
完善模板设置数据备份功能代码
1 parent 9bda75b commit a9963e5

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ Typecho 是由两个单词 type 和 echo 组成的,在发音的时候也发这
1919
或者github提交修改:https://github.com/jrotty/jrotty.github.io
2020

2121
再或者[点击这里进行留言](https://qqdie.com/typecho-doc.html)
22+
23+
**最近维护时间**
24+
25+
2020年4月17日

post/模板设置数据备份与恢复.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,70 @@
1111
`themeConfig($form)`函数里添加
1212

1313
```php
14+
$str1 = explode('/themes/', Helper::options()->themeUrl);
15+
$str2 = explode('/', $str1[1]);
16+
$name=$str2[0];//获取到模板文件夹名字也就是模板在数据库中的名字
1417
$db = Typecho_Db::get();
15-
$sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodu'));
18+
$sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name));
1619
$ysj = $sjdq['value'];
1720
if(isset($_POST['type']))
1821
{
19-
if($_POST["type"]=="备份模板数据"){
20-
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'))){
21-
$update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:Yodubf');
22+
if($_POST["type"]=="备份模板设置数据"){
23+
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'))){
24+
$update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:'.$name.'bf');
2225
$updateRows= $db->query($update);
23-
echo '<div class="tongzhi">备份已更新,请等待自动刷新!如果等不到请点击';
26+
echo '<div class="tongzhi col-mb-12 home">备份已更新,请等待自动刷新!如果等不到请点击';
2427
?>
2528
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
2629
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);</script>
2730
<?php
2831
}else{
2932
if($ysj){
3033
$insert = $db->insert('table.options')
31-
->rows(array('name' => 'theme:Yodubf','user' => '0','value' => $ysj));
34+
->rows(array('name' => 'theme:'.$name.'bf','user' => '0','value' => $ysj));
3235
$insertId = $db->query($insert);
33-
echo '<div class="tongzhi">备份完成,请等待自动刷新!如果等不到请点击';
36+
echo '<div class="tongzhi col-mb-12 home">备份完成,请等待自动刷新!如果等不到请点击';
3437
?>
3538
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
3639
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);</script>
3740
<?php
3841
}
3942
}
4043
}
41-
if($_POST["type"]=="还原模板数据"){
42-
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'))){
43-
$sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'));
44+
if($_POST["type"]=="还原模板设置数据"){
45+
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'))){
46+
$sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'));
4447
$bsj = $sjdub['value'];
45-
$update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:Yodu');
48+
$update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:'.$name);
4649
$updateRows= $db->query($update);
47-
echo '<div class="tongzhi">检测到模板备份数据,恢复完成,请等待自动刷新!如果等不到请点击';
50+
echo '<div class="tongzhi col-mb-12 home">检测到模板备份数据,恢复完成,请等待自动刷新!如果等不到请点击';
4851
?>
4952
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
5053
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2000);</script>
5154
<?php
5255
}else{
53-
echo '<div class="tongzhi">没有模板备份数据,恢复不了哦!</div>';
56+
echo '<div class="tongzhi col-mb-12 home">没有模板备份数据,恢复不了哦!</div>';
5457
}
5558
}
5659
if($_POST["type"]=="删除备份数据"){
57-
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'))){
58-
$delete = $db->delete('table.options')->where ('name = ?', 'theme:Yodubf');
60+
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'))){
61+
$delete = $db->delete('table.options')->where ('name = ?', 'theme:'.$name.'bf');
5962
$deletedRows = $db->query($delete);
60-
echo '<div class="tongzhi">删除成功,请等待自动刷新,如果等不到请点击';
63+
echo '<div class="tongzhi col-mb-12 home">删除成功,请等待自动刷新,如果等不到请点击';
6164
?>
6265
<a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div>
6366
<script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);</script>
6467
<?php
6568
}else{
66-
echo '<div class="tongzhi">不用删了!备份不存在!!!</div>';
69+
echo '<div class="tongzhi col-mb-12 home">不用删了!备份不存在!!!</div>';
6770
}
6871
}
6972
}
70-
echo '<form class="protected" action="?yodubf" method="post">
71-
<input type="submit" name="type" class="btn btn-s" value="备份模板数据" />&nbsp;&nbsp;<input type="submit" name="type" class="btn btn-s" value="还原模板数据" />&nbsp;&nbsp;<input type="submit" name="type" class="btn btn-s" value="删除备份数据" /></form>';
73+
echo '<form class="protected home col-mb-12" action="?'.$name.'bf" method="post">
74+
<input type="submit" name="type" class="btn btn-s" value="备份模板设置数据" />&nbsp;&nbsp;<input type="submit" name="type" class="btn btn-s" value="还原模板设置数据" />&nbsp;&nbsp;<input type="submit" name="type" class="btn btn-s" value="删除备份数据" /></form>';
7275
```
7376

74-
然后将里面出现的所有“yodu”改成你的**模板目录文件夹**的名字,如果拿不准就去数据库里看看模板的值名字。【模板目录文件夹名字不要用中文】
77+
【模板目录文件夹名字不要用中文】
7578

7679
**备份**
7780
当用户点击**备份**时,先判断是否已经存在备份,如果不存在就插入一条新的数据,数据name为yodubf,value为模板原本的数据。此时就存在了一条备份数据。

0 commit comments

Comments
 (0)