From ecbef7833d01e443f3d2f64d9e9e65765035f9a9 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 29 Apr 2022 17:18:14 +0800 Subject: [PATCH 1/7] 20220429 --- class/Api.php | 105 +++++++++++++++++++++++++++++++++++++++++++ controller/admin.php | 31 +++++++++++++ controller/api.php | 36 ++++++++++++++- controller/ico.php | 101 +++++++++++++++++++++++++++++++++++++++++ controller/index.php | 26 +++++++++++ 5 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 controller/ico.php diff --git a/class/Api.php b/class/Api.php index ab27e77..1a882a4 100755 --- a/class/Api.php +++ b/class/Api.php @@ -214,6 +214,38 @@ class Api { $this->err_msg(-1011,'The URL already exists!'); } } + /** + * 批量修改链接分类 + */ + public function batch_modify_category($data) { + $this->auth($token); + //获取链接ID,是一个数组 + $id = implode(',',$data['id']); + //获取分类ID + $fid = $data['fid']; + //查询分类ID是否存在 + $count = $this->db->count('on_categorys',[ 'id' => $fid]); + //如果分类ID不存在 + if( empty($fid) || empty($count) ) { + $this->err_msg(-2000,'分类ID不存在!'); + } + else{ + $sql = "UPDATE on_links SET fid='$fid' WHERE id IN ($id)"; + $re = $this->db->query($sql); + if( $re ) { + $id = $this->db->id(); + $data = [ + 'code' => 0, + 'msg' => "success" + ]; + exit(json_encode($data)); + } + else{ + $this->err_msg(-2000,'更新失败!'); + } + } + } + /** * 批量导入链接 */ @@ -909,6 +941,79 @@ class Api { $this->err_msg(-2000,$e->getMessage()); } } + /** + * 保存主题参数 + */ + public function save_theme_config($data) { + $this->auth($token); + //获取主题名称 + $name = $data['name']; + //获取config参数,是一个对象 + $config = $data['config']; + + //获取主题配置文件config.json + if ( is_dir("templates/".$name) ) { + $config_file = "templates/".$name."/config.json"; + } + else{ + $config_file = "data/templates/".$name."/config.json"; + } + + $config_content = json_encode($config,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT); + //写入配置 + try { + $re = @file_put_contents($config_file,$config_content); + $this->return_json(0,"success"); + } catch (\Throwable $th) { + $this->err_msg(-2000,"写入配置失败!"); + } + } + /** + * 获取主题参数 + */ + public function get_theme_config() { + $template = $this->db->get("on_options","value",[ + "key" => "theme" + ]); + //获取主题配置信息 + //获取主题配置 + if( file_exists("templates/".$template."/config.json") ) { + $config_file = "templates/".$template."/config.json"; + } + else if(data/templates/".$template."/config.json) { + $config_file = "data/templates/".$template."/config.json"; + } + else if( file_exists("templates/".$template."/info.json") ) { + $config_file = "templates/".$template."/info.json"; + } + else { + $config_file = "data/templates/".$template."/info.json"; + } + + //读取主题配置 + $config_content = @file_get_contents($config_file); + + //如果是info.json,则特殊处理下 + if ( strstr($config_file,"info.json") ) { + $theme_config = $config_content->config; + } + else{ + $theme_config = $config_content; + } + $theme_config = json_decode($theme_config); + $this->return_json(200,$theme_config,""); + } + /** + * 通用json消息返回 + */ + public function return_json($code,$data,$msg = "") { + $return = [ + "code" => intval($code), + "data" => $data, + "msg" => $msg + ]; + exit(json_encode($return)); + } /** * 更新option */ diff --git a/controller/admin.php b/controller/admin.php index 819af4e..ebb0c0b 100755 --- a/controller/admin.php +++ b/controller/admin.php @@ -43,6 +43,31 @@ if ( $page == 'edit_category' ) { } } +//如果是主题设置页面 +if ( $page == "setting/theme_config" ){ + //获取主题名称 + $name = trim($_GET['name']); + //获取主题目录 + if ( is_dir("templates/".$name) ) { + $theme_dir = "templates/".$name; + } + else{ + $theme_dir = "data/templates/".$name; + } + //读取主题配置 + $config_content = @file_get_contents("templates/".$name."/info.json"); + if( !$config_content ) { + $config_content = @file_get_contents("data/templates/".$name."/info.json"); + } + $configs = json_decode($config_content); + $configs = $configs->config; + //获取当前的配置参数 + $current_configs = file_get_contents($theme_dir."/config.json"); + + $current_configs = json_decode($current_configs); + //var_dump($current_configs); +} + //添加分类页面 if ( $page == 'add_category' ) { //查询父级分类 @@ -80,6 +105,12 @@ if ($page == 'edit_link') { } } +//链接列表页面 +if ( $page == "link_list" ) { + //查询所有分类信息,用于分类框选择 + $categorys = $db->select('on_categorys','*',[ 'ORDER' => ['weigth' => 'DESC'] ]); +} + //如果页面是添加链接页面 if ( ($page == 'add_link') || ($page == 'add_link_tpl') || ($page == 'add_quick_tpl') ) { //查询所有分类信息 diff --git a/controller/api.php b/controller/api.php index 7e62aee..14c3459 100755 --- a/controller/api.php +++ b/controller/api.php @@ -145,8 +145,8 @@ function category_list($api){ * 查询链接列表 */ function link_list($api){ - $page = empty(intval($_GET['page'])) ? 1 : intval($_GET['page']); - $limit = empty(intval($_GET['limit'])) ? 10 : intval($_GET['limit']); + $page = empty(intval($_REQUEST['page'])) ? 1 : intval($_REQUEST['page']); + $limit = empty(intval($_REQUEST['limit'])) ? 10 : intval($_REQUEST['limit']); //获取token $token = $_POST['token']; //获取分类ID @@ -322,4 +322,36 @@ function get_latest_version() { ]; } exit(json_encode($data)); +} + +//批量修改链接分类 +function batch_modify_category($api) { + //获取id列表 + $id = $_POST['id']; + //获取分类ID + $fid = intval($_POST['fid']); + + $data = [ + 'id' => $id, + 'fid' => $fid + ]; + + $api->batch_modify_category($data); +} + +//保存主题参数设置 +function save_theme_config($api) { + //获取所有POST数组,并组合为对象 + $post_data = $_POST; + //数组转对象 + foreach ($post_data as $key => $value) { + $data['config']->$key = $value; + } + $data['name'] = $post_data['name']; + unset($data['config']->name); + $api->save_theme_config($data); +} +//获取主题配置信息 +function get_theme_config($api) { + $api->get_theme_config(); } \ No newline at end of file diff --git a/controller/ico.php b/controller/ico.php new file mode 100644 index 0000000..af677f3 --- /dev/null +++ b/controller/ico.php @@ -0,0 +1,101 @@ +' . $first . ''; + //$value = 'data:image/svg+xml;base64,' . $src; + $value = $src; + return $value; +} + + +function hsv2rgb($h, $s, $v) +{ + $r = $g = $b = 0; + + $i = floor($h * 6); + $f = $h * 6 - $i; + $p = $v * (1 - $s); + $q = $v * (1 - $f * $s); + $t = $v * (1 - (1 - $f) * $s); + + switch ($i % 6) { + case 0: + $r = $v; + $g = $t; + $b = $p; + break; + case 1: + $r = $q; + $g = $v; + $b = $p; + break; + case 2: + $r = $p; + $g = $v; + $b = $t; + break; + case 3: + $r = $p; + $g = $q; + $b = $v; + break; + case 4: + $r = $t; + $g = $p; + $b = $v; + break; + case 5: + $r = $v; + $g = $p; + $b = $q; + break; + } + + return [ + floor($r * 255), + floor($g * 255), + floor($b * 255) + ]; +} + +/** + * 输出svg图像 + */ +function output_ico() { + //获取文字 + $text = @trim($_GET['text']); + $text = empty($text) ? '空' : $text; + + //获取当前主机名 + $host = $_SERVER['HTTP_HOST']; + //获取reffrer + $referer = $_SERVER['HTTP_REFERER']; + + //如果referer和主机名不匹配,则禁止调用 + if ( ( !empty($referer) ) && ( !strstr($referer,$host) ) ) { + exit('调用失败'); + } + else{ + header('Cache-Control: max-age=604800'); + header('Content-Type:image/svg+xml'); + echo letter_avatar($text); + } + +} + +//调用ico输出函数 +output_ico(); \ No newline at end of file diff --git a/controller/index.php b/controller/index.php index 375195f..b655016 100755 --- a/controller/index.php +++ b/controller/index.php @@ -162,6 +162,32 @@ $template = $db->get("on_options","value",[ $site = $db->get('on_options','value',[ 'key' => "s_site" ]); $site = unserialize($site); +//获取主题配置信息 +//获取主题配置 +if( file_exists("templates/".$template."/config.json") ) { + $config_file = "templates/".$template."/config.json"; +} +else if(data/templates/".$template."/config.json) { + $config_file = "data/templates/".$template."/config.json"; +} +else if( file_exists("templates/".$template."/info.json") ) { + $config_file = "templates/".$template."/info.json"; +} +else { + $config_file = "data/templates/".$template."/info.json"; +} + +//读取主题配置 +$config_content = @file_get_contents($config_file); +//如果是info.json,则特殊处理下 +if ( strstr($config_file,"info.json") ) { + $theme_config = $config_content->config; +} +else{ + $theme_config = $config_content; +} +$theme_config = json_decode($config_content); + //判断文件夹是否存在 if( is_dir('templates/'.$template) ){ $tpl_dir = 'templates/'; From f98865ae37cd4fb1589503917eedd7a102210edc Mon Sep 17 00:00:00 2001 From: xiaoz Date: Fri, 29 Apr 2022 17:20:05 +0800 Subject: [PATCH 2/7] 20220429 --- templates/admin/click.php | 3 - templates/admin/link_list.php | 26 ++++++- templates/admin/setting/theme.php | 10 +++ templates/admin/setting/theme_config.php | 83 ++++++++++++++++++++ templates/admin/setting/theme_detail.php | 1 + templates/admin/static/embed.js | 97 +++++++++++++++++++++++- templates/baisuTwo/config.json | 3 + templates/baisuTwo/index.php | 13 ++++ templates/baisuTwo/info.json | 10 ++- templates/baisuTwo/js/admin.js | 2 + templates/default/config.json | 5 ++ templates/default/index.php | 21 ++++- templates/default/info.json | 20 +++-- version.txt | 2 +- 14 files changed, 276 insertions(+), 20 deletions(-) create mode 100644 templates/admin/setting/theme_config.php create mode 100644 templates/baisuTwo/config.json create mode 100644 templates/default/config.json diff --git a/templates/admin/click.php b/templates/admin/click.php index 824bff8..4b5ac02 100755 --- a/templates/admin/click.php +++ b/templates/admin/click.php @@ -25,8 +25,6 @@ $admin_stay_time = $transition_page['admin_stay_time']; if ($is_login) { - //header("Refresh:1;url=".$link['url']); - header("Refresh:$admin_stay_time;url=".$link['url']); } else{ @@ -103,6 +101,5 @@ - diff --git a/templates/admin/link_list.php b/templates/admin/link_list.php index 6bce5a1..4e4f4b4 100755 --- a/templates/admin/link_list.php +++ b/templates/admin/link_list.php @@ -4,12 +4,36 @@
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
- + + + + + \ No newline at end of file diff --git a/templates/admin/setting/theme_detail.php b/templates/admin/setting/theme_detail.php index 0f7d6be..9316463 100644 --- a/templates/admin/setting/theme_detail.php +++ b/templates/admin/setting/theme_detail.php @@ -21,6 +21,7 @@

版本:version; ?>

更新时间:update; ?>

作者:author; ?>

+

使用说明:help_url; ?>

主页:homepage; ?>

diff --git a/templates/admin/static/embed.js b/templates/admin/static/embed.js index 6ef125f..a7a1b92 100755 --- a/templates/admin/static/embed.js +++ b/templates/admin/static/embed.js @@ -71,6 +71,7 @@ layui.use(['element','table','layer','form','upload'], function(){ elem: '#link_list' ,height: 520 ,url: 'index.php?c=api&method=link_list' //数据接口 + ,method: 'post' ,page: true //开启分页 ,toolbar: '#linktool' ,cols: [[ //表头 @@ -156,9 +157,41 @@ layui.use(['element','table','layer','form','upload'], function(){ //刷新当前页面 //window.location.reload(); break; - case 'getCheckLength': + case 'readmoredata': var data = checkStatus.data; - layer.msg('选中了:'+ data.length + ' 个'); + fidtext = $("#fid option:selected").text(); + fid = $("#fid").val(); + fid = parseInt(fid); + if( data.length == 0 ) { + layer.msg('未选中任何数据!'); + return false; + } + + if ( isNaN(fid) === true ){ + layer.msg('请先选择分类!',{icon:5}); + } + else{ + + layer.confirm('确认将选中链接的分类修改为【' + fidtext + '】?',{icon: 3, title:'温馨提示!'}, function(index){ + id = []; + for(let i = 0;i < data.length;i++) { + id.push(data[i].id); + } + + $.post("/index.php?c=api&method=batch_modify_category",{id:id,fid:fid},function(data,status){ + if (data.msg === "success") { + layer.msg("修改成功!",{icon:1}); + setTimeout(() => { + window.location.reload(); + }, 2000); + } + else{ + layer.msg(data.err_msg,{icon:5}); + } + }); + }); + } + //console.log(data); break; case 'isAll': layer.msg(checkStatus.isAll ? '全选': '未全选'); @@ -260,6 +293,66 @@ layui.use(['element','table','layer','form','upload'], function(){ return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 }); + //筛选链接 + form.on('submit(screen_link)', function(data){ + fid = data.field.fid; + if( fid == "" ) { + layer.msg("请先选择分类!",{icon:5}); + return false; + } + //表格重载 + var tableIns = table.render({ + elem: '#link_list' + ,height: 520 + ,url: 'index.php?c=api&method=link_list' //数据接口 + ,method: 'post' + ,page: true //开启分页 + ,toolbar: '#linktool' + ,where:{ + category_id:fid + } + ,cols: [[ //表头 + {type:'checkbox'} //开启复选框 + ,{field: 'id', title: 'ID', width:80, sort: true} + // ,{field: 'fid', title: '分类ID',sort:true, width:90} + ,{field: 'category_name', title: '所属分类',sort:true,width:120} + ,{field: 'url', title: 'URL',width:140,templet:function(d){ + var url = '' + d.url + ''; + return url; + }} + ,{field: 'title', title: '链接标题', width:140} + ,{field: 'add_time', title: '添加时间', width:148, sort: true,templet:function(d){ + var add_time = timestampToTime(d.add_time); + return add_time; + }} + ,{field: 'up_time', title: '修改时间', width:148,sort:true,templet:function(d){ + if(d.up_time == null){ + return ''; + } + else{ + var up_time = timestampToTime(d.up_time); + return up_time; + } + + }} + ,{field: 'weight', title: '权重', width: 75,sort:true} + ,{field: 'property', title: '私有', width: 80, sort: true,templet: function(d){ + if(d.property == 1) { + return ''; + } + else { + return ''; + } + }} + ,{field: 'click', title: '点击数',width:90,sort:true} + ,{fixed: 'right', title:'操作', toolbar: '#link_operate'} + ]] + }); + + //console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value} + return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 + }); + //保存站点设置 form.on('submit(set_site)', function(data){ $.post('/index.php?c=api&method=set_site',data.field,function(data,status){ diff --git a/templates/baisuTwo/config.json b/templates/baisuTwo/config.json new file mode 100644 index 0000000..0015cd6 --- /dev/null +++ b/templates/baisuTwo/config.json @@ -0,0 +1,3 @@ +{ + "link_description": "hide" +} \ No newline at end of file diff --git a/templates/baisuTwo/index.php b/templates/baisuTwo/index.php index e2312a6..74a0f0d 100644 --- a/templates/baisuTwo/index.php +++ b/templates/baisuTwo/index.php @@ -18,6 +18,15 @@ + @@ -419,6 +428,10 @@ 私有:
+
diff --git a/templates/baisuTwo/info.json b/templates/baisuTwo/info.json index 5621258..a3b1fe3 100644 --- a/templates/baisuTwo/info.json +++ b/templates/baisuTwo/info.json @@ -2,8 +2,12 @@ "name":"百素主题2", "description":"适用于OneNav的百素主题2", "homepage":"https://gitee.com/baisucode/baisu-two", - "version":"1.0.1", - "update":"2022/04/22", + "version":"1.0.2", + "update":"2022/04/29", "author":"baisu", - "screenshot":"https://img.rss.ink/imgs/2022/03/cba9f1946776a8f0.png" + "help_url":"https://dwz.ovh/gnae4", + "screenshot":"https://img.rss.ink/imgs/2022/03/cba9f1946776a8f0.png", + "config": { + "link_description":"hide" + } } \ No newline at end of file diff --git a/templates/baisuTwo/js/admin.js b/templates/baisuTwo/js/admin.js index 6e5c6e1..a3087cc 100644 --- a/templates/baisuTwo/js/admin.js +++ b/templates/baisuTwo/js/admin.js @@ -203,6 +203,7 @@ layui.use(['dropdown', 'layer', 'form'], function() { "description": data.data.description, "weight": data.data.weight, "property": property, + "fid":parseInt(data.data.fid) }); } else { //获取信息失败 @@ -287,6 +288,7 @@ function editFID(data) { name: data.name, font_icon: data.font_icon, weight: data.weight, + fid:data.fid, property: data.property, description: data.description, }, function(data, status) { diff --git a/templates/default/config.json b/templates/default/config.json new file mode 100644 index 0000000..f8a6c2e --- /dev/null +++ b/templates/default/config.json @@ -0,0 +1,5 @@ +{ + "full_width_mode": "on", + "link_description": "hide", + "favicon": "online" +} \ No newline at end of file diff --git a/templates/default/index.php b/templates/default/index.php index 2c747ab..786c5a0 100755 --- a/templates/default/index.php +++ b/templates/default/index.php @@ -14,6 +14,16 @@ + -
+
">