Example #1
0
 public function getName($id)
 {
     if ($id > 1000) {
         $obj = new UserDb($id);
     } else {
         $obj = new UserFile($id);
     }
     return $obj->getName();
 }
Example #2
0
 /**
  * 
  * 调用入口
  * @param unknown_type $action
  * 
  * @since 1.1.0
  */
 public function invoke($action)
 {
     if (!empty($this->file_id)) {
         $this->file = UserFile::model()->findByAttributes(array('id' => $this->file_id, 'is_deleted' => 0));
         if (!empty($this->file)) {
             $this->master = CUtils::getUserFromPath($this->file["file_path"]);
         }
     }
     switch ($action) {
         case self::ACTION_SEARCH:
             $retval = $this->handlerSeach();
             break;
         case self::ACTION_LIST_FRIENDS:
             $retval = $this->handlerList();
         default:
             break;
     }
     return $retval;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return UserFile the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = UserFile::model()->findByPk($id);
     $fileModel = new FileUploadForm();
     $fileModel = $model;
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $fileModel;
 }
Example #4
0
 /**
  *
  * 列举共享信息
  */
 public function handlerListDetails()
 {
     $this->_slaves = array();
     $this->_file = UserFile::model()->findByAttributes(array('id' => $this->_id, 'user_id' => $this->_userId, 'is_deleted' => 0));
     if (is_null($this->_file)) {
         throw new ApiException('Not Found');
     }
     if ($this->_file['file_type'] != 2) {
         throw new ApiException('Not Found');
     }
     $meta = FileMeta::model()->findByAttributes(array('file_path' => $this->_file['file_path'], 'meta_key' => self::SHARED_META_FLAG));
     if (!$meta) {
         throw new ApiException('Not Found');
     }
     $meta_value = unserialize($meta['meta_value']);
     if ($meta_value['master'] != $this->_userId) {
         throw new ApiException('Not Found');
     }
     $slaves = $meta_value['slaves'];
     $send = $meta_value['send_msg'];
     foreach ($slaves as $key => $value) {
         $user = User::model()->findByPk($key);
         if (!$user) {
             continue;
         }
         $mate = UserMeta::model()->findByAttributes(array("user_id" => $user->id, "meta_key" => "nick"));
         if ($mate) {
             $value = $mate->meta_value;
             if (!empty($value) && strlen(trim($value)) > 0) {
                 $nick = $value;
             }
         } else {
             $nick = $user['user_name'];
         }
         $shared_file = UserFile::model()->findByAttributes(array('user_id' => $key, 'file_path' => $value, 'is_deleted' => 0));
         $path = $this->_file['file_path'];
         $permission = Yii::app()->privilege->checkPrivilegeUser($key, $path);
         array_push($this->_slaves, array('user_id' => $key, 'user_name' => $user['user_name'], 'nick' => $nick, 'type' => $shared_file['file_type'], 'permission' => $permission, 'send' => $send));
     }
 }
Example #5
0
    html_error_quit("guest 没有Blog!");
} else {
    $link = pc_db_connect();
    $pc = pc_load_infor($link, $_GET["userid"]);
    if (!$pc) {
        pc_db_close($link);
        html_error_quit("对不起,您要查看的Blog不存在");
    }
    if (!pc_is_admin($currentuser, $pc)) {
        pc_db_close($link);
        html_error_quit("对不起,您要查看的Blog不存在");
    }
    $root_pid = bbs_userfile_getrootfid($pc["UID"]);
    $pid = intval($_GET['pid']) ? $_GET['pid'] : $root_pid;
    pc_get_userfiles($link, $pc, $used, $total);
    if (!($c_dir = new UserFile($pid, $pc["UID"]))) {
        pc_db_close($link);
        html_error_quit("对不起,您要查看的目录不存在");
    }
    if ($_GET['act'] == 'edit' || $_GET['act'] == 'edit2' || $_GET['act'] == 'rm' || $_GET['act'] == 'cp' || $_GET['act'] == 'mv' || $_GET['act'] == 'pt') {
        $fid = intval($_GET['fid']);
        if (!$fid) {
            html_error_quit("错误的参数");
        }
        if (!($f = new UserFile($fid, $pc['UID']))) {
            html_error_quit("文件/目录不存在");
        }
    }
    switch ($_GET['act']) {
        case 'add':
            @($errno = $_FILES['pcfile']['error']);
 /**
  *
  * 列举共享信息
  *
  * @since 1.1.0
  */
 public function handlerSetPermission()
 {
     $this->_file = UserFile::model()->findByAttributes(array('id' => $this->_id, 'is_deleted' => 0));
     if (is_null($this->_file)) {
         throw new ApiException('Not Found');
     }
     //判断此用户是否有 分配 权限
     $file_path = $this->_file["file_path"];
     $hasPermissionAllot = Yii::app()->privilege->hasPermission($file_path, MPrivilege::PERMISSION_GRANT);
     if (!$hasPermissionAllot) {
         $this->result["msg"] = Yii::t('front_common', 'Can not grant permission');
         throw new ApiException('Can not grant permission');
     }
     //
     // 将逗号分割的id组装成数组
     //
     if (!empty($this->_slaves)) {
         $this->_slaves = array_slice(explode(',', $this->_slaves), 0);
     } else {
         $this->_slaves = array();
     }
     $this->_permissions = array_slice(explode(',', $this->_permissions), 0);
     $tmpUser = $this->_slaves;
     //查询出此路径下的直接权限的所有用户
     $privileges = MUserPrivilege::model()->findAll('file_path=:file_path', array(':file_path' => $this->_file["file_path"]));
     $currentUser = MUserManager::getInstance()->getCurrentUser();
     foreach ($privileges as $pri) {
         //分配权限时如果权限表中的权限的所有者是自己, 则不进行处理
         if ($pri["user_id"] == $currentUser["id"]) {
             continue;
         }
         //如果此用户不存在则进行添加权限,已经存在则进行修改权限,否则进行删除权限操作
         if (in_array($pri["user_id"], $tmpUser)) {
             $newPermission = $this->getUserPermission($this->_slaves, $pri["user_id"]);
             //进行是否事件生成判断
             $this->updatePrivelegeEvent($pri, $newPermission);
             //更新权限
             Yii::app()->privilege->updatedPrivilege($pri["user_id"], $this->_file["file_path"], $newPermission);
             $tmpUser = CUtils::arrayRemove($tmpUser, $pri["user_id"]);
         } else {
             $pri->delete();
             $this->deletePrivelegeEvent($pri["user_id"], $pri["file_path"], unserialize($pri["permission"]));
         }
     }
     //创建权限
     foreach ($tmpUser as $index => $userId) {
         $permission = $this->getUserPermission($this->_slaves, $userId);
         $this->createPrivelegeEvent($userId, $this->_file["file_path"], $permission);
         Yii::app()->privilege->createPrivilege($userId, $this->_file["file_path"], $permission);
     }
 }
Example #7
0
 /**
  * 更新时间
  */
 public function updateTime($filePath)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "file_path = :file_path";
     $criteria->params = array("file_path" => $filePath);
     $item = UserFile::model()->find($criteria);
     if (isset($item)) {
         $item->save();
     }
 }
Example #8
0
 /**
  * 清理全部的缓存,包括多余的file_meta
  * @param $limit
  */
 public function cleanCache($limit)
 {
     //data源处理对象
     $dataObj = Yii::app()->data;
     // 回收站插件: -1保留值 0正常 1删除
     $this->handleCleanFileMeta($limit);
     // 清理ref_count等于0的文件
     $versions = MiniVersion::getInstance()->getCleanFiles(100);
     foreach ($versions as $version) {
         $files = UserFile::model()->findAll('version_id=?', array($version['id']));
         // 如果$file存在此version_id,不删除
         if (!empty($files)) {
             for ($i = 0; $i < count($files); $i++) {
                 MiniVersion::getInstance()->updateRefCount($version["id"]);
             }
             continue;
         }
         // 如果不存在的话,删除流文件,删除该条version记录
         $signature = $version['file_signature'];
         $signaturePath = MiniUtil::getPathBySplitStr($signature);
         // 判断文件是否存在
         if ($dataObj->exists($signaturePath) === false) {
             MiniVersion::getInstance()->deleteById($version["id"]);
             continue;
         }
         // 删除文件
         $dataObj->delete($signaturePath);
         //删除空的文件夹
         $parts = CUtils::getFoldersBySplitStr($signature);
         foreach ($parts as $part) {
             $dataObj->delete($part);
         }
         // 删除version记录
         MiniVersion::getInstance()->deleteById($version["id"]);
     }
     MiniUtil::deleteDir(BASE . 'temp');
 }
Example #9
0
 function uf_cp($target_fid)
 {
     if ($target_fid == $this->pid) {
         $this->err = '您只能将这个文件复制到另一个文件夹中';
         return false;
     }
     if ($this->type == 1) {
         $this->err = '仅有文件才能复制';
         return false;
     }
     if (!($target_file = new UserFile($target_fid, $this->uid))) {
         $this->err = '目标文件夹不存在';
         return false;
     }
     if (!$target_file->fid) {
         $this->err = '目标文件夹不存在';
         return false;
     }
     if ($target_file->type != 1) {
         $this->err = '您只能将这个文件复制到另一个文件夹中';
         return false;
     }
     $ret = $target_file->add_file($this->filename, 0, $this->filepath, $this->filetype, $this->access, $this->remark, 0);
     $this->err = $target_file->err;
     return $ret;
 }
Example #10
0
 /**
  *
  * 删除用户相关信息
  * @userIds 用户列表{1,2,3,4,5}这样的格式
  */
 public function deleteUsers($userIds)
 {
     if ($userIds != '' && strlen($userIds) > 0) {
         $ids = explode(',', $userIds);
         $userFile = new UserFile();
         foreach ($ids as $id) {
             // 删除用户共享文件
             $userFile->deleteSharedFolders($id);
             //删除所有标签信息
             Tag::model()->deleteUserAllTag($id);
             //删除我的最爱文件
             FileStar::model()->deleteUserAllStar($id);
         }
         //删除用户的文件信息
         $userFile->deleteUserFile($userIds);
         //删除用户的群组部门关系
         MiniUserGroupRelation::getInstance()->deleteUserRelation($userIds);
         //删除用户的事件信息
         MiniEvent::getInstance()->deleteByIds($userIds);
         //删除用户Meta以及用户自己
         foreach ($ids as $id) {
             //删除用户自身
             MiniUser::getInstance()->deleteUser($id);
         }
     }
 }
Example #11
0
 /**
  * 
  * 重命名冲突的文件名
  * @param int $parentId
  * @param string $name
  */
 private function handleRename($parentId, $name)
 {
     $children = UserFile::model()->findAllByAttributes(array("parent_file_id" => $parentId, "user_id" => $this->_userId, "is_deleted" => 0));
     $names = array();
     foreach ($children as $child) {
         $names[$child["file_name"]] = $child["file_name"];
     }
     // 重命名
     $name = CUtils::getConflictName($name, $names);
     return $name;
 }
Example #12
0
 /**
  * author thuan.nguyenhuy@gmail.com
  * set records of logfiles collection (Upload:1 /Donwload:2 /Rename:3 /Move:4 /Copy:5 /Clone:6)
  * @param int $ownerId
  * @param array $log include log information: action, content, descr, ip
  * @return array 
  */
 public static function historyAction($action, $linkCode, $allowdelete = 0)
 {
     $info = UserFile::getRecordInfoByLinkcode($linkCode, $allowdelete);
     $log = array('action' => Yii::t('logfile', $action), 'files' => $info, 'owner_id' => Yii::app()->user->id, 'descr' => $action, 'ip' => Yii::app()->request->userHostAddress);
     $isert = new LogFiles();
     $isert->_id = User::exportRandomPass(22);
     $isert->action = new MongoInt32($log["action"]);
     $isert->files = $log["files"];
     $isert->owner_id = new MongoInt32(Yii::app()->user->id);
     $isert->descr = $log["descr"];
     $isert->ip = $log["ip"];
     $isert->save();
 }
Example #13
0
 /**
  * 根据path找到共享
  */
 public function handlerFindSlave($user_id, $path)
 {
     $meta = FileMeta::model()->findByAttributes(array('file_path' => $path, 'meta_key' => ShareManager::SHARED_META_FLAG));
     if (!$meta) {
         return false;
     }
     $meta_value = unserialize($meta['meta_value']);
     $slaves = $meta_value['slaves'];
     $slaves[$meta_value['master']] = $meta_value['path'];
     if (isset($slaves[$user_id])) {
         $file = UserFile::model()->findByAttributes(array('file_path' => $meta_value['path']));
         if ($file) {
             return $file['id'];
         }
     }
     return false;
 }
Example #14
0
 /**
  * 从数据库中查询, 判断用户名是否重复
  * @param int $userId
  * @param int $parentId
  * @param string $fileName
  * @return string
  */
 public static function getConflictFileName($userId, $parentId, $fileName)
 {
     $files = UserFile::model()->getByParentID($userId, $parentId);
     $names = array();
     foreach ($files as $k => $v) {
         $names[$v["file_name"]] = $v["file_name"];
     }
     $fileName = CUtils::getConflictName($fileName, $names);
     return $fileName;
 }
Example #15
0
 /**
  * 获取回收站文件
  * @return boolean|string
  */
 private function getTrashList()
 {
     $condition = "user_id=:user_id and is_deleted = 1";
     //and parent_file_id not in (select id from ".Yii::app()->params['tablePrefix']."files where is_deleted = 1 and user_id=:user_id)";
     $params = array(':user_id' => $this->_userId);
     //
     // 修改查询条件
     //
     $value = array('condition' => $condition, 'params' => $params);
     $info = UserFile::model()->findAll(array('condition' => $value['condition'], 'params' => $value['params']));
     $files = '';
     foreach ($info as $item) {
         $files .= ',' . $item['id'];
     }
     if (empty($files)) {
         return false;
     }
     return substr($files, 1);
 }
Example #16
0
 public function findByUseridAndFileid($user_id, $file_id)
 {
     $data = UserFile::model()->findAllBySql("select * from " . Yii::app()->params['tablePrefix'] . "file_star where user_id=" . $user_id . " and file_id=" . $file_id);
     return $data;
 }
Example #17
0
 public function creatUserFile($fileDetail)
 {
     $file = new UserFile();
     $file["user_id"] = $fileDetail->user_id;
     $file["file_type"] = $fileDetail->file_type;
     $file["parent_file_id"] = $fileDetail->parent_file_id;
     $file["file_create_time"] = $fileDetail->file_create_time;
     $file["file_update_time"] = $fileDetail->file_update_time;
     $file["file_name"] = $fileDetail->file_name;
     $file["version_id"] = $fileDetail->version_id;
     $file["file_size"] = $fileDetail->file_size;
     $file["file_path"] = $fileDetail->file_path;
     $file["event_uuid"] = $fileDetail->event_uuid;
     $file->save();
 }
Example #18
0
 /**
  * 
  * 执行文件夹删除
  * @param UserFile $file
  */
 public function delete($parenFile)
 {
     $share_filter = MSharesFilter::init();
     $share_filter->handlerCheckByFile($this->_userId, $parenFile);
     //
     // 取消共享
     //
     if ($parenFile['file_type'] == 2 && $parenFile['user_id'] != $this->_userId || $parenFile['file_type'] == 3) {
         $parenFile = UserFile::model()->findByAttributes(array('file_path' => $share_filter->slaves[$this->_userId], 'is_deleted' => 0));
         if (!$parenFile) {
             throw new ApiException("Not found");
         }
         $handler = new ShareManager();
         $handler->_userId = $share_filter->operator;
         $handler->_id = $parenFile["id"];
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             throw new ApiException("Not found");
         }
         return;
     }
     // 更新每个元素以及子元素
     $parentPath = $parenFile["file_path"];
     $handler = new UserFile();
     $files = $handler->getFilesByPath($parentPath);
     // 轮询删除
     foreach ($files as $file) {
         if ($file["is_deleted"]) {
             continue;
         }
         // 已经删除的文件不做操作
         $file["event_uuid"] = MiniUtil::getEventRandomString(46);
         if ($file["file_type"] == 0) {
             if ($file["is_deleted"]) {
                 continue;
             }
             // 已经删除的文件不做操作
             $file["is_deleted"] = 1;
             $file->save();
             // 创建版本信息
             $this->handleFileMeta($file["file_path"], $file["version_id"], $file['user_id'], $this->_userNick, $this->_deviceName, $file['file_size']);
             // 创建事件
             MiniEvent::getInstance()->createEvent($file['user_id'], $this->_deviceId, $this->_action, $file["file_path"], $file["file_path"], $file["event_uuid"]);
             $share_filter->handlerAction($this->_action, $this->_deviceId, $file["file_path"], $file["file_path"]);
             continue;
         }
         $this->delete($file);
         $file["is_deleted"] = 1;
         $file->save();
         // 创建事件
         MiniEvent::getInstance()->createEvent($file['user_id'], $this->_deviceId, $this->_action, $file["file_path"], $file["file_path"], $file["event_uuid"]);
         $share_filter->handlerAction($this->_action, $this->_deviceId, $file["file_path"], $file["file_path"]);
     }
     $parenFile["event_uuid"] = MiniUtil::getEventRandomString(46);
     $parenFile["is_deleted"] = 1;
     $parenFile->save();
     // 创建事件
     MiniEvent::getInstance()->createEvent($parenFile['user_id'], $this->_deviceId, $this->_action, $parenFile["file_path"], $parenFile["file_path"], $parenFile["event_uuid"]);
     $share_filter->handlerAction($this->_action, $this->_deviceId, $parenFile["file_path"], $parenFile["file_path"]);
     //
     // 删除共享目录
     //
     if ($share_filter->_is_shared_path && $share_filter->operator == $share_filter->master) {
         $id = $parenFile["id"];
         $handler = new ShareManager();
         $handler->_userId = $share_filter->operator;
         $handler->_id = $id;
         try {
             $handler->invoke(ShareManager::CANCEL_SHARED);
         } catch (Exception $e) {
             throw new ApiException('Internal Server Error');
         }
     }
 }
Example #19
0
 /**
  * 获取各类文件数
  */
 public function getFileCount()
 {
     $fileModel = new UserFile();
     $data = array();
     $data['file_count'] = $fileModel->count();
     $data['office_count'] = $fileModel->officeCount();
     $data['image_count'] = $fileModel->imageCount();
     $data['deleted_count'] = $fileModel->deletedCount();
     $data['folders_count'] = $fileModel->foldersCount();
     $data['audio_count'] = $fileModel->audioCount();
     $data['vedio_count'] = $fileModel->vedioCount();
     return $data;
 }
Example #20
0
 public function getUsedSpaceById($id)
 {
     $usedSpace = 0;
     $used = UserFile::model()->getUsedSpace($id);
     if (count($used) > 0) {
         $usedSpace = $used[0]["usedSpace"];
     }
     return $usedSpace;
 }
Example #21
0
 /**
  * 
  * 根据路径创建目录
  */
 public function handleCreateByPath($path)
 {
     if ($path == "/{$this->_userId}" || $path == "\\" || $path == "/{$this->_userId}/") {
         return 0;
     }
     $event_uuid = MiniUtil::getEventRandomString(46);
     $file = UserFile::model()->find(array('condition' => 'file_path=:file_path', 'params' => array(':file_path' => $path)));
     if (empty($file) || is_null($file)) {
         $pathInfo = CUtils::pathinfo_utf($path);
         $parenPath = $pathInfo["dirname"];
         $fileName = $pathInfo["basename"];
         $parentId = $this->handleCreateByPath($parenPath);
         $file = new UserFile();
         $file['user_id'] = $this->_userId;
         $file['file_type'] = 1;
         $file['parent_file_id'] = $parentId;
         $file['file_create_time'] = time();
         $file['file_update_time'] = time();
         $file['file_name'] = $fileName;
         $file['file_path'] = $path;
         $file['is_deleted'] = 0;
         $file['version_id'] = 0;
         $file['file_size'] = 0;
         $file["event_uuid"] = $event_uuid;
         $file->save();
         $file['sort'] = $file['id'];
         $file->save();
         // 创建事件
         MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $path, $path, $event_uuid, $this->share_filter->type);
         $this->share_filter->handlerAction($this->_action, $this->_deviceId, $path, $path);
     } else {
         //
         // 回收站插件: -1保留值 0正常 1删除
         // 这里由is_deleted==1 特别修改为 is_deleted!=0
         // By Kindac 2012/11/5
         //
         if ($file["is_deleted"] != 0) {
             $file["is_deleted"] = 0;
             $file["file_update_time"] = time();
             $file["event_uuid"] = $event_uuid;
             //
             // 递归创建父目录
             //
             $pathInfo = CUtils::pathinfo_utf($path);
             $parenPath = $pathInfo["dirname"];
             $this->handleCreateByPath($parenPath);
             $file->save();
             MiniEvent::getInstance()->createEvent($this->_userId, $this->_deviceId, $this->_action, $path, $path, $event_uuid, $this->share_filter->type);
             $this->share_filter->handlerAction($this->_action, $this->_deviceId, $path, $path);
         }
     }
     return $file["id"];
 }
Example #22
0
 /**
  * web返回值处理
  */
 public function buildWebResponse()
 {
     if (!isset($this->success) || $this->success != true) {
         throw new MFilesException(Yii::t('api', MConst::INTERNAL_SERVER_ERROR), MConst::HTTP_CODE_500);
     }
     // 查询数据库,找出对应id
     $fileDetail = UserFile::model()->find(array('condition' => 'file_path=:file_path', 'params' => array(':file_path' => "/" . $this->user_id . $this->path)));
     if (empty($fileDetail)) {
         throw new MFileopsException(Yii::t('api', 'Can not find the folder.'), MConst::HTTP_CODE_404);
     }
     $pathInfo = MUtils::pathinfo_utf($this->share_filter->src_path);
     $user = MiniUser2::getInstance()->getUser2($this->user_id);
     $total = $user["space"];
     $usedSpace = $user["usedSpace"];
     $uploadSizeRemain = $total - $usedSpace;
     $cid = isset($_REQUEST['cid']) ? $_REQUEST['cid'] : 0;
     $data = array();
     $data["rev"] = $this->version_id;
     $data["is_user"] = 1;
     $data["user_id"] = $this->user_id;
     $data["group_id"] = 0;
     $data["aid"] = 0;
     $data["user_ip"] = "0.0.0.0";
     $data["upload_type"] = 1;
     //
     // dataserver 修改需要的返回值 文件path
     // by Kindac
     // since 2013/06/25
     //
     $data["temp_file_path"] = $this->file_path;
     $data["temp_file_name"] = $this->file_name;
     $data["temp_file_sha1"] = $this->file_hash;
     $data["is_share"] = 0;
     $data["file_ext"] = $pathInfo["extension"];
     $data["file_name_sort"] = strlen($this->file_name);
     $data["file_size"] = $this->size;
     $data["file_description"] = "";
     $data["pick_time"] = "";
     $data["is_collect"] = 0;
     $data["file_status"] = 1;
     $data["file_ptime"] = time();
     $data["file_id"] = $fileDetail->id;
     $data["ico"] = $pathInfo["extension"];
     $data["area_id"] = $cid;
     $data["category_id"] = $cid;
     $data["upload_size_remain"] = $uploadSizeRemain;
     $ret = array();
     $ret["state"] = true;
     $ret["data"] = $data;
     echo json_encode($ret);
 }