王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

Typecho 模板设置数据备份与恢复

Typecho 模板设置数据备份与恢复


Typecho模板设置数据会在你换模板的时刻被清空,如许的设置实在我照样蛮喜好的,不会有数据残留。
然则有些朋侪可能会愿望保存数据,如许下次在切换返来以后数据就保存了。

代码

在themeConfig($form)函数里增加

$db = Typecho_Db::get();$sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodu'));$ysj = $sjdq['value'];if(isset($_POST['type'])){ if($_POST["type"]=="备份模板数据"){if($db-&gt;fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'))){$update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:Yodubf');$updateRows= $db->query($update);echo '<div class="tongzhi">备份已更新,请守候自动革新!假如等不到请点击';?>    <a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div><script language="JavaScript">window.setTimeout("location='<?php Helper::options()->adminUrl('options-theme.php'); ?>'", 2500);</script><?php}else{if($ysj){     $insert = $db->insert('table.options')    ->rows(array('name' => 'theme:Yodubf','user' => '0','value' => $ysj));     $insertId = $db->query($insert);echo '<div class="tongzhi">备份完成,请守候自动革新!假如等不到请点击';?>    <a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div><script language="JavaScript">window.setTimeout("location='<?php Helper::options()->adminUrl('options-theme.php'); ?>'", 2500);</script><?php}}        }if($_POST["type"]=="复原模板数据"){if($db-&gt;fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'))){$sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'));$bsj = $sjdub['value'];$update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:Yodu');$updateRows= $db->query($update);echo '<div class="tongzhi">检测到模板备份数据,恢复完成,请守候自动革新!假如等不到请点击';?>    <a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div><script language="JavaScript">window.setTimeout("location='<?php Helper::options()->adminUrl('options-theme.php'); ?>'", 2000);</script><?php}else{echo '<div class="tongzhi">没有模板备份数据,恢复不了哦!</div>';}}if($_POST["type"]=="删除备份数据"){if($db-&gt;fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Yodubf'))){$delete = $db->delete('table.options')->where ('name = ?', 'theme:Yodubf');$deletedRows = $db->query($delete);echo '<div class="tongzhi">删除胜利,请守候自动革新,假如等不到请点击';?>    <a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div><script language="JavaScript">window.setTimeout("location='<?php Helper::options()->adminUrl('options-theme.php'); ?>'", 2500);</script><?php}else{echo '<div class="tongzhi">不必删了!备份不存在!!!</div>';}}    }echo '<span style="font-weight: bold;font-size: 16px;">高等操纵:</span><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="删除备份数据" />';


相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。