From 7625f0ed496dbf1bb3efbb3bd327dbd0fd747af4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 24 May 2008 21:48:19 +0000 Subject: [PATCH] Registration stub added, naming convention applied, support for PHP code (keep it simple!) in templates added --- .gitattributes | 9 +- .../selector/class_ApplicationHelper.php | 2 +- .../selector/class_ApplicationSelector.php | 4 +- application/ship-simu/init.php | 2 +- .../de/{html/home.tpl => code/home.ctp} | 0 .../ship-simu/templates/de/code/register.ctp | 13 ++ .../class_FilePointerNotOpenedException.php | 6 +- ...s_InvalidTemplateVariableNameException.php | 14 +- .../main/class_BaseFrameworkSystem.php | 54 +++++++- inc/classes/main/commands/class_ | 73 +++++++++++ .../commands/web/class_WebHomeCommand.php | 2 +- .../commands/web/class_WebRegisterCommand.php | 121 ++++++++++++++++++ .../classes/class_LocalFileDatabase.php | 12 +- ...ileIOStream.php => class_FileIoStream.php} | 0 .../main/template/class_TemplateEngine.php | 68 ++++++++-- ...eIOHandler.php => class_FileIoHandler.php} | 0 inc/database/lib-local.php | 2 +- inc/file_io.php | 2 +- index.php | 2 +- templates/de/code/emergency_exit.ctp | 2 +- 20 files changed, 346 insertions(+), 42 deletions(-) rename application/ship-simu/templates/de/{html/home.tpl => code/home.ctp} (100%) create mode 100644 application/ship-simu/templates/de/code/register.ctp create mode 100644 inc/classes/main/commands/class_ create mode 100644 inc/classes/main/commands/web/class_WebRegisterCommand.php rename inc/classes/main/io/{class_FileIOStream.php => class_FileIoStream.php} (100%) rename inc/classes/middleware/io/{class_FileIOHandler.php => class_FileIoHandler.php} (100%) diff --git a/.gitattributes b/.gitattributes index 99a5f08..ee51bff 100644 --- a/.gitattributes +++ b/.gitattributes @@ -119,9 +119,10 @@ application/ship-simu/templates/.htaccess -text application/ship-simu/templates/de/.htaccess -text application/ship-simu/templates/de/code/footer.ctp -text application/ship-simu/templates/de/code/header.ctp -text +application/ship-simu/templates/de/code/home.ctp -text +application/ship-simu/templates/de/code/register.ctp -text application/ship-simu/templates/de/code/shipsimu_main.ctp -text application/ship-simu/templates/de/html/.htaccess -text -application/ship-simu/templates/de/html/home.tpl -text application/ship-simu/templates/de/html/nav_advert.tpl -text application/ship-simu/templates/de/html/selector_ship-simu.tpl -text db/.htaccess -text @@ -246,9 +247,11 @@ inc/classes/main/class_ -text inc/classes/main/class_BaseFrameworkSystem.php -text inc/classes/main/class_FrameworkArrayObject.php -text inc/classes/main/commands/.htaccess -text +inc/classes/main/commands/class_ -text inc/classes/main/commands/class_BaseCommand.php -text inc/classes/main/commands/web/.htaccess -text inc/classes/main/commands/web/class_WebHomeCommand.php -text +inc/classes/main/commands/web/class_WebRegisterCommand.php -text inc/classes/main/compressor/.htaccess -text inc/classes/main/compressor/class_Bzip2Compressor.php -text inc/classes/main/compressor/class_GzipCompressor.php -text @@ -281,7 +284,7 @@ inc/classes/main/factories/objects/class_ObjectFactory.php -text inc/classes/main/factories/web/.htaccess -text inc/classes/main/factories/web/class_NewsFactory.php -text inc/classes/main/io/.htaccess -text -inc/classes/main/io/class_FileIOStream.php -text +inc/classes/main/io/class_FileIoStream.php -text inc/classes/main/io/class_FrameworkDirectoryPointer.php -text inc/classes/main/io/class_FrameworkFileInputPointer.php -text inc/classes/main/io/class_FrameworkFileOutputPointer.php -text @@ -310,7 +313,7 @@ inc/classes/middleware/database/class_DatabaseConnection.php -text inc/classes/middleware/debug/.htaccess -text inc/classes/middleware/debug/class_DebugMiddleware.php -text inc/classes/middleware/io/.htaccess -text -inc/classes/middleware/io/class_FileIOHandler.php -text +inc/classes/middleware/io/class_FileIoHandler.php -text inc/config.php -text inc/config/.htaccess -text inc/config/class_FrameworkConfiguration.php -text diff --git a/application/selector/class_ApplicationHelper.php b/application/selector/class_ApplicationHelper.php index 7f721c3..feafd24 100644 --- a/application/selector/class_ApplicationHelper.php +++ b/application/selector/class_ApplicationHelper.php @@ -179,7 +179,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica */ public final function entryPoint () { // Get a prepared instance of ApplicationSelector - $selInstance = ApplicationSelector::createApplicationSelector(LanguageSystem::getInstance(), FileIOHandler::getInstance()); + $selInstance = ApplicationSelector::createApplicationSelector(LanguageSystem::getInstance(), FileIoHandler::getInstance()); // Remove the ignore list from the object $selInstance->removeDirIgnoreList(); diff --git a/application/selector/class_ApplicationSelector.php b/application/selector/class_ApplicationSelector.php index a7f3294..2af2f70 100644 --- a/application/selector/class_ApplicationSelector.php +++ b/application/selector/class_ApplicationSelector.php @@ -80,7 +80,7 @@ class ApplicationSelector extends BaseFrameworkSystem { * @param $fileIOInstance The file I/O instance * @return $selInstance An instance of ApplicationSelector */ - public final static function createApplicationSelector (ManageableLanguage $langInstance, FileIOHandler $fileIOInstance) { + public final static function createApplicationSelector (ManageableLanguage $langInstance, FileIoHandler $fileIOInstance) { // Get a new instance $selInstance = new ApplicationSelector(); @@ -89,7 +89,7 @@ class ApplicationSelector extends BaseFrameworkSystem { // Set language and file I/O instances $selInstance->setLanguageInstance($langInstance); - $selInstance->setFileIOInstance($fileIOInstance); + $selInstance->setFileIoInstance($fileIOInstance); // Return the prepared instance return $selInstance; diff --git a/application/ship-simu/init.php b/application/ship-simu/init.php index 1a3fc08..00df8b6 100644 --- a/application/ship-simu/init.php +++ b/application/ship-simu/init.php @@ -49,7 +49,7 @@ require(PATH . "inc/output.php"); // Initialize file i/o system require(PATH . "inc/file_io.php"); -$app->setFileIOInstance($io); +$app->setFileIoInstance($io); // Include the language sub-system require(PATH . "inc/language.php"); diff --git a/application/ship-simu/templates/de/html/home.tpl b/application/ship-simu/templates/de/code/home.ctp similarity index 100% rename from application/ship-simu/templates/de/html/home.tpl rename to application/ship-simu/templates/de/code/home.ctp diff --git a/application/ship-simu/templates/de/code/register.ctp b/application/ship-simu/templates/de/code/register.ctp new file mode 100644 index 0000000..9c599c2 --- /dev/null +++ b/application/ship-simu/templates/de/code/register.ctp @@ -0,0 +1,13 @@ +
+ Anmeldung bei {?app_full_name?} +
+ +
+
+ + + + + addTextInputForm("username", 10, 255, true); ?> +
+
diff --git a/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php b/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php index 841782a..27fe8d1 100644 --- a/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php +++ b/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php @@ -25,13 +25,13 @@ class FilePointerNotOpenedException extends FrameworkException { /** * The constructor * - * @param $message Message from the exception + * @param $fqfn Full-qualified file name of (maybe) missing file * @param $code Code number for the exception * @return void */ - public function __construct ($path, $code) { + public function __construct ($fqfn, $code) { // Add a message around the missing class - $message = sprintf("Für die Datei %s konnte kein Pointer initialisiert werden. Möglicherweise ist die Datei nicht lesbar oder fehlt!", $path); + $message = sprintf("Not able to initialize a pointer for the file %s. Maybe the file is missing.", $fqfn); // Call parent constructor parent::__construct($message, $code); diff --git a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php index c5cbce4..3f92b37 100644 --- a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php +++ b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php @@ -25,18 +25,18 @@ class InvalidTemplateVariableNameException extends FrameworkException { /** * The constructor * - * @param $class An array holding our informations + * @param $classArray An array holding our informations * @param $code Code number for the exception * @return void */ - public function __construct (BaseFrameworkSystem $class, $code) { + public function __construct (array $classArray, $code) { // Add a message around the missing class - $message = sprintf("[%s:%d] Die im Template %s gefundene Variable %s ist nicht gültig! Gültige Variablennamen sind nur %s.", - $class[0]->__toString(), + $message = sprintf("[%s:%d] The template %s contains an invalid variable called %s. Valid variable names are only %s.", + $classArray[0]->__toString(), $this->getLine(), - basename($class[1]), - $class[2], - $class[3]->readConfig("tpl_valid_var") + basename($classArray[1]), + $classArray[2], + $classArray[3]->readConfig("tpl_valid_var") ); // Call parent constructor diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index f341fc9..c1f216e 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -219,8 +219,50 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final function __call ($methodName, $args) { // Implode all given arguments - $argsString = implode("|", $args); - if (empty($argsString)) $argsString = "NULL"; + $argsString = ""; + if (empty($args)) { + // No arguments + $argsString = "NULL"; + } elseif (is_array($args)) { + // Some arguments are there + foreach ($args as $arg) { + // Check the type + if (is_bool($arg)) { + // Boolean! + if ($arg) $argsString .= "true(bool)"; else $argsString .= "false(bool)"; + } elseif (is_int($arg)) { + // Integer + $argsString .= $arg."(int)"; + } elseif (is_float($arg)) { + // Floating point + $argsString .= $arg."(float)"; + } elseif ($arg instanceof BaseFramework) { + // Own object instance + $argsString .= $arg->__toString()."(Object)"; + } elseif (is_object($arg)) { + // External object + $argsString .= "unknown object(!)"; + } elseif (is_array($arg)) { + // Array + $argsString .= "Array(array)"; + } elseif (is_string($arg)) { + // String + $argsString .= "\"".$arg."\"(string)"; + } else { + // Unknown type (please report!) + $argsString .= $arg."(unknown!)"; + } + + // Add comma + $argsString .= ", "; + } + + // Remove last comma + if (substr($argsString, -2, 1) === ",") $argsString = substr($argsString, 0, -2); + } else { + // Invalid arguments! + $argsString = sprintf("!INVALID:%s!", $args); + } $this->getDebugInstance()->output(sprintf("[%s::%s] Stub! Args: %s", $this->__toString(), @@ -732,7 +774,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @return $fileIOInstance An instance to the file I/O sub-system */ - protected final function getFileIOInstance () { + protected final function getFileIoInstance () { return $this->fileIOInstance; } @@ -742,7 +784,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @param $fileIOInstance An instance to the file I/O sub-system * @return void */ - public final function setFileIOInstance (FileIOHandler $fileIOInstance) { + public final function setFileIoInstance (FileIoHandler $fileIOInstance) { $this->fileIOInstance = $fileIOInstance; } @@ -806,7 +848,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { if ($appInstance->getLanguageInstance() === null) { // Invalid language instance throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER); - } elseif ($appInstance->getFileIOInstance() === null) { + } elseif ($appInstance->getFileIoInstance() === null) { // Invalid language instance throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER); } @@ -816,7 +858,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $eval = sprintf("\$tplEngine = %s::create%s( \"%s\", \$appInstance->getLanguageInstance(), - \$appInstance->getFileIOInstance() + \$appInstance->getFileIoInstance() );", $this->getConfigInstance()->readConfig("tpl_engine"), $this->getConfigInstance()->readConfig("tpl_engine"), diff --git a/inc/classes/main/commands/class_ b/inc/classes/main/commands/class_ new file mode 100644 index 0000000..cbb5b60 --- /dev/null +++ b/inc/classes/main/commands/class_ @@ -0,0 +1,73 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ???Command extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription(""); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function create???Command (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new ???Command(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + } +} + +// [EOF] +?> diff --git a/inc/classes/main/commands/web/class_WebHomeCommand.php b/inc/classes/main/commands/web/class_WebHomeCommand.php index 9629b97..7030bd1 100644 --- a/inc/classes/main/commands/web/class_WebHomeCommand.php +++ b/inc/classes/main/commands/web/class_WebHomeCommand.php @@ -90,7 +90,7 @@ class WebHomeCommand extends BaseCommand implements Commandable { $templateInstance->assignTemplateWithVariable("footer", "footer"); // Load the home template - $templateInstance->loadWebTemplate("home"); + $templateInstance->loadCodeTemplate("home"); // Assign the home template with the master template as a content ... ;) $templateInstance->assignTemplateWithVariable("home", "content"); diff --git a/inc/classes/main/commands/web/class_WebRegisterCommand.php b/inc/classes/main/commands/web/class_WebRegisterCommand.php new file mode 100644 index 0000000..01ba9cd --- /dev/null +++ b/inc/classes/main/commands/web/class_WebRegisterCommand.php @@ -0,0 +1,121 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class WebRegisterCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Anmeldeformular-Command"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function createWebRegisterCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new WebRegisterCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get the application instance + $appInstance = $this->getResolverInstance()->getApplicationInstance(); + + // Prepare a template instance + $templateInstance = $this->prepareTemplateEngine($appInstance); + + // Assign all the application's data with template variables + $templateInstance->assignApplicationData($appInstance); + + // Load the master template + $masterTemplate = $appInstance->getMasterTemplate(); + + // Load header template + $templateInstance->loadCodeTemplate("header"); + + // Compile and assign it with a variable + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("header", "header"); + + // Load footer template + $templateInstance->loadCodeTemplate("footer"); + + // Compile and assign it with a variable + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("footer", "footer"); + + // Load the register template + $templateInstance->loadCodeTemplate("register"); + + // Assign the register template with the master template as a content ... ;) + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("register", "content"); + + // Load the master template + $templateInstance->loadCodeTemplate($masterTemplate); + + // Set title + $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter"))); + if (empty($title)) $title = "Register"; + $templateInstance->assignVariable("title", $title); + + // ... and all variables. This should be merged together in a pattern + // to make things easier. A cache mechanism should be added between + // these two calls to cache compiled templates. + $templateInstance->compileVariables(); + + // Get the content back from the template engine and put it in the response class + $templateInstance->transferToResponse($responseInstance); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/classes/class_LocalFileDatabase.php b/inc/classes/main/database/classes/class_LocalFileDatabase.php index 84babfe..b23dbc5 100644 --- a/inc/classes/main/database/classes/class_LocalFileDatabase.php +++ b/inc/classes/main/database/classes/class_LocalFileDatabase.php @@ -70,7 +70,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * * @param $savePath The local file path string * @param $ioInstance The input/output handler. This - * should be FileIOHandler + * should be FileIoHandler * @return $dbInstance An instance of LocalFileDatabase * @throws SavePathIsEmptyException If the given save path is an * empty string @@ -81,7 +81,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @throws SavePathWriteProtectedException If the save path is write- * protected */ - public final static function createLocalFileDatabase ($savePath, FileIOHandler $ioInstance) { + public final static function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) { // Get an instance $dbInstance = new LocalFileDatabase(); @@ -101,7 +101,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Set save path and IO instance $dbInstance->setSavePath($savePath); - $dbInstance->setFileIOInstance($ioInstance); + $dbInstance->setFileIoInstance($ioInstance); // Return database instance return $dbInstance; @@ -163,7 +163,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Save the file to disc we don't care here if the path is there, // this must be done in later methods. - $this->getFileIOInstance()->saveFile($fqfn, array($this->getCompressorChannel()->getCompressorExtension(), $serialized)); + $this->getFileIoInstance()->saveFile($fqfn, array($this->getCompressorChannel()->getCompressorExtension(), $serialized)); } /** @@ -263,7 +263,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $this->setLastFile($fqfn); // Get instance for file handler - $inputHandler = $this->getFileIOInstance(); + $inputHandler = $this->getFileIoInstance(); // Try to read from it. This makes it sure that the file is // readable and a valid database file @@ -356,7 +356,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend */ public final function getObjectFromCachedData ($uniqueID) { // Get instance for file handler - $inputHandler = $this->getFileIOInstance(); + $inputHandler = $this->getFileIoInstance(); // Get last file's name and contents $fqfn = $this->repairFQFN($this->getLastFile(), $uniqueID); diff --git a/inc/classes/main/io/class_FileIOStream.php b/inc/classes/main/io/class_FileIoStream.php similarity index 100% rename from inc/classes/main/io/class_FileIOStream.php rename to inc/classes/main/io/class_FileIoStream.php diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index 4c15006..f929b8a 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -138,7 +138,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * * @param $basePath The local base path for all templates * @param $langInstance An instance of LanguageSystem (default) - * @param $ioInstance An instance of FileIOHandler (default, middleware!) + * @param $ioInstance An instance of FileIoHandler (default, middleware!) * @return $tplInstance An instance of TemplateEngine * @throws BasePathIsEmptyException If the provided $basePath is empty * @throws InvalidBasePathStringException If $basePath is no string @@ -147,7 +147,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * @throws BasePathReadProtectedException If $basePath is * read-protected */ - public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIOHandler $ioInstance) { + public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) { // Get a new instance $tplInstance = new TemplateEngine(); @@ -177,7 +177,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); - $tplInstance->setFileIOInstance($ioInstance); + $tplInstance->setFileIoInstance($ioInstance); // Set template extensions $tplInstance->setRawTemplateExtension($cfgInstance->readConfig("raw_template_extension")); @@ -548,7 +548,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ private function loadRawTemplateData ($fqfn) { // Get a input/output instance from the middleware - $ioInstance = $this->getFileIOInstance(); + $ioInstance = $this->getFileIoInstance(); // Validate the instance if (is_null($ioInstance)) { @@ -612,13 +612,14 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Initialize all missing variables foreach ($variableMatches[3] as $key=>$var) { // Is the variable name valid? - if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config")) { + // @TODO Find a better way than ignoring our instance variable $this + if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config") && ($variableMatches[1][$key] != "this")) { // Invalid variable name throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR); + } elseif ($variableMatches[1][$key] != "this") { + // Try to assign it, empty strings are being ignored + $this->assignTemplateVariable($variableMatches[1][$key], $var); } - - // Try to assign it, empty strings are being ignored - $this->assignTemplateVariable($variableMatches[1][$key], $var); } } } @@ -990,6 +991,40 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate addslashes($this->getRawTemplateData()) ); + // This loop does remove the backslashes (\) in PHP parameters + // @TODO Make this some nicer... + while (strpos($eval, ""))); + $evalMiddle = stripslashes($evalMiddle); + + // Remove the middle part from right one + $evalRight = substr($evalRight, (strpos($evalRight, "?>") + 2)); + + // And put all together + $eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight); + } + + // Prepare PHP code for eval() command + $eval = str_replace( + "<%php", "\";", + str_replace( + "%>", "\$result = \"", $eval + ) + ); + // Debug message if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", $this->__toString(), @@ -1158,6 +1193,23 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Get the content and set it in the response class $responseInstance->writeToBody($this->getCompiledData()); } + + /** + * Assigns all the application data with template variables + * + * @param $appInstance A manageable application instance + * @return void + */ + public function assignApplicationData (ManageableApplication $appInstance) { + // Get long name and assign it + $this->assignVariable("app_full_name" , $appInstance->getAppName()); + + // Get short name and assign it + $this->assignVariable("app_short_name", $appInstance->getAppShortName()); + + // Get version number and assign it + $this->assignVariable("app_version" , $appInstance->getAppVersion()); + } } // [EOF] diff --git a/inc/classes/middleware/io/class_FileIOHandler.php b/inc/classes/middleware/io/class_FileIoHandler.php similarity index 100% rename from inc/classes/middleware/io/class_FileIOHandler.php rename to inc/classes/middleware/io/class_FileIoHandler.php diff --git a/inc/database/lib-local.php b/inc/database/lib-local.php index a14e7c8..1551156 100644 --- a/inc/database/lib-local.php +++ b/inc/database/lib-local.php @@ -24,7 +24,7 @@ // Zum Testen speichern wir in lokale Dateien (LocalFileDatabase) try { - $layer = LocalFileDatabase::createLocalFileDatabase(PATH . "db/", FileIOHandler::getInstance()); + $layer = LocalFileDatabase::createLocalFileDatabase(PATH . "db/", FileIoHandler::getInstance()); } catch (SavePathIsEmptyException $e) { ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", $e->getMessage() diff --git a/inc/file_io.php b/inc/file_io.php index 18b0cb4..de20bf5 100644 --- a/inc/file_io.php +++ b/inc/file_io.php @@ -25,7 +25,7 @@ */ // Get the instance -$io = FileIOHandler::createFileIOHandler(); +$io = FileIoHandler::createFileIoHandler(); // [EOF] ?> diff --git a/index.php b/index.php index 9cabcb0..1956b02 100644 --- a/index.php +++ b/index.php @@ -68,7 +68,7 @@ class ApplicationEntryPoint { // Get some instances $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine"); $lang = LanguageSystem::getInstance(); - $io = FileIOHandler::getInstance(); + $io = FileIoHandler::getInstance(); // Is the template engine loaded? if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) { diff --git a/templates/de/code/emergency_exit.ctp b/templates/de/code/emergency_exit.ctp index 4cd1cf9..d5c6f90 100644 --- a/templates/de/code/emergency_exit.ctp +++ b/templates/de/code/emergency_exit.ctp @@ -2,7 +2,7 @@ {?header:title="Problem in application framework detected!"?} -{?navigation:nav_row=home;imprint;contact?} +{?navigation?}
$content[message] -- 2.30.2