/** * @param AJXP_Node $ajxpNode * @param array $httpVars * @param bool $update * @return Repository[]|ShareLink[] * @throws Exception */ public function shareNode($ajxpNode, $httpVars, &$update) { $hiddenUserEntries = array(); $originalHttpVars = $httpVars; $ocsStore = new Pydio\OCS\Model\SQLStore(); $ocsClient = new Pydio\OCS\Client\OCSClient(); $userSelection = new UserSelection($this->repository, $httpVars); $mess = ConfService::getMessages(); /** * @var ShareLink[] $shareObjects */ $shareObjects = array(); // PUBLIC LINK if (isset($httpVars["enable_public_link"])) { if (!$this->getAuthorization($ajxpNode->isLeaf() ? "file" : "folder", "minisite")) { throw new Exception($mess["share_center." . ($ajxpNode->isLeaf() ? "225" : "226")]); } $this->shareObjectFromParameters($httpVars, $hiddenUserEntries, $shareObjects, "public"); } else { if (isset($httpVars["disable_public_link"])) { $this->getShareStore()->deleteShare("minisite", $httpVars["disable_public_link"], true); } } if (isset($httpVars["ocs_data"])) { $ocsData = json_decode($httpVars["ocs_data"], true); $removeLinks = $ocsData["REMOVE"]; foreach ($removeLinks as $linkHash) { // Delete Link, delete invitation(s) $this->getShareStore()->deleteShare("minisite", $linkHash, true); $invitations = $ocsStore->invitationsForLink($linkHash); foreach ($invitations as $invitation) { $ocsStore->deleteInvitation($invitation); $ocsClient->cancelInvitation($invitation); } } $newLinks = $ocsData["LINKS"]; foreach ($newLinks as $linkData) { $this->shareObjectFromParameters($linkData, $hiddenUserEntries, $shareObjects, "targetted", $userSelection->getUniqueNode()->getLabel()); } } $this->filterHttpVarsFromUniqueNode($httpVars, $ajxpNode); $users = array(); $groups = array(); $this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups); if ((count($users) || count($groups)) && !$this->getAuthorization($ajxpNode->isLeaf() ? "file" : "folder", "workspace")) { $users = $groups = array(); } foreach ($hiddenUserEntries as $entry) { $users[$entry["ID"]] = $entry; } if (!count($users) && !count($groups)) { ob_start(); unset($originalHttpVars["hash"]); $this->switchAction("unshare", $originalHttpVars, array()); ob_end_clean(); return null; } $newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups); foreach ($shareObjects as $shareObject) { $shareObject->setParentRepositoryId($this->repository->getId()); $shareObject->attachToRepository($newRepo->getId()); $shareObject->save(); if ($shareObject instanceof \Pydio\OCS\Model\TargettedLink) { $invitation = $shareObject->getPendingInvitation(); if (!empty($invitation)) { $ocsStore->generateInvitationId($invitation); try { $ocsClient->sendInvitation($invitation); } catch (Exception $e) { $this->getShareStore()->deleteShare("minisite", $shareObject->getHash(), true); $shareUserId = $shareObject->getUniqueUser(); unset($users[$shareUserId]); if (!count($users) && !count($groups)) { $this->getShareStore()->deleteShare("repository", $newRepo->getId()); } throw $e; } $ocsStore->storeInvitation($invitation); } } else { $this->getPublicAccessManager()->initFolder(); $url = $this->getPublicAccessManager()->buildPublicLink($shareObject->getHash()); $existingShortForm = $shareObject->getShortFormUrl(); if (empty($existingShortForm)) { $shortForm = ""; AJXP_Controller::applyHook("url.shorten", array($url, &$shortForm)); if (!empty($shortForm)) { $shareObject->setShortFormUrl($shortForm); $shareObject->save(); } } } } $shareObjects[] = $newRepo; return $shareObjects; }