openrat-cms

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

commit 9b82e7f5c330794869305b546810a1704526052d
parent 72fde6322ca0c8cb43079965f2be30b593c02c7c
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 26 Sep 2020 18:46:36 +0200

Now compatible with PHP 5.4 again.

Diffstat:
modules/cms/Dispatcher.class.php | 4++--
modules/cms/base/DefaultConfig.class.php | 3++-
modules/cms/generator/Publisher.class.php | 48++++++++++++++++++++++++++++++++----------------
modules/cms/generator/target/BaseTarget.class.php | 2--
modules/cms/model/BaseObject.class.php | 7+------
modules/configuration/Config.class.php | 5+++--
6 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/modules/cms/Dispatcher.class.php b/modules/cms/Dispatcher.class.php @@ -185,8 +185,8 @@ class Dispatcher Logger::$dateFormat = $logConfig['date_format']; Logger::$nsLookup = $logConfig['ns_lookup']; - Logger::$outputType = (int) constant(Logger::class.'::OUTPUT_' . strtoupper($logConfig['output'])); - Logger::$level = (int) constant(Logger::class.'::LEVEL_' . strtoupper($logConfig['level' ])); + Logger::$outputType = (int) constant('\\logger\\Logger::OUTPUT_' . strtoupper($logConfig['output'])); + Logger::$level = (int) constant('\\logger\\Logger::LEVEL_' . strtoupper($logConfig['level' ])); Logger::$messageCallback = function ( $key ) { diff --git a/modules/cms/base/DefaultConfig.class.php b/modules/cms/base/DefaultConfig.class.php @@ -758,7 +758,8 @@ class DefaultConfig { 'vrm' => 'x-world/x-vrml', ], 'publish' => - [ + [ + 'targets' => ['Local','Ftp','Ftps','Fax','SFtp','Scp','Dav'], 'edit' => true, 'default' => 'index', 'format' => '{filename}{language_sep}{language}{type_sep}{type}', diff --git a/modules/cms/generator/Publisher.class.php b/modules/cms/generator/Publisher.class.php @@ -4,6 +4,7 @@ namespace cms\generator; +use cms\base\Configuration as C; use cms\generator\target\Dav; use cms\generator\target\Fax; use cms\generator\target\Ftp; @@ -17,6 +18,7 @@ use cms\model\BaseObject; use cms\model\File; use cms\model\Folder; use cms\model\Link; +use cms\model\ModelBase; use cms\model\Page; use cms\model\Project; use cms\model\Url; @@ -113,9 +115,9 @@ class Publisher */ public function init() { - $confPublish = \cms\base\Configuration::config('publish'); + $confPublish = C::subset('publish'); - if ( \cms\base\Configuration::config('security','nopublish') ) + if ( C::subset('security')->is('nopublish') ) { $this->target = new NoBaseTarget(); Logger::warn('publishing is disabled.'); @@ -124,17 +126,25 @@ class Publisher $targetScheme = parse_url( $this->project->target_dir,PHP_URL_SCHEME ); - $availableTargets = [ Local::class,Ftp::class,Ftps::class,Fax::class,SFtp::class,Scp::class,Dav::class ]; + $availableTargets = $confPublish->get('targets',[]); - /** @var BaseTarget $target */ foreach($availableTargets as $target ) { - if ( $target::accepts( $targetScheme )) + $className = '\\cms\\generator\\target\\'.$target; + if ( !class_exists($className )) { + Logger::warn('Target '.$target.' is not available, class '.$className.' not found.'); + continue; + } + + /** @var BaseTarget $className */ + $targetObject = new $className( $this->project->target_dir ); + + if ( $targetObject::accepts( $targetScheme )) { - if ( ! $target::isAvailable() ) + if ( ! $targetObject::isAvailable() ) throw new PublisherException('The target "'.$targetScheme.'" is not available.' ); - $this->target = new $target( $this->project->target_dir ); + $this->target = $targetObject; break; } } @@ -142,15 +152,15 @@ class Publisher if ( empty( $this->target ) ) throw new PublisherException('The scheme "'.$targetScheme.'" is not supported.' ); - $this->contentNegotiation = ( $this->project->content_negotiation == '1' ); - $this->cutIndex = ( $this->project->cut_index == '1' ); + $this->target->open(); // Open the connetion to the target. - if ( $confPublish['command']['enable'] ) + $commandConfig = $confPublish->subset('command'); + if ( $commandConfig->is('enable') ) { - if ( $confPublish['command']['per_project'] && !empty($project->cmd_after_publish) ) + if ( $commandConfig->is('per_project') && !empty($project->cmd_after_publish) ) $this->commandAfterPublish = $project->cmd_after_publish; else - $this->commandAfterPublish = @$confPublish['command']['command']; + $this->commandAfterPublish = @$commandConfig->get('command'); } // Im Systemkommando Variablen ersetzen @@ -183,10 +193,16 @@ class Publisher $ausgabe = array(); $rc = false; Logger::debug('Executing system command: '.Logger::sanitizeInput($this->commandAfterPublish) ); - $user = Session::getUser(); - putenv("CMS_USER_NAME=".$user->name ); - putenv("CMS_USER_ID=" .$user->userid); - putenv("CMS_USER_MAIL=".$user->mail ); + + /** @var ModelBase $baseObjectToEnv */ + foreach( ['user' => Session::getUser(), + 'project' => $this->project ] + as $key=> $baseObjectToEnv ) { + + foreach( $baseObjectToEnv->getProperties() as $name=>$property ) + putenv('CMS_'.strtoupper($key).'_'.strtoupper($name).'='.$property ); + + } exec( $this->commandAfterPublish,$ausgabe,$rc ); diff --git a/modules/cms/generator/target/BaseTarget.class.php b/modules/cms/generator/target/BaseTarget.class.php @@ -34,8 +34,6 @@ abstract class BaseTarget implements Target public function __construct( $targetUrl ) { $this->url = new Url( $targetUrl ); - - $this->open(); } diff --git a/modules/cms/model/BaseObject.class.php b/modules/cms/model/BaseObject.class.php @@ -13,10 +13,7 @@ use util\YAML; use template_engine\components\ElseComponent; /** - * Superklasse fuer Objekte im Projektbaum. - * - * Dieses Objekt ist die Oberklasse fuer die Klassen Ordner, Datei, - * Link, Seite usw. + * Base class for all objects in the content tree. * * @author Jan Dankert */ @@ -1793,8 +1790,6 @@ SQL return ""; } - - } diff --git a/modules/configuration/Config.class.php b/modules/configuration/Config.class.php @@ -79,9 +79,10 @@ class Config public function is($name, $default = false) { if (isset($this->config[$name])) - return (bool)$this->config[$name]; + // This filter accepts 'true' and 'yes' for true and 'false' and 'no' for false. + return filter_var( $this->config[$name],FILTER_VALIDATE_BOOLEAN ); else - return $default; + return (bool) $default; }