summaryrefslogtreecommitdiffstats
path: root/libs/Options.php
blob: 3c85edeaaa869f208347cd59eaf8944db98123b5 (plain)
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
<?php
/**
 * 主题后台设置
 */
function themeConfig($form) {
	/**
	 *  主题设置备份 
	 *  From https://qqdie.com/archives/typecho-templates-backup-and-restore.html
	 */
	$db = Typecho_Db::get();
    $sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:Miracles'));
    $ysj = $sjdq['value'];
    if(isset($_POST['type'])){ 
      if($_POST["type"]=="备份模板数据"){
        if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:MiraclesBackup'))){
          $update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:MiraclesBackup');
          $updateRows= $db->query($update);
          echo '<div class="miracles-backup-alert">备份已更新,请等待自动刷新!如果等不到请点击';
?><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:MiraclesBackup','user' => '0','value' => $ysj));
      $insertId = $db->query($insert);
      echo '<div class="miracles-backup-alert">备份完成,请等待自动刷新!如果等不到请点击';
?><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->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:MiraclesBackup'))){
    $sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:MiraclesBackup'));
    $bsj = $sjdub['value'];
    $update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:Miracles');
    $updateRows= $db->query($update);
    echo '<div class="miracles-backup-alert">检测到模板备份数据,恢复完成,请等待自动刷新!如果等不到请点击';
?><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="miracles-backup-alert">没有模板备份数据,恢复不了哦!</div>';
    }
    }
    if($_POST["type"]=="删除备份数据"){
      if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:MiraclesBackup'))){
        $delete = $db->delete('table.options')->where ('name = ?', 'theme:MiraclesBackup');
        $deletedRows = $db->query($delete);
        echo '<div class="miracles-backup-alert">删除成功,请等待自动刷新,如果等不到请点击';
?><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="miracles-backup-alert">不用删了!备份不存在!!!</div>';
    }
  }
}

    /**
	 *  设置样式+面板
	 */
	$ver = themeVersion();
	 
	echo '<link rel="stylesheet" href="/usr/themes/Miracles/assets/css/setting.miracles.css"><link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC:300|Noto+Serif+SC:300&display=swap" rel="stylesheet">';
	echo '<div class="miracles-pannel">
	<h1>Miracles 主题设置面板</h1>
	<p>欢迎使用 Miracles 主题,目前版本是:'. $ver .'</span><br>
	作者博客:<a href="https://guhub.cn">Eltrac\'s</a> | 帮助文档:<a href="https://github.com/BigCoke233/miracles/wiki">WIKI</a> | 问题反馈:<a href="https://github.com/BigCoke233/miracles/issues">issues</a></p>
	<iframe class="miracles-news" src="https://gu.guhub.cn/news.html"></iframe>
   	  <form class="protected" action="?MiraclesBackup" method="post">
        <input type="submit" name="type" class="miracles-backup-button backup" value="备份模板数据" />&nbsp;&nbsp;
	    <input type="submit" name="type" class="miracles-backup-button recover" value="还原模板数据" />&nbsp;&nbsp;
	    <input type="submit" name="type" class="miracles-backup-button delete" value="删除备份数据" />
	  </form>
	</div>';
	
	/**
	 *  设置项
	 */
	//首要设置项
	$news = new Typecho_Widget_Helper_Form_Element_Text('news', NULL, NULL, _t('<h2>首要设置 First</h2>全站公告'), _t('输入公告内容,用户进入站点时自动弹出'));
    $form->addInput($news);
	
    //nav
	$navStyle = new Typecho_Widget_Helper_Form_Element_Select('navStyle',array('0'=>'顶部导航栏','1'=>'左侧抽屉蓝'),'0','<h2>导航栏 Nav</h2>类型','选择导航栏的类型(若选择左侧抽屉蓝,则下一条设置失效)');
    $form->addInput($navStyle);
	$nav_position = new Typecho_Widget_Helper_Form_Element_Select('nav_position',array('0'=>'不固定','1'=>'固定'),'0','是否固定','固定后,导航栏不会随滚动条滚动而移动在屏幕上的位置<hr>');
    $form->addInput($nav_position);
	
	//index-banner
	$bannerUrl = new Typecho_Widget_Helper_Form_Element_Text('bannerUrl', NULL, 'https://s2.ax1x.com/2019/07/10/ZcRGX8.png', _t('<h2>首页大图 Banner</h2>图片 Url'), _t('首页大图的图片地址'));
    $form->addInput($bannerUrl);
	$bannerHeight = new Typecho_Widget_Helper_Form_Element_Text('bannerHeight', NULL, '60', _t('高度'), _t('首页大图所占屏幕的高度,100为最大,填入纯数字,如"35"'));
    $form->addInput($bannerHeight);
	$bannerTitle = new Typecho_Widget_Helper_Form_Element_Text('bannerTitle', NULL, NULL, _t('标题'), _t('这里是首页大图显示的的标题'));
    $form->addInput($bannerTitle);
	$bannerIntro = new Typecho_Widget_Helper_Form_Element_Text('bannerIntro', NULL, NULL, _t('介绍'), _t('这里是首页大图标题下的简介<hr>'));
    $form->addInput($bannerIntro);
	
	//pjax
	$pjax = new Typecho_Widget_Helper_Form_Element_Select('pjax',array('0'=>'关闭','1'=>'开启'),'1','<h2>Pjax 预加载</h2>是否开启','Pjax 预加载功能的开关');
    $form->addInput($pjax);
	$pjax_complete = new Typecho_Widget_Helper_Form_Element_Textarea('pjax_complete', NULL, NULL, _t('完成后执行事件'), _t('Pjax 跳转页面后执行的事件,写入 js 代码,一般将 Pjax 重载(回调)函数写在这里。<hr>'));
    $form->addInput($pjax_complete);
	
	//improve
	$CDN = new Typecho_Widget_Helper_Form_Element_Select('CDN',array('0'=>'关闭','1'=>'开启'),'0','<h2>优化</h2>CDN 加速加载静态资源','开启后静态资源文件调用 JSdelivr 的 CDN 公用库,加快网页加载速度。本身有 CDN 的就不用了,不然反而可能会拖慢速度。<hr>');
    $form->addInput($CDN);
	
	//custom style
	$grayTheme = new Typecho_Widget_Helper_Form_Element_Select('grayTheme',array('0'=>'关闭','1'=>'开启'),'0','<h2>个性化</h2>哀悼模式','为京阿尼纵火时间而设计的开关,打开后网站变为黑白,Pray for 京阿尼');
    $form->addInput($grayTheme);
	$bodyFonts = new Typecho_Widget_Helper_Form_Element_Select('bodyFonts',array('0'=>'无衬线字体','1'=>'衬线字体'),'0','网站字体','选择网站的字体,无衬线字体即“思源黑体”,衬线字体即“思源宋体”');
    $form->addInput($bodyFonts);
	$cat = new Typecho_Widget_Helper_Form_Element_Select('cat',array('0'=>'不要','1'=>'小黑','2'=>'小白'),'0','领养猫咪','领养一只猫咪,这样你就可以在前台看到它啦!<hr>');
    $form->addInput($cat);
	
	//developer
	$headerEcho = new Typecho_Widget_Helper_Form_Element_Textarea('headerEcho', NULL, NULL, _t('<h2>开发者设置</h2>自定义头部信息'), _t('填写 html 代码,将输出在 &lt;head&gt; 标签中'));
    $form->addInput($headerEcho);
	$footerEcho = new Typecho_Widget_Helper_Form_Element_Textarea('footerEcho', NULL, NULL, _t('自定义页脚部信息'), _t('填写 html 代码,将输出在页脚的版权信息后'));
    $form->addInput($footerEcho);
	$cssEcho = new Typecho_Widget_Helper_Form_Element_Textarea('cssEcho', NULL, NULL, _t('自定义 CSS'), _t('填写 CSS 代码,输出在 head 标签结束之前的 style 标签内'));
    $form->addInput($cssEcho);
	$jsEcho = new Typecho_Widget_Helper_Form_Element_Textarea('jsEcho', NULL, NULL, _t('自定义 JavaScript'), _t('填写 JavaScript代码,输出在 body 标签结束之前'));
    $form->addInput($jsEcho);
}