/** * 獲取文本文件信息! * @param $path * @param $signature * @return mixed */ public function txtContent($path, $signature) { $share = new MiniShare(); $fileBiz = new FileBiz(); $canRead = $fileBiz->privilege($path); if (!$canRead) { throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409); } $minFileMeta = $share->getMinFileMetaByPath($path); $file = array(); $content = MiniFile::getInstance()->getTxtContent($minFileMeta['ori_path'], $signature); $file['content'] = $content; $file['type'] = $minFileMeta['mime_type']; return $file; }
/** * 在线浏览文件获得内容 * @param string $path 文件当前路径 * @param string $type 文件类型,可选择pdf/png * @throws * @return NULL */ public function previewContent($path, $type) { $file = MiniFile::getInstance()->getByPath($path); // 权限处理 if (empty($file)) { return array('success' => false, 'msg' => 'file not existed'); } $fileBiz = new FileBiz(); $canRead = $fileBiz->privilege($path); if (!$canRead) { throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409); } //获得文件当前版本对应的version $version = PluginMiniDocVersion::getInstance()->getVersion($file["version_id"]); $signature = $version["file_signature"]; $localPath = PluginMiniDocOption::getInstance()->getMiniDocCachePath() . $signature . "/" . $signature . "." . $type; if (!file_exists($localPath)) { //文档还在转换中 $node = PluginMiniDocNode::getInstance()->getConvertNode($signature); if (empty($node)) { throw new MFileopsException(Yii::t('api', 'convert error'), MConst::HTTP_CODE_412); } //根据情况判断是否需要向迷你文档拉取内容 $parentPath = dirname($localPath); //如果缓存目录不存在,则需要创建 if (!file_exists($parentPath)) { MUtils::MkDirsLocal($parentPath); } //文件不存在,则需要从迷你文档拉取文件内容 $url = PluginMiniDocNode::getInstance()->getDownloadUrl($node["id"], $version, $type); $http = new HttpClient(); $http->get($url); $status = $http->get_status(); if ($status == "200") { $content = $http->get_body(); //把文件内容存储到本地硬盘 file_put_contents($localPath, $content); Yii::log($signature . " get " . $type . " success", CLogger::LEVEL_INFO, "doc.convert"); } else { if (!($version["doc_convert_status"] == -1)) { //如迷你文档服务器不存在该文档,说明迷你文档服务器发生了变动 //这个时候自动启动负载均衡机制,把文档重新转换 PluginMiniDocVersion::getInstance()->pushConvertSignature($signature, ""); Yii::log($signature . " get " . $type . " error", CLogger::LEVEL_ERROR, "doc.convert"); } } } if (file_exists($localPath)) { if ($type === "png") { $contentType = "image/png"; } if ($type === "pdf") { $contentType = "Content-type: application/pdf"; } //Firefox+混合云模式下直接输出内容 //其它浏览器使用sendfile模式输出内容 $isSendFile = true; if (MiniUtil::isMixCloudVersion()) { $ua = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : NULL; if (strpos($ua, "Firefox") > 0 || strpos($ua, "Safari") > 0) { $isSendFile = false; } } if ($isSendFile) { header('Location: ' . MiniHttp::getMiniHost() . "assets/minidoc/" . $signature . "/" . $signature . "." . $type); } else { Header("Content-type: " . $contentType); echo file_get_contents($localPath); exit; } } }
/** * 获取文件的相关信息 */ public function info() { $path = MiniHttp::getParam("path", ""); $biz = new FileBiz(); $data = $biz->info($path); return $data; }
public function getAllSharedPath($userId) { $userPrivileges = MiniUserPrivilege::getInstance()->getByUserId($userId); $filePaths = array(); foreach ($userPrivileges as $userPrivilege) { array_push($filePaths, $userPrivilege['file_path']); } $groupPrivileges = MiniGroupPrivilege::getInstance()->getAllGroups(); $publicPrivileges = MiniGroupPrivilege::getInstance()->getPublic(); foreach ($publicPrivileges as $publicPrivilege) { array_push($filePaths, $publicPrivilege['file_path']); } $groupIds = array(); foreach ($groupPrivileges as $groupPrivilege) { array_push($groupIds, $groupPrivilege['group_id']); } $groupIdsArr = array(); $userGroupRelations = MiniUserGroupRelation::getInstance()->findUserGroup($userId); if (isset($userGroupRelations)) { foreach ($userGroupRelations as $userRelation) { $groupId = $userRelation['id']; $arr = array(); array_push($arr, $groupId); $result = MiniGroup::getInstance()->findById($groupId); if ($result['user_id'] > 0) { array_push($groupIdsArr, $groupId); } else { $ids = $this->getGroupIds($groupId, $arr); } } array_splice($groupIdsArr, 0, 0, $ids); $commonGroupIds = array_merge($groupIdsArr, $groupIds); foreach ($commonGroupIds as $commonGroupId) { $groupInfos = MiniGroupPrivilege::getInstance()->getByGroupId($commonGroupId); foreach ($groupInfos as $groupInfo) { $paths[] = $groupInfo['file_path']; } } if ($paths) { array_splice($filePaths, 0, 0, $paths); } } $paths = array(); $filePaths = array_unique($filePaths); foreach ($filePaths as $filePath) { $result = MiniFile::getInstance()->getByPath($filePath); if (count($result) == 0) { continue; } //当共享文件为共享者的时候进行过滤 $arr = explode("/", $filePath); $userId = $this->user['id']; $slaveId = $arr[1]; if ($slaveId == $userId) { continue; } $fileBiz = new FileBiz(); $canRead = $fileBiz->privilege($filePath); if (!$canRead) { continue; } $paths[] = $filePath; } return $paths; }