IndexAction.class.php (32880B)
1 <?php 2 3 namespace cms\action; 4 5 use \Auth; 6 use cms\model\BaseObject; 7 use cms\model\Project; 8 use cms\model\User; 9 use cms\model\Value; 10 use Exception; 11 use JSON; 12 use JSqueeze; 13 use Less_Parser; 14 use Logger; 15 use modules\util\UIUtils; 16 use ObjectNotFoundException; 17 use Session; 18 use template_engine\TemplateEngineInfo; 19 20 21 /** 22 * Action-Klasse fuer die Anzeige der Hauptseite. 23 * 24 * @author Jan Dankert 25 * @package openrat.actions 26 */ 27 class IndexAction extends Action 28 { 29 public $security = Action::SECURITY_GUEST; 30 31 32 /** 33 * Konstruktor 34 */ 35 function __construct() 36 { 37 parent::__construct(); 38 } 39 40 41 public function manifestView() 42 { 43 $user = Session::getUser(); 44 45 if ( $user ) 46 $this->lastModified( config('config','last_modification_time') ); 47 else 48 $this->lastModified( time() ); 49 50 $style = $this->getUserStyle( $user ); 51 52 $styleConfig = config('style-default'); // default style config 53 $userStyleConfig = config('style', $style); // user style config 54 55 if (is_array($userStyleConfig)) 56 $styleConfig = array_merge($styleConfig, $userStyleConfig ); // Merging user style into default style 57 else 58 ; // Unknown style name, we are ignoring this. 59 60 // Theme base color for smartphones colorizing their status bar. 61 $themeColor = UIUtils::getColorHexCode($styleConfig['title_background_color']); 62 63 64 65 66 $appName = config('application','name'); 67 68 $value = array( 69 'name' => $appName, 70 'description' => $appName, 71 'short_name' => 'CMS', 72 'display' => 'standalone', 73 'orientation' => 'landscape', 74 "background_color" => $themeColor, 75 ); 76 77 header("Content-Type: application/manifest+json"); 78 79 $this->outputAsJSON( $value ); 80 } 81 82 83 84 /** 85 * Show the UI. 86 */ 87 public function showView() 88 { 89 global $conf; 90 91 $user = Session::getUser(); 92 93 // Is a user logged in? 94 if ( !is_object($user) ) 95 { 96 // Lets try an auto login. 97 $this->tryAutoLogin(); 98 99 $user = Session::getUser(); 100 } 101 102 if ( $user ) 103 $this->lastModified( max( $user->loginDate,config('config','last_modification_time')) ); 104 else 105 $this->lastModified( config('config','last_modification_time') ); 106 107 // Theme für den angemeldeten Benuter ermitteln 108 $style = $this->getUserStyle($user); 109 110 $this->setTemplateVar('style',$style ); 111 112 $userIsLoggedIn = is_object($user); 113 114 // Welche Aktion soll ausgeführt werden? 115 $action = ''; 116 $id = 0; 117 $this->updateStartAction( $action, $id ); 118 119 $this->setTemplateVar('action',$action); 120 $this->setTemplateVar('id' ,$id ); 121 122 $this->setTemplateVar('jsFiles' , $this->getJSFiles() ); 123 $this->setTemplateVar('cssFiles',$this->getCSSFiles() ); 124 125 $styleConfig = config('style-default'); // default style config 126 $userStyleConfig = config('style', $style); // user style config 127 128 if (is_array($userStyleConfig)) 129 $styleConfig = array_merge($styleConfig,$userStyleConfig); // Merging user style into default style 130 else 131 ; // Unknown style name, we are ignoring this. 132 133 // Theme base color for smartphones colorizing their status bar. 134 $this->setTemplateVar('themeColor', UIUtils::getColorHexCode($styleConfig['title_background_color'])); 135 136 $messageOfTheDay = config('login', 'motd'); 137 138 if ( !empty($messageOfTheDay) ) 139 $this->addNotice('user','','MOTD',OR_NOTICE_INFO,array('motd'=>$messageOfTheDay) ); 140 141 if ( DEVELOPMENT ) 142 $this->addNotice('user','','DEVELOPMENT_MODE',OR_NOTICE_INFO ); 143 144 $methods = array( 145 'edit' => true, 146 'preview' => true, 147 'info' => true, 148 ); 149 150 $methodList = array(); 151 foreach( $methods as $method=>$openByDefault ) 152 { 153 $methodList[] = array('name'=>$method,'open'=>$openByDefault); 154 } 155 $this->setTemplateVar('methodList', $methodList); 156 $this->setTemplateVar('favicon_url', Conf()->subset('theme')->get('favicon','modules/cms-ui/themes/default/images/openrat-logo.ico') ); 157 158 // HTML-Datei direkt einbinden. 159 $vars = $this->getOutputData(); 160 $output = $vars['output']; // will be extracted in the included template file. 161 $notices = $vars['notices']; // will be extracted in the included template file. 162 163 require('modules/cms-ui/themes/default/layout/index.php'); 164 exit; 165 } 166 167 168 169 private function getCSSFiles() 170 { 171 $productionCSSFile = OR_THEMES_DIR . 'default/production/combined.min.css'; 172 173 if (PRODUCTION) 174 { 175 return array( 176 $productionCSSFile 177 ); 178 } 179 180 181 $css = array(); 182 183 $styleFiles = \FileUtils::readDir(OR_THEMES_DIR . 'default/style'); 184 foreach( $styleFiles as $styleFile ) { 185 if (substr($styleFile,-5) == '.less' ) 186 $css[] = OR_THEMES_DIR . 'default/style'.'/'.substr($styleFile,0,-5); 187 } 188 189 //$css[] = OR_HTML_MODULES_DIR . 'editor/codemirror/lib/codemirror'; 190 191 // Komponentenbasiertes CSS 192 foreach (TemplateEngineInfo::getComponentList() as $c) 193 { 194 $componentCssFile = OR_HTML_MODULES_DIR . 'template-engine/components/html/' . $c . '/' . $c; 195 if (is_file($componentCssFile . '.less')) 196 $css[] = $componentCssFile; 197 } 198 199 $css[] = OR_HTML_MODULES_DIR . 'editor/simplemde/simplemde'; 200 $css[] = OR_HTML_MODULES_DIR . 'editor/trumbowyg/ui/trumbowyg'; 201 202 $outFiles = array(); 203 $modified = false; 204 foreach ($css as $cssF) 205 { 206 $lessFile = $cssF . '.less'; 207 $cssFile = $cssF . '.css'; 208 $cssMinFile = $cssF . '.min.css'; 209 210 if (! is_file($lessFile) && is_file($cssMinFile)) 211 { 212 // Nur die min.css existiert. Das ist ok. 213 // Aber vielleicht muss die Production-CSS aktualisiert werden. 214 if (filemtime($cssMinFile) > filemtime($productionCSSFile)) { 215 // minifizierte CSS-Version ist neuer als Production-CSS, muss aktualisiert werden. 216 $modified = true; 217 } 218 $outFiles[] = $cssMinFile; 219 } 220 elseif (! is_file($lessFile)) 221 { 222 Logger::warn("Stylesheet not found: $lessFile"); 223 continue; 224 } 225 elseif (! is_file($cssFile) || ! is_writable($cssFile)) 226 { 227 Logger::warn("Stylesheet output file not found or not writable: $cssFile"); 228 continue; 229 } 230 elseif (! is_file($cssMinFile) || ! is_writable($cssMinFile)) 231 { 232 Logger::warn("Stylesheet output file not found or not writable: $cssMinFile"); 233 continue; 234 } 235 else 236 { 237 if (filemtime($lessFile) > filemtime($cssMinFile)) 238 { 239 // LESS-Source wurde geändert, CSS-Version muss aktualisiert werden. 240 $modified = true; 241 242 // Den absoluten Pfad zur LESS-Datei ermitteln. Dieser wird vom LESS-Parser für den korrekten Link 243 // auf die LESS-Datei in der Sourcemap benötigt. 244 $pfx = substr(realpath($lessFile),0,0-strlen(basename($lessFile))); 245 246 $parser = new Less_Parser(array( 247 'sourceMap' => true, 248 'indentation' => ' ', 249 'outputSourceFiles' => false, 250 'sourceMapBasepath' => $pfx 251 )); 252 253 254 $parser->parseFile( ltrim($lessFile,'./') ); 255 $source = $parser->getCss(); 256 257 file_put_contents($cssFile, $source); 258 259 $parser = new Less_Parser(array( 260 'compress' => true, 261 'sourceMap' => false, 262 'indentation' => '' 263 )); 264 $parser->parseFile($lessFile); 265 $source = $parser->getCss(); 266 267 268 file_put_contents($cssMinFile, $source); 269 } 270 271 $outFiles[] = $cssFile; 272 } 273 } 274 275 if ($modified) 276 { 277 if ( !is_writable($productionCSSFile)) 278 { 279 Logger::warn('Development mode, but style file is not writable: '.$productionCSSFile); 280 } 281 else 282 { 283 file_put_contents($productionCSSFile,''); 284 foreach ($css as $cssF) 285 { 286 $cssMinFile = $cssF . '.min.css'; 287 if ( is_file($cssMinFile)) 288 file_put_contents($productionCSSFile,file_get_contents($cssMinFile),FILE_APPEND); 289 } 290 } 291 } 292 293 return $outFiles; 294 } 295 296 297 public function themestyleView() 298 { 299 $themeLessFile = OR_THEMES_DIR . 'default/style/theme/openrat-theme.less'; 300 $this->lastModified(filemtime($themeLessFile)); 301 302 header('Content-Type: text/css'); 303 echo $this->getThemeCSS(); 304 exit; 305 } 306 307 308 309 private function getThemeCSS() 310 { 311 // Je Theme die Theme-CSS-Datei ausgeben. 312 $lessFile = OR_THEMES_DIR . 'default/style/theme/openrat-theme.less'; 313 $css = ''; 314 315 316 foreach (array_keys(config('style')) as $styleId) 317 { 318 try 319 { 320 $parser = new Less_Parser(array( 321 'sourceMap' => DEVELOPMENT, 322 'indentation' => ' ', 323 'outputSourceFiles' => false 324 )); 325 $parser->parseFile($lessFile,basename($lessFile)); 326 327 $styleConfig = array_merge( config('style-default'), config('style', $styleId) ); 328 $lessVars = array( 329 'cms-theme-id' => strtolower($styleId), 330 'cms-image-path' => 'themes/default/images/' 331 ); 332 333 foreach ($styleConfig as $styleSetting => $value) 334 $lessVars['cms-' . strtolower(strtr($styleSetting, '_', '-'))] = $value; 335 $parser->modifyVars($lessVars); 336 $css .= $parser->getCss(); 337 } 338 catch (Exception $e) 339 { 340 $css .= "\n\n/* WARNING!\n LESS Parser failed on file '$lessFile'. Reason: " . $e->__toString() . " */\n\n"; 341 } 342 } 343 344 if (PRODUCTION) 345 { 346 return $css; // Should we minify here? Bandwidth vs. cpu-load. 347 } 348 else 349 { 350 return $css; 351 } 352 } 353 354 355 356 private function getJSFiles() 357 { 358 $productionJSFile = OR_THEMES_DIR . 'default/production/combined.min.js'; 359 360 if (PRODUCTION) 361 { 362 return array( 363 $productionJSFile 364 ); 365 } 366 else 367 { 368 $js = array(); 369 $js[] = OR_THEMES_DIR . 'default/script/jquery'; 370 $js[] = OR_THEMES_DIR . 'default/script/jquery-ui'; 371 //$js[] = OR_THEMES_DIR . 'default/script/jquery.scrollTo'; 372 // $js[] = OR_THEMES_EXT_DIR default/script/jquery.mjs.nestedSortable.js"></script> 373 374 // Jquery-Plugins 375 $js[] = OR_THEMES_DIR . 'default/script/plugin/jquery-plugin-orSearch'; 376 $js[] = OR_THEMES_DIR . 'default/script/plugin/jquery-plugin-orLinkify'; 377 $js[] = OR_THEMES_DIR . 'default/script/plugin/jquery-plugin-orTree'; 378 $js[] = OR_THEMES_DIR . 'default/script/plugin/jquery-plugin-orLoadView'; 379 $js[] = OR_THEMES_DIR . 'default/script/plugin/jquery-plugin-orAutoheight'; 380 $js[] = OR_THEMES_DIR . 'default/script/jquery-qrcode'; 381 $js[] = OR_THEMES_DIR . 'default/script/jquery.hotkeys'; 382 383 // Codemirror Source Editor 384 385 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/lib/codemirror'; 386 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/handlebars/handlebars'; 387 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/smalltalk/smalltalk'; 388 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/php/php'; 389 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/cobol/cobol'; 390 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/haskell/haskell'; 391 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/mathematica/mathematica'; 392 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/pug/pug'; 393 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/livescript/livescript'; 394 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/yaml-frontmatter/yaml-frontmatter'; 395 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/stylus/stylus'; 396 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/markdown/markdown'; 397 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/jsx/jsx'; 398 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/velocity/velocity'; 399 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/fortran/fortran'; 400 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/mirc/mirc'; 401 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/xquery/xquery'; 402 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/elm/elm'; 403 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/vhdl/vhdl'; 404 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/verilog/verilog'; 405 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/spreadsheet/spreadsheet'; 406 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/coffeescript/coffeescript'; 407 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/tiddlywiki/tiddlywiki'; 408 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/mumps/mumps'; 409 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/eiffel/eiffel'; 410 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/webidl/webidl'; 411 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/ebnf/ebnf'; 412 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/http/http'; 413 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/textile/textile'; 414 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/r/r'; 415 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/haml/haml'; 416 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/ecl/ecl'; 417 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/cypher/cypher'; 418 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/sieve/sieve'; 419 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/soy/soy'; 420 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/pig/pig'; 421 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/apl/apl'; 422 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/crystal/crystal'; 423 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/clike/clike'; 424 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/oz/oz'; 425 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/modelica/modelica'; 426 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/gherkin/gherkin'; 427 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/swift/swift'; 428 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/scheme/scheme'; 429 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/idl/idl'; 430 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/yaml/yaml'; 431 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/vue/vue'; 432 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/twig/twig'; 433 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/cmake/cmake'; 434 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/asciiarmor/asciiarmor'; 435 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/pegjs/pegjs'; 436 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/solr/solr'; 437 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/tiki/tiki'; 438 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/slim/slim'; 439 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/puppet/puppet'; 440 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/meta'; 441 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/go/go'; 442 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/commonlisp/commonlisp'; 443 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/rust/rust'; 444 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/powershell/powershell'; 445 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/stex/stex'; 446 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/q/q'; 447 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/htmlembedded/htmlembedded'; 448 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/d/d'; 449 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/protobuf/protobuf'; 450 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/mscgen/mscgen'; 451 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/django/django'; 452 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/toml/toml'; 453 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/yacas/yacas'; 454 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/dockerfile/dockerfile'; 455 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/python/python'; 456 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/vb/vb'; 457 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/octave/octave'; 458 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/tcl/tcl'; 459 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/clojure/clojure'; 460 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/sass/sass'; 461 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/gas/gas'; 462 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/sas/sas'; 463 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/julia/julia'; 464 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/fcl/fcl'; 465 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/tornado/tornado'; 466 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/asterisk/asterisk'; 467 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/sql/sql'; 468 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/gfm/gfm'; 469 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/mllike/mllike'; 470 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/rst/rst'; 471 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/ntriples/ntriples'; 472 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/sparql/sparql'; 473 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/properties/properties'; 474 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/rpm/rpm'; 475 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/htmlmixed/htmlmixed'; 476 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/xml/xml'; 477 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/ttcn-cfg/ttcn-cfg'; 478 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/ttcn/ttcn'; 479 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/z80/z80'; 480 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/brainfuck/brainfuck'; 481 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/forth/forth'; 482 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/nginx/nginx'; 483 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/javascript/javascript'; 484 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/pascal/pascal'; 485 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/haxe/haxe'; 486 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/perl/perl'; 487 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/factor/factor'; 488 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/smarty/smarty'; 489 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/vbscript/vbscript'; 490 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/dylan/dylan'; 491 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/asn.1/asn.1'; 492 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/ruby/ruby'; 493 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/nsis/nsis'; 494 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/css/css'; 495 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/haskell-literate/haskell-literate'; 496 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/mbox/mbox'; 497 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/dtd/dtd'; 498 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/erlang/erlang'; 499 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/turtle/turtle'; 500 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/troff/troff'; 501 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/jinja2/jinja2'; 502 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/diff/diff'; 503 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/dart/dart'; 504 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/shell/shell'; 505 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/lua/lua'; 506 $js[] = OR_HTML_MODULES_DIR . 'editor/codemirror/mode/groovy/groovy'; 507 508 509 $js[] = OR_HTML_MODULES_DIR . 'editor/simplemde/simplemde'; 510 $js[] = OR_HTML_MODULES_DIR . 'editor/trumbowyg/trumbowyg'; 511 512 513 // OpenRat internal JS - als letztes, damit die vorigen bereits geladen sind. 514 $js[] = OR_THEMES_DIR . 'default/script/openrat/init'; 515 $js[] = OR_THEMES_DIR . 'default/script/openrat/view'; 516 $js[] = OR_THEMES_DIR . 'default/script/openrat/form'; 517 $js[] = OR_THEMES_DIR . 'default/script/openrat/workbench'; 518 $js[] = OR_THEMES_DIR . 'default/script/openrat/navigator'; 519 $js[] = OR_THEMES_DIR . 'default/script/openrat/common'; 520 521 // Komponentenbasiertes Javascript 522 foreach ( TemplateEngineInfo::getComponentList() as $c) 523 { 524 $componentJsFile = OR_HTML_MODULES_DIR . '/template-engine/components/html/' . $c . '/' . $c; 525 if (is_file($componentJsFile . '.js')) 526 $js[] = $componentJsFile; 527 } 528 529 530 $outDevJsFiles = array(); 531 $outProJsFiles = array(); 532 $lastModTime = 0; 533 534 foreach ($js as $jsFile) 535 { 536 $jsFileMin = $jsFile . '.min.js'; 537 $jsFileNormal = $jsFile . '.js'; 538 539 if (!is_file($jsFileNormal) && !is_file($jsFileMin)) 540 { 541 Logger::warn("Missing Javascript file: $jsFileNormal"); 542 continue; 543 } 544 elseif (is_file($jsFileNormal) && !is_file($jsFileMin)) 545 { 546 Logger::warn("Missing Min-Javascript file: $jsFileMin"); 547 continue; 548 } 549 elseif (!is_file($jsFileNormal) && is_file($jsFileMin)) 550 { 551 // Nur eine Min-Version existiert. Das ist ok. 552 $outDevJsFiles[] = $jsFileMin; 553 $outProJsFiles[] = $jsFileMin; 554 $modTime = filemtime($jsFileMin); 555 } 556 else 557 { 558 if ( filemtime($jsFileNormal) > filemtime($jsFileMin) ) 559 { 560 if ( is_writable( $jsFileMin) ) 561 { 562 $jz = new JSqueeze(); 563 file_put_contents($jsFileMin, $jz->squeeze(file_get_contents($jsFileNormal))); 564 $modTime = time(); 565 } 566 else 567 Logger::warn("Not writable: " . $jsFileMin); 568 } 569 else 570 { 571 $modTime = filemtime($jsFileMin); 572 } 573 $outDevJsFiles[] = $jsFileNormal; 574 $outProJsFiles[] = $jsFileMin; 575 } 576 $lastModTime = max($lastModTime, $modTime); 577 } 578 579 if ($lastModTime > filemtime($productionJSFile)) 580 { 581 if (! is_writable($productionJSFile)) 582 { 583 Logger::warn("Not writable: " . $productionJSFile); 584 } 585 else 586 { 587 file_put_contents($productionJSFile, ''); // Truncate file 588 foreach ($outProJsFiles as $srcFile) 589 file_put_contents($productionJSFile, "\n/* $srcFile */". file_get_contents($srcFile), FILE_APPEND); 590 } 591 } 592 } 593 594 return $outDevJsFiles; 595 } 596 597 598 private function getColorHexCode($colorName ) { 599 600 $colorName = strtolower($colorName); 601 602 $colors = array( 603 'aliceblue'=>'#f0f8ff', 604 'antiquewhite'=>'#faebd7', 605 'aqua'=>'#00ffff', 606 'aquamarine'=>'#7fffd4', 607 'azure'=>'#f0ffff', 608 'beige'=>'#f5f5dc', 609 'bisque'=>'#ffe4c4', 610 'black'=>'#000000', 611 'blanchedalmond'=>'#ffebcd', 612 'blue'=>'#0000ff', 613 'blueviolet'=>'#8a2be2', 614 'brown'=>'#a52a2a', 615 'burlywood'=>'#deb887', 616 'cadetblue'=>'#5f9ea0', 617 'chartreuse'=>'#7fff00', 618 'chocolate'=>'#d2691e', 619 'coral'=>'#ff7f50', 620 'cornflowerblue'=>'#6495ed', 621 'cornsilk'=>'#fff8dc', 622 'crimson'=>'#dc143c', 623 'cyan'=>'#00ffff', 624 'darkblue'=>'#00008b', 625 'darkcyan'=>'#008b8b', 626 'darkgoldenrod'=>'#b8860b', 627 'darkgray'=>'#a9a9a9', 628 'darkgrey'=>'#a9a9a9', 629 'darkgreen'=>'#006400', 630 'darkkhaki'=>'#bdb76b', 631 'darkmagenta'=>'#8b008b', 632 'darkolivegreen'=>'#556b2f', 633 'darkorange'=>'#ff8c00', 634 'darkorchid'=>'#9932cc', 635 'darkred'=>'#8b0000', 636 'darksalmon'=>'#e9967a', 637 'darkseagreen'=>'#8fbc8f', 638 'darkslateblue'=>'#483d8b', 639 'darkslategray'=>'#2f4f4f', 640 'darkslategrey'=>'#2f4f4f', 641 'darkturquoise'=>'#00ced1', 642 'darkviolet'=>'#9400d3', 643 'deeppink'=>'#ff1493', 644 'deepskyblue'=>'#00bfff', 645 'dimgray'=>'#696969', 646 'dimgrey'=>'#696969', 647 'dodgerblue'=>'#1e90ff', 648 'firebrick'=>'#b22222', 649 'floralwhite'=>'#fffaf0', 650 'forestgreen'=>'#228b22', 651 'fuchsia'=>'#ff00ff', 652 'gainsboro'=>'#dcdcdc', 653 'ghostwhite'=>'#f8f8ff', 654 'gold'=>'#ffd700', 655 'goldenrod'=>'#daa520', 656 'gray'=>'#808080', 657 'grey'=>'#808080', 658 'green'=>'#008000', 659 'greenyellow'=>'#adff2f', 660 'honeydew'=>'#f0fff0', 661 'hotpink'=>'#ff69b4', 662 'indianred'=>'#cd5c5c', 663 'indigo'=>'#4b0082', 664 'ivory'=>'#fffff0', 665 'khaki'=>'#f0e68c', 666 'lavender'=>'#e6e6fa', 667 'lavenderblush'=>'#fff0f5', 668 'lawngreen'=>'#7cfc00', 669 'lemonchiffon'=>'#fffacd', 670 'lightblue'=>'#add8e6', 671 'lightcoral'=>'#f08080', 672 'lightcyan'=>'#e0ffff', 673 'lightgoldenrodyellow'=>'#fafad2', 674 'lightgray'=>'#d3d3d3', 675 'lightgrey'=>'#d3d3d3', 676 'lightgreen'=>'#90ee90', 677 'lightpink'=>'#ffb6c1', 678 'lightsalmon'=>'#ffa07a', 679 'lightseagreen'=>'#20b2aa', 680 'lightskyblue'=>'#87cefa', 681 'lightslategray'=>'#778899', 682 'lightslategrey'=>'#778899', 683 'lightsteelblue'=>'#b0c4de', 684 'lightyellow'=>'#ffffe0', 685 'lime'=>'#00ff00', 686 'limegreen'=>'#32cd32', 687 'linen'=>'#faf0e6', 688 'magenta'=>'#ff00ff', 689 'maroon'=>'#800000', 690 'mediumaquamarine'=>'#66cdaa', 691 'mediumblue'=>'#0000cd', 692 'mediumorchid'=>'#ba55d3', 693 'mediumpurple'=>'#9370d8', 694 'mediumseagreen'=>'#3cb371', 695 'mediumslateblue'=>'#7b68ee', 696 'mediumspringgreen'=>'#00fa9a', 697 'mediumturquoise'=>'#48d1cc', 698 'mediumvioletred'=>'#c71585', 699 'midnightblue'=>'#191970', 700 'mintcream'=>'#f5fffa', 701 'mistyrose'=>'#ffe4e1', 702 'moccasin'=>'#ffe4b5', 703 'navajowhite'=>'#ffdead', 704 'navy'=>'#000080', 705 'oldlace'=>'#fdf5e6', 706 'olive'=>'#808000', 707 'olivedrab'=>'#6b8e23', 708 'orange'=>'#ffa500', 709 'orangered'=>'#ff4500', 710 'orchid'=>'#da70d6', 711 'palegoldenrod'=>'#eee8aa', 712 'palegreen'=>'#98fb98', 713 'paleturquoise'=>'#afeeee', 714 'palevioletred'=>'#d87093', 715 'papayawhip'=>'#ffefd5', 716 'peachpuff'=>'#ffdab9', 717 'peru'=>'#cd853f', 718 'pink'=>'#ffc0cb', 719 'plum'=>'#dda0dd', 720 'powderblue'=>'#b0e0e6', 721 'purple'=>'#800080', 722 'red'=>'#ff0000', 723 'rosybrown'=>'#bc8f8f', 724 'royalblue'=>'#4169e1', 725 'saddlebrown'=>'#8b4513', 726 'salmon'=>'#fa8072', 727 'sandybrown'=>'#f4a460', 728 'seagreen'=>'#2e8b57', 729 'seashell'=>'#fff5ee', 730 'sienna'=>'#a0522d', 731 'silver'=>'#c0c0c0', 732 'skyblue'=>'#87ceeb', 733 'slateblue'=>'#6a5acd', 734 'slategray'=>'#708090', 735 'slategrey'=>'#708090', 736 'snow'=>'#fffafa', 737 'springgreen'=>'#00ff7f', 738 'steelblue'=>'#4682b4', 739 'tan'=>'#d2b48c', 740 'teal'=>'#008080', 741 'thistle'=>'#d8bfd8', 742 'tomato'=>'#ff6347', 743 'turquoise'=>'#40e0d0', 744 'violet'=>'#ee82ee', 745 'wheat'=>'#f5deb3', 746 'white'=>'#ffffff', 747 'whitesmoke'=>'#f5f5f5', 748 'yellow'=>'#ffff00', 749 'yellowgreen'=>'#9acd32' 750 ); 751 752 return isset($colors[$colorName])?$colors[$colorName]:$colorName; 753 } 754 755 756 /** 757 * Ermittelt die erste zu startende Aktion. 758 * @param $action 759 * @param $id 760 */ 761 private function updateStartAction( &$action, &$id ) 762 { 763 $user = Session::getUser(); 764 765 if ( !is_object($user) ) 766 { 767 $action = 'login'; 768 $id = 0; 769 return; 770 } 771 772 773 // Die Action im originalen Request hat Priorität. 774 $params = new RequestParams(); 775 if ( !empty( $params->action ) ) 776 { 777 $action = $params->action; 778 $id = $params->id; 779 return; 780 } 781 782 783 // Das zuletzt geänderte Objekt benutzen. 784 if ( config('login','start','start_lastchanged_object') ) 785 { 786 $objectid = Value::getLastChangedObjectByUserId($user->userid); 787 788 if ( BaseObject::available($objectid)) 789 { 790 $object = new BaseObject($objectid); 791 $object->objectLoad(); 792 793 $action = $object->getType(); 794 $id = $objectid; 795 return; 796 } 797 } 798 799 // Das einzige Projekt benutzen 800 if ( config('login','start','start_single_project') ) 801 { 802 $projects = Project::getAllProjects(); 803 if ( count($projects) == 1 ) { 804 // Das einzige Projekt sofort starten. 805 $action = 'project'; 806 $id = array_keys($projects)[0]; 807 } 808 } 809 810 $action = 'projectlist'; 811 $id = 0; 812 } 813 814 private function tryAutoLogin() 815 { 816 $modules = config('security','autologin','modules'); 817 $username = null; 818 819 foreach( $modules as $module) 820 { 821 Logger::debug( 'Auto-Login module: '.$module ); 822 $moduleClass = $module.'Auth'; 823 $auth = new $moduleClass; 824 /* @type $auth Auth */ 825 try { 826 827 $username = $auth->username(); 828 } 829 catch( Exception $e ) { 830 Logger::warn( 'Error in auth-module '.$module.":\n".$e->__toString() ); 831 // Ignore this and continue with next module. 832 } 833 834 if ( $username ) 835 { 836 Logger::debug('Auto-Login for User '.$username.' with auth-module '.$module); 837 break; // Benutzername gefunden. 838 } 839 } 840 841 if ( $username ) 842 { 843 try 844 { 845 $user = User::loadWithName( $username ); 846 $user->setCurrent(); 847 // Do not update the login timestamp, because this is a readonly request. 848 Logger::info('auto-login for user '.$username); 849 } 850 catch( ObjectNotFoundException $e ) 851 { 852 Logger::warn('Username for autologin does not exist: '.$username); 853 854 // Kein Auto-Login moeglich, die Anmeldemaske anzeigen. 855 $this->setTemplateVars( array('dialogAction'=>'login','dialogMethod'=>'login')); 856 } 857 } 858 else 859 { 860 // Kein Auto-Login moeglich, die Anmeldemaske anzeigen. 861 $this->setTemplateVars( array('dialogAction'=>'login','dialogMethod'=>'login')); 862 } 863 } 864 865 /** 866 * @param User $user 867 * @return \Config|string 868 */ 869 private function getUserStyle( $user ) 870 { 871 // Theme für den angemeldeten Benuter ermitteln 872 if ( $user && isset(config('style')[$user->style])) 873 $style = $user->style; 874 else 875 $style = config('interface', 'style', 'default'); 876 return $style; 877 } 878 879 /** 880 * @param array $output 881 */ 882 protected function outputAsJSON( $output ) 883 { 884 $json = new JSON(); 885 header('Content-Type: application/json'); 886 echo $json->encode($output); 887 exit; 888 } 889 890 } 891 ?>