openrat-cms

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

commit 15ceb9a6f26ca36b952b571965c57f239c262bd2
parent 16e5aa01398f57abfa8fc71577babc284293146e
Author: Jan Dankert <develop@jandankert.de>
Date:   Sun, 10 Nov 2019 21:55:22 +0100

New: Page templates have access to the settings of the node object.

Diffstat:
modules/cms-core/action/ConfigurationAction.class.php | 31+++++++------------------------
modules/cms-core/model/Page.class.php | 8++++++++
modules/util/ArrayUtils.class.php | 19+++++++++++++++++++
3 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/modules/cms-core/action/ConfigurationAction.class.php b/modules/cms-core/action/ConfigurationAction.class.php @@ -59,17 +59,18 @@ class ConfigurationAction extends BaseAction // Language are to much entries unset($conf_cms['language']); + $split = "\xC2\xA0"."\xC2\xA0"."\xC2\xBB"."\xC2\xA0"."\xC2\xA0"; + $conf_cms['system'] = $this->getSystemConfiguration(); - $flatDefaultConfig = $this->flattenArray('',$conf_default); - $flatCMSConfig = $this->flattenArray('',Session::getConfig()); - $flatConfig = $this->flattenArray('',$conf_cms); + $flatDefaultConfig = \ArrayUtils::flattenArray('', $conf_default , $split ); + $flatCMSConfig = \ArrayUtils::flattenArray('', Session::getConfig(), $split ); + $flatConfig = \ArrayUtils::flattenArray('', $conf_cms , $split ); $config = array(); foreach( $flatConfig as $key=>$val ) - { - $config[] = array( 'key'=>$key,'value'=>$val,'class'=>(empty($flatCMSConfig[$key])?'readonly':(isset($flatDefaultConfig[$key]) && $flatDefaultConfig[$key]==$flatConfig[$key]?'default':'changed'))); - } + $config[] = array( 'key'=>$key,'value'=>substr($key,-8)=='password'?'*******************':$val,'class'=>(empty($flatCMSConfig[$key])?'readonly':(isset($flatDefaultConfig[$key]) && $flatDefaultConfig[$key]==$flatConfig[$key]?'default':'changed'))); + $this->setTemplateVar('config',$config ); } @@ -95,24 +96,6 @@ class ConfigurationAction extends BaseAction - private function flattenArray( $prefix,$arr ) - { - $new = array(); - foreach( $arr as $key=>$val) - { - if ( is_array($val) ) - { - $new[$prefix.$key] = ''; - - $splitter = "\xC2\xA0"."\xC2\xA0"."\xC2\xBB"."\xC2\xA0"."\xC2\xA0"; // NBSP+RDQUO+NBSP as UTF-8 - $new += $this->flattenArray($prefix.$key.$splitter,$val); - } - else - $new[$prefix.$key] = $key=='password'?'*******************':$val; - } - return $new; - } - /** * Reads system configuration. * @return array diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php @@ -596,6 +596,12 @@ SQL $data = array(); + // Template should have access to the page properties. + $data += \ArrayUtils::flattenArray('_page.' ,$this->getProperties() ); + // Template should have access to the settings of this node object. + $data += \ArrayUtils::flattenArray('_page.localsettings.',$this->getSettings() ); + $data += \ArrayUtils::flattenArray('_page.settings.' ,$this->getTotalSettings() ); + // No we are collecting the data and are fixing some old stuff. foreach( $elements as $elementId=>$elementName ) @@ -618,6 +624,8 @@ SQL $src = str_replace( '{{->'.$elementId.'}}','',$src ); } + Logger::trace( 'pagedata: '.print_r($data,true) ); + // Now we have collected all data, lets call the template engine: $template = new Mustache(); diff --git a/modules/util/ArrayUtils.class.php b/modules/util/ArrayUtils.class.php @@ -25,4 +25,23 @@ class ArrayUtils return $a; } + + + + public static function flattenArray( $prefix, $arr, $split= '.' ) + { + $new = array(); + foreach( $arr as $key=>$val) + { + if ( is_array($val) ) + { + $new[$prefix.$key] = ''; + + $new += self::flattenArray($prefix.$key.$split, $val, $split ); + } + else + $new[$prefix.$key] = $val; + } + return $new; + } } \ No newline at end of file