tpl = TEMPLATE.'explorer/'; $this->user = $_SESSION['kod_user']; if (isset($this->in['path'])) { //游客访问别人zip,解压到**目录;入口不检测权限 $path_from_not_check = array('explorer:unzip'); $path_from_not_check_flag = in_array(ST.':'.ACT,$path_from_not_check); if($path_from_not_check_flag){ $GLOBALS['path_from_auth_check'] = true; } $this->path = _DIR($this->in['path']); if($path_from_not_check_flag){ $GLOBALS['path_from_auth_check'] = false; } $this->check_system_path(); } } public function index(){ $dir = ''; if(isset($this->in['path']) && $this->in['path'] !=''){ $dir = _DIR_CLEAR($_GET['path']); $dir = rtrim($dir,'/').'/'; } $this->assign('dir',$dir); if ($this->config['forceWap']) { $this->display('index_wap.php'); }else{ $this->display('index.php'); } } //system virtual folder; private function check_system_path(){ if(!in_array(ACT,array('mkfile','mkdir','search', 'pathCuteDrag','pathCopyDrag','pathPast','fileDownload'))){ return; } if( $GLOBALS['path_type'] == KOD_USER_SHARE && !strstr(trim($this->in['path'],'/'),'/')){//分享根目录 show_json($this->L['error'],false); } if(in_array($GLOBALS['path_type'],array( KOD_USER_FAV, KOD_GROUP_ROOT_ALL, KOD_GROUP_ROOT_SELF ) )){ show_json($this->L['system_path_not_change'],false); } } public function pathInfo(){ $info_list = json_decode($this->in['data_arr'],true); if(!$info_list){ show_json($this->L['error'],false); } foreach ($info_list as &$val) { $val['path'] = _DIR($val['path']); } $data = path_info_muti($info_list,$this->L['time_type_info']); if(!$data){ show_json($this->L['not_exists'],false); } //属性查看,单个文件则生成临时下载地址。没有权限则不显示 if (count($info_list)==1 && $info_list[0]['type']!='folder') {//单个文件 $file = $info_list[0]['path']; if( $GLOBALS['is_root'] || $GLOBALS['auth']['explorer:fileDownload']==1 || isset($this->in['viewPage'])){ $data['download_path'] = _make_file_proxy($file); } if($data['size'] < 100*1024|| isset($this->in['get_md5'])){//100kb $data['file_md5'] = @md5_file($file); }else{ $data['file_md5'] = "..."; } //获取图片尺寸 $ext = get_path_ext($file); if(in_array($ext,array('jpg','gif','png','jpeg','bmp')) ){ load_class('imageThumb'); $size = imageThumb::imageSize($file); if($size){ $data['image_size'] = $size; } } } $data['path'] = _DIR_OUT($data['path']); show_json($data); } public function pathChmod(){ $info_list = json_decode($this->in['data_arr'],true); if(!$info_list){ show_json($this->L['error'],false); } $mod = octdec('0'.$this->in['mod']); $success=0;$error=0; foreach ($info_list as $val) { $path = _DIR($val['path']); if(chmod_path($path,$mod)){ $success++; }else{ $error++; } } $state = $error==0?true:false; $info = $success.' success,'.$error.' error'; if (count($info_list) == 1 && $error==0) { $info = $this->L['success']; } show_json($info,$state); } public function mkfile(){ $tpl_path = BASIC_PATH.'static/others/newfile-tpl/'; space_size_use_check(); $repeat_type = 'skip'; if(isset($this->in['repeat_type'])){ $repeat_type = $this->in['repeat_type']; } $new= rtrim($this->path,'/'); $new = get_filename_auto($new,'',$repeat_type);//已存在处理 创建副本 if(@touch($new)){ chmod_path($new,DEFAULT_PERRMISSIONS); if (isset($this->in['content'])) { file_put_contents($new,$this->in['content']); }else{ $ext = get_path_ext($new); $tpl_file = $tpl_path.'newfile.'.$ext; if(file_exists($tpl_file)){ $content = file_get_contents($tpl_file); file_put_contents($new,$content); } } space_size_use_change($new); show_json($this->L['create_success'],true,_DIR_OUT(iconv_app($new)) ); }else{ show_json($this->L['create_error'],false); } } public function mkdir(){ space_size_use_check(); $repeat_type = 'skip'; if(isset($this->in['repeat_type'])){ $repeat_type = $this->in['repeat_type']; } $new = rtrim($this->path,'/'); $new = get_filename_auto($new,'',$repeat_type);//已存在处理 创建副本 if(mk_dir($new,DEFAULT_PERRMISSIONS)){ chmod_path($new,DEFAULT_PERRMISSIONS); show_json($this->L['create_success'],true,_DIR_OUT(iconv_app($new)) ); }else{ show_json($this->L['create_error'],false); } } public function pathRname(){ $rname_to=_DIR($this->in['rname_to']); if (file_exist_case($rname_to)) { show_json($this->L['name_isexists'],false); } if(@rename($this->path,$rname_to)){ show_json($this->L['rname_success'],true,_DIR_OUT(iconv_app($rname_to)) ); }else{ show_json($this->L['no_permission_write_all'],false); } } public function search(){ if (!isset($this->in['search'])) show_json($this->L['please_inpute_search_words'],false); $is_content = intval($this->in['is_content']); $is_case = intval($this->in['is_case']); $ext= trim($this->in['ext']); //共享根目录不支持搜索 if( $GLOBALS['path_type'] == KOD_USER_SHARE && strstr($this->path,KOD_USER_SHARE)){ show_json($this->L['path_cannot_search'],false); } $list = path_search( $this->path, iconv_system(rawurldecode($this->in['search'])), $is_content,$ext,$is_case); show_json(_DIR_OUT($list)); } public function pathList(){ $user_path = $this->in['path']; if ($user_path=="") $user_path='/'; $list=$this->path($this->path); //自己的根目录 if($this->path== MYHOME || $this->path==HOME){ $this->_self_root_load($list['folderlist']); } //群组根目录 if( $list['info']['path_type'] == KOD_GROUP_PATH && !strstr(trim(_DIR_CLEAR($this->in['path']),'/'),'/') ){//自己的根目录 $this->_self_group_load($list['folderlist']); } $list['user_space'] = $this->user['config']; show_json($list); } public function treeList(){//树结构 $app = $this->in['app'];//是否获取文件 传folder|file if (isset($this->in['type']) && $this->in['type']=='init'){ $this->_tree_init($app); } //根树目录请求 switch(trim(rawurldecode($this->in['path']))){ case KOD_USER_FAV: show_json($this->_tree_fav(),true); break; case KOD_GROUP_ROOT_SELF: show_json($this->_group_self(),true); break; case KOD_GROUP_ROOT_ALL: show_json($this->_group_tree('1'),true); break; default:break; } //树目录组处理 if ( (isset($this->in['tree_icon']) && $this->in['tree_icon']!='groupPublic') && //公共目录刷新排除 !strstr(trim(rawurldecode($this->in['path']),'/'),'/') && ($GLOBALS['path_type'] == KOD_GROUP_PATH|| $GLOBALS['path_type'] == KOD_GROUP_SHARE)) { $list = $this->_group_tree($GLOBALS['path_id']); show_json($list,true); return; } //正常目录 $path=_DIR($this->in['path']); if (!path_readable($path)) show_json($this->L['no_permission_read'],false); $list_file = ($app == 'editor'?true:false);//编辑器内列出文件 $list=$this->path($path,$list_file,true); function sort_by_key($a, $b){ if ($a['name'] == $b['name']) return 0; return ($a['name'] > $b['name']) ? 1 : -1; } usort($list['folderlist'], "sort_by_key"); usort($list['filelist'], "sort_by_key"); if($path == MYHOME || $path==HOME){//自己的根目录 // $this->_self_root_load($list['folderlist']); } if ($app == 'editor') { $res = array_merge($list['folderlist'],$list['filelist']); show_json($res,true); }else{ show_json($list['folderlist'],true); } } //用户根目录 private function _self_group_load(&$root){ foreach ($root as $key => $value) { if($value['name'] == 'share'){ $root[$key] = array( 'name' => $this->L['group_share'], 'menuType' => "menufolder folderBox", 'ext' => "folder_share", 'isParent' => true, 'is_readable' => true, 'is_writeable' => true, 'path' => KOD_GROUP_PATH.':'.$GLOBALS['path_id'].'/share/', 'type' => 'folder', 'open' => false, 'isParent' => false ); break; } } $root = array_values($root); } //用户根目录 private function _self_root_load(&$root){ foreach ($root as $key => $value) { if($value['name'] == 'share'){ $root[$key] = array( 'name' => $this->L['my_share'], 'menuType' => "menuTreeUser", 'ext' => "folder_share", 'isParent' => true, 'is_readable' => true, 'is_writeable' => true, 'path' => KOD_USER_SHARE.':'.$this->user["user_id"].'/', 'type' => 'folder', 'open' => false, 'isParent' => false ); break; } } $root = array_values($root); //不开启回收站则不显示回收站 if($this->config['user']['recycle_open']=="1"){ // $root[] = array( // 'name'=>$this->L['recycle'], // 'menuType' =>"menuRecycleButton", // 'ext' =>"recycle", // 'isParent' => true, // 'is_readable' => true, // 'is_writeable' => true, // 'path' => KOD_USER_RECYCLE, // 'type' => 'folder', // 'open' => true, // 'isParent' => false // ); } } private function _tree_fav(){ $check_file = ($this->in['app'] == 'editor'?true:false); $favData=new fileCache(USER.'data/fav.php'); $fav_list = $favData->get(); $fav = array(); $GLOBALS['path_from_auth_check'] = true;//组权限发生变更。导致访问group_path 无权限退出问题 foreach($fav_list as $key => $val){ $the_path = _DIR($val['path']); $has_children = path_haschildren($the_path,$check_file); if( !isset($val['type'])){ $val['type'] = 'folder'; } if( in_array($val['type'],array('group'))){ $has_children = true; } $cell = array( 'name' => $val['name'], 'ext' => isset($val['ext'])?$val['ext']:"", 'menuType' => "menuTreeFav", 'path' => $val['path'], 'type' => $val['type'], 'open' => false, 'isParent' => $has_children ); if( $cell['type'] == 'folder' && $cell['ext'] == "" ){ $cell['menuType'] = 'menuTreeFolderFav'; $cell['exists'] = intval(file_exists($the_path)); } if(isset($val['type']) && $val['type']!='folder'){//icon优化 $cell['ext'] = $val['type']; } $fav[] = $cell; } $GLOBALS['path_from_auth_check'] = false; return $fav; } private function _tree_init($app){ if ($app == 'editor' && isset($this->in['project'])) { $list_project = $this->path(_DIR($this->in['project']),true,true); $project = array_merge($list_project['folderlist'],$list_project['filelist']); $tree_data = array( array('name'=> get_path_this($this->in['project']), 'children' =>$project, 'menuType' => "menuTreeRoot", 'ext' => "folder", 'path' => $this->in['project'], 'type' => 'folder', 'open' => true, 'isParent' => count($project)>0?true:false) ); show_json($tree_data); return; } $check_file = ($app == 'editor'?true:false); $fav = $this->_tree_fav($app); $public_path = KOD_GROUP_PATH.':1/'; $group_root = system_group::get_info(1); $group_root_name = $this->L['public_path']; if($group_root && $group_root['name'] != 'public'){ $group_root_name = $group_root['name']; } if(system_member::user_auth_group(1) == false){ $public_path = KOD_GROUP_SHARE.':1/';//不在公共组则只能读取公共组共享目录 } $list_public = $this->path(_DIR($public_path),$check_file,true); $list_root = $this->path(_DIR(MYHOME),$check_file,true); if ($check_file) {//编辑器 $root = array_merge($list_root['folderlist'],$list_root['filelist']); $public = array_merge($list_public['folderlist'],$list_public['filelist']); }else{//文件管理器 $root = $list_root['folderlist']; $public = $list_public['folderlist']; //$this->_self_root_load($root);//自己的根目录 含有我的共享和回收站 } $root_isparent = count($root)>0?true:false; $public_isparent = count($public)>0?true:false; $tree_data = array( 'fav'=>array( 'name' => $this->L['fav'], 'ext' => "treeFav", 'menuType' => "menuTreeFavRoot", 'children' => $fav, 'path' => KOD_USER_FAV, 'type' => 'folder', 'open' => true, 'isParent' => count($fav)>0?true:false ), 'my_home'=>array( 'name' => $this->L['root_path'], 'menuType' => "menuTreeRoot", 'ext' => "treeSelf", 'children' => $root, 'path' => MYHOME, 'type' => 'folder', 'open' => true, 'isParent' => $root_isparent ), 'public'=>array( 'name' => $group_root_name, 'menuType' => "menuTreeGroupRoot", 'ext' => "groupPublic", 'children' => $public, 'path' => $public_path, 'type' => 'folder', 'open' => true, 'isParent' => $public_isparent ), 'my_group'=>array( 'name' => $this->L['my_kod_group'],//TODO 'menuType' => "menuTreeGroupRoot", 'ext' => "groupSelfRoot", 'children' => $this->_group_self(), 'path' => KOD_GROUP_ROOT_SELF, 'type' => 'folder', 'open' => true, 'isParent' => true ), 'group'=>array( 'name' => $this->L['kod_group'], 'menuType' => "menuTreeGroupRoot", 'ext' => "groupRoot", 'children' => $this->_group_tree('1'), 'path' => KOD_GROUP_ROOT_ALL, 'type' => 'folder', 'open' => true, 'isParent' => true ), ); //编辑器简化树目录 if($app == 'editor'){ unset($tree_data['my_group']); unset($tree_data['group']); unset($tree_data['public']); //管理员,优化编辑器树目录 if($GLOBALS['is_root']==1){ $list_web = $this->path(_DIR(WEB_ROOT),$check_file,true); $web = array_merge($list_web['folderlist'],$list_web['filelist']); $tree_data['webroot'] = array( 'name' => "webroot", 'menuType' => "menuTreeRoot", 'ext' => "folder", 'children' => $web, 'path' => WEB_ROOT, 'type' => 'folder', 'open' => true, 'isParent' => true ); } } $result = array(); foreach ($tree_data as $key => $value) { //为空则不展示 if( count($value['children'])<1 && in_array($key,array('my_group','group')) ){//'fav' continue; //$value['isParent'] = false; } $result[] = $value; } show_json($result); } //session记录用户可以管理的组织;继承关系 private function _group_tree($node_id){//获取组织架构的用户和子组织;为空则获取根目录 $group_sql = system_group::load_data(); $groups = $group_sql->get(array('parent_id',$node_id)); $group_list = $this->_make_node_list($groups); if( $node_id == '1' && !$this->config['setting_system']['root_list_group']){//根群组不显示子群组 $group_list = array(); } if( $node_id == '1' && !$this->config['setting_system']['root_list_user']){//根群组不显示用户 return $group_list; } //user $user_list = array(); $user = system_member::get_user_at_group($node_id); foreach($user as $key => $val){ $tree_icon = 'user'; if ($val['user_id'] == $this->user['user_id']) { $tree_icon = 'userSelf'; } $user_list[] = array( 'name' => $val['name'], 'menuType' => "menuTreeUser", 'ext' => $tree_icon, 'path' => KOD_USER_SHARE.':'.$val['user_id'].'/', 'type' => 'folder', 'open' => false, 'isParent' => false ); } return array_merge($group_list,$user_list); } //session记录用户可以管理的组织;继承关系 private function _group_self(){//获取组织架构的用户和子组织;为空则获取根目录 $groups = array(); foreach ($this->user['group_info'] as $group_id=>$val){ if($group_id=='1') continue; $item = system_group::get_info($group_id); if($item){ $groups[] = $item; } } return $this->_make_node_list($groups); } private function _make_node_list($list){ $group_list = array(); if(!is_array($list)){ return $group_list; } foreach($list as $key => $val){ $group_path = KOD_GROUP_PATH; $auth = system_member::user_auth_group($val['group_id']); if($auth==false){//是否为该组内部成员 $group_path = KOD_GROUP_SHARE; $tree_icon = 'groupGuest'; }else{ $tree_icon = 'groupSelf'; } $has_children = true; $user_list = system_member::get_user_at_group($val['group_id']); if(count($user_list)==0 && $val['children']==''){ $has_children = false; } $group_list[] = array( 'name' => $val['name'], 'type' => 'folder', 'path' => $group_path.':'.$val['group_id'].'/', 'ext' => $tree_icon, 'tree_icon' => $tree_icon,//request 'menuType' => "menuTreeGroup", 'isParent' => $has_children ); } return $group_list; } public function pathDelete(){ $list = json_decode($this->in['data_arr'],true); $user_recycle = iconv_system(USER_RECYCLE); if (!is_dir($user_recycle)){ mk_dir($user_recycle); } $remove_to_recycle = $this->config['user']['recycle_open']; if(!path_writeable($user_recycle) || isset($this->in['shiftDelete']) ){//回收站不可写则直接删除;传入直接删除参数 $remove_to_recycle = '0'; } $success=0;$error=0; foreach ($list as $val) { if(!$val['path'] || $val['path'] == '/'){ $error++; continue; } $path_this = _DIR($val['path']); //不是自己目录的分享列表,不支持删除 if( $GLOBALS['path_type'] == KOD_USER_SHARE && $GLOBALS['path_id'] != $_SESSION['kod_user']['user_id'] && substr_count(trim($val['path'],'/'),'/') <= 1){ //分享根项目 show_json($this->L['no_permission_write'],false); } // 群组文件删除,移动到个人回收站。 // $GLOBALS['path_type'] == KOD_GROUP_SHARE || // $GLOBALS['path_type'] == KOD_GROUP_PATH || if( $remove_to_recycle !="1" || $GLOBALS['path_type'] == KOD_USER_RECYCLE ){//回收站删除 or 共享删除等直接删除 if ($val['type'] == 'folder') { if(del_dir($path_this)) $success ++; else $error++; }else{ if(del_file($path_this)) $success++; else $error++; } space_size_use_reset();//使用空间重置 }else{ $filename = $user_recycle.get_path_this($path_this); $filename = get_filename_auto($filename,date('_H-i-s'),'folder_rename');//已存在则追加时间 if (move_path($path_this,$filename,'',$this->config['user']['file_repeat'])) { $success++; }else{ $error++; } } } $state = $error==0?true:false; $info = $success.' success,'.$error.' error'; if ($error==0) { $info = $this->L['remove_success']; } show_json($info,$state); } private function _clear_temp(){ $path = iconv_system(USER_TEMP); $time = @filemtime($path); if(time() - $time > 600){//10min without updload del_dir($path); mk_dir($path); } } public function pathDeleteRecycle(){ $user_recycle = iconv_system(USER_RECYCLE); if(!isset($this->in['data_arr'])){ if (!del_dir($user_recycle)) { show_json($this->L['remove_fali'],false); }else{ mkdir($user_recycle); $this->_clear_temp(); space_size_use_reset();//使用空间重置 show_json($this->L['recycle_clear_success'],true); } } $list = json_decode($this->in['data_arr'],true); $success = 0;$error = 0; foreach ($list as $val) { $path_full = _DIR($val['path']); if ($val['type'] == 'folder') { if(del_dir($path_full)) $success ++; else $error++; }else{ if(del_file($path_full)) $success++; else $error++; } } space_size_use_reset();//使用空间重置 if (count($list) == 1) { if ($success) show_json($this->L['remove_success']); else show_json($this->L['remove_fali'],false); }else{ $code = $error==0?true:false; show_json($this->L['remove_success'].$success.'success,'.$error.'error',$code); } } public function pathCopy(){ session_start();//re start $the_list = json_decode($this->in['data_arr'],true); foreach ($the_list as $key => $value) { _DIR(rawurldecode($value['path']));//检测来源权限 } $_SESSION['path_copy']= json_encode($the_list); $_SESSION['path_copy_type']='copy'; show_json($this->L['copy_success']); } public function pathCute(){ session_start();//re start $the_list = json_decode($this->in['data_arr'],true); foreach ($the_list as $key => &$value) { $value['path'] = rawurldecode($value['path']); _DIR($value['path']); } $_SESSION['path_copy']= json_encode($the_list); $_SESSION['path_copy_type']='cute'; show_json($this->L['cute_success']); } public function pathCuteDrag(){ $clipboard = json_decode($this->in['data_arr'],true); $path_past=$this->path; $before_path_type = $GLOBALS['path_type']; $before_path_id = $GLOBALS['path_id']; if (!path_writeable($this->path)) show_json($this->L['no_permission_write'],false); $success=0;$error=0;$data = array(); foreach ($clipboard as $val) { $path_copy = _DIR($val['path']); $filename = get_path_this($path_copy); $auto_path = get_filename_auto($path_past.$filename,'',$this->config['user']['file_repeat']);//已存在处理 创建副本 //跨空间检测 if($before_path_id != $GLOBALS['path_id']){ space_size_use_check(); } if (move_path($path_copy,$auto_path,'',$this->config['user']['file_repeat'])) { $success++; //跨空间操作 用户——组——其他组 任意两者见处理;移动到此处;之前的空间使用量减少,目前的增加 if($before_path_id != $GLOBALS['path_id']){ space_size_use_change($auto_path); space_size_use_change($auto_path,false,$before_path_type,$before_path_id); } $data[] = _DIR_OUT(iconv_app($auto_path)); }else{ $error++; } } $state = $error==0?true:false; $msg = $success.' success,'.$error.' error'; if($error == 0){ $msg = $this->L['success']; } show_json($msg,$state,$data); } public function pathCopyDrag(){ $clipboard = json_decode($this->in['data_arr'],true); $path_past=$this->path; $before_path_type = $GLOBALS['path_type']; $before_path_id = $GLOBALS['path_id']; space_size_use_check(); if (!path_writeable($this->path)) show_json($this->L['no_permission_write'],false); $success=0;$error=0;$data = array(); foreach ($clipboard as $val) { $path_copy = _DIR($val['path']); $filename = get_path_this($path_copy); $auto_path = get_filename_auto($path_past.$filename,'',$this->config['user']['file_repeat']); if ($this->in['filename_auto']==1 && trim($auto_path,'/') == trim($path_copy,'/')) { $auto_path = get_filename_auto($path_past.$filename,'','folder_rename'); } if(copy_dir($path_copy,$auto_path)){ $success++; space_size_use_change($filename);//空间使用增加 $data[] = _DIR_OUT(iconv_app($auto_path)); }else{ $error++; } } $state = $error==0?true:false; $msg = $success.' success,'.$error.' error'; if($error == 0){ $msg = $this->L['success']; } show_json($msg,$state,$data); } public function clipboard(){ $clipboard = json_decode($_SESSION['path_copy'],true); if(!$clipboard){ $clipboard = array(); } show_json($clipboard,true,$_SESSION['path_copy_type']); } public function pathPast(){ if (!isset($_SESSION['path_copy'])){ show_json($this->L['clipboard_null'],false,array()); } $path_past=$this->path;//之前就自动处理权限判断; session_start();//re start $error = ''; $data = array(); $clipboard = json_decode($_SESSION['path_copy'],true); $copy_type = $_SESSION['path_copy_type']; $before_path_type = $GLOBALS['path_type']; $before_path_id = $GLOBALS['path_id']; if (!path_writeable($path_past)) show_json($this->L['no_permission_write'],false,$data); if ($copy_type == 'copy') { }else{ $_SESSION['path_copy'] = json_encode(array()); $_SESSION['path_copy_type'] = ''; } session_write_close(); $GLOBALS['path_from_auth_check'] = true;//粘贴来源检测权限;和粘贴到目标位置冲突 $list_num = count($clipboard); if ($list_num == 0) { show_json($this->L['clipboard_null'],false,$data); } for ($i=0; $i < $list_num; $i++) { $path_copy = _DIR($clipboard[$i]['path']); _DIR($this->in['path']);//重置path_type等数据 $filename = get_path_this($path_copy); $filename_out = iconv_app($filename); if (!file_exists($path_copy)){ $error .= "