/**
  * @param PublicAccessManager $publicAccessManager
  * @param array $messages
  * @return mixed
  * @throws Exception
  */
 public function getJsonData($publicAccessManager, $messages)
 {
     $storedData = $this->internal;
     $minisiteIsPublic = isset($storedData["PRELOG_USER"]);
     $dlDisabled = isset($storedData["DOWNLOAD_DISABLED"]) && $storedData["DOWNLOAD_DISABLED"] === true;
     $shareMeta = isset($this->additionalMeta) ? $this->additionalMeta : array();
     $internalUserId = isset($storedData["PRELOG_USER"]) ? $storedData["PRELOG_USER"] : $storedData["PRESET_LOGIN"];
     if (empty($internalUserId)) {
         throw new Exception("Oups, link " . $this->getHash() . " has no internal user id, this is not normal.");
     }
     $jsonData = array("public" => $minisiteIsPublic ? "true" : "false", "disable_download" => $dlDisabled, "hash" => $this->getHash(), "hash_is_shorten" => isset($shareMeta["short_form_url"]) || isset($this->internal["SHORT_FORM_URL"]), "internal_user_id" => $internalUserId);
     if (!isset($storedData["TARGET"]) || $storedData["TARGET"] == "public") {
         if (isset($shareMeta["short_form_url"])) {
             $jsonData["public_link"] = $shareMeta["short_form_url"];
         } else {
             if (isset($this->internal["SHORT_FORM_URL"])) {
                 $jsonData["public_link"] = $this->getShortFormUrl();
             } else {
                 $jsonData["public_link"] = $publicAccessManager->buildPublicLink($this->getHash());
             }
         }
     }
     if (!empty($storedData["DOWNLOAD_LIMIT"]) && !$dlDisabled) {
         $jsonData["download_counter"] = $this->store->getCurrentDownloadCounter($this->getHash());
         $jsonData["download_limit"] = $storedData["DOWNLOAD_LIMIT"];
     }
     if (!empty($storedData["EXPIRE_TIME"])) {
         $delta = $storedData["EXPIRE_TIME"] - time();
         $days = round($delta / (60 * 60 * 24));
         $jsonData["expire_time"] = date($messages["date_format"], $storedData["EXPIRE_TIME"]);
         $jsonData["expire_after"] = $days;
     } else {
         $jsonData["expire_after"] = 0;
     }
     $jsonData["is_expired"] = $this->store->isShareExpired($this->getHash(), $storedData);
     if (isset($storedData["AJXP_TEMPLATE_NAME"])) {
         $jsonData["minisite_layout"] = $storedData["AJXP_TEMPLATE_NAME"];
     }
     if (!$minisiteIsPublic) {
         $jsonData["has_password"] = true;
     }
     foreach ($this->store->modifiableShareKeys as $key) {
         if (isset($storedData[$key])) {
             $jsonData[$key] = $storedData[$key];
         }
     }
     return $jsonData;
 }
 /**
  * @param string $shareId
  * @param ShareStore $shareStore
  * @param PublicAccessManager $publicAccessManager
  * @param MetaWatchRegister|null $watcher
  * @return array|false
  * @throws Exception
  */
 public static function publicletToJson($shareId, $shareMeta, $shareStore, $publicAccessManager, $watcher, $node)
 {
     $messages = ConfService::getMessages();
     $elementWatch = false;
     $pData = $shareStore->loadShare($shareId);
     if (!count($pData)) {
         return false;
     }
     foreach ($shareStore->modifiableShareKeys as $key) {
         if (isset($pData[$key])) {
             $shareMeta[$key] = $pData[$key];
         }
     }
     if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId() && !AuthService::getLoggedUser()->isAdmin()) {
         throw new Exception($messages["share_center.48"]);
     }
     if (isset($shareMeta["short_form_url"])) {
         $link = $shareMeta["short_form_url"];
     } else {
         $link = $publicAccessManager->buildPublicLink($shareId);
     }
     if ($watcher != false && $node != null) {
         $result = array();
         $elementWatch = $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" => $shareStore->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" => $shareStore->isShareExpired($shareId, $pData)), $shareMeta);
     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->shareStore->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($this->baseProtocol . "://" . $repoId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
             }
             if ($node != null) {
                 $sharedEntries = $this->computeSharedRepositoryAccessRights($repoId, true, $node->getUrl());
             } 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::detectServerURL(true) . "?goto=" . $repo->getSlug() . "/", "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->shareStore->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;
 }