Merge branch 'master' of github.com:easysoft/zentaopms

This commit is contained in:
wangyidong
2017-05-04 15:19:07 +08:00
8 changed files with 214 additions and 32 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
<?php if($this->session->currentProductType !== 'normal') echo '<span class="label label-info">' . $branches[$branch] . '</span>';?>
</strong>
<div class='actions'>
<?php if(common::hasPriv('file', 'uploadImages')) echo html::a($this->createLink('file', 'uploadImages', 'module=bug&params=' . helper::safe64Encode("productID=$productID&projectID=$projectID&moduleID=$moduleID")), $lang->uploadImages, '', "data-toggle='modal' data-type='iframe' class='btn' data-width='600px'")?>
<?php if(common::hasPriv('file', 'uploadImages')) echo html::a($this->createLink('file', 'uploadImages', 'module=bug&params=' . helper::safe64Encode("productID=$productID&projectID=$projectID&moduleID=$moduleID")), $lang->uploadImages, '', "data-toggle='modal' data-type='iframe' class='btn' data-width='70%'")?>
<?php echo html::commonButton($lang->pasteText, "data-toggle='myModal'")?>
<button type="button" class="btn btn-default" data-toggle="customModal"><i class='icon icon-cog'></i> </button>
</div>
+35 -16
View File
@@ -364,30 +364,49 @@ class file extends control
* @access public
* @return void
*/
public function uploadImages($module, $params)
public function uploadImages($module, $params, $uid = '', $locate = false)
{
if($locate)
{
$sessionName = $uid . 'ImagesFile';
$imageFiles = $this->session->$sessionName;
$this->session->set($module . 'ImagesFile', $imageFiles);
unset($_SESSION[$sessionName]);
die(js::locate($this->createLink($module, 'batchCreate', helper::safe64Decode($params)), 'parent.parent'));
}
if($_FILES)
{
$file = $this->file->getUpload('file');
$file = $file[0];
if(!$file) die(js::alert($this->lang->error->noData));
if($file['extension'] != 'zip') die(js::alert($this->lang->file->errorSuffix));
if($file['size'] == 0) die(js::alert($this->lang->file->errorFileUpload));
if(@move_uploaded_file($file['tmpname'], $this->file->savePath . $file['pathname']))
$file = $this->file->getUploadImageFile('file');
if(!$file) die(json_encode(array('result' => 'fail', 'message' => $this->lang->error->noData)));
if(empty($file['extension']) or !in_array($file['extension'], $this->config->file->imageExtensions))
{
$zipFile = $this->file->savePath . $file['pathname'];
$files = $this->file->extractZip($zipFile);
die(json_encode(array('result' => 'fail', 'message' => $this->lang->file->errorFileFormate)));
}
unlink($zipFile);
if(!$files) die(js::alert($this->lang->file->errorExtract));
$this->session->set($module . 'ImagesFile', $files);
die(js::locate($this->createLink($module, 'batchCreate', helper::safe64Decode($params)), 'parent.parent'));
$imageFile = $this->file->saveUploadImageFile($file, $uid);
if($imageFile === false)
{
die(json_encode(array('result' => 'fail', 'message' => $this->lang->file->errorFileMove)));
}
else
{
if(!empty($imageFile))
{
$sessionName = $uid . 'ImagesFile';
$imageFiles = $this->session->$sessionName;
$fileName = basename($imageFile['pathname']);
$imageFiles[$fileName] = $imageFile;
$this->session->set($sessionName, $imageFiles);
}
die(json_encode(array('result' => 'success', 'file' => $file, 'message' => $this->lang->file->uploadSuccess)));
}
}
$this->view->uid = empty($uid) ? uniqid() : $uid;
$this->view->module = $module;
$this->view->params = $params;
$this->display();
}
+7 -5
View File
@@ -26,17 +26,19 @@ $lang->file->exportFields = "要导出字段";
$lang->file->defaultTPL = "默认模板";
$lang->file->setExportTPL = "设置";
$lang->file->preview = "预览";
$lang->file->addFile = '添加文件';
$lang->file->beginUpload = '开始上传';
$lang->file->uploadSuccess = '上传成功';
$lang->file->dragFile = '请拖拽文件到此处';
$lang->file->errorNotExists = "<span class='red'>文件夹 '%s' 不存在</span>";
$lang->file->errorCanNotWrite = "<span class='red'>文件夹 '%s' 不可写,请改变文件夹的权限。在linux中输入指令:sudo chmod -R 777 '%s'</span>";
$lang->file->confirmDelete = " 您确定删除该附件吗?";
$lang->file->errorFileSize = " 文件大小已经超过限制,可能不能成功上传!";
$lang->file->errorFileUpload = " 文件上传失败,文件大小可能超出限制";
$lang->file->errorFileFormate = " 文件上传失败,文件格式不在规定范围内";
$lang->file->errorFileMove = " 文件上传失败,移动文件时出错";
$lang->file->dangerFile = " 您选择的文件存在安全风险,系统将不予上传。";
$lang->file->errorSuffix = '压缩包格式错误,只能上传zip压缩包!';
$lang->file->errorExtract = '解压缩失败!可能文件已经损坏,或压缩包里含有非法上传文件。';
$lang->file->uploadImagesExplain = <<<EOD
<p>1、上传文件为包含图片的zip压缩包,程序会以文件名作为标题,以图片作为内容。</p>
<p>2、如果文件名开头含有 数字+下划线,以方便排序,程序会将他们忽略。</p>
<p>3、图片格式:jpg|jpeg|gif|png。</p>
EOD;
$lang->file->uploadImagesExplain = '注:请上传"jpg|jpeg|gif|png"格式的图片,程序会以文件名作为标题,以图片作为内容。';
+103
View File
@@ -171,6 +171,109 @@ class fileModel extends model
return $files;
}
/**
* get uploaded image file from zui.uploader.
*
* @param string $htmlTagName
* @access public
* @return array
*/
public function getUploadImageFile($htmlTagName = 'file')
{
if(!isset($_FILES[$htmlTagName]) || empty($_FILES[$htmlTagName]['name'])) return;
$this->app->loadClass('purifier', true);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
extract($_FILES[$htmlTagName]);
if(!validater::checkFileName($name)) return array();
if($this->post->name) $name = $this->post->name;
$file = array();
$file['id'] = 0;
$file['extension'] = $this->getExtension($name);
$file['title'] = !empty($_POST['label']) ? htmlspecialchars($_POST['label']) : substr($name, 0, strpos($name, $file['extension']) - 1);
$file['title'] = $purifier->purify($file['title']);
$file['size'] = $_POST['size'];
$file['tmpname'] = $tmp_name;
$file['uuid'] = $_POST['uuid'];
$file['pathname'] = $this->setPathName(0, $file['extension']);
$file['chunkpath'] = 'chunks' . DS .'f_' . $file['uuid'] . '.' . $file['extension'] . '.part';
$file['chunks'] = isset($_POST['chunks']) ? intval($_POST['chunks']) : 0;
$file['chunk'] = isset($_POST['chunk']) ? intval($_POST['chunk']) : 0;
return $file;
}
/**
* Save uploaded image file.
*
* @param int $file
* @param int $uid
* @access public
* @return array|bool
*/
public function saveUploadImageFile($file, $uid)
{
$imageFile = array();
$cachePath = $this->app->getCacheRoot() . 'uploadimages/';
if(!is_dir($cachePath)) mkdir($cachePath, 0777, true);
$imageFilePath = $cachePath . $uid . '/';
if(!is_dir($imageFilePath)) mkdir($imageFilePath);
$fileName = basename($file['pathname']);
$file['realpath'] = $imageFilePath . $fileName;
if($file['chunks'] > 1)
{
$fileSavePath = $cachePath . $file['chunkpath'];
if(!file_exists($fileSavePath)) mkdir(dirname($fileSavePath));
if($file['chunk'] > 0)
{
$uploadFile = fopen($fileSavePath, 'a+b');
$tmpChunkFile = fopen($file['tmpname'], 'rb');
while($buff = fread($tmpChunkFile, 4069))
{
fwrite($uploadFile, $buff);
}
fclose($uploadFile);
fclose($tmpChunkFile);
}
else
{
if(!move_uploaded_file($file['tmpname'], $fileSavePath)) return false;
}
if($file['chunk'] == ($file['chunks'] - 1))
{
rename($fileSavePath, $file['realpath']);
$imageFile['extension'] = $file['extension'];
$imageFile['pathname'] = $file['pathname'];
$imageFile['title'] = $file['title'];
$imageFile['realpath'] = $file['realpath'];
$imageFile['size'] = $file['size'];
}
}
else
{
if(!move_uploaded_file($file['tmpname'], $file['realpath'])) return false;
$imageFile['extension'] = $file['extension'];
$imageFile['pathname'] = $file['pathname'];
$imageFile['title'] = $file['title'];
$imageFile['realpath'] = $file['realpath'];
$imageFile['size'] = $file['size'];
}
return $imageFile;
}
/**
* Get extension of a file.
*
+38 -9
View File
@@ -11,13 +11,42 @@
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<form class='form-condensed' enctype='multipart/form-data' method='post' target='hiddenwin' style='padding: 20px 5% 50px'>
<table class='table table-form'>
<tr>
<td class='w-p70'><input type='file' name='file' class='form-control'/></td>
<td><?php echo html::submitButton();?></td>
</tr>
<tr><td colspan='2'><div class='alert'><?php echo $lang->file->uploadImagesExplain?></div></td></tr>
</table>
</form>
<?php
js::import($jsRoot . 'uploader/min.js');
css::import($jsRoot . 'uploader/min.css');
?>
<style>
#uploader{padding: 20px;}
#uploader > span{display:block; margin-bottom:10px; color: #29a8cd;}
</style>
<div class='uploader' id='uploader' data-url='<?php echo inlink('uploadImages', "module=$module&params=$params&uid=$uid");?>'>
<div class='uploader-message text-center'>
<div class='content'></div>
<button type='button' class='close'>×</button>
</div>
<div class='file-list file-list-lg' data-drag-placeholder="<?php echo $lang->file->dragFile;?>"></div>
<span><?php echo $this->lang->file->uploadImagesExplain?></span>
<div class='uploader-footer'>
<div class='uploader-status pull-right text-muted'></div>
<button type='button' class='btn btn-primary uploader-btn-browse'><i class='icon icon-plus'></i><?php echo $lang->file->addFile;?></button>
<button type='button' class='btn btn-success uploader-btn-start'><i class='icon icon-cloud-upload'></i><?php echo $lang->file->beginUpload;?></button>
<?php echo html::a(inlink('uploadImages', "module=$module&params=$params&uid=$uid&locate=true"), $lang->save, '', "class='btn'");?>
</div>
</div>
<script>
$('#uploader').uploader({
onBeforeUpload: function(file)
{
this.plupload.setOption(
{
'multipart_params':
{
label: file.ext ? file.name.substr(0, file.name.length - file.ext.length - 1) : file.name,
uuid: file.id,
size: file.size
}
});
}
});
</script>
<?php include '../../common/view/footer.lite.html.php';?>
+1 -1
View File
@@ -20,7 +20,7 @@
<?php if($product->type !== 'normal') echo '<span class="label label-info">' . $branches[$branch] . '</span>';?>
</strong>
<div class='actions'>
<?php if(common::hasPriv('file', 'uploadImages')) echo html::a($this->createLink('file', 'uploadImages', 'module=story&params=' . helper::safe64Encode("productID=$productID&moduleID=$moduleID")), $lang->uploadImages, '', "data-toggle='modal' data-type='iframe' class='btn' data-width='600px'")?>
<?php if(common::hasPriv('file', 'uploadImages')) echo html::a($this->createLink('file', 'uploadImages', 'module=story&params=' . helper::safe64Encode("productID=$productID&moduleID=$moduleID")), $lang->uploadImages, '', "data-toggle='modal' data-type='iframe' class='btn' data-width='70%'")?>
<?php echo html::commonButton($lang->pasteText, "data-toggle='myModal'")?>
<button type="button" class="btn btn-default" data-toggle="customModal"><i class='icon icon-cog'></i> </button>
</div>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long