Permalink
Browse files

Embed CURRENT_MINISITE session key in ApplicationState, save / load i…

…n middlewares.

Update DL links for public links
  • Loading branch information...
1 parent fef670f commit 345dac83c5819e16ad1251f010a738a8d1260b1b @cdujeu cdujeu committed Sep 22, 2016
@@ -23,6 +23,7 @@
use Pydio\Core\Http\Server;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\SessionService;
+use Pydio\Core\Utils\ApplicationState;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -75,6 +76,10 @@ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface $r
SessionService::close();
});
+ if(SessionService::has(SessionService::CTX_MINISITE_HASH)){
+ ApplicationState::setStateMinisite(SessionService::fetch(SessionService::CTX_MINISITE_HASH));
+ }
+
return Server::callNextMiddleWare($requestInterface, $responseInterface, $next);
}
@@ -26,6 +26,7 @@
use Pydio\Core\Model\UserInterface;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\UsersService;
+use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Vars\StringHelper;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -132,9 +133,7 @@ protected function repositoryToXML($repoObject, $isActive, $exposed, $streams, $
}
$descTag = "";
- $public = false;
- if(!empty($_SESSION["CURRENT_MINISITE"])) $public = true;
- $description = $repoObject->getDescription($public, $ownerLabel);
+ $description = $repoObject->getDescription(ApplicationState::hasMinisiteHash(), $ownerLabel);
if (!empty($description)) {
$descTag = '<description>'. StringHelper::xmlEntities($description, true) .'</description>';
}
@@ -24,6 +24,7 @@
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\UsersService;
+use Pydio\Core\Utils\ApplicationState;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -126,7 +127,7 @@ protected function writeRepositoriesData(ContextInterface $ctx)
}
foreach ($accessible as $repoId => $repoObject) {
- if(!isSet($_SESSION["CURRENT_MINISITE"]) && $repoObject->hasContentFilter()){
+ if(!ApplicationState::hasMinisiteHash() && $repoObject->hasContentFilter()){
continue;
}
$accessStatus = '';
@@ -41,6 +41,7 @@ class SessionService implements RepositoriesCache
const LANGUAGES_KEY = "PYDIO_LANGUAGES";
const CTX_LANGUAGE_KEY = "PYDIO_CTX_LANGUAGE";
const CTX_CHARSET_KEY = "PYDIO_CTX_CHARSET";
+ const CTX_MINISITE_HASH = "PYDIO_CTX_MINISITE";
private static $sessionName = PYDIO_SESSION_NAME;
@@ -43,6 +43,11 @@ class ApplicationState
private static $sapiType = "session";
/**
+ * @var string
+ */
+ private static $minisiteHash = null;
+
+ /**
* @param string $restBase
*/
public static function setSapiRestBase($restBase){
@@ -76,6 +81,27 @@ public static function sapiUsesSession(){
}
/**
+ * @param $hash
+ */
+ public static function setStateMinisite($hash){
+ self::$minisiteHash = $hash;
+ }
+
+ /**
+ * @return bool
+ */
+ public static function hasMinisiteHash(){
+ return self::$minisiteHash !== null;
+ }
+
+ /**
+ * @return string
+ */
+ public static function getMinisiteHash(){
+ return self::$minisiteHash;
+ }
+
+ /**
* Check if data/cache/first_run_passed file exists or not
* @return bool
*/
@@ -50,7 +50,7 @@ class PowerFSController extends Plugin
public function performChecks()
{
- if (class_exists("\\Pydio\\Share\\ShareCenter") && \Pydio\Share\ShareCenter::currentContextIsLinkDownload()) {
+ if(ApplicationState::hasMinisiteHash() && ApplicationState::getSapiRestBase() !== null){
throw new Exception("Disable during link download");
}
}
@@ -227,11 +227,11 @@
if(staticClass.getRESTPreviewLinks){
var links = staticClass.getRESTPreviewLinks(node);
$H(links).each(function(pair){
- modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "?dl=true&ct=true"+pair.value}));
+ modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "/dl"+node.getPath()+"?ct=true"+pair.value}));
});
}
}
- var dlLink = document.location.href.split('?').shift() + "?dl=true&file=" + encodeURIComponent(node.getPath());
+ var dlLink = document.location.href.split('?').shift() + "/dl" + node.getPath();
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:MessageHash['share_center.60'],link:dlLink}));
}
]]></dialogOnOpen>
@@ -253,7 +253,7 @@
</action>
<action name="download">
<pre_processing>
- <serverCallback methodName="preProcessDownload" applyCondition="$apply=isSet($_SESSION['CURRENT_MINISITE']);"/>
+ <serverCallback methodName="preProcessDownload" applyCondition="$apply=\Pydio\Core\Services\SessionService::has(\Pydio\Core\Services\SessionService::CTX_MINISITE_HASH);"/>
</pre_processing>
</action>
</actions>
@@ -92,7 +92,8 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
}
if($sessions){
- $_SESSION["CURRENT_MINISITE"] = $hash;
+ SessionService::save(SessionService::CTX_MINISITE_HASH, $hash);
+ ApplicationState::setStateMinisite($hash);
}
if(!empty($ctx) && $ctx->hasUser() && isSet($shareData["REPOSITORY"])){
$repoObject = UsersService::getRepositoryWithPermission($ctx->getUser(), $shareData["REPOSITORY"]);
@@ -533,17 +533,19 @@ protected function toggleWatchOnSharedRepository($childRepoId, $userId, $toggle
*/
public function preProcessDownload(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface){
- if(isSet($_SESSION["CURRENT_MINISITE"])){
- $hash = $_SESSION["CURRENT_MINISITE"];
- $share = $this->getShareStore()->loadShareObject($hash);
- if(!empty($share)){
- if($share->isExpired()){
- throw new \Exception('Link is expired');
- }
- if($share->hasDownloadLimit()){
- $share->incrementDownloadCount();
- $share->save();
- }
+ if(!ApplicationState::hasMinisiteHash()) {
+ return;
+ }
+
+ $hash = ApplicationState::getMinisiteHash();
+ $share = $this->getShareStore()->loadShareObject($hash);
+ if(!empty($share)){
+ if($share->isExpired()){
+ throw new \Exception('Link is expired');
+ }
+ if($share->hasDownloadLimit()){
+ $share->incrementDownloadCount();
+ $share->save();
}
}
@@ -32,6 +32,7 @@
use Pydio\Core\Services\RolesService;
use Pydio\Core\Services\SessionService;
use Pydio\Core\Services\UsersService;
+use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\DBHelper;
use Pydio\Log\Core\Logger;
@@ -82,7 +83,7 @@ function tryToLogUser(ServerRequestInterface &$request, ResponseInterface &$resp
{
$httpVars = $request->getParsedBody();
- if (isset($_SESSION["CURRENT_MINISITE"])) {
+ if (ApplicationState::hasMinisiteHash()) {
return false;
}
@@ -81,7 +81,7 @@ protected function logUserFromSession(\Psr\Http\Message\ServerRequestInterface &
}
- if (ConfService::getGlobalConf("ALLOW_GUEST_BROWSING", "auth") && !isSet($_SESSION["CURRENT_MINISITE"])) {
+ if (ConfService::getGlobalConf("ALLOW_GUEST_BROWSING", "auth") && !ApplicationState::hasMinisiteHash()) {
$authDriver = ConfService::getAuthDriverImpl();
if (!$authDriver->userExists("guest")) {
@@ -165,8 +165,8 @@ protected function replaceVars($tplString, $mess, $rich = true)
*/
public function getMainLink()
{
- if(isSet($_SESSION["CURRENT_MINISITE"]) && class_exists("\\Pydio\\Share\\ShareCenter")){
- $hash = $_SESSION["CURRENT_MINISITE"];
+ if(ApplicationState::hasMinisiteHash() && class_exists("\\Pydio\\Share\\ShareCenter")){
+ $hash = ApplicationState::getMinisiteHash();
$shareCenter = \Pydio\Share\ShareCenter::getShareCenter($this->getContext());
if(!empty($shareCenter)){
return $shareCenter->getPublicAccessManager()->buildPublicLink($hash);
@@ -251,7 +251,7 @@ private function computeLocationType(){
$crtUserId = "shared";
$crtUser = $this->getNode()->hasUser() ? $this->getNode()->getUser() : null;
if($crtUser != null) $crtUserId = $crtUser->getId();
- if(isSet($_SESSION["CURRENT_MINISITE"])){
+ if(ApplicationState::hasMinisiteHash()){
if($repo->hasContentFilter()){
$type = "minisite.file";
}else{
@@ -719,8 +719,8 @@ Class.create("Diaporama", AbstractEditor, {
getRESTPreviewLinks:function(node){
return {
- "Original image": "&file=" + encodeURIComponent(node.getPath()),
- "Thumbnail (200px)": "&get_thumb=true&dimension=200&file=" + encodeURIComponent(node.getPath())
+ "Original image": "",
+ "Thumbnail (200px)": "&get_thumb=true&dimension=200"
};
},
@@ -172,7 +172,7 @@ Class.create("IMagickPreviewer", Diaporama, {
getRESTPreviewLinks:function(node){
return {
- "First Page Thumbnail": "&file=" + encodeURIComponent(node.getPath())
+ "First Page Thumbnail": ""
};
},
@@ -243,7 +243,7 @@ soundManager.setup({\n\
},
getRESTPreviewLinks:function(node){
- return {"MP3 Stream": "&file=" + encodeURIComponent(node.getPath())};
+ return {"MP3 Stream": ""};
},
getPreview : function(ajxpNode, rich){
@@ -92,7 +92,7 @@ preload="auto" width="#{WIDTH}" height="#{HEIGHT}" data-setup="{}">\n\
},
getRESTPreviewLinks:function(node){
- return {"Video Stream": "&file=" + encodeURIComponent(node.getPath())};
+ return {"Video Stream": ""};
},
@@ -22,6 +22,7 @@
namespace Pydio\Gui;
use Exception;
+use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Http\UserAgent;
use Pydio\Core\PluginFramework\Plugin;
@@ -37,7 +38,9 @@ class MobileNativeRedirect extends Plugin
{
public function performChecks()
{
- if (isSet($_SESSION["CURRENT_MINISITE"])) throw new Exception("Disabled for minisites");
+ if (ApplicationState::hasMinisiteHash()) {
+ throw new Exception("Disabled for minisites");
+ }
if (UserAgent::userAgentIsWindowsPhone()) {
throw new Exception("No native app for windows phone");
}

0 comments on commit 345dac8

Please sign in to comment.