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

Last commit: Thu Dec 26 19:53:54 2024 +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.
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 class IndexShowAction extends IndexAction implements Method { 27 28 public function view() { 29 30 $this->addContentSecurityPolicy(); 31 32 $user = $this->currentUser; 33 34 // Is a user logged in? 35 if ( !is_object($user) ) 36 { 37 // Lets try an auto login. 38 $this->tryAutoLogin(); 39 40 $user = $this->currentUser; 41 } 42 43 $configLastModificationTime = C::subset('config')->get('last_modification_time', 0); 44 45 if ( $user ) 46 $this->lastModified( max( $user->loginDate, $configLastModificationTime) ); 47 else 48 $this->lastModified( $configLastModificationTime ); 49 50 // Theme für den angemeldeten Benuter ermitteln 51 $style = $this->getUserStyle($user); 52 53 $this->setTemplateVar('style',$style ); 54 55 $this->setTemplateVar('scriptLink', $this->getScriptLink() ); 56 $this->setTemplateVar('scriptModuleLink',$this->getScriptModuleLink() ); 57 $this->setTemplateVar('jsExt' ,(PRODUCTION?'.min.js' :'.js' ) ); 58 $this->setTemplateVar('cssExt' ,(PRODUCTION?'.min.css':'.css') ); 59 $this->setTemplateVar('styleLink' , $this->getStyleLink() ); 60 61 $this->setTemplateVar('themeStyleLink', Html::url('index','themestyle',0,['style'=>$style]) ); 62 $this->setTemplateVar('manifestLink' , Html::url('index','manifest',0,['output'=>'json'] ) ); 63 64 $themeStyle = new ThemeStyle( Configuration::subset('style')->get($style,[]) ); // user style config 65 66 // Theme base color for smartphones colorizing their status bar. 67 $this->setTemplateVar('themeColor', $themeStyle->getThemeColor()); 68 69 $messageOfTheDay = C::subset('login')->get('motd',''); 70 71 if ( $messageOfTheDay ) 72 $this->addInfoFor( new User(),Messages::MOTD,array('motd' => $messageOfTheDay) ); 73 74 if ( DEVELOPMENT ) 75 $this->addInfoFor( new User(),Messages::DEVELOPMENT_MODE ); 76 77 $this->setTemplateVar('favicon_url', C::subset('theme')->get('favicon','modules/cms/ui/themes/default/images/openrat-logo.ico') ); 78 79 $vars = $this->getResponse()->getOutputData(); 80 $this->setTemplateVar( 'notices',$vars['notices'] ); // will be extracted in the included template file. 81 $this->setTemplateVar( 'charset','UTF-8' ); 82 83 $app = C::subset('application'); 84 $appName = $app->get('name' ); 85 $appOperator = $app->get('operator'); 86 $this->setTemplateVar( 'defaultTitle', $appName.(($appOperator!=$appName)?' - '.$appOperator:'')); 87 88 $this->setTemplateVar('language',C::subset('language')->get('language_code') ); 89 } 90 91 92 public function post() { 93 } 94 95 96 /** 97 * Gets CSS file for displaying the UI. 98 * 99 * @return string 100 */ 101 protected function getStyleLink() 102 { 103 // Ok, for now there is only 1 CSS file, which contains all UI styles. 104 return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::STYLE_MINIFIED_FILENAME:Theme::STYLE_FILENAME); 105 } 106 107 108 109 /** 110 * Gets JS file for displaying the UI. 111 * 112 * @return string 113 * @deprecated 114 */ 115 protected function getScriptLink() 116 { 117 return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::SCRIPT_MINIFIED_FILENAME:Theme::SCRIPT_FILENAME); 118 } 119 120 /** 121 * Gets JS file for displaying the UI. 122 * 123 * @return string 124 */ 125 protected function getScriptModuleLink() 126 { 127 return Startup::THEMES_DIR . 'default/script/openrat/init.'.(PRODUCTION?'min.':'').'js'; 128 } 129 130 131 132 133 protected function tryAutoLogin() 134 { 135 $username = AuthRunner::getUsername('autologin'); 136 137 if ( $username ) 138 { 139 try 140 { 141 $user = User::loadWithName( $username,User::AUTH_TYPE_INTERNAL ); 142 $user->setCurrent(); 143 // Do not update the login timestamp, because this is a readonly request. 144 Logger::info('auto-login for user '.$username); 145 } 146 catch( ObjectNotFoundException $e ) 147 { 148 Logger::warn('Username for autologin does not exist: '.$username); 149 } 150 } 151 } 152 153 154 }
Download modules/cms/ui/action/index/IndexShowAction.class.php
History 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.