Inheritance: extends OCA\Richdocuments\Db
Ejemplo n.º 1
0
 /**
  * Start a editing session or return an existing one
  * @param string $uid of the user starting a session
  * @param \OCA\Richdocuments\File $file - file object
  * @return array
  * @throws \Exception
  */
 public static function start($uid, $file)
 {
     // Create a directory to store genesis
     $genesis = new \OCA\Richdocuments\Genesis($file);
     $oldSession = new 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 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 = \OCA\Richdocuments\Helper::getMemberColor($uid);
     $member = new \OCA\Richdocuments\Db\Member([$sessionData['es_id'], $uid, $memberColor, time(), intval($file->isPublicShare()), $file->getToken()]);
     if (!$member->insert()) {
         throw new \Exception('Failed to add member into database');
     }
     $sessionData['member_id'] = (string) $member->getLastInsertId();
     // Do we have OC_Avatar in out disposal?
     if (\OC::$server->getConfig()->getSystemValue('enable_avatars', true) !== true) {
         $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
     } else {
         $imageUrl = $uid;
     }
     $displayName = $file->isPublicShare() ? $uid . ' ' . \OCA\Richdocuments\Db\Member::getGuestPostfix() : \OC::$server->getUserSession()->getUser()->getDisplayName($uid);
     $userId = $file->isPublicShare() ? $displayName : \OC::$server->getUserSession()->getUser()->getUID();
     $op = new \OCA\Richdocuments\Db\Op();
     $op->addMember($sessionData['es_id'], $sessionData['member_id'], $displayName, $userId, $memberColor, $imageUrl);
     $sessionData['title'] = basename($file->getPath());
     $sessionData['permissions'] = $file->getPermissions();
     return $sessionData;
 }
Ejemplo n.º 2
0
 /**
  * @NoAdminRequired
  * @PublicPage
  * @param int $memberId
  * @param string $name
  */
 public function rename($memberId, $name)
 {
     $member = new Db\Member();
     $member->load($memberId);
     if ($member->getEsId() && $member->getStatus() == Db\Member::MEMBER_STATUS_ACTIVE && $member->getIsGuest()) {
         $guestMark = Db\Member::getGuestPostfix();
         if (substr($name, -strlen($guestMark)) !== $guestMark) {
             $name = $name . ' ' . $guestMark;
         }
         $op = new Db\Op();
         $op->changeNick($member->getEsId(), $memberId, $name);
     }
     return array('status' => 'success');
 }
Ejemplo n.º 3
0
 protected function loadMember($memberId, $expectedEsId = null)
 {
     if (!$memberId) {
         throw new \Exception('Member id can not be empty');
     }
     $member = new Db\Member();
     $member->load($memberId);
     //check if member belongs to the session
     if (!is_null($expectedEsId) && $expectedEsId !== $member->getEsId()) {
         throw new \Exception($memberId . ' does not belong to session ' . $expectedEsId);
     }
     return $member;
 }
 /**
  * @NoAdminRequired
  * lists the documents the user has access to (including shared files, once the code in core has been fixed)
  * also adds session and member info for these files
  */
 public function listAll()
 {
     $found = Storage::getDocuments();
     $fileIds = array();
     $documents = array();
     foreach ($found as $key => $document) {
         if (is_object($document)) {
             $documents[] = $document->getData();
         } else {
             $documents[$key] = $document;
         }
         $documents[$key]['icon'] = preg_replace('/\\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype']));
         $documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']);
         $fileIds[] = $document['fileid'];
     }
     usort($documents, function ($a, $b) {
         return @$b['mtime'] - @$a['mtime'];
     });
     $session = new Db\Session();
     $sessions = $session->getCollectionBy('file_id', $fileIds);
     $members = array();
     $member = new Db\Member();
     foreach ($sessions as $session) {
         $members[$session['es_id']] = $member->getActiveCollection($session['es_id']);
     }
     return array('status' => 'success', 'documents' => $documents, 'sessions' => $sessions, 'members' => $members);
 }
Ejemplo n.º 5
0
 /** Prepare document(s) structure
  */
 private function prepareDocuments($rawDocuments)
 {
     $discovery_parsed = null;
     try {
         $discovery = $this->getDiscovery();
         $loadEntities = libxml_disable_entity_loader(true);
         $discovery_parsed = simplexml_load_string($discovery);
         libxml_disable_entity_loader($loadEntities);
         if ($discovery_parsed === false) {
             $this->cache->remove('discovery.xml');
             $wopiRemote = $this->appConfig->getAppValue('wopi_url');
             return array('status' => 'error', 'message' => $this->l10n->t('Collabora Online: discovery.xml from "%s" is not a well-formed XML string.', array($wopiRemote)), 'hint' => $this->l10n->t('Please contact the "%s" administrator.', array($wopiRemote)));
         }
     } catch (ResponseException $e) {
         return array('status' => 'error', 'message' => $e->getMessage(), 'hint' => $e->getHint());
     }
     $fileIds = array();
     $documents = array();
     $lolang = strtolower(str_replace('_', '-', $this->settings->getUserValue($this->uid, 'core', 'lang', 'en')));
     foreach ($rawDocuments as $key => $document) {
         if (is_object($document)) {
             $documents[] = $document->getData();
         } else {
             $documents[$key] = $document;
         }
         $documents[$key]['icon'] = preg_replace('/\\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype']));
         $documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']);
         $ret = $this->getWopiSrcUrl($discovery_parsed, $document['mimetype']);
         $documents[$key]['urlsrc'] = $ret['urlsrc'];
         $documents[$key]['action'] = $ret['action'];
         $documents[$key]['lolang'] = $lolang;
         $fileIds[] = $document['fileid'];
     }
     usort($documents, function ($a, $b) {
         return @$b['mtime'] - @$a['mtime'];
     });
     $session = new Db\Session();
     $sessions = $session->getCollectionBy('file_id', $fileIds);
     $members = array();
     $member = new Db\Member();
     foreach ($sessions as $session) {
         $members[$session['es_id']] = $member->getActiveCollection($session['es_id']);
     }
     return array('status' => 'success', 'documents' => $documents, 'sessions' => $sessions, 'members' => $members);
 }