Browse Source

优化探索发现

dev
xiaoz 6 years ago
parent
commit
c6ef896496
  1. 74
      application/controllers/Found.php
  2. 12
      application/controllers/Upload.php
  3. 2
      application/helpers/basic_helper.php
  4. 9
      application/libraries/Image.php
  5. 17
      application/models/Query.php
  6. 35
      application/views/user/found.php
  7. 2
      data/version.txt
  8. 17
      static/embed.js
  9. 12
      static/style.css

74
application/controllers/Found.php

@ -9,19 +9,85 @@
$this->load->model('query','',TRUE); $this->load->model('query','',TRUE);
//加载辅助函数 //加载辅助函数
} }
//方法映射
public function _remap($type = 'all',$params = array())
{
$page = @$params[0];
//var_dump($params);
//exit;
if(!isset($page)){
$page = 0;
}
$this->index($type,$page);
}
//探索发现页面 //探索发现页面
public function index(){ public function index($type = 'all',$page = 0){
//加载常用类
$this->load->library('basic');
//检测用户是否登录
$data['is_login'] = $this->basic->is_login();
$siteinfo = $this->query->site_setting(); $siteinfo = $this->query->site_setting();
$siteinfo = $siteinfo->values; $siteinfo = $siteinfo->values;
$siteinfo = json_decode($siteinfo); $siteinfo = json_decode($siteinfo);
//每页显示16张图片
$limit = 16;
//echo $page;
$siteinfo->title = '探索发现 - '.$siteinfo->title; $siteinfo->title = '探索发现 - '.$siteinfo->title;
//SQL语句
$sql_header = "SELECT a.id,a.imgid,a.path,a.thumb_path,a.date,a.compression,a.level,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.imgid = b.imgid AND a.user = 'visitor' AND a.level = 'everyone' ";
//根据条件生成不同的SQL语句
switch($type){
case 'all':
//查询游客上传图片总数
$num = $this->query->count_num('visitor')->num;
$config['base_url'] = "/found/all/";
$sql = $sql_header."ORDER BY a.id DESC LIMIT $limit OFFSET $page";
break;
case 'gif':
$num = $this->query->count_num('gif')->num;
$config['base_url'] = "/found/gif/";
$sql = $sql_header."AND b.ext = '.gif' ORDER BY a.id DESC LIMIT $limit OFFSET $page";
break;
case 'views':
$num = $this->query->count_num('visitor')->num;
$config['base_url'] = "/found/views/";
$sql = $sql_header."ORDER BY b.views DESC LIMIT $limit OFFSET $page";
break;
case 'large':
$num = $this->query->count_num('large')->num;
$config['base_url'] = "/found/large/";
$sql = $sql_header."AND b.width >= 1920 AND b.height >= 1080 ORDER BY a.id DESC LIMIT $limit OFFSET $page";
break;
default:
//查询游客上传图片总数
$num = $this->query->count_num('visitor')->num;
$config['base_url'] = "/found/all/";
$sql = $sql_header."ORDER BY a.id DESC LIMIT $limit OFFSET $page";
break;
}
//查询图片信息,返回对象 //查询图片信息,返回对象
$data['imgs'] = $this->query->found(96); //$data['imgs'] = $this->query->found(96);
$data['imgs'] = $this->db->query($sql)->result_array();
//查询域名 //查询域名
$data['domain'] = $this->query->domain('localhost'); $data['domain'] = $this->query->domain('localhost');
//进行分页
//调用分页类
$this->load->library('pagination');
//$config['base_url'] = "/found/all/";
$config['total_rows'] = $num;
$config['per_page'] = $limit;
$config['first_url'] = 0;
$config['first_link'] = '首页';
$config['last_link'] = '尾页';
$config['attributes'] = array('class' => 'paging'); //设置分页的class
$config['next_link'] = '下一页'; //下一页文本
$config['prev_link'] = '上一页'; //上一页文本
$this->pagination->initialize($config);
$data['page'] = $this->pagination->create_links();
//加载视图 //加载视图
$this->load->view('user/header',$siteinfo); $this->load->view('user/header',$siteinfo);
$this->load->view('user/found',$data); $this->load->view('user/found',$data);

12
application/controllers/Upload.php

@ -114,7 +114,17 @@
//生成缩略图 //生成缩略图
$this->load->library('image'); $this->load->library('image');
$this->image->thumbnail($full_path,290,175); if(!$this->image->thumbnail($full_path,290,175)){
//像素太小就不生产缩略图
$thumbnail_url = $domain.$relative_path;
}
//CI获取获取.bmp 图片的像素,认为.bmp不是图像类型,改用其它方法获取像素
if($data['file_type'] == 'image/x-ms-bmp'){
$tmpinfo = getimagesize($full_path);
$data['image_width'] = $tmpinfo[0];
$data['image_height'] = $tmpinfo[1];
}
//查询图片是否上传过 //查询图片是否上传过
if($imginfo = $this->query->repeat($imgid)){ if($imginfo = $this->query->repeat($imgid)){

2
application/helpers/basic_helper.php

@ -84,7 +84,7 @@
case 'image/jpeg': case 'image/jpeg':
return '.jpg'; return '.jpg';
break; break;
case 'image/bmp': case 'image/x-ms-bmp':
return '.bmp'; return '.bmp';
break; break;
case 'image/webp': case 'image/webp':

9
application/libraries/Image.php

@ -55,12 +55,11 @@
$this->CI->load->library('image_lib', $config); $this->CI->load->library('image_lib', $config);
$this->CI->image_lib->resize(); $this->CI->image_lib->resize();
} }
} }
//图片像素太小了,不创建缩略图
else{
return FALSE;
}
} }
//检测是否支持ImageMagick //检测是否支持ImageMagick
protected function check(){ protected function check(){

17
application/models/Query.php

@ -237,6 +237,23 @@
case 'month': case 'month':
$sql = "SELECT count(*) AS num FROM `img_images` WHERE date LIKE strftime('%Y-%m','now') || '%'"; $sql = "SELECT count(*) AS num FROM `img_images` WHERE date LIKE strftime('%Y-%m','now') || '%'";
break; break;
case 'gif':
$sql = "SELECT count(*) AS num FROM (SELECT a.id,b.ext FROM img_images a INNER JOIN img_imginfo b ON a.imgid = b.imgid AND a.user = 'visitor' AND b.ext = '.gif')";
break;
case 'large':
$sql = "SELECT count(*) AS num FROM
(
SELECT a.id,a.imgid,a.path,a.thumb_path,a.date,a.compression,a.level,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.imgid = b.imgid
AND a.user = 'visitor'
AND a.level = 'everyone'
AND b.width >= 1920
AND b.height >= 1080
ORDER BY a.id DESC
)";
break;
default: default:
# code... # code...
break; break;

35
application/views/user/found.php

@ -2,15 +2,18 @@
// 很无奈的将逻辑写到这里 // 很无奈的将逻辑写到这里
// 写一个获取缩略图的函数 // 写一个获取缩略图的函数
$this->load->helper('basic'); $this->load->helper('basic');
//载入常用类
//$this->load->library('basic');
?> ?>
<div class="layui-container" style = "margin-top:2em;margin-bottom:6em;"> <div class="layui-container" style = "margin-top:1em;margin-bottom:6em;">
<div class="layui-row"> <div class="layui-row">
<div class="layui-col-lg12"> <div class="layui-col-lg12" style = "margin-bottom:1em;">
<!-- <div class="layui-btn-group"> <div class="layui-btn-group">
<button class="layui-btn layui-btn-sm"> 默认</button> <a href="/found/all/0" class="layui-btn layui-btn-sm">默认</a>
<button class="layui-btn layui-btn-sm">浏览量</button> <a href="/found/gif/0" class="layui-btn layui-btn-sm">GIF动图</a>
<button class="layui-btn layui-btn-sm">高清</button> <a href="/found/views/0" class="layui-btn layui-btn-sm">浏览量</a>
</div> --> <a href="/found/large/0" class="layui-btn layui-btn-sm">大图</a>
</div>
</div> </div>
</div> </div>
<div class="layui-row layui-col-space5" id = "found"> <div class="layui-row layui-col-space5" id = "found">
@ -31,6 +34,15 @@
<!-- 图片链接 --> <!-- 图片链接 -->
<a href="javascript:;" title="图片链接" class="layui-btn layui-btn-xs layui-btn-normal" onclick = "showlink('<?php echo $img_url; ?>','<?php echo $thumburl; ?>')"><i class="fa fa-link"></i></a> <a href="javascript:;" title="图片链接" class="layui-btn layui-btn-xs layui-btn-normal" onclick = "showlink('<?php echo $img_url; ?>','<?php echo $thumburl; ?>')"><i class="fa fa-link"></i></a>
<a href="/img/<?php echo $img['imgid']; ?>" target = "_blank" class="layui-btn layui-btn-xs layui-btn-normal"><i class="fa fa-globe"></i></a> <a href="/img/<?php echo $img['imgid']; ?>" target = "_blank" class="layui-btn layui-btn-xs layui-btn-normal"><i class="fa fa-globe"></i></a>
<!-- 用户已登录才显示删除按钮 -->
<?php
if($is_login){
?>
<button class="layui-btn layui-btn-xs layui-btn-danger" title = "删除这张图片" onclick = "del_img('<?php echo $img['id']; ?>','<?php echo $img['imgid'] ?>','<?php echo $img['path']; ?>','<?php echo $thumbpath; ?>')">
<i class="fa fa-trash-o"></i>
</button>
<?php } ?>
<!-- 删除按钮end -->
</div> </div>
</div> </div>
</div> </div>
@ -38,7 +50,16 @@
} }
?> ?>
</div> </div>
<!-- 分页按钮 -->
<div class="layui-row" style = "margin-top:2em;margin-bottom:5em;">
<div class="layui-col-lg6" id = "paging">
<?php echo $page; ?>
</div>
</div>
<!-- 分页按钮 -->
</div> </div>
<!-- 这个div是container结束那部分 -->
<div class="layui-row" id = "imglink"> <div class="layui-row" id = "imglink">
<div class="layui-col-lg10 layui-col-md-offset1"> <div class="layui-col-lg10 layui-col-md-offset1">

2
data/version.txt

@ -1 +1 @@
v2.1-20190318 v2.1.1-20190323

17
static/embed.js

@ -231,3 +231,20 @@ function resetpass(){
}); });
} }
} }
//删除单张图片
function del_img(id,imgid,path,thumbnail_path){
layer.confirm('确认删除这张图片?', {icon: 3, title:'温馨提示!'}, function(index){
$.post("/set/del_img",{imgid:imgid,path:path,thumbnail_path:thumbnail_path},function(data,status){
var re = JSON.parse(data);
if(re.code == 200) {
$("#img"+id).remove();
console.log("#img"+id);
}
else{
layer.msg(data);
}
});
layer.close(index);
});
}

12
static/style.css

@ -539,3 +539,15 @@ body{
margin-bottom:20px; margin-bottom:20px;
color:#FFFFFF; color:#FFFFFF;
} }
/* 分页CSS样式 */
#paging .paging{
padding:0.6em;
background: #eeeeee;
margin-right: 0.5em;
}
#paging strong{
padding:0.6em;
background: #5FB878;
margin-right: 0.5em;
color:#FFFFFF;
}
Loading…
Cancel
Save