]> git.mxchange.org Git - shipsimu.git/commitdiff
Image generator added, first CAPTCHA added with missing controller (partly work)
authorRoland Häder <roland@mxchange.org>
Mon, 23 Jun 2008 18:05:10 +0000 (18:05 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 23 Jun 2008 18:05:10 +0000 (18:05 +0000)
37 files changed:
.gitattributes
application/ship-simu/exceptions.php
application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php
application/ship-simu/templates/de/code/captch_graphic_code.ctp [new file with mode: 0644]
inc/classes/exceptions/class_FrameworkException.php
inc/classes/exceptions/main/class_ClassNotFoundException.php
inc/classes/exceptions/xml/class_InvalidXmlNodeException.php
inc/classes/exceptions/xml/class_XmlNodeMismatchException.php [new file with mode: 0644]
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/commands/web/class_WebRegisterCommand.php
inc/classes/main/database/class_BaseDatabaseFrontend.php
inc/classes/main/database/databases/class_LocalFileDatabase.php
inc/classes/main/database/wrapper/class_NewsDatabaseWrapper.php
inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php
inc/classes/main/filter/auth/class_UserAuthFilter.php
inc/classes/main/filter/class_BaseFilter.php
inc/classes/main/helper/class_BaseHelper.php
inc/classes/main/helper/images/class_ImageHelper.php
inc/classes/main/helper/web/class_WebFormHelper.php
inc/classes/main/images/class_
inc/classes/main/images/class_BaseImage.php
inc/classes/main/images/extended/class_PngImage.php
inc/classes/main/resolver/class_BaseResolver.php
inc/classes/main/response/class_ImageResponse.php
inc/classes/main/result/class_DatabaseResult.php
inc/classes/main/template/class_BaseTemplateEngine.php
inc/classes/main/template/image/class_ImageTemplateEngine.php
inc/classes/main/template/web/class_WebTemplateEngine.php
inc/classes/main/user/class_Guest.php
inc/classes/main/user/class_User.php
inc/config/class_FrameworkConfiguration.php
inc/loader/class_ClassLoader.php
templates/images/_cache/.htaccess [new file with mode: 0644]
templates/images/de/image/base_image.img [deleted file]
templates/images/de/image/base_image.itp [new file with mode: 0644]
templates/images/de/image/emergency_exit.img [deleted file]
templates/images/de/image/emergency_exit.itp [new file with mode: 0644]

index 513b4ff9d0f6c597d0eb1ee945563c64993e1e60..d5934558a5aace417f9f4d76edc75790cbe0f592 100644 (file)
@@ -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
index b5b8bdc9e83632cddc5388abb02678e9fd4a70fa..69f0d9aa73bcecd7e90e6bd19455440f93a5e1c0 100644 (file)
@@ -32,7 +32,10 @@ function __exceptionHandler (FrameworkException $e) {
                $e->getHexCode(),
                $e->getMessage(),
                $e->getPrintableBackTrace()
-       ));
+       ),
+               $e->getHexCode(),
+               $e->getExtraData()
+       );
 } // END - function
 
 // Set the new handler
index 04b45c74a01076093915a17ceedcc8ac9a7c49d6..a4bebd6589c2ef204f989081a5ed7b0ce21e6ce2 100644 (file)
@@ -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 (file)
index 0000000..bb422da
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+// Get a helper instance without a form tag
+$helper = WebFormHelper::createWebFormHelper($this, "captcha_code", false, false);
+$helper->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]
+?>
+<div id="captcha_image">
+       <img src="$config[base_url]/index.php?app=ship-simu&amp;page=captcha_image&amp;encrypt={?encrypted_code?}&amp;response=image" alt="CAPTCHA-Bild" title="CAPTCHA-Bild" id="captcha_img" />
+</div>
+<div id="captcha_code">
+       {?captcha_code?}
+</div>
index 34e48023f10574ef46ed46bae26509f22e941384..c36ba093884239f71344099fb42604139538f6de 100644 (file)
@@ -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: <pre>%s</pre>",
+                               $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]
index 3c9511c6bccf4f9cb064a7cd314e3b7b55a11901..5ced9d85f55800935b9e84edbdc31e869b3398f6 100644 (file)
@@ -37,6 +37,9 @@ class ClassNotFoundException extends FrameworkException {
                        $msgArray[1]
                );
 
+               // Set extra data
+               $this->setExtraData($msgArray[1]);
+
                // Call parent constructor
                parent::__construct($message, $code);
        }
index 75a23535024894bd7a346794c3063d7e5b735273..eb52f0ccb0139dc256db638a842fc858fc00850f 100644 (file)
@@ -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 (file)
index 0000000..a9357b4
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * An exception thrown when an XML node does not match the excepted
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 132d5bead183dfded68bd84dbbf9eec2ce96f3f3..a4052ef3056ae17f1bbd949b9a0b9a4982631de4 100644 (file)
@@ -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
         *
index 0ad939dd25d0ea6d06a4dcb197a42b990ce40741..5448e2a7c27f8f9cee35045d5635dc3eef5310fa 100644 (file)
@@ -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();
 
index c53fb4e2feee1d9bf4457242ed3dfd3aa48666c0..046ae8b192e53f2f4be998543d8e708ee2631aa8 100644 (file)
@@ -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
index b3ee46ecb7b2b22851e2337439289394b4797417..81ad7fd40d14a914372f1a376b7626600e6f455f 100644 (file)
@@ -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"
index c8c43dc79ed585bad7cbcd45359f0a41bb1672c6..1b8b6ad5917c164541cf3f63d97acc6200184079 100644 (file)
@@ -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
 
index e2ff935633930c99f6a86ba8a3b271ef2d6d5887..f1caa49379c4c604261fbd39ab84486b1ab3b2cb 100644 (file)
@@ -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";
index a75e7be66acd3687c045f9fe5c081199c50347e8..fc001a32fc55c91ca4fa80d41e4846b5f71be5fd 100644 (file)
@@ -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
index 3800c49250d1e6fe2ad8bdd1e62f9af95249cb48..195d3e1b8bbf9ed60e4e91280a23ff1027e64277 100644 (file)
@@ -23,7 +23,7 @@
  */
 class BaseFilter extends BaseFrameworkSystem {
        // Exception constants
-       const EXCEPTION_FILTER_CHAIN_ABORTED = 0x090;
+       const EXCEPTION_FILTER_CHAIN_ABORTED = 0xa00;
 
        /**
         * Protected constructor
index d266d5bd98c03c39f1a1fc004965e302c08eb8cf..2c0c3c8b3a88fcd0302f90a9ad7ef5f978016b61 100644 (file)
  */
 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
         *
index 5490a408aa5283ecf94c10a3266c027a2e35a4bb..84081a11de710cad995fabc3d4c4fb984008b7f7 100644 (file)
@@ -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();
index 8d20001046a071f98afbff5556decf17bb8b727c..43ea97822218276adde87a38717d69b8046a878f 100644 (file)
@@ -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
index 9a90092975e66e2625dfaafe58f6672600f5b06b..5ff229098cb2879377120ea31c84ac78ee74d1bf 100644 (file)
@@ -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;
        }
index 2273945d43a22a319e5bd669c53aa78451ba9536..356f41809c46ca84542dddef04ec519e05e7686d 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-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}<br />\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}<br />\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]
 ?>
index 4693a3d1633d2f785eb7f06ad2b2eef84c0d0c14..e5f184d90b782882e53091f5afd872eb8162a51e 100644 (file)
@@ -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]
index eedeef38fd2fb5469c9444594588ac238f2ee34f..539a42535ed5d155a143d689630dd7f4222380f1 100644 (file)
@@ -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
index 2e2fd09c121a7789c8513d872b3d28abf39fb89f..3d16954207dde2a8425aedb034bc3570df9b8f27 100644 (file)
@@ -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]
index 75948a695b6c126ec38606ae7d8bcc20bd643f22..08bf40355dbaa9a102859f4bc5ca68b575a385d2 100644 (file)
@@ -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
index 7188fda70d6f9e2241ce30355554c5b71660f3ca..00691efa515ccc45bcfee424e748deda9738a4ef 100644 (file)
@@ -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."<br />\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."<br />\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."<br />\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."<br />\n";
+               // Some debug code to look on the file which is being loaded
+               //* DEBUG: */ echo __METHOD__.": FQFN=".$fqfn."<br />\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=<pre>".htmlentities($currEntry['value'])."</pre>\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']."=<pre>".htmlentities($currVariable['value'])."</pre>\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=<pre>".htmlentities($rawCode)."</pre>\n";
                preg_match_all($this->regExpVarValue, $rawCode, $varMatches);
 
                // Compile all variables
+               //* DEBUG: */ echo "<pre>".print_r($varMatches, true)."</pre>";
                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."<br />\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]
index 6e80fd1a15b4b7598dc700a1135b57d075c2e06f..c2542d816f991c81de1fa2e336447a9b83c282e0 100644 (file)
@@ -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: &gt;".$element."&lt;<br />\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: &gt;".$nodeName."&lt;<br />\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);
        }
 }
 
index b5cab112520bc028ffb69f10316d0877da3eb57d..35d34c581730fbd03baca34d2ede6a56896d25be 100644 (file)
@@ -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);
index ffe6772c21bb24382215e304b2b9c45cae0e72da..fa9a50d012e4baffc670daca21e7a830b901a07f 100644 (file)
@@ -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
index 62b0d5517e9b903f38b46d440bf47f33d3f0d680..0e998a0fc5774406c81df8a4a0634b7947ac6d32 100644 (file)
@@ -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
index 493af366e33c1a362449311ee5bc102f874ddcd6..32453ab45cb0a54e4280f4f11a5bef5c43b7f0bb 100644 (file)
@@ -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
index 2d36b78a337014782b06d50b8988f34fb24da2a7..c7dc2d755de71ba29f30585b3aaa9f70f6baef34 100644 (file)
@@ -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<br />\n";
                        require($this->classes[$fileName]);
+                       //* DEBUG: */ echo "LOAD: ".$fileName." - End<br />\n";
 
                        // Count this include
                        $this->total++;
diff --git a/templates/images/_cache/.htaccess b/templates/images/_cache/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/templates/images/de/image/base_image.img b/templates/images/de/image/base_image.img
deleted file mode 100644 (file)
index 39781ef..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<image>
-       <type value="{?image_type?}" />
-       <resolution>
-               <width value="{?image_width?}" />
-               <height value="{?image_height?}" />
-       </resolution>
-       <background-color>
-               <red value="{?image_bg_red?}" />
-               <green value="{?image_bg_green?}" />
-               <blue value="{?image_bg_blue?}" />
-       </background-color>
-       <foreground-color>
-               <red value="{?image_bg_red?}" />
-               <green value="{?image_bg_green?}" />
-               <blue value="{?image_bg_blue?}" />
-       </foreground-color>
-       <image-string>
-               <text value="{?image_string?}" />
-       </image-string>
-</image>
diff --git a/templates/images/de/image/base_image.itp b/templates/images/de/image/base_image.itp
new file mode 100644 (file)
index 0000000..ecba6c9
--- /dev/null
@@ -0,0 +1,27 @@
+<image>
+       <type value="{?image_type?}" />
+       <base>
+               <name value="{?image_name?}" />
+       </base>
+       <resolution>
+               <width value="{?image_width?}" />
+               <height value="{?image_height?}" />
+       </resolution>
+       <background-color>
+               <red value="{?image_bg_red?}" />
+               <green value="{?image_bg_green?}" />
+               <blue value="{?image_bg_blue?}" />
+       </background-color>
+       <foreground-color>
+               <red value="{?image_fg_red?}" />
+               <green value="{?image_fg_green?}" />
+               <blue value="{?image_fg_blue?}" />
+       </foreground-color>
+       <image-string value="groupable">
+               <string-name value="{?image_string_name?}" />
+               <x value="{?image_x?}" />
+               <y value="{?image_y?}" />
+               <font-size value="{?image_size?}" />
+               <text value="{?image_string?}" />
+       </image-string>
+</image>
diff --git a/templates/images/de/image/emergency_exit.img b/templates/images/de/image/emergency_exit.img
deleted file mode 100644 (file)
index b46b738..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-// Needed in every image template to initialy set the image type
-$helper = ImageHelper::createImageHelper($this, "png");
-$helper->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 (file)
index 0000000..fbe870c
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+// Needed in every image template to initialy set the image type
+$helper = ImageHelper::createImageHelper($this, "png");
+$helper->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]
+?>