openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 4528f13c448f7a5fc9b9defb721b3fdebf406c4a
parent 4c0c55c05fd331bef753c862056819feed75b3f7
Author: Jan Dankert <develop@jandankert.de>
Date:   Fri, 22 Nov 2019 00:35:51 +0100

New: More helper function for filesystem utils.

Diffstat:
modules/cms-publish/PublishPublic.class.php | 12+++++-------
modules/util/FileUtils.class.php | 19++++++++++++++++---
2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/modules/cms-publish/PublishPublic.class.php b/modules/cms-publish/PublishPublic.class.php @@ -9,6 +9,7 @@ use cms\model\Link; use cms\model\Page; use cms\model\Project; use cms\model\Url; +use FileUtils; use Ftp; use Logger; use OpenRatException; @@ -103,19 +104,16 @@ class PublishPublic extends Publish $this->ftp->passive = ( $project->ftp_passive == '1' ); } - $localDir = rtrim( $project->target_dir,'/' ); + $targetDir = rtrim( $project->target_dir,'/' ); - if ( $confPublish['filesystem']['per_project'] && (!empty($localDir)) ) + if ( FileUtils::isAbsolutePath($targetDir) && $confPublish['filesystem']['per_project'] ) { - $this->localDestinationDirectory = $localDir; // Projekteinstellung verwenden. + $this->localDestinationDirectory = FileUtils::toAbsolutePath([$targetDir]); // Projekteinstellung verwenden. } else { - if ( ! $localDir ) - $localDir = $project->name; - // Konfiguriertes Verzeichnis verwenden. - $this->localDestinationDirectory = $confPublish['filesystem']['directory'].$localDir; + $this->localDestinationDirectory = FileUtils::toAbsolutePath([$confPublish['filesystem']['directory'],$targetDir]); } diff --git a/modules/util/FileUtils.class.php b/modules/util/FileUtils.class.php @@ -113,6 +113,20 @@ class FileUtils } } -} -?>- \ No newline at end of file + + public static function isAbsolutePath( $path ) { + return @$path[0] == '/'; + } + + + public static function toAbsolutePath( $pathElements ) { + $pathElements = array_map( function($path) { return trim($path,'/'); },$pathElements ); + return array_reduce( $pathElements, function($path,$item){return $path.($item?'/'.$item:'');},'' ); + } + + + public static function toRelativePath( $pathElements ) { + return '.'.self::toAbsolutePath($pathElements); + } +}