openrat-cms

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

commit 51fcf404034a1d775d281b25a65bdc946b480691
parent a86b477bab2bad3d5d3863657efa148ca3b096ab
Author: Jan Dankert <develop@jandankert.de>
Date:   Wed, 18 Nov 2020 20:23:57 +0100

Cleaning up the UI actions.

Diffstat:
Mmodules/cms/ui/action/IndexAction.class.php | 312-------------------------------------------------------------------------------
Mmodules/cms/ui/action/TitleAction.class.php | 68--------------------------------------------------------------------
Mmodules/cms/ui/action/TreeAction.class.php | 267-------------------------------------------------------------------------------
Mmodules/cms/ui/action/index/IndexManifestAction.class.php | 12+++++++++++-
Mmodules/cms/ui/action/index/IndexShowAction.class.php | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/cms/ui/action/index/IndexThemestyleAction.class.php | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmodules/cms/ui/action/title/TitleAvailableAction.class.php | 27---------------------------
Mmodules/cms/ui/action/title/TitleShowAction.class.php | 4++++
Mmodules/cms/ui/action/tree/TreeBranchAction.class.php | 33+++++++++++++++++++++++++++++++++
Mmodules/cms/ui/action/tree/TreePathAction.class.php | 212+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 433 insertions(+), 675 deletions(-)

diff --git a/modules/cms/ui/action/IndexAction.class.php b/modules/cms/ui/action/IndexAction.class.php @@ -44,318 +44,6 @@ class IndexAction extends Action parent::__construct(); } - - /** - * Getting the website manifest file. - */ - public function manifestView() - { - $user = Session::getUser(); - - if ( $user ) - $this->lastModified( C::subset('config')->get('last_modification_time',time() ) ); - else - $this->lastModified( time() ); - - $style = $this->getUserStyle( $user ); - - $styleConfig = C::Conf()->subset('style-default' ); // default style config - $userStyleConfig = C::subset('style')->subset( $style ); // user style config - - if ( $userStyleConfig->hasContent() ) - $styleConfig->merge( $userStyleConfig ); // Merging user style into default style - else - ; // Unknown style name, we are ignoring this. - - // Theme base color for smartphones colorizing their status bar. - $themeColor = UIUtils::getColorHexCode($styleConfig['title_background_color']); - - - $appName = C::subset(['application'])->get('name',Startup::TITLE); - - $value = array( - 'name' => $appName, - 'description' => $appName, - 'short_name' => 'CMS', - 'display' => 'standalone', - 'orientation' => 'landscape', - 'background_color' => $themeColor, - ); - - header("Content-Type: application/manifest+json"); - $json = new JSON(); - $this->setTemplateVar( 'manifest',$json->encode($value) ); - } - - - - /** - * Show the UI. - */ - public function showView() - { - $this->setContentSecurityPolicy(); - - $user = Session::getUser(); - - // Is a user logged in? - if ( !is_object($user) ) - { - // Lets try an auto login. - $this->tryAutoLogin(); - - $user = Session::getUser(); - } - - $configLastModificationTime = C::subset('config')->get('last_modification_time', 0); - - if ( $user ) - $this->lastModified( max( $user->loginDate, $configLastModificationTime) ); - else - $this->lastModified( $configLastModificationTime ); - - // Theme für den angemeldeten Benuter ermitteln - $style = $this->getUserStyle($user); - - $this->setTemplateVar('style',$style ); - - $userIsLoggedIn = is_object($user); - - // Welche Aktion soll ausgeführt werden? - $action = ''; - $id = 0; - $this->updateStartAction( $action, $id ); - - $this->setTemplateVar('action',$action); - $this->setTemplateVar('id' ,$id ); - - $this->setTemplateVar('scriptLink', $this->getScriptLink() ); - $this->setTemplateVar('styleLink' , $this->getStyleLink() ); - - $this->setTemplateVar('themeStyleLink', Html::url('index','themestyle') ); - $this->setTemplateVar('manifestLink' , Html::url('index','manifest' ) ); - - $styleConfig = C::Conf()->get('style-default',[]); // default style config - $userStyleConfig = C::subset('style')->get( $style,[]); // user style config - - if ( $userStyleConfig ) - $styleConfig = array_merge($styleConfig,$userStyleConfig); // Merging user style into default style - else - ; // Unknown style name, we are ignoring this. - - // Theme base color for smartphones colorizing their status bar. - $this->setTemplateVar('themeColor', UIUtils::getColorHexCode($styleConfig['title_background_color'])); - - $messageOfTheDay = C::subset('login')->get('motd',''); - - if ( $messageOfTheDay ) - $this->addInfoFor( new User(),Messages::MOTD,array('motd' => $messageOfTheDay) ); - - if ( DEVELOPMENT ) - $this->addInfoFor( new User(),Messages::DEVELOPMENT_MODE ); - - $methods = array( - 'edit' => true, - 'preview' => true, - 'info' => true, - ); - - $methodList = array(); - foreach( $methods as $method=>$openByDefault ) - { - $methodList[] = array('name'=>$method,'open'=>$openByDefault); - } - $this->setTemplateVar('methodList', $methodList); - $this->setTemplateVar('favicon_url', C::subset('theme')->get('favicon','modules/cms/ui/themes/default/images/openrat-logo.ico') ); - - $vars = $this->getOutputData(); - $this->setTemplateVar( 'notices',$vars['notices'] ); // will be extracted in the included template file. - $this->setTemplateVar( 'charset','UTF-8' ); - - $app = C::subset('application'); - $appName = $app->get('name' ); - $appOperator = $app->get('operator'); - $this->setTemplateVar( 'defaultTitle', $appName.(($appOperator!=$appName)?' - '.$appOperator:'')); - - $this->setTemplateVar('language',Configuration::subset('language')->get('language_code') ); - } - - - /** - * Gets CSS file for displaying the UI. - * - * @return string - */ - protected function getStyleLink() - { - // Ok, for now there is only 1 CSS file, which contains all UI styles. - return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::STYLE_MINIFIED_FILENAME:Theme::STYLE_FILENAME); - } - - - public function themestyleView() - { - $themeLessFile = Startup::THEMES_DIR . 'default/style/theme/openrat-theme.less'; - $this->lastModified(filemtime($themeLessFile)); - - header('Content-Type: text/css'); - - $this->setTemplateVar('style',$this->getThemeCSS() ); - } - - - /** - * Gets the theme CSS. - * - * @return string - */ - protected function getThemeCSS() - { - // Je Theme die Theme-CSS-Datei ausgeben. - $lessFile = Startup::THEMES_DIR . 'default/style/theme/openrat-theme.less'; - $css = ''; - - - foreach ( C::subset('style')->subsets() as $styleId => $styleConfig) - { - try - { - $styleConfig = C::Conf()->subset('style-default')->merge( $styleConfig ); - - if ( DEVELOPMENT ) - $css .= "\n".'/* Theme: '.$styleId.' */'."\n"; - - $lessVars = array( - 'cms-theme-id' => strtolower($styleId), - 'cms-image-path' => '"'.Startup::THEMES_DIR.'default/images/'.'"', - ); - - foreach ($styleConfig->getConfig() as $styleSetting => $value) - $lessVars['cms-' . strtolower(strtr($styleSetting, '_', '-'))] = $value; - - // we must create a new instance here, because the less parser is buggy when changing vars. - $parser = new Less(array( - 'sourceMap' => DEVELOPMENT, - 'indentation' => DEVELOPMENT?"\t":'', - 'outputSourceFiles' => false, - 'compress' => PRODUCTION - )); - $parser->parseFile($lessFile,basename($lessFile)); - $parser->modifyVars($lessVars); - $css .= $parser->getCss(); - } - catch (Exception $e) - { - Logger::warn( new \RuntimeException("LESS Parser failed on file '$lessFile'.", 0,$e) ); - - // For not confusing the browser we are displaying a CSS with a comment. - if ( DEVELOPMENT ) - $css .= "\n\n/* ERROR!\n LESS Parser failed on file '$lessFile'. Reason: " . $e->__toString() . " */\n\n"; - } - } - - return $css; - } - - - /** - * Gets JS file for displaying the UI. - * - * @return string - */ - protected function getScriptLink() - { - return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::SCRIPT_MINIFIED_FILENAME:Theme::SCRIPT_FILENAME); - } - - - /** - * Ermittelt die erste zu startende Aktion. - * @param $action - * @param $id - */ - protected function updateStartAction(&$action, &$id ) - { - $user = Session::getUser(); - - if ( !is_object($user) ) - { - $action = 'login'; - $id = 0; - return; - } - - - // Die Action im originalen Request hat Priorität. - $params = new RequestParams(); - if ( !empty( $params->action ) ) - { - $action = $params->action; - $id = $params->id; - return; - } - - - $startConfig = Configuration::subset( ['login','start'] ); - // Das zuletzt geänderte Objekt benutzen. - if ( $startConfig->is('start_lastchanged_object',true) ) - { - $objectid = Value::getLastChangedObjectByUserId($user->userid); - - if ( BaseObject::available($objectid)) - { - $object = new BaseObject($objectid); - $object->objectLoad(); - - $action = $object->getType(); - $id = $objectid; - return; - } - } - - // Das einzige Projekt benutzen - if ( $startConfig->is('start_single_project',true) ) - { - $projects = Project::getAllProjects(); - if ( count($projects) == 1 ) { - // Das einzige Projekt sofort starten. - $action = 'project'; - $id = array_keys($projects)[0]; - } - } - - $action = 'projectlist'; - $id = 0; - } - - protected function tryAutoLogin() - { - $username = AuthRunner::getUsername('autologin'); - - if ( $username ) - { - try - { - $user = User::loadWithName( $username,User::AUTH_TYPE_INTERNAL ); - $user->setCurrent(); - // Do not update the login timestamp, because this is a readonly request. - Logger::info('auto-login for user '.$username); - } - catch( ObjectNotFoundException $e ) - { - Logger::warn('Username for autologin does not exist: '.$username); - - // Kein Auto-Login moeglich, die Anmeldemaske anzeigen. - $this->setTemplateVars( array('dialogAction'=>'login','dialogMethod'=>'login')); - } - } - else - { - // Kein Auto-Login moeglich, die Anmeldemaske anzeigen. - $this->setTemplateVars( array('dialogAction'=>'login','dialogMethod'=>'login')); - } - } - /** * @param User $user * @return \configuration\Config|string diff --git a/modules/cms/ui/action/TitleAction.class.php b/modules/cms/ui/action/TitleAction.class.php @@ -37,72 +37,4 @@ use util\Html; class TitleAction extends Action { public $security = Action::SECURITY_GUEST; - - /** - * Fuellen der Variablen und Anzeigen der Titelleiste - */ - public function showView() - { - $this->setTemplateVar('buildinfo',Startup::TITLE.' '.Startup::VERSION.' - build date '.Startup::DATE ); - - $user = Session::getUser(); - - if ( !is_object($user) ) - { - $this->setTemplateVar('isLoggedIn' ,false ); - $this->setTemplateVar('userfullname',\cms\base\Language::lang('NOT_LOGGED_IN') ); - return; // Kein Benutzer angemeldet. - } - - $this->setTemplateVar('isLoggedIn',true ); - - if ( DEVELOPMENT ) { - $db = DB::get(); - $this->setTemplateVar('dbname',$db->conf['name'].(Startup::readonly()?' ('.\cms\base\Language::lang('readonly').')':'')); - $this->setTemplateVar('dbid' ,$db->id); - } - - $this->setTemplateVar('username' ,$user->name ); - $this->setTemplateVar('userfullname',$user->fullname); - - // Urls zum Benutzerprofil und zum Abmelden - //$this->setTemplateVar('profile_url',Html::url( 'profile' )); - //$this->setTemplateVar('logout_url' ,Html::url( 'index','logout' )); - $this->setTemplateVar('isAdmin',$this->userIsAdmin() ); - - if ( Configuration::subset(['interface','session'])->is('auto_extend',true) ) - { - $this->setTemplateVar('ping_url' ,Html::url('title','ping') ); - $this->setTemplateVar('ping_timeout',ini_get('session.gc_maxlifetime')-60 ); - } - } - - - public function historyView() - { - $resultList = array(); - - $history = Session::get('history'); - - if ( is_array($history) ) - { - foreach( array_reverse($history) as $objectid ) - { - $o = new BaseObject( $objectid ); - $o->load(); - $resultList[$objectid] = array(); - $resultList[$objectid]['url'] = Html::url($o->getType(),'',$objectid); - $resultList[$objectid]['type'] = $o->getType(); - $resultList[$objectid]['name'] = $o->name; - $resultList[$objectid]['lastchange_date'] = $o->lastchangeDate; - - if ( $o->desc != '' ) - $resultList[$objectid]['desc'] = $o->desc; - else - $resultList[$objectid]['desc'] = \cms\base\Language::lang('NO_DESCRIPTION_AVAILABLE'); - } - } - - $this->setTemplateVar( 'history',$resultList ); - } } diff --git a/modules/cms/ui/action/TreeAction.class.php b/modules/cms/ui/action/TreeAction.class.php @@ -55,271 +55,4 @@ class TreeAction extends BaseAction parent::__construct(); } - - /** - * Starting the tree. - */ - public function showView() { - - // no data required here. - } - - - /** - * Anzeigen des Baumes fuer asynchrone Anfragen. - */ - public function branchView() - { - - $type = $this->getRequestVar('type'); - - $branch = $this->loadTreeBranch( $type ); - - $this->setTemplateVar( 'branch',$branch ); - } - - - - protected function loadTreeBranch($type ) - { - $tree = new Tree(); - - try - { - $method = new \ReflectionMethod($tree,$type); - if ( $this->hasRequestVar('id')) - $method->invoke($tree, $this->getRequestVar('id') ); - else - $method->invoke($tree); // <== Executing the Action - } - catch (\ReflectionException $re) - { - throw new \LogicException('Treemethod not found: '.$type); - } - - - $branch = array(); - foreach($tree->treeElements as $element ) - { - $branch[] = get_object_vars($element); - } - - return $branch; - } - - - /** - * The path to an object. - */ - public function pathView() - { - $type = $this->getRequestVar('type'); - $id = $this->getRequestVar('id', RequestParams::FILTER_ALPHANUM); - - $result = $this->calculatePath($type, $id); - $this->setTemplateVar('path', $result); - - $name = $this->calculateName($type, $id); - $this->setTemplateVar('actual', $this->pathItem($type, $id, $name)); - } - - - - /** - * The path to an object. - */ - protected function calculatePath($type, $id) { - - switch( $type ) { - - case 'projectlist': - return array(); - - case 'configuration': - return array(); - - case 'project': - return array( - $this->pathItem('projectlist',0) - ); - case 'folder': - case 'link' : - case 'url' : - case 'page' : - case 'file' : - case 'image' : - $o = new BaseObject( $id ); - $o->load(); - - $result= array( - $this->pathItem('projectlist' ), - $this->pathItem('project' , $o->projectid), - ); - - $parents = array_keys( $o->parentObjectFileNames(true) ); - foreach( $parents as $pid ) - { - $f = new Folder($pid); - $f->load(); - $result[] = $this->pathItem('folder' ,$pid,$f->filename ); - } - return $result; - - case 'pageelement' : - - $ids = explode('_',$id); - if ( count($ids) > 1 ) - { - list( $pageid, $elementid ) = $ids; - } - - $p = new Page($pageid); - $p->load(); - - $result= array( - $this->pathItem('projectlist' ), - $this->pathItem('project' , $p->projectid), - ); - - $parents = array_keys( $p->parentObjectFileNames(true ) ); - foreach( $parents as $pid ) { - $f = new Folder($pid); - $f->load(); - $result[] = $this->pathItem('folder' ,$pid,$f->filename ); - } - $result[] = $this->pathItem('page' ,$id,$p->filename ); - return $result; - - case 'userlist': - case 'usergroup': - return array( - //$this->pathItem('usergroup' ,0) - ); - case 'user': - return array( - //$this->pathItem('userandgroups',0), - $this->pathItem('userlist',0) - ); - case 'grouplist': - return array( - //array('type'=>'userandgroups','action'=>'userandgroups','id'=>0) - ); - case 'group': - return array( - //$this->pathItem('userandgroups',0), - $this->pathItem('grouplist' ,0) - ); - - case 'templatelist': - case 'languagelist': - case 'modellist': - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$id) - ); - - case 'template': - $t = new Template( $id ); - $t->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$t->projectid), - $this->pathItem('templatelist',$t->projectid) - ); - - case 'element': - $e = new Element( $id ); - $e->load(); - $t = new Template( $e->templateid ); - $t->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$t->projectid ), - $this->pathItem('templatelist',$t->projectid ), - $this->pathItem('template' ,$t->templateid,$t->name) - ); - - case 'language': - $l = new Language( $id ); - $l->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$l->projectid), - $this->pathItem('languagelist',$l->projectid) - ); - - case 'model': - $m = new Model( $id ); - $m->load(); - - return array( - $this->pathItem('projectlist' ,0 ), - $this->pathItem('project' ,$m->projectid), - $this->pathItem('modellist' ,$m->projectid) - ); - - default: - throw new \InvalidArgumentException('Unknown type: '.$type); - } - } - - - - protected function pathItem($action, $id = 0, $name = '' ) { - return array('type'=>$this->typeToInternal($action),'action'=>$action ,'id'=>$id,'name'=>$name ); - } - - - private function typeToInternal($type) - { - switch( $type) { - - case 'projectlist': - return 'projects'; - - case 'userlist': - return 'users'; - - case 'grouplist': - return 'groups'; - - case 'templatelist': - return 'templates'; - - case 'languagelist': - return 'languages'; - - case 'modellist': - return 'models'; - - default: - return $type; - } - - } - - /** - * @param $type - * @param $id - * @return string - */ - protected function calculateName($type, $id) - { - $o = ModelFactory::create($type, $id); - - if ($o) { - $o->load(); - $name = $o->getName(); - } - else{ - //$name = \cms\base\Language::lang($type); - $name = ''; - } - return $name; - } - - } diff --git a/modules/cms/ui/action/index/IndexManifestAction.class.php b/modules/cms/ui/action/index/IndexManifestAction.class.php @@ -24,7 +24,13 @@ use util\UIUtils; use \util\exception\ObjectNotFoundException; +/** + * Creating the website manifest. + * + * See https://developer.mozilla.org/de/docs/Web/Manifest + */ class IndexManifestAction extends IndexAction implements Method { + public function view() { $user = Session::getUser(); @@ -44,7 +50,7 @@ class IndexManifestAction extends IndexAction implements Method { ; // Unknown style name, we are ignoring this. // Theme base color for smartphones colorizing their status bar. - $themeColor = UIUtils::getColorHexCode($styleConfig['title_background_color']); + $themeColor = UIUtils::getColorHexCode($styleConfig->get('title_background_color','white')); $appName = C::subset(['application'])->get('name',Startup::TITLE); @@ -56,12 +62,16 @@ class IndexManifestAction extends IndexAction implements Method { 'display' => 'standalone', 'orientation' => 'landscape', 'background_color' => $themeColor, + 'theme_color' => $themeColor, + 'start_url' => './', ); header("Content-Type: application/manifest+json"); $json = new JSON(); $this->setTemplateVar( 'manifest',$json->encode($value) ); } + + public function post() { } } diff --git a/modules/cms/ui/action/index/IndexShowAction.class.php b/modules/cms/ui/action/index/IndexShowAction.class.php @@ -23,7 +23,9 @@ use logger\Logger; use util\Less; use \util\exception\ObjectNotFoundException; class IndexShowAction extends IndexAction implements Method { + public function view() { + $this->setContentSecurityPolicy(); $user = Session::getUser(); @@ -109,6 +111,122 @@ class IndexShowAction extends IndexAction implements Method { $this->setTemplateVar('language',C::subset('language')->get('language_code') ); } + + public function post() { } + + + /** + * Gets CSS file for displaying the UI. + * + * @return string + */ + protected function getStyleLink() + { + // Ok, for now there is only 1 CSS file, which contains all UI styles. + return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::STYLE_MINIFIED_FILENAME:Theme::STYLE_FILENAME); + } + + + + /** + * Gets JS file for displaying the UI. + * + * @return string + */ + protected function getScriptLink() + { + return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::SCRIPT_MINIFIED_FILENAME:Theme::SCRIPT_FILENAME); + } + + + /** + * Ermittelt die erste zu startende Aktion. + * @param $action + * @param $id + */ + protected function updateStartAction(&$action, &$id ) + { + $user = Session::getUser(); + + if ( !is_object($user) ) + { + $action = 'login'; + $id = 0; + return; + } + + + // Die Action im originalen Request hat Priorität. + $params = new RequestParams(); + if ( !empty( $params->action ) ) + { + $action = $params->action; + $id = $params->id; + return; + } + + + $startConfig = Configuration::subset( ['login','start'] ); + // Das zuletzt geänderte Objekt benutzen. + if ( $startConfig->is('start_lastchanged_object',true) ) + { + $objectid = Value::getLastChangedObjectByUserId($user->userid); + + if ( BaseObject::available($objectid)) + { + $object = new BaseObject($objectid); + $object->objectLoad(); + + $action = $object->getType(); + $id = $objectid; + return; + } + } + + // Das einzige Projekt benutzen + if ( $startConfig->is('start_single_project',true) ) + { + $projects = Project::getAllProjects(); + if ( count($projects) == 1 ) { + // Das einzige Projekt sofort starten. + $action = 'project'; + $id = array_keys($projects)[0]; + } + } + + $action = 'projectlist'; + $id = 0; + } + + protected function tryAutoLogin() + { + $username = AuthRunner::getUsername('autologin'); + + if ( $username ) + { + try + { + $user = User::loadWithName( $username,User::AUTH_TYPE_INTERNAL ); + $user->setCurrent(); + // Do not update the login timestamp, because this is a readonly request. + Logger::info('auto-login for user '.$username); + } + catch( ObjectNotFoundException $e ) + { + Logger::warn('Username for autologin does not exist: '.$username); + + // Kein Auto-Login moeglich, die Anmeldemaske anzeigen. + $this->setTemplateVars( array('dialogAction'=>'login','dialogMethod'=>'login')); + } + } + else + { + // Kein Auto-Login moeglich, die Anmeldemaske anzeigen. + $this->setTemplateVars( array('dialogAction'=>'login','dialogMethod'=>'login')); + } + } + + } diff --git a/modules/cms/ui/action/index/IndexThemestyleAction.class.php b/modules/cms/ui/action/index/IndexThemestyleAction.class.php @@ -33,4 +33,59 @@ class IndexThemestyleAction extends IndexAction implements Method { } public function post() { } + + + /** + * Gets the theme CSS. + * + * @return string + */ + protected function getThemeCSS() + { + // Je Theme die Theme-CSS-Datei ausgeben. + $lessFile = Startup::THEMES_DIR . 'default/style/theme/openrat-theme.less'; + $css = ''; + + + foreach ( C::subset('style')->subsets() as $styleId => $styleConfig) + { + try + { + $styleConfig = C::Conf()->subset('style-default')->merge( $styleConfig ); + + if ( DEVELOPMENT ) + $css .= "\n".'/* Theme: '.$styleId.' */'."\n"; + + $lessVars = array( + 'cms-theme-id' => strtolower($styleId), + 'cms-image-path' => '"'.Startup::THEMES_DIR.'default/images/'.'"', + ); + + foreach ($styleConfig->getConfig() as $styleSetting => $value) + $lessVars['cms-' . strtolower(strtr($styleSetting, '_', '-'))] = $value; + + // we must create a new instance here, because the less parser is buggy when changing vars. + $parser = new Less(array( + 'sourceMap' => DEVELOPMENT, + 'indentation' => DEVELOPMENT?"\t":'', + 'outputSourceFiles' => false, + 'compress' => PRODUCTION + )); + $parser->parseFile($lessFile,basename($lessFile)); + $parser->modifyVars($lessVars); + $css .= $parser->getCss(); + } + catch (Exception $e) + { + Logger::warn( new \RuntimeException("LESS Parser failed on file '$lessFile'.", 0,$e) ); + + // For not confusing the browser we are displaying a CSS with a comment. + if ( DEVELOPMENT ) + $css .= "\n\n/* ERROR!\n LESS Parser failed on file '$lessFile'. Reason: " . $e->__toString() . " */\n\n"; + } + } + + return $css; + } + } diff --git a/modules/cms/ui/action/title/TitleAvailableAction.class.php b/modules/cms/ui/action/title/TitleAvailableAction.class.php @@ -1,27 +0,0 @@ -<?php -namespace cms\action\base; -use cms\action\BaseAction; -use cms\action\Method; -use cms\ui\action\TitleAction; -use util\ClassName; - -class TitleAvailableAction extends TitleAction implements Method { - public function view() { - - $action = $this->getRequestVar('queryaction'); - - $viewMethods = array_filter( ['pub','prop','history','rights','add','pw','memberships','advanced','changeto','changetemplate','src','size','maintanance','settings','archive','rights','delete','preview'], - function ($methodName) use ($action) { - // Filter existent methods - $className = new ClassName( ucfirst($action).ucfirst($methodName).'Action'); - $className->addNamespace( ['cms']['action'][$action]); - - return $className->exists(); - }); - - $this->setTemplateVar('views', $viewMethods); - } - - public function post() { - } -} diff --git a/modules/cms/ui/action/title/TitleShowAction.class.php b/modules/cms/ui/action/title/TitleShowAction.class.php @@ -9,7 +9,9 @@ use util\Html; use util\Session; class TitleShowAction extends TitleAction implements Method { + public function view() { + $this->setTemplateVar('buildinfo',Startup::TITLE.' '.Startup::VERSION.' - build date '.Startup::DATE ); $user = Session::getUser(); @@ -43,6 +45,8 @@ class TitleShowAction extends TitleAction implements Method { $this->setTemplateVar('ping_timeout',ini_get('session.gc_maxlifetime')-60 ); } } + + public function post() { } } diff --git a/modules/cms/ui/action/tree/TreeBranchAction.class.php b/modules/cms/ui/action/tree/TreeBranchAction.class.php @@ -2,6 +2,8 @@ namespace cms\ui\action\tree; use cms\ui\action\TreeAction; use cms\action\Method; +use util\Tree; + class TreeBranchAction extends TreeAction implements Method { public function view() { @@ -11,6 +13,37 @@ class TreeBranchAction extends TreeAction implements Method { $this->setTemplateVar( 'branch',$branch ); } + + public function post() { } + + + protected function loadTreeBranch($type ) + { + $tree = new Tree(); + + try + { + $method = new \ReflectionMethod($tree,$type); + if ( $this->hasRequestVar('id')) + $method->invoke($tree, $this->getRequestVar('id') ); + else + $method->invoke($tree); // <== Executing the Action + } + catch (\ReflectionException $re) + { + throw new \LogicException('Treemethod not found: '.$type); + } + + + $branch = array(); + foreach($tree->treeElements as $element ) + { + $branch[] = get_object_vars($element); + } + + return $branch; + } + } diff --git a/modules/cms/ui/action/tree/TreePathAction.class.php b/modules/cms/ui/action/tree/TreePathAction.class.php @@ -1,9 +1,22 @@ <?php namespace cms\ui\action\tree; use cms\action\RequestParams; +use cms\model\BaseObject; +use cms\model\Element; +use cms\model\Folder; +use cms\model\Language; +use cms\model\Model; +use cms\model\ModelFactory; +use cms\model\Page; +use cms\model\Template; use cms\ui\action\TreeAction; use cms\action\Method; + +/** + * Calculating a path to an object, normally used for a breadcrumb navigation. + */ class TreePathAction extends TreeAction implements Method { + public function view() { $type = $this->getRequestVar('type'); $id = $this->getRequestVar('id', RequestParams::FILTER_ALPHANUM); @@ -14,6 +27,205 @@ class TreePathAction extends TreeAction implements Method { $name = $this->calculateName($type, $id); $this->setTemplateVar('actual', $this->pathItem($type, $id, $name)); } + + public function post() { } + + + /** + * The path to an object. + */ + protected function calculatePath($type, $id) { + + switch( $type ) { + + case 'projectlist': + return array(); + + case 'configuration': + return array(); + + case 'project': + return array( + $this->pathItem('projectlist',0) + ); + case 'folder': + case 'link' : + case 'url' : + case 'page' : + case 'file' : + case 'image' : + $o = new BaseObject( $id ); + $o->load(); + + $result= array( + $this->pathItem('projectlist' ), + $this->pathItem('project' , $o->projectid), + ); + + $parents = array_keys( $o->parentObjectFileNames(true) ); + foreach( $parents as $pid ) + { + $f = new Folder($pid); + $f->load(); + $result[] = $this->pathItem('folder' ,$pid,$f->filename ); + } + return $result; + + case 'pageelement' : + + $ids = explode('_',$id); + if ( count($ids) > 1 ) + { + list( $pageid, $elementid ) = $ids; + } + + $p = new Page($pageid); + $p->load(); + + $result= array( + $this->pathItem('projectlist' ), + $this->pathItem('project' , $p->projectid), + ); + + $parents = array_keys( $p->parentObjectFileNames(true ) ); + foreach( $parents as $pid ) { + $f = new Folder($pid); + $f->load(); + $result[] = $this->pathItem('folder' ,$pid,$f->filename ); + } + $result[] = $this->pathItem('page' ,$id,$p->filename ); + return $result; + + case 'userlist': + case 'usergroup': + return array( + //$this->pathItem('usergroup' ,0) + ); + case 'user': + return array( + //$this->pathItem('userandgroups',0), + $this->pathItem('userlist',0) + ); + case 'grouplist': + return array( + //array('type'=>'userandgroups','action'=>'userandgroups','id'=>0) + ); + case 'group': + return array( + //$this->pathItem('userandgroups',0), + $this->pathItem('grouplist' ,0) + ); + + case 'templatelist': + case 'languagelist': + case 'modellist': + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$id) + ); + + case 'template': + $t = new Template( $id ); + $t->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$t->projectid), + $this->pathItem('templatelist',$t->projectid) + ); + + case 'element': + $e = new Element( $id ); + $e->load(); + $t = new Template( $e->templateid ); + $t->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$t->projectid ), + $this->pathItem('templatelist',$t->projectid ), + $this->pathItem('template' ,$t->templateid,$t->name) + ); + + case 'language': + $l = new Language( $id ); + $l->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$l->projectid), + $this->pathItem('languagelist',$l->projectid) + ); + + case 'model': + $m = new Model( $id ); + $m->load(); + + return array( + $this->pathItem('projectlist' ,0 ), + $this->pathItem('project' ,$m->projectid), + $this->pathItem('modellist' ,$m->projectid) + ); + + default: + throw new \InvalidArgumentException('Unknown type: '.$type); + } + } + + + protected function pathItem($action, $id = 0, $name = '' ) { + return array('type'=>$this->typeToInternal($action),'action'=>$action ,'id'=>$id,'name'=>$name ); + } + + + private function typeToInternal($type) + { + switch( $type) { + + case 'projectlist': + return 'projects'; + + case 'userlist': + return 'users'; + + case 'grouplist': + return 'groups'; + + case 'templatelist': + return 'templates'; + + case 'languagelist': + return 'languages'; + + case 'modellist': + return 'models'; + + default: + return $type; + } + + } + + /** + * @param $type + * @param $id + * @return string + */ + protected function calculateName($type, $id) + { + $o = ModelFactory::create($type, $id); + + if ($o) { + $o->load(); + $name = $o->getName(); + } + else{ + //$name = \cms\base\Language::lang($type); + $name = ''; + } + return $name; + } + }