From 8ff2f773e29b6628131d73271f5cac9b2756374e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jun 2008 18:05:10 +0000 Subject: [PATCH] Image generator added, first CAPTCHA added with missing controller (partly work) --- .gitattributes | 7 +- application/ship-simu/exceptions.php | 5 +- .../helper/class_ShipSimuLoginHelper.php | 2 +- .../templates/de/code/captch_graphic_code.ctp | 16 + .../exceptions/class_FrameworkException.php | 37 ++ .../main/class_ClassNotFoundException.php | 3 + .../xml/class_InvalidXmlNodeException.php | 1 - .../xml/class_XmlNodeMismatchException.php | 47 ++ .../main/class_BaseFrameworkSystem.php | 24 + .../commands/web/class_WebRegisterCommand.php | 3 + .../database/class_BaseDatabaseFrontend.php | 2 +- .../databases/class_LocalFileDatabase.php | 6 +- .../wrapper/class_NewsDatabaseWrapper.php | 2 +- .../wrapper/class_UserDatabaseWrapper.php | 2 +- .../main/filter/auth/class_UserAuthFilter.php | 2 +- inc/classes/main/filter/class_BaseFilter.php | 2 +- inc/classes/main/helper/class_BaseHelper.php | 29 +- .../main/helper/images/class_ImageHelper.php | 139 ++++- .../main/helper/web/class_WebFormHelper.php | 8 +- inc/classes/main/images/class_ | 3 + inc/classes/main/images/class_BaseImage.php | 511 +++++++++++++++++- .../main/images/extended/class_PngImage.php | 27 +- .../main/resolver/class_BaseResolver.php | 6 +- .../main/response/class_ImageResponse.php | 30 +- .../main/result/class_DatabaseResult.php | 4 +- .../template/class_BaseTemplateEngine.php | 208 ++++--- .../image/class_ImageTemplateEngine.php | 292 +++++++++- .../template/web/class_WebTemplateEngine.php | 3 - inc/classes/main/user/class_Guest.php | 6 +- inc/classes/main/user/class_User.php | 6 +- inc/config/class_FrameworkConfiguration.php | 4 +- inc/loader/class_ClassLoader.php | 2 + templates/images/_cache/.htaccess | 1 + .../image/{base_image.img => base_image.itp} | 15 +- templates/images/de/image/emergency_exit.img | 22 - templates/images/de/image/emergency_exit.itp | 40 ++ 36 files changed, 1326 insertions(+), 191 deletions(-) create mode 100644 application/ship-simu/templates/de/code/captch_graphic_code.ctp create mode 100644 inc/classes/exceptions/xml/class_XmlNodeMismatchException.php create mode 100644 templates/images/_cache/.htaccess rename templates/images/de/image/{base_image.img => base_image.itp} (54%) delete mode 100644 templates/images/de/image/emergency_exit.img create mode 100644 templates/images/de/image/emergency_exit.itp diff --git a/.gitattributes b/.gitattributes index 513b4ff..d593455 100644 --- a/.gitattributes +++ b/.gitattributes @@ -133,6 +133,7 @@ application/ship-simu/main/structures/extended/upper/class_Bridge.php -text application/ship-simu/starter.php -text application/ship-simu/templates/.htaccess -text application/ship-simu/templates/de/.htaccess -text +application/ship-simu/templates/de/code/captch_graphic_code.ctp -text application/ship-simu/templates/de/code/footer.ctp -text application/ship-simu/templates/de/code/header.ctp -text application/ship-simu/templates/de/code/home.ctp -text @@ -264,6 +265,7 @@ inc/classes/exceptions/user/class_UserPasswordMismatchException.php -text inc/classes/exceptions/user/class_UsernameMissingException.php -text inc/classes/exceptions/xml/.htaccess -text inc/classes/exceptions/xml/class_InvalidXmlNodeException.php -text +inc/classes/exceptions/xml/class_XmlNodeMismatchException.php -text inc/classes/exceptions/xml/class_XmlParserException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/actions/.htaccess -text @@ -638,10 +640,11 @@ templates/de/code/footer_msg.ctp -text templates/de/code/header.ctp -text templates/de/html/.htaccess -text templates/images/.htaccess -text +templates/images/_cache/.htaccess -text templates/images/de/.htaccess -text templates/images/de/image/.htaccess -text -templates/images/de/image/base_image.img -text -templates/images/de/image/emergency_exit.img -text +templates/images/de/image/base_image.itp -text +templates/images/de/image/emergency_exit.itp -text tests/ConfigTest.php -text tests/RegistryTest.php -text tests/RequestTest.php -text diff --git a/application/ship-simu/exceptions.php b/application/ship-simu/exceptions.php index b5b8bdc..69f0d9a 100644 --- a/application/ship-simu/exceptions.php +++ b/application/ship-simu/exceptions.php @@ -32,7 +32,10 @@ function __exceptionHandler (FrameworkException $e) { $e->getHexCode(), $e->getMessage(), $e->getPrintableBackTrace() - )); + ), + $e->getHexCode(), + $e->getExtraData() + ); } // END - function // Set the new handler diff --git a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php index 04b45c7..a4bebd6 100644 --- a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php +++ b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php @@ -36,7 +36,7 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin { private $authMethod = ""; // Exception constants - const EXCEPTION_INVALID_USER_INSTANCE = 0x080; + const EXCEPTION_INVALID_USER_INSTANCE = 0x900; /** * Protected constructor diff --git a/application/ship-simu/templates/de/code/captch_graphic_code.ctp b/application/ship-simu/templates/de/code/captch_graphic_code.ctp new file mode 100644 index 0000000..bb422da --- /dev/null +++ b/application/ship-simu/templates/de/code/captch_graphic_code.ctp @@ -0,0 +1,16 @@ +addFormGroup('captcha_code', "Unser Spiel ist durch ein grafisches CAPTCHA gesichert. Du musst den angezeigten Code wiederholen, damit du unser Spiel nutzen kannst."); +$helper->addFieldText('captcha_code', "Bitte wiederhole den Code:"); +$helper->addInputTextField('captcha_code'); +$helper->flushContent(); + +// [EOF] +?> +
+ CAPTCHA-Bild +
+
+ {?captcha_code?} +
diff --git a/inc/classes/exceptions/class_FrameworkException.php b/inc/classes/exceptions/class_FrameworkException.php index 34e4802..c36ba09 100644 --- a/inc/classes/exceptions/class_FrameworkException.php +++ b/inc/classes/exceptions/class_FrameworkException.php @@ -29,6 +29,11 @@ abstract class FrameworkException extends ReflectionException { */ private $backTrace = array(); + /** + * Extra data + */ + private $extraData = ""; + /** * The super constructor for all exceptions * @@ -44,6 +49,19 @@ abstract class FrameworkException extends ReflectionException { $message = (string) $message; $code = (int) $code; + // In emergency exit? + if (defined('EMERGENCY_EXIT_CALLED')) { + // Output message + printf("[%s:] Message: %s, Backtrace:
%s
", + $this->__toString(), + $message, + $this->getPrintableBackTrace() + ); + + // End here + exit; + } // END - if + // Make sure everything is assigned properly parent::__construct($message, $code); } @@ -150,6 +168,25 @@ abstract class FrameworkException extends ReflectionException { // Return it return $hexCode; } + + /** + * Setter for extra data + * + * @param $extraData Extra data to store + * @return void + */ + protected final function setExtraData ($extraData) { + $this->extraData = $extraData; + } + + /** + * Getter for extra data + * + * @return $extraData Extra data to store + */ + public final function getExtraData () { + return $this->extraData; + } } // [EOF] diff --git a/inc/classes/exceptions/main/class_ClassNotFoundException.php b/inc/classes/exceptions/main/class_ClassNotFoundException.php index 3c9511c..5ced9d8 100644 --- a/inc/classes/exceptions/main/class_ClassNotFoundException.php +++ b/inc/classes/exceptions/main/class_ClassNotFoundException.php @@ -37,6 +37,9 @@ class ClassNotFoundException extends FrameworkException { $msgArray[1] ); + // Set extra data + $this->setExtraData($msgArray[1]); + // Call parent constructor parent::__construct($message, $code); } diff --git a/inc/classes/exceptions/xml/class_InvalidXmlNodeException.php b/inc/classes/exceptions/xml/class_InvalidXmlNodeException.php index 75a2353..eb52f0c 100644 --- a/inc/classes/exceptions/xml/class_InvalidXmlNodeException.php +++ b/inc/classes/exceptions/xml/class_InvalidXmlNodeException.php @@ -43,7 +43,6 @@ class InvalidXmlNodeException extends FrameworkException { $classArray[1], $attributes ); - die($message); // Call parent exception constructor parent::__construct($message, $code); diff --git a/inc/classes/exceptions/xml/class_XmlNodeMismatchException.php b/inc/classes/exceptions/xml/class_XmlNodeMismatchException.php new file mode 100644 index 0000000..a9357b4 --- /dev/null +++ b/inc/classes/exceptions/xml/class_XmlNodeMismatchException.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 XmlNodeMismatchException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $classArray Array holding the exception data + * @param $code Error code + * @return void + */ + public function __construct (array $classArray, $code) { + // Construct our message + $message = sprintf("[%s:%d] XML nodes mismatch. Given: %s, Expected: %s", + $classArray[0]->__toString(), + $this->getLine(), + $lassArray[1], + $lassArray[2] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 132d5be..a4052ef 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -63,6 +63,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $resolverInstance = null; + /** + * Template engine instance + */ + private $templateInstance = null; + /** * The real class name */ @@ -320,6 +325,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } } + /** + * 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; + } + /** * Setter for search instance * diff --git a/inc/classes/main/commands/web/class_WebRegisterCommand.php b/inc/classes/main/commands/web/class_WebRegisterCommand.php index 0ad939d..5448e2a 100644 --- a/inc/classes/main/commands/web/class_WebRegisterCommand.php +++ b/inc/classes/main/commands/web/class_WebRegisterCommand.php @@ -78,6 +78,9 @@ class WebRegisterCommand extends BaseCommand implements Commandable, Registerabl // Assign all the application's data with template variables $templateInstance->assignApplicationData($appInstance); + // Assign base URL + $templateInstance->assignConfigVariable('base_url'); + // Load the master template $masterTemplate = $appInstance->getMasterTemplate(); diff --git a/inc/classes/main/database/class_BaseDatabaseFrontend.php b/inc/classes/main/database/class_BaseDatabaseFrontend.php index c53fb4e..046ae8b 100644 --- a/inc/classes/main/database/class_BaseDatabaseFrontend.php +++ b/inc/classes/main/database/class_BaseDatabaseFrontend.php @@ -24,7 +24,7 @@ */ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements DatabaseFrontendInterface { // Constants for exceptions - const EXCEPTION_SQL_QUERY = 0x050; + const EXCEPTION_SQL_QUERY = 0x500; /** * The limiter instance diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index b3ee46e..81ad7fd 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -26,9 +26,9 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontendInterface { // Constants for MySQL backward-compatiblity (PLEASE FIX THEM!) - const DB_CODE_TABLE_MISSING = 0x010; - const DB_CODE_TABLE_UNWRITEABLE = 0x011; - const DB_CODE_DATA_FILE_CORRUPT = 0x012; + const DB_CODE_TABLE_MISSING = 0x100; + const DB_CODE_TABLE_UNWRITEABLE = 0x101; + const DB_CODE_DATA_FILE_CORRUPT = 0x102; /** * Save path for "file database" diff --git a/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php index c8c43dc..1b8b6ad 100644 --- a/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php @@ -29,7 +29,7 @@ class NewsDatabaseWrapper extends BaseDatabaseWrapper { private $cacheInstance = null; // Constants for exceptions - const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x070; + const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x700; // Constants for database columns diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index e2ff935..f1caa49 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -29,7 +29,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { private $cacheInstance = null; // Constants for exceptions - const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x070; + const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x800; // Constants for database columns const DB_COLUMN_USERNAME = "username"; diff --git a/inc/classes/main/filter/auth/class_UserAuthFilter.php b/inc/classes/main/filter/auth/class_UserAuthFilter.php index a75e7be..fc001a3 100644 --- a/inc/classes/main/filter/auth/class_UserAuthFilter.php +++ b/inc/classes/main/filter/auth/class_UserAuthFilter.php @@ -23,7 +23,7 @@ */ class UserAuthFilter extends BaseFilter implements Filterable { // Exception constants - const EXCEPTION_AUTH_DATA_INVALID = 0x0a0; + const EXCEPTION_AUTH_DATA_INVALID = 0xb00; /** * The login method we shall choose diff --git a/inc/classes/main/filter/class_BaseFilter.php b/inc/classes/main/filter/class_BaseFilter.php index 3800c49..195d3e1 100644 --- a/inc/classes/main/filter/class_BaseFilter.php +++ b/inc/classes/main/filter/class_BaseFilter.php @@ -23,7 +23,7 @@ */ class BaseFilter extends BaseFrameworkSystem { // Exception constants - const EXCEPTION_FILTER_CHAIN_ABORTED = 0x090; + const EXCEPTION_FILTER_CHAIN_ABORTED = 0xa00; /** * Protected constructor diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php index d266d5b..2c0c3c8 100644 --- a/inc/classes/main/helper/class_BaseHelper.php +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -23,13 +23,9 @@ */ class BaseHelper extends BaseFrameworkSystem { // Exception constants - const EXCEPTION_XML_PARSER_ERROR = 0x0d0; - const EXCEPTION_XML_NODE_UNKNOWN = 0x0d1; - - /** - * Template engine instance - */ - private $templateInstance = null; + const EXCEPTION_XML_PARSER_ERROR = 0xe00; + const EXCEPTION_XML_NODE_UNKNOWN = 0xe01; + const EXCEPTION_XML_NODE_MISMATCH = 0xe02; /** * Rendered content created by the helper class @@ -51,25 +47,6 @@ class BaseHelper extends BaseFrameworkSystem { $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 * diff --git a/inc/classes/main/helper/images/class_ImageHelper.php b/inc/classes/main/helper/images/class_ImageHelper.php index 5490a40..84081a1 100644 --- a/inc/classes/main/helper/images/class_ImageHelper.php +++ b/inc/classes/main/helper/images/class_ImageHelper.php @@ -27,6 +27,11 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { */ private $imageType = "png"; + /** + * The image name + */ + private $imageName = ""; + /** * Width of the image in pixel */ @@ -56,9 +61,14 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { ); /** - * Image message string + * All image strings */ - private $imageString = "No message set!"; + private $imageStrings = array(); + + /** + * Current string name + */ + private $currString = ""; /** * Protected constructor @@ -105,7 +115,7 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { } /** - * Getter for image type + * Getter for image name * * @return $imageType Type of the image */ @@ -113,6 +123,44 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { return $this->imageType; } + /** + * Setter for base image + * + * @param $baseImage A base image template + * @return void + */ + public final function setBaseImage ($baseImage) { + $this->baseImage = (string) $baseImage; + } + + /** + * Getter for base image + * + * @return $baseImage A base image template + */ + public final function getBaseImage () { + return $this->baseImage; + } + + /** + * Setter for image name + * + * @param $imageName Name of the image + * @return void + */ + public final function setImageName ($imageName) { + $this->imageName = (string) $imageName; + } + + /** + * Getter for image name + * + * @return $imageName Name of the image + */ + protected final function getImageName () { + return $this->imageName; + } + /** * Setter for image width * @@ -179,6 +227,24 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { $this->foregroundColor['blue'] = (int) $blue; } + /** + * Adds an image string to the buffer by the given string name + * + * @param $stringName String name (identifier) + */ + public function addTextLine ($stringName) { + // Create the image string + $this->imageStrings[$stringName] = array( + 'x' => "", + 'y' => "", + 'size' => "", + 'string' => "" + ); + + // Set current string name + $this->currString = $stringName; + } + /** * Setter for image message string * @@ -186,7 +252,7 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { * @return void */ public final function setImageString ($imageString) { - $this->imageString = (string) $imageString; + $this->imageStrings[$this->currString]['string'] = (string) $imageString; } /** @@ -195,26 +261,56 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { * @return $imageString A message to display in the image */ public final function getImageString () { - return $this->imageString; + return $this->imageStrings[$this->currString]['string']; } /** - * Setter for base image + * Setter for X/Y coordinates for strings * - * @param $baseImage A base image template + * @param $x X coordinate + * @param $y Y coordinate * @return void */ - public final function setBaseImage ($baseImage) { - $this->baseImage = (string) $baseImage; + public final function setCoord ($x, $y) { + $this->imageStrings[$this->currString]['x'] = (int) $x; + $this->imageStrings[$this->currString]['y'] = (int) $y; } /** - * Getter for base image + * Getter for X coordinate * - * @return $baseImage A base image template + * @return $x X coordinate */ - public final function getBaseImage () { - return $this->baseImage; + public final function getX () { + return $this->imageStrings[$this->currString]['x']; + } + + /** + * Getter for Y coordinate + * + * @return $y Y coordinate + */ + public final function getY () { + return $this->imageStrings[$this->currString]['y']; + } + + /** + * Setter for font size + * + * @param $fontSize Font size for strings + * @return void + */ + public final function setFontSize ($fontSize) { + $this->imageStrings[$this->currString]['size'] = (int) $fontSize; + } + + /** + * Getter for font size + * + * @return $fontSize Font size for strings + */ + public final function getFontSize () { + return $this->imageStrings[$this->currString]['size']; } /** @@ -230,6 +326,7 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { $templateInstance->loadCodeTemplate($this->getBaseImage()); // Assign all the image values with the template + $templateInstance->assignVariable("image_name" , $this->getImageName()); $templateInstance->assignVariable("image_type" , $this->getImageType()); $templateInstance->assignVariable("image_width" , $this->getWidth()); $templateInstance->assignVariable("image_height" , $this->getHeight()); @@ -239,7 +336,21 @@ class ImageHelper extends BaseHelper implements HelpableTemplate { $templateInstance->assignVariable("image_fg_red" , $this->foregroundColor['red']); $templateInstance->assignVariable("image_fg_green", $this->foregroundColor['green']); $templateInstance->assignVariable("image_fg_blue" , $this->foregroundColor['blue']); - $templateInstance->assignVariable("image_string" , $this->getImageString()); + + // Add all strings + foreach ($this->imageStrings as $id=>$imageString) { + // Set current string id + $this->currString = $id; + + // Set variable group + $templateInstance->setVariableGroup($id); + + // Add group variables + $templateInstance->addGroupVariable("image_x" , $this->getX()); + $templateInstance->addGroupVariable("image_y" , $this->getY()); + $templateInstance->addGroupVariable("image_size" , $this->getFontSize()); + $templateInstance->addGroupVariable("image_string", $this->getImageString()); + } // END - foreach // Get the raw content $imageContent = $templateInstance->getRawTemplateData(); diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index 8d20001..43ea978 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -59,10 +59,10 @@ class WebFormHelper extends BaseHelper implements HelpableTemplate { private $formEnabled = true; // Class Constants - const EXCEPTION_FORM_NAME_INVALID = 0x030; - const EXCEPTION_CLOSED_FORM = 0x031; - const EXCEPTION_OPENED_FORM = 0x032; - const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x033; + const EXCEPTION_FORM_NAME_INVALID = 0x300; + const EXCEPTION_CLOSED_FORM = 0x301; + const EXCEPTION_OPENED_FORM = 0x302; + const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x303; /** * Protected constructor diff --git a/inc/classes/main/images/class_ b/inc/classes/main/images/class_ index 9a90092..5ff2290 100644 --- a/inc/classes/main/images/class_ +++ b/inc/classes/main/images/class_ @@ -47,6 +47,9 @@ class ???Image extends BaseImage { // Get a new instance $imageInstance = new ???Image(); + // Set image type + $imageInstance->setImageType("???"); + // Return the instance return $imageInstance; } diff --git a/inc/classes/main/images/class_BaseImage.php b/inc/classes/main/images/class_BaseImage.php index 2273945..356f418 100644 --- a/inc/classes/main/images/class_BaseImage.php +++ b/inc/classes/main/images/class_BaseImage.php @@ -21,7 +21,65 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseImage extends BaseFrameworkSystem { +class BaseImage extends BaseFrameworkSystem implements Registerable { + /** + * Image type + */ + private $imageType = ""; + + /** + * Width of the image + */ + private $width = ""; + + /** + * Height of the image + */ + private $height = ""; + + /** + * Background color in RGB + */ + private $backgroundColor = array( + 'red' => "", + 'green' => "", + 'blue' => "" + ); + + /** + * Foreground color in RGB + */ + private $foregroundColor = array( + 'red' => "", + 'green' => "", + 'blue' => "" + ); + + /** + * Current choosen color array + */ + private $colorMode = ""; + + /** + * Image resource + */ + private $imageResource = null; + + /** + * Image name + */ + private $imageName = ""; + + /** + * String name + */ + private $stringName = ""; + + /** + * Groupable image strings? + */ + private $groupable = "single"; + /** * Protected constructor * @@ -36,7 +94,456 @@ class BaseImage extends BaseFrameworkSystem { $this->removeNumberFormaters(); $this->removeSystemArray(); } -} + /** + * Private setter for all colors + * + * @param $colorMode Wether background or foreground color + * @param $colorChannel Red, green or blue channel? + * @param $colorValue Value to set + */ + private final function setColor ($colorMode, $colorChannel, $colorValue) { + // Construct the eval() command + $eval = sprintf("\$this->%s['%s'] = \"%s\";", + $colorMode, + $colorChannel, + $colorValue + ); + + // Run the command + //* DEBUG: */ echo "mode={$colorMode}, channel={$colorChannel}, value={$colorValue}
\n"; + eval($eval); + } + + /** + * Setter for image width + * + * @param $width Width of the image + * @return void + */ + public final function setWidth ($width) { + $this->width = $width; + } + + /** + * Getter for image width + * + * @return $width Width of the image + */ + public final function getWidth () { + return $this->width; + } + + /** + * Setter for image height + * + * @param $height Height of the image + * @return void + */ + public final function setHeight ($height) { + $this->height = $height; + } + + /** + * Getter for image height + * + * @return $height Height of the image + */ + public final function getHeight () { + return $this->height; + } + + /** + * Finish the type handling (unused at the moment) + * + * @return void + * @todo Find something usefull for this method. + */ + public function finishType () { + // Empty at the momemt + } + + /** + * Prepares the class for resolution (unused at the moment) + * + * @return void + * @todo Find something usefull for this method. + */ + public function initResolution () { + // Empty at the momemt + } + + /** + * Finish resolution handling (unused at the moment) + * + * @return void + * @todo Find something usefull for this method. + */ + public function finishResolution () { + // Empty at the momemt + } + + /** + * Prepares the class for base (unused at the moment) + * + * @return void + * @todo Find something usefull for this method. + */ + public function initBase () { + // Empty at the momemt + } + + /** + * Finish base handling (unused at the moment) + * + * @return void + * @todo Find something usefull for this method. + */ + public function finishBase () { + // Empty at the momemt + } + + /** + * Prepares the class for background color + * + * @return void + */ + public function initBackgroundColor () { + $this->colorMode = "backgroundColor"; + } + + /** + * Finish background color handling + * + * @return void + * @todo Find something usefull for this method. + */ + public function finishBackgroundColor () { + // Empty at the moment + } + + /** + * Prepares the class for foreground color + * + * @return void + */ + public function initForegroundColor () { + $this->colorMode = "foregroundColor"; + } + + /** + * Finish foreground color handling + * + * @return void + * @todo Find something usefull for this method. + */ + public function finishForegroundColor () { + // Empty at the moment + } + + /** + * Prepares the class for string (unused at the moment) + * + * @param $groupable Wether this image string is groupable or single + * @return void + * @todo Find something usefull for this method. + */ + public function initImageString ($groupable = "single") { + $this->groupable = $groupable; + } + + /** + * Finish string handling (unused at the moment) + * + * @return void + * @todo Find something usefull for this method. + */ + public function finishImageString () { + // Empty at the momemt + } + + /** + * Setter for red color + * + * @param $red Red color value + * @return void + */ + public final function setRed ($red) { + // Get array name + $arrayName = $this->colorMode; + + // Set image color + $this->setColor($arrayName, 'red', $red); + } + + /** + * Setter for green color + * + * @param $green Green color value + * @return void + */ + public final function setGreen ($green) { + // Get array name + $arrayName = $this->colorMode; + + // Set image color + $this->setColor($arrayName, 'green', $green); + } + + /** + * Setter for blue color + * + * @param $blue Blue color value + * @return void + */ + public final function setBlue ($blue) { + // Get array name + $arrayName = $this->colorMode; + + // Set image color + $this->setColor($arrayName, 'blue', $blue); + } + + /** + * Setter for image string + * + * @param $string String to set in image + * @return void + */ + public final function setString ($string) { + $this->imageString = (string) $string; + } + + /** + * Getter for image string + * + * @return $string String to set in image + */ + public final function getString () { + return $this->imageString; + } + + /** + * Setter for image type + * + * @param $imageType Type to set in image + * @return void + */ + protected final function setImageType ($imageType) { + $this->imageType = (string) $imageType; + } + + /** + * Getter for image type + * + * @return $imageType Type to set in image + */ + public final function getImageType () { + return $this->imageType; + } + + /** + * Setter for image name + * + * @param $name Name of the image + * @return void + */ + public final function setImageName ($name) { + $this->imageName = (string) $name; + } + + /** + * Getter for image name + * + * @return $name Name of the image + */ + public final function getImageName () { + return $this->imageName; + } + + /** + * Getter for image resource + * + * @return $imageResource An image resource from imagecreatetruecolor() function + */ + public final function getImageResource() { + return $this->imageResource; + } + + /** + * Setter for X coordinate + * + * @param $x X coordinate + * @return void + */ + public final function setX ($x) { + $this->x = $x; + } + + /** + * Getter for X coordinate + * + * @return $x X coordinate + */ + public final function getX () { + return $this->x; + } + + /** + * Setter for Y coordinate + * + * @param $y Y coordinate + * @return void + */ + public final function setY ($y) { + $this->y = $y; + } + + /** + * Getter for Y coordinate + * + * @return $y Y coordinate + */ + public final function getY () { + return $this->y; + } + + /** + * Setter for font size + * + * @param $fontSize Font size for strings + * @return void + */ + public final function setFontSize ($fontSize) { + $this->fontSize = $fontSize; + } + + /** + * Getter for font size + * + * @return $fontSize Font size for strings + */ + public final function getFontSize () { + return $this->fontSize; + } + + /** + * Setter for string name + * + * @param $stringName String name to set + * @return void + */ + public final function setStringName($stringName) { + $this->stringName = $stringName; + } + + /** + * Finish this image by producing it + * + * @return void + */ + public function finishImage () { + // Get template instance + $templateInstance = $this->getTemplateInstance(); + + // Compile width and height + $width = $templateInstance->compileRawCode($this->getWidth()); + $height = $templateInstance->compileRawCode($this->getHeight()); + + // Set both again + $this->setWidth($width); + $this->setHeight($height); + + // Get a image resource + $this->imageResource = imagecreatetruecolor($width, $height); + + // Compile background colors + $red = $templateInstance->compileRawCode($this->backgroundColor['red']); + $green = $templateInstance->compileRawCode($this->backgroundColor['green']); + $blue = $templateInstance->compileRawCode($this->backgroundColor['blue']); + + // Set all back + $this->initBackgroundColor(); + $this->setRed($red); + $this->setGreen($green); + $this->setBlue($blue); + + // Get a pointer for background color + $backColor = imagecolorallocate($this->imageResource, $red, $green, $blue); + + // Fill the image + imagefill($this->imageResource, 0, 0, $backColor); + + // Compile foreground colors + $red = $templateInstance->compileRawCode($this->foregroundColor['red']); + $green = $templateInstance->compileRawCode($this->foregroundColor['green']); + $blue = $templateInstance->compileRawCode($this->foregroundColor['blue']); + + // Set all fore + $this->initForegroundColor(); + $this->setRed($red); + $this->setGreen($green); + $this->setBlue($blue); + + // Get a pointer for foreground color + $foreColor = imagecolorallocate($this->imageResource, $red, $green, $blue); + + switch ($this->groupable) { + case "single": // Single image string + // Compile image string + $imageString = $templateInstance->compileRawCode($this->getString()); + + // Set it back + $this->setString($imageString); + + // Compile X/Y coordinates and font size + $x = $templateInstance->compileRawCode($this->getX()); + $y = $templateInstance->compileRawCode($this->getY()); + $size = $templateInstance->compileRawCode($this->getFontSize()); + + // Set the image string + imagestring($this->imageResource, $size, $x, $y, $imageString, $foreColor); + break; + + case "groupable": // More than one string allowed + // Walk through all groups + foreach ($templateInstance->getVariableGroups() as $group => $set) { + // Set the group + $templateInstance->setVariableGroup($group, false); + + // Compile image string + $imageString = $templateInstance->compileRawCode($this->getString()); + + // Compile X/Y coordinates and font size + $x = $templateInstance->compileRawCode($this->getX()); + $y = $templateInstance->compileRawCode($this->getY()); + $size = $templateInstance->compileRawCode($this->getFontSize()); + + // Set the image string + //* DEBUG: */ echo __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}
\n"; + imagestring($this->imageResource, $size, $x, $y, $imageString, $foreColor); + } // END - foreach + break; + } + + // You need finishing in your image class! + } + + /** + * Getter for full created image content + * + * @return $imageContent The raw image content + */ + public function getContent () { + // Get cache file name + $cacheFile = $this->getTemplateInstance()->getImageCacheFqfn(); + + // Load the content + $imageContent = file_get_contents($cacheFile); + + // And return it + return $imageContent; + } +} // [EOF] ?> diff --git a/inc/classes/main/images/extended/class_PngImage.php b/inc/classes/main/images/extended/class_PngImage.php index 4693a3d..e5f184d 100644 --- a/inc/classes/main/images/extended/class_PngImage.php +++ b/inc/classes/main/images/extended/class_PngImage.php @@ -41,15 +41,38 @@ class PngImage extends BaseImage { /** * Creates an instance of this image class * - * @return $imageInstance An instance of this image class + * @param $templateInstance A template instance + * @return $imageInstance An instance of this image class */ - public final static function createPngImage() { + public final static function createPngImage(CompileableTemplate $templateInstance) { // Get a new instance $imageInstance = new PngImage(); + // Set template instance + $imageInstance->setTemplateInstance($templateInstance); + + // Set image type + $imageInstance->setImageType("png"); + // Return the instance return $imageInstance; } + + /** + * Finish this image by producing it + * + * @return void + */ + public function finishImage () { + // Call parent method + parent::finishImage(); + + // Get a file name for our image + $cacheFile = $this->getTemplateInstance()->getImageCacheFqfn(); + + // Finish the image and send it to a cache file + imagepng($this->getImageResource(), $cacheFile, 9, PNG_ALL_FILTERS); + } } // [EOF] diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index eedeef3..539a425 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -28,9 +28,9 @@ class BaseResolver extends BaseFrameworkSystem { private $className = ""; // Exception constants - const EXCEPTION_INVALID_COMMAND = 0x0c0; - const EXCEPTION_INVALID_CONTROLLER = 0x0c1; - const EXCEPTION_INVALID_ACTION = 0x0c2; + const EXCEPTION_INVALID_COMMAND = 0xd00; + const EXCEPTION_INVALID_CONTROLLER = 0xd01; + const EXCEPTION_INVALID_ACTION = 0xd02; /** * Protected constructor diff --git a/inc/classes/main/response/class_ImageResponse.php b/inc/classes/main/response/class_ImageResponse.php index 2e2fd09..3d16954 100644 --- a/inc/classes/main/response/class_ImageResponse.php +++ b/inc/classes/main/response/class_ImageResponse.php @@ -55,6 +55,11 @@ class ImageResponse extends BaseFrameworkSystem implements Responseable { */ private $fatalMessages = array(); + /** + * Instance of the image + */ + private $imageInstance = null; + /** * Protected constructor * @@ -170,6 +175,7 @@ class ImageResponse extends BaseFrameworkSystem implements Responseable { $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 + $this->addHeader('Content-type', 'image/'.$this->imageInstance->getImageType()); // Define the charset to be used //$this->addHeader('Content-Type:', sprintf("text/html; charset=%s", $this->getConfigInstance()->readConfig('header_charset'))); @@ -191,14 +197,12 @@ class ImageResponse extends BaseFrameworkSystem implements Responseable { // Are there some error messages? if (count($this->fatalMessages) == 0) { - // Flush the output to the world - $this->getWebOutputInstance()->output($this->responseBody); + // Get image content from cache + $imageContent = $this->imageInstance->getContent(); + die($imageContent); } else { // Display all error messages - $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages); - - // Send the error messages out to the world - $this->getWebOutputInstance()->output($this->responseBody); + $this->partialStub("Fatal messages are currently unsupported in image response."); } // Clear response header and body @@ -218,8 +222,8 @@ class ImageResponse extends BaseFrameworkSystem implements Responseable { // Set new template engine $cfg->setConfigEntry('template_class', "ImageTemplateEngine"); - $cfg->setConfigEntry('raw_template_extension', ".img"); - $cfg->setConfigEntry('code_template_extension', ".img"); + $cfg->setConfigEntry('raw_template_extension', ".itp"); + $cfg->setConfigEntry('code_template_extension', ".itp"); $cfg->setConfigEntry('tpl_base_path', "templates/images/"); $cfg->setConfigEntry('code_template_type', "image"); @@ -370,6 +374,16 @@ class ImageResponse extends BaseFrameworkSystem implements Responseable { $this->addCookie($cookieName, $_COOKIE[$cookieName], false); } // END - if } + + /** + * Setter for image instanxe + * + * @param $imageInstance An instance of an image + * @return void + */ + public final function setImageInstance (BaseImage $imageInstance) { + $this->imageInstance = $imageInstance; + } } // [EOF] diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index 75948a6..08bf403 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -23,8 +23,8 @@ */ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, UpdateableResult, SeekableIterator { // Exception constants - const EXCEPTION_INVALID_DATABASE_RESULT = 0x0b0; - const EXCEPTION_RESULT_UPDATE_FAILED = 0x0b1; + const EXCEPTION_INVALID_DATABASE_RESULT = 0xc00; + const EXCEPTION_RESULT_UPDATE_FAILED = 0xc01; /** * Current position in array diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 7188fda..00691ef 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -65,10 +65,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { private $lastTemplate = ""; /** - * The variable stack for the templates. This must be initialized and - * shall become an instance of FrameworkArrayObject. + * The variable stack for the templates */ - private $varStack = null; + private $varStack = array(); /** * Configuration variables in a simple array @@ -112,20 +111,20 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private $helpers = array(); - // Exception codes for the template engine - const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x020; - const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x021; - const EXCEPTION_INVALID_VIEW_HELPER = 0x022; + /** + * Current variable group + */ + private $currGroup = "general"; /** - * Initialize the variable stack. This holds all variables for later - * compilation. - * - * @return void + * All template groups except "general" */ - public final function initVariableStack () { - $this->varStack = new FrameworkArrayObject("FakedVariableStack"); - } + private $varGroups = array(); + + // Exception codes for the template engine + const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x200; + const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x201; + const EXCEPTION_INVALID_VIEW_HELPER = 0x202; /** * Protected constructor @@ -152,18 +151,18 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // First everything is not found $found = false; - // Now search for it - for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { - // Get current item - $currEntry = $idx->current(); - - // Is the entry found? - if ($currEntry['name'] == $var) { - // Found! - $found = $idx->key(); - break; - } - } + // Is the group there? + if (isset($this->varStack[$this->currGroup])) { + // Now search for it + foreach ($this->varStack[$this->currGroup] as $idx=>$currEntry) { + // Is the entry found? + if ($currEntry['name'] == $var) { + // Found! + $found = $idx; + break; + } // END - if + } // END - foreach + } // END - if // Return the current position return $found; @@ -179,21 +178,19 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // First everything is not found $content = null; - // Now search for it - for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { - // Get current item - $currEntry = $idx->current(); + // Get variable index + $found = $this->isVariableAlreadySet($var); - // Is the entry found? - if ($currEntry['name'] == $var) { - // Found! - $content = $currEntry['value']; - break; - } - } + // Is the variable found? + if ($found !== false) { + // Read it + $found = $this->varStack[$this->currGroup][$found]['value']; + } // END - if + + //* DEBUG: */ echo __METHOD__.": group=".$this->currGroup.",var=".$var.", found=".$found."
\n"; // Return the current position - return $content; + return $found; } /** @@ -204,11 +201,72 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @return void */ private function addVariable ($var, $value) { + // Set general variable group + $this->setVariableGroup("general"); + // Add it to the stack - $this->varStack->append(array( - 'name' => trim($var), - 'value' => trim($value) - )); + $this->addGroupVariable($var, $value); + } + + /** + * Returns all variables of current group or empty array + * + * @return $result Wether array of found variables or empty array + */ + private function readCurrentGroup () { + // Default is not found + $result = array(); + + // Is the group there? + if (isset($this->varStack[$this->currGroup])) { + // Then use it + $result = $this->varStack[$this->currGroup]; + } // END - if + + // Return result + return $result; + } + + /** + * Settter for variable group + * + * @param $groupName Name of variable group + * @param $add Wether add this group + * @return void + */ + public function setVariableGroup ($groupName, $add = true) { + // Set group name + //* DEBIG: */ echo __METHOD__.": currGroup=".$groupName."
\n"; + $this->currGroup = $groupName; + + // Skip group "general" + if (($groupName != "general") && ($add === true)) { + $this->varGroups[$groupName] = "OK"; + } // END - if + } + + + /** + * Adds a variable to current group + * + * @param $var Variable to set + * @param $value Value to store in variable + * @return void + */ + public function addGroupVariable ($var, $value) { + //* DEBUG: */ echo __METHOD__.": group=".$this->currGroup.", var=".$var.", value=".$value."
\n"; + + // Get current variables in group + $currVars = $this->readCurrentGroup(); + + // Append our variable + $currVars[] = array( + 'name' => $var, + 'value' => $value + ); + + // Add it to the stack + $this->varStack[$this->currGroup] = $currVars; } /** @@ -219,20 +277,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @return void */ private function modifyVariable ($var, $value) { - // It should be there so let's look again... - for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { - // Get current entry - $currEntry = $idx->current(); - - // Is this the requested variable? - if ($currEntry['name'] == $var) { - // Change it to the other value - $this->varStack->offsetSet($idx->key(), array( - 'name' => $var, - 'value' => $value - )); - } - } + // Get index for variable + $idx = $this->isVariableAlreadySet($var); + + // Is the variable set? + if ($idx !== false) { + // Then modify it + $this->varStack[$this->currGroup][$idx]['value'] = $value; + } // END - if } /** @@ -494,7 +546,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { throw new MissingMethodException(array($ioInstance, 'loadFileContents'), self::EXCEPTION_MISSING_METHOD); } - /* DEBUG: */ echo __METHOD__.": FQFN=".$fqfn."
\n"; + // Some debug code to look on the file which is being loaded + //* DEBUG: */ echo __METHOD__.": FQFN=".$fqfn."
\n"; // Load the raw template $rawTemplateData = $ioInstance->loadFileContents($fqfn); @@ -803,10 +856,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $content = $this->getRawTemplateData(); // Walk through all variables - for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { - // Get current entry - $currEntry = $idx->current(); - + foreach ($this->varStack['general'] as $currEntry) { // Replace all [$var] or {?$var?} with the content //* DEBUG: */ echo "name=".$currEntry['name'].", value=
".htmlentities($currEntry['value'])."
\n"; $content = str_replace("\$content[".$currEntry['name']."]", $currEntry['value'], $content); @@ -901,12 +951,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $validVar = $this->getConfigInstance()->readConfig('tpl_valid_var'); $dummy = array(); - // Iterate through all variables - for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { - - // Get current variable from the stack - $currVariable = $idx->current(); - + // Iterate through all general variables + foreach ($this->varStack['general'] as $currVariable) { // Transfer it's name/value combination to the $content array //* DEBUG: */ echo $currVariable['name']."=
".htmlentities($currVariable['value'])."
\n"; $dummy[$currVariable['name']] = $currVariable['value']; @@ -1054,7 +1100,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * * @return void */ - public final function output () { + public function output () { // Check which type of template we have switch ($this->getTemplateType()) { case "html": // Raw HTML templates can be send to the output buffer @@ -1079,7 +1125,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Loads a given view helper (by name) * - * @param $helperName The helper's name + * @param $helperName The helper's name * @return void * @throws ViewHelperNotFoundException If the given view helper was not found */ @@ -1165,19 +1211,37 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $rawCode Raw code to compile * @return $rawCode Compile code with inserted variable value */ - protected function compileRawCode ($rawCode) { + public function compileRawCode ($rawCode) { // Find the variables + //* DEBUG: */ echo "rawCode=
".htmlentities($rawCode)."
\n"; preg_match_all($this->regExpVarValue, $rawCode, $varMatches); // Compile all variables + //* DEBUG: */ echo "
".print_r($varMatches, true)."
"; foreach ($varMatches[0] as $match) { - // Replace the variable with it's value, if found - $rawCode = str_replace("{?".$match."?}", $this->readVariable($match), $rawCode); + // Add variable tags around it + $varCode = "{?".$match."?}"; + + // Is the variable found in code? (safes some calls) + if (strpos($rawCode, $varCode) !== false) { + // Replace the variable with it's value, if found + //* DEBUG: */ echo __METHOD__.": match=".$match."
\n"; + $rawCode = str_replace($varCode, $this->readVariable($match), $rawCode); + } // END - if } // END - foreach // Return the compiled data return $rawCode; } + + /** + * Getter for variable group array + * + * @return $vargroups All variable groups + */ + public final function getVariableGroups () { + return $this->varGroups; + } } // [EOF] diff --git a/inc/classes/main/template/image/class_ImageTemplateEngine.php b/inc/classes/main/template/image/class_ImageTemplateEngine.php index 6e80fd1..c2542d8 100644 --- a/inc/classes/main/template/image/class_ImageTemplateEngine.php +++ b/inc/classes/main/template/image/class_ImageTemplateEngine.php @@ -25,18 +25,23 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl /** * Main nodes in the XML tree ("image" is ignored) */ - private $mainNodes = array("type", "resolution", "background-color", "foreground-color", "image-string"); + private $mainNodes = array("base", "type", "resolution", "background-color", "foreground-color", "image-string"); /** * Sub nodes in the XML tree */ - private $subNodes = array("width", "height", "red", "green", "blue", "text"); + private $subNodes = array("name", "string-name", "x", "y", "font-size", "width", "height", "red", "green", "blue", "text"); /** * Image instance */ private $imageInstance = null; + /** + * Current main node + */ + private $currMainNode = ""; + /** * Protected constructor * @@ -96,9 +101,6 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl // Set the base path $tplInstance->setBasePath($basePath); - // Initialize the variable stack - $tplInstance->initVariableStack(); - // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); $tplInstance->setFileIoInstance($ioInstance); @@ -148,7 +150,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl /** * Handles the start element of an XML resource * - * @param $resource XML parser resource + * @param $resource XML parser resource (currently ignored) * @param $element The element we shall handle * @param $attributes All attributes * @return void @@ -162,6 +164,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $element = strtolower($element); // Is the element a main node? + //* DEBUG: */ echo "START: >".$element."<
\n"; if (in_array($element, $this->mainNodes)) { // Okay, main node found! $methodName = "setImage" . $this->convertToClassName($element); @@ -170,7 +173,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $methodName = "setImageProperty" . $this->convertToClassName($element); } elseif ($element != "image") { // Invalid node name found - throw new InvalidXmlNodeException(array($this, $element, $attributes), self::EXCEPTION_XML_NODE_UNKNOWN); + throw new InvalidXmlNodeException(array($this, $element, $attributes), BaseHelper::EXCEPTION_XML_NODE_UNKNOWN); } // Call method @@ -178,6 +181,57 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl call_user_func_array(array($this, $methodName), $attributes); } + /** + * Ends the main or sub node by sending out the gathered data + * + * @param $resource An XML resource pointer (currently ignored) + * @param $nodeName Name of the node we want to finish + * @return void + * @throws XmlNodeMismatchException If current main node mismatches the closing one + */ + public function endElement ($resource, $nodeName) { + // Make all lower-case + $nodeName = strtolower($nodeName); + + // Does this match with current main node? + //* DEBUG: */ echo "END: >".$nodeName."<
\n"; + if (($nodeName != $this->currMainNode) && (in_array($nodeName, $this->mainNodes))) { + // Did not match! + throw new XmlNodeMismatchException (array($this, $nodeName, $this->currMainNode), BaseHelper::EXCEPTION_XML_NODE_MISMATCH); + } elseif (in_array($nodeName, $this->subNodes)) { + // Silently ignore sub nodes + return; + } + + // Construct method name + $methodName = "finish" . $this->convertToClassName($nodeName); + + // Call the corresponding method + call_user_func_array(array($this->imageInstance, $methodName), array()); + } + + /** + * Currently not used + * + * @param $resource XML parser resource (currently ignored) + * @param $characters Characters to handle + * @return void + * @todo Find something usefull with this! + */ + public function characterHandler ($resource, $characters) { + // Trim all spaces away + $characters = trim($characters); + + // Is this string empty? + if (empty($characters)) { + // Then skip it silently + return false; + } // END - if + + // Unfinished work! + $this->partialStub("Handling extra characters is not yet supported!"); + } + /** * Intializes the image * @@ -195,6 +249,9 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl * @return void */ private function setImageType ($imageType) { + // Set group to general + $this->setVariableGroup("general"); + // Try to compile it first to get the value from variable stack $imageType = $this->compileRawCode($imageType); @@ -202,7 +259,226 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $className = $this->convertToClassName($imageType."_image"); // And try to initiate it - $this->imageInstance = ObjectFactory::createObjectByName($className); + $this->imageInstance = ObjectFactory::createObjectByName($className, array($this)); + + // Set current main node to type + $this->currMainNode = "type"; + } + + /** + * "Setter" for resolution, we first need to collect the resolution from the + * sub-nodes. So first, this method will prepare an array for it + * + * @return void + */ + private function setImageResolution () { + // Call the image class + $this->imageInstance->initResolution(); + + // Current main node is resolution + $this->currMainNode = "resolution"; + } + + /** + * "Setter" for base information. For more details see above method! + * + * @return void + * @see ImageTemplateEngine::setImageResolution + */ + private function setImageBase () { + // Call the image class + $this->imageInstance->initBase(); + + // Current main node is resolution + $this->currMainNode = "base"; + } + + /** + * "Setter" for background-color. For more details see above method! + * + * @return void + * @see ImageTemplateEngine::setImageResolution + */ + private function setImageBackgroundColor () { + // Call the image class + $this->imageInstance->initBackgroundColor(); + + // Current main node is background-color + $this->currMainNode = "background-color"; + } + + /** + * "Setter" for foreground-color. For more details see above method! + * + * @return void + * @see ImageTemplateEngine::setImageResolution + */ + private function setImageForegroundColor () { + // Call the image class + $this->imageInstance->initForegroundColor(); + + // Current main node is foreground-color + $this->currMainNode = "foreground-color"; + } + + /** + * "Setter" for image-string. For more details see above method! + * + * @param $groupable Wether this image string is groupable + * @return void + * @see ImageTemplateEngine::setImageResolution + */ + private function setImageImageString ($groupable = "single") { + // Call the image class + $this->imageInstance->initImageString($groupable); + + // Current main node is foreground-color + $this->currMainNode = "image-string"; + } + + /** + * Setter for image name + * + * @param $imageName Name of the image + * @return void + */ + private function setImagePropertyName ($imageName) { + // Call the image class + $this->imageInstance->setImageName($imageName); + } + + /** + * Setter for image width + * + * @param $width Width of the image or variable + * @return void + */ + private function setImagePropertyWidth ($width) { + // Call the image class + $this->imageInstance->setWidth($width); + } + + /** + * Setter for image height + * + * @param $height Height of the image or variable + * @return void + */ + private function setImagePropertyHeight ($height) { + // Call the image class + $this->imageInstance->setHeight($height); + } + + /** + * Setter for image red color + * + * @param $red Red color value + * @return void + */ + private function setImagePropertyRed ($red) { + // Call the image class + $this->imageInstance->setRed($red); + } + + /** + * Setter for image green color + * + * @param $green Green color value + * @return void + */ + private function setImagePropertyGreen ($green) { + // Call the image class + $this->imageInstance->setGreen($green); + } + + /** + * Setter for image blue color + * + * @param $blue Blue color value + * @return void + */ + private function setImagePropertyBlue ($blue) { + // Call the image class + $this->imageInstance->setBlue($blue); + } + + /** + * Setter for string name (identifier) + * + * @param $stringName String name (identifier) + * @return void + */ + private function setImagePropertyStringName ($stringName) { + // Call the image class + $this->imageInstance->setStringName($stringName); + } + + /** + * Setter for font size + * + * @param $fontSize Size of the font + * @return void + */ + private function setImagePropertyFontSize ($fontSize) { + // Call the image class + $this->imageInstance->setFontSize($fontSize); + } + + /** + * Setter for image string + * + * @param $imageString Image string to set + * @return void + */ + private function setImagePropertyText ($imageString) { + // Call the image class + $this->imageInstance->setString($imageString); + } + + /** + * Setter for X coordinate + * + * @param $x X coordinate + * @return void + */ + private function setImagePropertyX ($x) { + // Call the image class + $this->imageInstance->setX($x); + } + + /** + * Setter for Y coordinate + * + * @param $y Y coordinate + * @return void + */ + private function setImagePropertyY ($y) { + // Call the image class + $this->imageInstance->setY($y); + } + + /** + * Getter for image cache file (FQFN) + * + * @return $fqfn Full-qualified file name of the image cache + */ + public function getImageCacheFqfn () { + // Get the FQFN ready + $fqfn = $this->getBasePath()."_cache/" . md5($this->imageInstance->getImageName()) . "." . $this->imageInstance->getImageType(); + + // Return it + return $fqfn; + } + + /** + * Outputs the image to the world + * + * @param $responseInstance An instance of a Responseable class + * @return void + */ + public function transferToResponse (Responseable $responseInstance) { + // Set the image instance + $responseInstance->setImageInstance($this->imageInstance); } } diff --git a/inc/classes/main/template/web/class_WebTemplateEngine.php b/inc/classes/main/template/web/class_WebTemplateEngine.php index b5cab11..35d34c5 100644 --- a/inc/classes/main/template/web/class_WebTemplateEngine.php +++ b/inc/classes/main/template/web/class_WebTemplateEngine.php @@ -82,9 +82,6 @@ class WebTemplateEngine extends BaseTemplateEngine implements CompileableTemplat // Set the base path $tplInstance->setBasePath($basePath); - // Initialize the variable stack - $tplInstance->initVariableStack(); - // Set the language and IO instances $tplInstance->setLanguageInstance($langInstance); $tplInstance->setFileIoInstance($ioInstance); diff --git a/inc/classes/main/user/class_Guest.php b/inc/classes/main/user/class_Guest.php index ffe6772..fa9a50d 100644 --- a/inc/classes/main/user/class_Guest.php +++ b/inc/classes/main/user/class_Guest.php @@ -38,9 +38,9 @@ class Guest extends BaseFrameworkSystem implements ManageableGuest, Registerable private $email = ""; // Exceptions - const EXCEPTION_USERNAME_NOT_FOUND = 0x060; - const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x061; - const EXCEPTION_USER_PASS_MISMATCH = 0x062; + const EXCEPTION_USERNAME_NOT_FOUND = 0x700; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x701; + const EXCEPTION_USER_PASS_MISMATCH = 0x702; /** * Protected constructor diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 62b0d55..0e998a0 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -38,9 +38,9 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { private $email = ""; // Exceptions - const EXCEPTION_USERNAME_NOT_FOUND = 0x060; - const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x061; - const EXCEPTION_USER_PASS_MISMATCH = 0x062; + const EXCEPTION_USERNAME_NOT_FOUND = 0x600; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x601; + const EXCEPTION_USER_PASS_MISMATCH = 0x602; /** * Protected constructor diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 493af36..32453ab 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -39,8 +39,8 @@ class FrameworkConfiguration implements Registerable { private static $cfgInstance = null; // Some constants for the configuration system - const EXCEPTION_CONFIG_ENTRY_IS_EMPTY = 0x040; - const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0x041; + const EXCEPTION_CONFIG_ENTRY_IS_EMPTY = 0x400; + const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0x401; /** * Protected constructor diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 2d36b78..c7dc2d7 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -309,7 +309,9 @@ class ClassLoader { // Now look it up in our index if (isset($this->classes[$fileName])) { // File is found so load it only once + //* DEBUG: */ echo "LOAD: ".$fileName." - Start
\n"; require($this->classes[$fileName]); + //* DEBUG: */ echo "LOAD: ".$fileName." - End
\n"; // Count this include $this->total++; diff --git a/templates/images/_cache/.htaccess b/templates/images/_cache/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/templates/images/_cache/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/templates/images/de/image/base_image.img b/templates/images/de/image/base_image.itp similarity index 54% rename from templates/images/de/image/base_image.img rename to templates/images/de/image/base_image.itp index 39781ef..ecba6c9 100644 --- a/templates/images/de/image/base_image.img +++ b/templates/images/de/image/base_image.itp @@ -1,5 +1,8 @@ + + + @@ -10,11 +13,15 @@ - - - + + + - + + + + + diff --git a/templates/images/de/image/emergency_exit.img b/templates/images/de/image/emergency_exit.img deleted file mode 100644 index b46b738..0000000 --- a/templates/images/de/image/emergency_exit.img +++ /dev/null @@ -1,22 +0,0 @@ -setBaseImage("base_image"); - -// Set image dimensions -$helper->setWidth(400); -$helper->setHeight(200); - -// Background and foreground color -$helper->setBackgroundColorRedGreenBlue(0xFF, 0xAA, 0xAA); -$helper->setForegroundColorRedGreenBlue(0x00, 0x00, 0x00); - -// Add error message -$helper->setImageString("Genereller Fehler!"); - -// Flush content to the template engine -$helper->flushContent(); - -// Comment this out if image is done -//$this->debugInstance(); -?> diff --git a/templates/images/de/image/emergency_exit.itp b/templates/images/de/image/emergency_exit.itp new file mode 100644 index 0000000..fbe870c --- /dev/null +++ b/templates/images/de/image/emergency_exit.itp @@ -0,0 +1,40 @@ +setImageName("emergency_exit"); +$helper->setBaseImage("base_image"); + +// Set image dimensions +$helper->setWidth(200); +$helper->setHeight(100); + +// Background and foreground color +$helper->setBackgroundColorRedGreenBlue(0xA0, 0x00, 0x30); +$helper->setForegroundColorRedGreenBlue(0xFF, 0xFF, 0xFF); + +// Add header line +$helper->addTextLine("header"); +$helper->setCoord(18, 10); +$helper->setFontSize(5); +$helper->setImageString("Fehler-Code: {?code?}"); + +// Add info line +$helper->addTextLine("info"); +$helper->setCoord(68, 40); +$helper->setFontSize(5); +$helper->setImageString("Info:"); + +// Add extra line +$helper->addTextLine("extra"); +$helper->setCoord(18, 70); +$helper->setFontSize(2); +$helper->setImageString("{?extra?}"); + +// Flush content to the template engine +$helper->flushContent(); + +// Comment this out if image is done +//$this->debugInstance(); + +// [EOF] +?> -- 2.39.5