diff --git a/class/Api.php b/class/Api.php index 3936c2e..f8b2365 100755 --- a/class/Api.php +++ b/class/Api.php @@ -15,14 +15,15 @@ class Api { /** * 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); $data = [ 'name' => htmlspecialchars($name,ENT_QUOTES), 'add_time' => time(), 'weight' => $weight, 'property' => $property, - 'description' => htmlspecialchars($description,ENT_QUOTES) + 'description' => htmlspecialchars($description,ENT_QUOTES), + 'font_icon' => $font_icon ]; //插入分类目录 $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); //如果id为空 if( empty($id) ){ @@ -63,7 +64,8 @@ class Api { 'up_time' => time(), 'weight' => $weight, '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]); //var_dump( $this->db->log() ); @@ -636,9 +638,13 @@ class Api { * 循环读取db/sql/目录下的.sql文件 */ public function get_sql_update_list($data) { - //待升级的数据库文件目录 + //鉴权 + if( !$this->is_login() ) { + $this->err_msg(-1002,'Authorization failure!'); + } + //待更新的数据库文件目录 $sql_dir = 'db/sql/'; - //sql文件列表,默认为空 + //待更新的sql文件列表,默认为空 $sql_files_all = []; //打开一个目录,读取里面的文件列表 if (is_dir($sql_dir)){ @@ -663,23 +669,28 @@ class Api { if ( $num === 0 ) { $data = [ "code" => 0, - "data" => ['on_db_logs'] + "data" => ['on_db_logs.sql'] ]; exit(json_encode($data)); }else{ - //如果不为0,则需要进行比对 + //如果不为0,则需要查询数据库更新表里面的数据进行差集比对 $get_on_db_logs = $this->db->select("on_db_logs",[ "sql_name" ],[ "status" => "TRUE" ]); - //声明一个空数组,存储已更新的数据库 + //声明一个空数组,存储已更新的数据库列表 $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_diff() 函数返回两个数组的差集数组 $diff_result = array_diff($sql_files_all,$already_dbs); + //去掉键 + $diff_result = array_values($diff_result); + sort($diff_result); + $data = [ "code" => 0, "data" => $diff_result @@ -692,13 +703,17 @@ class Api { * 执行SQL更新语句,只执行单条更新 */ public function exe_sql($data) { + //鉴权 + if( !$this->is_login() ) { + $this->err_msg(-1002,'Authorization failure!'); + } //数据库sql目录 $sql_dir = 'db/sql/'; $name = $data['name']; - $sql_name = $sql_dir.$name.'.sql'; + $sql_name = $sql_dir.$name; //如果文件不存在,直接返回错误 if ( !file_exists($sql_name) ) { - $this->err_msg(-2000,$name.'.sql不存在!'); + $this->err_msg(-2000,$name.'不存在!'); } //读取需要更新的SQL内容 try { @@ -708,24 +723,24 @@ class Api { if( $result ) { //将更新信息写入数据库 $insert_re = $this->db->insert("on_db_logs",[ - "sql_name" => $name.'.sql', + "sql_name" => $name, "update_time" => time() ]); if( $insert_re ) { $data = [ "code" => 0, - "data" => $name.".sql更新完成!" + "data" => $name."更新完成!" ]; exit(json_encode($data)); } else { - $this->err_msg(-2000,$name.".sql更新失败,请人工检查!"); + $this->err_msg(-2000,$name."更新失败,请人工检查!"); } } else{ //如果执行失败 - $this->err_msg(-2000,$name.".sql更新失败,请人工检查!"); + $this->err_msg(-2000,$name."更新失败,请人工检查!"); } } catch(Exception $e){ $this->err_msg(-2000,$e->getMessage()); diff --git a/controller/api.php b/controller/api.php index bd5aa0b..c9745a1 100755 --- a/controller/api.php +++ b/controller/api.php @@ -84,7 +84,9 @@ function add_category($api){ $description = empty($_POST['description']) ? '' : $_POST['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 = 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); } /** * 删除分类目录 diff --git a/data/update.log b/data/update.log index 6f905c6..d42f791 100755 --- a/data/update.log +++ b/data/update.log @@ -44,5 +44,7 @@ CREATE INDEX on_options_key_IDX ON on_options ("key"); 2. API新增查询单个链接信息get_a_link 3. API支持查询指定分类下的链接link_list,传递参数category_id -20220307 -1. 数据库SQL更新API(尚未写完,下班了,先提交) \ No newline at end of file +20220308 +1. 新增数据库更新功能 +2. 初始数据库更新 +3. 分离分类图标字体设置 \ No newline at end of file diff --git a/db/index.html b/db/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/db/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/db/onenav.simple.db3 b/db/onenav.simple.db3 old mode 100755 new mode 100644 index 895d56f..dfb5cae Binary files a/db/onenav.simple.db3 and b/db/onenav.simple.db3 differ diff --git a/db/sql/20220101.sql b/db/sql/20220101.sql deleted file mode 100644 index e69de29..0000000 diff --git a/db/sql/20220301.sql b/db/sql/20220301.sql deleted file mode 100644 index e69de29..0000000 diff --git a/db/sql/20220308.sql b/db/sql/20220308.sql new file mode 100644 index 0000000..c1d8dab --- /dev/null +++ b/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); + diff --git a/templates/admin/add_category.php b/templates/admin/add_category.php index a9b2624..03d831d 100755 --- a/templates/admin/add_category.php +++ b/templates/admin/add_category.php @@ -12,6 +12,14 @@ + +
+ +
+ +
+
+
@@ -40,6 +48,7 @@
+

关于字体图标的说明请参考帮助文档:https://dwz.ovh/7nr1f

diff --git a/templates/admin/edit_category.php b/templates/admin/edit_category.php index c18f254..df99207 100755 --- a/templates/admin/edit_category.php +++ b/templates/admin/edit_category.php @@ -18,6 +18,14 @@ ' placeholder="请输入分类名称" autocomplete="off" class="layui-input"> + +
+ +
+ ' placeholder="请输入字体图标,如:fa fa-bookmark-o" autocomplete="off" class="layui-input"> +
+
+
@@ -46,9 +54,11 @@
+

关于字体图标的说明请参考帮助文档:https://dwz.ovh/7nr1f

+ diff --git a/templates/admin/index.php b/templates/admin/index.php index 9b3bbd0..3bdc2a5 100755 --- a/templates/admin/index.php +++ b/templates/admin/index.php @@ -34,6 +34,14 @@
捐赠地址: https://dwz.ovh/donation
+ + +
+

日志输出:

+ +
+ + @@ -42,4 +50,5 @@ diff --git a/templates/admin/static/embed.js b/templates/admin/static/embed.js index 29ece02..94c6d88 100755 --- a/templates/admin/static/embed.js +++ b/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"); + } + }}); +} + diff --git a/templates/default/index.php b/templates/default/index.php index c31185e..be462b1 100755 --- a/templates/default/index.php +++ b/templates/default/index.php @@ -86,11 +86,11 @@ //遍历分类目录并显示 foreach ($categorys as $category) { //var_dump($category); - + $font_icon = empty($category['font_icon']) ? '' : " "; ?>
  • -
    +
  • @@ -146,6 +146,7 @@ } ?>
    +
    diff --git a/version.txt b/version.txt index 4f936b1..bbc01fb 100755 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.9.15-20220225 \ No newline at end of file +v0.9.16-20220308 \ No newline at end of file