コード例 #1
0
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (strpos($action, "sharelist") === false && !isset($this->accessDriver)) {
         throw new Exception("Cannot find access driver!");
     }
     if (strpos($action, "sharelist") === false && $this->accessDriver->getId() == "access.demo") {
         $errorMessage = "This is a demo, all 'write' actions are disabled!";
         if ($httpVars["sub_action"] == "delegate_repo") {
             return AJXP_XMLWriter::sendMessage(null, $errorMessage, false);
         } else {
             print $errorMessage;
         }
         return null;
     }
     switch ($action) {
         //------------------------------------
         // SHARING FILE OR FOLDER
         //------------------------------------
         case "share":
             $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : "";
             if (empty($subAction) && isset($httpVars["simple_share_type"])) {
                 $subAction = "create_minisite";
                 if (!isset($httpVars["simple_right_read"]) && !isset($httpVars["simple_right_download"])) {
                     $httpVars["simple_right_read"] = $httpVars["simple_right_download"] = "true";
                 }
             }
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             if (!file_exists($ajxpNode->getUrl())) {
                 throw new Exception("Cannot share a non-existing file: " . $ajxpNode->getUrl());
             }
             //$metadata = null;
             $newMeta = null;
             $maxdownload = abs(intval($this->getFilteredOption("FILE_MAX_DOWNLOAD", $this->repository->getId())));
             $download = isset($httpVars["downloadlimit"]) ? abs(intval($httpVars["downloadlimit"])) : 0;
             if ($maxdownload == 0) {
                 $httpVars["downloadlimit"] = $download;
             } elseif ($maxdownload > 0 && $download == 0) {
                 $httpVars["downloadlimit"] = $maxdownload;
             } else {
                 $httpVars["downloadlimit"] = min($download, $maxdownload);
             }
             $maxexpiration = abs(intval($this->getFilteredOption("FILE_MAX_EXPIRATION", $this->repository->getId())));
             $expiration = isset($httpVars["expiration"]) ? abs(intval($httpVars["expiration"])) : 0;
             if ($maxexpiration == 0) {
                 $httpVars["expiration"] = $expiration;
             } elseif ($maxexpiration > 0 && $expiration == 0) {
                 $httpVars["expiration"] = $maxexpiration;
             } else {
                 $httpVars["expiration"] = min($expiration, $maxexpiration);
             }
             $forcePassword = $this->getFilteredOption("SHARE_FORCE_PASSWORD", $this->repository->getId());
             $httpHash = null;
             $originalHash = null;
             if ($subAction == "delegate_repo") {
                 header("Content-type:text/plain");
                 $auth = $this->getAuthorization("folder", "workspace");
                 if (!$auth) {
                     print 103;
                     break;
                 }
                 $result = $this->createSharedRepository($httpVars, $this->repository, $this->accessDriver);
                 if (is_a($result, "Repository")) {
                     $newMeta = array("id" => $result->getUniqueId(), "type" => "repository");
                     $numResult = 200;
                 } else {
                     $numResult = $result;
                 }
                 print $numResult;
             } else {
                 if ($subAction == "create_minisite") {
                     header("Content-type:text/plain");
                     if (isset($httpVars["hash"]) && !empty($httpVars["hash"])) {
                         $httpHash = $httpVars["hash"];
                     }
                     if (isset($httpVars["simple_share_type"])) {
                         $httpVars["create_guest_user"] = "******";
                         if ($httpVars["simple_share_type"] == "private" && !isset($httpVars["guest_user_pass"])) {
                             throw new Exception("Please provide a guest_user_pass for private link");
                         }
                     }
                     if ($forcePassword && (isset($httpVars["create_guest_user"]) && $httpVars["create_guest_user"] == "true" && empty($httpVars["guest_user_pass"]) || isset($httpVars["guest_user_id"]) && isset($httpVars["guest_user_pass"]) && $httpVars["guest_user_pass"] == "")) {
                         $mess = ConfService::getMessages();
                         throw new Exception($mess["share_center.175"]);
                     }
                     $res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
                     if (!is_array($res)) {
                         $url = $res;
                     } else {
                         list($hash, $url) = $res;
                         $newMeta = array("id" => $hash, "type" => "minisite");
                         if ($httpHash != null && $hash != $httpHash) {
                             $originalHash = $httpHash;
                         }
                     }
                     print $url;
                 } else {
                     $data = $this->accessDriver->makePublicletOptions($file, $httpVars["password"], $httpVars["expiration"], $httpVars["downloadlimit"], $this->repository);
                     $customData = array();
                     foreach ($httpVars as $key => $value) {
                         if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") {
                             $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value;
                         }
                     }
                     if (count($customData)) {
                         $data["PLUGINS_DATA"] = $customData;
                     }
                     list($hash, $url) = $this->writePubliclet($data, $this->accessDriver, $this->repository);
                     $newMeta = array("id" => $hash, "type" => "file");
                     if (isset($httpVars["format"]) && $httpVars["format"] == "json") {
                         header("Content-type:application/json");
                         echo json_encode(array("element_id" => $hash, "publiclet_link" => $url));
                     } else {
                         header("Content-type:text/plain");
                         echo $url;
                     }
                     flush();
                 }
             }
             if ($newMeta != null && $ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) {
                 $this->addShareInMeta($ajxpNode, $newMeta["type"], $newMeta["id"], $originalHash);
             }
             AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
             // as the result can be quite small (e.g error code), make sure it's output in case of OB active.
             flush();
             break;
         case "toggle_link_watch":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $watchValue = $httpVars["set_watch"] == "true" ? true : false;
             $folder = false;
             $shNode = new AJXP_Node($this->urlBase . $file);
             if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "folder") {
                 $folder = true;
                 $node = new AJXP_Node($this->baseProtocol . "://" . $httpVars["repository_id"] . "/");
             } else {
                 $node = new AJXP_Node($this->urlBase . $file);
             }
             $this->getSharesFromMeta($shNode, $shares, false);
             if (!count($shares)) {
                 break;
             }
             if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) {
                 $elementId = $httpVars["element_id"];
             } else {
                 $sKeys = array_keys($shares);
                 $elementId = $sKeys[0];
             }
             if ($this->watcher !== false) {
                 if (!$folder) {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_READ, array($elementId));
                     } else {
                         $this->watcher->removeWatchFromFolder($node, AuthService::getLoggedUser()->getId(), true, $elementId);
                     }
                 } else {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH);
                     } else {
                         $this->watcher->removeWatchFromFolder($node, AuthService::getLoggedUser()->getId());
                     }
                 }
             }
             $mess = ConfService::getMessages();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["share_center.47"], null);
             AJXP_XMLWriter::close();
             break;
         case "load_shared_element_data":
             $node = null;
             if (isset($httpVars["hash"])) {
                 $t = "minisite";
                 if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "file") {
                     $t = "file";
                 }
                 $parsedMeta = array($httpVars["hash"] => array("type" => $t));
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $node = new AJXP_Node($this->urlBase . $file);
                 $this->getSharesFromMeta($node, $parsedMeta, true);
             }
             $flattenJson = false;
             $jsonData = array();
             foreach ($parsedMeta as $shareId => $shareMeta) {
                 $jsonData[] = $this->shareToJson($shareId, $shareMeta, $node);
                 if ($shareMeta["type"] != "file") {
                     $flattenJson = true;
                 }
             }
             header("Content-type:application/json");
             if ($flattenJson && count($jsonData)) {
                 $jsonData = $jsonData[0];
             }
             echo json_encode($jsonData);
             break;
         case "unshare":
             if (isset($httpVars["hash"])) {
                 $res = $this->getShareStore()->deleteShare($httpVars["element_type"], $httpVars["hash"]);
                 if ($res !== false) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage("Successfully unshared element", null);
                     AJXP_XMLWriter::close();
                 }
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $ajxpNode = new AJXP_Node($this->urlBase . $file);
                 $this->getSharesFromMeta($ajxpNode, $shares, false);
                 if (count($shares)) {
                     if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) {
                         $elementId = $httpVars["element_id"];
                     } else {
                         $sKeys = array_keys($shares);
                         $elementId = $sKeys[0];
                     }
                     if (isset($shares[$elementId]) && isset($shares[$elementId]["type"])) {
                         $t = $shares[$elementId]["type"];
                     } else {
                         $t = "file";
                     }
                     $this->getShareStore()->deleteShare($t, $elementId);
                     $this->removeShareFromMeta($ajxpNode, $elementId);
                     AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
                 }
             }
             break;
         case "reset_counter":
             if (isset($httpVars["hash"])) {
                 $userId = AuthService::getLoggedUser()->getId();
                 if (isset($httpVars["owner_id"]) && $httpVars["owner_id"] != $userId) {
                     if (!AuthService::getLoggedUser()->isAdmin()) {
                         throw new Exception("You are not allowed to access this resource");
                     }
                     $userId = $httpVars["owner_id"];
                 }
                 $this->getShareStore()->resetDownloadCounter($httpVars["hash"], $userId);
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $ajxpNode = new AJXP_Node($this->urlBase . $file);
                 $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
                 if (!isset($metadata["shares"]) || !is_array($metadata["shares"])) {
                     return null;
                 }
                 if (isset($httpVars["element_id"]) && isset($metadata["shares"][$httpVars["element_id"]])) {
                     $this->getShareStore()->resetDownloadCounter($httpVars["element_id"], $httpVars["owner_id"]);
                 } else {
                     $keys = array_keys($metadata["shares"]);
                     foreach ($keys as $key) {
                         $this->getShareStore()->resetDownloadCounter($key, null);
                     }
                 }
             }
             break;
         case "update_shared_element_data":
             if (!in_array($httpVars["p_name"], array("counter", "tags"))) {
                 return null;
             }
             $hash = AJXP_Utils::decodeSecureMagic($httpVars["element_id"]);
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if ($this->getShareStore()->shareIsLegacy($hash)) {
                 // Store in metadata
                 $ajxpNode = new AJXP_Node($this->urlBase . $file);
                 $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
                 if (isset($metadata["shares"][$httpVars["element_id"]])) {
                     if (!is_array($metadata["shares"][$httpVars["element_id"]])) {
                         $metadata["shares"][$httpVars["element_id"]] = array();
                     }
                     $metadata["shares"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"];
                     $ajxpNode->setMetadata("ajxp_shared", $metadata, true, AJXP_METADATA_SCOPE_REPOSITORY);
                 }
             } else {
                 $this->getShareStore()->updateShareProperty($hash, $httpVars["p_name"], $httpVars["p_value"]);
             }
             break;
         case "sharelist-load":
             $parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : "";
             $userContext = $httpVars["user_context"];
             $currentUser = true;
             if ($userContext == "global" && AuthService::getLoggedUser()->isAdmin()) {
                 $currentUser = false;
             }
             $nodes = $this->listSharesAsNodes("/data/repositories/{$parentRepoId}/shares", $currentUser, $parentRepoId);
             AJXP_XMLWriter::header();
             if ($userContext == "current") {
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns template_name="ajxp_user.shares">
                 <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
                 <column messageId="share_center.132" attributeName="shared_element_parent_repository_label" sortType="String"/>
                 <column messageId="3" attributeName="share_type_readable" sortType="String"/>
                 </columns>');
             } else {
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="filelist" template_name="ajxp_conf.repositories">
                 <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
                 <column messageId="share_center.159" attributeName="owner" sortType="String"/>
                 <column messageId="3" attributeName="share_type_readable" sortType="String"/>
                 <column messageId="share_center.52" attributeName="share_data" sortType="String"/>
                 </columns>');
             }
             foreach ($nodes as $node) {
                 AJXP_XMLWriter::renderAjxpNode($node);
             }
             AJXP_XMLWriter::close();
             break;
         case "sharelist-clearExpired":
             $currentUser = ConfService::getRepository()->getAccessType() != "ajxp_conf";
             $count = $this->clearExpiredFiles($currentUser);
             AJXP_XMLWriter::header();
             if ($count) {
                 AJXP_XMLWriter::sendMessage("Removed " . count($count) . " expired links", null);
             } else {
                 AJXP_XMLWriter::sendMessage("Nothing to do", null);
             }
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     return null;
 }
コード例 #2
0
ファイル: class.ShareCenter.php プロジェクト: biggtfish/cms
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->accessDriver)) {
         throw new Exception("Cannot find access driver!");
     }
     if ($this->accessDriver->getId() == "access.demo") {
         $errorMessage = "This is a demo, all 'write' actions are disabled!";
         if ($httpVars["sub_action"] == "delegate_repo") {
             return AJXP_XMLWriter::sendMessage(null, $errorMessage, false);
         } else {
             print $errorMessage;
         }
         return;
     }
     switch ($action) {
         //------------------------------------
         // SHARING FILE OR FOLDER
         //------------------------------------
         case "share":
             $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : "";
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             if (!file_exists($ajxpNode->getUrl())) {
                 throw new Exception("Cannot share a non-existing file: " . $ajxpNode->getUrl());
             }
             $metadata = null;
             if ($subAction == "delegate_repo") {
                 header("Content-type:text/plain");
                 $result = $this->createSharedRepository($httpVars, $this->repository, $this->accessDriver);
                 if (is_a($result, "Repository")) {
                     $metadata = array("element" => $result->getUniqueId());
                     $numResult = 200;
                 } else {
                     $numResult = $result;
                 }
                 print $numResult;
             } else {
                 if ($subAction == "create_minisite") {
                     header("Content-type:text/plain");
                     $res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
                     if (!is_array($res)) {
                         $url = $res;
                     } else {
                         list($hash, $url) = $res;
                         $metadata = array("element" => $hash, "minisite" => isset($httpVars["create_guest_user"]) ? "public" : "private");
                     }
                     print $url;
                 } else {
                     $maxdownload = abs(intval($this->getFilteredOption("FILE_MAX_DOWNLOAD", $this->repository->getId())));
                     $download = isset($httpVars["downloadlimit"]) ? abs(intval($httpVars["downloadlimit"])) : 0;
                     if ($maxdownload == 0) {
                         $httpVars["downloadlimit"] = $download;
                     } elseif ($maxdownload > 0 && $download == 0) {
                         $httpVars["downloadlimit"] = $maxdownload;
                     } else {
                         $httpVars["downloadlimit"] = min($download, $maxdownload);
                     }
                     $maxexpiration = abs(intval($this->getFilteredOption("FILE_MAX_EXPIRATION", $this->repository->getId())));
                     $expiration = isset($httpVars["expiration"]) ? abs(intval($httpVars["expiration"])) : 0;
                     if ($maxexpiration == 0) {
                         $httpVars["expiration"] = $expiration;
                     } elseif ($maxexpiration > 0 && $expiration == 0) {
                         $httpVars["expiration"] = $maxexpiration;
                     } else {
                         $httpVars["expiration"] = min($expiration, $maxexpiration);
                     }
                     $data = $this->accessDriver->makePublicletOptions($file, $httpVars["password"], $httpVars["expiration"], $httpVars["downloadlimit"], $this->repository);
                     $customData = array();
                     foreach ($httpVars as $key => $value) {
                         if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") {
                             $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value;
                         }
                     }
                     if (count($customData)) {
                         $data["PLUGINS_DATA"] = $customData;
                     }
                     list($hash, $url) = $this->writePubliclet($data, $this->accessDriver, $this->repository);
                     $metaArray = array();
                     if ($ajxpNode->hasMetaStore()) {
                         $existingMeta = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, true);
                         if (isset($existingMeta) && is_array($existingMeta) && array_key_exists("element", $existingMeta)) {
                             if (is_string($existingMeta["element"])) {
                                 $metaArray[$existingMeta["element"]] = array();
                             } else {
                                 $metaArray = $existingMeta["element"];
                             }
                         }
                     }
                     $metaArray[$hash] = array();
                     $metadata = array("element" => $metaArray);
                     if (isset($httpVars["format"]) && $httpVars["format"] == "json") {
                         header("Content-type:application/json");
                         echo json_encode(array("element_id" => $hash, "publiclet_link" => $url));
                     } else {
                         header("Content-type:text/plain");
                         echo $url;
                     }
                     flush();
                 }
             }
             if ($metadata != null && $ajxpNode->hasMetaStore()) {
                 $ajxpNode->setMetadata("ajxp_shared", $metadata, true, AJXP_METADATA_SCOPE_REPOSITORY, true);
             }
             AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
             // as the result can be quite small (e.g error code), make sure it's output in case of OB active.
             flush();
             break;
         case "toggle_link_watch":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $watchValue = $httpVars["set_watch"] == "true" ? true : false;
             $folder = false;
             if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "folder") {
                 $folder = true;
                 $node = new AJXP_Node($this->baseProtocol . "://" . $httpVars["repository_id"] . "/");
             } else {
                 $node = new AJXP_Node($this->urlBase . $file);
             }
             $metadata = $node->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             $elementId = $metadata["element"];
             if (isset($httpVars["element_id"]) && is_Array($metadata["element"]) && isset($metadata["element"][$httpVars["element_id"]])) {
                 $elementId = $httpVars["element_id"];
             }
             if ($this->watcher !== false) {
                 if (!$folder) {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_READ, array($elementId));
                     } else {
                         $this->watcher->removeWatchFromFolder($node, AuthService::getLoggedUser()->getId(), true, $elementId);
                     }
                 } else {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH);
                     } else {
                         $this->watcher->removeWatchFromFolder($node, AuthService::getLoggedUser()->getId());
                     }
                 }
             }
             $mess = ConfService::getMessages();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["share_center.47"], null);
             AJXP_XMLWriter::close();
             break;
         case "load_shared_element_data":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $elementType = $httpVars["element_type"];
             $messages = ConfService::getMessages();
             $node = new AJXP_Node($this->urlBase . $file);
             $metadata = $node->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             $elementWatch = false;
             if (count($metadata)) {
                 header("Content-type:application/json");
                 if ($elementType == "file") {
                     $elements = $metadata["element"];
                     if (is_string($elements)) {
                         $elements = array($elements => true);
                     }
                     $jsonData = array();
                     foreach ($elements as $element => $elementData) {
                         if (!is_array($elementData)) {
                             $elementData = array();
                         }
                         $pData = self::loadPublicletData($element);
                         if (!count($pData)) {
                             continue;
                         }
                         if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId()) {
                             throw new Exception($messages["share_center.48"]);
                         }
                         if (isset($elementData["short_form_url"])) {
                             $link = $elementData["short_form_url"];
                         } else {
                             $link = $this->buildPublicletLink($element);
                         }
                         if ($this->watcher != false) {
                             $result = array();
                             $elementWatch = $this->watcher->hasWatchOnNode($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_NAMESPACE, $result);
                             if ($elementWatch && !in_array($element, $result)) {
                                 $elementWatch = false;
                             }
                         }
                         $jsonData[] = array_merge(array("element_id" => $element, "publiclet_link" => $link, "download_counter" => PublicletCounter::getCount($element), "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), $elementData);
                     }
                 } else {
                     if ($elementType == "repository") {
                         if (isset($metadata["minisite"])) {
                             $minisiteData = self::loadPublicletData($metadata["element"]);
                             $repoId = $minisiteData["REPOSITORY"];
                             $minisiteIsPublic = isset($minisiteData["PRELOG_USER"]);
                             $dlDisabled = isset($minisiteData["DOWNLOAD_DISABLED"]);
                             if (isset($metadata["short_form_url"])) {
                                 $minisiteLink = $metadata["short_form_url"];
                             } else {
                                 $minisiteLink = $this->buildPublicletLink($metadata["element"]);
                             }
                         } else {
                             $repoId = $metadata["element"];
                         }
                         $repo = ConfService::getRepositoryById($repoId);
                         if ($repo == null || $repo->getOwner() != AuthService::getLoggedUser()->getId()) {
                             //throw new Exception($messages["share_center.48"]);
                             $jsonData = array("repositoryId" => $repoId, "label" => "Error - Cannot find shared data", "description" => "Cannot find repository", "entries" => array(), "element_watch" => false, "repository_url" => "");
                             echo json_encode($jsonData);
                             break;
                         }
                         if ($this->watcher != false) {
                             $elementWatch = $this->watcher->hasWatchOnNode(new AJXP_Node($this->baseProtocol . "://" . $repoId . "/"), AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_NAMESPACE);
                         }
                         $sharedEntries = $this->computeSharedRepositoryAccessRights($repoId, true, $this->urlBase . $file);
                         $jsonData = array("repositoryId" => $repoId, "label" => $repo->getDisplay(), "description" => $repo->getDescription(), "entries" => $sharedEntries, "element_watch" => $elementWatch, "repository_url" => AJXP_Utils::detectServerURL(true) . "?goto=" . $repo->getSlug() . "/");
                         if (isset($minisiteData)) {
                             $jsonData["minisite"] = array("public" => $minisiteIsPublic ? "true" : "false", "public_link" => $minisiteLink, "disable_download" => $dlDisabled);
                         }
                     }
                 }
                 echo json_encode($jsonData);
             }
             break;
         case "unshare":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             if (count($metadata)) {
                 $eType = $httpVars["element_type"];
                 if (isset($metadata["minisite"])) {
                     $eType = "minisite";
                 }
                 $elementId = $metadata["element"];
                 $updateMeta = false;
                 if (isset($httpVars["element_id"])) {
                     if (is_array($metadata["element"]) && isset($metadata["element"][$httpVars['element_id']])) {
                         $elementId = $httpVars["element_id"];
                         unset($metadata["element"][$httpVars['element_id']]);
                         if (count($metadata["element"]) > 0) {
                             $updateMeta = true;
                         }
                     }
                 }
                 self::deleteSharedElement($eType, $elementId, AuthService::getLoggedUser());
                 if ($updateMeta) {
                     $ajxpNode->setMetadata("ajxp_shared", $metadata, true, AJXP_METADATA_SCOPE_REPOSITORY, true);
                 } else {
                     $ajxpNode->removeMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, true);
                 }
             }
             AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
             break;
         case "reset_counter":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             if (isset($metadata["element"][$httpVars["element_id"]])) {
                 PublicletCounter::reset($httpVars["element_id"]);
             }
             break;
         case "update_shared_element_data":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if (!in_array($httpVars["p_name"], array("counter", "tags"))) {
             }
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             if (isset($metadata["element"][$httpVars["element_id"]])) {
                 if (!is_array($metadata["element"][$httpVars["element_id"]])) {
                     $metadata["element"][$httpVars["element_id"]] = array();
                 }
                 $metadata["element"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"];
                 $ajxpNode->setMetadata("ajxp_shared", $metadata, true, AJXP_METADATA_SCOPE_REPOSITORY);
             }
             break;
         default:
             break;
     }
 }
コード例 #3
0
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->accessDriver)) {
         throw new Exception("Cannot find access driver!");
     }
     if ($this->accessDriver->getId() == "access.demo") {
         $errorMessage = "This is a demo, all 'write' actions are disabled!";
         if ($httpVars["sub_action"] == "delegate_repo") {
             return AJXP_XMLWriter::sendMessage(null, $errorMessage, false);
         } else {
             print $errorMessage;
         }
         return;
     }
     switch ($action) {
         //------------------------------------
         // SHARING FILE OR FOLDER
         //------------------------------------
         case "share":
             $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : "";
             if ($subAction == "delegate_repo") {
                 header("Content-type:text/plain");
                 $result = $this->createSharedRepository($httpVars, $this->repository, $this->accessDriver);
                 print $result;
             } else {
                 if ($subAction == "list_shared_users") {
                     header("Content-type:text/html");
                     if (!ConfService::getAuthDriverImpl()->usersEditable()) {
                         break;
                     }
                     $loggedUser = AuthService::getLoggedUser();
                     $crtValue = $httpVars["value"];
                     if (!empty($crtValue)) {
                         $regexp = '^' . preg_quote($crtValue);
                     } else {
                         $regexp = null;
                     }
                     $limit = min($this->pluginConf["SHARED_USERS_LIST_LIMIT"], 20);
                     $allUsers = AuthService::listUsers($regexp, 0, $limit, false);
                     $users = "";
                     $index = 0;
                     foreach ($allUsers as $userId => $userObject) {
                         if (!$userObject->hasParent() && ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING") || $userObject->getParent() == $loggedUser->getId()) {
                             if ($regexp != null && !preg_match("/{$regexp}/i", $userId)) {
                                 continue;
                             }
                             $users .= "<li>" . $userId . "</li>";
                             $index++;
                         }
                         if ($index == $limit) {
                             break;
                         }
                     }
                     if (strlen($users)) {
                         print "<ul>" . $users . "</ul>";
                     }
                 } else {
                     $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                     if (!isset($httpVars["downloadlimit"])) {
                         $httpVars["downloadlimit"] = 0;
                     }
                     $data = $this->accessDriver->makePublicletOptions($file, $httpVars["password"], $httpVars["expiration"], $httpVars["downloadlimit"], $this->repository);
                     $customData = array();
                     foreach ($httpVars as $key => $value) {
                         if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") {
                             $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value;
                         }
                     }
                     if (count($customData)) {
                         $data["PLUGINS_DATA"] = $customData;
                     }
                     $url = $this->writePubliclet($data, $this->accessDriver, $this->repository);
                     if ($this->metaStore != null) {
                         $ar = explode(".", basename($url));
                         $this->metaStore->setMetadata(new AJXP_Node($this->urlBase . $file), "ajxp_shared", array("element" => array_shift($ar)), true, AJXP_METADATA_SCOPE_REPOSITORY);
                     }
                     header("Content-type:text/plain");
                     echo $url;
                 }
             }
             break;
         case "load_shared_element_data":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $elementType = $httpVars["element_type"];
             $messages = ConfService::getMessages();
             if ($this->metaStore != null) {
                 $metadata = $this->metaStore->retrieveMetadata(new AJXP_Node($this->urlBase . $file), "ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             }
             if (count($metadata)) {
                 header("Content-type:application/json");
                 if ($elementType == "file") {
                     $pData = self::loadPublicletData($metadata["element"]);
                     if ($pData["OWNER_ID"] != AuthService::getLoggedUser()->getId()) {
                         throw new Exception("You are not allowed to access this data");
                     }
                     if (isset($metadata["short_form_url"])) {
                         $link = $metadata["short_form_url"];
                     } else {
                         $link = $this->buildPublicletLink($metadata["element"]);
                     }
                     $jsonData = array("publiclet_link" => $link, "download_counter" => PublicletCounter::getCount($metadata["element"]), "download_limit" => $pData["DOWNLOAD_LIMIT"], "expire_time" => $pData["EXPIRE_TIME"] != 0 ? date($messages["date_format"], $pData["EXPIRE_TIME"]) : 0, "has_password" => !empty($pData["PASSWORD"]));
                 } else {
                     if ($elementType == "repository") {
                         $repoId = $metadata["element"];
                         $repo = ConfService::getRepositoryById($repoId);
                         if ($repo->getOwner() != AuthService::getLoggedUser()->getId()) {
                             throw new Exception("You are not allowed to access this data");
                         }
                         $sharedUsers = array();
                         $sharedRights = "";
                         $loggedUser = AuthService::getLoggedUser();
                         $users = AuthService::listUsers();
                         foreach ($users as $userId => $userObject) {
                             if ($userObject->getId() == $loggedUser->getId()) {
                                 continue;
                             }
                             if ($userObject->canWrite($repoId) && $userObject->canRead($repoId)) {
                                 $sharedUsers[] = $userId;
                                 $sharedRights = "rw";
                             } else {
                                 if ($userObject->canRead($repoId)) {
                                     $sharedUsers[] = $userId;
                                     $sharedRights = "r";
                                 } else {
                                     if ($userObject->canWrite($repoId)) {
                                         $sharedUsers[] = $userId;
                                         $sharedRights = "w";
                                     }
                                 }
                             }
                         }
                         $jsonData = array("repositoryId" => $repoId, "label" => $repo->getDisplay(), "rights" => $sharedRights, "users" => $sharedUsers);
                     }
                 }
                 echo json_encode($jsonData);
             }
             break;
         case "unshare":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             $metadata = $this->metaStore->retrieveMetadata($ajxpNode, "ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             if (count($metadata)) {
                 self::deleteSharedElement($httpVars["element_type"], $metadata["element"], AuthService::getLoggedUser());
                 $this->metaStore->removeMetadata($ajxpNode, "ajxp_shared", true);
             }
             break;
         case "reset_counter":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $metadata = $this->metaStore->retrieveMetadata(new AJXP_Node($this->urlBase . $file), "ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
             if (isset($metadata["element"])) {
                 PublicletCounter::reset($metadata["element"]);
             }
             break;
         default:
             break;
     }
 }