예제 #1
0
파일: session.php 프로젝트: hjimmy/owncloud
 /**
  * Start a editing session or return an existing one
  * @param string $uid of the user starting a session
  * @param \OCA\Documents\File $file - file object
  * @return array
  * @throws \Exception
  */
 public static function start($uid, $file)
 {
     // Create a directory to store genesis
     $genesis = new Genesis($file);
     list($ownerView, $path) = $file->getOwnerViewAndPath();
     $mimetype = $ownerView->getMimeType($path);
     if (!Filter::isSupportedMimetype($mimetype)) {
         throw new \Exception($path . ' is ' . $mimetype . ' and is not supported by Documents app');
     }
     $oldSession = new Db_Session();
     $oldSession->loadBy('file_id', $file->getFileId());
     //If there is no existing session we need to start a new one
     if (!$oldSession->hasData()) {
         $newSession = new Db_Session(array($genesis->getPath(), $genesis->getHash(), $file->getOwner(), $file->getFileId()));
         if (!$newSession->insert()) {
             throw new \Exception('Failed to add session into database');
         }
     }
     $sessionData = $oldSession->loadBy('file_id', $file->getFileId())->getData();
     $memberColor = Helper::getMemberColor($uid);
     $member = new Db_Member(array($sessionData['es_id'], $uid, $memberColor, time(), intval($file->isPublicShare()), $file->getToken()));
     if ($member->insert()) {
         // Do we have OC_Avatar in out disposal?
         if (!class_exists('\\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true) {
             $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
         } else {
             $imageUrl = $uid;
         }
         $displayName = $file->isPublicShare() ? $uid . ' ' . Db_Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
         $sessionData['member_id'] = (string) $member->getLastInsertId();
         $op = new Db_Op();
         $op->addMember($sessionData['es_id'], $sessionData['member_id'], $displayName, $memberColor, $imageUrl);
     } else {
         throw new \Exception('Failed to add member into database');
     }
     $sessionData['title'] = basename($path);
     $sessionData['permissions'] = $ownerView->getFilePermissions($path);
     return $sessionData;
 }
예제 #2
0
 /**
  * @NoAdminRequired
  */
 public function download($path)
 {
     if (!$path) {
         $response = new JSONResponse();
         $response->setStatus(Http::STATUS_BAD_REQUEST);
         return $response;
     }
     $fullPath = '/files' . $path;
     $fileInfo = \OC\Files\Filesystem::getFileInfo($path);
     if ($fileInfo) {
         if ($fileInfo->getMimeType() !== \OCA\Documents\Filter\Office::NATIVE_MIMETYPE) {
             $file = new File($fileInfo->getId());
             $genesis = new Genesis($file);
             $fullPath = $genesis->getPath();
         }
     }
     return new DownloadResponse($this->request, $this->uid, $fullPath);
 }