Skip to content

Commit

Permalink
Merge pull request #94 from youranreus/dev3.0
Browse files Browse the repository at this point in the history
version 3.3.8
  • Loading branch information
youranreus authored Feb 4, 2023
2 parents 2278bd5 + fb2693e commit 74783a1
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 65 deletions.
2 changes: 1 addition & 1 deletion components/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<script src="<?php echo G::staticUrl("static/js/toastify.min.js"); ?>?v=3.211"></script>
<script src="<?php echo G::staticUrl("static/js/tocbot.min.js"); ?>?v=3.211"></script>
<script src="<?php echo G::staticUrl("static/js/lib$minInfix.js?v=$devTag"); ?>"></script>
<script src="<?php echo G::staticUrl("static/js/prism.js"); ?>?v=1.03" data-manual></script>
<script src="<?php echo G::staticUrl("static/js/prism.js?v=$devTag"); ?>" data-manual></script>
<script src="<?php echo G::staticUrl("static/js/G$minInfix.js?v=$devTag"); ?>"></script>
<script>
<?php $this->options->customFooterJS(); ?>
Expand Down
2 changes: 1 addition & 1 deletion components/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
foreach($widgets as $w)
{
switch ($w->type)
switch ($w->type ?? $w->name)
{
case 'photo':
echo '
Expand Down
155 changes: 98 additions & 57 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,75 @@
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('GEditor', 'wordCounter');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('GEditor', 'wordCounter');

/**
* 是否存在备份
*/
function hasBackup($db) {
return $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:'.G::$themeBackup));
}

/**
* 备份完成提示
*/
function backupNotice($msg, $refresh = true) {
$content = $msg.''.($refresh ? ',即将自动刷新' : '');
if ($refresh) {
$url = Helper::options()->adminUrl.'options-theme.php';
$content .= '
<a href="'.$url.'">手动刷新</a>
<script language="JavaScript">window.setTimeout("location=\''.$url.'\'", 2500);</script>
';
}

echo '<div class="backup-notice">'.$content.'</div>';
}

/**
* 备份操作
*/
function makeBackup($db, $hasBackup) {
$currentConfig = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:G'))['value'];
$query = $hasBackup
? $db->update('table.options')->rows(array('value' => $currentConfig))->where('name = ?', 'theme:'.G::$themeBackup)
: $db->insert('table.options')->rows(array('name' => 'theme:'.G::$themeBackup, 'user' => '0', 'value' => $currentConfig));

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

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

/**
* 恢复备份
*/
function restoreBackup($db, $hasBackup) {
if (!$hasBackup)
return ['msg' => '没有模板备份数据,恢复不了哦!', 'refresh' => false];

$backupConfig = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:'.G::$themeBackup))['value'];
$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];
}

/**
* 删除备份
*/
function deleteBackup($db, $hasBackup) {
if (!$hasBackup)
return ['msg' => '没有模板备份数据哦', 'refresh' => false];

$delete = $db->delete('table.options')->where('name = ?', 'theme:'.G::$themeBackup);
$deletedRows = $db->query($delete);

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

function themeConfig($form)
{
Expand Down Expand Up @@ -154,66 +223,38 @@ function themeConfig($form)
$form->addInput($advanceSetting);

$db = Typecho_Db::get();
$sjdq = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:G'));
$ysj = $sjdq['value'];
$hasBackup = hasBackup($db);
if (isset($_POST['type'])) {
if ($_POST["type"] == "备份模板数据") {
if ($db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:Gbf'))) {
$update = $db->update('table.options')->rows(array('value' => $ysj))->where('name = ?', 'theme:Gbf');
$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:Gbf', '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->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:Gbf'))) {

$sjdub = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:Gbf'));
$bsj = $sjdub['value'];
$update = $db->update('table.options')->rows(array('value' => $bsj))->where('name = ?', 'theme:G');
$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->fetchRow($db->select()->from('table.options')->where('name = ?', 'theme:Gbf'))) {
$delete = $db->delete('table.options')->where('name = ?', 'theme:Gbf');
$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>';
}
$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="?Gbf" method="post"><h4>数据备份</h4>
<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></div>';
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>
';
}


Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package G
* @author 季悠然
* @version 3.3.7
* @version 3.3.8
* @link https://季悠然.space
*/

Expand Down
4 changes: 3 additions & 1 deletion 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.7";
public static $version = "3.3.8";

/**
* 主题配置
Expand Down Expand Up @@ -42,6 +42,8 @@ class G

public static $themeUrl = '';

public static $themeBackup = 'Gbf';

/**
* 初始化
*
Expand Down
2 changes: 1 addition & 1 deletion post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
if (isset($_POST['agree'])) {
if ($_POST['agree'] == $this->cid)
exit(G::agree($this->cid));
exit((string)G::agree($this->cid));
exit('error');
}
$agree = $this->hidden ? array('agree' => 0, 'recording' => true) : G::agreeNum($this->cid);
Expand Down
2 changes: 1 addition & 1 deletion static/css/Admin/S.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified static/img/loading2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion static/js/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ let makePrismLineNum = () => {
if (ele.length > 0)
for (let element of ele)
element.className = element.className + " line-numbers";

// 适配c++
// 真的是吐了,把+号塞类名里,就这样吧
document.querySelectorAll('code[class="c++"]')?.forEach((cpp) => {
cpp.className = 'lang-cpp';
})

if (typeof Prism !== "undefined") {
Prism.highlightAll(true, null);
}
Expand Down Expand Up @@ -187,7 +194,7 @@ let darkModeToggle = () => {
*/
let autoDarkMode = () => {
const [start, end] = window.G_CONFIG.nightSpan.split('-');
if (new Date().getHours() >= parseInt(start) || new Date().getHours() < parseInt(end))
if ((new Date().getHours() >= parseInt(start) || new Date().getHours() < parseInt(end)) || (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches))
document.querySelector('link[title="dark"]').disabled = false;
else
document.querySelector('link[title="dark"]').disabled = true;
Expand Down
Loading

0 comments on commit 74783a1

Please sign in to comment.