Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix issues in LegacyPubliclet
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Feb 4, 2016
1 parent c8265ff commit 57660a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
22 changes: 13 additions & 9 deletions core/src/plugins/action.share/class.LegacyPubliclet.php
Expand Up @@ -30,7 +30,12 @@ private static function renderError($data, $hash, $message = null){
MinisiteRenderer::renderError($data, $hash, $message);
}

public static function render($data){
/**
* @param array $data
* @param array $options
* @param ShareStore $shareStore
*/
public static function render($data, $options, $shareStore){

if(isset($data["SECURITY_MODIFIED"]) && $data["SECURITY_MODIFIED"] === true){
self::renderError($data, "false");
Expand All @@ -52,17 +57,17 @@ public static function render($data){
} else {
include(dirname(__FILE__)."/res/i18n/en.php");
}
if(isSet($mess)) $messages = $mess;
if(isSet($mess)) {
$messages = $mess;
}

$AJXP_LINK_HAS_PASSWORD = false;
$AJXP_LINK_BASENAME = SystemTextEncoding::toUTF8(basename($data["FILE_PATH"]));
AJXP_PluginsService::getInstance()->initActivePlugins();

$shareCenter = self::getShareCenter();

ConfService::setLanguage($language);
$mess = ConfService::getMessages();
if ($shareCenter->getShareStore()->isShareExpired($shortHash, $data))
if ($shareStore->isShareExpired($shortHash, $data))
{
self::renderError(array(), $shortHash, $mess["share_center.165"]);
return;
Expand All @@ -71,8 +76,7 @@ public static function render($data){

$customs = array("title", "legend", "legend_pass", "background_attributes_1","text_color", "background_color", "textshadow_color");
$images = array("button", "background_1");
$shareCenter = AJXP_PluginsService::findPlugin("action", "share");
$confs = $shareCenter->getConfigs();
$confs = $options;
$confs["CUSTOM_SHAREPAGE_BACKGROUND_ATTRIBUTES_1"] = "background-repeat:repeat;background-position:50% 50%;";
$confs["CUSTOM_SHAREPAGE_BACKGROUND_1"] = "plugins/action.share/res/hi-res/02.jpg";
$confs["CUSTOM_SHAREPAGE_TEXT_COLOR"] = "#ffffff";
Expand Down Expand Up @@ -131,7 +135,7 @@ public static function render($data){
$driver->loadManifest();

//$hash = md5(serialize($data));
$shareCenter->getShareStore()->incrementDownloadCounter($shortHash);
$shareStore->incrementDownloadCounter($shortHash);

//AuthService::logUser($data["OWNER_ID"], "", true);
AuthService::logTemporaryUser($data["OWNER_ID"], $shortHash);
Expand Down Expand Up @@ -190,7 +194,7 @@ public static function render($data){
* @param Repository $repository
* @param ShareStore $shareStore
* @param PublicAccessManager $publicAccessManager
* @return array An array containing the hash (0) and the generated url (1)
* @return string|array An array containing the hash (0) and the generated url (1)
*/
public function writePubliclet(&$data, $accessDriver, $repository, $shareStore, $publicAccessManager)
{
Expand Down
24 changes: 21 additions & 3 deletions core/src/plugins/action.share/class.PublicAccessManager.php
Expand Up @@ -25,7 +25,7 @@
class PublicAccessManager
{
/**
* @var AJXP_Plugin
* @var array
*/
private $options;

Expand All @@ -37,6 +37,9 @@ public function __construct($options){
$this->options = $options;
}

/**
* Initialize download folder if not already done
*/
public function initFolder()
{
$downloadFolder = $this->getPublicDownloadFolder();
Expand Down Expand Up @@ -75,6 +78,11 @@ public function initFolder()

}

/**
* Compute external link from the given hash
* @param string $hash
* @return string
*/
public function buildPublicLink($hash)
{
$addLang = ConfService::getLanguage() != ConfService::getCoreConf("DEFAULT_LANGUAGE");
Expand All @@ -87,7 +95,10 @@ public function buildPublicLink($hash)
}
}


/**
* Compute base URL for external links
* @return mixed|string
*/
public function buildPublicDlURL()
{
$downloadFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER");
Expand All @@ -113,11 +124,18 @@ public function computeMinisiteToServerURL()
return AJXP_Utils::getTravelPath($minisite, $server);
}


/**
* Get download folder path from configuration
* @return string
*/
public function getPublicDownloadFolder(){
return ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER");
}

/**
* Build download folder URL from configuration and current URL
* @return string|null
*/
public function getPublicDownloadUrl(){
$downloadFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER");
$dlURL = ConfService::getCoreConf("PUBLIC_DOWNLOAD_URL");
Expand Down
8 changes: 5 additions & 3 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -221,7 +221,6 @@ public function switchAction($action, $httpVars, $fileVars)
}
}
$userSelection = new UserSelection(ConfService::getRepository(), $httpVars);
$file = $userSelection->getUniqueFile();
$ajxpNode = $userSelection->getUniqueNode();
if (!file_exists($ajxpNode->getUrl())) {
throw new Exception("Cannot share a non-existing file: ".$ajxpNode->getUrl());
Expand Down Expand Up @@ -829,7 +828,7 @@ public function updateNodeSharedData($oldNode=null, $newNode=null, $copy = false

} else {

if(isSet($publicLink["FILE_PATH"])){
if(isset($publicLink) && is_array($publicLink) && isSet($publicLink["FILE_PATH"])){
$publicLink["FILE_PATH"] = str_replace($oldNode->getPath(), $newNode->getPath(), $publicLink["FILE_PATH"]);
$this->getShareStore()->deleteShare("file", $id);
$this->getShareStore()->storeShare($newNode->getRepositoryId(), $publicLink, "file", $id);
Expand Down Expand Up @@ -915,7 +914,10 @@ public static function loadShareByHash($hash){
public static function loadPubliclet($data)
{
require_once("class.LegacyPubliclet.php");
LegacyPubliclet::render($data);
$shareCenter = self::getShareCenter();
$options = $shareCenter->getConfigs();
$shareStore = $shareCenter->getShareStore();
LegacyPubliclet::render($data, $options, $shareStore);
}


Expand Down

0 comments on commit 57660a8

Please sign in to comment.