예제 #1
0
 /**
  * 控制器执行主逻辑函数
  *
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $user_id = $user["user_id"];
     $user_name = $user["user_name"];
     $device_uuid = $device["user_device_uuid"];
     $device_name = $device["user_device_name"];
     $db_user_device = MiniUserDevice::getInstance()->getByUuid($device_uuid);
     if ($db_user_device === NULL) {
         throw new MFileopsException(Yii::t('api', 'the device does not match'), MConst::HTTP_CODE_403);
     }
     $id = $db_user_device["id"];
     $ret = MiniUserDevice::getInstance()->deleteDevice($db_user_device["id"]);
     if ($ret === false) {
         throw new MFileopsException(Yii::t('api', 'remove the device failure'), MConst::HTTP_CODE_403);
     }
     $response = array();
     $response["stataus"] = "ok";
     $response["did"] = $device_uuid;
     $response["display_name"] = $device_name;
     $response["uid"] = $user_id;
     $response["user_name"] = $user_name;
     echo json_encode($response);
 }
예제 #2
0
 /**
  * 静态方法, 单例统一访问入口
  * @return object  返回对象的唯一实例
  */
 public static function getInstance()
 {
     if (is_null(self::$_instance) || !isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
예제 #3
0
 /**
  * @param $filePath
  * @return mixed
  */
 public function create($filePath)
 {
     $fileMeta = MiniFileMeta::getInstance()->getFileMeta($filePath, 'lock');
     $device = MUserManager::getInstance()->getCurrentDevice();
     $metaValues = array();
     $userId = $this->user['id'];
     if (count($fileMeta) != 0) {
         $values = unserialize($fileMeta['meta_value']);
         //判断有没有重复的数据,如果有重复数据,不添加
         $isDouble = false;
         foreach ($values as $value) {
             if ($value['user_id'] == $userId) {
                 $value['open_time'] = date('Y-m-d H:i:s');
                 $isDouble = true;
             }
             $metaValues[] = $value;
         }
         if (!$isDouble) {
             $metaValues[] = array('user_id' => $userId, 'device_name' => $device['user_device_name'], 'open_time' => date('Y-m-d H:i:s'));
         }
     } else {
         $metaValues[] = array('user_id' => $userId, 'device_name' => $device['user_device_name'], 'open_time' => date('Y-m-d H:i:s'));
     }
     return MiniFileMeta::getInstance()->createFileMeta($filePath, 'lock', serialize($metaValues));
 }
예제 #4
0
 public function recover($path)
 {
     $sessionUser = $this->user;
     $device = MUserManager::getInstance()->getCurrentDevice();
     $userId = $sessionUser["id"];
     $filePath = "/" . $userId;
     $arrPath = explode("/", $path);
     return MiniFile::getInstance()->recoverDelete($path, $userId, $device);
 }
예제 #5
0
 /**
  * 初始化需要的参数
  */
 public static function initMFilesCommon()
 {
     // 参数默认值
     $overwrite = true;
     // 是否覆盖,true-覆盖,false-不覆盖,默认值true
     $locale = "bytes";
     // 返回metadata时,size单位转换,默认值为 bytes
     // 文件的版本。如果$parent_rev为文件最新版本,则覆盖,否则生成冲突文件。
     // e.g "test.txt"重命名为"test (conflicted copy).txt",
     // 如果$parent_rev对应的版本不存在,则不会保存,返回400错误
     $parentRev = 0;
     if (isset($_REQUEST["locale"])) {
         $locale = $_REQUEST["locale"];
     }
     if (isset($_REQUEST["overwrite"])) {
         $overwrite = $_REQUEST["overwrite"];
         if (is_string($overwrite) === true) {
             if (strtolower($overwrite) === "false") {
                 $overwrite = false;
             } elseif (strtolower($overwrite) === "true") {
                 $overwrite = true;
             }
         }
     }
     if (isset($_REQUEST["parent_rev"])) {
         $parentRev = $_REQUEST["parent_rev"];
     }
     // 新加参数文件属性"创建时间"和"修改时间"
     $createTime = isset($_REQUEST["create_time"]) ? (int) $_REQUEST["create_time"] : time();
     $updateTime = isset($_REQUEST["update_time"]) ? (int) $_REQUEST["update_time"] : time();
     // 如果时间小于2000-01-01 00:00:00 (946681200),则使用当前时间
     if ($createTime < 946681200) {
         $createTime = time();
     }
     if ($updateTime < 946681200) {
         $createTime = time();
     }
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $fileCommon = new MFilesCommon();
     $fileCommon->overwrite = $overwrite;
     $fileCommon->locale = $locale;
     $fileCommon->parent_rev = $parentRev;
     $fileCommon->user_id = $user["user_id"];
     $fileCommon->user_nick = $user["user_name"];
     $fileCommon->user_device_id = $device["device_id"];
     $fileCommon->user_device_name = $device["user_device_name"];
     $fileCommon->action = MConst::CREATE_FILE;
     $fileCommon->file_update_time = $updateTime;
     $fileCommon->file_create_time = $createTime;
     $fileCommon->conflict = false;
     // 生成冲突文件标志
     $fileCommon->space = $user["space"];
     $fileCommon->used_space = $user["usedSpace"];
     $fileCommon->create_event = true;
     return $fileCommon;
 }
예제 #6
0
 /**
  * 初始化参数对象
  * 解析外部参数
  * @param string $uri
  * @param array $config
  * @throws Exception
  * @throws MException
  * @return mix
  */
 public static function initMThumbnailBase($uri, $config = NULL)
 {
     $thumbnailBase = new MThumbnailBase();
     $format = "jpeg";
     $size = "small";
     if (isset($_REQUEST["format"])) {
         $format = strtolower($_REQUEST["format"]);
     }
     // 默认值format
     if ($format != "jpeg" && $format != "png") {
         $format = "jpeg";
     }
     // 默认值size
     if (isset($_REQUEST["size"])) {
         $size = $_REQUEST["size"];
     }
     $signature = $_REQUEST["signature"];
     // 解析文件路径,若返回false,则错误处理
     $urlManager = new MUrlManager();
     $path = $urlManager->parsePathFromUrl($uri);
     if ($path == false) {
         throw new MException(Yii::t('api', MConst::PATH_ERROR), MConst::HTTP_CODE_404);
     }
     $parts = array_slice(explode('/', $uri), 3);
     $root = $parts[0];
     // 检索的根路径
     // 解析路径
     $path = "/" . $path;
     $path = MUtils::convertStandardPath($path);
     // 用户信息
     $user = MUserManager::getInstance()->getCurrentUser();
     if (!empty($_REQUEST["userId"]) && $_REQUEST["userId"] != 'undefined' && $user['user_name'] == 'admin') {
         $userId = $_REQUEST["userId"];
         $user = MiniUser::getInstance()->getUser($userId);
     }
     if (dirname($path) == "/") {
         $path = "/" . $user['id'] . $path;
     }
     $device = MUserManager::getInstance()->getCurrentDevice();
     $thumbnailBase->user_id = $user["user_id"];
     $thumbnailBase->user_nick = $user["user_name"];
     $thumbnailBase->user_device_id = $device["device_id"];
     $thumbnailBase->size = $size;
     $thumbnailBase->format = $format;
     $thumbnailBase->path = MUtils::convertStandardPath($path);
     $thumbnailBase->root = $root;
     $thumbnailBase->config = $config;
     // 检查共享
     $share_filter = MSharesFilter::init();
     if ($share_filter->handlerCheck($thumbnailBase->user_id, $path, true)) {
         $thumbnailBase->user_id = $share_filter->master;
         $thumbnailBase->path = $share_filter->_path;
     }
     return $thumbnailBase;
 }
예제 #7
0
 /**
  *
  * 空间检查
  */
 private function spaceFilter($size)
 {
     $user = MUserManager::getInstance()->getCurrentUser();
     $space = $user["space"];
     $used_space = $user["usedSpace"];
     //
     // 空间检查
     //
     $used_space += $size;
     if ($used_space > $space) {
         throw new MFilesException(Yii::t('api', "User is over storage quota."), MConst::HTTP_CODE_507);
     }
 }
예제 #8
0
 public function invoke()
 {
     $filter = new MUserFilter();
     $filter->oauth2Judge();
     //check user auth
     $user = MUserManager::getInstance()->getCurrentUser();
     $userId = $user["id"];
     $user = MiniUser::getInstance()->getUser($userId);
     if ($user["is_admin"] !== true) {
         throw new MiniException(1200);
     }
     parent::invoke();
 }
예제 #9
0
 /**
  * (non-PHPdoc)
  * @see MCopyController::beforeInvoke()
  */
 protected function beforeInvoke()
 {
     $this->obtain_user();
     //
     // 获取用户数据,如user_id
     //
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $this->owner = $user["user_id"];
     $this->master = $this->owner;
     $this->user_nick = $user["user_name"];
     $this->_user_device_id = $device["device_id"];
     $this->_user_device_name = $device["user_device_name"];
 }
 /**
  * 判断文件夹内是否有父目录被共享
  */
 public function isParentShared($path)
 {
     $arr = explode('/', $path);
     $parentPath = "/" . $arr[1];
     for ($i = 2; $i < count($arr); $i++) {
         $parentPath = $parentPath . "/" . $arr[$i];
         $file = MiniFile::getInstance()->getByFilePath($parentPath);
         if ($file['file_type'] == 2 || $file['file_type'] == 4) {
             $user = MUserManager::getInstance()->getCurrentUser();
             $userId = $user['user_id'];
             $this->permission = $this->getPermission($userId, $file['file_path']);
             $this->shareRootPath = $file['file_path'];
             return true;
         }
     }
     return false;
 }
예제 #11
0
 /**
  * 控制器执行主逻辑函数
  * @param $uri 地址
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $data = array();
     $data['user_name'] = $user["user_name"];
     $data['display_name'] = $user["nick"];
     $data['id'] = $user["id"];
     $data['uid'] = $user["user_uuid"];
     $data['space'] = (double) $user["space"];
     $data['used_space'] = (double) $user["usedSpace"];
     $data['email'] = $user["email"];
     $data['phone'] = $user["phone"];
     $data['avatar'] = $user["avatar"];
     $data['mult_user'] = false;
     $data['site_id'] = MiniSiteUtils::getSiteID();
     $data["device_id"] = $device["id"];
     $value = MiniOption::getInstance()->getOptionValue('site_company');
     if (isset($value)) {
         $license['company'] = $value;
     } else {
         $license['company'] = "";
     }
     $license['licensestr'] = "";
     //免费版本
     $license['is_vip'] = false;
     // 目前针对iis服务器,使客户端禁用put协议
     if (isset($_SERVER['SERVER_SOFTWARE']) && strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'iis') !== false) {
         $data['disable_put'] = true;
     }
     // 32M
     $blockSize = 4 * 1024 * 1024;
     // 内存配置需要
     $mem_limit = CUtils::return_bytes(ini_get('memory_limit'));
     if ($mem_limit < 4 * $blockSize) {
         $blockSize = $mem_limit / 4;
     }
     $postMaxSize = CUtils::return_bytes(ini_get('post_max_size'));
     $uploadMaxFileSize = CUtils::return_bytes(ini_get('upload_max_filesize'));
     $min = $postMaxSize > $uploadMaxFileSize ? $uploadMaxFileSize : $postMaxSize;
     $data['block_size'] = $min > $blockSize ? $blockSize : $min;
     if ($data['block_size'] == $postMaxSize && $data['block_size'] == $uploadMaxFileSize) {
         $data['block_size'] = $data['block_size'] - 104858;
     }
     echo json_encode($data);
 }
예제 #12
0
 /**
  * 
  * 过滤器入口
  * @param string $uri
  */
 public function invoke($uri = null)
 {
     // 转换动作
     switch ($this->action) {
         case "files":
             if (@$_SERVER["REQUEST_METHOD"] === "GET") {
                 return;
             } else {
                 $this->action = "files_post";
             }
             break;
         case "fileops":
             $this->action = $this->handleGetAction($uri);
             if ($this->action == "delete") {
                 return;
             }
             break;
         case "files_sec":
         case "restore":
         case "files_put":
             break;
         default:
             // 默认不进行空间检查
             return;
     }
     // 获取用户信息
     $user = MUserManager::getInstance()->getCurrentUser();
     $user_id = $user["user_id"];
     $space = $user["space"];
     $usedSpace = $user["usedSpace"];
     // 预测空间是否超出限制,新接口中size作为文件大小参数判断
     switch ($this->action) {
         case "files_put":
         case "filse_post":
             $usedSpace += isset($_REQUEST['size']) ? $_REQUEST['size'] : 0;
             break;
         default:
             break;
     }
     // 空间检查
     if ($usedSpace >= $space) {
         throw new MFileopsException(Yii::t('api', "User is over storage quota."), MConst::HTTP_CODE_507);
     }
 }
예제 #13
0
 /**
  * 控制器执行主逻辑函数
  * @param null $uri
  * @throws MException
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     // 解析控制器中对应操作名称
     $urlManager = new MUrlManager();
     $urlArray = $urlManager->parseActionFromUrl();
     if ($urlArray === false) {
         throw new MException(Yii::t('api', '{class} do not call an action', array('{class}' => get_class($this))));
     }
     $action = $urlArray["action"];
     $this->commonUri = $urlArray["uri"];
     self::$namespace = "api.{$action}";
     // 进行程序执行之前首先进行oauth用户身份信息验证
     // 排除指定動作可以匿名訪問
     $canAnonymous = false;
     if ($action == "info" || $action == "report") {
         $canAnonymous = true;
     }
     if ($action == "link") {
         $parts = explode("/", $this->commonUri);
         $subAction = $parts[2];
         if ($subAction == "selected") {
             $canAnonymous = true;
         }
     }
     if ($canAnonymous) {
         header('Access-Control-Allow-Origin: *');
         header('Access-Control-Allow-Methods: POST');
     }
     if (!$canAnonymous) {
         $filter = new MUserFilter();
         $filter->invoke($this->commonUri);
         // 过滤器,检查空间剩余
         $spaceFilter = new MActionFilter();
         $spaceFilter->action = $action;
         $spaceFilter->invoke($this->commonUri);
         // 修改在线用户状态
         $this->user = MUserManager::getInstance()->getCurrentUser();
         $this->device = MUserManager::getInstance()->getCurrentDevice();
         //更新设备在线状态
         MiniOnlineDevice::getInstance()->setOnlineDeviceValue($this->user["id"], $this->user["appId"], $this->device["id"]);
     }
     $this->{$action}();
 }
예제 #14
0
 /**
  *
  * oauth2.0的验证
  */
 public function oauth2Judge()
 {
     $oauth = new PDOOAuth2();
     $token = $oauth->verifyAccessToken();
     if ($token) {
         $user = MUserManager::getInstance()->getUserOauth2($token["device_id"]);
         //获取用户的信息
         if ($user === NULL) {
             $oauth->errorWWWAuthenticateResponseHeader(OAUTH2_HTTP_DISABLED, NULL, OAUTH2_HTTP_DISABLED, 'This user has been disabled.', NULL, NULL);
             return false;
         }
         $user["appId"] = $token["appId"];
         //修改了User的appId值
         MUserManager::getInstance()->setCurrentUser($user);
         if (!$user["user_status"]) {
             $oauth->errorWWWAuthenticateResponseHeader(OAUTH2_HTTP_DISABLED, NULL, SYSTEM_ERROR_USER_DISABLED, 'This user has been disabled.', NULL, NULL);
         }
     }
 }
예제 #15
0
 /**
  * oauth2.0的验证
  */
 private function oauth2()
 {
     $oauth = new PDOOAuth2();
     $token = $oauth->verifyAccessToken();
     if ($token) {
         $user = MUserManager::getInstance()->getUserOauth2($token["device_id"]);
         // 获取用户的信息
         if ($user === NULL) {
             $oauth->errorWWWAuthenticateResponseHeader(OAUTH2_HTTP_FORBIDDEN, NULL, SYSTEM_ERROR_USER_DISABLED, 'This user has been disabled.', NULL, NULL);
             return false;
         }
         $user["appId"] = $token["appId"];
         MUserManager::getInstance()->setCurrentUser($user);
         if (!$user["user_status"]) {
             $oauth->errorWWWAuthenticateResponseHeader(OAUTH2_HTTP_FORBIDDEN, NULL, SYSTEM_ERROR_USER_DISABLED, 'This user has been disabled.', NULL, NULL);
         }
     } else {
         throw new CException("Unauthorized", 401);
     }
     return true;
 }
예제 #16
0
 /**
  * 获得当前用户
  * @return array|null
  */
 public function getUser()
 {
     if (isset($this->user)) {
         return $this->user;
     }
     $user = MUserManager::getInstance()->getCurrentUser();
     if (!empty($user)) {
         $user = MiniUser::getInstance()->getUser($user["id"]);
         $data = array();
         $data['user_uuid'] = $user["user_uuid"];
         $data['user_name'] = $user["user_name"];
         $data['display_name'] = $user["nick"];
         $data['space'] = (double) $user["space"];
         $data['used_space'] = (double) $user["usedSpace"];
         $data['email'] = $user["email"];
         $data['phone'] = $user["phone"];
         $data['avatar'] = $user["avatar"];
         $data['is_admin'] = $user["is_admin"];
         $data['code'] = MiniOption::getInstance()->getOptionValue("code");
         $this->user = $data;
         return $data;
     }
     return NULL;
 }
예제 #17
0
 /**
  * 控制器执行主逻辑函数
  */
 public function invoke($uri = null)
 {
     $this->setAction(MConst::CREATE_FILE);
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $urlManager = new MUrlManager();
     $root = $urlManager->parseRootFromUrl($uri);
     if ($root == false) {
         //支持参数模式传递上传路径
         $path = MiniHttp::getParam("path", "");
         if (empty($path)) {
             throw new MFilesException(Yii::t('api', MConst::PATH_ERROR), MConst::HTTP_CODE_411);
         }
     }
     // 初始化创建文件公共类句柄
     $createFileHandler = MFilesCommon::initMFilesCommon();
     if (count($_FILES) == 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "5"), MConst::HTTP_CODE_400);
     }
     $keys = array_keys($_FILES);
     if (count($keys) != 1) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "6"), MConst::HTTP_CODE_400);
     }
     $key = $keys[0];
     // 检查请求参数$_FILES
     if (isset($_FILES[$key]) === false) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "7"), MConst::HTTP_CODE_400);
     }
     // 检查文件上传过程是否有错
     if ($_FILES[$key]["error"] != 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "8"), MConst::HTTP_CODE_400);
     }
     $fileName = $_FILES[$key]["name"];
     $type = MiniUtil::getMimeType($fileName);
     $size = $_FILES[$key]["size"];
     $tmpName = $_FILES[$key]["tmp_name"];
     // 验证文件是否已经上传成功
     if (file_exists($tmpName) === false) {
         throw new MFilesException(Yii::t('api', MConst::INTERNAL_SERVER_ERROR), MConst::HTTP_CODE_500);
     }
     // 检查文件上传错误
     if (filesize($tmpName) != $size) {
         throw new MFilesException(Yii::t('api', "The file upload error!"), MConst::HTTP_CODE_400);
     }
     //断点文件上传
     if ($this->isBreakpointUpload()) {
         $filesController = new MFilePutController();
         $filesController->invoke($uri);
     } else {
         //完整文件上传
         $signature = MiniUtil::getFileHash($tmpName);
         // 解析路径
         $path = MiniHttp::getParam("path", "");
         $path = MiniUtil::specialWordReplace($path);
         $parentPath = dirname($path);
         $user = MUserManager::getInstance()->getCurrentUser();
         $parentFile = MiniFile::getInstance()->getByPath($parentPath);
         //如果目录存在,且该目录is_delete=1,则把目录状态删除状态修改为0
         if (!empty($parentFile) && $parentFile['is_deleted'] == 1) {
             $values = array();
             $values['is_deleted'] = false;
             MiniFile::getInstance()->updateByPath($parentPath, $values);
         } else {
             //如果是根目录,则不用新建目录
             //否则会创建文件名名称的文件夹出来,而且目标文件位于该文件夹的下面
             if (!MiniUtil::isRootPath($parentPath, $user["id"])) {
                 MiniFile::getInstance()->createFolder($parentPath, $user['id']);
             }
         }
         $createFileHandler->size = $size;
         $createFileHandler->parent_path = MUtils::convertStandardPath($parentPath);
         $createFileHandler->file_name = MiniUtil::specialWordReplace($fileName);
         $createFileHandler->root = $root;
         $createFileHandler->path = MUtils::convertStandardPath($path);
         $createFileHandler->type = $type;
         // 文件不存在,保存文件
         $createFileHandler->saveFile($tmpName, $signature, $size);
         // 保存文件meta
         $createFileHandler->saveFileMeta();
         // 处理不同端,不同返回值
         if (MUserManager::getInstance()->isWeb() === true) {
             $createFileHandler->buildWebResponse();
             return;
         }
         $createFileHandler->buildResult();
     }
 }
예제 #18
0
 /**
  * 控制器执行主逻辑函数
  *
  * @return mixed $value 返回最终需要执行完的结果
  */
 public function invoke($uri = null)
 {
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $params = $_REQUEST;
     // 检查参数
     if (isset($params) === false || $params == null) {
         throw new Exception(Yii::t('api', 'Invalid parameters'));
     }
     // 文件大小格式化参数
     $locale = "bytes";
     if (isset($params["locale"])) {
         $locale = $params["locale"];
     }
     $url = $uri;
     $url_manager = new MUrlManager();
     $this->_root = $url_manager->parseRootFromUrl($uri);
     $path = $url_manager->parsePathFromUrl($uri);
     $path = MUtils::convertStandardPath($path);
     $originalPath = $path;
     // 检查共享
     $share_filter = MSharesFilter::init();
     //        $share_filter
     //
     // 获取用户数据,如user_id
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $this->_user_id = $user["user_id"];
     $user_nick = $user["user_name"];
     $user_device_id = $device["device_id"];
     $this->_user_device_name = $device["user_device_name"];
     $rev = $params["rev"];
     $rev = intval($rev);
     $path = "/{$this->_user_id}{$path}";
     //
     // 该文件是否具有此版本
     //
     $file_meta = MFileMetas::queryFileMeta($path, MConst::VERSION);
     if ($file_meta == false || empty($file_meta)) {
         throw new MFileopsException(Yii::t('api', '    Unable to find the revision at that path'), MConst::HTTP_CODE_404);
     }
     if (MUtils::isExistReversion($rev, $file_meta[0]["meta_value"]) == false) {
         throw new MFileopsException(Yii::t('api', '    Unable to find the revision at that path'), MConst::HTTP_CODE_404);
     }
     //
     // 查询版本信息
     //
     $version = MiniVersion::getInstance()->getVersion($rev);
     if ($version == null) {
         throw new MFileopsException(Yii::t('api', '    Unable to find the revision at that path'), MConst::HTTP_CODE_404);
     }
     $size = $version["file_size"];
     $file_hash = $version["file_signature"];
     //
     // 查询文件信息
     //
     $query_db_file = MFiles::queryFilesByPath($path);
     if ($query_db_file === false || empty($query_db_file)) {
         throw new MFileopsException(Yii::t('api', 'not existed'), MConst::HTTP_CODE_404);
     }
     if ($query_db_file[0]["file_type"] == MConst::OBJECT_TYPE_DIRECTORY) {
         // 文件夹不需要版本
         throw new MFileopsException(Yii::t('api', 'folder not existed version'), MConst::HTTP_CODE_403);
     }
     if ($rev !== $query_db_file[0]["version_id"]) {
         //
         // 更新文件版本
         //
         $updates = array();
         $updates["version_id"] = $rev;
         $updates["file_update_time"] = time();
         $updates["file_size"] = $size;
         $updates["event_uuid"] = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
         $ret = MFiles::updateFileDetailById($query_db_file[0]["id"], $updates);
         if ($ret === false) {
             throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
         }
         $file_detail = new MFiles();
         $file_detail->file_name = $query_db_file[0]["file_name"];
         //
         // 保存事件
         //
         $context = array("hash" => $file_hash, "rev" => (int) $rev, "bytes" => (int) $size);
         //
         // 增加修改事件
         //
         $ret = MiniEvent::getInstance()->createEvent($this->_user_id, $user_device_id, MConst::MODIFY_FILE, $path, serialize($context), $updates["event_uuid"]);
         if ($ret === false) {
             throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
         }
         $this->handleFileMeta($path, $rev, $user_nick, $this->_user_device_name, $query_db_file[0]["file_size"]);
     }
     // TODO
     $mime_type = $version["mime_type"];
     $response = array();
     $response["size"] = MUtils::getSizeByLocale($locale, $size);
     $response["is_deleted"] = true;
     $response["bytes"] = intval($size);
     $response["thumb_exists"] = MUtils::isExistThumbnail($mime_type, $size);
     $response["path"] = $originalPath;
     $response["root"] = $this->_root;
     $response["is_dir"] = false;
     $response["mime_type"] = $mime_type;
     $response["modified"] = MUtils::formatIntTime(time());
     $response["rev"] = strval($rev);
     $response["revision"] = $rev;
     echo json_encode($response);
 }
예제 #19
0
 /**
  * 处理返回值
  */
 public function buildResult($query_db_file, $to_path = null)
 {
     // 处理不同端,不同返回值
     if (MUserManager::getInstance()->isWeb() === true) {
         $this->buildWebResponse();
         return;
     }
     if ($this->isEcho === false) {
         return;
     }
     $is_dir = true;
     $size = $query_db_file["file_size"];
     $response = array();
     if ($query_db_file["file_type"] == MConst::OBJECT_TYPE_FILE) {
         // 根据文件名后缀判断mime type
         $mime_type = MiniUtil::getMimeType($query_db_file["file_name"]);
         $is_dir = false;
         $response["mime_type"] = $mime_type;
         $response["thumb_exists"] = MUtils::isExistThumbnail($mime_type, (int) $query_db_file["file_size"]);
     }
     // 去除/{user_id}
     $path = CUtils::removeUserFromPath($query_db_file["file_path"]);
     $response["size"] = MUtils::getSizeByLocale($this->_locale, $size);
     $response["is_deleted"] = false;
     $response["bytes"] = intval($size);
     $response["modified"] = MUtils::formatIntTime($query_db_file["file_update_time"]);
     if ($to_path) {
         $path = $to_path;
     } else {
         $path = $query_db_file["file_path"];
     }
     $path_info = MUtils::pathinfo_utf($path);
     $path_info_out = MUtils::pathinfo_utf($this->to_share_filter->src_path);
     $path = MUtils::convertStandardPath($path_info_out['dirname'] . "/" . $path_info['basename']);
     $response["path"] = $path;
     $response["root"] = $this->_root;
     $response["is_dir"] = $is_dir;
     $response["rev"] = strval($query_db_file["version_id"]);
     $response["revision"] = intval($query_db_file["version_id"]);
     // 增加操作返回事件编码
     $response["event_uuid"] = $query_db_file["event_uuid"];
     echo json_encode($response);
 }
예제 #20
0
 public function MiniShare()
 {
     $this->user = MUserManager::getInstance()->getCurrentUser();
     $this->device = MUserManager::getInstance()->getCurrentDevice();
 }
예제 #21
0
 /**
  * 搜索公共目录,共享目录
  */
 public function handleSearchRoot($path, $query)
 {
     $user = MUserManager::getInstance()->getCurrentUser();
     $sharedpaths = array();
     $publicFiles = MiniFile::getInstance()->getPublics();
     $groupShareFiles = MiniGroupPrivilege::getInstance()->getAllGroups();
     $userShareFiles = MiniUserPrivilege::getInstance()->getAllUserPrivilege($user["id"]);
     $shareFiles = array_merge($publicFiles, $groupShareFiles, $userShareFiles);
     foreach ($shareFiles as $shareFile) {
         $sharedpaths[] = $shareFile['file_path'];
     }
     $sharedpaths = array_unique($sharedpaths);
     //
     // 搜索共享目录,根目录查询
     //
     if ($path != '/' . $this->_user_id) {
         return array();
     }
     $query = str_replace("%", "\\%", $query);
     //        $sql = ' file_name like "%' . $query . '%"';
     $sql = '';
     $retval = array();
     foreach ($sharedpaths as $sharedpath) {
         $condition = $sql . 'parent_file_id=0 and file_path="' . $sharedpath . '" ';
         $files = MFiles::findAll($condition);
         if (empty($files)) {
             continue;
         }
         $retval = array_merge($retval, $files);
     }
     return $retval;
 }
예제 #22
0
 /**
  * 处理返回值组装
  * @param string $root
  * @param string $path
  * @param integer $version_id
  * @param string $modified
  * @param boolean $is_dir
  */
 public function buildResult($root, $path, $version_id, $modified, $is_dir)
 {
     // 处理不同端,不同返回值
     if (MUserManager::getInstance()->isWeb() === true) {
         $this->buildWebResponse();
         return;
     }
     $response = array();
     $response["size"] = "0";
     $response["is_deleted"] = true;
     $response["bytes"] = 0;
     $response["thumb_exists"] = false;
     $response["path"] = $path;
     $response["root"] = $root;
     $response["is_dir"] = $is_dir;
     $response["rev"] = strval($version_id);
     $response["revision"] = intval($version_id);
     $response["modified"] = MUtils::formatIntTime($modified);
     if ($is_dir === false) {
         $response["mime_type"] = "text/plain";
     }
     if (!$this->isOutput) {
         return $response;
     }
     echo json_encode($response);
 }
예제 #23
0
 /**
  * 取消共享,删除权限
  */
 public function delete($filePath)
 {
     $arr = explode('/', $filePath);
     $isRoot = false;
     $isMine = false;
     if (count($arr) == 3) {
         $isRoot = true;
     }
     $fileOwnerId = $arr[1];
     $currentUser = $this->user;
     $currentUserId = $currentUser['user_id'];
     if ($fileOwnerId == $currentUserId) {
         $isMine = true;
     }
     if ($isRoot && !$isMine) {
         //如果是在根目录下且不是自己的目录 则后台控制不准取消共享
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_409);
     }
     $this->share_filter = MSharesFilter::init();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $userDeviceId = $device["device_id"];
     $this->share_filter->slaves = $this->getSlaveIdsByPath($filePath);
     MiniUserPrivilege::getInstance()->deleteByFilePath($filePath);
     MiniGroupPrivilege::getInstance()->deleteByFilePath($filePath);
     MiniFile::getInstance()->cancelPublic($filePath);
     $eventAction = MConst::CANCEL_SHARED;
     MiniEvent::getInstance()->createEvent($this->user['id'], $userDeviceId, $eventAction, $filePath, $filePath, MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID), $this->share_filter->type);
     $this->share_filter->is_shared = true;
     //把共享目录下的共享目录设置记录删除
     MiniFileMeta::getInstance()->deleteFileMetaByPath($filePath, "share_model");
     // 为每个共享用户创建事件
     $this->share_filter->handlerAction($eventAction, $userDeviceId, $filePath, $filePath);
     return true;
 }
예제 #24
0
 /**
  * 显示捕获的错误信息
  * 
  * @param integer $code 错误代码
  * @param string $message 消息
  * @param string $file 文件名
  * @param string $line 错误行号
  */
 public function displayError($code, $message, $file, $line)
 {
     $content = "";
     if (YII_DEBUG) {
         $content = "<h1>PHP Error [{$code}]</h1>\n";
         $content .= "<p>{$message} ({$file}:{$line})</p>\n";
         $content .= '<pre>';
         //
         // 获取trace信息,并忽略前面三个
         //
         $trace = debug_backtrace();
         if (count($trace) > 3) {
             $trace = array_slice($trace, 3);
         }
         foreach ($trace as $i => $t) {
             if (!isset($t['file'])) {
                 $t['file'] = 'unknown';
             }
             if (!isset($t['line'])) {
                 $t['line'] = 0;
             }
             if (!isset($t['function'])) {
                 $t['function'] = 'unknown';
             }
             $content .= "#{$i} {$t['file']}({$t['line']}): ";
             if (isset($t['object']) && is_object($t['object'])) {
                 $content .= get_class($t['object']) . '->';
             }
             $content .= "{$t['function']}()\n";
         }
         $content .= '</pre>';
     } else {
         $content = "<h1>PHP Error [{$code}]</h1>\n";
         $content .= "<p>{$message}</p>\n";
     }
     Yii::log($content, CLogger::LEVEL_ERROR, "miniyun.api");
     if (MUserManager::getInstance()->isWeb() === true) {
         $message = CUtils::transtalte(self::$scene, '', 500);
         header("HTTP/1.1 200 OK");
         $result = array();
         $result["state"] = false;
         $result["code"] = 0;
         $result["message"] = Yii::t('api_message', $message);
         $result["msg"] = Yii::t('api_message', $message);
         $result["msg_code"] = "0";
         $result["data"] = array("d" => false);
     } else {
         MiniUtil::sendResponse(500, $content);
     }
 }
예제 #25
0
 /**
  * 控制器执行主逻辑函数, 复制文件或者文件夹
  */
 public function invoke($uri = null)
 {
     $this->setAction(MConst::COPY);
     $this->beforeInvoke();
     $this->beforecheck();
     $user = MUserManager::getInstance()->getCurrentUser();
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $params = $_REQUEST;
     // 检查参数
     if (isset($params) === false) {
         throw new MFileopsException(Yii::t('api', 'Bad Request 11'), MConst::HTTP_CODE_400);
     }
     // 文件大小格式化参数
     $locale = "bytes";
     if (isset($params["root"]) === false || isset($params["from_path"]) === false || isset($params["to_path"]) === false) {
         throw new MFileopsException(Yii::t('api', 'Bad Request 12'), MConst::HTTP_CODE_400);
     }
     if (isset($params["locale"])) {
         $locale = $params["locale"];
     }
     $root = $params["root"];
     $this->_from_path = $params["from_path"];
     $this->_to_path = $params["to_path"];
     if ($params['is_root']) {
         $this->_to_path = '/' . $user['id'] . $this->_to_path;
     }
     //
     // 检查文件名是否有效
     //
     $isInvalid = MUtils::checkNameInvalid(MUtils::get_basename($this->_to_path));
     if ($isInvalid) {
         throw new MFileopsException(Yii::t('api', 'Bad Request 13'), MConst::HTTP_CODE_400);
     }
     //
     // 转换路径分隔符,便于以后跨平台,如:将 "\"=>"/"
     //
     $this->_from_path = MUtils::convertStandardPath($this->_from_path);
     $this->_to_path = MUtils::convertStandardPath($this->_to_path);
     if ($this->_from_path == "/" || $this->_to_path == "/" || $this->_from_path === false || $this->_to_path === false) {
         throw new MFileopsException(Yii::t('api', 'Bad Request 14'), MConst::HTTP_CODE_400);
     }
     if ($this->_to_path[strlen($this->_to_path) - 1] == "/") {
         // 目标文件无效,403 error
         throw new Exception(Yii::t('api', 'The file or folder name is invalid'), MConst::HTTP_CODE_403);
     }
     //
     // 检查共享
     //
     $from_share_filter = MSharesFilter::init();
     $this->to_share_filter = MSharesFilter::init();
     // 当从共享目录拷贝到其他目录时,源目录用户id设置为共享用户id
     //        if ($from_share_filter->handlerCheck($this->owner, $this->_from_path)) {
     //            $this->master = $from_share_filter->master;
     //            $this->_from_path = $from_share_filter->_path;
     //        }
     //
     //        // 当拷贝到共享目录的时候,目标目录的用户id设置为共享用户id
     //        if ($this->to_share_filter->handlerCheck($this->_user_id, $this->_to_path)) {
     //            $this->_user_id = $this->to_share_filter->master;
     //            $this->user_nick      = $this->to_share_filter->master_nick;
     //            $this->_to_path = $this->to_share_filter->_path;
     //        }
     //        if($this->_from_shared_path){
     //            $this->_from_path =  $this->_from_shared_path;
     //        }else{
     //            $this->_from_path = "/".$this->master.$this->_from_path;
     //        }
     //        if($this->_to_shared_path){
     //            $this->_to_path =  $this->_to_shared_path;
     //        }else{
     //            $this->_to_path   = "/".$this->_user_id.$this->_to_path;
     //        }
     //
     // 检查目标路径是否在复制目录下
     //
     if (strpos($this->_to_path, $this->_from_path . "/") === 0) {
         throw new MFileopsException(Yii::t('api', 'Can not be copied to the subdirectory'), MConst::HTTP_CODE_403);
     }
     $check = CUtils::removeUserFromPath($this->_to_path);
     if (empty($check) || $check == '/') {
         throw new MFileopsException(Yii::t('api', 'Can not be copied to the error directory'), MConst::HTTP_CODE_403);
     }
     //
     // 检查目标路径文件是否存在
     //
     $queryToPathDbFile = MFiles::queryAllFilesByPath($this->_to_path);
     $isUpdate = false;
     if ($queryToPathDbFile) {
         if ($queryToPathDbFile[0]["is_deleted"] == false) {
             // 已经存在,403 error
             throw new MFileopsException(Yii::t('api', 'There is already a item at the given destination'), MConst::HTTP_CODE_403);
         }
         $isUpdate = true;
     }
     //
     // 查询其信息
     //
     $fileName = MUtils::get_basename($this->_to_path);
     $queryFromPathDbFile = MFiles::queryFilesByPath($this->_from_path);
     $queryToPathDbFile = MFiles::queryFilesByPath(dirname($this->_to_path));
     if ($queryFromPathDbFile === false || empty($queryFromPathDbFile)) {
         throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
     }
     $fromArr = explode('/', $this->_from_path);
     $fromId = $fromArr[1];
     if ($params['root']) {
         $toArr = explode('/', $this->_to_path);
         $toId = $toArr[1];
     } else {
         $toId = $user['id'];
     }
     //权限判断
     //当属于共享目录时才进行权限控制(源路径)
     $fromFile = MiniFile::getInstance()->getByFilePath($this->_from_path);
     if ($fromId != $user['id']) {
         //判断文件重命名是否有权限操作
         $permissionArr = UserPermissionBiz::getInstance()->getPermission($this->_from_path, $user['id']);
         if (!isset($permissionArr)) {
             $permission = MConst::SUPREME_PERMISSION;
         } else {
             $permission = $permissionArr['permission'];
         }
         $miniPermission = new MiniPermission($permission);
         $canCopy = $miniPermission->canCopy($fromFile['file_type']);
         if (!$canCopy) {
             throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
         }
     }
     $isSharedPath = false;
     //主要用于判断是否为被共享文件
     //目标路径
     if ($toId != $user['id']) {
         $isSharedPath = true;
         //拷贝到 (目标路径的创建权限)  的判断
         //            if ($query_from_path_db_file[0]["file_type"] == 0){  //文件
         //                $this->to_share_filter->hasPermissionExecute($this->_to_path, MPrivilege::FILE_CREATE);
         //            } else {                                           //文件夹
         //                $this->to_share_filter->hasPermissionExecute($this->_to_path, MPrivilege::FOLDER_CREATE);
         //            }
     } else {
         $model = new GeneralFolderPermissionBiz($this->_to_path);
         if ($model->isParentShared($this->_to_path)) {
             //如果是父目录被共享
             $isSharedPath = true;
         }
     }
     if ($isSharedPath) {
         $permissionArr = UserPermissionBiz::getInstance()->getPermission(dirname($this->_to_path), $user['id']);
         if (!isset($permissionArr)) {
             $permission = MConst::SUPREME_PERMISSION;
         } else {
             $permission = $permissionArr['permission'];
             $privilegeModel = new PrivilegeBiz();
             $this->to_share_filter->slaves = $privilegeModel->getSlaveIdsByPath($permissionArr['share_root_path']);
             $this->to_share_filter->is_shared = true;
         }
         $miniPermission = new MiniPermission($permission);
         $toFile = MiniFile::getInstance()->getByFilePath(dirname($this->_to_path));
         $canCopy = $miniPermission->canCopy($toFile['file_type']);
         if (!$canCopy) {
             throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
         }
     }
     //
     // 查询目标路径父目录信息
     //
     $parentPath = dirname($this->_to_path);
     $createFolder = new MCreateFolderController();
     $createFolder->_user_device_id = $this->_user_device_id;
     $createFolder->_user_id = $this->_user_id;
     $createFolder->share_filter = $this->to_share_filter;
     $parentFileId = $createFolder->handlerParentFolder($parentPath);
     //
     // 组装对象信息
     //
     $fileDetail = new MFiles();
     $fileDetail->file_name = $fileName;
     $fileDetail->file_path = $this->_to_path;
     $this->assembleFileDetail($fileName, $parentFileId, $fileDetail, $queryFromPathDbFile[0]);
     //
     // 首先处理复制根目录操作
     //
     if ($isUpdate) {
         $fileDetail->event_uuid = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
         $updates = array();
         $updates["file_update_time"] = time();
         $updates["is_deleted"] = intval(false);
         $updates["event_uuid"] = $fileDetail->event_uuid;
         $updates["file_type"] = $fileDetail->file_type;
         $retValue = MFiles::updateFileDetailByPath($this->_to_path, $updates);
     } else {
         $retValue = MFiles::CreateFileDetail($fileDetail, $this->_user_id);
     }
     if ($retValue === false) {
         throw new MFileopsException(Yii::t('api', 'Internal Server Error'), MConst::HTTP_CODE_500);
     }
     //
     // 更新版本信息
     //
     $this->updateVerRef(array($fileDetail));
     $retValue = MiniEvent::getInstance()->createEvent($this->_user_id, $this->_user_device_id, $fileDetail->event_action, $fileDetail->file_path, $fileDetail->context, $fileDetail->event_uuid, $this->to_share_filter->type);
     if ($retValue === false) {
         throw new MFileopsException(Yii::t('api', 'There is already a item at the given destination'), MConst::HTTP_CODE_500);
     }
     $context = $fileDetail->context;
     if ($fileDetail->file_type == 0) {
         $context = unserialize($context);
     }
     $this->to_share_filter->handlerAction($fileDetail->event_action, $this->_user_device_id, $fileDetail->file_path, $context);
     //
     // 判断操作的是文件夹,还是文件
     //
     $createArray = array();
     $queryDbFile = MFiles::queryFilesByPath($this->_to_path);
     //
     // 查询其复制目录路径id
     //
     if ($queryDbFile === false || empty($queryDbFile)) {
         throw new MFileopsException(Yii::t('api', 'Not found the source files of the specified path'), MConst::HTTP_CODE_404);
     }
     if ($fileDetail->file_type != MConst::OBJECT_TYPE_FILE) {
         $fileDetail->id = $queryDbFile[0]["id"];
         $fileDetail->file_size = $queryDbFile[0]["file_size"];
         $this->handlerChildrenFile($fileDetail);
         //
         // 处理版本信息
         //
         $moveController = new MMoveController();
         $moveController->versions = array();
         $createArray = $moveController->handleChildrenVersions($createArray, $this->_user_id, $this->user_nick, $this->_from_path, $this->_to_path, $queryToPathDbFile[0]["id"], $this->_user_device_name, $queryFromPathDbFile[0]["file_size"]);
         $this->versions = $moveController->versions;
     } else {
         $fileMeta = new MFileMetas();
         $fileMeta->version_id = $queryFromPathDbFile[0]["version_id"];
         //
         // 查询其版本
         //
         $fileVersion = MFileMetas::queryFileMeta($this->_to_path, MConst::VERSION);
         $fileMeta->is_add = false;
         if ($fileVersion) {
             $metaValue = MUtils::getFileVersions($this->_user_device_name, $fileDetail->file_size, $fileMeta->version_id, MConst::CREATE_FILE, $this->_user_id, $this->user_nick, $fileVersion[0]["meta_value"]);
         } else {
             $metaValue = MUtils::getFileVersions($this->_user_device_name, $fileDetail->file_size, $fileMeta->version_id, MConst::CREATE_FILE, $this->_user_id, $this->user_nick);
             $fileMeta->is_add = true;
             // 不存在记录,需要添加
         }
         $fileMeta->meta_value = $metaValue;
         $fileMeta->file_path = $this->_to_path;
         $createArray[$queryFromPathDbFile[0]["file_path"]] = $fileMeta;
         //
         // 添加到需要更新的版本ref
         //
         array_push($this->versions, $fileMeta->version_id);
     }
     //
     // 创建版本信息
     //
     MFileMetas::batchCreateFileMetas($createArray, MConst::VERSION);
     //        if ($ret === false)
     //        {
     //            throw new MFileopsException(
     //                                        Yii::t('api','Internal Server Error'),
     //                                        MConst::HTTP_CODE_500);
     //        }
     //
     // 更新版本
     //
     foreach ($createArray as $key => $fileMeta) {
         if ($fileMeta->is_add === true) {
             // 不存在记录,不需要更新
             continue;
         }
         MFileMetas::updateFileMeta($fileMeta->file_path, MConst::VERSION, $fileMeta->meta_value);
     }
     //
     // 处理不同端,不同返回值
     //
     if (MUserManager::getInstance()->isWeb() === true) {
         $this->buildWebResponse();
         return;
     }
     $response = array();
     $isDir = true;
     if ($queryDbFile[0]["file_type"] == MConst::OBJECT_TYPE_FILE) {
         // TODO
         $mimeType = "text/plain";
         $response["mime_type"] = $mimeType;
         $isDir = false;
         $response["thumb_exists"] = MUtils::isExistThumbnail($mimeType, (int) $queryDbFile[0]["file_size"]);
     }
     $size = $queryDbFile[0]["file_size"];
     $response["size"] = MUtils::getSizeByLocale($locale, $size);
     $response["bytes"] = intval($size);
     $pathInfo = MUtils::pathinfo_utf($this->_to_path);
     $pathInfoOut = MUtils::pathinfo_utf($this->to_share_filter->src_path);
     $path = MUtils::convertStandardPath($pathInfoOut['dirname'] . "/" . $pathInfo['basename']);
     $response["path"] = $path;
     $response["root"] = $root;
     $response["is_dir"] = $isDir;
     $response["rev"] = strval($queryDbFile[0]["version_id"]);
     $response["revision"] = intval($queryDbFile[0]["version_id"]);
     $response["modified"] = MUtils::formatIntTime($queryDbFile[0]["file_update_time"]);
     //
     // 如果标记为不输出结果的话,直接返回$response
     //
     if (!$this->isOutput) {
         return $response;
     }
     echo json_encode($response);
 }
예제 #26
0
 /**
  *
  * 是否具有删除文件夹功能
  *
  * @since 1.0.7
  */
 public function hasFolderDelete()
 {
     $this->operateName = $this->getOperateName(self::FOLDER_DELETE);
     if (array_key_exists(self::FOLDER_DELETE, $this->permission)) {
         if (!$this->permission[self::RESOURCE_READ]) {
             return false;
         }
         if (!$permissions[$permission]) {
             return false;
         }
         //检查子目录是否有文件或者文件夹不能删除的权限
         $currentUser = MUserManager::getInstance()->getCurrentUser();
         $user_id = $currentUser["id"];
         if (!$this->isDeleteChildFolder($user_id, $this->file_path)) {
             return false;
         }
         return true;
     }
     return false;
 }
예제 #27
0
 /**
  * 根据cookie中的accessToken获得用户信息
  */
 private function getUserByAccessToken()
 {
     //当accessToken在session中的时候,他的优先级最高,然后cookie里面的accessToken
     //这里解决新版客户端网页加载的问题
     $accessToken = Yii::app()->session["accessToken"];
     if (empty($accessToken)) {
         //PC客户端从Post参数获得access_token
         if (MiniHttp::isPCClient()) {
             $accessToken = MiniHttp::getParam("access_token", "");
         } else {
             if (!array_key_exists("accessToken", $_COOKIE)) {
                 $accessToken = MiniHttp::getParam("access_token", "");
                 if (empty($accessToken)) {
                     return NULL;
                 }
             } else {
                 $accessToken = $_COOKIE['accessToken'];
             }
         }
     }
     if (empty($accessToken)) {
         return NULL;
     }
     $accessInfo = MiniToken2::getInstance()->getAccessInfo2($accessToken);
     if (!isset($accessInfo)) {
         return NULL;
     }
     $user = MUserManager::getInstance()->getUserOauth2($accessInfo["device_id"]);
     //获取用户的信息
     return $user;
 }
예제 #28
0
 /**
  * 获得当前用户
  * @return mixed
  */
 public function getCurrentUser()
 {
     return MUserManager::getInstance()->getCurrentUser();
 }
예제 #29
0
 /**
  * 处理创建文件信息及事件
  * @param string $folderPath
  * @param int $parentFileId
  * @param boolean $hadFileDelete
  * @param int $userId
  * @return array
  */
 private function createFileMeta($folderPath, $parentFileId, $hadFileDelete, $userId)
 {
     $fileName = MUtils::get_basename($folderPath);
     // 组装对象信息
     $fileDetail = array();
     $fileDetail["file_create_time"] = time();
     $fileDetail["file_update_time"] = time();
     $fileDetail["file_name"] = $fileName;
     $fileDetail["file_path"] = $folderPath;
     $fileDetail["file_size"] = 0;
     $fileDetail["file_type"] = MConst::OBJECT_TYPE_DIRECTORY;
     $fileDetail["parent_file_id"] = $parentFileId;
     $fileDetail["event_uuid"] = MiniUtil::getEventRandomString(MConst::LEN_EVENT_UUID);
     $fileDetail["mime_type"] = NULL;
     // 保存文件元数据
     if ($hadFileDelete) {
         $updates = array();
         $updates["file_update_time"] = time();
         $updates["is_deleted"] = intval(false);
         $updates["file_type"] = MConst::OBJECT_TYPE_DIRECTORY;
         $updates["event_uuid"] = $fileDetail["event_uuid"];
         // 存在已被删除的数据,只需更新
         $this->updateByPath($folderPath, $updates);
     } else {
         // 不存在数据,添加
         $file = $this->getByPath($folderPath);
         if (empty($file)) {
             if (!empty($fileDetail["file_name"])) {
                 $this->create($fileDetail, $userId);
                 $device = MUserManager::getInstance()->getCurrentDevice();
                 $event_action = MConst::CREATE_DIRECTORY;
                 MiniEvent::getInstance()->createEvent($userId, $device["device_id"], $event_action, $fileDetail["file_path"], $fileDetail["file_path"], $fileDetail["event_uuid"], 0);
             }
         }
     }
     return $fileDetail;
 }
예제 #30
0
 /**
  * 获取文件以前版本的mtadata
  * @param null $uri
  * @throws MException
  * @throws MFilesException
  */
 public function invoke($uri = null)
 {
     parent::init();
     // 解析url地址,获取root和path,path必须指向一个文件
     $urlManager = new MUrlManager();
     $path = $urlManager->parsePathFromUrl($uri);
     $root = $urlManager->parseRootFromUrl($uri);
     if ($path == false) {
         throw new MException(Yii::t('api', MConst::PATH_ERROR), MConst::HTTP_CODE_411);
     }
     $path = "/" . $path;
     // Default is 10. Max is 1,000.
     $revLimit = 10;
     if (isset($_REQUEST["rev_limit"]) != false) {
         $revLimit = $_REQUEST["rev_limit"];
     }
     $revLimit = $revLimit <= 1000 ? $revLimit : 1000;
     // 文件大小格式化参数
     $locale = "bytes";
     if (isset($_REQUEST["locale"])) {
         $locale = $_REQUEST["locale"];
     }
     // callback -
     // TODO 实现callback
     $callback = NULL;
     // 获取用户数据,如user_id
     $user = MUserManager::getInstance()->getCurrentUser();
     $device = MUserManager::getInstance()->getCurrentDevice();
     $userId = $user["user_id"];
     $userNick = $user["user_name"];
     $userDeviceId = $device["device_id"];
     //
     // 查询文件
     //
     $fileDetail = MFiles::queryAllFilesByPath("/" . $userId . $path);
     if ($fileDetail === false || count($fileDetail) == 0) {
         throw new MException(Yii::t('api', MConst::NOT_FOUND), MConst::HTTP_CODE_404);
     }
     // 判断文件类型,如不是文件则返回错误
     if ($fileDetail[0]["file_type"] != 0) {
         throw new MException(Yii::t('api', "Not Acceptable"), MConst::HTTP_CODE_406);
     }
     $fileMeta = MFileMetas::queryFileMeta("/" . $userId . $path, MConst::VERSION);
     if ($fileMeta == false || empty($fileMeta)) {
         throw new MFilesException(Yii::t("api", MConst::INTERNAL_SERVER_ERROR), MConst::HTTP_CODE_500);
     }
     //
     // 文件版本历史
     //
     $versions = unserialize($fileMeta[0]["meta_value"]);
     $count = 1;
     // 计数器
     //
     // 轮询
     //
     $response = array();
     foreach ($versions as $k => $v) {
         $var = array();
         $var["rev"] = strval($v["version_id"]);
         $var["revision"] = (int) $v["version_id"];
         $var["bytes"] = 0;
         $var["size"] = "0 bytes";
         $var["thumb_exists"] = false;
         $var["modified"] = MUtils::formatIntTime(microtime(true) * 10000);
         $var["mime_type"] = MConst::DEFAULT_FILE_MIME_TYPE;
         $var["path"] = $path;
         $var["is_dir"] = false;
         $var["root"] = $root;
         if ($v["type"] == MConst::DELETE) {
             $var["is_deleted"] = true;
         }
         //
         // 文件版本信息
         //
         $fileVersion = MiniVersion::getInstance()->getVersion($v["version_id"]);
         if ($fileVersion == null) {
             $var["is_deleted"] = true;
         } else {
             $var['hash'] = $fileVersion["file_signature"];
             $var["bytes"] = (int) $fileVersion["file_size"];
             $var["size"] = MUtils::getSizeByLocale($locale, $fileVersion["file_size"]);
             $var["thumb_exists"] = $this->isExistThumbnail($fileVersion["file_size"], $fileVersion["mime_type"]);
             $var["modified"] = MUtils::formatIntTime($fileVersion["updated_at"]);
             $var["mime_type"] = is_null($fileVersion["mime_type"]) ? $var["mime_type"] : $fileVersion["mime_type"];
         }
         array_push($response, $var);
         if ($count >= $revLimit) {
             break;
         }
         $count += 1;
     }
     echo json_encode($response);
 }