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

Commit

Permalink
Fix various condition issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed May 27, 2016
1 parent 1e28a12 commit 4b3658b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
4 changes: 4 additions & 0 deletions core/src/plugins/action.share/src/Legacy/LegacyPubliclet.php
Expand Up @@ -366,6 +366,10 @@ public static function migrateLegacyMeta($shareCenter, $shareStore, $shareRightM
if(file_exists($legacyLinkFile)){
// Load file, move it to DB and move the meta
$publiclet = $shareStore->loadShare($element);
if($publiclet === false){
print("\n--Could not load publiclet $element, skipping");
continue;
}
rename($legacyLinkFile, $legacyLinkFile.".migrated");
if(isSet($share["minisite"])){
print("\n--Migrate legacy minisite to new minisite?");
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/action.share/src/Model/ShareLink.php
Expand Up @@ -186,9 +186,9 @@ public function parseHttpVars($httpVars){
// Existing already
$value = Utils::sanitize($httpVars["custom_handle"], AJXP_SANITIZE_ALPHANUM);
$value = strtolower($value);
if(strlen($value) < $this->store->hashMinLength){
if(strlen($value) < $this->store->getHashMinLength()){
$mess = ConfService::getMessages();
throw new \Exception(str_replace("%s", $this->store->hashMinLength, $mess["share_center.223"]));
throw new \Exception(str_replace("%s", $this->store->getHashMinLength(), $mess["share_center.223"]));
}
$test = $this->store->loadShare($value);
$mess = ConfService::getMessages();
Expand Down Expand Up @@ -379,7 +379,7 @@ public function getDownloadLimit(){
}

public static function isShareExpired($data){
return ($data["EXPIRE_TIME"] && time() > $data["EXPIRE_TIME"]) ||
return (isSet($data["EXPIRE_TIME"]) && time() > $data["EXPIRE_TIME"]) ||
($data["DOWNLOAD_LIMIT"] && $data["DOWNLOAD_LIMIT"]> 0 && isSet($data["DOWNLOAD_COUNT"]) && $data["DOWNLOAD_LIMIT"] <= $data["DOWNLOAD_COUNT"]);
}

Expand Down
5 changes: 5 additions & 0 deletions core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -1226,6 +1226,11 @@ public static function loadShareByHash($hash){
$shareCenter = self::getShareCenter();
$data = $shareCenter->getShareStore()->loadShare($hash);
$mess = ConfService::getMessages();
if($data === false){
AuthService::disconnect();
self::loadMinisite([], $hash, $mess["share_center.166"]);
return;
}
if(ShareLink::isShareExpired($data)){
AuthService::disconnect();
self::loadMinisite($data, $hash, $mess["share_center.165"]);
Expand Down
28 changes: 12 additions & 16 deletions core/src/plugins/action.share/src/Store/ShareStore.php
Expand Up @@ -40,7 +40,11 @@ class ShareStore {

var $sqlSupported = false;
var $downloadFolder;
var $hashMinLength;
/**
* @var int
*/
private $hashMinLength;

public $modifiableShareKeys = array("counter", "tags", "short_form_url");
/**
* @var sqlConfDriver
Expand All @@ -59,6 +63,10 @@ public function __construct($downloadFolder, $hashMinLength = 32){
}
}

public function getHashMinLength(){
return $this->hashMinLength;
}

/**
* @return ShareMetaManager
*/
Expand Down Expand Up @@ -442,7 +450,7 @@ public function deleteShare($type, $element, $keepRepository = false, $ignoreRep
AuthService::deleteUser($element);
} else if ($type == "file") {
$publicletData = $this->loadShare($element);
if (isSet($publicletData["OWNER_ID"]) && $this->testUserCanEditShare($publicletData["OWNER_ID"], $publicletData)) {
if ($publicletData!== false && isSet($publicletData["OWNER_ID"]) && $this->testUserCanEditShare($publicletData["OWNER_ID"], $publicletData)) {
if(isSet($publicletData["PUBLICLET_PATH"]) && is_file($publicletData["PUBLICLET_PATH"])){
unlink($publicletData["PUBLICLET_PATH"]);
}else if($this->sqlSupported){
Expand Down Expand Up @@ -656,18 +664,7 @@ public function resetDownloadCounter($hash, $userId){
$share->resetDownloadCount();
$share->save();
}

/**
* Check if share is expired
* @param string $hash
* @param array $data
* @return bool
*/
public function isShareExpired($hash, $data){
return ($data["EXPIRE_TIME"] && time() > $data["EXPIRE_TIME"]) ||
($data["DOWNLOAD_LIMIT"] && $data["DOWNLOAD_LIMIT"]> 0 && isSet($data["DOWNLOAD_COUNT"]) && $data["DOWNLOAD_LIMIT"] <= $data["DOWNLOAD_COUNT"]);
}


/**
* Find all expired shares and remove them.
* @param bool|true $currentUser
Expand All @@ -692,8 +689,7 @@ public function clearExpiredFiles($currentUser = true)
if ($currentUser && ( !isSet($publicletData["OWNER_ID"]) || $publicletData["OWNER_ID"] != $userId )) {
continue;
}
if( (isSet($publicletData["EXPIRE_TIME"]) && is_numeric($publicletData["EXPIRE_TIME"]) && $publicletData["EXPIRE_TIME"] > 0 && $publicletData["EXPIRE_TIME"] < time()) ||
(isSet($publicletData["DOWNLOAD_LIMIT"]) && $publicletData["DOWNLOAD_LIMIT"] > 0 && isSet($publicletData["DOWNLOAD_COUNT"]) && $publicletData["DOWNLOAD_LIMIT"] <= $publicletData["DOWNLOAD_COUNT"]) ) {
if (ShareLink::isShareExpired($publicletData)){
if(!$currentUser) $switchBackToOriginal = true;
$this->deleteExpiredPubliclet($hash, $publicletData);
$deleted[] = $publicletData["FILE_PATH"];
Expand Down

0 comments on commit 4b3658b

Please sign in to comment.