/**
  * @return string
  */
 public function getMainLink()
 {
     if (isset($_SESSION["CURRENT_MINISITE"])) {
         $hash = $_SESSION["CURRENT_MINISITE"];
         $shareCenter = ShareCenter::getShareCenter();
         if (!empty($shareCenter)) {
             return $shareCenter->buildPublicletLink($hash);
         }
     }
     return AJXP_Utils::getWorkspaceShortcutURL($this->getNode()->getRepository()) . $this->getNode()->getPath();
 }
 /**
  * @param MetaWatchRegister|false $watcher
  * @param ShareRightsManager $rightsManager
  * @param PublicAccessManager $publicAccessManager
  * @param array $messages
  * @return array|false
  */
 public function toJson($watcher, $rightsManager, $publicAccessManager, $messages)
 {
     $repoRootNode = new AJXP_Node("pydio://" . $this->getRepositoryId() . "/");
     $elementWatch = false;
     if ($watcher != false) {
         $elementWatch = $watcher->hasWatchOnNode($repoRootNode, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
     }
     $sharedEntries = $rightsManager->computeSharedRepositoryAccessRights($this->getRepositoryId(), true, $repoRootNode);
     if (empty($sharedEntries)) {
         return false;
     }
     $cFilter = $this->getRepository()->getContentFilter();
     if (!empty($cFilter)) {
         $cFilter = $cFilter->toArray();
     }
     $jsonData = array("repositoryId" => $this->getRepositoryId(), "users_number" => AuthService::countUsersForRepository($this->getRepositoryId()), "label" => $this->getRepository()->getDisplay(), "description" => $this->getRepository()->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::getWorkspaceShortcutURL($this->getRepository()) . "/", "content_filter" => $cFilter, "share_owner" => $this->getOwner(), "share_scope" => $this->getVisibilityScope());
     $jsonData["links"] = array();
     foreach ($this->shareLinks as $shareLink) {
         $uniqueUser = $shareLink->getUniqueUser();
         $found = false;
         foreach ($sharedEntries as $entry) {
             if ($entry["ID"] == $uniqueUser) {
                 $found = true;
             }
         }
         if (!$found) {
             // STRANGE, THE ASSOCIATED USER IS MISSING
             error_log("Found shareLink orphan with uniqueUser " . $uniqueUser);
             continue;
         }
         $jsonData["links"][$shareLink->getHash()] = $shareLink->getJsonData($publicAccessManager, $messages);
     }
     return $jsonData;
 }
 /**
  * @param String $shareId
  * @param array $shareMeta
  * @param AJXP_Node $node
  * @throws Exception
  * @return array|bool
  */
 public function shareToJson($shareId, $shareMeta, $node = null)
 {
     $messages = ConfService::getMessages();
     $jsonData = array();
     $elementWatch = false;
     if ($shareMeta["type"] == "file") {
         require_once "class.LegacyPubliclet.php";
         $jsonData = LegacyPubliclet::publicletToJson($shareId, $shareMeta, $this->getShareStore(), $this->getPublicAccessManager(), $this->watcher, $node);
     } else {
         if ($shareMeta["type"] == "minisite" || $shareMeta["type"] == "repository") {
             $repoId = $shareId;
             if (strpos($repoId, "repo-") === 0) {
                 // Legacy
                 $repoId = str_replace("repo-", "", $repoId);
                 $shareMeta["type"] = "repository";
             }
             $minisite = $shareMeta["type"] == "minisite";
             if ($minisite) {
                 $shareLink = $this->getShareStore()->loadShareObject($shareId);
                 $repoId = $shareLink->getRepositoryId();
             }
             $notExistsData = array("error" => true, "repositoryId" => $repoId, "users_number" => 0, "label" => "Error - Cannot find shared data", "description" => "Cannot find repository", "entries" => array(), "element_watch" => false, "repository_url" => "");
             $repo = ConfService::getRepositoryById($repoId);
             if ($repoId == null || $repo == null && $node != null) {
                 if ($minisite) {
                     $this->getShareStore()->getMetaManager()->removeShareFromMeta($node, $shareId);
                 }
                 return $notExistsData;
             }
             try {
                 $this->getShareStore()->testUserCanEditShare($repo->getOwner(), $repo->options);
             } catch (Exception $e) {
                 $notExistsData["label"] = $e->getMessage();
                 return $notExistsData;
             }
             if ($this->watcher != false && $node != null) {
                 $elementWatch = $this->watcher->hasWatchOnNode(new AJXP_Node("pydio://" . $repoId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
             }
             if ($node != null) {
                 $sharedEntries = $this->getRightsManager()->computeSharedRepositoryAccessRights($repoId, true, new AJXP_Node("pydio://" . $repoId . "/"));
             } else {
                 $sharedEntries = $this->getRightsManager()->computeSharedRepositoryAccessRights($repoId, true, null);
             }
             if (empty($sharedEntries) && $minisite) {
                 $this->getShareStore()->getMetaManager()->removeShareFromMeta($node, $shareId);
                 return $notExistsData;
             }
             $cFilter = $repo->getContentFilter();
             if (!empty($cFilter)) {
                 $cFilter = $cFilter->toArray();
             }
             $jsonData = array("repositoryId" => $repoId, "users_number" => AuthService::countUsersForRepository($repoId), "label" => $repo->getDisplay(), "description" => $repo->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::getWorkspaceShortcutURL($repo) . "/", "content_filter" => $cFilter, "share_owner" => $repo->getOwner(), "share_scope" => isset($repo->options["SHARE_ACCESS"]) ? $repo->options["SHARE_ACCESS"] : "private");
             if ($minisite && isset($shareLink)) {
                 $shareLink->setAdditionalMeta($shareMeta);
                 $jsonData["minisite"] = $shareLink->getJsonData($this->getPublicAccessManager(), $messages);
             }
         }
     }
     return $jsonData;
 }
 /**
  * @param String $shareId
  * @param Array $shareData
  * @param AJXP_Node $node
  * @throws Exception
  * @return array|bool
  */
 public function shareToJson($shareId, $shareData, $node = null)
 {
     $messages = ConfService::getMessages();
     $jsonData = array();
     $elementWatch = false;
     if ($shareData["type"] == "file") {
         $pData = $this->getShareStore()->loadShare($shareId);
         if (!count($pData)) {
             return false;
         }
         foreach ($this->getShareStore()->modifiableShareKeys as $key) {
             if (isset($pData[$key])) {
                 $shareData[$key] = $pData[$key];
             }
         }
         if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId() && !AuthService::getLoggedUser()->isAdmin()) {
             throw new Exception($messages["share_center.48"]);
         }
         if (isset($shareData["short_form_url"])) {
             $link = $shareData["short_form_url"];
         } else {
             $link = $this->buildPublicletLink($shareId);
         }
         if ($this->watcher != false && $node != null) {
             $result = array();
             $elementWatch = $this->watcher->hasWatchOnNode($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_NAMESPACE, $result);
             if ($elementWatch && !in_array($shareId, $result)) {
                 $elementWatch = false;
             }
         }
         $jsonData = array_merge(array("element_id" => $shareId, "publiclet_link" => $link, "download_counter" => $this->getShareStore()->getCurrentDownloadCounter($shareId), "download_limit" => $pData["DOWNLOAD_LIMIT"], "expire_time" => $pData["EXPIRE_TIME"] != 0 ? date($messages["date_format"], $pData["EXPIRE_TIME"]) : 0, "has_password" => !empty($pData["PASSWORD"]), "element_watch" => $elementWatch, "is_expired" => $this->getShareStore()->isShareExpired($shareId, $pData)), $shareData);
     } else {
         if ($shareData["type"] == "minisite" || $shareData["type"] == "repository") {
             $repoId = $shareId;
             if (strpos($repoId, "repo-") === 0) {
                 // Legacy
                 $repoId = str_replace("repo-", "", $repoId);
                 $shareData["type"] = "repository";
             }
             $minisite = $shareData["type"] == "minisite";
             $minisiteIsPublic = false;
             $dlDisabled = false;
             $minisiteLink = '';
             if ($minisite) {
                 $minisiteData = $this->getShareStore()->loadShare($shareId);
                 $repoId = $minisiteData["REPOSITORY"];
                 $minisiteIsPublic = isset($minisiteData["PRELOG_USER"]);
                 $dlDisabled = isset($minisiteData["DOWNLOAD_DISABLED"]) && $minisiteData["DOWNLOAD_DISABLED"] === true;
                 if (isset($shareData["short_form_url"])) {
                     $minisiteLink = $shareData["short_form_url"];
                 } else {
                     $minisiteLink = $this->buildPublicletLink($shareId);
                 }
             }
             $notExistsData = array("error" => true, "repositoryId" => $repoId, "users_number" => 0, "label" => "Error - Cannot find shared data", "description" => "Cannot find repository", "entries" => array(), "element_watch" => false, "repository_url" => "");
             $repo = ConfService::getRepositoryById($repoId);
             if ($repoId == null || $repo == null && $node != null) {
                 if ($minisite) {
                     $this->removeShareFromMeta($node, $shareId);
                 }
                 return $notExistsData;
             } else {
                 if (!AuthService::getLoggedUser()->isAdmin() && $repo->getOwner() != AuthService::getLoggedUser()->getId()) {
                     return $notExistsData;
                 }
             }
             if ($this->watcher != false && $node != null) {
                 $elementWatch = $this->watcher->hasWatchOnNode(new AJXP_Node("pydio://" . $repoId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
             }
             if ($node != null) {
                 $sharedEntries = $this->computeSharedRepositoryAccessRights($repoId, true, "pydio://" . $repoId . "/");
             } else {
                 $sharedEntries = $this->computeSharedRepositoryAccessRights($repoId, true, null);
             }
             $cFilter = $repo->getContentFilter();
             if (!empty($cFilter)) {
                 $cFilter = $cFilter->toArray();
             }
             $jsonData = array("repositoryId" => $repoId, "users_number" => AuthService::countUsersForRepository($repoId), "label" => $repo->getDisplay(), "description" => $repo->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::getWorkspaceShortcutURL($repo) . "/", "content_filter" => $cFilter);
             if (isset($minisiteData)) {
                 if (!empty($minisiteData["DOWNLOAD_LIMIT"]) && !$dlDisabled) {
                     $jsonData["download_counter"] = $this->getShareStore()->getCurrentDownloadCounter($shareId);
                     $jsonData["download_limit"] = $minisiteData["DOWNLOAD_LIMIT"];
                 }
                 if (!empty($minisiteData["EXPIRE_TIME"])) {
                     $delta = $minisiteData["EXPIRE_TIME"] - time();
                     $days = round($delta / (60 * 60 * 24));
                     $jsonData["expire_time"] = date($messages["date_format"], $minisiteData["EXPIRE_TIME"]);
                     $jsonData["expire_after"] = $days;
                 } else {
                     $jsonData["expire_after"] = 0;
                 }
                 $jsonData["is_expired"] = $this->getShareStore()->isShareExpired($shareId, $minisiteData);
                 if (isset($minisiteData["AJXP_TEMPLATE_NAME"])) {
                     $jsonData["minisite_layout"] = $minisiteData["AJXP_TEMPLATE_NAME"];
                 }
                 if (!$minisiteIsPublic) {
                     $jsonData["has_password"] = true;
                 }
                 $jsonData["minisite"] = array("public" => $minisiteIsPublic ? "true" : "false", "public_link" => $minisiteLink, "disable_download" => $dlDisabled, "hash" => $shareId, "hash_is_shorten" => isset($shareData["short_form_url"]));
                 foreach ($this->getShareStore()->modifiableShareKeys as $key) {
                     if (isset($minisiteData[$key])) {
                         $jsonData[$key] = $minisiteData[$key];
                     }
                 }
             }
         }
     }
     return $jsonData;
 }