From 41d1294ebfa1de4a0b5658704496d6c26fe472d1 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 10 Mar 2019 19:07:01 +0800 Subject: [PATCH] Feat: Folder share --- application/index/controller/Share.php | 40 +++- application/index/controller/Viewer.php | 15 +- application/index/model/FileManage.php | 24 +- application/index/model/ShareHandler.php | 24 +- application/index/view/error.html | 6 +- application/index/view/home/home.html | 139 ++++++++---- application/index/view/home/home1.html | 100 --------- application/index/view/share/share_dir.html | 210 ++++++++++-------- .../index/view/share/share_dir_old.html | 105 +++++++++ application/index/view/viewer/markdown.html | 45 +++- application/index/view/viewer/video.html | 49 +++- application/route.php | 3 + 12 files changed, 506 insertions(+), 254 deletions(-) delete mode 100644 application/index/view/home/home1.html create mode 100644 application/index/view/share/share_dir_old.html diff --git a/application/index/controller/Share.php b/application/index/controller/Share.php index 61733de7..59f2902d 100644 --- a/application/index/controller/Share.php +++ b/application/index/controller/Share.php @@ -35,9 +35,10 @@ class Share extends Controller{ 'dirData' => $shareObj->dirData, 'shareData' => $shareObj->shareData, 'loginStatus' => $this->userObj->loginStatus, - 'userData' => $this->userObj->userSQLData, + 'userData' => $this->userObj->getInfo(), 'groupData' => $shareObj->shareOwner->groupData, 'allowPreview' => Option::getValue("allowdVisitorDownload"), + 'path' => empty(input("get.path"))?"/":input("get.path"), ]); }else{ return view('share_single', [ @@ -85,6 +86,20 @@ class Share extends Controller{ } } + public function Content(){ + $shareId = input('param.key'); + $filePath = input('get.path'); + $shareObj = new ShareHandler($shareId,false); + if(empty($filePath)){ + //todo 单文件时 + }else{ + $contentHandller = $shareObj->getContent($this->userObj,$filePath); + } + if(!$contentHandller[0]){ + return json(["result"=>["success"=>false,"error"=>$contentHandller[1]]]); + } + } + public function chekPwd(){ $shareId = input('key'); $inputPwd = input('password'); @@ -122,7 +137,7 @@ class Share extends Controller{ $shareId = input('param.key'); $reqPathTo = stripslashes(json_decode(file_get_contents("php://input"),true)['path']); $shareObj = new ShareHandler($shareId,false); - return $shareObj->ListFile($reqPathTo); + return json($shareObj->ListFile($reqPathTo)); } public function ListPic(){ @@ -133,8 +148,8 @@ class Share extends Controller{ } public function Thumb(){ - $shareId = input('get.shareKey'); - $filePath = input('get.path'); + $shareId = input('param.key'); + $filePath = urldecode(input('get.path')); if(input("get.isImg") != "true"){ return ""; } @@ -147,6 +162,23 @@ class Share extends Controller{ } } + public function DocPreview(){ + $shareId = input('param.key'); + $filePath = urldecode(input('get.path')); + $shareObj = new ShareHandler($shareId,false); + if(empty($filePath)){ + //TODO 单文件时 + }else{ + $Redirect = $shareObj->getDocPreview($this->userObj,$filePath); + } + + if($Redirect[0]){ + $this->redirect($Redirect[1],302); + }else{ + $this->error($Redirect[1],403,$this->siteOptions); + } + } + public function Delete(){ $shareId = input('post.id'); $shareObj = new ShareHandler($shareId,false); diff --git a/application/index/controller/Viewer.php b/application/index/controller/Viewer.php index 014bf946..94ae7a39 100644 --- a/application/index/controller/Viewer.php +++ b/application/index/controller/Viewer.php @@ -7,6 +7,7 @@ use \app\index\model\Option; use \app\index\model\User; use think\Session; use \app\index\model\FileManage; +use \app\index\model\ShareHandler; class Viewer extends Controller{ @@ -26,12 +27,17 @@ class Viewer extends Controller{ $pathSplit = explode("/",urldecode($path)); $userInfo = $this->userObj->getInfo(); $groupData = $this->userObj->getGroupData(); + $url = "/File/Preview?action=preview&path=".$path; + if(input("get.share")==true){ + $url = "/Share/Preview/".input("get.shareKey")."/?path=".$path; + } return view('video', [ 'options' => Option::getValues(['basic']), 'userInfo' => $userInfo, 'groupData' => $groupData, - 'url' => "/File/Preview?action=preview&path=".$path, + 'url' => $url, 'fileName' => end($pathSplit), + 'isSharePage' => input("?get.share")?"true":"false", ]); } @@ -40,13 +46,18 @@ class Viewer extends Controller{ $pathSplit = explode("/",urldecode($path)); $userInfo = $this->userObj->getInfo(); $groupData = $this->userObj->getGroupData(); + $url = "/File/Content?action=preview&path=".$path; + if(input("get.share")==true){ + $url = "/Share/Content/".input("get.shareKey")."/?path=".$path; + } return view('markdown', [ 'options' => Option::getValues(['basic']), 'userInfo' => $userInfo, 'groupData' => $groupData, - 'url' => "/File/Content?action=preview&path=".$path, + 'url' => $url, 'fileName' => end($pathSplit), 'path' => urldecode($path), + 'isSharePage' => input("?get.share")?"true":"false", ]); } diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index 8b9f9aac..473d6ca4 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -636,11 +636,14 @@ class FileManage extends Model{ } /** - * [List description] - * @param [type] $path [description] - * @param [type] $uid [description] + * 列出文件 + * + * @param 路径 $path + * @param 用户UID $uid + * @param boolean $isShare 是否为分享模式下列出文件 + * @return void */ - static function ListFile($path,$uid){ + static function ListFile($path,$uid,$isShare=false,$originPath=null){ $fileList = Db::name('files')->where('upload_user',$uid)->where('dir',$path)->select(); $dirList = Db::name('folders')->where('owner',$uid)->where('position',$path)->select(); $count= 0; @@ -657,6 +660,12 @@ class FileManage extends Model{ $fileListData['result'][$count]['id'] = $value['id']; $fileListData['result'][$count]['pic'] = ""; $fileListData['result'][$count]['path'] = $value['position']; + if($isShare){ + if (substr($value['position'], 0, strlen($originPath)) == $originPath) { + $value['position'] = substr($value['position'], strlen($originPath)); + } + $fileListData['result'][$count]['path'] = ($value['position']=="")?"/":$value['position']; + } $count++; } foreach ($fileList as $key => $value) { @@ -665,10 +674,15 @@ class FileManage extends Model{ $fileListData['result'][$count]['size'] = $value['size']; $fileListData['result'][$count]['date'] = $value['upload_date']; $fileListData['result'][$count]['type'] = 'file'; - $fileListData['result'][$count]['name2'] = $value["dir"]; $fileListData['result'][$count]['id'] = $value["id"]; $fileListData['result'][$count]['pic'] = $value["pic_info"]; $fileListData['result'][$count]['path'] = $value['dir']; + if($isShare){ + if (substr($value['dir'], 0, strlen($originPath)) == $originPath) { + $value['dir'] = substr($value['dir'], strlen($originPath)); + } + $fileListData['result'][$count]['path'] = ($value['dir']=="")?"/":$value['dir']; + } $count++; } diff --git a/application/index/model/ShareHandler.php b/application/index/model/ShareHandler.php index fb59a8db..3305e076 100644 --- a/application/index/model/ShareHandler.php +++ b/application/index/model/ShareHandler.php @@ -95,6 +95,28 @@ class ShareHandler extends Model{ return $fileObj->getThumb(); } + public function getDocPreview($user,$path){ + $checkStatus = $this->checkSession($user); + if(!$checkStatus[0]){ + return [$checkStatus[0],$checkStatus[1]]; + } + $reqPath = Db::name('folders')->where('position_absolute',$this->shareData["source_name"])->find(); + $fileObj = new FileManage($reqPath["position_absolute"].$path,$this->shareData["owner"]); + $tmpUrl = $fileObj->signTmpUrl(); + return[true,"http://view.officeapps.live.com/op/view.aspx?src=".urlencode($tmpUrl)]; + } + + public function getContent($user,$path=null){ + $checkStatus = $this->checkSession($user); + if(!$checkStatus[0]){ + return [$checkStatus[0],$checkStatus[1]]; + } + $reqPath = Db::name('folders')->where('position_absolute',$this->shareData["source_name"])->find(); + $fileObj = new FileManage($reqPath["position_absolute"].$path,$this->shareData["owner"]); + $fileObj->getContent(); + exit(); + } + public function checkSession($user){ if($this->lockStatus){ return [false,"会话过期,请刷新页面"]; @@ -146,7 +168,7 @@ class ShareHandler extends Model{ } $reqPath = Db::name('folders')->where('position_absolute',$this->shareData["source_name"])->find(); $path = $path == "/"?"":$path; - return FileManage::ListFile($this->shareData["source_name"].$path,$this->shareData["owner"]); + return FileManage::ListFile($this->shareData["source_name"].$path,$this->shareData["owner"],true,$this->shareData["source_name"]); } public function Preview($user){ diff --git a/application/index/view/error.html b/application/index/view/error.html index c7e74ff2..806ca31d 100644 --- a/application/index/view/error.html +++ b/application/index/view/error.html @@ -1,6 +1,4 @@ -{extend name="header_public" /} -{block name="title"}错误提示 - {$options.siteName}{/block} -{block name="content"} +
@@ -19,6 +17,4 @@ -{$options.js_code} -{/block} \ No newline at end of file diff --git a/application/index/view/home/home.html b/application/index/view/home/home.html index 41d59e95..06a53f5d 100644 --- a/application/index/view/home/home.html +++ b/application/index/view/home/home.html @@ -1,6 +1,7 @@ - + + @@ -8,7 +9,7 @@ manifest.json provides metadata used when your web app is added to the homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/ --> - +