From: Roland Häder Date: Fri, 19 Sep 2008 19:10:47 +0000 (+0000) Subject: Fixes for image generation X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=commitdiff_plain;h=8ff12f905898b0c2b7ff8124c9749ad6fb9c44f3;ds=sidebyside Fixes for image generation --- diff --git a/.gitattributes b/.gitattributes index ff8b2fa..aaa38f0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -46,6 +46,7 @@ application/blog/templates/images/de/image/code_captcha.itp -text application/selector/.htaccess -text application/selector/class_ApplicationHelper.php -text application/selector/class_ApplicationSelector.php -text +application/selector/config.php -text application/selector/debug.php -text application/selector/exceptions.php -text application/selector/init.php -text @@ -685,8 +686,11 @@ inc/classes/main/resolver/controller/image/class_ImageControllerResolver.php -te inc/classes/main/resolver/controller/web/.htaccess -text inc/classes/main/resolver/controller/web/class_WebControllerResolver.php -text inc/classes/main/response/.htaccess -text -inc/classes/main/response/class_HttpResponse.php -text -inc/classes/main/response/class_ImageResponse.php -text +inc/classes/main/response/class_BaseResponse.php -text +inc/classes/main/response/http/.htaccess -text +inc/classes/main/response/http/class_HttpResponse.php -text +inc/classes/main/response/image/.htaccess -text +inc/classes/main/response/image/class_ImageResponse.php -text inc/classes/main/result/.htaccess -text inc/classes/main/result/class_DatabaseResult.php -text inc/classes/main/rng/.htaccess -text diff --git a/application/blog/class_ApplicationHelper.php b/application/blog/class_ApplicationHelper.php index 0746faa..c3334fd 100644 --- a/application/blog/class_ApplicationHelper.php +++ b/application/blog/class_ApplicationHelper.php @@ -229,6 +229,17 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica print("MSG:".$message."
\n"); } // END - if } + + /** + * Assigns application-depending data + * + * @param $templateInstance An instance of a template engine + * @return void + */ + public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + // Assign charset + $templateInstance->assignConfigVariable('header_charset'); + } } // [EOF] diff --git a/application/blog/config.php b/application/blog/config.php index 5ceea91..f06094d 100644 --- a/application/blog/config.php +++ b/application/blog/config.php @@ -25,6 +25,9 @@ // Get a configuration instance for shorter lines $cfg = FrameworkConfiguration::getInstance(); +// CFG: HEADER-CHARSET +$cfg->setConfigEntry('header_charset', "utf-8"); + // CFG: DEFAULT-WEB-COMMAND $cfg->setConfigEntry('default_web_command', "home"); diff --git a/application/blog/init.php b/application/blog/init.php index 4043f37..fa7aee2 100644 --- a/application/blog/init.php +++ b/application/blog/init.php @@ -33,6 +33,9 @@ * along with this program. If not, see . */ +// Get config instance +$cfg = FrameworkConfiguration::getInstance(); + // Initialize output system require($cfg->readConfig('base_path') . 'inc/output.php'); diff --git a/application/selector/class_ApplicationHelper.php b/application/selector/class_ApplicationHelper.php index aa297cc..d51ca02 100644 --- a/application/selector/class_ApplicationHelper.php +++ b/application/selector/class_ApplicationHelper.php @@ -199,6 +199,17 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica public function handleFatalMessages (array $messageList) { die("
".print_r($messageList, true)."
"); } + + /** + * Assigns application-depending data + * + * @param $templateInstance An instance of a template engine + * @return void + */ + public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + // Assign charset + $templateInstance->assignConfigVariable('header_charset'); + } } // [EOF] diff --git a/application/selector/class_ApplicationSelector.php b/application/selector/class_ApplicationSelector.php index 1f664a6..8d6d914 100644 --- a/application/selector/class_ApplicationSelector.php +++ b/application/selector/class_ApplicationSelector.php @@ -187,10 +187,7 @@ class ApplicationSelector extends BaseFrameworkSystem { */ public function readApplicationDirectory () { // Generate the base path for all applications - $appBasePath = sprintf("%s%s/", - $this->getConfigInstance()->readConfig('base_path'), - $this->getConfigInstance()->readConfig('application_path') - ); + $appBasePath = $this->getConfigInstance()->readConfig('application_path'); // Add the selector path to the ignore list $this->addDirIgnoreList($this->getConfigInstance()->readConfig('selector_path')); @@ -198,7 +195,7 @@ class ApplicationSelector extends BaseFrameworkSystem { // Get a directory pointer for the application path $dirInstance = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($appBasePath); - // Backup and remove the 'app' from global name space + // Backup and remove the 'app' from local name space /*$appBackup = $app; unset($app);*/ diff --git a/application/selector/config.php b/application/selector/config.php new file mode 100644 index 0000000..62cd1b7 --- /dev/null +++ b/application/selector/config.php @@ -0,0 +1,50 @@ + + * @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 . + */ + +// Get a configuration instance for shorter lines +$cfg = FrameworkConfiguration::getInstance(); + +// CFG: HEADER-CHARSET +$cfg->setConfigEntry('header_charset', "utf-8"); + +// CFG: DEFAULT-WEB-COMMAND +$cfg->setConfigEntry('default_web_command', "home"); + +// CFG: DEFAULT-IMAGE-COMMAND +$cfg->setConfigEntry('default_image_command', "build"); + +// CFG: PAGE-WITH-NEWS +$cfg->setConfigEntry('page_with_news', "home"); + +// CFG: FORM-ACTION +$cfg->setConfigEntry('form_action', "index.php?app={?app_short_name?}&page=do_form"); + +// CFG: FORM-METHOD +$cfg->setConfigEntry('form_method', "post"); + +// CFG: FORM-TARGET +$cfg->setConfigEntry('form_target', "_self"); + +// [EOF] +?> diff --git a/application/selector/init.php b/application/selector/init.php index cac841d..71893f0 100644 --- a/application/selector/init.php +++ b/application/selector/init.php @@ -25,6 +25,9 @@ * along with this program. If not, see . */ +// Get config instance +$cfg = FrameworkConfiguration::getInstance(); + // Initialize output system require($cfg->readConfig('base_path') . 'inc/output.php'); diff --git a/application/ship-simu/class_ApplicationHelper.php b/application/ship-simu/class_ApplicationHelper.php index 43cac88..9f06072 100644 --- a/application/ship-simu/class_ApplicationHelper.php +++ b/application/ship-simu/class_ApplicationHelper.php @@ -229,6 +229,17 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica print("MSG:".$message."
\n"); } // END - if } + + /** + * Assigns application-depending data + * + * @param $templateInstance An instance of a template engine + * @return void + */ + public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + // Assign charset + $templateInstance->assignConfigVariable('header_charset'); + } } // [EOF] diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 995707f..84c14b6 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -25,6 +25,9 @@ // Get a configuration instance for shorter lines $cfg = FrameworkConfiguration::getInstance(); +// CFG: HEADER-CHARSET +$cfg->setConfigEntry('header_charset', "utf-8"); + // CFG: DEFAULT-WEB-COMMAND $cfg->setConfigEntry('default_web_command', "home"); diff --git a/application/ship-simu/init.php b/application/ship-simu/init.php index 548894c..7b65cae 100644 --- a/application/ship-simu/init.php +++ b/application/ship-simu/init.php @@ -33,6 +33,9 @@ * along with this program. If not, see . */ +// Get config instance +$cfg = FrameworkConfiguration::getInstance(); + // Initialize output system require($cfg->readConfig('base_path') . 'inc/output.php'); diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php index b9d0cd7..1bb449a 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php @@ -87,7 +87,7 @@ class WebShipsimuProfileCommand extends BaseCommand implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Make sure only allowed values are comming through - foreach ($this->allowedData as $alias=>$element) { + foreach ($this->allowedData as $alias => $element) { // Get data $data = $requestInstance->getRequestElement($element); diff --git a/application/ship-simu/main/registration/class_ShipSimuRegistration.php b/application/ship-simu/main/registration/class_ShipSimuRegistration.php index a043056..31e6e63 100644 --- a/application/ship-simu/main/registration/class_ShipSimuRegistration.php +++ b/application/ship-simu/main/registration/class_ShipSimuRegistration.php @@ -163,7 +163,7 @@ class ShipSimuRegistration extends BaseRegistration { } // END - if // Add a lot elements to the dataset criteria - foreach ($this->criteriaElements as $alias=>$element) { + foreach ($this->criteriaElements as $alias => $element) { // Do we have an alias? if (is_string($alias)) { // Yes, so use it @@ -181,7 +181,7 @@ class ShipSimuRegistration extends BaseRegistration { } // END - foreach // Mark the username as unique key - $criteriaInstance->setUniqueKey('username'); + $criteriaInstance->setUniqueKey(UserDatabaseWrapper::DB_COLUMN_USERNAME); // Add account status as configured $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry); diff --git a/application/todo/class_ApplicationHelper.php b/application/todo/class_ApplicationHelper.php index ccedad6..47680fb 100644 --- a/application/todo/class_ApplicationHelper.php +++ b/application/todo/class_ApplicationHelper.php @@ -229,6 +229,17 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica print("MSG:".$message."
\n"); } // END - if } + + /** + * Assigns application-depending data + * + * @param $templateInstance An instance of a template engine + * @return void + */ + public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + // Assign charset + $templateInstance->assignConfigVariable('header_charset'); + } } // [EOF] diff --git a/application/todo/config.php b/application/todo/config.php index a1a4544..89e52e1 100644 --- a/application/todo/config.php +++ b/application/todo/config.php @@ -25,6 +25,9 @@ // Get a configuration instance for shorter lines $cfg = FrameworkConfiguration::getInstance(); +// CFG: HEADER-CHARSET +$cfg->setConfigEntry('header_charset', "utf-8"); + // CFG: DEFAULT-WEB-COMMAND $cfg->setConfigEntry('default_web_command', "home"); diff --git a/application/todo/init.php b/application/todo/init.php index 3f7a885..c8d19e3 100644 --- a/application/todo/init.php +++ b/application/todo/init.php @@ -33,6 +33,9 @@ * along with this program. If not, see . */ +// Get config instance +$cfg = FrameworkConfiguration::getInstance(); + // Initialize output system require($cfg->readConfig('base_path') . 'inc/output.php'); diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 061b2f4..7e461ac 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -718,8 +718,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // END - if // Generate FQFN for all application templates - $fqfn = sprintf("%s%s/%s/%s", - $this->getConfigInstance()->readConfig('base_path'), + $fqfn = sprintf("%s%s/%s", $this->getConfigInstance()->readConfig('application_path'), strtolower($appInstance->getAppShortName()), $this->getConfigInstance()->readConfig('tpl_base_path') @@ -892,7 +891,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // END - if // Add line number to the code - foreach (explode("\n", $phpCode) as $lineNo=>$code) { + foreach (explode("\n", $phpCode) as $lineNo => $code) { // Add line numbers $markedCode .= sprintf("%s: %s\n", ($lineNo + 1), diff --git a/inc/classes/main/commands/web/class_WebLoginFailedCommand.php b/inc/classes/main/commands/web/class_WebLoginFailedCommand.php index 9981133..7c74d7b 100644 --- a/inc/classes/main/commands/web/class_WebLoginFailedCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginFailedCommand.php @@ -63,6 +63,9 @@ class WebLoginFailedCommand extends BaseCommand implements Commandable { // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($appInstance); + // Assign application data with template engine + $templateInstance->assignApplicationData($appInstance); + // Load the master template $masterTemplate = $appInstance->getMasterTemplate(); diff --git a/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php b/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php index 15ecb70..bbb7f2f 100644 --- a/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php +++ b/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php @@ -63,6 +63,9 @@ class WebLogoutDoneCommand extends BaseCommand implements Commandable { // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($appInstance); + // Assign application data + $templateInstance->assignApplicationData($appInstance); + // Load the master template $masterTemplate = $appInstance->getMasterTemplate(); diff --git a/inc/classes/main/criteria/class_SearchCriteria.php b/inc/classes/main/criteria/class_SearchCriteria.php index b9f27db..c95d853 100644 --- a/inc/classes/main/criteria/class_SearchCriteria.php +++ b/inc/classes/main/criteria/class_SearchCriteria.php @@ -188,9 +188,9 @@ class SearchCriteria extends BaseFrameworkSystem implements LocalSearchCriteria $counted = 0; // Walk through all entries - foreach ($entryArray as $key=>$entry) { + foreach ($entryArray as $key => $entry) { // Then walk through all search criteria - foreach ($this->searchCriteria as $criteriaKey=>$criteriaValue) { + foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) { // Is the element found and does it match? if (($key == $criteriaKey) && ($criteriaValue == $entry)) { // Then count this one up diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index a8cda74..25cf938 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -385,7 +385,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Is this an array? if (is_array($dataArray)) { // Search in the criteria with FMFW (First Matches, First Wins) - foreach ($dataArray as $key=>$value) { + foreach ($dataArray as $key => $value) { // Get criteria element $criteria = $criteriaInstance->getCriteriaElemnent($key); @@ -513,7 +513,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Is this an array? if (is_array($dataArray)) { // Search in the criteria with FMFW (First Matches, First Wins) - foreach ($dataArray as $key=>$value) { + foreach ($dataArray as $key => $value) { // Get criteria element $criteria = $searchInstance->getCriteriaElemnent($key); @@ -531,7 +531,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend } // END - if // Entry found, so update it - foreach ($criteriaArray as $criteriaKey=>$criteriaValue) { + foreach ($criteriaArray as $criteriaKey => $criteriaValue) { $dataArray[$criteriaKey] = $criteriaValue; } // END - foreach diff --git a/inc/classes/main/images/class_BaseImage.php b/inc/classes/main/images/class_BaseImage.php index 7c1e089..7f667cd 100644 --- a/inc/classes/main/images/class_BaseImage.php +++ b/inc/classes/main/images/class_BaseImage.php @@ -469,10 +469,10 @@ class BaseImage extends BaseFrameworkSystem implements Registerable { $this->setBlue($blue); // Get a pointer for background color - $backColor = imagecolorallocate($this->imageResource, $red, $green, $blue); + $backColor = imagecolorallocate($this->getImageResource(), $red, $green, $blue); // Fill the image - imagefill($this->imageResource, 0, 0, $backColor); + imagefill($this->getImageResource(), 0, 0, $backColor); // Compile foreground colors $red = $templateInstance->compileRawCode($this->foregroundColor['red']); @@ -486,7 +486,7 @@ class BaseImage extends BaseFrameworkSystem implements Registerable { $this->setBlue($blue); // Get a pointer for foreground color - $foreColor = imagecolorallocate($this->imageResource, $red, $green, $blue); + $foreColor = imagecolorallocate($this->getImageResource(), $red, $green, $blue); switch ($this->groupable) { case "single": // Single image string @@ -502,7 +502,7 @@ class BaseImage extends BaseFrameworkSystem implements Registerable { $size = $templateInstance->compileRawCode($this->getFontSize()); // Set the image string - imagestring($this->imageResource, $size, $x, $y, $imageString, $foreColor); + imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor); break; case "groupable": // More than one string allowed @@ -521,7 +521,7 @@ class BaseImage extends BaseFrameworkSystem implements Registerable { // Set the image string //* DEBUG: */ echo __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}
\n"; - imagestring($this->imageResource, $size, $x, $y, $imageString, $foreColor); + imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor); } // END - foreach break; } diff --git a/inc/classes/main/images/extended/class_PngImage.php b/inc/classes/main/images/extended/class_PngImage.php index f8ee28b..8b03320 100644 --- a/inc/classes/main/images/extended/class_PngImage.php +++ b/inc/classes/main/images/extended/class_PngImage.php @@ -64,6 +64,12 @@ class PngImage extends BaseImage { // Get a file name for our image $cacheFile = $this->getTemplateInstance()->getImageCacheFqfn(); + // Does it exist? + if (file_exists($cacheFile)) { + // Remove it + @unlink($cacheFile); + } // END - if + // Finish the image and send it to a cache file imagepng($this->getImageResource(), $cacheFile, 9, PNG_ALL_FILTERS); } diff --git a/inc/classes/main/mailer/debug/class_DebugMailer.php b/inc/classes/main/mailer/debug/class_DebugMailer.php index ffc3fc6..042ee69 100644 --- a/inc/classes/main/mailer/debug/class_DebugMailer.php +++ b/inc/classes/main/mailer/debug/class_DebugMailer.php @@ -85,13 +85,13 @@ class DebugMailer extends BaseMailer implements DeliverableMail { $templateInstance->assignVariable('subject', $this->getSubjectLine()); // Walk through all variables, first config to assign them - foreach ($recipientList['config_vars'] as $variable=>$dummy) { + foreach ($recipientList['config_vars'] as $variable => $dummy) { // Load the config value and set it $templateInstance->assignConfigVariable($variable); } // END - if // Now do the same with the values but ask the "value instance" instead! - foreach ($recipientList['value_vars'] as $variable=>$dummy) { + foreach ($recipientList['value_vars'] as $variable => $dummy) { // Is the value instance there? if (!isset($recipientList['values'][$variable])) { // Throw exception diff --git a/inc/classes/main/output/class_ConsoleOutput.php b/inc/classes/main/output/class_ConsoleOutput.php index b1cae5c..bcc1fc5 100644 --- a/inc/classes/main/output/class_ConsoleOutput.php +++ b/inc/classes/main/output/class_ConsoleOutput.php @@ -90,7 +90,7 @@ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer { public final function output ($outStream=false) { if ($outStream === false) { // Output something here... - foreach ($this->vars as $var=>$value) { + foreach ($this->vars as $var => $value) { $this->output("var=".$var.", value=".$value.""); } } else { diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index a046f18..0241cfc 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -72,8 +72,8 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { * @return void */ public function prepareRequestData () { - // Copy the $_REQUEST array - $this->requestData = $_REQUEST; + // Copy GET then POST data + $this->requestData = array_merge($_GET, $_POST); } /** @@ -124,6 +124,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { * @return void */ public function setRequestElement ($element, $value) { + error_log(__METHOD__.":{$element}={$value}"); $this->requestData[$element] = $value; } diff --git a/inc/classes/main/response/class_BaseResponse.php b/inc/classes/main/response/class_BaseResponse.php new file mode 100644 index 0000000..2ecfaa2 --- /dev/null +++ b/inc/classes/main/response/class_BaseResponse.php @@ -0,0 +1,200 @@ + + * @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 . + * + * The extended headers are taken from phpMyAdmin setup tool, written by + * Michal Cihar , licensed under GNU GPL 2.0. + */ +class BaseResponse extends BaseFrameworkSystem { + /** + * Response status + */ + private $responseStatus = "200 OK"; + + /** + * Array with all headers + */ + private $responseHeaders = array(); + + /** + * Cookies we shall sent out + */ + private $cookies = array(); + + /** + * Body of the response + */ + private $responseBody = ""; + + /** + * Instance of the template engine + */ + private $templateInstance = null; + + /** + * Fatal resolved messages from filters and so on + */ + private $fatalMessages = array(); + + /** + * Protected constructor + * + * @param $className Name of the concrete response + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for status + * + * @param $status New response status + * @return void + */ + public final function setResponseStatus ($status) { + $this->responseStatus = (string) $status; + } + + /** + * Add header element + * + * @param $name Name of header element + * @param $value Value of header element + * @return void + */ + public final function addHeader ($name, $value) { + $this->responseHeaders[$name] = $value; + } + + /** + * Reset the header array + * + * @return void + */ + public final function resetResponseHeaders () { + $this->responseHeaders = array(); + } + + /** + * "Writes" data to the response body + * + * @param $output Output we shall sent in the HTTP response + * @return void + */ + public final function writeToBody ($output) { + $this->responseBody .= $output; + } + + /** + * Sets the response body to something new + * + * @param $output Output we shall sent in the HTTP response + * @return void + */ + public final function setResponseBody ($output) { + $this->responseBody = $output; + } + + /** + * Adds a fatal message id to the response. The added messages can then be + * processed and outputed to the world + * + * @param $messageId The message id we shall add + * @return void + */ + public final function addFatalMessage ($messageId) { + // Adds the resolved message id to the fatal message list + $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId); + } + + /** + * Flushs the cached HTTP response to the outer world + * + * @param $force Wether we shall force the output or abort if headers are + * already sent with an exception + * @return void + * @throws ResponseHeadersAlreadySentException Thrown if headers are + * already sent + */ + public function flushBuffer ($force = false) { + if ((headers_sent()) && (!$force)) { + // Headers are already sent! + throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); + } elseif (!headers_sent()) { + // Send headers out + header("HTTP/1.1 {$this->responseStatus}"); + + // Used later + $now = gmdate('D, d M Y H:i:s') . ' GMT'; + + // General header for no caching + $this->addHeader('Expired', $now); // RFC2616 - Section 14.21 + $this->addHeader('Last-Modified', $now); + $this->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 + $this->addHeader('Pragma', 'no-cache'); // HTTP/1.0 + + // Define the charset to be used + //$this->addHeader('Content-type:', sprintf("text/html; charset=%s", $this->getConfigInstance()->readConfig('header_charset'))); + + // Send all headers + foreach ($this->responseHeaders as $name => $value) { + header("{$name}: {$value}"); + //* DEBUG: */ echo "{$name}: {$value}
\n"; + } // END - foreach + + // Send cookies out? + if (count($this->cookies) > 0) { + // Send all cookies + $cookieString = implode(" ", $this->cookies); + header("Set-Cookie: {$cookieString}"); + + // Remove them all + $this->cookies = array(); + } // END - if + } + + // Are there some error messages? + if (count($this->fatalMessages) == 0) { + // Flush the output to the world + $this->getWebOutputInstance()->output($this->responseBody); + } else { + // Display all error messages + $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages); + + // Send the error messages out to the world + $this->getWebOutputInstance()->output($this->responseBody); + } + + // Clear response header and body + $this->setResponseBody(""); + $this->resetResponseHeaders(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/response/class_HttpResponse.php b/inc/classes/main/response/class_HttpResponse.php deleted file mode 100644 index 869d358..0000000 --- a/inc/classes/main/response/class_HttpResponse.php +++ /dev/null @@ -1,362 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software - * @license GNU GPL 3.0 or any newer version - * @link http://www.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 . - * - * The extended headers are taken from phpMyAdmin setup tool, written by - * Michal Cihar , licensed under GNU GPL 2.0. - */ -class HttpResponse extends BaseFrameworkSystem implements Responseable { - /** - * Response status - */ - private $responseStatus = "200 OK"; - - /** - * Array with all headers - */ - private $responseHeaders = array(); - - /** - * Cookies we shall sent out - */ - private $cookies = array(); - - /** - * Body of the response - */ - private $responseBody = ""; - - /** - * Instance of the template engine - */ - private $templateInstance = null; - - /** - * Fatal resolved messages from filters and so on - */ - private $fatalMessages = array(); - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - } - - /** - * Creates an object of this class - * - * @param $appInstance An instance of a manageable application - * @return $responseInstance A prepared instance of this class - */ - public final static function createHttpResponse (ManageableApplication $appInstance) { - // Get a new instance - $responseInstance = new HttpResponse(); - - // Set the application instance - $responseInstance->setApplicationInstance($appInstance); - - // Initialize the template engine here - $responseInstance->initTemplateEngine($appInstance); - - // Return the prepared instance - return $responseInstance; - } - - /** - * Setter for status - * - * @param $status New response status - * @return void - */ - public final function setResponseStatus ($status) { - $this->responseStatus = (string) $status; - } - - /** - * Add header element - * - * @param $name Name of header element - * @param $value Value of header element - * @return void - */ - public final function addHeader ($name, $value) { - $this->responseHeaders[$name] = $value; - } - - /** - * Reset the header array - * - * @return void - */ - public final function resetResponseHeaders () { - $this->responseHeaders = array(); - } - - /** - * "Writes" data to the response body - * - * @param $output Output we shall sent in the HTTP response - * @return void - */ - public function writeToBody ($output) { - $this->responseBody .= $output; - } - - /** - * Sets the response body to something new - * - * @param $output Output we shall sent in the HTTP response - * @return void - */ - public function setResponseBody ($output) { - $this->responseBody = $output; - } - - /** - * Flushs the cached HTTP response to the outer world - * - * @param $force Wether we shall force the output or abort if headers are - * already sent with an exception - * @return void - * @throws ResponseHeadersAlreadySentException Thrown if headers are - * already sent - */ - public function flushBuffer ($force=false) { - if ((headers_sent()) && (!$force)) { - // Headers are already sent! - throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } elseif (!headers_sent()) { - // Send headers out - header("HTTP/1.1 {$this->responseStatus}"); - - // Used later - $now = gmdate('D, d M Y H:i:s') . ' GMT'; - - // General header for no caching - $this->addHeader('Expired', $now); // rfc2616 - Section 14.21 - $this->addHeader('Last-Modified', $now); - $this->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 - $this->addHeader('Pragma', 'no-cache'); // HTTP/1.0 - - // Define the charset to be used - //$this->addHeader('Content-Type:', sprintf("text/html; charset=%s", $this->getConfigInstance()->readConfig('header_charset'))); - - foreach ($this->responseHeaders as $name=>$value) { - header("{$name}: {$value}"); - } // END - foreach - - // Send cookies out? - if (count($this->cookies) > 0) { - // Send all cookies - $cookieString = implode(" ", $this->cookies); - header("Set-Cookie: {$cookieString}"); - - // Remove them all - $this->cookies = array(); - } // END - if - } - - // Are there some error messages? - if (count($this->fatalMessages) == 0) { - // Flush the output to the world - $this->getWebOutputInstance()->output($this->responseBody); - } else { - // Display all error messages - $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages); - - // Send the error messages out to the world - $this->getWebOutputInstance()->output($this->responseBody); - } - - // Clear response header and body - $this->setResponseBody(""); - $this->resetResponseHeaders(); - } - - /** - * Initializes the template engine instance - * - * @param $appInstance An instance of a manageable application - * @return void - */ - public final function initTemplateEngine (ManageableApplication $appInstance) { - $this->setTemplateInstance($this->prepareTemplateInstance($appInstance)); - } - - /** - * Adds a fatal message id to the response. The added messages can then be - * processed and outputed to the world - * - * @param $messageId The message id we shall add - * @return void - */ - public final function addFatalMessage ($messageId) { - // Adds the resolved message id to the fatal message list - $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId); - } - - /** - * Adds a cookie to the response - * - * @param $cookieName Cookie's name - * @param $cookieValue Value to store in the cookie - * @param $encrypted Do some extra encryption on the value - * @param $expires Timestamp of expiration (default: configured) - * @return void - * @throws ResponseHeadersAlreadySentException If headers are already sent - * @todo Encryption of cookie data not yet supported. - * @todo Why are these parameters conflicting? - * @todo If the return statement is removed and setcookie() commented out, - * @todo this will send only one cookie out, the first one. - */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) { - //* DEBUG: */ echo $cookieName."=".$cookieValue."
\n"; - // Are headers already sent? - if (headers_sent()) { - // Throw an exception here - //* DEBUG: */ return; - throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if - - // Shall we encrypt the cookie? - if ($encrypted === true) { - } // END - if - - // For slow browsers set the cookie array element first - $_COOKIE[$cookieName] = $cookieValue; - - // Get all config entries - if (is_null($expires)) { - $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire')); - } // END - if - - $path = $this->getConfigInstance()->readConfig('cookie_path'); - $domain = $this->getConfigInstance()->readConfig('cookie_domain'); - - setcookie($cookieName, $cookieValue, $expires); - //, $path, $domain, (isset($_SERVER['HTTPS'])) - return; - - // Now construct the full header - $cookieString = $cookieName . "=" . $cookieValue . "; "; - $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT"; - // $cookieString .= "; path=".$path."; domain=".$domain; - - // Set the cookie as a header - $this->cookies[$cookieName] = $cookieString; - } - - /** - * Redirect to a configured URL. The URL can be absolute or relative. In - * case of relative URL it will be extended automatically. - * - * @param $configEntry The configuration entry which holds our URL - * @return void - * @throws ResponseHeadersAlreadySentException If headers are already sent - */ - public function redirectToConfiguredUrl ($configEntry) { - // Is the header not yet sent? - if (headers_sent()) { - // Throw an exception here - throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if - - // Get the url from config - $url = $this->getConfigInstance()->readConfig($configEntry); - - // Do we have a "http" in front of the URL? - if (substr(strtolower($url), 0, 4) != "http") { - // Is there a / in front of the relative URL? - if (substr($url, 0, 1) == "/") $url = substr($url, 1); - - // No, then extend it with our base URL - $url = $this->getConfigInstance()->readConfig('base_url') . "/" . $url; - } // END - if - - // Add redirect header - $this->addHeader("Location", $url); - - // Set correct response status - $this->setResponseStatus("301 Moved Permanently"); - - // Clear the body - $this->setResponseBody(""); - - // Flush the result - $this->flushBuffer(); - - // All done here... - exit(); - } - - /** - * Expires the given cookie if it is set - * - * @param $cookieName Cookie to expire - * @return void - */ - public function expireCookie ($cookieName) { - // Is the cookie there? - if (isset($_COOKIE[$cookieName])) { - // Then expire it with 20 minutes past - $this->addCookie($cookieName, "", false, (time() - 1200)); - - // Remove it from array - unset($_COOKIE[$cookieName]); - } // END - if - } - - /** - * Refreshs a given cookie. This will make the cookie live longer - * - * @param $cookieName Cookie to refresh - * @return void - */ - public function refreshCookie ($cookieName) { - // Only update existing cookies - if (isset($_COOKIE[$cookieName])) { - // Update the cookie - $this->addCookie($cookieName, $_COOKIE[$cookieName], false); - } // END - if - } - - /** - * Getter for default command - * - * @return $defaultCommand Default command for this response - */ - public function getDefaultCommand () { - $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command'); - return $defaultCommand; - } -} - -// [EOF] -?> diff --git a/inc/classes/main/response/class_ImageResponse.php b/inc/classes/main/response/class_ImageResponse.php deleted file mode 100644 index 71acb35..0000000 --- a/inc/classes/main/response/class_ImageResponse.php +++ /dev/null @@ -1,381 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software - * @license GNU GPL 3.0 or any newer version - * @link http://www.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 . - * - * The extended headers are taken from phpMyAdmin setup tool, written by - * Michal Cihar , licensed under GNU GPL 2.0. - */ -class ImageResponse extends BaseFrameworkSystem implements Responseable { - /** - * Response status - */ - private $responseStatus = "200 OK"; - - /** - * Array with all headers - */ - private $responseHeaders = array(); - - /** - * Cookies we shall sent out - */ - private $cookies = array(); - - /** - * Body of the response - */ - private $responseBody = ""; - - /** - * Fatal resolved messages from filters and so on - */ - private $fatalMessages = array(); - - /** - * Instance of the image - */ - private $imageInstance = null; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - } - - /** - * Creates an object of this class - * - * @param $appInstance An instance of a manageable application - * @return $responseInstance A prepared instance of this class - */ - public final static function createImageResponse (ManageableApplication $appInstance) { - // Get a new instance - $responseInstance = new ImageResponse(); - - // Set the application instance - $responseInstance->setApplicationInstance($appInstance); - - // Initialize the template engine here - $responseInstance->initTemplateEngine($appInstance); - - // Return the prepared instance - return $responseInstance; - } - - /** - * Setter for status - * - * @param $status New response status - * @return void - */ - public final function setResponseStatus ($status) { - $this->responseStatus = (string) $status; - } - - /** - * Add header element - * - * @param $name Name of header element - * @param $value Value of header element - * @return void - */ - public final function addHeader ($name, $value) { - $this->responseHeaders[$name] = $value; - } - - /** - * Reset the header array - * - * @return void - */ - public final function resetResponseHeaders () { - $this->responseHeaders = array(); - } - - /** - * "Writes" data to the response body - * - * @param $output Output we shall sent in the HTTP response - * @return void - */ - public function writeToBody ($output) { - $this->responseBody .= $output; - } - - /** - * Sets the response body to something new - * - * @param $output Output we shall sent in the HTTP response - * @return void - */ - public function setResponseBody ($output) { - $this->responseBody = $output; - } - - /** - * Flushs the cached HTTP response to the outer world - * - * @param $force Wether we shall force the output or abort if headers are - * already sent with an exception - * @return void - * @todo Add support for fatal messages in image response - * @throws ResponseHeadersAlreadySentException Thrown if headers are - * already sent - */ - public function flushBuffer ($force=false) { - if ((headers_sent()) && (!$force)) { - // Headers are already sent! - throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } elseif (!headers_sent()) { - // Send headers out - header("HTTP/1.1 {$this->responseStatus}"); - - // Used later - $now = gmdate('D, d M Y H:i:s') . ' GMT'; - - // General header for no caching - $this->addHeader('Expired', $now); // rfc2616 - Section 14.21 - $this->addHeader('Last-Modified', $now); - $this->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 - $this->addHeader('Pragma', 'no-cache'); // HTTP/1.0 - $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'))); - - foreach ($this->responseHeaders as $name=>$value) { - header("{$name}: {$value}"); - } // END - foreach - - // Send cookies out? - if (count($this->cookies) > 0) { - // Send all cookies - $cookieString = implode(" ", $this->cookies); - header("Set-Cookie: {$cookieString}"); - - // Remove them all - $this->cookies = array(); - } // END - if - } - - // Are there some error messages? - if (count($this->fatalMessages) == 0) { - // Get image content from cache - $imageContent = $this->imageInstance->getContent(); - die($imageContent); - } else { - // Display all error messages - $this->partialStub("Fatal messages are currently unsupported in image response."); - } - - // Clear response header and body - $this->setResponseBody(""); - $this->resetResponseHeaders(); - } - - /** - * Initializes the template engine instance - * - * @param $appInstance An instance of a manageable application - * @return void - */ - public final function initTemplateEngine (ManageableApplication $appInstance) { - // Get config instance - $cfg = $this->getConfigInstance(); - - // Set new template engine - $cfg->setConfigEntry('template_class' , $cfg->readConfig('image_template_class')); - $cfg->setConfigEntry('raw_template_extension' , ".img"); - $cfg->setConfigEntry('code_template_extension', ".itp"); - $cfg->setConfigEntry('tpl_base_path' , "templates/images/"); - $cfg->setConfigEntry('code_template_type' , "image"); - - // Get a prepared instance - $this->setTemplateInstance($this->prepareTemplateInstance($appInstance)); - } - - /** - * Adds a fatal message id to the response. The added messages can then be - * processed and outputed to the world - * - * @param $messageId The message id we shall add - * @return void - */ - public final function addFatalMessage ($messageId) { - // Adds the resolved message id to the fatal message list - $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId); - } - - /** - * Adds a cookie to the response - * - * @param $cookieName Cookie's name - * @param $cookieValue Value to store in the cookie - * @param $encrypted Do some extra encryption on the value - * @param $expires Timestamp of expiration (default: configured) - * @return void - * @throws ResponseHeadersAlreadySentException If headers are already sent - * @todo Encryption of cookie data not yet supported. - * @todo Why are these parameters conflicting? - * @todo If the return statement is removed and setcookie() commented out, - * @todo this will send only one cookie out, the first one. - */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) { - // Are headers already sent? - if (headers_sent()) { - // Throw an exception here - throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if - - // Shall we encrypt the cookie? - if ($encrypted === true) { - } // END - if - - // For slow browsers set the cookie array element first - $_COOKIE[$cookieName] = $cookieValue; - - // Get all config entries - if (is_null($expires)) { - $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire')); - } // END - if - - $path = $this->getConfigInstance()->readConfig('cookie_path'); - $domain = $this->getConfigInstance()->readConfig('cookie_domain'); - - setcookie($cookieName, $cookieValue, $expires); - //, $path, $domain, (isset($_SERVER['HTTPS'])) - return; - - // Now construct the full header - $cookieString = $cookieName . "=" . $cookieValue . "; "; - $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT"; - // $cookieString .= "; path=".$path."; domain=".$domain; - - // Set the cookie as a header - $this->cookies[$cookieName] = $cookieString; - } - - /** - * Redirect to a configured URL. The URL can be absolute or relative. In - * case of relative URL it will be extended automatically. - * - * @param $configEntry The configuration entry which holds our URL - * @return void - * @throws ResponseHeadersAlreadySentException If headers are already sent - */ - public function redirectToConfiguredUrl ($configEntry) { - // Is the header not yet sent? - if (headers_sent()) { - // Throw an exception here - throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if - - // Get the url from config - $url = $this->getConfigInstance()->readConfig($configEntry); - - // Do we have a "http" in front of the URL? - if (substr(strtolower($url), 0, 4) != "http") { - // Is there a / in front of the relative URL? - if (substr($url, 0, 1) == "/") $url = substr($url, 1); - - // No, then extend it with our base URL - $url = $this->getConfigInstance()->readConfig('base_url') . "/" . $url; - } // END - if - - // Add redirect header - $this->addHeader("Location", $url); - - // Set correct response status - $this->setResponseStatus("301 Moved Permanently"); - - // Clear the body - $this->setResponseBody(""); - - // Flush the result - $this->flushBuffer(); - - // All done here... - exit(); - } - - /** - * Expires the given cookie if it is set - * - * @param $cookieName Cookie to expire - * @return void - */ - public function expireCookie ($cookieName) { - // Is the cookie there? - if (isset($_COOKIE[$cookieName])) { - // Then expire it with 20 minutes past - $this->addCookie($cookieName, "", false, (time() - 1200)); - - // Remove it from array - unset($_COOKIE[$cookieName]); - } // END - if - } - - /** - * Refreshs a given cookie. This will make the cookie live longer - * - * @param $cookieName Cookie to refresh - * @return void - */ - public function refreshCookie ($cookieName) { - // Only update existing cookies - if (isset($_COOKIE[$cookieName])) { - // Update the cookie - $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; - } - - /** - * Getter for default command - * - * @return $defaultCommand Default command for this response - */ - public function getDefaultCommand () { - $defaultCommand = $this->getConfigInstance()->readConfig('default_image_command'); - return $defaultCommand; - } -} - -// [EOF] -?> diff --git a/inc/classes/main/response/http/.htaccess b/inc/classes/main/response/http/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/response/http/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/response/http/class_HttpResponse.php b/inc/classes/main/response/http/class_HttpResponse.php new file mode 100644 index 0000000..50bf2de --- /dev/null +++ b/inc/classes/main/response/http/class_HttpResponse.php @@ -0,0 +1,211 @@ + + * @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 . + * + * The extended headers are taken from phpMyAdmin setup tool, written by + * Michal Cihar , licensed under GNU GPL 2.0. + */ +class HttpResponse extends BaseResponse implements Responseable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an object of this class + * + * @param $appInstance An instance of a manageable application + * @return $responseInstance A prepared instance of this class + */ + public final static function createHttpResponse (ManageableApplication $appInstance) { + // Get a new instance + $responseInstance = new HttpResponse(); + + // Set the application instance + $responseInstance->setApplicationInstance($appInstance); + + // Initialize the template engine here + $responseInstance->initTemplateEngine($appInstance); + + // Return the prepared instance + return $responseInstance; + } + + /** + * Initializes the template engine instance + * + * @param $appInstance An instance of a manageable application + * @return void + */ + public final function initTemplateEngine (ManageableApplication $appInstance) { + $this->setTemplateInstance($this->prepareTemplateInstance($appInstance)); + } + + /** + * Adds a cookie to the response + * + * @param $cookieName Cookie's name + * @param $cookieValue Value to store in the cookie + * @param $encrypted Do some extra encryption on the value + * @param $expires Timestamp of expiration (default: configured) + * @return void + * @throws ResponseHeadersAlreadySentException If headers are already sent + * @todo Encryption of cookie data not yet supported. + * @todo Why are these parameters conflicting? + * @todo If the return statement is removed and setcookie() commented out, + * @todo this will send only one cookie out, the first one. + */ + public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) { + //* DEBUG: */ echo $cookieName."=".$cookieValue."
\n"; + // Are headers already sent? + if (headers_sent()) { + // Throw an exception here + //* DEBUG: */ return; + throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); + } // END - if + + // Shall we encrypt the cookie? + if ($encrypted === true) { + } // END - if + + // For slow browsers set the cookie array element first + $_COOKIE[$cookieName] = $cookieValue; + + // Get all config entries + if (is_null($expires)) { + $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire')); + } // END - if + + $path = $this->getConfigInstance()->readConfig('cookie_path'); + $domain = $this->getConfigInstance()->readConfig('cookie_domain'); + + setcookie($cookieName, $cookieValue, $expires); + //, $path, $domain, (isset($_SERVER['HTTPS'])) + return; + + // Now construct the full header + $cookieString = $cookieName . "=" . $cookieValue . "; "; + $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT"; + // $cookieString .= "; path=".$path."; domain=".$domain; + + // Set the cookie as a header + $this->cookies[$cookieName] = $cookieString; + } + + /** + * Redirect to a configured URL. The URL can be absolute or relative. In + * case of relative URL it will be extended automatically. + * + * @param $configEntry The configuration entry which holds our URL + * @return void + * @throws ResponseHeadersAlreadySentException If headers are already sent + */ + public function redirectToConfiguredUrl ($configEntry) { + // Is the header not yet sent? + if (headers_sent()) { + // Throw an exception here + throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); + } // END - if + + // Assign application data + $this->getTemplateInstance()->assignApplicationData($this->getApplicationInstance()); + + // Get the url from config + $url = $this->getConfigInstance()->readConfig($configEntry); + + // Compile the URL + $url = $this->getTemplateInstance()->compileRawCode($url); + + // Do we have a "http" in front of the URL? + if (substr(strtolower($url), 0, 4) != "http") { + // Is there a / in front of the relative URL? + if (substr($url, 0, 1) == "/") $url = substr($url, 1); + + // No, then extend it with our base URL + $url = $this->getConfigInstance()->readConfig('base_url') . "/" . $url; + } // END - if + + // Add redirect header + $this->addHeader("Location", $url); + + // Set correct response status + $this->setResponseStatus("301 Moved Permanently"); + + // Clear the body + $this->setResponseBody(""); + + // Flush the result + $this->flushBuffer(); + + // All done here... + exit(); + } + + /** + * Expires the given cookie if it is set + * + * @param $cookieName Cookie to expire + * @return void + */ + public function expireCookie ($cookieName) { + // Is the cookie there? + if (isset($_COOKIE[$cookieName])) { + // Then expire it with 20 minutes past + $this->addCookie($cookieName, "", false, (time() - 1200)); + + // Remove it from array + unset($_COOKIE[$cookieName]); + } // END - if + } + + /** + * Refreshs a given cookie. This will make the cookie live longer + * + * @param $cookieName Cookie to refresh + * @return void + */ + public function refreshCookie ($cookieName) { + // Only update existing cookies + if (isset($_COOKIE[$cookieName])) { + // Update the cookie + $this->addCookie($cookieName, $_COOKIE[$cookieName], false); + } // END - if + } + + /** + * Getter for default command + * + * @return $defaultCommand Default command for this response + */ + public function getDefaultCommand () { + $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command'); + return $defaultCommand; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/response/image/.htaccess b/inc/classes/main/response/image/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/response/image/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/response/image/class_ImageResponse.php b/inc/classes/main/response/image/class_ImageResponse.php new file mode 100644 index 0000000..c03e6ea --- /dev/null +++ b/inc/classes/main/response/image/class_ImageResponse.php @@ -0,0 +1,268 @@ + + * @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 . + * + * The extended headers are taken from phpMyAdmin setup tool, written by + * Michal Cihar , licensed under GNU GPL 2.0. + */ +class ImageResponse extends BaseResponse implements Responseable { + /** + * Instance of the image + */ + private $imageInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an object of this class + * + * @param $appInstance An instance of a manageable application + * @return $responseInstance A prepared instance of this class + */ + public final static function createImageResponse (ManageableApplication $appInstance) { + // Get a new instance + $responseInstance = new ImageResponse(); + + // Set the application instance + $responseInstance->setApplicationInstance($appInstance); + + // Initialize the template engine here + $responseInstance->initTemplateEngine($appInstance); + + // Return the prepared instance + return $responseInstance; + } + + /** + * Initializes the template engine instance + * + * @param $appInstance An instance of a manageable application + * @return void + */ + public final function initTemplateEngine (ManageableApplication $appInstance) { + // Get config instance + $cfg = $this->getConfigInstance(); + + // Set new template engine + $cfg->setConfigEntry('template_class' , $cfg->readConfig('image_template_class')); + $cfg->setConfigEntry('raw_template_extension' , ".img"); + $cfg->setConfigEntry('code_template_extension', ".itp"); + $cfg->setConfigEntry('tpl_base_path' , "templates/images/"); + $cfg->setConfigEntry('code_template_type' , "image"); + + // Get a prepared instance + $this->setTemplateInstance($this->prepareTemplateInstance($appInstance)); + } + + /** + * Adds a cookie to the response + * + * @param $cookieName Cookie's name + * @param $cookieValue Value to store in the cookie + * @param $encrypted Do some extra encryption on the value + * @param $expires Timestamp of expiration (default: configured) + * @return void + * @throws ResponseHeadersAlreadySentException If headers are already sent + * @todo Encryption of cookie data not yet supported. + * @todo Why are these parameters conflicting? + * @todo If the return statement is removed and setcookie() commented out, + * @todo this will send only one cookie out, the first one. + */ + public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) { + // Are headers already sent? + if (headers_sent()) { + // Throw an exception here + throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); + } // END - if + + // Shall we encrypt the cookie? + if ($encrypted === true) { + } // END - if + + // For slow browsers set the cookie array element first + $_COOKIE[$cookieName] = $cookieValue; + + // Get all config entries + if (is_null($expires)) { + $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire')); + } // END - if + + $path = $this->getConfigInstance()->readConfig('cookie_path'); + $domain = $this->getConfigInstance()->readConfig('cookie_domain'); + + setcookie($cookieName, $cookieValue, $expires); + //, $path, $domain, (isset($_SERVER['HTTPS'])) + return; + + // Now construct the full header + $cookieString = $cookieName . "=" . $cookieValue . "; "; + $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT"; + // $cookieString .= "; path=".$path."; domain=".$domain; + + // Set the cookie as a header + $this->cookies[$cookieName] = $cookieString; + } + + /** + * Redirect to a configured URL. The URL can be absolute or relative. In + * case of relative URL it will be extended automatically. + * + * @param $configEntry The configuration entry which holds our URL + * @return void + * @throws ResponseHeadersAlreadySentException If headers are already sent + */ + public function redirectToConfiguredUrl ($configEntry) { + // Is the header not yet sent? + if (headers_sent()) { + // Throw an exception here + throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); + } // END - if + + // Assign application data + $this->getTemplateInstance()->assignApplicationData($this->getApplicationInstance()); + + // Get the url from config + $url = $this->getConfigInstance()->readConfig($configEntry); + + // Compile the URL + $url = $this->getTemplateInstance()->compileRawCode($url); + + // Do we have a "http" in front of the URL? + if (substr(strtolower($url), 0, 4) != "http") { + // Is there a / in front of the relative URL? + if (substr($url, 0, 1) == "/") $url = substr($url, 1); + + // No, then extend it with our base URL + $url = $this->getConfigInstance()->readConfig('base_url') . "/" . $url; + } // END - if + + // Add redirect header + $this->addHeader("Location", $url); + + // Set correct response status + $this->setResponseStatus("301 Moved Permanently"); + + // Clear the body + $this->setResponseBody(""); + + // Flush the result + $this->flushBuffer(); + + // All done here... + exit(); + } + + /** + * Flushs the cached HTTP response to the outer world + * + * @param $force Wether we shall force the output or abort if headers are + * already sent with an exception + * @return void + */ + public function flushBuffer ($force = false) { + // Finish the image + $this->getImageInstance()->finishImage(); + + // Get image content + $content = $this->getImageInstance()->getContent(); + + // Set it as response body + $this->setResponseBody($content); + + // Set content type + $this->addHeader('Content-type', "image/".$this->getImageInstance()->getImageType()); + + // Call parent method + parent::flushBuffer($force); + } + + /** + * Expires the given cookie if it is set + * + * @param $cookieName Cookie to expire + * @return void + */ + public function expireCookie ($cookieName) { + // Is the cookie there? + if (isset($_COOKIE[$cookieName])) { + // Then expire it with 20 minutes past + $this->addCookie($cookieName, "", false, (time() - 1200)); + + // Remove it from array + unset($_COOKIE[$cookieName]); + } // END - if + } + + /** + * Refreshs a given cookie. This will make the cookie live longer + * + * @param $cookieName Cookie to refresh + * @return void + */ + public function refreshCookie ($cookieName) { + // Only update existing cookies + if (isset($_COOKIE[$cookieName])) { + // Update the cookie + $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; + } + + /** + * Getter for image instanxe + * + * @return $imageInstance An instance of an image + */ + public final function getImageInstance () { + return $this->imageInstance; + } + + /** + * Getter for default command + * + * @return $defaultCommand Default command for this response + */ + public function getDefaultCommand () { + $defaultCommand = $this->getConfigInstance()->readConfig('default_image_command'); + return $defaultCommand; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index f7b1648..3f8918b 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -103,7 +103,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $entryKey = $this->key(); // Now get the update criteria array and update all entries - foreach ($updateInstance->getUpdateCriteria() as $criteriaKey=>$criteriaValue) { + foreach ($updateInstance->getUpdateCriteria() as $criteriaKey => $criteriaValue) { // Update data $this->resultArray['rows'][$entryKey][$criteriaKey] = $criteriaValue; @@ -318,7 +318,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $currentEntry = $this->current(); // Walk only through out-dated columns - foreach ($this->outDated as $key=>$dummy) { + foreach ($this->outDated as $key => $dummy) { // Does this key exist? //* DEBUG: */ echo "outDated: {$key}
\n"; if (isset($currentEntry[$key])) { diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 4db73b6..7e1aa7c 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -69,11 +69,6 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private $varStack = array(); - /** - * Configuration variables in a simple array - */ - private $configVariables = array(); - /** * Loaded templates for recursive protection and detection */ @@ -154,10 +149,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Is the group there? if (isset($this->varStack[$this->currGroup])) { // Now search for it - foreach ($this->varStack[$this->currGroup] as $idx=>$currEntry) { + foreach ($this->varStack[$this->currGroup] as $idx => $currEntry) { + //* DEBUG: */ echo __METHOD__.":currGroup={$this->currGroup},idx={$idx},currEntry={$currEntry['name']},var={$var}
\n"; // Is the entry found? if ($currEntry['name'] == $var) { // Found! + //* DEBUG: */ echo __METHOD__.":FOUND!
\n"; $found = $idx; break; } // END - if @@ -586,7 +583,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Did we find some variables? if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) { // Initialize all missing variables - foreach ($variableMatches[3] as $key=>$var) { + foreach ($variableMatches[3] as $key => $var) { // Variable name $varName = $variableMatches[1][$key]; @@ -628,10 +625,17 @@ class BaseTemplateEngine extends BaseFrameworkSystem { if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) { // Template not found, but maybe variable assigned? + //* DEBUG: */ echo __METHOD__.":template={$template}
\n"; if ($this->isVariableAlreadySet($template) !== false) { // Use that content here $this->loadedRawData[$template] = $this->readVariable($template); + // Recursive protection: + $this->loadedTemplates[] = $template; + } elseif (isset($this->varStack['config'][$template])) { + // Use that content here + $this->loadedRawData[$template] = $this->varStack['config'][$template]; + // Recursive protection: $this->loadedTemplates[] = $template; } else { @@ -671,7 +675,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { if (in_array($template, $this->compiledTemplates)) { // Abort here... return; - } + } // END - if // Remember this template being compiled $this->compiledTemplates[] = $template; @@ -703,7 +707,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private function insertAllTemplates (array $templateMatches) { // Run through all loaded codes - foreach ($this->loadedRawData as $template=>$code) { + foreach ($this->loadedRawData as $template => $code) { // Search for the template $foundIndex = array_search($template, $templateMatches[1]); @@ -766,7 +770,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private function assignAllVariables (array $varMatches) { // Search for all variables - foreach ($varMatches[1] as $key=>$var) { + foreach ($varMatches[1] as $key => $var) { // Detect leading equals if (substr($varMatches[2][$key], 0, 1) == "=") { @@ -796,7 +800,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { if (count($this->loadedRawData) > 0) { // Then compile all! - foreach ($this->loadedRawData as $template=>$code) { + foreach ($this->loadedRawData as $template => $code) { // Is this template already compiled? if (in_array($template, $this->compiledTemplates)) { @@ -836,7 +840,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private function insertRawTemplates () { // Load all templates - foreach ($this->rawTemplates as $template=>$content) { + foreach ($this->rawTemplates as $template => $content) { // Set the template as a variable with the content $this->assignVariable($template, $content); } @@ -895,7 +899,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ public function assignConfigVariable ($var) { // Sweet and simple... - $this->configVariables[$var] = $this->getConfigInstance()->readConfig($var); + //* DEBUG: */ echo __METHOD__.":var={$var}
\n"; + $this->varStack['config'][$var] = $this->getConfigInstance()->readConfig($var); } /** @@ -916,7 +921,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Load a specified code template into the engine * - * @param $template The code template we shall load which is + * @param $template The code template we shall load which is * located in "code" by default * @return void */ @@ -944,14 +949,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Transfer it's name/value combination to the $content array //* DEBUG: */ echo $currVariable['name']."=
".htmlentities($currVariable['value'])."
\n"; $dummy[$currVariable['name']] = $currVariable['value']; - }// END - if - // Set the new variable (don't remove the second dollar !) + // Set the new variable (don't remove the second dollar!) $$validVar = $dummy; // Prepare all configuration variables - $config = $this->configVariables; + $config = null; + if (isset($this->varStack['config'])) { + $config = $this->varStack['config']; + } // END - if // Remove some variables unset($idx); @@ -1184,6 +1191,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Get version number and assign it $this->assignVariable('app_version' , $appInstance->getAppVersion()); + + // Assign extra application-depending data + $appInstance->assignExtraTemplateData($this); } /** diff --git a/inc/classes/third_party/api/wernisportal/class_WernisApi.php b/inc/classes/third_party/api/wernisportal/class_WernisApi.php index 4c306dd..cdda5d4 100644 --- a/inc/classes/third_party/api/wernisportal/class_WernisApi.php +++ b/inc/classes/third_party/api/wernisportal/class_WernisApi.php @@ -200,7 +200,7 @@ class WernisApi extends BaseFrameworkSystem { // Construct the request string $requestString = $this->config['api_url'] . $scriptName."?api_id=".$this->config['wernis_api_id']."&api_key=".$this->config['wernis_api_key']; - foreach ($requestData as $key=>$value) { + foreach ($requestData as $key => $value) { $requestString .= "&".$key."=".$value; } diff --git a/inc/config.php b/inc/config.php index 8f25248..d50782a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -42,7 +42,7 @@ $cfg->setConfigEntry('base_url', $cfg->detectBaseUrl()); $cfg->setConfigEntry('db_type', "local"); // CFG: LOCAL-DB-PATH -$cfg->setConfigEntry('local_db_path', $cfg->readConfig('base_path', "db/")); +$cfg->setConfigEntry('local_db_path', $cfg->readConfig('base_path') . "db/"); // CFG: TIME-ZONE $cfg->setDefaultTimezone("Europe/Berlin"); @@ -84,7 +84,7 @@ $cfg->setConfigEntry('lang_base_path', "inc/language/"); // DON'T MISS THE TRAIL $cfg->setConfigEntry('compressor_base_path', "inc/classes/main/compressor/"); // DON'T MISS THE TRAILING SLASH! // CFG: APPLICATION-PATH -$cfg->setConfigEntry('application_path', "application"); +$cfg->setConfigEntry('application_path', $cfg->readConfig('base_path') . "application/"); // CFG: COMPILE-OUTPUT-PATH $cfg->setConfigEntry('compile_output_path', "templates/_compiled/"); // DON'T MISS THE TRAILING SLASH! @@ -116,9 +116,6 @@ $cfg->setConfigEntry('tpl_selector_prefix', "selector"); // CFG: WEB-CONTENT-TYPE $cfg->setConfigEntry('web_content_type', "text/html"); -// CFG: HEADER-CHARSET -$cfg->setConfigEntry('header_charset', "utf-8"); - // CFG: VALID-TEMPLATE-VARIABLE $cfg->setConfigEntry('tpl_valid_var', "content"); diff --git a/inc/database.php b/inc/database.php index 7f9003a..03bc377 100644 --- a/inc/database.php +++ b/inc/database.php @@ -23,7 +23,7 @@ */ // Initialize layer -$layer = null; +$layerInstance = null; // Get config instance $cfg = FrameworkConfiguration::getInstance(); @@ -51,7 +51,7 @@ unset($INC); // Prepare database instance try { - $db = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getInstance(), $layer); + $db = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getInstance(), $layerInstance); } catch (NullPointerException $e) { ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: %s
\n", $e->getMessage() diff --git a/inc/database/lib-local.php b/inc/database/lib-local.php index f9ec63e..ae748c5 100644 --- a/inc/database/lib-local.php +++ b/inc/database/lib-local.php @@ -24,7 +24,7 @@ // Zum Testen speichern wir in lokale Dateien (LocalFileDatabase) try { - $layer = LocalFileDatabase::createLocalFileDatabase(FrameworkConfiguration::getInstance()->readConfig('local_db_path'), FileIoHandler::getInstance()); + $layerInstance = LocalFileDatabase::createLocalFileDatabase(FrameworkConfiguration::getInstance()->readConfig('local_db_path'), FileIoHandler::getInstance()); } catch (SavePathIsEmptyException $e) { ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer could not be initialized. Reason: %s", $e->getMessage() diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 5f5f97a..134b8c1 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -119,8 +119,8 @@ class ClassLoader { // Construct the FQFN for the cache if (!defined('DEVELOPER')) { - $this->listCacheFQFN = $this->cfgInstance->readConfig('base_path') . $this->cfgInstance->readConfig('local_db_path') . "list-" . $this->cfgInstance->readConfig('app_name') . ".cache"; - $this->classCacheFQFN = $this->cfgInstance->readConfig('base_path') . $this->cfgInstance->readConfig('local_db_path') . "class-" . $this->cfgInstance->readConfig('app_name') . ".cache"; + $this->listCacheFQFN = $this->cfgInstance->readConfig('local_db_path') . "list-" . $this->cfgInstance->readConfig('app_name') . ".cache"; + $this->classCacheFQFN = $this->cfgInstance->readConfig('local_db_path') . "class-" . $this->cfgInstance->readConfig('app_name') . ".cache"; } // END - if // Set suffix and prefix from configuration @@ -334,7 +334,7 @@ class ClassLoader { */ private function includeExtraConfigs () { // Run through all class names (should not be much) - foreach ($this->classes as $fileName=>$fqfn) { + foreach ($this->classes as $fileName => $fqfn) { // Is this a config? if (substr($fileName, 0, $this->prefixLen) == $this->prefix) { // Then include it diff --git a/inc/selector.php b/inc/selector.php index 69f4134..ddab769 100644 --- a/inc/selector.php +++ b/inc/selector.php @@ -45,8 +45,7 @@ foreach ($configAppIncludes as $inc) { } // Generate a FQFN for the helper class - $fqfn = sprintf("%s%s/%s/%s%s", - $cfg->readConfig('base_path'), + $fqfn = sprintf("%s%s/%s%s", $cfg->readConfig('application_path'), $cfg->readConfig('app_name'), $inc, diff --git a/index.php b/index.php index f6c6005..5b3894a 100644 --- a/index.php +++ b/index.php @@ -93,13 +93,25 @@ class ApplicationEntryPoint { // Get and prepare backtrace for output $backtraceArray = debug_backtrace(); $backtrace = ""; - foreach ($backtraceArray as $key=>$trace) { + foreach ($backtraceArray as $key => $trace) { if (!isset($trace['file'])) $trace['file'] = __FILE__; if (!isset($trace['line'])) $trace['line'] = __LINE__; if (!isset($trace['args'])) $trace['args'] = array(); $backtrace .= "".basename($trace['file']).":".$trace['line'].", ".$trace['function']."(".count($trace['args']).")
"; } // END - foreach + // Init application instance + $appInstance = null; + + // Is the class there? + if (class_exists('ApplicationHelper')) { + // Get application instance + $appInstance = ApplicationHelper::getInstance(); + + // Assign application data + $templateInstance->assignApplicationData($appInstance); + } // END - if + // Assign variables $templateInstance->assignVariable('message', $message); $templateInstance->assignVariable('code', $code); diff --git a/templates/de/code/header.ctp b/templates/de/code/header.ctp index 7da5dba..c9291e9 100644 --- a/templates/de/code/header.ctp +++ b/templates/de/code/header.ctp @@ -10,7 +10,7 @@ - +