diff --git a/application/config/routes.php b/application/config/routes.php index 1339115..539fa19 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -55,4 +55,7 @@ $route['translate_uri_dashes'] = FALSE; //API路由 $route['api/upload'] = 'upload/localhost'; $route['api/upload/parse'] = 'upload/parse'; -$route['api/upload/(:any)'] = 'upload/localhost/$1'; \ No newline at end of file +$route['api/upload/(:any)'] = 'upload/localhost/$1'; +$route['api/parse'] = '/upload/parse'; +//删除链接 +$route['delete/(:any)'] = '/del/token/$1'; \ No newline at end of file diff --git a/application/controllers/Del.php b/application/controllers/Del.php index 7536a67..8614f7d 100644 --- a/application/controllers/Del.php +++ b/application/controllers/Del.php @@ -1,5 +1,11 @@ load->model('query','',TRUE); + //加载数据库模型 + $this->load->model('delete','',TRUE); //加载类 $this->load->library('basic'); - //检测是否登录 - $this->basic->is_login(TRUE); - } - //根据img_images ID删除图片 + //根据img_images ID删除图片,需要检查用户是否登录 public function id($id){ + //检测是否登录 + $this->basic->is_login(TRUE); + @$id = (int)$id; $img = $this->query->img_id($id); @@ -38,5 +46,32 @@ $re = json_encode($re); echo $re; } + //根据token删除单张图片,不需要登录,只需要知道token即可 + public function token($value){ + //对value进行过滤 + $value = trim($value); + $value = strip_tags($value); + $len = strlen($value); + if($len !== 16){ + exit('不是有效的token!'); + } + //获取图片信息 + $img = $this->query->get_token($value); + //如果返回空,说明token不存在 + if($img === NULL){ + exit('token不存在,可能是图片已经被删除!'); + } + //删除图片 + //从数据库中删除 + $this->delete->del_img($img->imgid); + //从磁盘中删除 + $path = FCPATH.$img->path; + $thumbnail_path = FCPATH.$img->thumb_path; + //缩略图地址 + unlink($path); + unlink($thumbnail_path); + + echo '图片已删除!'; + } } ?> \ No newline at end of file diff --git a/application/controllers/Maintain.php b/application/controllers/Maintain.php index 62293af..2f420d3 100644 --- a/application/controllers/Maintain.php +++ b/application/controllers/Maintain.php @@ -58,6 +58,15 @@ // $query = $this->db->query($sql)->row(); // var_dump($query); } + //版本升级 + public function upgrade(){ + $data['admin_title'] = 'ImgURL升级'; + //加载视图 + $this->load->view('admin/header',$data); + $this->load->view('admin/left'); + $this->load->view('admin/upgrade'); + $this->load->view('admin/footer'); + } } ?> \ No newline at end of file diff --git a/application/controllers/Upgrade.php b/application/controllers/Upgrade.php new file mode 100644 index 0000000..f676118 --- /dev/null +++ b/application/controllers/Upgrade.php @@ -0,0 +1,32 @@ +load->library('basic'); + $this->basic->is_login(TRUE); + //加载模型 + $this->load->model('query','',TRUE); + } + public function v22_to_v23(){ + //升级数据库操作 + $result = $this->query->to23(); + if($result){ + echo '升级完毕,请关闭此页面!'; + } + else{ + echo '升级失败,未知错误!'; + } + } +} \ No newline at end of file diff --git a/application/controllers/Upload.php b/application/controllers/Upload.php index a5cf28d..975ecc0 100644 --- a/application/controllers/Upload.php +++ b/application/controllers/Upload.php @@ -21,6 +21,8 @@ public $temp; //用户是否已经登录的属性 protected $user; + //获取站点主域名 + protected $main_domain; //构造函数 public function __construct() { @@ -44,6 +46,8 @@ $this->load->library('basic'); //加载查询模型 $this->load->model('query','',TRUE); + $this->main_domain = $this->basic->domain(); + //用户已经登录 if($this->basic->is_login(FALSE)){ $this->user = 'admin'; @@ -155,7 +159,17 @@ } //图片没有上传过 else{ - //需要插入到images表的数据 + $arr = array( + "ip" => get_ip(), + "ua" => get_ua(), + "date" => $this->date + ); + + //生成token + $token = $this->token($arr); + //生成删除链接 + $delete = $this->main_domain.'/delete/'.$token; + //需要插入到img_images表的数据 $datas = array( "imgid" => $imgid, "path" => $relative_path, @@ -165,7 +179,8 @@ "ua" => get_ua(), "date" => $this->date, "user" => $this->user, - "level" => 'unknown' + "level" => 'unknown', + "token" => $token ); //需要插入到imginfo表的数据 $imginfo = array( @@ -189,7 +204,8 @@ "url" => $url, "thumbnail_url" => $thumbnail_url, "width" => $data['image_width'], - "height" => $data['image_height'] + "height" => $data['image_height'], + "delete" => $delete ); //根据不同的类型返回不同的数据 $this->re_data($type,$info); @@ -442,5 +458,22 @@ $this->succeed_msg($info); //echo $re; } + /* + 1. 该方法生成图片的唯一删除token + 2. 参数为一个数组,内容为IP/UA/DATE + 3. ip + ua + date + 4位随机数,进行md5加密得到token + */ + protected function token($arr){ + $ip = $arr['ip']; + $ua = $arr['ua']; + $date = $arr['date']; + //生成4位随机数 + $str = GetRandStr(4); + $token = $ip.$ua.$date.$str; + $token = md5($token); + //token只需要16位 + $token = substr($token, 8, 16); + return $token; + } } ?> \ No newline at end of file diff --git a/application/helpers/basic_helper.php b/application/helpers/basic_helper.php index 970dcd1..cb1a489 100644 --- a/application/helpers/basic_helper.php +++ b/application/helpers/basic_helper.php @@ -141,4 +141,24 @@ return $img['path']; } } + //生成4位随机数,方法来自:https://blog.csdn.net/happy_jijiawei/article/details/50581094 + function GetRandStr($len) + { + $chars = array( + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", + "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", + "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", + "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", + "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", + "3", "4", "5", "6", "7", "8", "9" + ); + $charsLen = count($chars) - 1; + shuffle($chars); + $output = ""; + for ($i=0; $i<$len; $i++) + { + $output .= $chars[mt_rand(0, $charsLen)]; + } + return $output; + } ?> \ No newline at end of file diff --git a/application/libraries/Basic.php b/application/libraries/Basic.php index 5ca61af..0fd1599 100644 --- a/application/libraries/Basic.php +++ b/application/libraries/Basic.php @@ -134,5 +134,10 @@ break; } } + //获取站点主域名 + public function domain(){ + $domain = $this->CI->query->get_domain(); + return $domain; + } } ?> \ No newline at end of file diff --git a/application/models/Query.php b/application/models/Query.php index dd190ca..86d98ae 100644 --- a/application/models/Query.php +++ b/application/models/Query.php @@ -323,5 +323,46 @@ $datas = $this->db->query($sql)->result_array(); return $datas; } + //v2.2升级v2.3 + public function to23(){ + // $sql = 'alter table "img_images" ADD "token" TEXT(16) DEFAULT NULL; + // CREATE UNIQUE INDEX "token" ON "img_images" ("token" ASC); + // '; + $sqls = array( + 'alter table "img_images" ADD "token" TEXT(16) DEFAULT NULL;', + 'CREATE UNIQUE INDEX "token" ON "img_images" ("token" ASC)', + 'CREATE UNIQUE INDEX "imginfo_imgid" ON "img_imginfo" ("imgid" ASC)' + ); + //遍历SQL语句 + foreach ($sqls as $value) { + $datas = $this->db->query($value); + } + //var_dump($datas); + if($datas){ + return TRUE; + } + else{ + return FALSE; + } + } + //查询站点主域名 + public function get_domain() { + $sql = 'SELECT "values" FROM "img_options" WHERE `name` = "site_url"'; + $data = $this->db->query($sql)->row(); + + if($data){ + return $data->values; + } + else{ + return FALSE; + } + } + //根据token查询图片信息 + public function get_token($value){ + //先获取img id + $sql = "SELECT a.*,b.mime,b.width,b.height,b.views,b.ext,b.client_name FROM img_images AS a INNER JOIN img_imginfo AS b ON a.token = '{$value}' AND a.imgid = b.imgid"; + $imginfo = $this->db->query($sql)->row(); + return $imginfo; + } } ?> \ No newline at end of file diff --git a/application/views/admin/header.php b/application/views/admin/header.php index bf3fcc7..2a9b323 100644 --- a/application/views/admin/header.php +++ b/application/views/admin/header.php @@ -13,7 +13,7 @@ <?php echo $admin_title; ?> - ImgURL后台管理 - + diff --git a/application/views/admin/images.php b/application/views/admin/images.php index d18ff51..5e143d4 100644 --- a/application/views/admin/images.php +++ b/application/views/admin/images.php @@ -140,7 +140,15 @@
-
+
+ 操作: +
+ + + +
+
+
diff --git a/application/views/admin/index.php b/application/views/admin/index.php index 90955be..9c5be72 100644 --- a/application/views/admin/index.php +++ b/application/views/admin/index.php @@ -1,3 +1,4 @@ +
diff --git a/application/views/admin/left.php b/application/views/admin/left.php index a8a4693..e050145 100644 --- a/application/views/admin/left.php +++ b/application/views/admin/left.php @@ -34,8 +34,9 @@
  • 管理维护
    -
    当前版本
    -
    1.x升级2.x
    +
    当前版本
    +
    1.x升级2.x
    +
    版本升级
    - Copyright © 2017-2019 Powered by ImgURL | Author xiaoz.me | + Copyright © 2017-2019 Powered by ImgURL | Author xiaoz.me | logout diff --git a/application/views/user/header.php b/application/views/user/header.php index 2c6d151..fa18b42 100644 --- a/application/views/user/header.php +++ b/application/views/user/header.php @@ -45,8 +45,13 @@
  • 多图上传
  • 探索发现
  • 更新日志
  • -
  • API
  • -
  • 帮助文档
  • +
  • + 帮助文档 +
    +
    安装ImgURL
    +
    ImgURL API
    +
    +
  • 源码
  • 关于
  • diff --git a/application/views/user/home.php b/application/views/user/home.php index f0adf2d..3552971 100644 --- a/application/views/user/home.php +++ b/application/views/user/home.php @@ -40,14 +40,14 @@
    -
    +
    点此可查看详情
    @@ -91,7 +96,7 @@ targetElement: load1, isCompleteImg:false, data:{ - name:"alanzhang", + name:"imgurl", }, success:function(data){ //转为对象 @@ -125,11 +130,13 @@ } else{ layer.msg(res.msg); + layer.closeAll('loading'); } }, error: function(error){ layer.closeAll('loading'); layer.msg('上传失败!'); + layer.closeAll('loading'); } }); diff --git a/application/views/user/log.php b/application/views/user/log.php index c778bf1..aba5270 100644 --- a/application/views/user/log.php +++ b/application/views/user/log.php @@ -4,6 +4,22 @@
      +
    • + +
      +

      2019年6月

      +

      ImgURL v2.3发布

      +
        +
      • API支持base64编码上传
      • +
      • 支持.webp上传
      • +
      • 增加IIS rewrite规则
      • +
      • SEO优化
      • +
      • 优化探索发现,最多显示160张图片
      • +
      • 优化图片管理,支持按ID/ImgID/IP/时间等条件筛选图片,已支持全选操作
      • +
      • 修复部分用户启用CDN后无法登录问题
      • +
      +
      +
    • diff --git a/application/views/user/multiple.php b/application/views/user/multiple.php index 7d06627..9814614 100644 --- a/application/views/user/multiple.php +++ b/application/views/user/multiple.php @@ -25,6 +25,7 @@
    • HTML
    • Markdown
    • BBCode
    • +
    • Delete Link
    @@ -43,6 +44,10 @@
    
                         
    + +
    diff --git a/data/imgurl-simple.db3 b/data/imgurl-simple.db3 index 66e7b22..4e8c73f 100644 Binary files a/data/imgurl-simple.db3 and b/data/imgurl-simple.db3 differ diff --git a/data/version.txt b/data/version.txt index 2917133..2bd9311 100644 --- a/data/version.txt +++ b/data/version.txt @@ -1 +1 @@ -v2.24-20190530 \ No newline at end of file +v2.3-20190605 \ No newline at end of file diff --git a/static/embed.js b/static/embed.js index 433766a..419a1a2 100644 --- a/static/embed.js +++ b/static/embed.js @@ -68,6 +68,7 @@ layui.use(['upload','form','element','layer','flow'], function(){ $("#html").val(""); $("#markdown").val("![](" + res.url + ")"); $("#bbcode").val("[img]" + res.url + "[/img]"); + $("#dlink").val(res.delete); $("#imgshow").show(); //对图片进行鉴黄识别 identify(res.id); @@ -95,6 +96,7 @@ layui.use(['upload','form','element','layer','flow'], function(){ $("#re-html pre").empty(); $("#re-md pre").empty(); $("#re-bbc pre").empty(); + $("#re-dlink pre").empty(); layer.load(); //上传loading n = 0; } @@ -110,7 +112,7 @@ layui.use(['upload','form','element','layer','flow'], function(){ if(res.code == 200){ //得到百分比 //var col = (n / total) * 100; - multiple(res.url); + multiple(res.url,res.delete); //对图片进行鉴黄识别 identify(res.id); //element.progress('up-status', col + '%'); @@ -128,11 +130,12 @@ layui.use(['upload','form','element','layer','flow'], function(){ }); //显示多图上传结果 -function multiple(url){ +function multiple(url,dlink){ $("#re-url pre").append(url + "
    "); $("#re-html pre").append("<img src = '" + url + "' />" + "
    "); $("#re-md pre").append("![](" + url + ")" + "
    "); $("#re-bbc pre").append("[img]" + url + "[/img]" + "
    "); + $("#re-dlink pre").append(dlink + "
    "); } //复制链接 @@ -266,4 +269,9 @@ function createAndDownloadFile(fileName, content) { aTag.href = URL.createObjectURL(blob); aTag.click(); URL.revokeObjectURL(blob); -} \ No newline at end of file +} + +//改用jquery异步加载背景图 +$(document).ready(function(){ + $("body").css("background-image","url('/static/images/bg.jpg')"); +}); \ No newline at end of file diff --git a/static/js/admin.js b/static/js/admin.js index 2d026f9..5c0aebe 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -281,4 +281,19 @@ function find_date_img(){ return FALSE; } window.location.href = '/manage/images/' + user + '/?date=' + date; -} \ No newline at end of file +} +//$("#quanxuan").click(function(){ +// $("input[name='checkbox']").attr("checked","true"); +//}) + +/* +下面几个操作的方法来源于:https://www.cnblogs.com/diony/p/8028424.html +*/ +//全选按钮 +function check_all(){ + $("input[name='chk']").attr("checked","true"); +} +//取消全选 +function cancel_all(){ + $("input[name='chk']").removeAttr("checked"); +} diff --git a/static/style.css b/static/style.css index 57270db..2f95237 100644 --- a/static/style.css +++ b/static/style.css @@ -1,8 +1,8 @@ body{ - background-image:url('/static/images/bg.jpg'); + /*background-image:url('/static/images/bg.jpg');*/ background-size: cover; - width: 100%; - color:#232323; + /*width: 100%; + color:#232323;*/ } @media screen and (max-width:640px) { body{ @@ -358,7 +358,7 @@ body{ margin-left:auto; margin-right:auto; - border: 1px solid #ECECEC; + /*border: 1px solid #ECECEC;*/ border-radius: 5px; max-height: 175px; } @@ -605,3 +605,10 @@ body{ display: none; } } +.title h2{ + overflow: hidden; + text-overflow:ellipsis; +} +#links .layui-input{ + height:32px; +} \ No newline at end of file