From c42b8268dcbbfb501fc7924fbf57316a83e1d5a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 31 May 2008 11:13:28 +0000 Subject: [PATCH] Code merge from latest ship-simu code --- .gitattributes | 32 + .../mxchange/class_ApplicationHelper.php | 32 +- inc/classes/exceptions/helper/.htaccess | 1 + .../helper/class_FormClosedException.php | 47 ++ .../helper/class_FormGroupClosedException.php | 46 ++ .../helper/class_FormOpenedException.php | 47 ++ .../helper/class_InvalidFormNameException.php | 45 ++ .../class_FilePointerNotOpenedException.php | 12 +- ...s_InvalidTemplateVariableNameException.php | 23 +- inc/classes/exceptions/user/.htaccess | 1 + .../user/class_UsernameMissingException.php | 46 ++ .../class_ManageableApplication.php | 22 +- .../interfaces/commands/class_Commandable.php | 2 +- inc/classes/interfaces/filter/.htaccess | 1 + .../interfaces/filter/class_Filterable.php | 36 ++ .../interfaces/request/class_Requestable.php | 14 +- .../resolver/class_ControllerResolver.php | 2 +- .../response/class_Responseable.php | 9 + inc/classes/interfaces/user/.htaccess | 1 + .../interfaces/user/class_ManageableUser.php | 28 + .../main/class_BaseFrameworkSystem.php | 145 ++++- .../main/class_FrameworkArrayObject.php | 10 - inc/classes/main/commands/class_ | 73 +++ .../commands/web/class_WebDoFormCommand.php | 77 +++ .../commands/web/class_WebHomeCommand.php | 10 +- .../commands/web/class_WebRegisterCommand.php | 121 ++++ .../main/compressor/class_Bzip2Compressor.php | 2 +- .../main/compressor/class_GzipCompressor.php | 2 +- .../main/compressor/class_NullCompressor.php | 2 +- .../main/console/class_ConsoleTools.php | 14 +- .../main/controller/class_BaseController.php | 89 ++- .../default/class_WebDefaultController.php | 27 +- .../class_WebDefaultNewsController.php | 40 +- inc/classes/main/controller/form/.htaccess | 1 + .../form/class_WebDoFormController.php | 94 +++ .../classes/class_LocalFileDatabase.php | 14 +- .../main/debug/class_DebugConsoleOutput.php | 14 +- .../main/debug/class_DebugErrorLogOutput.php | 14 +- .../main/debug/class_DebugWebOutput.php | 14 +- .../main/extended/class_ObjectLimits.php | 14 +- .../extended/class_SerializationContainer.php | 2 +- .../factories/objects/class_ObjectFactory.php | 2 +- .../factories/web/class_WebNewsFactory.php | 117 ++++ inc/classes/main/filter/.htaccess | 1 + inc/classes/main/filter/class_ | 72 +++ .../filter/class_AbstractFilterDecorator.php | 87 +++ inc/classes/main/filter/class_FilterChain.php | 93 +++ inc/classes/main/filter/validator/.htaccess | 1 + .../class_UserNameValidatorFilter.php | 131 ++++ inc/classes/main/helper/.htaccess | 1 + inc/classes/main/helper/class_ | 53 ++ inc/classes/main/helper/class_BaseHelper.php | 90 +++ inc/classes/main/helper/web/.htaccess | 1 + .../main/helper/web/class_WebFormHelper.php | 589 ++++++++++++++++++ inc/classes/main/io/class_FileIOStream.php | 4 +- inc/classes/main/io/class_FileIoStream.php | 232 +++++++ .../io/class_FrameworkDirectoryPointer.php | 14 +- .../io/class_FrameworkFileInputPointer.php | 14 +- .../io/class_FrameworkFileOutputPointer.php | 14 +- .../main/language/class_LanguageSystem.php | 71 ++- .../main/output/class_ConsoleOutput.php | 16 +- inc/classes/main/output/class_WebOutput.php | 14 +- .../main/request/class_HttpRequest.php | 37 +- .../main/resolver/class_BaseResolver.php | 36 +- .../resolver/web/class_WebCommandResolver.php | 63 +- .../web/class_WebControllerResolver.php | 36 +- .../main/response/class_HttpResponse.php | 78 ++- .../main/template/class_TemplateEngine.php | 160 +++-- inc/classes/main/user/.htaccess | 1 + inc/classes/main/user/class_User.php | 103 +++ .../middleware/class_BaseMiddleware.php | 14 +- .../compressor/class_CompressorChannel.php | 12 +- .../database/class_DatabaseConnection.php | 4 +- .../debug/class_DebugMiddleware.php | 4 +- .../middleware/io/class_FileIOHandler.php | 4 +- .../middleware/io/class_FileIoHandler.php | 181 ++++++ inc/config.php | 87 +-- inc/config/class_FrameworkConfiguration.php | 10 +- inc/config/config-hubmaster.php | 40 +- inc/database.php | 6 +- inc/database/lib-local.php | 18 +- inc/file_io.php | 8 +- inc/includes.php | 10 +- inc/language.php | 2 +- inc/loader/class_ClassLoader.php | 16 +- inc/output.php | 2 +- inc/selector.php | 28 +- templates/de/code/emergency_exit.ctp | 9 + templates/de/code/header.ctp | 4 +- 89 files changed, 3362 insertions(+), 454 deletions(-) create mode 100644 inc/classes/exceptions/helper/.htaccess create mode 100644 inc/classes/exceptions/helper/class_FormClosedException.php create mode 100644 inc/classes/exceptions/helper/class_FormGroupClosedException.php create mode 100644 inc/classes/exceptions/helper/class_FormOpenedException.php create mode 100644 inc/classes/exceptions/helper/class_InvalidFormNameException.php create mode 100644 inc/classes/exceptions/user/.htaccess create mode 100644 inc/classes/exceptions/user/class_UsernameMissingException.php create mode 100644 inc/classes/interfaces/filter/.htaccess create mode 100644 inc/classes/interfaces/filter/class_Filterable.php create mode 100644 inc/classes/interfaces/user/.htaccess create mode 100644 inc/classes/interfaces/user/class_ManageableUser.php create mode 100644 inc/classes/main/commands/class_ create mode 100644 inc/classes/main/commands/web/class_WebDoFormCommand.php create mode 100644 inc/classes/main/commands/web/class_WebRegisterCommand.php create mode 100644 inc/classes/main/controller/form/.htaccess create mode 100644 inc/classes/main/controller/form/class_WebDoFormController.php create mode 100644 inc/classes/main/factories/web/class_WebNewsFactory.php create mode 100644 inc/classes/main/filter/.htaccess create mode 100644 inc/classes/main/filter/class_ create mode 100644 inc/classes/main/filter/class_AbstractFilterDecorator.php create mode 100644 inc/classes/main/filter/class_FilterChain.php create mode 100644 inc/classes/main/filter/validator/.htaccess create mode 100644 inc/classes/main/filter/validator/class_UserNameValidatorFilter.php create mode 100644 inc/classes/main/helper/.htaccess create mode 100644 inc/classes/main/helper/class_ create mode 100644 inc/classes/main/helper/class_BaseHelper.php create mode 100644 inc/classes/main/helper/web/.htaccess create mode 100644 inc/classes/main/helper/web/class_WebFormHelper.php create mode 100644 inc/classes/main/io/class_FileIoStream.php create mode 100644 inc/classes/main/user/.htaccess create mode 100644 inc/classes/main/user/class_User.php create mode 100644 inc/classes/middleware/io/class_FileIoHandler.php diff --git a/.gitattributes b/.gitattributes index 89c91266dc..9a65b24927 100644 --- a/.gitattributes +++ b/.gitattributes @@ -40,6 +40,11 @@ inc/classes/exceptions/database/local_file/class_SavePathIsEmptyException.php -t inc/classes/exceptions/database/local_file/class_SavePathIsNoDirectoryException.php -text inc/classes/exceptions/database/local_file/class_SavePathReadProtectedException.php -text inc/classes/exceptions/database/local_file/class_SavePathWriteProtectedException.php -text +inc/classes/exceptions/helper/.htaccess -text +inc/classes/exceptions/helper/class_FormClosedException.php -text +inc/classes/exceptions/helper/class_FormGroupClosedException.php -text +inc/classes/exceptions/helper/class_FormOpenedException.php -text +inc/classes/exceptions/helper/class_InvalidFormNameException.php -text inc/classes/exceptions/io/.htaccess -text inc/classes/exceptions/io/class_DirPointerNotOpenedException.php -text inc/classes/exceptions/io/class_FilePointerNotOpenedException.php -text @@ -89,6 +94,8 @@ inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php - inc/classes/exceptions/template/class_UnexpectedTemplateTypeException.php -text inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -text inc/classes/exceptions/template/class_ViewHelperNotFoundException.php -text +inc/classes/exceptions/user/.htaccess -text +inc/classes/exceptions/user/class_UsernameMissingException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/application/.htaccess -text inc/classes/interfaces/application/class_ManageableApplication.php -text @@ -110,6 +117,8 @@ inc/classes/interfaces/debug/.htaccess -text inc/classes/interfaces/debug/class_Debugger.php -text inc/classes/interfaces/extended/.htaccess -text inc/classes/interfaces/extended/class_LimitableObject.php -text +inc/classes/interfaces/filter/.htaccess -text +inc/classes/interfaces/filter/class_Filterable.php -text inc/classes/interfaces/io/.htaccess -text inc/classes/interfaces/io/class_Streamable.php -text inc/classes/interfaces/io/file/.htaccess -text @@ -129,14 +138,19 @@ inc/classes/interfaces/response/class_Responseable.php -text inc/classes/interfaces/template/.htaccess -text inc/classes/interfaces/template/class_CompileableTemplate.php -text inc/classes/interfaces/template/view/class_ViewHelper.php -text +inc/classes/interfaces/user/.htaccess -text +inc/classes/interfaces/user/class_ManageableUser.php -text inc/classes/main/.htaccess -text 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_WebDoFormCommand.php -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 @@ -149,6 +163,8 @@ inc/classes/main/controller/class_BaseController.php -text inc/classes/main/controller/default/.htaccess -text inc/classes/main/controller/default/class_WebDefaultController.php -text inc/classes/main/controller/default/class_WebDefaultNewsController.php -text +inc/classes/main/controller/form/.htaccess -text +inc/classes/main/controller/form/class_WebDoFormController.php -text inc/classes/main/controller/registration/.htaccess -text inc/classes/main/controller/registration/class_DefaultRegistrationController.php -text inc/classes/main/database/.htaccess -text @@ -168,8 +184,21 @@ inc/classes/main/factories/objects/.htaccess -text 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/factories/web/class_WebNewsFactory.php -text +inc/classes/main/filter/.htaccess -text +inc/classes/main/filter/class_ -text +inc/classes/main/filter/class_AbstractFilterDecorator.php -text +inc/classes/main/filter/class_FilterChain.php -text +inc/classes/main/filter/validator/.htaccess -text +inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text +inc/classes/main/helper/.htaccess -text +inc/classes/main/helper/class_ -text +inc/classes/main/helper/class_BaseHelper.php -text +inc/classes/main/helper/web/.htaccess -text +inc/classes/main/helper/web/class_WebFormHelper.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 @@ -189,6 +218,8 @@ inc/classes/main/response/.htaccess -text inc/classes/main/response/class_HttpResponse.php -text inc/classes/main/template/.htaccess -text inc/classes/main/template/class_TemplateEngine.php -text +inc/classes/main/user/.htaccess -text +inc/classes/main/user/class_User.php -text inc/classes/middleware/.htaccess -text inc/classes/middleware/class_BaseMiddleware.php -text inc/classes/middleware/compressor/.htaccess -text @@ -199,6 +230,7 @@ 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/mxchange/class_ApplicationHelper.php b/application/mxchange/class_ApplicationHelper.php index 435d343ed5..28d71b7d42 100644 --- a/application/mxchange/class_ApplicationHelper.php +++ b/application/mxchange/class_ApplicationHelper.php @@ -60,14 +60,19 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica */ private static $thisInstance = null; + /** + * Master template + */ + private $masterTemplate = "mxchange_main"; + /** * Private constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description $this->setObjectDescription("Application-Helper"); @@ -166,6 +171,29 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // Not yet implemented trigger_error(__METHOD__.": Not yet implemented!"); } + + /** + * Getter for master template name + * + * @return $masterTemplate Name of the master template + */ + public final function getMasterTemplate () { + return $this->masterTemplate; + } + + /** + * Handle the indexed array of fatal messages and puts them out in an + * acceptable fasion + * + * @param $messageList An array of fatal messages + * @return void + */ + public function handleFatalMessages (array $messageList) { + // Walk through all messages + foreach ($messageList as $message) { + die("MSG:".$message); + } + } } // [EOF] diff --git a/inc/classes/exceptions/helper/.htaccess b/inc/classes/exceptions/helper/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/exceptions/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/helper/class_FormClosedException.php b/inc/classes/exceptions/helper/class_FormClosedException.php new file mode 100644 index 0000000000..93909118ec --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormClosedException.php @@ -0,0 +1,47 @@ + + * @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 FormClosedException extends FrameworkException { + /** + * The constructor + * + * @param $classArray Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Could not add form element %s because form is closed.", + $classArray[0]->__toString(), + $this->getLine(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_FormGroupClosedException.php b/inc/classes/exceptions/helper/class_FormGroupClosedException.php new file mode 100644 index 0000000000..608228de94 --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormGroupClosedException.php @@ -0,0 +1,46 @@ + + * @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 FormGroupClosedException extends FrameworkException { + /** + * The constructor + * + * @param $classArray Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Could not add sub group %s because no form group has been opened before.", + $classArray[0]->__toString(), + $this->getLine(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_FormOpenedException.php b/inc/classes/exceptions/helper/class_FormOpenedException.php new file mode 100644 index 0000000000..e964c7c33e --- /dev/null +++ b/inc/classes/exceptions/helper/class_FormOpenedException.php @@ -0,0 +1,47 @@ + + * @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 FormOpenedException extends FrameworkException { + /** + * The constructor + * + * @param $class Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (BaseFrameworkSystem $class, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Form is not yet closed. Close it with method %s::addFormTag() and add no parameters.", + $class->__toString(), + $this->getLine(), + $class->__toString() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_InvalidFormNameException.php b/inc/classes/exceptions/helper/class_InvalidFormNameException.php new file mode 100644 index 0000000000..85b51371c7 --- /dev/null +++ b/inc/classes/exceptions/helper/class_InvalidFormNameException.php @@ -0,0 +1,45 @@ + + * @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 InvalidFormNameException extends FrameworkException { + /** + * The constructor + * + * @param $class Class throwing the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (BaseFrameworkSystem $class, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Form name not set.", + $class->__toString(), + $this->getLine() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php b/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php index 9c7a8a8914..27fe8d1d40 100644 --- a/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php +++ b/inc/classes/exceptions/io/class_FilePointerNotOpenedException.php @@ -3,10 +3,10 @@ * An exception thrown when a file pointer is not opened * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,19 +19,19 @@ * 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 . + * along with this program. If not, see . */ 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 8a3151cc0d..01fd09fa43 100644 --- a/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php +++ b/inc/classes/exceptions/template/class_InvalidTemplateVariableNameException.php @@ -3,10 +3,11 @@ * An exception thrown when a template variable name is invalid * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @link http://www.ship-simu.org + * @deprecated * * 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 @@ -19,24 +20,24 @@ * 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 . + * along with this program. If not, see . */ class InvalidTemplateVariableNameException extends FrameworkException { /** * The constructor * - * @param $class An array holding our informations - * @param $code Code number for the exception + * @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/exceptions/user/.htaccess b/inc/classes/exceptions/user/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/exceptions/user/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/user/class_UsernameMissingException.php b/inc/classes/exceptions/user/class_UsernameMissingException.php new file mode 100644 index 0000000000..8016cf3767 --- /dev/null +++ b/inc/classes/exceptions/user/class_UsernameMissingException.php @@ -0,0 +1,46 @@ + + * @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 UsernameMissingException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray The non-optional message for the exception + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code = 0) { + // Create the message + $message = sprintf("[%s:%d] Username %s was not found.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Make sure everything is assigned properly + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/application/class_ManageableApplication.php b/inc/classes/interfaces/application/class_ManageableApplication.php index f342a0a7ca..d1d7267aad 100644 --- a/inc/classes/interfaces/application/class_ManageableApplication.php +++ b/inc/classes/interfaces/application/class_ManageableApplication.php @@ -8,10 +8,10 @@ * - And many more... * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -24,7 +24,7 @@ * 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 . + * along with this program. If not, see . */ interface ManageableApplication extends FrameworkInterface { /** @@ -71,12 +71,28 @@ interface ManageableApplication extends FrameworkInterface { */ function setAppShortName ($shortName); + /** + * Getter for master template name + * + * @return $masterTemplate Name of the master template + */ + function getMasterTemplate (); + /** * Launches the application * * @return void */ function entryPoint (); + + /** + * Handle the indexed array of fatal messages and puts them out in an + * acceptable fasion + * + * @param $messageList An array of fatal messages + * @return void + */ + function handleFatalMessages (array $messageList); } // [EOF] diff --git a/inc/classes/interfaces/commands/class_Commandable.php b/inc/classes/interfaces/commands/class_Commandable.php index 4b3eaba9f8..8b3392df81 100644 --- a/inc/classes/interfaces/commands/class_Commandable.php +++ b/inc/classes/interfaces/commands/class_Commandable.php @@ -23,7 +23,7 @@ */ interface Commandable extends FrameworkInterface { /** - * Executes the given command with given request and response objects + * Executes the 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 diff --git a/inc/classes/interfaces/filter/.htaccess b/inc/classes/interfaces/filter/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/interfaces/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/filter/class_Filterable.php b/inc/classes/interfaces/filter/class_Filterable.php new file mode 100644 index 0000000000..bc4bb30754 --- /dev/null +++ b/inc/classes/interfaces/filter/class_Filterable.php @@ -0,0 +1,36 @@ + + * @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 . + */ +interface Filterable extends FrameworkInterface { + /** + * Executes the filter 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 + */ + function execute (Requestable $requestInstance, Responseable $responseInstance); +} + +// +?> diff --git a/inc/classes/interfaces/request/class_Requestable.php b/inc/classes/interfaces/request/class_Requestable.php index 7ef0f9a399..a7b39bf581 100644 --- a/inc/classes/interfaces/request/class_Requestable.php +++ b/inc/classes/interfaces/request/class_Requestable.php @@ -3,10 +3,10 @@ * An interface for requests * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,7 +19,7 @@ * 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 . + * along with this program. If not, see . */ interface Requestable extends FrameworkInterface { /** @@ -62,6 +62,14 @@ interface Requestable extends FrameworkInterface { * @return $headerValue Value of the header or 'null' if not found */ function getHeader ($headerName); + + /** + * Sets wether the request was valid (default: true) + * + * @param $isValid Wether the request is valid + * @return void + */ + function requestIsValid ($isValid = true); } // diff --git a/inc/classes/interfaces/resolver/class_ControllerResolver.php b/inc/classes/interfaces/resolver/class_ControllerResolver.php index e953ceee2e..76ec16a244 100644 --- a/inc/classes/interfaces/resolver/class_ControllerResolver.php +++ b/inc/classes/interfaces/resolver/class_ControllerResolver.php @@ -27,7 +27,7 @@ interface ControllerResolver extends FrameworkInterface { * * @return $controllerInstance A controller instance for the default command */ - function resolveDefaultController (); + function resolveCommandController (); } // diff --git a/inc/classes/interfaces/response/class_Responseable.php b/inc/classes/interfaces/response/class_Responseable.php index 7416b948ca..ae9f4ae91f 100644 --- a/inc/classes/interfaces/response/class_Responseable.php +++ b/inc/classes/interfaces/response/class_Responseable.php @@ -57,6 +57,15 @@ interface Responseable extends FrameworkInterface { * already sent */ function flushBuffer($force=false); + + /** + * Adds a fatal message id to the response. The added messages can then be + * processed and outputed to the world + * + * @param $messageId The message id we shall add + * @return void + */ + function addFatalMessage ($messageId); } // diff --git a/inc/classes/interfaces/user/.htaccess b/inc/classes/interfaces/user/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/interfaces/user/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/user/class_ManageableUser.php b/inc/classes/interfaces/user/class_ManageableUser.php new file mode 100644 index 0000000000..eef4ef82c4 --- /dev/null +++ b/inc/classes/interfaces/user/class_ManageableUser.php @@ -0,0 +1,28 @@ + + * @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 . + */ +interface ManageableUser extends FrameworkInterface { +} + +// +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 4abdf29958..1ccb1c2c76 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -149,6 +149,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_INVALID_CONTROLLER = 0x032; const EXCEPTION_HEADERS_ALREADY_SENT = 0x033; const EXCEPTION_DEFAUL_CONTROLLER_GONE = 0x034; + const EXCEPTION_CLASS_NOT_FOUND = 0x035; /** * In the super constructor these system classes shall be ignored or else @@ -218,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(), @@ -245,16 +288,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Initialize debug instance if (is_null($this->getDebugInstance())) { // Set the debug output system if it is not debug class ;) - $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig("debug_engine"))); + $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_engine'))); } // Initialize web instance if (is_null($this->getWebOutputInstance())) { // Generate the eval() command $eval = sprintf("\$this->setWebOutputInstance(%s::create%s(\"%s\"));", - $this->getConfigInstance()->readConfig("web_engine"), - $this->getConfigInstance()->readConfig("web_engine"), - $this->getConfigInstance()->readConfig("web_content_type") + $this->getConfigInstance()->readConfig('web_engine'), + $this->getConfigInstance()->readConfig('web_engine'), + $this->getConfigInstance()->readConfig('web_content_type') ); // Debug message @@ -272,7 +315,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set the compressor channel $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s", PATH, - $this->getConfigInstance()->readConfig("compressor_base_path") + $this->getConfigInstance()->readConfig('compressor_base_path') ))); } @@ -304,7 +347,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @return $cfhInstance - Configuration instance */ - public final function getConfigInstance () { + protected final function getConfigInstance () { return self::$cfgInstance; } @@ -731,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; } @@ -741,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; } @@ -796,16 +839,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Generate FQFN for all application templates $fqfn = sprintf("%s%s/%s/%s", PATH, - $this->getConfigInstance()->readConfig("application_path"), + $this->getConfigInstance()->readConfig('application_path'), strtolower($appInstance->getAppShortName()), - $this->getConfigInstance()->readConfig("tpl_base_path") + $this->getConfigInstance()->readConfig('tpl_base_path') ); // Are both instances set? 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); } @@ -815,10 +858,10 @@ 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"), + $this->getConfigInstance()->readConfig('tpl_engine'), + $this->getConfigInstance()->readConfig('tpl_engine'), $fqfn ); @@ -853,10 +896,76 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ public final function debugInstance () { // Generate the output - $content = "
".trim(print_r($this, true))."
"; + $content = sprintf("
%s
", + trim(print_r($this, true)) + ); // Output it - ApplicationEntryPoint::app_die("Debug output:".$content); + ApplicationEntryPoint::app_die(sprintf("%s debug output:%s", $this->__toString(), $content)); + } + + /** + * Output a partial stub message for the caller method + * + * @param $message An optional message to display + * @return void + */ + protected function partialStub ($message = "") { + // Get the backtrace + $backtrace = debug_backtrace(); + + // Generate the class::method string + $methodName = "UnknownClass::unknownMethod"; + if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) { + $methodName = $backtrace[1]['class']."::".$backtrace[1]['function']; + } + + // Construct the full message + $stubMessage = sprintf("[%s:] Partial stub!", + $methodName + ); + + // Is the extra message given? + if (!empty($message)) { + // Then add it as well + $stubMessage .= sprintf(" Message: %s", $message); + } + + // Debug instance is there? + if (!is_null($this->getDebugInstance())) { + // Output stub message + $this->getDebugInstance()->output($stubMessage); + } else { + // Trigger an error + trigger_error($stubMessage."
\n"); + } + } + + /** + * Converts e.g. a command from URL to a valid class by keeping out bad characters + * + * @param $str The string, what ever it is needs to be converted + * @return $className Generated class name + */ + public function convertToClassName ($str) { + $className = ""; + foreach (explode("_", $str) as $strPart) { + $className .= ucfirst(strtolower($strPart)); + } + return $className; + } + + /** + * Outputs a debug backtrace and stops further script execution + * + * @return void + */ + public function debugBacktrace () { + // Sorry, there is no other way getting this nice backtrace + print "
\n";
+		debug_print_backtrace();
+		print "
"; + exit; } } diff --git a/inc/classes/main/class_FrameworkArrayObject.php b/inc/classes/main/class_FrameworkArrayObject.php index 85397a4157..d97f403812 100644 --- a/inc/classes/main/class_FrameworkArrayObject.php +++ b/inc/classes/main/class_FrameworkArrayObject.php @@ -24,16 +24,6 @@ * along with this program. If not, see . */ class FrameworkArrayObject extends ArrayObject { - /** - * Constructor for smooth coding style ;-) - * - * @param $class The class's real name - * @return void - */ - public function constructor ($class) { - // $class will be ignored for backward compatiblity - } - /** * Get real class' name back * diff --git a/inc/classes/main/commands/class_ b/inc/classes/main/commands/class_ new file mode 100644 index 0000000000..cbb5b60fe4 --- /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_WebDoFormCommand.php b/inc/classes/main/commands/web/class_WebDoFormCommand.php new file mode 100644 index 0000000000..e4c2300971 --- /dev/null +++ b/inc/classes/main/commands/web/class_WebDoFormCommand.php @@ -0,0 +1,77 @@ + + * @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 WebDoFormCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Command for handling forms on a centralized place"); + + // 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 createWebDoFormCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new WebDoFormCommand(); + + // 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) { + // Should never be executed... + echo "This should never be executed!
";
+		debug_print_backtrace();
+		die("
Good bye..."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/commands/web/class_WebHomeCommand.php b/inc/classes/main/commands/web/class_WebHomeCommand.php index f45b0d7960..0b7e9c41a3 100644 --- a/inc/classes/main/commands/web/class_WebHomeCommand.php +++ b/inc/classes/main/commands/web/class_WebHomeCommand.php @@ -23,7 +23,7 @@ */ class WebHomeCommand extends BaseCommand implements Commandable { /** - * Private constructor + * Protected constructor * * @return void */ @@ -32,7 +32,7 @@ class WebHomeCommand extends BaseCommand implements Commandable { parent::__construct(__CLASS__); // Set special description - $this->setObjectDescription("Home-Command"); + $this->setObjectDescription("Command for the "home" page"); // Create unique ID number $this->createUniqueID(); @@ -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"); @@ -99,9 +99,9 @@ class WebHomeCommand extends BaseCommand implements Commandable { $templateInstance->loadCodeTemplate($masterTemplate); // Set title - $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter"))); + $title = ucfirst($requestInstance->getRequestElement($this->getConfigInstance()->readConfig('command_parameter'))); if (empty($title)) $title = "Home"; - $templateInstance->assignVariable("title", $title); + $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 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 0000000000..af1d7488b8 --- /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("Command for the registration form"); + + // 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/compressor/class_Bzip2Compressor.php b/inc/classes/main/compressor/class_Bzip2Compressor.php index 88322b60c4..24566b91d8 100644 --- a/inc/classes/main/compressor/class_Bzip2Compressor.php +++ b/inc/classes/main/compressor/class_Bzip2Compressor.php @@ -32,7 +32,7 @@ class Bzip2Compressor extends BaseFrameworkSystem implements Compressor { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("BZIP2-Kompressor"); + $this->setObjectDescription("BZIP2 compressor"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/compressor/class_GzipCompressor.php b/inc/classes/main/compressor/class_GzipCompressor.php index 4e95f801f9..08b1a6ded0 100644 --- a/inc/classes/main/compressor/class_GzipCompressor.php +++ b/inc/classes/main/compressor/class_GzipCompressor.php @@ -32,7 +32,7 @@ class GzipCompressor extends BaseFrameworkSystem implements Compressor { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("GZIP-Kompressor"); + $this->setObjectDescription("GZIP compressor"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/compressor/class_NullCompressor.php b/inc/classes/main/compressor/class_NullCompressor.php index a8a570c581..157dc1a9ea 100644 --- a/inc/classes/main/compressor/class_NullCompressor.php +++ b/inc/classes/main/compressor/class_NullCompressor.php @@ -32,7 +32,7 @@ class NullCompressor extends BaseFrameworkSystem implements Compressor { parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Null-Kompressor"); + $this->setObjectDescription("Null compressor"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/console/class_ConsoleTools.php b/inc/classes/main/console/class_ConsoleTools.php index 175102af60..054c8c7db3 100644 --- a/inc/classes/main/console/class_ConsoleTools.php +++ b/inc/classes/main/console/class_ConsoleTools.php @@ -3,10 +3,10 @@ * This class contains static helper functions for console applications * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,20 +19,20 @@ * 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 . + * along with this program. If not, see . */ class ConsoleTools extends BaseFrameworkSystem { /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Console-Tools"); + $this->setObjectDescription("General console tools"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index f7aea5c307..a2bf811584 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -1,6 +1,8 @@ * @version 0.0.0 @@ -22,6 +24,21 @@ * along with this program. If not, see . */ class BaseController extends BaseFrameworkSystem { + /** + * Instance of a CommandResolver class + */ + private $resolverInstance = null; + + /** + * Pre filter chain instance + */ + private $preFilterChain = null; + + /** + * Post filter chain instance + */ + private $postFilterChain = null; + /** * Protected constructor * @@ -33,6 +50,76 @@ class BaseController extends BaseFrameworkSystem { // Clean up a little $this->removeNumberFormaters(); + $this->removeSystemArray(); + + // Initialize both filter chains + $this->preFilterChain = FilterChain::createFilterChain(); + $this->postFilterChain = FilterChain::createFilterChain(); + } + + /** + * Getter for a command resolver instance + * + * @return $resolverInstance An instance of a command resolver class + */ + public final function getResolverInstance () { + return $this->resolverInstance; + } + + /** + * Setter for a command resolver instance + * + * @param $resolverInstance An instance of a command resolver class + * @return void + */ + public final function setResolverInstance (CommandResolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Adds a filter to the pre filter chain + * + * @param $filterInstance An instance of a filter + * @return void + */ + public function addPreFilter (Filterable $filterInstance) { + // Add the pre filter + $this->preFilterChain->addFilter($filterInstance); + } + + /** + * Adds a filter to the post filter chain + * + * @param $filterInstance An instance of a filter + * @return void + */ + public function addPostFilter (Filterable $filterInstance) { + // Add the post filter + $this->postFilterChain->addFilter($filterInstance); + } + + /** + * Executes all pre filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Execute all pre filters + $this->preFilterChain->processFilters($requestInstance, $responseInstance); + } + + /** + * Executes all post filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Execute all post filters + $this->postFilterChain->processFilters($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/default/class_WebDefaultController.php b/inc/classes/main/controller/default/class_WebDefaultController.php index 38d92ce366..9d60e61786 100644 --- a/inc/classes/main/controller/default/class_WebDefaultController.php +++ b/inc/classes/main/controller/default/class_WebDefaultController.php @@ -23,12 +23,7 @@ */ class WebWebDefaultController extends BaseController implements Controller { /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - - /** - * Private constructor + * Protected constructor * * @return void */ @@ -37,13 +32,10 @@ class WebWebDefaultController extends BaseController implements Controller { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Standart-Controller für alle übrigen Anfragen"); + $this->setObjectDescription("Default controller for all other requests"); // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -63,16 +55,6 @@ class WebWebDefaultController extends BaseController implements Controller { return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -82,7 +64,10 @@ class WebWebDefaultController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + + // This request was valid! :-D + $requestInstance->requestIsValid(); // Execute the command $commandInstance->execute($requestInstance, $responseInstance); diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index ff86531c71..b8bbc05544 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -23,12 +23,7 @@ */ class WebDefaultNewsController extends BaseController implements Controller { /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - - /** - * Private constructor + * Protected constructor * * @return void */ @@ -37,13 +32,10 @@ class WebDefaultNewsController extends BaseController implements Controller { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Standart-Controller mit News-Auflistung"); + $this->setObjectDescription("Default controller with news"); // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -63,16 +55,6 @@ class WebDefaultNewsController extends BaseController implements Controller { return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -82,13 +64,13 @@ class WebDefaultNewsController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); - - // Get the news page variable from the request instance - $newsPage = $requestInstance->getRequestElement("news_page"); + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); // Load the news here - $this->loadNews($newsPage); + $this->loadNewsByRequest($requestInstance); + + // This request was valid! :-D + $requestInstance->requestIsValid(); // Execute the command $commandInstance->execute($requestInstance, $responseInstance); @@ -98,12 +80,14 @@ class WebDefaultNewsController extends BaseController implements Controller { } /** - * Loads news from the connected database for later usage + * Loads news by a given request * - * @param $newsPage Page of listed news we want to read + * @param $requestInstance An instance of a request class * @return void */ - private function loadNews ($newsPage) { + private function loadNewsByRequest (Requestable $requestInstance) { + // Generate a new news object but not carring about which concrete we have + $newsInstance = WebNewsFactory::createFactoryByRequest($requestInstance)->createNewsObject(); } } diff --git a/inc/classes/main/controller/form/.htaccess b/inc/classes/main/controller/form/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/main/controller/form/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/form/class_WebDoFormController.php b/inc/classes/main/controller/form/class_WebDoFormController.php new file mode 100644 index 0000000000..9ffcf78b57 --- /dev/null +++ b/inc/classes/main/controller/form/class_WebDoFormController.php @@ -0,0 +1,94 @@ + + * @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 WebDoFormController extends BaseController implements Controller { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Controller for handling forms"); + + // Create unique ID number + $this->createUniqueID(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a resolver class + * @return $controllerInstance A prepared instance of this class + */ + public final static function createWebDoFormController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new WebDoFormController(); + + // Set resolver instance + $controllerInstance->setResolverInstance($resolverInstance); + + // We need the controller instance in the resolver class so set it here + $resolverInstance->setControllerInstance($controllerInstance); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + // Get the "form action" + $formAction = $requestInstance->getRequestElement('form'); + + // Get command instance from resolver + $commandInstance = $this->getResolverInstance()->resolveCommand($formAction); + + // Execute *very* generic pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // Is the request still valid? Post filters shall only be executed of + // the request is valid + if ($requestInstance->isRequestValid()) { + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Execute *very* generic ppost filters + $this->executePostFilters($requestInstance, $responseInstance); + } + + // Flush the buffer out + $responseInstance->flushBuffer(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/classes/class_LocalFileDatabase.php b/inc/classes/main/database/classes/class_LocalFileDatabase.php index 84babfeafd..dbe55ac36d 100644 --- a/inc/classes/main/database/classes/class_LocalFileDatabase.php +++ b/inc/classes/main/database/classes/class_LocalFileDatabase.php @@ -55,7 +55,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Dateidatenbankschicht"); + $this->setObjectDescription("Class for local file databases"); // Create unique ID $this->createUniqueID(); @@ -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/debug/class_DebugConsoleOutput.php b/inc/classes/main/debug/class_DebugConsoleOutput.php index 8efe0b56cd..e9be4a5910 100644 --- a/inc/classes/main/debug/class_DebugConsoleOutput.php +++ b/inc/classes/main/debug/class_DebugConsoleOutput.php @@ -3,10 +3,10 @@ * A debug output class for the console (e.g. hub software) * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,20 +19,20 @@ * 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 . + * along with this program. If not, see . */ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe auf Konsole"); + $this->setObjectDescription("Debug output for the console"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/debug/class_DebugErrorLogOutput.php b/inc/classes/main/debug/class_DebugErrorLogOutput.php index a11a9f7844..1a1723fd69 100644 --- a/inc/classes/main/debug/class_DebugErrorLogOutput.php +++ b/inc/classes/main/debug/class_DebugErrorLogOutput.php @@ -3,10 +3,10 @@ * A debug output class for PHP's error_log() command * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,20 +19,20 @@ * 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 . + * along with this program. If not, see . */ class DebugErrorLogOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe in error_log()"); + $this->setObjectDescription("Debug output to error_log()"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/debug/class_DebugWebOutput.php b/inc/classes/main/debug/class_DebugWebOutput.php index 844605fcd6..0c763e010b 100644 --- a/inc/classes/main/debug/class_DebugWebOutput.php +++ b/inc/classes/main/debug/class_DebugWebOutput.php @@ -3,10 +3,10 @@ * A debug output class for the web browser * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,20 +19,20 @@ * 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 . + * along with this program. If not, see . */ class DebugWebOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Debug-Ausgabe auf Konsole"); + $this->setObjectDescription("Debug output for webpages"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/extended/class_ObjectLimits.php b/inc/classes/main/extended/class_ObjectLimits.php index 13a658ac63..3c23f805ae 100644 --- a/inc/classes/main/extended/class_ObjectLimits.php +++ b/inc/classes/main/extended/class_ObjectLimits.php @@ -4,10 +4,10 @@ * objects to the datatabase connection or else a lot heap would be saved. * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -20,7 +20,7 @@ * 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 . + * along with this program. If not, see . */ class ObjectLimits extends BaseFrameworkSystem { /** @@ -30,16 +30,16 @@ class ObjectLimits extends BaseFrameworkSystem { private $limitArray = null; /** - * Private constructor + * Protected constructor * * @return void */ - private final function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Limitierungsobjekt"); + $this->setObjectDescription("Class for "limiting" other classes. See description for details."); // Create unique ID number $this->createUniqueID(); diff --git a/inc/classes/main/extended/class_SerializationContainer.php b/inc/classes/main/extended/class_SerializationContainer.php index a0980e3d61..7924d4c92e 100644 --- a/inc/classes/main/extended/class_SerializationContainer.php +++ b/inc/classes/main/extended/class_SerializationContainer.php @@ -44,7 +44,7 @@ class SerializationContainer extends FrameworkArrayObject { * @return $containerInstance An instance of SerializationContainer * @throws GetterNotFoundException If a getter was not found */ - public final static function createSerializationContainer (ObjectLimits $limitInstance, $object) { + public final static function createSerializationContainer (ObjectLimits $limitInstance, FrameworkInterface $object) { // Get an instance $containerInstance = new SerializationContainer(); diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php index fd983cac70..5dda5fb904 100644 --- a/inc/classes/main/factories/objects/class_ObjectFactory.php +++ b/inc/classes/main/factories/objects/class_ObjectFactory.php @@ -33,7 +33,7 @@ class ObjectFactory extends BaseFactory { parent::__construct(__CLASS__); // Set object description - $this->setObjectDescription("Objekte-Fabrik"); + $this->setObjectDescription("Simple generic object factory"); } /** diff --git a/inc/classes/main/factories/web/class_WebNewsFactory.php b/inc/classes/main/factories/web/class_WebNewsFactory.php new file mode 100644 index 0000000000..5a604a7798 --- /dev/null +++ b/inc/classes/main/factories/web/class_WebNewsFactory.php @@ -0,0 +1,117 @@ + + * @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 WebNewsFactory extends BaseFactory { + /** + * Instance of a request class + */ + private $requestInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Factory for webpages with news"); + } + + /** + * Singleton getter for a special factory instance depending on the given + * request + * + * @param $requestInstance An instance of a request class + * @return $factoryInstance An instance of a WebNewsFactory class + */ + public final static function createFactoryByRequest (Requestable $requestInstance) { + // Generate the new instance + $factoryInstance = new WebNewsFactory(); + + // Get the element name from configuration + $element = FrameworkConfiguration::getInstance()->readConfig('app_selector_get'); + + // Analyze the request, first get the Uni* application name (short one from URL) + $appName = $requestInstance->getRequestElement($element); + + // Initialize some variables + $className = ""; + $className2 = $appName; + + // Then construct the class name + foreach (array("_", "-") as $exp) { + $array = explode($exp, $className2); + foreach ($array as $el) { + $className .= ucfirst(strtolower($el)); + } + + // Copy it back and clear the class name + $className2 = $className; + $className = ""; + } + + // After all is done, copy it back and add this class' name + $className = $className2 . $factoryInstance->__toString(); + + // Once we have that name, try to load initialize it + $realFactoryInstance = ObjectFactory::createObjectByName($className); + + // And assign it with the factory + $factoryInstance->setRealFactoryInstance($realFactoryInstance); + + // Remember the request we have used for later usage + $factoryInstance->setRequestInstance($requestInstance); + + // Return the prepared factory instance + return $factoryInstance; + } + + /** + * Setter for the request instance + * + * @param $requestInstance An instance of a request object + * @return void + */ + public final function setRequestInstance (Requestable $requestInstance) { + $this->requestInstance = $requestInstance; + } + + /** + * Creates a new object instance and returns it + * + * @return $newsInstance An instance of a news object + */ + public function createNewsObject () { + // Ask the real factory class for doing this + $newsInstance = $this->getRealFactoryInstance()->createNewObject($this->requestInstance); + + // And return it + return $newsInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/.htaccess b/inc/classes/main/filter/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/main/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/class_ b/inc/classes/main/filter/class_ new file mode 100644 index 0000000000..b79b83d210 --- /dev/null +++ b/inc/classes/main/filter/class_ @@ -0,0 +1,72 @@ + + * @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 ???Filter extends BaseFrameworkSystem implements Filterable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A concrete filter"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function create???Filter () { + // Get a new instance + $filterInstance = new ???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter 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) { + // Implement this! + $this->partialStub("Please implement this method."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_AbstractFilterDecorator.php b/inc/classes/main/filter/class_AbstractFilterDecorator.php new file mode 100644 index 0000000000..a9a1d4a66a --- /dev/null +++ b/inc/classes/main/filter/class_AbstractFilterDecorator.php @@ -0,0 +1,87 @@ + + * @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 . + */ +abstract class AbstractFilterDecorator extends BaseFrameworkSystem implements Filterable { + /** + * The decorated filter instance + */ + private $filterInstance = null; + + /** + * Private constructor + * + * @param $className Name of the real class' name + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for the decorated filter instance + * + * @param $filterInstance An instance of a filter + * @return void + */ + protected final function setFilterInstance (Filterable $filterInstance) { + $this->filterInstance = $filterInstance; + } + + /** + * Getter for the decorated filter instance + * + * @return $filterInstance An instance of a filter + */ + protected final function getFilterInstance () { + return $this->filterInstance; + } + + /** + * Execute the inner filter + * + * @param<->$requestInstance<-->An instance of a request class + * @param<->$responseInstance<->An instance of a response class + * @return void + */ + public final function execute (Requestable $requestInstance, Responseable $responseInstance) { + $this->getFilterInstance()->execute($requestInstance, $responseInstance); + } + + + /** + * Do the execution of the filter + * + * @param<->$requestInstance<-->An instance of a request class + * @param<->$responseInstance<->An instance of a response class + * @return void + */ + abstract public function doExecute (Requestable $requestInstance, Responseable $responseInstance); +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_FilterChain.php b/inc/classes/main/filter/class_FilterChain.php new file mode 100644 index 0000000000..cf2ff3b3c0 --- /dev/null +++ b/inc/classes/main/filter/class_FilterChain.php @@ -0,0 +1,93 @@ + + * @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 FilterChain extends BaseFrameworkSystem { + /** + * All filters together + */ + private $filters = array(); + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter chain class"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @return $chainInstance An instance of this class + */ + public final static function createFilterChain () { + // Get a new instance + $chainInstance = new FilterChain(); + + // Return the prepared instance + return $chainInstance; + } + + /** + * Add a new filter + * + * @param $filerInstance An instance of a filter class + * @return void + */ + public final function addFilter (Filterable $filterInstance) { + $this->filters[] = $filterInstance; + } + + /** + * Process all added filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function processFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Run all filters + //* DEBUG */ echo "COUNT=".count($this->filters)."
\n"; + foreach ($this->filters as $filterInstance) { + // Execute this filter + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.
\n"; + $filterInstance->execute($requestInstance, $responseInstance); + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.
\n"; + } + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/validator/.htaccess b/inc/classes/main/filter/validator/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/main/filter/validator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php new file mode 100644 index 0000000000..1c7c54afc8 --- /dev/null +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -0,0 +1,131 @@ + + * @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 UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for username validation"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createUserNameValidatorFilter () { + // Get a new instance + $filterInstance = new UserNameValidatorFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter 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 username from request + $userName = $requestInstance->getRequestElement('username'); + + // Is the username set? + if (is_null($userName)) { + // Not found in form so stop the filtering process + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_unset'); + + // Abort here + return false; + } elseif (empty($userName)) { + // Empty field! + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_empty'); + + // Abort here + return false; + } elseif ($this->ifUserNameIsTaken($userName)) { + // Username is already taken + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_taken'); + + // Abort here + return false; + } + } + + /** + * Check wether the username as already been taken + * + * @param $userName Username to check for existence + * @return $alreadyTaken Wether the username has been taken + */ + private function ifUserNameIsTaken ($userName) { + // Default is already taken + $alreadyTaken = true; + + // Try to create a user instance + try { + // If this instance is created then the username *does* exist + $userInstance = User::createUserByUsername($userName); + } catch (UsernameMissingException $e) { + // Okay, this user is missing! + $alreadyTaken = false; + } catch (FrameworkException $e) { + // Something bad happend + ApplicationEntryPoint::app_die(sprintf("Exception: %s", $e->__toString())); + } + + // Return the result + return $alreadyTaken; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/.htaccess b/inc/classes/main/helper/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/main/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/helper/class_ b/inc/classes/main/helper/class_ new file mode 100644 index 0000000000..8a1892b8a0 --- /dev/null +++ b/inc/classes/main/helper/class_ @@ -0,0 +1,53 @@ + + * @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 extends BaseHelper { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription(""); + } + + /** + * Creates the helper class + * + * @return $helperInstance A preparedf instance of this class + */ + public final static function createHelper () { + // Get new instance + $helperInstance = new Helper(); + + // Return the prepared instance + return $helperInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php new file mode 100644 index 0000000000..02a99e3aa1 --- /dev/null +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -0,0 +1,90 @@ + + * @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 BaseHelper extends BaseFrameworkSystem { + /** + * Template engine instance + */ + private $templateInstance = null; + + /** + * Rendered content created by the helper class + */ + private $content = ""; + + /** + * Private constructor + * + * @param $className Real name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for template engine instances + * + * @param $templateInstance An instance of a template engine class + * @return void + */ + protected final function setTemplateInstance (CompileableTemplate $templateInstance) { + $this->templateInstance = $templateInstance; + } + + /** + * Getter for template engine instances + * + * @return $templateInstance An instance of a template engine class + */ + protected final function getTemplateInstance () { + return $this->templateInstance; + } + + /** + * Add content + * + * @param $newContent New content to add + * @return void + */ + protected final function addContent ($newContent) { + $this->content .= (string) trim($newContent)."\r\n"; + } + + /** + * Getter for content + * + * @return $content The rendered content by this helper + */ + protected final function getContent () { + return $this->content; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/web/.htaccess b/inc/classes/main/helper/web/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/main/helper/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php new file mode 100644 index 0000000000..fb0f1b24d3 --- /dev/null +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -0,0 +1,589 @@ + + * @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 WebFormHelper extends BaseHelper { + /** + * Wether the form tag is opened (keep at false or else your forms will + * never work!) + */ + private $formOpened = false; + + /** + * Name of the form + */ + private $formName = ""; + + /** + * Wether the group is opened or not + */ + private $groupOpened = false; + + /** + * Wether the sub group is opened or not + */ + private $subGroupOpened = false; + + /** + * Name of the sub group + */ + private $subGroupName = ""; + + // Class Constants + const EXCEPTION_FORM_NAME_INVALID = 0xb00; + const EXCEPTION_CLOSED_FORM = 0xb01; + const EXCEPTION_OPENED_FORM = 0xb02; + const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0xb03; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Helper class for HTML forms"); + + // Create unique ID number + $this->createUniqueID(); + } + + /** + * Creates the helper class with the given template engine instance and form name + * + * @param $templateInstance An instance of a valid template engine + * @param $formName Name of the form + * @param $formId Value for "id" attribute (default: $formName) + * @return $helperInstance A preparedf instance of this class + */ + public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) { + // Get new instance + $helperInstance = new WebFormHelper(); + + // Set template instance + $helperInstance->setTemplateInstance($templateInstance); + + // Is the form id not set? + if ($formId === false) { + // Use form id from form name + $formId = $formName; + } + + // Create the form + $helperInstance->addFormTag($formName, $formId); + + // Return the prepared instance + return $helperInstance; + } + + /** + * Add the form tag or close it an already opened form tag + * + * @param $formName Name of the form (default: false) + * @param $formId Id of the form (attribute "id"; default: false) + * @return void + * @throws InvalidFormNameException If the form name is invalid (=false) + */ + public function addFormTag ($formName = false, $formId = false) { + // When the form is not yet opened at least form name must be valid + if (($this->formOpened === false) && ($formName === false)) { + // Thrown an exception + throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID); + } + + // Close the form is default + $formContent = ""; + + // Check wether we shall open or close the form + if ($this->formOpened === false) { + // Add HTML code + $formContent = sprintf("
getConfigInstance()->readConfig('form_action'), + $this->getConfigInstance()->readConfig('form_method'), + $this->getConfigInstance()->readConfig('form_target') + ); + + // Is the form id set? + if ($formId !== false) { + // Then add it as well + $formContent .= sprintf(" id=\"%s_form\"", + $formId + ); + } + + // Add close bracket + $formContent .= ">"; + + // Open the form and remeber the form name + $this->formOpened = true; + $this->formName = $formName; + } else { + // Add the hidden field required to identify safely this form + $this->addInputHiddenField('form', $this->formName); + + // Is a group open? + if ($this->groupOpened === true) { + // Then automatically close it here + $this->addFormGroup("", ""); + } + + // @TODO Add some unique PIN here to bypass problems with some browser and/or extensions + // Simply close it + $this->formOpened = false; + } + + // Add it to the content + $this->addContent($formContent); + } + + /** + * Add a text input tag to the form or throw an exception if it is not yet + * opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputTextField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $fieldValue + ); + + // And add it maybe with a "li" tag + $this->addContent($inputContent); + } + + /** + * Add a password input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputPasswordField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $fieldValue + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a hidden input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputHiddenField ($fieldName, $fieldValue = "") { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldValue + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a checkbox input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $fieldName Input field name + * @param $fieldChecked Wether the field is checked (defaut: checked) + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputCheckboxField ($fieldName, $fieldChecked = true) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Set wether the check box is checked... + $checked = " checked=\"checked\""; + if ($fieldChecked === false) $checked = " "; + + // Generate the content + $inputContent = sprintf("", + $fieldName, + $fieldName, + $checked + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a reset input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $buttonText Text displayed on the button + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputResetButton ($buttonText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "reset"), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $this->formName, + $buttonText + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a reset input tag to the form or throw an exception if it is not + * yet opened. The field's name will be set as id. + * + * @param $buttonText Text displayed on the button + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addInputSubmitButton ($buttonText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "submit"), self::EXCEPTION_CLOSED_FORM); + } + + // Generate the content + $inputContent = sprintf("", + $this->formName, + $this->formName, + $buttonText + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add a form group or close an already opened and open a new one + * + * @param $groupName Name of the group + * @param $groupText Text including HTML to show above this group + * @return void + * @throws FormClosedException If no form has been opened before + * @throws EmptyVariableException If $groupName is not set + */ + public function addFormGroup ($groupName, $groupText) { + // Is a form opened? + if ($this->formOpened === false) { + // Throw exception here + throw new FormClosedException(array($this, $groupName), self::EXCEPTION_CLOSED_FORM); + } + + // At least the group name should be set + if ((empty($groupName)) && ($this->groupOpened === false)) { + // Throw exception here + throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Initialize content with closing div by default + $content = " \n"; + + // Is this group opened? + if ($this->groupOpened === false) { + // Begin the div/span blocks + $content = sprintf(" +
+ + %s + +
", + $groupName, + $groupName, + $groupName, + $groupText, + $groupName + ); + + // Add the content + $this->addContent($content); + + // Switch the state + $this->groupOpened = true; + } else { + // Is a sub group opened? + if ($this->subGroupOpened === true) { + // Close it here + $this->addFormSubGroup("", ""); + } + + // Add the content + $this->addContent($content); + + // Switch the state + $this->groupOpened = false; + + // All call it again if the group name is not empty + if (!empty($groupName)) { + $this->addFormGroup($groupName, $groupText); + } + } + } + + /** + * Add a form sub group or close an already opened and open a new one or + * throws an exception if no group has been opened before or if the sub + * group name is empty. + * + * @param $subGroupName Name of the group + * @param $subGroupText Text including HTML to show above this group + * @return void + * @throws FormGroupClosedException If no group has been opened before + * @throws EmptyVariableException If $subGroupName is not set + */ + public function addFormSubGroup ($subGroupName, $subGroupText) { + // Is a group opened? + if ($this->groupOpened === false) { + // Throw exception here + throw new FormGroupClosedException(array($this, $subGroupName), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP); + } + + // At least the sub group name should be set + if ((empty($subGroupName)) && ($this->subGroupOpened === false)) { + // Throw exception here + throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Initialize content with closing div by default + $content = "
\n
"; + + // Is this group opened? + if ($this->subGroupOpened === false) { + // Begin the span block + $content = sprintf(" +
+ + %s + +
", + $subGroupName, + $subGroupName, + $subGroupName, + $subGroupText, + $subGroupName + ); + + // Add the content + $this->addContent($content); + + // Switch the state and remeber the name + $this->subGroupOpened = true; + $this->subGroupName = $subGroupName; + } else { + // Add the content + $this->addContent($content); + + // Switch the state + $this->subGroupOpened = false; + + // All call it again if sub group name is not empty + if (!empty($subGroupName)) { + $this->addFormSubGroup($subGroupName, $subGroupText); + } + } + } + + /** + * Add text surrounded by a span block when there is a group opened before + * or else by a div block. + * + * @param $fieldName Field name + * @param $fieldText Text for the field + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addFieldText ($fieldName, $fieldText) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); + } + + // Set the block type + $block = "div"; + if ($this->groupOpened === true) $block = "span"; + + // Generate the content + $inputContent = sprintf(" <%s id=\"%s_text\"> + %s + ", + $block, + $fieldName, + $fieldText, + $block + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Add text (notes) surrounded by a div block. Still opened groups or sub + * groups will be automatically closed. + * + * @param $formNotes The form notes we shell addd + * @return void + * @throws FormClosedException If the form is not yet opened + */ + public function addFormNote ($formNotes) { + // Is the form opened? + if ($this->formOpened === false) { + // Throw an exception + throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM); + } + + // Is a group open? + if ($this->groupOpened === true) { + // Then automatically close it here + $this->addFormGroup("unknown", ""); + } + + // Generate the content + $inputContent = sprintf("
+ %s +
", + $formNotes + ); + + // And add it + $this->addContent($inputContent); + } + + /** + * Checks wether the registration requires a valid email address + * + * @return $required Wether the email address is required + */ + public function ifRegisterRequiresEmailVerification () { + $required = ($this->getConfigInstance()->readConfig('register_requires_email') == "Y"); + return $required; + } + + /** + * Checks wether profile data shall be asked + * + * @return $required Wether profile shall be asked + */ + public function ifRegisterIncludesProfile () { + $required = ($this->getConfigInstance()->readConfig('register_includes_profile') == "Y"); + return $required; + } + + /** + * Checks wether personal data shall be asked + * + * @return $required Wether personal data shall be asked + */ + public function ifRegisterIncludesPersonaData () { + $required = ($this->getConfigInstance()->readConfig('register_personal_data') == "Y"); + return $required; + } + + /** + * Checks wether email addresses can only be once used + * + * @return $isUnique + */ + public function ifEmailMustBeUnique () { + $isUnique = ($this->getConfigInstance()->readConfig('register_email_unique') == "Y"); + return $isUnique; + } + + /** + * Checks wether the specified chat protocol is enabled in this form + * + * @return $required Wether the specified chat protocol is enabled + */ + public function ifChatEnabled ($chatProtocol) { + $required = ($this->getConfigInstance()->readConfig(sprintf("chat_enabled_%s", $chatProtocol)) == "Y"); + return $required; + } + + /** + * Flushs the content out (not yet secured against open forms, etc.!) or + * throw an exception if it is not yet closed + * + * @return void + * @throws FormOpenedException If the form is still open + */ + public function flushContent () { + // Is the form still open? + if ($this->formOpened === true) { + // Throw an exception + throw new FormOpenedException ($this, self::EXCEPTION_OPENED_FORM); + } + + // Send content to template engine + $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent()); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/io/class_FileIOStream.php b/inc/classes/main/io/class_FileIOStream.php index 155774a1bb..aea932f26c 100644 --- a/inc/classes/main/io/class_FileIOStream.php +++ b/inc/classes/main/io/class_FileIOStream.php @@ -25,9 +25,9 @@ class FileIOStream extends BaseFrameworkSystem implements FileInputStreamer, Fil /** * Private constructor */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set part description $this->setObjectDescription("Universal Datei-Ein-/Ausgabesystem"); diff --git a/inc/classes/main/io/class_FileIoStream.php b/inc/classes/main/io/class_FileIoStream.php new file mode 100644 index 0000000000..ee02a8d2ff --- /dev/null +++ b/inc/classes/main/io/class_FileIoStream.php @@ -0,0 +1,232 @@ + + * @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 FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, FileOutputStreamer { + /** + * Protected constructor + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Universal file I/O stream system"); + + // Create unique ID + $this->createUniqueID(); + + // Clean-up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Create a file IO stream. This is a class for performing all actions + * on files like creating, deleting and loading them. + * + * @return $ioInstance An instance of FileIoStream + */ + public final static function createFileIoStream () { + // Create new instance + $ioInstance = new FileIoStream(); + + // Return the instance + return $ioInstance; + } + + /** + * Saves data to a given local file + * + * @param $fileName The file name for the to be saved file + * @param $dataArray The data we shall store to the file + * @return void + * @see FileOutputStreamer + */ + public final function saveFile ($fileName, $dataArray) { + // Try it five times + $dirName = ""; $fileInstance = null; + for ($idx = 0; $idx < 5; $idx++) { + // Get a file output pointer + try { + $fileInstance = FrameworkFileOutputPointer::createFrameworkFileOutputPointer($fileName, 'w'); + } catch (FilePointerNotOpenedException $e) { + // Create missing directory + $dirName = dirname($fileName); + for ($idx2 = 0; $idx2 < (2 - $idx); $idx2++) { + $dirName = dirname($dirName); + } + // Try to create it + @mkdir($dirName); + } + } + + // Write a header information for validation purposes + $fileInstance->writeToFile(sprintf("@head^%s:%s:%s:%s\n", + $dataArray[0], + time(), + strlen($dataArray[1]), + md5($dataArray[1]) + )); + + // Encode the (maybe) binary stream with Base64 + $b64Stream = base64_encode($dataArray[1]); + + // write the data line by line + $line = str_repeat(" ", 50); $idx = 0; + while (strlen($line) == 50) { + // Get 50 chars or less + $line = substr($b64Stream, $idx, 50); + + // Save it to the stream + $fileInstance->writeToFile(sprintf("@data^%s:%s\n", + $line, + md5($line) + )); + + // Advance to the next 50-chars block + $idx += 50; + } + + // Close the file + $fileInstance->closeFile(); + } + + /** + * Reads from a local file + * + * @param $fqfn The full-qualified file-name which we shall load + * @return $array An array with the element 'header' and 'data' + * @see FileInputStreamer + */ + public final function loadFileContents ($fqfn) { + // Initialize some variables and arrays + $inputBuffer = ""; + $lastBuffer = ""; + $header = array(); + $data = array(); + $readData = ""; // This will contain our read data + + // Get a file input handler + $fileInstance = FrameworkFileInputPointer::createFrameworkFileInputPointer($fqfn); + + // Read all it's contents (we very and transparently decompress it below) + while ($readRawLine = $fileInstance->readFromFile()) { + // Add the read line to the buffer + $inputBuffer .= $readRawLine; + + // Break infinite loop maybe caused by the input handler + if ($lastBuffer == $inputBuffer) break; + + // Remember last read line for avoiding possible infinite loops + $lastBuffer = $inputBuffer; + } + + // Close directory handle + $fileInstance->closeFile(); + + // Convert it into an array + $inputBuffer = explode("\n", $inputBuffer); + + // Now process the read lines and verify it's content + foreach ($inputBuffer as $rawLine) { + // Trim it a little but not the leading spaces/tab-stops + $rawLine = rtrim($rawLine); + + // Analyze this line + if (substr($rawLine, 0, 5) == "@head") { + // Header found, so let's extract it + $header = explode("^", $rawLine); + $header = trim($header[1]); + + // Now we must convert it again into an array + $header = explode(":", $header); + + // Is the header (maybe) valid? + if (count($header) != 4) { + // Throw an exception + throw new InvalidArrayCountException(array($this, "header", count($header), 4), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); + } + } elseif (substr($rawLine, 0, 5) == "@data") { + // Is a data line! + $data = explode("^", $rawLine); + $data = $data[1]; + + // First element is the data, second the MD5 checksum + $data = explode(":", $data); + + // Validate the read line + if (count($data) == 2) { + if (md5($data[0]) != $data[1]) { + // MD5 hash did not match! + throw new InvalidMD5ChecksumException(array($this, md5($data[0]), $data[1]), self::EXCEPTION_MD5_CHECKSUMS_MISMATCH); + } + } else { + // Invalid count! + throw new InvalidArrayCountException(array($this, "data", count($data), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); + } + + // Add this to the readData string + $readData .= $data[0]; + } else { + // Other raw lines than header/data tagged lines and re-add the new-line char + $readData .= $rawLine."\n"; + } + } + + // Was raw lines read and no header/data? + if ((!empty($readData)) && (count($header) == 0) && (count($data) == 0)) { + // Return raw lines back + return $readData; + } + + // Was a header found? + if (count($header) != 4) { + // Throw an exception + throw new InvalidArrayCountException(array($this, "header", count($header), 4), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); + } + + // Decode all from Base64 + $readData = @base64_decode($readData); + + // Does the size match? + if (strlen($readData) != $header[2]) { + // Size did not match + throw new InvalidDataLengthException(array($this, strlen($readData), $header[2]), self::EXCEPTION_UNEXPECTED_STRING_SIZE); + } + + // Validate the decoded data with the final MD5 hash + if (md5($readData) != $header[3]) { + // MD5 hash did not match! + throw new InvalidMD5ChecksumException(array($this, md5($readData), $header[3]), self::EXCEPTION_MD5_CHECKSUMS_MISMATCH); + } + + // Return all in an array + return array( + 'header' => $header, + 'data' => $readData + ); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/io/class_FrameworkDirectoryPointer.php b/inc/classes/main/io/class_FrameworkDirectoryPointer.php index f02faf9923..f05bfc0275 100644 --- a/inc/classes/main/io/class_FrameworkDirectoryPointer.php +++ b/inc/classes/main/io/class_FrameworkDirectoryPointer.php @@ -3,10 +3,10 @@ * A class for directory reading and getting its contents * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,7 +19,7 @@ * 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 . + * along with this program. If not, see . */ class FrameworkDirectoryPointer extends BaseFrameworkSystem { /** @@ -33,14 +33,14 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem { private $dirPointer = null; /** - * Private constructor + * Protected constructor */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Verzeichnis-Handler"); + $this->setObjectDescription("Helper for handling directories"); // Create unique ID $this->createUniqueID(); diff --git a/inc/classes/main/io/class_FrameworkFileInputPointer.php b/inc/classes/main/io/class_FrameworkFileInputPointer.php index c66d76d6ec..b93c0026b5 100644 --- a/inc/classes/main/io/class_FrameworkFileInputPointer.php +++ b/inc/classes/main/io/class_FrameworkFileInputPointer.php @@ -3,10 +3,10 @@ * A class for reading files * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,7 +19,7 @@ * 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 . + * along with this program. If not, see . */ class FrameworkFileInputPointer extends BaseFrameworkSystem { /** @@ -33,14 +33,14 @@ class FrameworkFileInputPointer extends BaseFrameworkSystem { private $filePointer = null; /** - * Private constructor + * Protected constructor */ - private final function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Dateiausgabe-Handler"); + $this->setObjectDescription("Handler for reading from files"); // Create unique ID $this->createUniqueID(); diff --git a/inc/classes/main/io/class_FrameworkFileOutputPointer.php b/inc/classes/main/io/class_FrameworkFileOutputPointer.php index 9705137b60..350cd7241a 100644 --- a/inc/classes/main/io/class_FrameworkFileOutputPointer.php +++ b/inc/classes/main/io/class_FrameworkFileOutputPointer.php @@ -3,10 +3,10 @@ * A class for writing files * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,7 +19,7 @@ * 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 . + * along with this program. If not, see . */ class FrameworkFileOutputPointer extends BaseFrameworkSystem { /** @@ -33,14 +33,14 @@ class FrameworkFileOutputPointer extends BaseFrameworkSystem { private $filePointer = null; /** - * Private constructor + * Protected constructor */ - private final function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Dateiausgabe-Handler"); + $this->setObjectDescription("Handler for writing to files"); // Create unique ID $this->createUniqueID(); diff --git a/inc/classes/main/language/class_LanguageSystem.php b/inc/classes/main/language/class_LanguageSystem.php index baac159a95..73763676b8 100644 --- a/inc/classes/main/language/class_LanguageSystem.php +++ b/inc/classes/main/language/class_LanguageSystem.php @@ -4,10 +4,10 @@ * application and whole framework * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -20,7 +20,7 @@ * 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 . + * along with this program. If not, see . */ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { /** @@ -44,16 +44,16 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { private static $thisInstance = null; /** - * Private constructor + * Protected constructor * * @return void */ - private final function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Sprachsystem"); + $this->setObjectDescription("Language sub-system"); // Create unique ID number $this->createUniqueID(); @@ -66,7 +66,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { /** * Creates an instance of the class LanguageSystem and prepares it for usage * - * @param $basePath The local base path for all language strings + * @param $basePath The local base path for all language strings * @return $langInstance An instance of LanguageSystem * @throws LanguagePathIsEmptyException If the provided $basePath is empty * @throws InvalidLanguagePathStringException If $basePath is no string @@ -101,7 +101,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { $langInstance->initLanguageStrings(); // Set language code from default config - $langInstance->setLanguageCode($langInstance->getConfigInstance()->readConfig("default_lang")); + $langInstance->setLanguageCode(FrameworkConfiguration::getInstance()->readConfig('default_lang')); // Remember this instance self::$thisInstance = $langInstance; @@ -120,26 +120,37 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { } /** - * Initialize the array-object for all later language strings + * Setter for base path * + * @param $basePath The local base path for all templates * @return void */ - public function initLanguageStrings () { - $this->langStrings = new FrameworkArrayObject(); + protected final function setBasePath ($basePath) { + // And set it + $this->basePath = (string) $basePath; } /** - * Setter for base path + * Setter for language code * - * @param $basePath The local base path for all templates + * @param $langCode The language code for the current application * @return void */ - public final function setBasePath ($basePath) { + protected final function setLanguageCode ($langCode) { // Cast it - $basePath = (string) $basePath; + $langCode = (string) $langCode; - // And set it - $this->basePath = $basePath; + // And set it (only 2 chars) + $this->langCode = substr($langCode, 0, 2); + } + + /** + * Initialize the array-object for all later language strings + * + * @return void + */ + public function initLanguageStrings () { + $this->langStrings = new FrameworkArrayObject(); } /** @@ -152,17 +163,25 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage { } /** - * Setter for language code + * Get the plain message from the cache variable for the given message id * - * @param $langCode The language code for the current application - * @return void + * @param $messageId The message id we shall find in the cache variable + * @return $messageText The plain message text */ - public final function setLanguageCode ($langCode) { - // Cast it - $langCode = (string) $langCode; + public function getMessage ($messageId) { + // Default is missing message text + $messageText = sprintf("!%s!", + $messageId + ); + + // Try to look it up in the cache variable + if ($this->langStrings->offsetExists($messageId)) { + // Return the message string + $messageText = $this->langStrings->offsetGet($messageId); + } - // And set it (only 2 chars) - $this->langCode = substr($langCode, 0, 2); + // Return the text + return $messageText; } } diff --git a/inc/classes/main/output/class_ConsoleOutput.php b/inc/classes/main/output/class_ConsoleOutput.php index 3bf27fcedb..7eeb854eeb 100644 --- a/inc/classes/main/output/class_ConsoleOutput.php +++ b/inc/classes/main/output/class_ConsoleOutput.php @@ -4,10 +4,10 @@ * for console output * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -20,7 +20,7 @@ * 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 . + * along with this program. If not, see . */ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { /** @@ -34,16 +34,16 @@ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { private $vars = array(); /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Console-Ausgabe-Handler"); + $this->setObjectDescription("Console output class"); // Create an unique ID $this->createUniqueID(); @@ -81,7 +81,7 @@ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { */ public final static function getInstance() { if (is_null(self::$consoleInstance)) { - $contentType = FrameworkConfiguration::getInstance()->readConfig("web_content_type"); + $contentType = FrameworkConfiguration::getInstance()->readConfig('web_content_type'); self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType); } return self::$consoleInstance; diff --git a/inc/classes/main/output/class_WebOutput.php b/inc/classes/main/output/class_WebOutput.php index 27e5c83ddc..b1eecc9f36 100644 --- a/inc/classes/main/output/class_WebOutput.php +++ b/inc/classes/main/output/class_WebOutput.php @@ -4,10 +4,10 @@ * browser * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -20,7 +20,7 @@ * 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 . + * along with this program. If not, see . */ class WebOutput extends BaseFrameworkSystem implements OutputStreamer { /** @@ -29,16 +29,16 @@ class WebOutput extends BaseFrameworkSystem implements OutputStreamer { private static $webInstance = null; /** - * Private constructor + * Protected constructor * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description - $this->setObjectDescription("Web-Ausgabe-Handler"); + $this->setObjectDescription("Class for web output e.g. XHTML code"); // Create an unique ID $this->createUniqueID(); diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index 6826d76b71..b95bab1bbd 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -27,6 +27,13 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { */ private $requestData = array(); + /** + * Wether this request is valid and can be further processed. The default is + * valid so make sure your intercepting filters sets this attribute to false + * when they need to intercept the data flow. + */ + private $requestIsValid = true; + /** * Protected constructor * @@ -37,7 +44,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("HTTP-Anfrage"); + $this->setObjectDescription("HTTP request"); // Create unique ID number $this->createUniqueID(); @@ -145,6 +152,34 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Return the value return $headerValue; } + + /** + * Getter for request method. This getter might be useful for security filters + * + * @return $requestMethod Used request method + */ + public final function getRequestMethod () { + return $_SERVER['REQUEST_METHOD']; + } + + /** + * Sets wether the request was valid (default: true) + * + * @param $isValid Wether the request is valid + * @return void + */ + public final function requestIsValid ($isValid = true) { + $this->requestIsValid = (bool) $isValid; + } + + /** + * Returns wether this request is valid + * + * @return $requestIsValid Wether this request is valid + */ + public final function isRequestValid () { + return $this->requestIsValid; + } } // [EOF] diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index d442ef38e4..9345109a8a 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -33,7 +33,12 @@ class BaseResolver extends BaseFrameworkSystem { private $commandPrefix = ""; /** - * Private constructor + * A controller instance + */ + private $controllerInstance = null; + + /** + * Protected constructor * * @return void */ @@ -42,9 +47,29 @@ class BaseResolver extends BaseFrameworkSystem { parent::__construct($class); // Clean up a little + $this->removeNumberFormaters(); $this->removeSystemArray(); } + /** + * Setter for controller instance (this surely breaks a bit the MVC patterm) + * + * @param $controllerInstance An instance of the controller + * @return void + */ + public final function setControllerInstance (Controller $controllerInstance) { + $this->controllerInstance = $controllerInstance; + } + + /** + * Getter for controller instance (this surely breaks a bit the MVC patterm) + * + * @return $controllerInstance An instance of the controller + */ + public final function getControllerInstance () { + return $this->controllerInstance; + } + /** * Setter for command name * @@ -94,7 +119,7 @@ class BaseResolver extends BaseFrameworkSystem { // Now, let us create the full name of the command class $class = sprintf("%s%sCommand", $this->commandPrefix, - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); // Is this class already loaded? @@ -103,6 +128,13 @@ class BaseResolver extends BaseFrameworkSystem { $isValid = true; } + // Debug output + //echo "----- ".__METHOD__." -----
\n"; + //print($class."
");
+		//debug_print_backtrace();
+		//var_dump($isValid);
+		//print("
"); + // Set command name $this->setCommandName($commandName); diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index 30b31b5240..47baef47bf 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -28,7 +28,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { private $lastCommandInstance = ""; /** - * Private constructor + * Protected constructor * * @return void */ @@ -37,15 +37,11 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Lokaler Kommandoauflöser"); + $this->setObjectDescription("Resolver for local web commands"); // Create unique ID number $this->createUniqueID(); - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - // Set prefix to "Web" $this->setCommandPrefix("Web"); } @@ -53,23 +49,23 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { /** * Creates an instance of a Web command resolver with a given default command * - * @param $defaultCommand The default command we shall execute + * @param $commandName The default command we shall execute * @param $appInstance An instance of a manageable application helper class * @return $resolverInstance The prepared command resolver instance * @throws EmptyVariableException Thrown if the default command is not set * @throws InvalidCommandException Thrown if the default command is invalid */ - public final static function createWebCommandResolver ($defaultCommand, ManageableApplication $appInstance) { + public final static function createWebCommandResolver ($commandName, ManageableApplication $appInstance) { // Create the new instance $resolverInstance = new WebCommandResolver(); - // Is the variable $defaultCommand set and the command is valid? - if (empty($defaultCommand)) { + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { // Then thrown an exception here throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($defaultCommand)) { + } elseif (!$resolverInstance->isCommandValid($commandName)) { // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } // Set the application instance @@ -98,10 +94,10 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { // Test if the required parameter is set try { // This goes fine so let's resolv the command - $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter")); + $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig('command_parameter')); // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig("default_command"); + if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command'); // Check if the command is valid if (!$this->isCommandValid($commandName)) { @@ -128,6 +124,33 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { return $commandInstance; } + /** + * Resolves the command by its direct name and returns an instance of its class + * + * @param $commandName The direct command name we shall resolve + * @return $commandInstance An instance of the command class + * @throws InvalidCommandException Thrown if $commandName is invalid + */ + public function resolveCommand ($commandName) { + // Initiate the instance variable + $commandInstance = null; + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command'); + + // Check if the command is valid + if (!$this->isCommandValid($commandName)) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // Return the instance + return $commandInstance; + } + /** * "Loads" a given command and instances it if not yet cached * @@ -138,18 +161,18 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { */ private function loadCommand ($commandName) { // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + $defaultCommand = $this->getConfigInstance()->readConfig('default_command'); // Init command instance $commandInstance = null; // Create command class name - $class = sprintf("Web%sCommand", - ucfirst(strtolower($commandName)) + $className = sprintf("Web%sCommand", + $this->convertToClassName($commandName) ); // Is this class loaded? - if (!class_exists($class)) { + if (!class_exists($className)) { // Class not found, so try the default one or throw exception if ($commandName != $defaultCommand) { // Try the default command @@ -162,8 +185,8 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { // Initiate the command $eval = sprintf("\$commandInstance = %s::create%s(\$this);", - $class, - $class + $className, + $className ); // Run the command diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index c3bebd50f4..9e50d94516 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -23,12 +23,17 @@ */ class WebControllerResolver extends BaseResolver implements ControllerResolver { /** - * Last successfull resolved controller + * Last successfull resolved controller (name) */ private $lastControllerName = ""; /** - * Private constructor + * Last successfull resolved controller (instance) + */ + private $lastControllerInstance = null; + + /** + * Protected constructor * * @return void */ @@ -37,15 +42,11 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription(""); + $this->setObjectDescription("Resolver for local web controllers"); // Create unique ID number $this->createUniqueID(); - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - // Set prefix to "Web" $this->setCommandPrefix("Web"); } @@ -89,7 +90,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * @throws InvalidControllerInstanceException Thrown if $commandInstance * is invalid */ - public function resolveDefaultController () { + public function resolveCommandController () { // Init variables $commandName = ""; $controllerInstance = null; @@ -114,8 +115,8 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); } - // Set last command - $this->lastCommandInstance = $controllerInstance; + // Set last controller + $this->lastControllerInstance = $controllerInstance; } catch (MissingArrayElementsException $e) { // Just catch it here... } @@ -133,8 +134,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * controller class is missing (bad!) */ private function loadController ($commandName) { + // Debug message + //print("----- ".__METHOD__." -----
");
+		 //debug_print_backtrace();
+		 //print("
"); + // + // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + $defaultCommand = $this->getConfigInstance()->readConfig('default_command'); // Init controller instance $controllerInstance = null; @@ -146,11 +153,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { if ($commandName != $defaultCommand) { // Create controller class name $class = sprintf("Web%sController", - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); - } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") { + } elseif ($this->getConfigInstance()->readConfig('home_with_news') == "Y") { // Yes, display news in home then set default controller with news $class = "WebDefaultNewsController"; + } else { + // No nes at "home" page + $class = "WebDefaultController"; } // Is this class loaded? diff --git a/inc/classes/main/response/class_HttpResponse.php b/inc/classes/main/response/class_HttpResponse.php index 05e6f987cf..52ad2a76db 100644 --- a/inc/classes/main/response/class_HttpResponse.php +++ b/inc/classes/main/response/class_HttpResponse.php @@ -20,6 +20,9 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * The extended headers are taken from phpMyAdmin setup tool, written by + * Michal Cihar , licensed under GNU GPL 2.0. */ class HttpResponse extends BaseFrameworkSystem implements Responseable { /** @@ -42,6 +45,11 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { */ private $templateEngine = null; + /** + * Fatal resolved messages from filters and so on + */ + private $fatalMessages = array(); + /** * Protected constructor * @@ -52,7 +60,7 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("HTTP-Antwort"); + $this->setObjectDescription("HTTP response"); // Create unique ID number $this->createUniqueID(); @@ -72,6 +80,9 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { // Get a new instance $responseInstance = new HttpResponse(); + // Set the application instance + $responseInstance->setApplicationInstance($appInstance); + // Initialize the template engine here $responseInstance->initTemplateEngine($appInstance); @@ -100,6 +111,15 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { $this->responseHeaders[$name] = $value; } + /** + * Reset the header array + * + * @return void + */ + public final function resetResponseHeaders () { + $this->responseHeaders = array(); + } + /** * "Writes" data to the response body * @@ -110,6 +130,16 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { $this->responseBody .= $output; } + /** + * Sets the response body to something new + * + * @param $output Output we shall sent in the HTTP response + * @return void + */ + public function setReponseBody ($output) { + $this->responseBody = $output; + } + /** * Flushs the cached HTTP response to the outer world * @@ -125,16 +155,40 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); } elseif (!headers_sent()) { // Send headers out - header("HTTP/1.0 {$this->responseStatus}"); + header("HTTP/1.1 {$this->responseStatus}"); + + // Used later + $now = gmdate('D, d M Y H:i:s') . ' GMT'; + + // General header for no caching + $this->addHeader('Expired', $now); // rfc2616 - Section 14.21 + $this->addHeader('Last-Modified', $now); + $this->addHeader('Cache-Control:', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 + $this->addHeader('Pragma:', 'no-cache'); // HTTP/1.0 + + // Define the charset to be used + $this->addHeader('Content-Type:', 'text/html; charset=utf-8'); + foreach ($this->responseHeaders as $name=>$value) { header("{$name}: {$value}"); } } - // Flush the output to the world - $this->getWebOutputInstance()->output($this->responseBody); - $this->reponseBody = ""; - $this->responseHeaders = array(); + // Are there some error messages? + if (count($this->fatalMessages) == 0) { + // Flush the output to the world + $this->getWebOutputInstance()->output($this->responseBody); + } else { + // Display all error messages + $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages); + + // Send the error messages out to the world + $this->getWebOutputInstance()->output($this->responseBody); + } + + // Clear response header and body + $this->setReponseBody(""); + $this->resetResponseHeaders(); } /** @@ -155,6 +209,18 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { public final function getTemplateEngine () { return $this->templateEngine; } + + /** + * Adds a fatal message id to the response. The added messages can then be + * processed and outputed to the world + * + * @param $messageId The message id we shall add + * @return void + */ + public final function addFatalMessage ($messageId) { + // Adds the resolved message id to the fatal message list + $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId); + } } // [EOF] diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index e11b84d553..412d26ac44 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -123,7 +123,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Template-Engine"); + $this->setObjectDescription("Web template engine"); // Create unique ID number $this->createUniqueID(); @@ -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(); @@ -167,7 +167,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate } // Get configuration instance - $cfgInstance = $tplInstance->getConfigInstance(); + $cfgInstance = FrameworkConfiguration::getInstance(); // Set the base path $tplInstance->setBasePath($basePath); @@ -177,14 +177,14 @@ 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")); - $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig("code_template_extension")); + $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension')); + $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension')); // Absolute output path for compiled templates - $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig("compile_output_path")); + $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig('compile_output_path')); // Return the prepared instance return $tplInstance; @@ -518,7 +518,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate $ext = $this->getRawTemplateExtension(); // If we shall load a code-template we need to switch the file extension - if ($this->getTemplateType() == $this->getConfigInstance()->readConfig("code_template_type")) { + if ($this->getTemplateType() == $this->getConfigInstance()->readConfig('code_template_type')) { // Switch over to the code-template extension $ext = $this->getCodeTemplateExtension(); } @@ -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)) { @@ -596,9 +596,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * * @param $rawData The raw template data we shall analyze * @return void - * @throws InvalidTemplateVariableNameException If a variable name - * in a template is - * invalid */ private function extractVariablesFromRawData ($rawData) { // Cast to string @@ -611,12 +608,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) { // 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")) { - // Invalid variable name - throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR); - } - // Try to assign it, empty strings are being ignored $this->assignTemplateVariable($variableMatches[1][$key], $var); } @@ -651,24 +642,24 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // RECURSIVE PROTECTION! BE CAREFUL HERE! if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) { - // Then try to search for code-templates first - try { - // Load the code template and remember it's contents - $this->loadCodeTemplate($template); - $this->loadedRawData[$template] = $this->getRawTemplateData(); + // Template not found, but maybe variable assigned? + if ($this->isVariableAlreadySet($template) !== false) { + // Use that content here + $this->loadedRawData[$template] = $this->readVariable($template); - // Remember this template for recursion detection - // RECURSIVE PROTECTION! + // Recursive protection: $this->loadedTemplates[] = $template; - } catch (FilePointerNotOpenedException $e) { - // Template not found, but maybe variable assigned? - if ($this->isVariableAlreadySet($template) !== false) { - // Use that content here - $this->loadedRawData[$template] = $this->readVariable($template); - - // Recursive protection: + } else { + // Then try to search for code-templates + try { + // Load the code template and remember it's contents + $this->loadCodeTemplate($template); + $this->loadedRawData[$template] = $this->getRawTemplateData(); + + // Remember this template for recursion detection + // RECURSIVE PROTECTION! $this->loadedTemplates[] = $template; - } else { + } catch (FilePointerNotOpenedException $e) { // Even this is not done... :/ $this->rawTemplates[] = $template; } @@ -914,7 +905,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function loadWebTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->readConfig("web_template_type")); + $this->setTemplateType($this->getConfigInstance()->readConfig('web_template_type')); // Load the special template $this->loadTemplate($template); @@ -929,7 +920,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function loadEmailTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->readConfig("email_template_type")); + $this->setTemplateType($this->getConfigInstance()->readConfig('email_template_type')); // Load the special template $this->loadTemplate($template); @@ -944,7 +935,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function loadCodeTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->readConfig("code_template_type")); + $this->setTemplateType($this->getConfigInstance()->readConfig('code_template_type')); // Load the special template $this->loadTemplate($template); @@ -957,7 +948,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate */ public final function compileVariables () { // Initialize the $content array - $validVar = $this->getConfigInstance()->readConfig("tpl_valid_var"); + $validVar = $this->getConfigInstance()->readConfig('tpl_valid_var'); $dummy = array(); // Iterate through all variables @@ -982,22 +973,64 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate unset($idx); unset($currVariable); - // Finalize the compilation of template variables - $this->finalizeVariableCompilation(); + // Run the compilation twice to get content from helper classes in + $cnt = 0; + while ($cnt < 3) { + // Finalize the compilation of template variables + $this->finalizeVariableCompilation(); - // Prepare the eval() command for comiling the template - $eval = sprintf("\$result = \"%s\";", - addslashes($this->getRawTemplateData()) - ); + // Prepare the eval() command for comiling the template + $eval = sprintf("\$result = \"%s\";", + addslashes($this->getRawTemplateData()) + ); - // Debug message - if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); + // 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); + } // END - while + + // 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(), + htmlentities($eval) + )); + + // Run the constructed command. This will "compile" all variables in + eval($eval); - // Run the constructed command. This will "compile" all variables in - eval($eval); + // Set raw template data + $this->setRawTemplateData($result); + $cnt++; + } // Set the new content $this->setCompiledData($result); @@ -1008,15 +1041,15 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * * @return void * @throws UnexpectedTemplateTypeException If the template type is - * not "code" + * not "code" * @throws InvalidArrayCountException If an unexpected array - * count has been found + * count has been found */ public final function compileTemplate () { // We will only work with template type "code" from configuration - if ($this->getTemplateType() != $this->getConfigInstance()->readConfig("code_template_type")) { + if ($this->getTemplateType() != $this->getConfigInstance()->readConfig('code_template_type')) { // Abort here - throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig("code_template_type")), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); + throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig('code_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); } // END - if // Get the raw data. @@ -1158,6 +1191,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/main/user/.htaccess b/inc/classes/main/user/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/classes/main/user/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php new file mode 100644 index 0000000000..53e8b46efe --- /dev/null +++ b/inc/classes/main/user/class_User.php @@ -0,0 +1,103 @@ + + * @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 User extends BaseFrameworkSystem implements ManageableUser { + /** + * Username + */ + private $username = ""; + + // Exceptions + const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; + + /** + * Private constructor + * + * @return void + */ + protected function __construct ($class = "") { + // Is the class name empty? Then this is not a specialized user class + if (empty($class)) $class = __CLASS__; + + // Call parent constructor + parent::__construct($class); + + // Set part description + $this->setObjectDescription("Generic user class"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this user class by a provided username. This + * factory method will check if the username is already taken and if not + * so it will throw an exception. + * + * @param $username Username we need a class instance for + * @return $userInstance An instance of this user class + * @throws UsernameMissingException If the username does not exist + */ + public final static function createUserByUsername ($userName) { + // Get a new instance + $userInstance = new User(); + + // Set the username + $userInstance->setUsername($userName); + + // Check if the username exists + if (!$userInstance->ifUsernameExists()) { + // Throw an exception here + throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND); + } + + // Return the instance + return $userInstance; + } + + /** + * Setter for username + * + * @param $userName The username to set + * @return void + */ + protected final function setUsername ($userName) { + $this->userNane = $userName; + } + + /** + * Getter for username + * + * @return $userName The username to set + */ + public final function getUsername () { + return $this->userNane; + } +} + +// [EOF] +?> diff --git a/inc/classes/middleware/class_BaseMiddleware.php b/inc/classes/middleware/class_BaseMiddleware.php index 88bc16e12b..59d90ad242 100644 --- a/inc/classes/middleware/class_BaseMiddleware.php +++ b/inc/classes/middleware/class_BaseMiddleware.php @@ -27,23 +27,13 @@ class BaseMiddleware extends BaseFrameworkSystem { * * @return void */ - private function __construct ($class) { + protected function __construct ($class) { // Call parent constructor - parent::constructor($class); + parent::__construct($class); // Clean up a little $this->removeNumberFormaters(); } - - /** - * Public constructor - * - * @return void - */ - public function constructor ($class) { - // Just call the private constructor - $this->__construct($class); - } } // [EOF] diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index 8dae607bbf..1b33041fd8 100644 --- a/inc/classes/middleware/compressor/class_CompressorChannel.php +++ b/inc/classes/middleware/compressor/class_CompressorChannel.php @@ -3,10 +3,10 @@ * Middleware class for selecting the right compressor channel * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,16 +19,16 @@ * 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 . + * along with this program. If not, see . */ class CompressorChannel extends BaseMiddleware { // Output handler instance private $compressor = null; // Public constructor - private function __construct () { + protected function __construct () { // Call parent constructor! - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description $this->setObjectDescription("Komprimierungshandler"); @@ -55,7 +55,7 @@ class CompressorChannel extends BaseMiddleware { // Read all directories but no sub directories while ($dir = $dirPointer->readDirectoryExcept(array("..", ".", ".htaccess"))) { // Is this a class file? - if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == $cInstance->getConfigInstance()->readConfig("php_extension"))) { + if ((substr($dir, 0, 6) == "class_") && (substr($dir, -4, 4) == FrameworkConfiguration::getInstance()->readConfig('php_extension'))) { // Get the compressor's name. That's why you must name // your files like your classes and also that's why you // must keep on class in one file. diff --git a/inc/classes/middleware/database/class_DatabaseConnection.php b/inc/classes/middleware/database/class_DatabaseConnection.php index d7db9d8697..14255d7922 100644 --- a/inc/classes/middleware/database/class_DatabaseConnection.php +++ b/inc/classes/middleware/database/class_DatabaseConnection.php @@ -32,9 +32,9 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li private static $thisInstance = null; // Private constructor - private final function __construct() { + protected function __construct() { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description $this->setObjectDescription("Datenbank-Mittelschicht"); diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index 2cc4882330..3e1d66d550 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -39,9 +39,9 @@ class DebugMiddleware extends BaseMiddleware { * * @return void */ - private final function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description $this->setObjectDescription("Debug-Ausgabe-Handler"); diff --git a/inc/classes/middleware/io/class_FileIOHandler.php b/inc/classes/middleware/io/class_FileIOHandler.php index 7e0d35ad52..c514a4abc2 100644 --- a/inc/classes/middleware/io/class_FileIOHandler.php +++ b/inc/classes/middleware/io/class_FileIOHandler.php @@ -43,9 +43,9 @@ class FileIOHandler extends BaseMiddleware { * * @return void */ - private function __construct () { + protected function __construct () { // Call parent constructor - parent::constructor(__CLASS__); + parent::__construct(__CLASS__); // Set description $this->setObjectDescription("Datei-Ein-/Ausgabe-Handler"); diff --git a/inc/classes/middleware/io/class_FileIoHandler.php b/inc/classes/middleware/io/class_FileIoHandler.php new file mode 100644 index 0000000000..c41f7cb2d8 --- /dev/null +++ b/inc/classes/middleware/io/class_FileIoHandler.php @@ -0,0 +1,181 @@ + + * @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 FileIoHandler extends BaseMiddleware { + /** + * The *real* file input class we shall use for reading data + */ + private $inputStream = null; + + /** + * The *real* file output class we shall use for reading data + */ + private $outputStream = null; + + /** + * An instance of this class + */ + private static $thisInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set description + $this->setObjectDescription("Datei-Ein-/Ausgabe-Handler"); + + // Create an unique ID + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + + // Set own instance + self::$thisInstance = $this; + } + + /** + * Creates an instance of this class and prepares the IO system. This is + * being done by setting the default file IO class + * + * @return $ioInstance A prepared instance of FilIOHandler + */ + public final static function createFileIoHandler () { + // Get instance + $ioHandler = new FileIoHandler(); + + // Set the *real* file IO instances (both the same) + $ioHandler->setInputStream(FileIoStream::createFileIoStream()); + $ioHandler->setOutputStream(FileIoStream::createFileIoStream()); + + // Return instance + return $ioHandler; + } + + /** + * Getter for an instance of this class + * + * @return $thisInstance An instance of this class + */ + public final static function getInstance () { + return self::$thisInstance; + } + + /** + * Setter for the *real* file input instance + * + * @param $inputStream The *real* file-input class + */ + public final function setInputStream (FileInputStreamer $inputStream) { + $this->inputStream = $inputStream; + } + + /** + * Getter for the *real* file input instance + * + * @return $inputStream The *real* file-input class + */ + public final function getInputStream () { + return $this->inputStream; + } + + /** + * Setter for the *real* file output instance + * + * @param $outputStream The *real* file-output class + */ + public final function setOutputStream (FileOutputStreamer $outputStream) { + $this->outputStream = $outputStream; + } + + /** + * Getter for the *real* file output instance + * + * @return $outputStream The *real* file-output class + */ + public final function getOutputStream () { + return $this->outputStream; + } + + /** + * Saves a file with data by using the current output stream + * + * @see FileOutputStreamer + */ + public function saveFile ($fileName, $dataArray) { + // Get output stream + $outInstance = $this->getOutputStream(); + + // Is it a valid stream? + if (is_null($outInstance)) { + // No class returned + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_object($outInstance)) { + // Not an object! ;-( + throw new NoObjectException($outInstance, self::EXCEPTION_IS_NO_OBJECT); + } elseif (!method_exists($outInstance, 'saveFile')) { + // Nope, so throw exception + throw new MissingMethodException(array($outInstance, 'saveFile'), self::EXCEPTION_MISSING_METHOD); + } + + // Send the fileName and dataArray to the output handler + $outInstance->saveFile($fileName, $dataArray); + } + + /** Loads data from a file over the input handler + * + * @see FileInputStreamer + */ + public function loadFileContents ($fqfn) { + // Initialize the array + $array = array(); + + // Get output stream + $inInstance = $this->getInputStream(); + + // Is it a valid stream? + if (is_null($inInstance)) { + // No class returned + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } elseif (!is_object($inInstance)) { + // Not an object! ;-( + throw new NoObjectException($inInstance, self::EXCEPTION_IS_NO_OBJECT); + } elseif (!method_exists($inInstance, 'loadFileContents')) { + // Nope, so throw exception + throw new MissingMethodException(array($inInstance, 'loadFileContents'), self::EXCEPTION_MISSING_METHOD); + } + + // Read from the input handler + return $inInstance->loadFileContents($fqfn); + } +} + +// [EOF] +?> diff --git a/inc/config.php b/inc/config.php index ab944bf115..d5622f3cbb 100644 --- a/inc/config.php +++ b/inc/config.php @@ -5,10 +5,10 @@ * configuration entries there. * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -21,20 +21,23 @@ * 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 . + * along with this program. If not, see . */ // Load the class from inc/config direktory -@require_once(dirname(__FILE__) . "/config/class_FrameworkConfiguration.php"); +@require_once(dirname(__FILE__) . '/config/class_FrameworkConfiguration.php'); // Get a new configuration instance $cfg = FrameworkConfiguration::createFrameworkConfiguration(); // CFG: SERVER-PATH -$cfg->definePath(dirname(dirname(__FILE__)) . "/"); // DON'T MISS THE TRAILING SLASH!!! +$cfg->definePath(dirname(dirname(__FILE__)) . '/'); // DON'T MISS THE TRAILING SLASH!!! // CFG: DATABASE-TYPE -$cfg->defineDatabaseType("local"); +$cfg->defineDatabaseType('local'); + +// CFG: LOCAL-DB-PATH +$cfg->setConfigEntry('local_db_path', 'db/'); // CFG: TIME-ZONE $cfg->setDefaultTimezone("Europe/Berlin"); @@ -43,103 +46,103 @@ $cfg->setDefaultTimezone("Europe/Berlin"); $cfg->setMagicQuotesRuntime(false); // CFG: PHP-SCRIPT-EXTENSION -$cfg->setConfigEntry("php_extension", ".php"); +$cfg->setConfigEntry('php_extension', ".php"); // CFG: CLASS-PREFIX -$cfg->setConfigEntry("class_prefix", "class_"); +$cfg->setConfigEntry('class_prefix', "class_"); // CFG: CLASS-SUFFIX -$cfg->setConfigEntry("class_suffix", ".php"); +$cfg->setConfigEntry('class_suffix', ".php"); // CFG: RAW-TEMPLATE-EXTENSION -$cfg->setConfigEntry("raw_template_extension", ".tpl"); +$cfg->setConfigEntry('raw_template_extension', ".tpl"); // CFG: CODE-TEMPLATE-EXTENSION -$cfg->setConfigEntry("code_template_extension", ".ctp"); +$cfg->setConfigEntry('code_template_extension', ".ctp"); // CFG: SELECTOR-GET -$cfg->setConfigEntry("app_selector_get", "app"); +$cfg->setConfigEntry('app_selector_get', "app"); + +// CFG: SELECTOR-PATH +$cfg->setConfigEntry('selector_path', "selector"); // CFG: APPLICATION-HELPER -$cfg->setConfigEntry("app_helper_class", "ApplicationHelper"); +$cfg->setConfigEntry('app_helper_class', "ApplicationHelper"); -// CFG: SELECTOR-PATH -$cfg->setConfigEntry("selector_path", "selector"); +// CFG: LAUNCH-METHOD +$cfg->setConfigEntry('entry_method', "entryPoint"); // CFG: TEMPLATE-BASE-PATH -$cfg->setConfigEntry("tpl_base_path", "templates/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('tpl_base_path', "templates/"); // DON'T MISS THE TRAILING SLASH! // CFG: LANGUAGE-BASE-PATH -$cfg->setConfigEntry("lang_base_path", "inc/language/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('lang_base_path', "inc/language/"); // DON'T MISS THE TRAILING SLASH! // CFG: COMPRESSOR-BASE-PATH -$cfg->setConfigEntry("compressor_base_path", "inc/classes/main/compressor/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('compressor_base_path', "inc/classes/main/compressor/"); // DON'T MISS THE TRAILING SLASH! // CFG: APPLICATION-PATH -$cfg->setConfigEntry("application_path", "application"); +$cfg->setConfigEntry('application_path', "application"); // CFG: COMPILE-OUTPUT-PATH -$cfg->setConfigEntry("compile_output_path", "templates/_compiled/"); // DON'T MISS THE TRAILING SLASH! +$cfg->setConfigEntry('compile_output_path', "templates/_compiled/"); // DON'T MISS THE TRAILING SLASH! // CFG: TEMPLATE-ENGINE -$cfg->setConfigEntry("tpl_engine", "TemplateEngine"); +$cfg->setConfigEntry('tpl_engine', "TemplateEngine"); // CFG: DEBUG-ENGINE -$cfg->setConfigEntry("debug_engine", "DebugWebOutput"); +$cfg->setConfigEntry('debug_engine', "DebugWebOutput"); // CFG: DEFAULT-LANGUAGE -$cfg->setConfigEntry("default_lang", "de"); // A two-char language string: de for german, en for english and so on +$cfg->setConfigEntry('default_lang', "de"); // A two-char language string: de for german, en for english and so on // CFG: WEB-TEMPLATE-TYPE -$cfg->setConfigEntry("web_template_type", "html"); +$cfg->setConfigEntry('web_template_type', "html"); // CFG: EMAIL-TEMPLATE-TYPE -$cfg->setConfigEntry("email_template_type", "emails"); +$cfg->setConfigEntry('email_template_type', "emails"); // CFG: CODE-TEMPLATE-TYPE -$cfg->setConfigEntry("code_template_type", "code"); +$cfg->setConfigEntry('code_template_type', "code"); // CFG: WEB-ENGINE -$cfg->setConfigEntry("web_engine", "WebOutput"); +$cfg->setConfigEntry('web_engine', "WebOutput"); // CFG: SELECTOR-TEMPLATE-PREFIX -$cfg->setConfigEntry("tpl_selector_prefix", "selector"); +$cfg->setConfigEntry('tpl_selector_prefix', "selector"); // CFG: WEB-CONTENT-TYPE -$cfg->setConfigEntry("web_content_type", "text/html"); +$cfg->setConfigEntry('web_content_type', "text/html"); // CFG: VALID-TEMPLATE-VARIABLE -$cfg->setConfigEntry("tpl_valid_var", "content"); +$cfg->setConfigEntry('tpl_valid_var', "content"); // CFG: META-AUTHOR -$cfg->setConfigEntry("meta_author", "Roland Häder"); +$cfg->setConfigEntry('meta_author', "Roland Häder"); // CFG: META-PUBLISHER -$cfg->setConfigEntry("meta_publisher", "Roland Häder"); +$cfg->setConfigEntry('meta_publisher', "Roland Häder"); // CFG: META-KEYWORDS -$cfg->setConfigEntry("meta_keywords", "test,test,test"); +$cfg->setConfigEntry('meta_keywords', "test,test,test"); // CFG: META-DESCRIPTION -$cfg->setConfigEntry("meta_description", "A lame description for an application framework"); - -// CFG: LAUNCH-METHOD -$cfg->setConfigEntry("entry_method", "entryPoint"); +$cfg->setConfigEntry('meta_description', "A lame description for an application framework"); // CFG: SELECTOR-MAIN-TEMPLATE -$cfg->setConfigEntry("selector_main_tpl", "selector_main"); +$cfg->setConfigEntry('selector_main_tpl', "selector_main"); // CFG: SELECTOR-APPS-TEMPLATE -$cfg->setConfigEntry("selector_apps_tpl", "selector_apps"); +$cfg->setConfigEntry('selector_apps_tpl', "selector_apps"); // CFG: SELECTOR-NAME -$cfg->setConfigEntry("selector_name", "selector"); +$cfg->setConfigEntry('selector_name', "selector"); // CFG: DEFAULT-APPLICATION -$cfg->setConfigEntry("default_application", "selector"); +$cfg->setConfigEntry('default_application', "selector"); // CFG: VERBOSE-LEVEL -$cfg->setConfigEntry("verbose_level", 0); +$cfg->setConfigEntry('verbose_level', 0); // [EOF] ?> diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index fc920402b4..6c81052d52 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -7,10 +7,10 @@ * * @see ClassLoader * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -23,7 +23,7 @@ * 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 . + * along with this program. If not, see . */ class FrameworkConfiguration { /** @@ -43,9 +43,9 @@ class FrameworkConfiguration { const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0xc01; /** - * Private constructor + * Protected constructor */ - private function __construct () { + protected function __construct () { // Empty for now } diff --git a/inc/config/config-hubmaster.php b/inc/config/config-hubmaster.php index 1ec81dfae8..0c59d29df3 100644 --- a/inc/config/config-hubmaster.php +++ b/inc/config/config-hubmaster.php @@ -25,64 +25,64 @@ $cfg = FrameworkConfiguration::getInstance(); // CFG: HUB-LISTEN-ADDR -$cfg->setConfigEntry("hub_listen_addr", "0.0.0.0"); +$cfg->setConfigEntry('hub_listen_addr', "0.0.0.0"); // CFG: HUB-LISTEN-PORT (zero = auto-choose) -$cfg->setConfigEntry("hub_listen_port", 9060); +$cfg->setConfigEntry('hub_listen_port', 9060); // CFG: HUB-MAX-AUTH-TRIES -$cfg->setConfigEntry("hub_max_auth_tries", 3); +$cfg->setConfigEntry('hub_max_auth_tries', 3); // CFG: HUB-MSG-AUTH-TRIES -$cfg->setConfigEntry("hub_msg_auth_tries", "AUTH_MAX_TRIES"); +$cfg->setConfigEntry('hub_msg_auth_tries', "AUTH_MAX_TRIES"); // CFG: HUB-MSG-SPOOFING -$cfg->setConfigEntry("hub_msg_spoofing", "SPOOFING"); +$cfg->setConfigEntry('hub_msg_spoofing', "SPOOFING"); // CFG: HUB-MSG-AUTH-REPLY -$cfg->setConfigEntry("hub_msg_auth_reply_timeout", "TIMEOUT_AUTH"); +$cfg->setConfigEntry('hub_msg_auth_reply_timeout', "TIMEOUT_AUTH"); // CFG: HUB-MSG-BYE -$cfg->setConfigEntry("hub_msg_bye", "BYE"); +$cfg->setConfigEntry('hub_msg_bye', "BYE"); // CFG: HUB-MASTER-IP -$cfg->setConfigEntry("hub_master_ip", "192.168.1.17"); +$cfg->setConfigEntry('hub_master_ip', "192.168.1.17"); // CFG: HUB-MASTER-PORT -$cfg->setConfigEntry("hub_master_port", 9060); +$cfg->setConfigEntry('hub_master_port', 9060); // CFG: HUB-AUTH-REQUEST -$cfg->setConfigEntry("hub_auth_request", "AUTH"); +$cfg->setConfigEntry('hub_auth_request', "AUTH"); // CFG: HUB-AUTH-REQUEST-TIMEOUT (5 seconds for whole auth procedure shall be fine) -$cfg->setConfigEntry("hub_auth_request_timeout", 5); +$cfg->setConfigEntry('hub_auth_request_timeout', 5); // CFG: HUB-PEER-HELLO -$cfg->setConfigEntry("hub_peer_hello", "HELLO"); +$cfg->setConfigEntry('hub_peer_hello', "HELLO"); // CFG: HUB-HELLO-REPLY -$cfg->setConfigEntry("hub_hello_reply", "ELHO"); +$cfg->setConfigEntry('hub_hello_reply', "ELHO"); // CFG: HUB-HELLO-TIMEOUT -$cfg->setConfigEntry("hub_hello_timeout", 30); +$cfg->setConfigEntry('hub_hello_timeout', 30); // CFG: HUB-HELLO-RETRIES -$cfg->setConfigEntry("hub_hello_retires", 3); +$cfg->setConfigEntry('hub_hello_retires', 3); // CFG: HUB-PEER-PING -$cfg->setConfigEntry("hub_peer_ping", "PING"); +$cfg->setConfigEntry('hub_peer_ping', "PING"); // CFG: HUB-PING-REPLY -$cfg->setConfigEntry("hub_ping_reply", "PONG"); +$cfg->setConfigEntry('hub_ping_reply', "PONG"); // CFG: HUB-PING-TIMEOUT -$cfg->setConfigEntry("hub_ping_timeout", 10); +$cfg->setConfigEntry('hub_ping_timeout', 10); // CFG: HUB-PING-MAXDROPS -$cfg->setConfigEntry("hub_ping_maxdrops", 3); +$cfg->setConfigEntry('hub_ping_maxdrops', 3); // CFG: HUB-PEER-MISS-PONG -$cfg->setConfigEntry("hub_peer_miss_pong", "PONG_MISS"); +$cfg->setConfigEntry('hub_peer_miss_pong', "PONG_MISS"); // [EOF] ?> diff --git a/inc/database.php b/inc/database.php index ad29f0e495..62e64fb92b 100644 --- a/inc/database.php +++ b/inc/database.php @@ -34,7 +34,11 @@ This will choose the local-file-based database type (layer)"); } // Generate FQFN for the database layer -$INC = sprintf("%sinc/database/lib-%s%s", PATH, _DB_TYPE, FrameworkConfiguration::getInstance()->readConfig("php_extension")); +$INC = sprintf("%sinc/database/lib-%s%s", + PATH, + _DB_TYPE, + FrameworkConfiguration::getInstance()->readConfig('php_extension') +); // Load the database layer include if ((file_exists($INC)) && (is_file($INC)) && (is_readable($INC))) { diff --git a/inc/database/lib-local.php b/inc/database/lib-local.php index a689fed4bc..95b0f89541 100644 --- a/inc/database/lib-local.php +++ b/inc/database/lib-local.php @@ -3,10 +3,10 @@ * Initializes the local file database class * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,30 +19,30 @@ * 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 . + * along with this program. If not, see . */ // Zum Testen speichern wir in lokale Dateien (LocalFileDatabase) try { - $layer = LocalFileDatabase::createLocalFileDatabase(PATH . "db/", FileIOHandler::getInstance()); + $layer = LocalFileDatabase::createLocalFileDatabase(PATH . FrameworkConfiguration::getInstance()->readConfig('local_db_path'), FileIoHandler::getInstance()); } catch (SavePathIsEmptyException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathNotFoundException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathIsNoDirectoryException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathReadProtectedException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } catch (SavePathWriteProtectedException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] Debug-Instanz konnte nicht gesetzt werden. Reason: %s
\n", + ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s
\n", $e->getMessage() )); } diff --git a/inc/file_io.php b/inc/file_io.php index 92c96b6c41..de20bf54ca 100644 --- a/inc/file_io.php +++ b/inc/file_io.php @@ -5,10 +5,10 @@ * instances will we generated. * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -21,11 +21,11 @@ * 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 . + * along with this program. If not, see . */ // Get the instance -$io = FileIOHandler::createFileIOHandler(); +$io = FileIoHandler::createFileIoHandler(); // [EOF] ?> diff --git a/inc/includes.php b/inc/includes.php index c9158581e7..b699ea9118 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -3,10 +3,10 @@ * Loads more include files by using the generic class loader * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,11 +19,11 @@ * 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 . + * along with this program. If not, see . */ // Include the class loader function -require(sprintf("%sinc/loader/class_ClassLoader%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); +require(sprintf("%sinc/loader/class_ClassLoader%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); /** * Is the devel package included? @@ -32,7 +32,7 @@ if (is_dir(sprintf("%sdevel", PATH))) { /** * Load all development includes */ - ClassLoader::getInstance()->loadClasses("devel"); + ClassLoader::getInstance()->loadClasses('devel'); } // Shall we include additional configs where you can configure some things? Then diff --git a/inc/language.php b/inc/language.php index 552dc45894..60c9e28ebc 100644 --- a/inc/language.php +++ b/inc/language.php @@ -23,7 +23,7 @@ try { $lang = LanguageSystem::createLanguageSystem(sprintf("%s%s", PATH, - FrameworkConfiguration::getInstance()->readConfig("lang_base_path") + FrameworkConfiguration::getInstance()->readConfig('lang_base_path') )); } catch (LanguagePathIsEmptyException $e) { ApplicationEntryPoint::app_die(sprintf("[Main:] The language sub-system could not be initialized for the following reason: %s", diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 79389f647d..edbe3cb2ff 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -3,10 +3,10 @@ * This class loads class include files with a specific prefix and suffix * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,7 +19,7 @@ * 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 . + * along with this program. If not, see . * * ---------------------------------- * 1.1 @@ -101,8 +101,8 @@ class ClassLoader { $this->dirList = new ArrayObject(); // Set suffix and prefix from configuration - $this->suffix = $cfgInstance->readConfig("class_suffix"); - $this->prefix = $cfgInstance->readConfig("class_prefix"); + $this->suffix = $cfgInstance->readConfig('class_suffix'); + $this->prefix = $cfgInstance->readConfig('class_prefix'); // Estimate length of prefix and suffix for substr() function (cache) $this->sufLen = strlen($this->suffix); @@ -289,9 +289,9 @@ class ClassLoader { } // Initial load of core classes and the FrameworkDirectoryPointer class -require_once(sprintf("%sinc/classes/interfaces/class_FrameworkInterface%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); -require_once(sprintf("%sinc/classes/main/class_BaseFrameworkSystem%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); -require_once(sprintf("%sinc/classes/main/io/class_FrameworkDirectoryPointer%s", PATH, FrameworkConfiguration::getInstance()->readConfig("php_extension"))); +require_once(sprintf("%sinc/classes/interfaces/class_FrameworkInterface%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); +require_once(sprintf("%sinc/classes/main/class_BaseFrameworkSystem%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); +require_once(sprintf("%sinc/classes/main/io/class_FrameworkDirectoryPointer%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension'))); // Initialize the class loader $loader = new ClassLoader(FrameworkConfiguration::getInstance()); diff --git a/inc/output.php b/inc/output.php index 20f3fe8f5b..7b9302a0a6 100644 --- a/inc/output.php +++ b/inc/output.php @@ -23,7 +23,7 @@ */ // Get a debugger instance -$debug = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getInstance()->readConfig("debug_engine")); +$debug = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getInstance()->readConfig('debug_engine')); // Empty string should be ignored and used for testing the middleware DebugMiddleware::getInstance()->output(""); diff --git a/inc/selector.php b/inc/selector.php index 7af8aa0605..e608de177a 100644 --- a/inc/selector.php +++ b/inc/selector.php @@ -3,10 +3,10 @@ * The application selector main include file * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -19,27 +19,27 @@ * 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 . + * along with this program. If not, see . */ // Does the user has an application specified? -if (!empty($_GET[FrameworkConfiguration::getInstance()->readConfig("app_selector_get")])) { +if (!empty($_GET[FrameworkConfiguration::getInstance()->readConfig('app_selector_get')])) { // Set the application from string - $application = (string) $_GET[FrameworkConfiguration::getInstance()->readConfig("app_selector_get")]; + $application = (string) $_GET[FrameworkConfiguration::getInstance()->readConfig('app_selector_get')]; } elseif (!empty($_SERVER['argv'][1])) { // Set the application from string $application = (string) $_SERVER['argv'][1]; - $app = explode("=", trim($application)); - if ($app[0] == FrameworkConfiguration::getInstance()->readConfig("app_selector_get")) { + $app = explode('=', trim($application)); + if ($app[0] == FrameworkConfiguration::getInstance()->readConfig('app_selector_get')) { // Application is valid! $application = trim($app[1]); } else { // Invalid entry found, first must be "app"! - $application = FrameworkConfiguration::getInstance()->readConfig("default_application"); + $application = FrameworkConfiguration::getInstance()->readConfig('default_application'); } } else { // Set the "application selector" application - $application = FrameworkConfiguration::getInstance()->readConfig("default_application"); + $application = FrameworkConfiguration::getInstance()->readConfig('default_application'); } // Secure it, by keeping out tags @@ -50,7 +50,7 @@ $application = preg_replace('/([^a-z_-])+/i', "", $application); // Try to load these includes in the given order $configAppIncludes = array( - sprintf("class_%s", FrameworkConfiguration::getInstance()->readConfig("app_helper_class")), // The ApplicationHelper class + sprintf("class_%s", FrameworkConfiguration::getInstance()->readConfig('app_helper_class')), // The ApplicationHelper class "config", // The application's own configuration "init", // The application initializer "loader", // The application's class loader @@ -70,20 +70,20 @@ foreach ($configAppIncludes as $inc) { // Generate a FQFN for the helper class $fqfn = sprintf("%s%s/%s/%s%s", PATH, - FrameworkConfiguration::getInstance()->readConfig("application_path"), + FrameworkConfiguration::getInstance()->readConfig('application_path'), $application, $inc, - FrameworkConfiguration::getInstance()->readConfig("php_extension") + FrameworkConfiguration::getInstance()->readConfig('php_extension') ); // Does the include file exists? if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) { // Load it require_once($fqfn); - } elseif (FrameworkConfiguration::getInstance()->readConfig("verbose_level") > 0) { + } elseif (FrameworkConfiguration::getInstance()->readConfig('verbose_level') > 0) { // File is missing trigger_error(sprintf("Cannot load application script %s! File is missing or read-protected.", - $inc . FrameworkConfiguration::getInstance()->readConfig("php_extension") + $inc . FrameworkConfiguration::getInstance()->readConfig('php_extension') )); } } diff --git a/templates/de/code/emergency_exit.ctp b/templates/de/code/emergency_exit.ctp index 06cbde487f..d5c6f906a9 100644 --- a/templates/de/code/emergency_exit.ctp +++ b/templates/de/code/emergency_exit.ctp @@ -8,4 +8,13 @@ $content[message]
+
+
+ Backtrace: +
+
+ $content[backtrace] +
+
+ {?footer_msg:footer_msg="Please contact the support and supply the full above message, if you think you are not qualified to fix this problem."?} diff --git a/templates/de/code/header.ctp b/templates/de/code/header.ctp index 2b2457d157..cce846071d 100644 --- a/templates/de/code/header.ctp +++ b/templates/de/code/header.ctp @@ -1,5 +1,5 @@ - - + + $content[title] -- 2.30.2