Browse Source

v2.3

master
xiaoz 6 years ago
parent
commit
1fcf702d44
  1. 5
      application/config/routes.php
  2. 45
      application/controllers/Del.php
  3. 9
      application/controllers/Maintain.php
  4. 32
      application/controllers/Upgrade.php
  5. 39
      application/controllers/Upload.php
  6. 20
      application/helpers/basic_helper.php
  7. 5
      application/libraries/Basic.php
  8. 41
      application/models/Query.php
  9. 2
      application/views/admin/header.php
  10. 10
      application/views/admin/images.php
  11. 1
      application/views/admin/index.php
  12. 5
      application/views/admin/left.php
  13. 22
      application/views/admin/upgrade.php
  14. 3
      application/views/user/footer.php
  15. 9
      application/views/user/header.php
  16. 15
      application/views/user/home.php
  17. 16
      application/views/user/log.php
  18. 5
      application/views/user/multiple.php
  19. BIN
      data/imgurl-simple.db3
  20. 2
      data/version.txt
  21. 14
      static/embed.js
  22. 17
      static/js/admin.js
  23. 15
      static/style.css

5
application/config/routes.php

@ -55,4 +55,7 @@ $route['translate_uri_dashes'] = FALSE; @@ -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';
$route['api/upload/(:any)'] = 'upload/localhost/$1';
$route['api/parse'] = '/upload/parse';
//删除链接
$route['delete/(:any)'] = '/del/token/$1';

45
application/controllers/Del.php

@ -1,5 +1,11 @@ @@ -1,5 +1,11 @@
<?php
// 该控制器删除图片
/**
* ImgURL删除图片类
*
* @package upgrade
* @author xiaoz
* @link https://imgurl.org/
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Del extends CI_Controller{
//构造函数
@ -8,14 +14,16 @@ @@ -8,14 +14,16 @@
//加载模型
$this->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 @@ @@ -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 '图片已删除!';
}
}
?>

9
application/controllers/Maintain.php

@ -58,6 +58,15 @@ @@ -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');
}
}
?>

32
application/controllers/Upgrade.php

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<?php
/**
* ImgURL升级类
*
* @package upgrade
* @author xiaoz
* @link https://imgurl.org/
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Upgrade extends CI_Controller{
//构造函数
public function __construct(){
parent::__construct();
//加载辅助类
$this->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 '升级失败,未知错误!';
}
}
}

39
application/controllers/Upload.php

@ -21,6 +21,8 @@ @@ -21,6 +21,8 @@
public $temp;
//用户是否已经登录的属性
protected $user;
//获取站点主域名
protected $main_domain;
//构造函数
public function __construct()
{
@ -44,6 +46,8 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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;
}
}
?>

20
application/helpers/basic_helper.php

@ -141,4 +141,24 @@ @@ -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;
}
?>

5
application/libraries/Basic.php

@ -134,5 +134,10 @@ @@ -134,5 +134,10 @@
break;
}
}
//获取站点主域名
public function domain(){
$domain = $this->CI->query->get_domain();
return $domain;
}
}
?>

41
application/models/Query.php

@ -323,5 +323,46 @@ @@ -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;
}
}
?>

2
application/views/admin/header.php

@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
<title><?php echo $admin_title; ?> - ImgURL后台管理</title>
<link rel="stylesheet" href="/static/layui/css/layui.css">
<link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/static/css/admin.css?v=<?php echo $version; ?>">
<link rel="stylesheet" href="/static/css/admin.css?v=<?php echo $version; ?>">
<script src = "/static/js/jquery.min.js"></script>
</head>
<body class="layui-layout-body">

10
application/views/admin/images.php

@ -140,7 +140,15 @@ @@ -140,7 +140,15 @@
<div class="layui-col-lg6" id = "paging">
<?php echo $page; ?>
</div>
<div class="layui-col-lg6">
<div class="layui-col-lg3">
<span>操作:</span>
<div class="layui-btn-group">
<button type="button" class="layui-btn layui-btn-xs" onclick = "check_all()">全选</button>
<button type="button" class="layui-btn layui-btn-xs" onclick = "cancel_all()">取消全选</button>
<!--<button type="button" class="layui-btn layui-btn-xs" onclick = "invert_selection()">反选</button>-->
</div>
</div>
<div class="layui-col-lg3">
<!-- <button class="layui-btn layui-btn-xs" id = "checkAll">全选</button>--> <label>选中项:</label><button class="layui-btn layui-btn-xs layui-btn-danger" onclick = "del_more()">删除</button>
</div>
</div>

1
application/views/admin/index.php

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
<script src="/static/js/Chart.min.js"></script>
<div class="layui-container" style = "margin-top:2em;">
<div class="layui-row layui-col-space20">
<div class="layui-col-lg3">

5
application/views/admin/left.php

@ -34,8 +34,9 @@ @@ -34,8 +34,9 @@
<li class="layui-nav-item">
<a href="javascript:;"><i class="layui-icon layui-icon-app"></i> 管理维护</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;" onclick = "version()">当前版本</a></dd>
<dd><a href="/maintain/upto2">1.x升级2.x</a></dd>
<dd><a href="javascript:;" onclick = "version()">当前版本</a></dd>
<dd><a href="/maintain/upto2">1.x升级2.x</a></dd>
<dd><a href="/maintain/upgrade">版本升级</a></dd>
<!-- <dd><a href="/maintain/upto2">检查更新</a></dd> -->
<!-- <dd><a href="javascript:;">FTP</a></dd> -->
<!-- <dd><a href="">七牛云</a></dd>

22
application/views/admin/upgrade.php

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
<?php
//读取版本号
$content = file_get_contents(FCPATH."/data/version.txt");
$content = explode("-",$content);
$version = $content[0];
?>
<div class="layui-container" style = "margin-top:2em;">
<div class="layui-row">
<div class="layui-col-lg12">
<div>
<ol>
<li>1. 您当前使用的版本为<code style = "color:red;"><?php echo $version; ?></code></li>
<li>2. 升级之前请备份数据,升级之前请备份数据,升级之前请备份数据</li>
<li>3. 不要跨版本升级</li>
<li>4. 上述准备完成后,点击下方对应的版本进行升级</li>
<li>4. 没事不要乱点,否则后果自负</li>
</ol>
</div>
<div style = "margin-top:1em;"><a href="/upgrade/v22_to_v23" class="layui-btn" target = "_blank">v2.2 > v2.3</a></div>
</div>
</div>
</div>

3
application/views/user/footer.php

@ -10,8 +10,9 @@ @@ -10,8 +10,9 @@
<div class = "footer">
<div class = "layui-container">
<div class = "layui-row">
<!--未经作者授权,请勿去掉版权,谢谢-->
<div class = "layui-col-lg12">
Copyright © 2017-2019 Powered by <a href="https://imgurl.org/" target = "_blank">ImgURL</a> | Author <a href="https://www.xiaoz.me/" target = "_blank">xiaoz.me</a> |
Copyright © 2017-2019 Powered by <a href="https://imgurl.org/" target = "_blank" title = "ImgURL是一个开源免费的图床程序">ImgURL</a> | Author <a href="https://www.xiaoz.me/" target = "_blank" title = "小z博客">xiaoz.me</a> |
<!-- 简单判断用户是否登录 -->
<?php if((isset($_COOKIE['user'])) && (isset($_COOKIE['token']))){ ?>
<a href="/user/logout">logout</a>

9
application/views/user/header.php

@ -45,8 +45,13 @@ @@ -45,8 +45,13 @@
<li class="layui-nav-item"><a href="/home/multiple"><i class="layui-icon layui-icon-upload"></i> 多图上传</a></li>
<li class="layui-nav-item"><a href="/found"><i class="layui-icon layui-icon-search"></i> 探索发现</a></li>
<li class="layui-nav-item"><a href="/home/log"><i class="layui-icon layui-icon-notice"></i> 更新日志</a></li>
<li class="layui-nav-item"><a href="https://doc.xiaoz.me/#/imgurl2/api" target = "_blank"><i class="layui-icon layui-icon-template-1"></i> API</a></li>
<li class="layui-nav-item"><a href="https://doc.xiaoz.me/#/imgurl2/" target = "_blank" rel = "nofollow"><i class="layui-icon">&#xe705;</i> 帮助文档</a></li>
<li class="layui-nav-item">
<a href="https://dwz.ovh/imgurldoc" target = "_blank" rel = "nofollow"><i class="layui-icon">&#xe705;</i> 帮助文档</a>
<dl class="layui-nav-child"> <!-- 二级菜单 -->
<dd><a href="https://www.xiaoz.me/doc/doc-imgurl/install" rel = "nofollow" target = "_blank">安装ImgURL</a></dd>
<dd><a href="https://www.xiaoz.me/doc/doc-imgurl/api" rel = "nofollow" target = "_blank">ImgURL API</a></dd>
</dl>
</li>
<li class="layui-nav-item"><a href="https://github.com/helloxz/imgurl" target = "_blank" rel = "nofollow"><i class="layui-icon">&#xe635;</i> 源码</a></li>
<li class="layui-nav-item"><a href="/page/use"><i class="layui-icon">&#xe60b;</i> 关于</a></li>
<!-- 简单判断用户是否登录 -->

15
application/views/user/home.php

@ -40,14 +40,14 @@ @@ -40,14 +40,14 @@
<!-- 图片显示区域 -->
<!-- 显示缩略图 -->
<div class="layui-col-lg4">
<div id = "img-thumb"><a href="" target = "_blank"><img src="" alt=""></a></div>
<div id = "img-thumb"><a href="" target = "_blank"><img src="" alt="点此可查看详情"></a></div>
</div>
<!-- 显示地址 -->
<div class="layui-col-lg7 layui-col-md-offset1">
<div id="links">
<table class="layui-table" lay-skin="nob">
<table class="layui-table" lay-skin="nob" lay-size="sm">
<colgroup>
<col width="80">
<col width="100">
<col width="450">
<col>
</colgroup>
@ -72,6 +72,11 @@ @@ -72,6 +72,11 @@
<td><input type="text" class="layui-input" id="bbcode" data-cip-id="bbcode"></td>
<td><a href="javascript:;" class="layui-btn layui-btn-sm" onclick="copyurl('bbcode')">复制</a></td>
</tr>
<tr>
<td>Delete Link</td>
<td><input type="text" class="layui-input" id="dlink" data-cip-id="dlink"></td>
<td><a href="javascript:;" class="layui-btn layui-btn-sm" onclick="copyurl('dlink')">复制</a></td>
</tr>
</tbody>
</table>
</div>
@ -91,7 +96,7 @@ @@ -91,7 +96,7 @@
targetElement: load1,
isCompleteImg:false,
data:{
name:"alanzhang",
name:"imgurl",
},
success:function(data){
//转为对象
@ -125,11 +130,13 @@ @@ -125,11 +130,13 @@
}
else{
layer.msg(res.msg);
layer.closeAll('loading');
}
},
error: function(error){
layer.closeAll('loading');
layer.msg('上传失败!');
layer.closeAll('loading');
}
});
</script>

16
application/views/user/log.php

@ -4,6 +4,22 @@ @@ -4,6 +4,22 @@
<div id="timeline">
<!-- <h2 sytle = "line-height:1em;">ImgURL更新日志</h2> -->
<ul class="layui-timeline">
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">
<h3 class="layui-timeline-title">2019年6月</h3>
<p>ImgURL v2.3发布</p>
<ul>
<li>API支持base64编码上传</li>
<li>支持.webp上传</li>
<li>增加IIS rewrite规则</li>
<li>SEO优化</li>
<li>优化探索发现,最多显示160张图片</li>
<li>优化图片管理,支持按ID/ImgID/IP/时间等条件筛选图片,已支持全选操作</li>
<li>修复部分用户启用CDN后无法登录问题</li>
</ul>
</div>
</li>
<li class="layui-timeline-item">
<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
<div class="layui-timeline-content layui-text">

5
application/views/user/multiple.php

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
<li>HTML</li>
<li>Markdown</li>
<li>BBCode</li>
<li>Delete Link</li>
</ul>
<div class="layui-tab-content" style="height: 100px;">
<!-- 第一个选显卡结果 -->
@ -43,6 +44,10 @@ @@ -43,6 +44,10 @@
<div class="layui-tab-item" id = "re-bbc">
<pre></pre>
</div>
<!-- 返回删除链接 -->
<div class="layui-tab-item" id = "re-dlink">
<pre></pre>
</div>
</div>
</div>
<!-- 导出txt按钮 -->

BIN
data/imgurl-simple.db3

Binary file not shown.

2
data/version.txt

@ -1 +1 @@ @@ -1 +1 @@
v2.24-20190530
v2.3-20190605

14
static/embed.js

@ -68,6 +68,7 @@ layui.use(['upload','form','element','layer','flow'], function(){ @@ -68,6 +68,7 @@ layui.use(['upload','form','element','layer','flow'], function(){
$("#html").val("<img src = '" + res.url + "' />");
$("#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(){ @@ -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(){ @@ -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(){ @@ -128,11 +130,12 @@ layui.use(['upload','form','element','layer','flow'], function(){
});
//显示多图上传结果
function multiple(url){
function multiple(url,dlink){
$("#re-url pre").append(url + "<br>");
$("#re-html pre").append("&lt;img src = '" + url + "' /&gt;" + "<br>");
$("#re-md pre").append("![](" + url + ")" + "<br>");
$("#re-bbc pre").append("[img]" + url + "[/img]" + "<br>");
$("#re-dlink pre").append(dlink + "<br>");
}
//复制链接
@ -266,4 +269,9 @@ function createAndDownloadFile(fileName, content) { @@ -266,4 +269,9 @@ function createAndDownloadFile(fileName, content) {
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(blob);
}
}
//改用jquery异步加载背景图
$(document).ready(function(){
$("body").css("background-image","url('/static/images/bg.jpg')");
});

17
static/js/admin.js

@ -281,4 +281,19 @@ function find_date_img(){ @@ -281,4 +281,19 @@ function find_date_img(){
return FALSE;
}
window.location.href = '/manage/images/' + user + '/?date=' + date;
}
}
//$("#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");
}

15
static/style.css

@ -1,8 +1,8 @@ @@ -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{ @@ -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{ @@ -605,3 +605,10 @@ body{
display: none;
}
}
.title h2{
overflow: hidden;
text-overflow:ellipsis;
}
#links .layui-input{
height:32px;
}
Loading…
Cancel
Save