*
* @param $basePath The local base path for all templates
* @param $langInstance An instance of LanguageSystem (default)
- * @param $ioInstance An instance of FileIOHandler (default, middleware!)
+ * @param $ioInstance An instance of FileIoHandler (default, middleware!)
* @return $tplInstance An instance of TemplateEngine
* @throws BasePathIsEmptyException If the provided $basePath is empty
* @throws InvalidBasePathStringException If $basePath is no string
* @throws BasePathReadProtectedException If $basePath is
* read-protected
*/
- public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIOHandler $ioInstance) {
+ public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) {
// Get a new instance
$tplInstance = new TemplateEngine();
// Set the language and IO instances
$tplInstance->setLanguageInstance($langInstance);
- $tplInstance->setFileIOInstance($ioInstance);
+ $tplInstance->setFileIoInstance($ioInstance);
// Set template extensions
$tplInstance->setRawTemplateExtension($cfgInstance->readConfig("raw_template_extension"));
*/
private function loadRawTemplateData ($fqfn) {
// Get a input/output instance from the middleware
- $ioInstance = $this->getFileIOInstance();
+ $ioInstance = $this->getFileIoInstance();
// Validate the instance
if (is_null($ioInstance)) {
// Initialize all missing variables
foreach ($variableMatches[3] as $key=>$var) {
// Is the variable name valid?
- if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config")) {
+ // @TODO Find a better way than ignoring our instance variable $this
+ if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config") && ($variableMatches[1][$key] != "this")) {
// Invalid variable name
throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR);
+ } elseif ($variableMatches[1][$key] != "this") {
+ // Try to assign it, empty strings are being ignored
+ $this->assignTemplateVariable($variableMatches[1][$key], $var);
}
-
- // Try to assign it, empty strings are being ignored
- $this->assignTemplateVariable($variableMatches[1][$key], $var);
}
}
}
addslashes($this->getRawTemplateData())
);
+ // This loop does remove the backslashes (\) in PHP parameters
+ // @TODO Make this some nicer...
+ while (strpos($eval, "<?") !== false) {
+ // Get left part before "<?"
+ $evalLeft = substr($eval, 0, strpos($eval, "<?"));
+
+ // Get all from right of "<?"
+ $evalRight = substr($eval, (strpos($eval, "<?") + 2));
+
+ // Is this a full PHP tag?
+ if (substr(strtolower($evalRight), 0, 3) == "php") {
+ // Remove "php" string from full PHP tag
+ $evalRight = substr($evalRight, 3);
+ }
+
+ // Cut middle part out and remove escapes
+ $evalMiddle = trim(substr($evalRight, 0, strpos($evalRight, "?>")));
+ $evalMiddle = stripslashes($evalMiddle);
+
+ // Remove the middle part from right one
+ $evalRight = substr($evalRight, (strpos($evalRight, "?>") + 2));
+
+ // And put all together
+ $eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight);
+ }
+
+ // Prepare PHP code for eval() command
+ $eval = str_replace(
+ "<%php", "\";",
+ str_replace(
+ "%>", "\$result = \"", $eval
+ )
+ );
+
// Debug message
if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command: <pre><em>%s</em></pre><br />\n",
$this->__toString(),
// Get the content and set it in the response class
$responseInstance->writeToBody($this->getCompiledData());
}
+
+ /**
+ * Assigns all the application data with template variables
+ *
+ * @param $appInstance A manageable application instance
+ * @return void
+ */
+ public function assignApplicationData (ManageableApplication $appInstance) {
+ // Get long name and assign it
+ $this->assignVariable("app_full_name" , $appInstance->getAppName());
+
+ // Get short name and assign it
+ $this->assignVariable("app_short_name", $appInstance->getAppShortName());
+
+ // Get version number and assign it
+ $this->assignVariable("app_version" , $appInstance->getAppVersion());
+ }
}
// [EOF]