File modules/cms/ui/action/index/IndexShowAction.class.php

Last commit: Sat Oct 17 01:14:30 2026 +0200	Jan Dankert	New: Using a structured class for the API-Response. The output for GET-Requests is now without the "output" layer.
1 <?php 2 namespace cms\ui\action\index; 3 use cms\action\Method; 4 use cms\model\User; 5 use cms\ui\action\IndexAction; 6 use cms\ui\themes\ThemeStyle; 7 use language\Messages; 8 use util\Html; 9 use util\Session; 10 use util\UIUtils; 11 use cms\base\Configuration as C; 12 use cms\action\RequestParams; 13 use cms\auth\Auth; 14 use cms\auth\AuthRunner; 15 use cms\base\Configuration; 16 use cms\base\Startup; 17 use cms\model\BaseObject; 18 use cms\model\Project; 19 use cms\model\Value; 20 use cms\ui\themes\Theme; 21 use Exception; 22 use util\json\JSON; 23 use logger\Logger; 24 use util\Less; 25 use \util\exception\ObjectNotFoundException; 26 use cms\base\Language as L; 27 28 29 class IndexShowAction extends IndexAction implements Method { 30 31 public function view() { 32 33 $this->addContentSecurityPolicy(); 34 35 $user = $this->currentUser; 36 37 // Is a user logged in? 38 if ( !is_object($user) ) 39 { 40 // Lets try an auto login. 41 $this->tryAutoLogin(); 42 43 $user = $this->currentUser; 44 } 45 46 $configLastModificationTime = C::subset('config')->get('last_modification_time', 0); 47 48 if ( $user ) 49 $this->lastModified( max( $user->loginDate, $configLastModificationTime) ); 50 else 51 $this->lastModified( $configLastModificationTime ); 52 53 // Theme für den angemeldeten Benuter ermitteln 54 $style = $this->getUserStyle($user); 55 56 $this->setTemplateVar('style',$style ); 57 58 $this->setTemplateVar('scriptLink', $this->getScriptLink() ); 59 $this->setTemplateVar('scriptModuleLink',$this->getScriptModuleLink() ); 60 $this->setTemplateVar('jsExt' ,(PRODUCTION?'.min.js' :'.js' ) ); 61 $this->setTemplateVar('cssExt' ,(PRODUCTION?'.min.css':'.css') ); 62 $this->setTemplateVar('styleLink' , $this->getStyleLink() ); 63 64 $this->setTemplateVar('themeLink' , Html::url('index','theme',0,['output'=>'css'] ) ); 65 $this->setTemplateVar('manifestLink' , Html::url('index','manifest',0,['output'=>'json'] ) ); 66 67 $themeStyle = new ThemeStyle( Configuration::subset('style')->get($style,[]) ); // user style config 68 69 // Theme base color for smartphones colorizing their status bar. 70 $this->setTemplateVar('themeColor', $themeStyle->getThemeColor()); 71 72 $messageOfTheDay = C::subset('login')->get('motd',''); 73 74 $notices = []; 75 if ( $messageOfTheDay ) 76 $notices[] = L::lang(Messages::MOTD,array('motd' => $messageOfTheDay) ); 77 78 if ( DEVELOPMENT ) 79 $notices[] = L::lang(Messages::DEVELOPMENT_MODE ); 80 81 $this->setTemplateVar('notices', $notices ); 82 83 $this->setTemplateVar('favicon_url', C::subset('theme')->get('favicon','modules/cms/ui/themes/default/images/openrat-logo.ico') ); 84 85 $vars = $this->getResponse()->getOutputData(); 86 $this->setTemplateVar( 'notices',$vars['notices'] ); // will be extracted in the included template file. 87 $this->setTemplateVar( 'charset','UTF-8' ); 88 89 $app = C::subset('application'); 90 $appName = $app->get('name' ); 91 $appOperator = $app->get('operator'); 92 $this->setTemplateVar( 'defaultTitle', $appName.(($appOperator!=$appName)?' - '.$appOperator:'')); 93 94 $this->setTemplateVar('language',C::subset('language')->get('language_code') ); 95 } 96 97 98 public function post() { 99 } 100 101 102 /** 103 * Gets CSS file for displaying the UI. 104 * 105 * @return string 106 */ 107 protected function getStyleLink() 108 { 109 // Ok, for now there is only 1 CSS file, which contains all UI styles. 110 return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::STYLE_MINIFIED_FILENAME:Theme::STYLE_FILENAME); 111 } 112 113 114 115 /** 116 * Gets JS file for displaying the UI. 117 * 118 * @return string 119 * @deprecated 120 */ 121 protected function getScriptLink() 122 { 123 return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::SCRIPT_MINIFIED_FILENAME:Theme::SCRIPT_FILENAME); 124 } 125 126 /** 127 * Gets JS file for displaying the UI. 128 * 129 * @return string 130 */ 131 protected function getScriptModuleLink() 132 { 133 return Startup::THEMES_DIR . 'default/script/openrat/init.'.(PRODUCTION?'min.':'').'js'; 134 } 135 136 137 138 139 protected function tryAutoLogin() 140 { 141 $username = AuthRunner::getUsername('autologin'); 142 143 if ( $username ) 144 { 145 try 146 { 147 $user = User::loadWithName( $username,User::AUTH_TYPE_INTERNAL ); 148 $user->setCurrent(); 149 // Do not update the login timestamp, because this is a readonly request. 150 Logger::info('auto-login for user '.$username); 151 } 152 catch( ObjectNotFoundException $e ) 153 { 154 Logger::warn('Username for autologin does not exist: '.$username); 155 } 156 } 157 } 158 159 160 }
Download modules/cms/ui/action/index/IndexShowAction.class.php
History Sat, 17 Oct 2026 01:14:30 +0200 Jan Dankert New: Using a structured class for the API-Response. The output for GET-Requests is now without the "output" layer. Tue, 13 Oct 2026 00:22:21 +0200 Jan Dankert Refactoring: Fixing the flickering UI: Create CSS with dark/light-schemes, so the browser can decide which to use. Thu, 26 Dec 2024 19:53:54 +0100 Jan Dankert The ThemeStyle is now able to mix colors and all colors are now internally hold as RGB; New Group background colors in the UI. Sun, 13 Oct 2024 13:17:32 +0200 Jan Dankert New Minifier for CSS and JS: Leave JS Linebreaks as they are (for better debugging); Exploded CSS files (instead of a combined one), LESS is necessary but should be avoided in the future. Fri, 15 Apr 2022 14:51:22 +0200 dankert Refactoring: User,Config and Database info is now stored in the Request, because so there is no session required for clients which are using Basic Authorization. Sat, 19 Mar 2022 00:09:47 +0100 dankert Refactoring: Outputs are setting their content-type themself. Sun, 13 Feb 2022 23:35:26 +0100 dankert Refactoring: New class "Response" which stores all output information. Sat, 18 Dec 2021 03:47:23 +0100 dankert New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments. Sat, 27 Mar 2021 10:40:59 +0100 Jan Dankert Only generate the actual necessary theme style. Wed, 17 Mar 2021 22:27:33 +0100 Jan Dankert Refactoring: Using ES6-Modules (experimental) Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Wed, 10 Feb 2021 22:04:26 +0100 Jan Dankert Provide the theme configuration through a class. Mon, 8 Feb 2021 23:04:22 +0100 Jan Dankert New: A sidebar with sticky buttons as a shortcut to some methods. Wed, 18 Nov 2020 20:23:57 +0100 Jan Dankert Cleaning up the UI actions. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.