openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 80a7acf4b072317888f7731b82e46cb116fc7ae4
parent 82f2f8353e48a7c35c0bb5759d9b408d9f250ccc
Author: Jan Dankert <devnull@localhost>
Date:   Sun,  1 Jul 2018 23:22:35 +0200

Embedded-Views werden jetzt in der UI.class verarbeitet und der Dispatcher direkt mit der Aktion-Verarbeitung aufgerufen.

Diffstat:
modules/cms-core/Dispatcher.class.php | 27++++++++++++---------------
modules/cms-ui/UI.class.php | 51++++++++++++++++++++++++++++++++++++++++++++++++++-
modules/cms-ui/themes/default/layout/index.php | 23++++-------------------
3 files changed, 66 insertions(+), 35 deletions(-)

diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -33,23 +33,19 @@ class Dispatcher public $action; public $subaction; - private $isAction; + public $isAction; /** * @return array data for the client */ public function doAction() { - if(!defined('PRODUCTION')) { - - define('PRODUCTION', config('production')); - define('DEVELOPMENT', !PRODUCTION); - } + define('PRODUCTION', config('production')); + define('DEVELOPMENT', !PRODUCTION); // Start the session. All classes should have been loaded up to now. - if(session_status()==PHP_SESSION_NONE && !headers_sent()) - session_start(); + session_start(); global $SESS; $SESS = &$_SESSION; @@ -76,9 +72,7 @@ class Dispatcher $this->checkPostToken(); - if(!defined('FILE_SEP')) - - define('FILE_SEP', $conf['interface']['file_separator']); + define('FILE_SEP', $conf['interface']['file_separator']); // Is this a POST request? $this->isAction = $_SERVER['REQUEST_METHOD'] == 'POST'; @@ -108,7 +102,7 @@ class Dispatcher $this->commitDatabaseTransaction(); if ( DEVELOPMENT ) - Logger::trace('Output' . "\n" . print_r($result, true)); + Logger::trace('Output' . "\n" . print_r($result, true)); // Weitere Variablen anreichern. $result['session'] = array('name' => session_name(), 'id' => session_id(), 'token' => token()); @@ -121,7 +115,7 @@ class Dispatcher Session::close(); // Ablaufzeit für den Inhalt auf aktuelle Zeit setzen. - #header('Expires: ' . substr(date('r', time() - date('Z')), 0, -5) . 'GMT', false); + header('Expires: ' . substr(date('r', time() - date('Z')), 0, -5) . 'GMT', false); return $result; } @@ -268,9 +262,12 @@ class Dispatcher } /** - * @return array + * Aufruf der Action-Methode. + * Diese Methode muss public sein, da sie für Embedded-Actions aus dem UI direkt aufgerufen wird. + * + * @return array Vollständige Rückgabe aller Daten als assoziatives Array */ - private function callActionMethod() + public function callActionMethod() { global $REQ; $actionClassName = ucfirst($this->action) . 'Action'; diff --git a/modules/cms-ui/UI.class.php b/modules/cms-ui/UI.class.php @@ -56,7 +56,30 @@ class UI } } - public static function executeAction( $action, $subaction ) + public static function executeEmbedded($action, $subaction) + { + try { + UI::executeEmbeddedAction($action,$subaction); + + } catch (BadMethodCallException $e) { + // Action-Method does not exist. + return ""; + } catch (ObjectNotFoundException $e) { + Logger::warn("Object not found: " . $e->__toString()); // Nicht so schlimm, da dies bei gelöschten Objekten vorkommen kann. + return DEVELOPMENT ? $e->getMessage() : ""; + } catch (OpenRatException $e) { + Logger::warn( $e->__toString() ); + return DEVELOPMENT ? $e->getMessage() : lang($e->key); + } catch (SecurityException $e) { + Logger::info( $e->getMessage() ); + return DEVELOPMENT ? $e->getMessage() : ""; + } catch (Exception $e) { + Logger::info( $e->getMessage() ); + return DEVELOPMENT ? $e->getMessage() : ""; + } + } + + private static function executeAction( $action, $subaction ) { $dispatcher = new Dispatcher(); @@ -80,6 +103,32 @@ class UI UI::outputTemplate($tplName,$data['output']); } + private static function executeEmbeddedAction( $action, $subaction ) + { + $dispatcher = new Dispatcher(); + + $dispatcher->action = $action; + if(!defined('OR_ACTION')) + define('OR_ACTION', $action); + + $dispatcher->subaction = $subaction; + if(!defined('OR_METHOD')) + define('OR_METHOD', $subaction); + + // Embedded Actions are ALWAYS Queries (means: GET). + $dispatcher->isAction = false; + + $data = $dispatcher->callActionMethod(); + + // The action is able to change its method and action name. + $subaction = $dispatcher->subaction; + $action = $dispatcher->action; + + $tplName = $action . '/' . $subaction; + + UI::outputTemplate($tplName,$data['output']); + } + /** * Executes and outputs a HTML template. * diff --git a/modules/cms-ui/themes/default/layout/index.php b/modules/cms-ui/themes/default/layout/index.php @@ -46,7 +46,7 @@ <a href=""></a> </header> <div class="view-static" data-action="tree" data-method="show"> - <?php echo embedView('tree','show'); ?> + <?php embedView('tree','show'); ?> </div> </nav> @@ -56,7 +56,7 @@ <span class="title"></span> </header> <div class="view" data-method="edit"> - <?php echo embedView('login','login'); ?> + <?php embedView('login','login'); ?> </div> </main> @@ -66,7 +66,7 @@ <a href=""></a> </header> <div class="view" data-method="info"> - <?php echo embedView('login','login'); ?> + <?php embedView('login','login'); ?> </div> </aside> @@ -95,21 +95,6 @@ </html> <?php function embedView( $action, $method ) { - try { - - return cms_ui\UI::executeAction($action,$method); - } - catch (BadMethodCallException $e) { - // Action-Method does not exist. - return "Method dows not exist: ".$method; - } catch (ObjectNotFoundException $e) { - return "Object not found"; - } catch (OpenRatException $e) { - return lang($e->key); - } catch (SecurityException $e) { - return("You are not allowed to execute '".$action.'/'.$method."''."); - } catch (Exception $e) { - return "Hups...: ".$e->__toString(); - } + echo cms_ui\UI::executeEmbedded($action,$method); } ?> \ No newline at end of file