Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * @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;
 }