Skip to content

Commit

Permalink
附件上传功能更新
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhiliang committed Jan 8, 2016
1 parent c46701a commit 57abcd0
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 346 deletions.
57 changes: 57 additions & 0 deletions App/Admin/Controller/AttachmentController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | TP-Admin [ 多功能后台管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2015 http://www.hhailuo.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: XiaoYao <[email protected]>
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Admin\Controller\CommonController;

/**
* 附件操作
*/
class AttachmentController extends CommonController {
protected $db;
function __construct() {
parent::__construct();
$this->db = model("Attachment");
}
public function index() {
echo "等待开发中……";
}

public function album_list() {
$search = array();
if (isset($_GET['search'])) {
if($_GET['start_time'] && !is_numeric($_GET['start_time'])) {
$search['_string'] = "uploadtime >= " . strtotime($_GET['start_time']);
}
if($_GET['end_time'] && !is_numeric($_GET['end_time'])) {
if ( isset($search['_string'])) {
$search['_string'] .= " and uploadtime <= " . strtotime($_GET['end_time']);
} else {
$search['uploadtime'] = array( 'lt',strtotime($_GET['end_time']) );
}
}
if ($_GET['filename']) {
$search['name'] = array('like', "%".safe_replace($_GET['filename'])."%");
}
}

if (isset($_GET['CKEditor'])) {
$data = $this->db->attachment_list($search, "id desc", '32');
$this->assign('attachs', $data['data']);
$this->assign('pages', $data['pages']);
$this->display("album_for_ckeditor");
} else {
$data = $this->db->attachment_list($search);
$this->assign('attachs', $data['data']);
$this->assign('pages', $data['pages']);
$this->assign('params', explode(',', $_GET['args']));
$this->display();
}
}
}
7 changes: 3 additions & 4 deletions App/Admin/Controller/FileController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ public function upload() {
$result['message'] = $upload->getError();
} else {
$attach_info = current($info);
// 同步到CDN源

$attach_info['thumbs'] = AttachmentLogic::createThumb($attach_info);
// 将附件插入附件表
$attach_info = array(
'actor_id' => $this->user['id'],
'type' => 1,
'url' => $attach_info["savepath"] . $attach_info["savename"],
'path' => $attach_info["savepath"] . $attach_info["savename"],
'name' => $attach_info["savename"],
// 'size' => $attach_info['size'],
'size' => $attach_info['size'],
'ext' => $attach_info['ext'],
'thumbs' => json_decode($attachment_info['thumbs']),
'ip' => get_client_ip(),
'uploaded_at' => date('Y-m-d H:i:s'),
);

if($attachment_id = model("Attachment")->add($attach_info)) {
$attach_info['id'] = $attachment_id;
$attach_info['thumbs'] = AttachmentLogic::createThumb($attach_info);
$result['data'] = $attach_info;
} else {
$result['code'] = 10014;
Expand Down
230 changes: 113 additions & 117 deletions App/Admin/View/Attachment/album_for_ckeditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,121 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理中心</title>
<link href="__PUBLIC__/css/admin/reset.css" rel="stylesheet" type="text/css">
<link href="__PUBLIC__/css/admin/zh-cn-system.css" rel="stylesheet" type="text/css">
<link href="__PUBLIC__/css/admin/table_form.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/admin/style/zh-cn-styles1.css" title="styles1" media="screen">
<link rel="alternate stylesheet" type="text/css" href="__PUBLIC__/css/admin/style/zh-cn-styles2.css" title="styles2" media="screen">
<link rel="alternate stylesheet" type="text/css" href="__PUBLIC__/css/admin/style/zh-cn-styles3.css" title="styles3" media="screen">
<link rel="alternate stylesheet" type="text/css" href="__PUBLIC__/css/admin/style/zh-cn-styles4.css" title="styles4" media="screen">
<script type="text/javascript" src="__PUBLIC__/js/admin/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/admin/jquery.cookie.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/admin/styleswitch.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/admin/admin_common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/JSCal/jscal2.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/JSCal/lang/cn.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/JSCal/jscal2.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/JSCal/border-radius.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/JSCal/win2k/win2k.css">
<link rel="stylesheet" type="text/css" href="CSS_PATH/admin/upload.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/admin/skins/default.css">
<style type="text/css">
.attachment-list li {
width: 120px;
padding: 5px 0;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理中心</title>
<link href="{:asset('css/admin/reset.css')}" rel="stylesheet" type="text/css">
<link href="{:asset('css/admin/zh-cn-system.css')}" rel="stylesheet" type="text/css">
<link href="{:asset('css/admin/table_form.css')}" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="{:asset('css/JSCal/jscal2.css')}">
<link rel="stylesheet" type="text/css" href="{:asset('css/JSCal/border-radius.css')}">
<link rel="stylesheet" type="text/css" href="{:asset('css/JSCal/win2k/win2k.css')}">
<link rel="stylesheet" type="text/css" href="{:asset('css/admin/upload.css')}">
<link rel="stylesheet" type="text/css" href="{:asset('js/admin/skins/default.css')}">
<style type="text/css">
.attachment-list li {
width: 120px;
padding: 5px 0;
}
</style>
<script type="text/javascript" src="{:asset('js/jquery.min.js')}"></script>
<script type="text/javascript" src="{:asset('js/jquery.cookie.js')}"></script>
<script type="text/javascript" src="{:asset('js/admin/admin_common.js')}"></script>
<script type="text/javascript" src="{:asset('js/JSCal/jscal2.js')}"></script>
<script type="text/javascript" src="{:asset('js/JSCal/lang/cn.js')}"></script>
</head>
<body>
<div>
<form name="myform" action="" method="get">
<table width="100%" cellspacing="0" class="search-form">
<tr>
<td>
<div class="lh26 explain-col"> 时间:<input type="text" name="start_time" id="start_time" value="<?php echo $_GET['start_time']; ?>" class="date input-text" readonly="">
<script type="text/javascript">
Calendar.setup({
weekNumbers: false,
inputField : "start_time",
trigger : "start_time",
dateFormat: "%Y-%m-%d",
showTime: false,
minuteStep: 1,
onSelect : function() {this.hide();}
});
</script>&nbsp;-&nbsp;<input type="text" name="end_time" id="end_time" value="<?php echo $_GET['end_time']; ?>" class="date input-text" readonly=""><script type="text/javascript">
Calendar.setup({
weekNumbers: false,
inputField : "end_time",
trigger : "end_time",
dateFormat: "%Y-%m-%d",
showTime: false,
minuteStep: 1,
onSelect : function() {this.hide();}
});
</script>
<label>名称</label>
<input type="text" value="<?php echo $_GET['filename']; ?>" class="input-text" name="filename">
<input type='hidden' name='CKEditor' value='<?php echo $_GET['CKEditor']; ?>'>
<input type='hidden' name='CKEditorFuncNum' value='<?php echo $_GET['CKEditorFuncNum']; ?>'>
<input type='hidden' name='langCode' value='<?php echo $_GET['langCode']; ?>'>
<input type="submit" value="搜索" class="button" name="search">
</div>
</td>
</tr>
</table>
</form>
<ul class="attachment-list" id="fsUploadProgress">
<?php foreach ($attachs as $key => $attach) { ?>
<li>
<div class="img-wrap">
<a href="javascript:;" onclick="javascript:album_cancel(this,'<?php echo $attach['id']; ?>')">
<div class="icon"></div>
<?php if( in_array($attach['ext'], array( 'jpg','gif','png','jpeg' ) ) ) { ?>
<img src="<?php echo $attach['url']; ?>" width="100" height="88" path="<?php echo $attach['url']; ?>" title="<?php echo $attach['name']; ?>">
<?php } else { ?>
<img src="IMG_PATH/admin/flv.png" width="80" path="<?php echo $attach['url']; ?>" title="<?php echo $attach['name']; ?>">
<div>
<form name="myform" action="" method="get">
<table width="100%" cellspacing="0" class="search-form">
<tr>
<td>
<div class="lh26 explain-col"> 时间:<input type="text" name="start_time" id="start_time" value="<?php echo $_GET['start_time']; ?>" class="date input-text" readonly="">
<script type="text/javascript">
Calendar.setup({
weekNumbers: false,
inputField : "start_time",
trigger : "start_time",
dateFormat: "%Y-%m-%d",
showTime: false,
minuteStep: 1,
onSelect : function() {this.hide();}
});
</script>&nbsp;-&nbsp;<input type="text" name="end_time" id="end_time" value="<?php echo $_GET['end_time']; ?>" class="date input-text" readonly=""><script type="text/javascript">
Calendar.setup({
weekNumbers: false,
inputField : "end_time",
trigger : "end_time",
dateFormat: "%Y-%m-%d",
showTime: false,
minuteStep: 1,
onSelect : function() {this.hide();}
});
</script>
<label>名称</label>
<input type="text" value="<?php echo $_GET['filename']; ?>" class="input-text" name="filename">
<input type='hidden' name='CKEditor' value='<?php echo $_GET['CKEditor']; ?>'>
<input type='hidden' name='CKEditorFuncNum' value='<?php echo $_GET['CKEditorFuncNum']; ?>'>
<input type='hidden' name='langCode' value='<?php echo $_GET['langCode']; ?>'>
<input type="submit" value="搜索" class="button" name="search">
</div>
</td>
</tr>
</table>
</form>
<ul class="attachment-list" id="fsUploadProgress">
<?php foreach ($attachs as $key => $attach) { ?>
<li>
<div class="img-wrap">
<a href="javascript:;" onclick="javascript:album_cancel(this,'<?php echo $attach['id']; ?>')">
<div class="icon"></div>
<?php if( in_array($attach['ext'], array( 'jpg','gif','png','jpeg' ) ) ) { ?>
<img src="<?php echo $attach['url']; ?>" width="100" height="88" path="<?php echo $attach['url']; ?>" title="<?php echo $attach['name']; ?>">
<?php } else { ?>
<img src="IMG_PATH/admin/flv.png" width="80" path="<?php echo $attach['url']; ?>" title="<?php echo $attach['name']; ?>">
<?php } ?>
</a>
</div>
</li>
<?php } ?>
</a>
</div>
</li>
<?php } ?>
</ul>
<div id="pages"><?php echo $pages; ?></div>
<table class="aui_dialog" align="right">
<tr>
<td colspan="2" class="aui_footer">
<div class="aui_buttons">
<button class="aui_state_highlight" data-type="commit" type="button">确定</button><button type="button" data-type="cancel">取消</button>
</div>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
function album_cancel(obj,id){
var src = $(obj).children("img").attr("path");
var filename = $(obj).children("img").attr("title");
if($(obj).hasClass('on')){
$(obj).removeClass("on");
} else {
var num = $("#fsUploadProgress a.on").length;
var file_upload_limit = 1;
if(num >= file_upload_limit) {alert('不能选择超过'+file_upload_limit+'个附件'); return false;}
$(obj).addClass("on");
}
}
$(document).ready(function(){
$(".aui_buttons button").click(function(e){
$type = $(this).data("type");
if ($type == 'commit') {
var src = $("#fsUploadProgress a.on");
if (src.length > 0) {
window.opener.CKEDITOR.tools.callFunction(<?php echo $_GET['CKEditorFuncNum']; ?>, $(src).children("img").attr("path"));
};
// window.opener.CKEDITOR.tools.callFunction(<?php echo $_GET['CKEditorFuncNum']; ?>, '');
}
window.close();
})
})
</script>
</ul>
<div id="pages"><?php echo $pages; ?></div>
<table class="aui_dialog" align="right">
<tr>
<td colspan="2" class="aui_footer">
<div class="aui_buttons">
<button class="aui_state_highlight" data-type="commit" type="button">确定</button><button type="button" data-type="cancel">取消</button>
</div>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
function album_cancel(obj,id){
var src = $(obj).children("img").attr("path");
var filename = $(obj).children("img").attr("title");
if($(obj).hasClass('on')){
$(obj).removeClass("on");
} else {
var num = $("#fsUploadProgress a.on").length;
var file_upload_limit = 1;
if(num >= file_upload_limit) {alert('不能选择超过'+file_upload_limit+'个附件'); return false;}
$(obj).addClass("on");
}
}

$(document).ready(function(){
$(".aui_buttons button").click(function(e){
$type = $(this).data("type");
if ($type == 'commit') {
var src = $("#fsUploadProgress a.on");
if (src.length > 0) {
window.opener.CKEDITOR.tools.callFunction(<?php echo $_GET['CKEditorFuncNum']; ?>, $(src).children("img").attr("path"));
};
// window.opener.CKEDITOR.tools.callFunction(<?php echo $_GET['CKEditorFuncNum']; ?>, '');
}
window.close();
})
})
</script>
</body>
</html>
Loading

0 comments on commit 57abcd0

Please sign in to comment.