Skip to content

Commit

Permalink
Merge pull request #95 from youranreus/dev3.0
Browse files Browse the repository at this point in the history
version 3.3.9
  • Loading branch information
youranreus authored Feb 5, 2023
2 parents 74783a1 + 0a92ea3 commit 94ad4cd
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 51 deletions.
3 changes: 2 additions & 1 deletion components/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
katex: <?php echo $this->options->enableKatex == 1 ? 'true' : 'false' ?>,
imgUrl: "<?php echo G::staticUrl('static/img/'); ?>",
autoTOC: <?php echo G::$config["enableDefaultTOC"] == 1 ? 'true' : 'false' ?>,
nightSpan: "<?php echo G::$config["autoNightSpan"]; ?>"
nightSpan: "<?php echo G::$config["autoNightSpan"]; ?>",
nightMode: "<?php echo G::$config["autoNightMode"]; ?>",
};

function custom_callback() {
Expand Down
93 changes: 51 additions & 42 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ function makeBackup($db, $hasBackup) {

$rows = $db->query($query);

return $rows
? ['msg' => $hasBackup ? '备份已经成功更新' : '备份成功', 'refresh' => true]
: ['msg' => '备份失败', 'refresh' => false];
return ['msg' => $hasBackup ? '备份已经成功更新' : '备份成功', 'refresh' => true];
}

/**
Expand All @@ -61,9 +59,7 @@ function restoreBackup($db, $hasBackup) {
$update = $db->update('table.options')->rows(array('value' => $backupConfig))->where('name = ?', 'theme:G');
$updateRows = $db->query($update);

return $updateRows
? ['msg' => '恢复成功', 'refresh' => true]
: ['msg' => '恢复失败', 'refresh' => false];
return ['msg' => '恢复成功', 'refresh' => true];
}

/**
Expand All @@ -76,9 +72,46 @@ function deleteBackup($db, $hasBackup) {
$delete = $db->delete('table.options')->where('name = ?', 'theme:'.G::$themeBackup);
$deletedRows = $db->query($delete);

return $deletedRows
? ['msg' => '删除成功', 'refresh' => true]
: ['msg' => '删除失败', 'refresh' => false];
return ['msg' => '删除成功', 'refresh' => true];
}

/**
* 备份主方法
*/
function backup() {
$db = Typecho_Db::get();
$hasBackup = hasBackup($db);
if (isset($_POST['type'])) {
$result = [];
switch($_POST['type']) {
case '创建备份':
case '更新备份':
$result = makeBackup($db, $hasBackup);
break;
case '恢复备份':
$result = restoreBackup($db, $hasBackup);
break;
case '删除备份':
$result = deleteBackup($db, $hasBackup);
break;
default:
$result = ["msg" => "", "refresh" => false];
break;
}
if ($result["msg"])
backupNotice($result["msg"], $result["refresh"]);
}
echo '
<div id="backup">
<form class="protected Data-backup" action="?'.G::$themeBackup.'" method="post">
<h4>数据备份</h4>
<p style="opacity: 0.5">'.($hasBackup ? '当前已有备份' : '当前暂无备份').',你可以选择</p>
<input type="submit" name="type" class="btn btn-s" value="'.($hasBackup ? '更新备份' : '创建备份').'" />&nbsp;&nbsp;
'.($hasBackup ? '<input type="submit" name="type" class="btn btn-s" value="恢复备份" />&nbsp;&nbsp;' : '').'
'.($hasBackup ? '<input type="submit" name="type" class="btn btn-s" value="删除备份" />' : '').'
</form>
</div>
';
}

function themeConfig($form)
Expand Down Expand Up @@ -152,6 +185,14 @@ function themeConfig($form)
$autoNightSpan = new Typecho_Widget_Helper_Form_Element_Text('autoNightSpan', null, '23-6', _t('自动夜间模式时间段'), _t('24小时制,当前晚上x点到第二天早上y点视为夜间,需要自动开启夜间模式,例: 23-6'));
$form->addInput($autoNightSpan);

$autoNightMode = new Typecho_Widget_Helper_Form_Element_Radio('autoNightMode', array(
'3' => _t('跟随系统'),
'2' => _t('自定义时间段'),
'1' => _t('同时开启'),
'0' => _t('关闭')
), '3', _t('自动夜间模式控制模式'), _t('默认为跟随系统'));
$form->addInput($autoNightMode);

$enableDefaultTOC = new Typecho_Widget_Helper_Form_Element_Radio('enableDefaultTOC', array(
'1' => _t('开启'),
'0' => _t('关闭')
Expand Down Expand Up @@ -222,39 +263,7 @@ function themeConfig($form)
$advanceSetting = new Typecho_Widget_Helper_Form_Element_Textarea('advanceSetting', null, null, _t('高级设置'), _t('看着就很高级'));
$form->addInput($advanceSetting);

$db = Typecho_Db::get();
$hasBackup = hasBackup($db);
if (isset($_POST['type'])) {
$result = [];
switch($_POST['type']) {
case '创建备份':
case '更新备份':
$result = makeBackup($db, $hasBackup);
break;
case '恢复备份':
$result = restoreBackup($db, $hasBackup);
break;
case '删除备份':
$result = deleteBackup($db, $hasBackup);
break;
default:
$result = ["msg" => "", "refresh" => false];
break;
}
if ($result["msg"])
backupNotice($result["msg"], $result["refresh"]);
}
echo '
<div id="backup">
<form class="protected Data-backup" action="?'.G::$themeBackup.'" method="post">
<h4>数据备份</h4>
<p style="opacity: 0.5">'.($hasBackup ? '当前已有备份' : '当前暂无备份').',你可以选择</p>
<input type="submit" name="type" class="btn btn-s" value="'.($hasBackup ? '更新备份' : '创建备份').'" />&nbsp;&nbsp;
'.($hasBackup ? '<input type="submit" name="type" class="btn btn-s" value="恢复备份" />&nbsp;&nbsp;' : '').'
'.($hasBackup ? '<input type="submit" name="type" class="btn btn-s" value="删除备份" />' : '').'
</form>
</div>
';
backup();
}


Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package G
* @author 季悠然
* @version 3.3.8
* @link https://季悠然.space
* @version 3.3.9
* @link https://mitsuha.space
*/

if (!defined('__TYPECHO_ROOT_DIR__')) exit;
Expand Down
5 changes: 3 additions & 2 deletions libs/G.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class G
*
* @var string
*/
public static $version = "3.3.8";
public static $version = "3.3.9";

/**
* 主题配置
Expand All @@ -35,7 +35,8 @@ class G
'footerLOGO' => '',
'enableUPYUNLOGO' => '',
'enableDefaultTOC' => '',
'autoNightSpan' => ''
'autoNightSpan' => '',
'autoNightMode' => '',
];

public static $advanceConfig = [];
Expand Down
2 changes: 1 addition & 1 deletion static/css/G.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/css/G.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/css/G.less
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ footer {
font-size: 0.875rem;
z-index: 2;
position: relative;
word-wrap: break-word;
}
}

Expand Down
11 changes: 10 additions & 1 deletion static/js/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@ let darkModeToggle = () => {
*/
let autoDarkMode = () => {
const [start, end] = window.G_CONFIG.nightSpan.split('-');
if ((new Date().getHours() >= parseInt(start) || new Date().getHours() < parseInt(end)) || (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches))
const nightMode = window.G_CONFIG.nightMode;
const nightModeMap = {
'3': window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches,
'2': new Date().getHours() >= parseInt(start) || new Date().getHours() < parseInt(end),
'1': (new Date().getHours() >= parseInt(start) || new Date().getHours() < parseInt(end)) || (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches),
};

if (nightMode === '0' || !Object.keys(nightModeMap).includes(nightMode)) return;

if (nightModeMap[nightMode])
document.querySelector('link[title="dark"]').disabled = false;
else
document.querySelector('link[title="dark"]').disabled = true;
Expand Down
2 changes: 1 addition & 1 deletion static/js/G.min.js

Large diffs are not rendered by default.

0 comments on commit 94ad4cd

Please sign in to comment.