找回密码
 注册
首页 ≡≡网络技术≡≡ PHP语言 Veno-File-Manager (VFM4)云盘,让编辑用户无权移动删除 ...

CMS Veno-File-Manager (VFM4)云盘,让编辑用户无权移动删除只读目录

灰儿 2022-9-19 08:37:29
Veno-File-Manager (VFM4)云盘,让编辑用户无权移动、更名、删除用户只读目录

1.修改前端显示UI代码,让游客和登录用户显示公共目录(public_dirs)、用户只读目录(user_read_dirs)和根目录(starting_dir)中的文件
打开根目录 vfm-admin/template/list-files.php 文件,把条件判断语句改为如下格式:
  1. if ($gateKeeper->isAccessAllowed()){
  2. if( $location->editAllowed()
  3.     || $location->guestReadtAllowed()
  4.     || $location->userReadtAllowed() && $gateKeeper->isUserLoggedIn()
  5.     || $location->getCleanPath() ==="") {
  6.     if ($gateKeeper->isAllowed('view_enable')) {

  7.   列表显示文件代码 }
  8.   显示上传文件功能区块代码 }
  9. }
复制代码

存在问题,当以上代码中添加 guestReadtAllowed()、userReadtAllowed() 、getCleanPath() ==="" 三条判断语句后,会出现一个新的bug,即编辑(editor)用户打开首页、游客公共目录(public_dirs)或用户只读公共目录(user_read_dirs),一直显示加载状态,打不开网页。
编辑用户打开首页不正常.jpg

解决方法:
打开根目录 vfm-admin/include/load-js.php文件,查找与更名 (rename_enable) 相关代码,把显示条件判断语句改为如下格式:
单选操作(右侧):更名
  1. if ($gateKeeper->isAllowed('rename_enable') && $location->editAllowed())
复制代码

解决浏览公共目录(user_read_dirs)下文件时时,“多选操作”菜单中仍显示移动、复制和删除按钮的问题:

065348szprnwn8npwnw3rp.png

大概在65行左右,添加条件判断语句,使“多选操作”菜单中不显示移动、复制和删除按钮,改后代码如下:
  1. if ($gateKeeper->isAllowed('move_enable') && $location->checkUserDir()) { ?>
  2.    
  3.         [url=#]getString("move"); ?>[/url]
  4.    
  5.     }
  6. if ($gateKeeper->isAllowed('copy_enable') && $location->checkUserDir()) { ?>
  7.    
  8.         [url=#]getString("copy"); ?>[/url]
  9.    
  10.     }
  11. if ($gateKeeper->isAllowed('delete_enable') && $location->checkUserDir()) { ?>
  12.     [url=#]getString("delete"); ?>[/url]
  13.    
  14.     } ?>
复制代码

也可以把条件语句改为如下代码:
  1. if ($gateKeeper->isAllowed('move_enable') && !$location->guestReadtAllowed() && !$location->userReadtAllowed() && $location->getCleanPath() !=="")
复制代码

解决PC列表模式下显示公共目录(user_read_dirs)下文件时时,表格仍显示重命名和删除列的问题:

111655w1jydk111auo1dnr.png

大概在137行左右,添加条件判断语句,使表格不显示重命名和删除列,改后代码如下:
  1. if ($gateKeeper->isAllowed('rename_enable') && $location->checkUserDir()) { ?>
  2.    
  3.         
  4.    
  5.     } ?>

  6. if ($gateKeeper->isAllowed('delete_enable') && $location->checkUserDir()) {  ?>
  7.    
  8.     } ?>
复制代码

存在问题:即是游客公共目录(public_dirs)又是用户私有目录的文件夹,编辑用户没有编辑权限。

2.修改ajax请求代码,使游客和登录用户能获取到公共目录(public_dirs)、用户只读目录(user_read_dirs)和根目录(starting_dir)中的文件
打开根目录  /vfm-admin/ajax/get-files.php  文件,查找如下代码:
  1. if ($gateKeeper->isAccessAllowed() && $location->editAllowed('../../') && $gateKeeper->isAllowed('view_enable'))
  2. {
  3. $fullpath = $location->getFullPath();
  4. ...
  5. }
复制代码


改为如下代码:
  1. $cleanlocdir = rtrim(ltrim($locdir, './'), '/');
  2. $startdir = './'.$setUp->getConfig('starting_dir');
  3. $cleanstartdir = rtrim(ltrim($startdir, './'), '/');

  4. if ($cleanlocdir === $cleanstartdir
  5. || $gateKeeper->isAccessAllowed()
  6. && $location->guestReadtAllowed('../../')  
  7. || $location->editAllowed('../../')  
  8. || $location->userReadtAllowed('../../')
  9. && $gateKeeper->isAllowed('view_enable')) {
  10.     $fullpath = $location->getFullPath();
  11. ...
  12. }
复制代码


解决平铺视图模式下显示公共目录(user_read_dirs)下文件时时,在文件右上角显示重命名和删除按钮问题:

102241c6d9009s06w9z2iq.png

大概在271行左右,添加条件判断语句,使平铺视图文件右上角不显示重命名和删除按钮,改后代码如下:
  1. if ($gateKeeper->isAllowed('rename_enable') && $location->editAllowed('../../')) {
  2.     $data['icon'] .= '
  3.         
  4.             
  5.         
  6.    
  7. ';
  8. }
  9. if ($gateKeeper->isAllowed('delete_enable') && $location->editAllowed('../../')) {
  10.     $data['icon'] .= '
  11.         
  12.             
  13.         
  14.    
  15. ';
  16. }
复制代码


解决PC浏览器打开公共目录(user_read_dirs)时,在文件列表右侧显示重命名和删除按钮问题:
094805yqr3zcgcga5rh555.png

大概在326行左右,添加条件判断语句,使文件列表右侧不显示重命名和删除按钮,改后代码如下:
  1. $data['delete'] = '';

  2. if ($gateKeeper->isAllowed('delete_enable') && $location->editAllowed('../../')) {
  3.     $data['delete'] .= '
  4. ';
  5. }
复制代码


解决手机端打开公共目录(user_read_dirs)时,在文件列表右侧显示重命名和删除按钮问题:

103252jb2mkib41554gvbv.png

大概在342行左右,添加条件判断语句,使文件列表右侧不显示重命名和删除按钮,改后代码如下码:
  1. if ($gateKeeper->isAllowed('rename_enable') && $location->editAllowed('../../')) {
  2.     $data['delete'] .= '
  3.     '.$setUp->getString("rename").'';
  4. }
  5. if ($gateKeeper->isAllowed('delete_enable') && $location->editAllowed('../../')) {
  6.     $data['delete'] .= '
  7.     '.$setUp->getString("delete").'';
  8. }
复制代码

相关文件:
打开根目录 vfm-admin/template/list-files.php   //多选操作(左侧):移动、复制、删除
根目录 vfm-admin/include/load-js.php             //单选操作(右侧):更名
根目录 vfm-admin/ajax/get-files.php               //单选操作(右侧):删除



您需要登录后才可以回帖 登录 | 注册
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。