Browse Source

20220308

pull/47/head
xiaoz 3 years ago
parent
commit
495611ebbb
  1. 47
      class/Api.php
  2. 8
      controller/api.php
  3. 6
      data/update.log
  4. 1
      db/index.html
  5. BIN
      db/onenav.simple.db3
  6. 0
      db/sql/20220101.sql
  7. 0
      db/sql/20220301.sql
  8. 7
      db/sql/20220308.sql
  9. 9
      templates/admin/add_category.php
  10. 10
      templates/admin/edit_category.php
  11. 9
      templates/admin/index.php
  12. 37
      templates/admin/static/embed.js
  13. 5
      templates/default/index.php
  14. 2
      version.txt

47
class/Api.php

@ -15,14 +15,15 @@ class Api {
/** /**
* name:创建分类目录 * name:创建分类目录
*/ */
public function add_category($token,$name,$property = 0,$weight = 0,$description = ''){ public function add_category($token,$name,$property = 0,$weight = 0,$description = '',$font_icon = ''){
$this->auth($token); $this->auth($token);
$data = [ $data = [
'name' => htmlspecialchars($name,ENT_QUOTES), 'name' => htmlspecialchars($name,ENT_QUOTES),
'add_time' => time(), 'add_time' => time(),
'weight' => $weight, 'weight' => $weight,
'property' => $property, 'property' => $property,
'description' => htmlspecialchars($description,ENT_QUOTES) 'description' => htmlspecialchars($description,ENT_QUOTES),
'font_icon' => $font_icon
]; ];
//插入分类目录 //插入分类目录
$this->db->insert("on_categorys",$data); $this->db->insert("on_categorys",$data);
@ -46,7 +47,7 @@ class Api {
* 修改分类目录 * 修改分类目录
* *
*/ */
public function edit_category($token,$id,$name,$property = 0,$weight = 0,$description = ''){ public function edit_category($token,$id,$name,$property = 0,$weight = 0,$description = '',$font_icon = ''){
$this->auth($token); $this->auth($token);
//如果id为空 //如果id为空
if( empty($id) ){ if( empty($id) ){
@ -63,7 +64,8 @@ class Api {
'up_time' => time(), 'up_time' => time(),
'weight' => $weight, 'weight' => $weight,
'property' => $property, 'property' => $property,
'description' => htmlspecialchars($description,ENT_QUOTES) 'description' => htmlspecialchars($description,ENT_QUOTES),
'font_icon' => $font_icon
]; ];
$re = $this->db->update('on_categorys',$data,[ 'id' => $id]); $re = $this->db->update('on_categorys',$data,[ 'id' => $id]);
//var_dump( $this->db->log() ); //var_dump( $this->db->log() );
@ -636,9 +638,13 @@ class Api {
* 循环读取db/sql/目录下的.sql文件 * 循环读取db/sql/目录下的.sql文件
*/ */
public function get_sql_update_list($data) { public function get_sql_update_list($data) {
//待升级的数据库文件目录 //鉴权
if( !$this->is_login() ) {
$this->err_msg(-1002,'Authorization failure!');
}
//待更新的数据库文件目录
$sql_dir = 'db/sql/'; $sql_dir = 'db/sql/';
//sql文件列表,默认为空 //待更新的sql文件列表,默认为空
$sql_files_all = []; $sql_files_all = [];
//打开一个目录,读取里面的文件列表 //打开一个目录,读取里面的文件列表
if (is_dir($sql_dir)){ if (is_dir($sql_dir)){
@ -663,23 +669,28 @@ class Api {
if ( $num === 0 ) { if ( $num === 0 ) {
$data = [ $data = [
"code" => 0, "code" => 0,
"data" => ['on_db_logs'] "data" => ['on_db_logs.sql']
]; ];
exit(json_encode($data)); exit(json_encode($data));
}else{ }else{
//如果不为0,则需要进行比对 //如果不为0,则需要查询数据库更新表里面的数据进行差集比对
$get_on_db_logs = $this->db->select("on_db_logs",[ $get_on_db_logs = $this->db->select("on_db_logs",[
"sql_name" "sql_name"
],[ ],[
"status" => "TRUE" "status" => "TRUE"
]); ]);
//声明一个空数组,存储已更新的数据库 //声明一个空数组,存储已更新的数据库列表
$already_dbs = []; $already_dbs = [];
foreach ($get_on_db_logs as $key => $value) { foreach ($get_on_db_logs as $value) {
array_push($already_dbs,$value['sql_name']); array_push($already_dbs,$value['sql_name']);
} }
//array_diff() 函数返回两个数组的差集数组 //array_diff() 函数返回两个数组的差集数组
$diff_result = array_diff($sql_files_all,$already_dbs); $diff_result = array_diff($sql_files_all,$already_dbs);
//去掉键
$diff_result = array_values($diff_result);
sort($diff_result);
$data = [ $data = [
"code" => 0, "code" => 0,
"data" => $diff_result "data" => $diff_result
@ -692,13 +703,17 @@ class Api {
* 执行SQL更新语句,只执行单条更新 * 执行SQL更新语句,只执行单条更新
*/ */
public function exe_sql($data) { public function exe_sql($data) {
//鉴权
if( !$this->is_login() ) {
$this->err_msg(-1002,'Authorization failure!');
}
//数据库sql目录 //数据库sql目录
$sql_dir = 'db/sql/'; $sql_dir = 'db/sql/';
$name = $data['name']; $name = $data['name'];
$sql_name = $sql_dir.$name.'.sql'; $sql_name = $sql_dir.$name;
//如果文件不存在,直接返回错误 //如果文件不存在,直接返回错误
if ( !file_exists($sql_name) ) { if ( !file_exists($sql_name) ) {
$this->err_msg(-2000,$name.'.sql不存在!'); $this->err_msg(-2000,$name.'不存在!');
} }
//读取需要更新的SQL内容 //读取需要更新的SQL内容
try { try {
@ -708,24 +723,24 @@ class Api {
if( $result ) { if( $result ) {
//将更新信息写入数据库 //将更新信息写入数据库
$insert_re = $this->db->insert("on_db_logs",[ $insert_re = $this->db->insert("on_db_logs",[
"sql_name" => $name.'.sql', "sql_name" => $name,
"update_time" => time() "update_time" => time()
]); ]);
if( $insert_re ) { if( $insert_re ) {
$data = [ $data = [
"code" => 0, "code" => 0,
"data" => $name.".sql更新完成!" "data" => $name."更新完成!"
]; ];
exit(json_encode($data)); exit(json_encode($data));
} }
else { else {
$this->err_msg(-2000,$name.".sql更新失败,请人工检查!"); $this->err_msg(-2000,$name."更新失败,请人工检查!");
} }
} }
else{ else{
//如果执行失败 //如果执行失败
$this->err_msg(-2000,$name.".sql更新失败,请人工检查!"); $this->err_msg(-2000,$name."更新失败,请人工检查!");
} }
} catch(Exception $e){ } catch(Exception $e){
$this->err_msg(-2000,$e->getMessage()); $this->err_msg(-2000,$e->getMessage());

8
controller/api.php

@ -84,7 +84,9 @@ function add_category($api){
$description = empty($_POST['description']) ? '' : $_POST['description']; $description = empty($_POST['description']) ? '' : $_POST['description'];
//描述过滤 //描述过滤
$description = htmlspecialchars($description); $description = htmlspecialchars($description);
$api->add_category($token,$name,$property,$weight,$description); //获取字体图标
$font_icon = htmlspecialchars($_POST['font_icon'],ENT_QUOTES);
$api->add_category($token,$name,$property,$weight,$description,$font_icon);
} }
/** /**
* 修改分类目录入口 * 修改分类目录入口
@ -105,7 +107,9 @@ function edit_category($api){
$description = empty($_POST['description']) ? '' : $_POST['description']; $description = empty($_POST['description']) ? '' : $_POST['description'];
//描述过滤 //描述过滤
$description = htmlspecialchars($description); $description = htmlspecialchars($description);
$api->edit_category($token,$id,$name,$property,$weight,$description); //字体图标
$font_icon = htmlspecialchars($_POST['font_icon'],ENT_QUOTES);
$api->edit_category($token,$id,$name,$property,$weight,$description,$font_icon);
} }
/** /**
* 删除分类目录 * 删除分类目录

6
data/update.log

@ -44,5 +44,7 @@ CREATE INDEX on_options_key_IDX ON on_options ("key");
2. API新增查询单个链接信息get_a_link 2. API新增查询单个链接信息get_a_link
3. API支持查询指定分类下的链接link_list,传递参数category_id 3. API支持查询指定分类下的链接link_list,传递参数category_id
20220307 20220308
1. 数据库SQL更新API(尚未写完,下班了,先提交) 1. 新增数据库更新功能
2. 初始数据库更新
3. 分离分类图标字体设置

1
db/index.html

@ -0,0 +1 @@

BIN
db/onenav.simple.db3

Binary file not shown.

0
db/sql/20220101.sql

0
db/sql/20220301.sql

7
db/sql/20220308.sql

@ -0,0 +1,7 @@
-- 分类目录增加字体图标列
ALTER TABLE on_categorys ADD font_icon TEXT(32);
-- 链接表新增字段topping,默认值0(不置顶),1为置顶,先保留后续使用
ALTER TABLE on_links ADD topping INTEGER DEFAULT 0 NOT NULL;
-- 增加一个备用链接字段
ALTER TABLE on_links ADD url_standby TEXT(256);

9
templates/admin/add_category.php

@ -12,6 +12,14 @@
<input type="text" name="name" required lay-verify="required" placeholder="请输入分类名称" autocomplete="off" class="layui-input"> <input type="text" name="name" required lay-verify="required" placeholder="请输入分类名称" autocomplete="off" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item">
<label class="layui-form-label">字体图标</label>
<div class="layui-input-block">
<input type="text" name="font_icon" placeholder="请输入字体图标,如:fa fa-bookmark-o" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">权重</label> <label class="layui-form-label">权重</label>
<div class="layui-input-block"> <div class="layui-input-block">
@ -40,6 +48,7 @@
</div> </div>
</div> </div>
</form> </form>
<p>关于字体图标的说明请参考帮助文档:<a href="https://dwz.ovh/7nr1f" target = "_blank" title = "字体图标使用说明">https://dwz.ovh/7nr1f</a></p>
</div> </div>
</div> </div>

10
templates/admin/edit_category.php

@ -18,6 +18,14 @@
<input type="text" name="name" required lay-verify="required" value = '<?php echo $category['name']; ?>' placeholder="请输入分类名称" autocomplete="off" class="layui-input"> <input type="text" name="name" required lay-verify="required" value = '<?php echo $category['name']; ?>' placeholder="请输入分类名称" autocomplete="off" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item">
<label class="layui-form-label">字体图标</label>
<div class="layui-input-block">
<input type="text" name="font_icon" value = '<?php echo $category['font_icon']; ?>' placeholder="请输入字体图标,如:fa fa-bookmark-o" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">权重</label> <label class="layui-form-label">权重</label>
<div class="layui-input-block"> <div class="layui-input-block">
@ -46,9 +54,11 @@
</div> </div>
</div> </div>
</form> </form>
<p>关于字体图标的说明请参考帮助文档:<a href="https://dwz.ovh/7nr1f" target = "_blank" title = "字体图标使用说明">https://dwz.ovh/7nr1f</a></p>
</div> </div>
</div> </div>
<!-- 内容主题区域END --> <!-- 内容主题区域END -->
</div> </div>

9
templates/admin/index.php

@ -34,6 +34,14 @@
<div class="layui-col-lg4"> <div class="layui-col-lg4">
<div class = "admin-msg">捐赠地址: <a href="https://dwz.ovh/donation" rel = "nofollow" target="_blank">https://dwz.ovh/donation</a></div> <div class = "admin-msg">捐赠地址: <a href="https://dwz.ovh/donation" rel = "nofollow" target="_blank">https://dwz.ovh/donation</a></div>
</div> </div>
<!-- 日志输出窗口 -->
<div class="layui-col-lg12">
<p><h3 style = "padding-bottom:1em;">日志输出:</h3></p>
<textarea id = "console_log" name="desc" rows="20" placeholder="日志输出控制台" class="layui-textarea" readonly="readonly"></textarea>
</div>
<!-- 日志输出窗口END -->
</div> </div>
</div> </div>
</div> </div>
@ -42,4 +50,5 @@
<?php include_once('footer.php'); ?> <?php include_once('footer.php'); ?>
<script> <script>
check_weak_password(); check_weak_password();
get_sql_update_list();
</script> </script>

37
templates/admin/static/embed.js

@ -430,3 +430,40 @@ function check_weak_password(){
} }
}); });
} }
//获取待更新数据库列表,http://onenav.com/index.php?c=api&method=exe_sql&name=on_db_logs.sql
function get_sql_update_list() {
$("#console_log").append("正在检查数据库更新...\n");
$.get("index.php?c=api&method=get_sql_update_list",function(data,status){
if ( data.code == 0 ) {
//如果没有可用更新,直接结束
if ( data.data.length == 0 ) {
$("#console_log").append("当前无可用更新!\n");
return false;
}
else{
$("#console_log").append("检查到可更新SQL列表:\n");
$("#console_log").append("正在准备更新...\n");
for(i in data.data) {
sqlname = data.data[i];
//$("#console_log").append(data.data[i] + "\n");
exe_sql(sqlname);
}
}
}
});
}
//更新SQL函数
function exe_sql(sqlname) {
$.ajax({ url: "index.php?c=api&method=exe_sql&name=" + sqlname, async:false, success: function(data,status){
if( data.code == 0 ){
$("#console_log").append(sqlname + "更新完毕!\n");
}
else {
$("#console_log").append(sqlname + "更新失败!\n");
}
}});
}

5
templates/default/index.php

@ -86,11 +86,11 @@
//遍历分类目录并显示 //遍历分类目录并显示
foreach ($categorys as $category) { foreach ($categorys as $category) {
//var_dump($category); //var_dump($category);
$font_icon = empty($category['font_icon']) ? '' : "<i class='{$category['font_icon']}'></i> ";
?> ?>
<a href="#category-<?php echo $category['id']; ?>"> <a href="#category-<?php echo $category['id']; ?>">
<li class="mdui-list-item mdui-ripple"> <li class="mdui-list-item mdui-ripple">
<div class="mdui-list-item-content category-name"><?php echo htmlspecialchars_decode($category['name']); ?></div> <div class="mdui-list-item-content category-name"><?php echo $font_icon; ?><?php echo htmlspecialchars_decode($category['name']); ?></div>
</li> </li>
</a> </a>
@ -146,6 +146,7 @@
} }
?> ?>
<div id = "category-<?php echo $category['id']; ?>" class = "mdui-col-xs-12 mdui-typo-title cat-title"> <div id = "category-<?php echo $category['id']; ?>" class = "mdui-col-xs-12 mdui-typo-title cat-title">
<?php echo $font_icon; ?>
<?php echo htmlspecialchars_decode($category['name']); ?> <?php echo $property; ?> <?php echo htmlspecialchars_decode($category['name']); ?> <?php echo $property; ?>
<span class = "mdui-typo-caption"><?php echo $category['description']; ?></span> <span class = "mdui-typo-caption"><?php echo $category['description']; ?></span>
</div> </div>

2
version.txt

@ -1 +1 @@
v0.9.15-20220225 v0.9.16-20220308
Loading…
Cancel
Save