<?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->addInputHiddenField('captcha_hash', $this->readVariable('captcha_hash'));
-$helper->flushContent();
+$captchaHelper = WebFormHelper::createWebFormHelper($this, 'captcha_code', false, false);
+$captchaHelper->addFormGroup('code', "");
+$captchaHelper->addFieldText('code', "Bitte wiederhole den Code:");
+$captchaHelper->addInputTextField('code');
+$captchaHelper->addInputHiddenField('hash', $this->readVariable('captcha_hash'));
+$captchaHelper->flushContent();
// [EOF]
?>
// Get helper instance for web forms. This will add the opening form-tag to
// the helper's render cache which is simply a small variable in the class
// BaseHelper.
-$helper = WebFormHelper::createWebFormHelper($this, "shipsimu_user_login");
+$helper = WebFormHelper::createWebFormHelper($this, 'shipsimu_user_login');
// Formular deaktiviert?
if ($helper->ifLoginIsEnabled()) {
// Ist Gastlogin erlaubt?
if ($helper->ifGuestLoginAllowed()) {
// Neue Helper-Instanz holen
- $helper = WebFormHelper::createWebFormHelper($this, "shipsimu_guest_login");
+ $helper = WebFormHelper::createWebFormHelper($this, 'shipsimu_guest_login');
$helper->addInputHiddenConfiguredField('username', 'guest_login');
$helper->addInputHiddenConfiguredField('pass', 'guest_login');
// Get helper instance for web forms. This will add the opening form-tag to
// the helper's render cache which is simply a small variable in the class
// BaseHelper.
-$helper = WebFormHelper::createWebFormHelper($this, "shipsimu_register");
+$helper = WebFormHelper::createWebFormHelper($this, 'shipsimu_register');
// Always ask at least for nickname and password
$helper->addFormGroup('login', "Bitte gebe hier gewünschten Nickname und dein Zugangspasswort ein.");
*
* @return void
*/
- public function debugBacktrace () {
+ public function debugBackTrace () {
// Sorry, there is no other way getting this nice backtrace
print "<pre>\n";
debug_print_backtrace();
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Should never be executed...
- $this->debugBacktrace();
+ $this->debugBackTrace();
}
/**
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseCaptcha extends BaseHelper {
+ /**
+ * A helper instance for the form
+ */
+ private $helperInstance = null;
+
/**
* Instance of an RNG
*/
protected final function getRngInstance () {
return $this->rngInstance;
}
+
+ /**
+ * Setter for helper instance
+ *
+ * @param $helperInstance An instance of a helper class
+ * @return void
+ */
+ protected final function setHelperInstance (HelpableTemplate $helperInstance) {
+ $this->helperInstance = $helperInstance;
+ }
+
+ /**
+ * Getter for helper instance
+ *
+ * @return $helperInstance An instance of a helper class
+ */
+ public final function getHelperInstance () {
+ return $this->helperInstance;
+ }
}
// [EOF]
/**
* Creates an instance of this captcha class
*
- * @param $templateInstance An instance of a template engine
+ * @param $helperInstance An instance of a helper class
* @param $extraInstance An extra instance, just for better hash data
* @return $captchaInstance An instance of this captcha class
*/
- public final static function createGraphicalCodeCaptcha (CompileableTemplate $templateInstance, FrameworkInterface $extraInstance = null) {
+ public final static function createGraphicalCodeCaptcha (HelpableTemplate $helperInstance, FrameworkInterface $extraInstance = null) {
// Get a new instance
$captchaInstance = new GraphicalCodeCaptcha();
// Set template instance
- $captchaInstance->setTemplateInstance($templateInstance);
+ $captchaInstance->setHelperInstance($helperInstance);
// Initialize the RNG
$captchaInstance->initializeRandomNumberGenerator($extraInstance);
* @return void
*/
public function renderCode () {
+ // Get helper instance
+ $helperInstance = $this->getHelperInstance();
+
+ // Get template instance
+ $templateInstance = $helperInstance->getTemplateInstance();
+
// Load a template for this CAPTCHA
- $this->getTemplateInstance()->loadCodeTemplate("captch_graphic_code");
+ $templateInstance->loadCodeTemplate("captch_graphic_code");
+
+ // Rename variable
+ $templateInstance->renameVariable('captcha_code', $helperInstance->getFormName().'_captcha');
+ $templateInstance->renameVariable('captcha_hash', $helperInstance->getFormName().'_hash');
+ $templateInstance->renameVariable('encrypted_code', $helperInstance->getFormName().'_encrypt');
// Assign variables
- $this->getTemplateInstance()->assignVariable('encrypted_code', urlencode(base64_encode($this->encryptedString)));
- $this->getTemplateInstance()->assignVariable('captcha_hash', $this->hashedString);
+ $templateInstance->assignVariable($helperInstance->getFormName().'_encrypt', urlencode(base64_encode($this->encryptedString)));
+ $templateInstance->assignVariable($helperInstance->getFormName().'_hash', $this->hashedString);
// Compile the template
- $this->getTemplateInstance()->compileTemplate();
+ $templateInstance->compileTemplate();
// Get the content back
- $this->addContent($this->getTemplateInstance()->getRawTemplateData());
+ $this->addContent($templateInstance->getRawTemplateData());
}
}
*/
private $subGroupOpened = false;
+ /**
+ * Name of the group
+ */
+ private $groupName = "";
+
/**
* Name of the sub group
*/
// Is a group open?
if ($this->groupOpened === true) {
// Then automatically close it here
- $this->addFormGroup("", "");
+ $this->addFormGroup();
} // END - if
// Simply close it
/**
* Add a form group or close an already opened and open a new one
*
- * @param $groupName Name of the group
+ * @param $groupName Name of the group or last opened if empty
* @param $groupText Text including HTML to show above this group
* @return void
* @throws FormClosedException If no form has been opened before
* @throws EmptyVariableException If $groupName is not set
*/
- public function addFormGroup ($groupName, $groupText) {
+ public function addFormGroup ($groupName = "", $groupText = "") {
// Is a form opened?
if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw exception here
if ((empty($groupName)) && ($this->groupOpened === false)) {
// Throw exception here
throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (empty($groupName)) {
+ // Close the last opened
+ $groupName = $this->groupName;
+ }
+
+ // Same group to open?
+ if (($this->groupOpened === false) && ($groupName == $this->groupName)) {
+ // Abort here silently
+ return false;
} // END - if
// Initialize content with closing div by default
$this->addContent($content);
// Switch the state
+ $this->groupName = $groupName;
$this->groupOpened = true;
} else {
// Is a sub group opened?
if ($this->subGroupOpened === true) {
// Close it here
- $this->addFormSubGroup("", "");
+ $this->addFormSubGroup();
} // END - if
// Add the content
* throws an exception if no group has been opened before or if the sub
* group name is empty.
*
- * @param $subGroupName Name of the group
+ * @param $subGroupName Name of the group or last opened if empty
* @param $subGroupText Text including HTML to show above this group
* @return void
* @throws FormGroupClosedException If no group has been opened before
* @throws EmptyVariableException If $subGroupName is not set
*/
- public function addFormSubGroup ($subGroupName, $subGroupText) {
+ public function addFormSubGroup ($subGroupName = "", $subGroupText = "") {
// Is a group opened?
if ($this->groupOpened === false) {
// Throw exception here
if ((empty($subGroupName)) && ($this->subGroupOpened === false)) {
// Throw exception here
throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } // END - if
+ } elseif (empty($subGroupName)) {
+ // Close the last opened
+ $subGroupName = $this->subGroupName;
+ }
// Initialize content with closing div by default
$content = " </div>\n</div><!-- Sub group- CLOSE //-->";
// Is a group open?
if ($this->groupOpened === true) {
// Then automatically close it here
- $this->addFormGroup("", "");
+ $this->addFormGroup();
} // END - if
// Generate the content
if (($this->formOpened === true) && ($this->formEnabled === true)) {
// Close the form automatically
$this->addFormTag();
- } // END - if
+ } elseif ($this->formEnabled === false) {
+ if ($this->subGroupOpened === true) {
+ // Close sub group
+ $this->addFormSubGroup();
+ } elseif ($this->groupOpened === true) {
+ // Close group
+ $this->addFormGroup();
+ }
+ }
// Send content to template engine
+ //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->getContent())."<br />\n";
$this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
}
$extraInstance = Registry::getRegistry()->getInstance('extra');
// Get a configured instance
- $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this->getTemplateInstance(), $extraInstance));
+ $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this, $extraInstance));
// Initiate the CAPTCHA
$captchaInstance->initiateCaptcha();
} // END - if
// Debug output
- //* DEBUG: */ $this->debugBacktrace();
+ //* DEBUG: */ $this->debugBackTrace();
// Set action name
$this->setActionName($actionName);
} // END - if
// Debug output
- //* DEBUG: */ $this->debugBacktrace();
+ //* DEBUG: */ $this->debugBackTrace();
// Set command name
$this->setCommandName($commandName);
} // END - while
// Debug output
- //* DEBUG: */ $this->debugBacktrace();
+ //* DEBUG: */ $this->debugBackTrace();
// Return the result
return $isValid;
*/
private function loadController ($controllerName) {
// Debug message
- //* DEBUG: */ $this->debugBacktrace();
+ //* DEBUG: */ $this->debugBackTrace();
// Cache default command
$defaultController = $this->getConfigInstance()->readConfig('default_command');
* @return void
*/
private final function setTemplateType ($templateType) {
- // Cast it
- $templateType = (string) $templateType;
-
- // And set it (only 2 letters)
- $this->templateType = $templateType;
+ $this->templateType = (string) $templateType;
}
/**
* @return void
*/
private final function setLastTemplate ($template) {
- // Cast it to string
- $template = (string) $template;
- $this->lastTemplate = $template;
+ $this->lastTemplate = (string) $template;
}
/**
* @return void
*/
public final function setBasePath ($basePath) {
- // Cast it
- $basePath = (string) $basePath;
-
// And set it
- $this->basePath = $basePath;
+ $this->basePath = (string) $basePath;
}
/**
* @return void
*/
public final function setRawTemplateExtension ($templateExtension) {
- // Cast it
- $templateExtension = (string) $templateExtension;
-
// And set it
- $this->templateExtension = $templateExtension;
+ $this->templateExtension = (string) $templateExtension;
}
/**
* @return void
*/
public final function setCodeTemplateExtension ($codeExtension) {
- // Cast it
- $codeExtension = (string) $codeExtension;
-
// And set it
- $this->codeExtension = $codeExtension;
+ $this->codeExtension = (string) $codeExtension;
}
/**
* @return void
*/
public final function setCompileOutputPath ($compileOutputPath) {
- // Cast it
- $compileOutputPath = (string) $compileOutputPath;
-
// And set it
- $this->compileOutputPath = $compileOutputPath;
+ $this->compileOutputPath = (string) $compileOutputPath;
}
/**
* @return void
*/
private final function setRawTemplateData ($rawTemplateData) {
- // Cast it to string
- $rawTemplateData = (string) $rawTemplateData;
-
// And store it in this class
- $this->rawTemplateData = $rawTemplateData;
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($rawTemplateData)." Bytes set.<br />\n";
+ //* DEBUG: */ echo $this->currGroup." variables: ".count($this->varStack[$this->currGroup]).", groups=".count($this->varStack)."<br />\n";
+ $this->rawTemplateData = (string) $rawTemplateData;
+ }
+
+ /**
+ * Getter for raw template data
+ *
+ * @return $rawTemplateData The raw data from the template
+ */
+ public final function getRawTemplateData () {
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->rawTemplateData)." Bytes read.<br />\n";
+ return $this->rawTemplateData;
}
/**
* @return void
*/
private final function setCompiledData ($compiledData) {
- // Cast it to string
- $compiledData = (string) $compiledData;
-
// And store it in this class
- $this->compiledData = $compiledData;
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($compiledData)." Bytes set.<br />\n";
+ $this->compiledData = (string) $compiledData;
+ }
+
+ /**
+ * Getter for compiled templates
+ */
+ public final function getCompiledData () {
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->compiledData)." Bytes read.<br />\n";
+ return $this->compiledData;
}
/**
* @return void
*/
private function loadTemplate ($template) {
- // Cast it to string
- $template = (string) $template;
-
// Get extension for the template
$ext = $this->getRawTemplateExtension();
$this->getBasePath(),
$this->getLanguageInstance()->getLanguageCode(),
$this->getTemplateType(),
- $template,
+ (string) $template,
$ext
);
private function finalizeVariableCompilation () {
// Get the content
$content = $this->getRawTemplateData();
+ //* DEBUG: */ echo __METHOD__.": content before=".strlen($content)." (".md5($content).")<br />\n";
// Walk through all variables
foreach ($this->varStack['general'] as $currEntry) {
+ //* DEBUG: */ echo __METHOD__.": name=".$currEntry['name'].", value=<pre>".htmlentities($currEntry['value'])."</pre>\n";
// Replace all [$var] or {?$var?} with the content
- //* DEBUG: */ echo "name=".$currEntry['name'].", value=<pre>".htmlentities($currEntry['value'])."</pre>\n";
+ // Old behaviour, will become obsolete!
$content = str_replace("\$content[".$currEntry['name']."]", $currEntry['value'], $content);
+
+ // Yet another old way
$content = str_replace("[".$currEntry['name']."]", $currEntry['value'], $content);
+
+ // The new behaviour
$content = str_replace("{?".$currEntry['name']."?}", $currEntry['value'], $content);
} // END - for
+ //* DEBUG: */ echo __METHOD__.": content after=".strlen($content)." (".md5($content).")<br />\n";
+
// Set the content back
$this->setRawTemplateData($content);
}
- /**
- * Getter for raw template data
- *
- * @return $rawTemplateData The raw data from the template
- */
- public final function getRawTemplateData () {
- return $this->rawTemplateData;
- }
-
- /**
- * Getter for compiled templates
- */
- public final function getCompiledData () {
- return $this->compiledData;
- }
-
/**
* Load a specified web template into the engine
*
- * @param $template The web template we shall load which is
- * located in "html" by default
+ * @param $template The web template we shall load which is located in
+ * "html" by default
* @return void
*/
public function loadWebTemplate ($template) {
/**
* Load a specified email template into the engine
*
- * @param $template The email template we shall load which is
- * located in "emails" by default
+ * @param $template The email template we shall load which is located in
+ * "emails" by default
* @return void
*/
public function loadEmailTemplate ($template) {
$eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight);
} // END - while
- // Prepare PHP code for eval() command
+ // Get length for check if PHP code was found
$evalLength = strlen($eval);
+
+ // Prepare PHP code for eval() command
$eval = str_replace(
"<%php", "\";",
str_replace(
)
);
- // Did something change?
+ // Was PHP code found in template?
if (strlen($eval) != $evalLength) {
// Run the constructed command. This will "compile" all variables in
@eval($eval);
+ //* DEBUG: */ print("<pre>".htmlentities($eval)."</pre>");
} // END - if
// Goes something wrong?
$this->debugOutput(sprintf("Failed eval() code: <pre>%s</pre>", $this->markupCode($eval, true)), true);
// Output backtrace here
- $this->debugBacktrace();
+ $this->debugBackTrace();
} // END - if
// Set raw template data
$this->setRawTemplateData($result);
$cnt++;
- }
+ } // END - while
+
+ // Final variable assignment
+ $this->finalizeVariableCompilation();
// Set the new content
- $this->setCompiledData($result);
+ $this->setCompiledData($this->getRawTemplateData());
}
/**
* @throws InvalidArrayCountException If an unexpected array
* count has been found
*/
- public final function compileTemplate () {
+ public function compileTemplate () {
// We will only work with template type "code" from configuration
if ($this->getTemplateType() != $this->getConfigInstance()->readConfig('code_template_type')) {
// Abort here
}
/**
- * Output the compiled page to the outside world. In case of web templates
- * this would be vaild (X)HTML code. And in case of email templates this
- * would store a prepared email body inside the template engine.
+ * A old deprecated method
*
* @return void
+ * @deprecated
+ * @see BaseTemplateEngine::transferToResponse
*/
public function output () {
// Check which type of template we have
public final function getVariableGroups () {
return $this->varGroups;
}
+
+ /**
+ * Renames a variable in code and in stack
+ *
+ * @param $oldName Old name of variable
+ * @param $newName New name of variable
+ * @return void
+ */
+ public function renameVariable ($oldName, $newName) {
+ //* DEBUG: */ echo __METHOD__.": oldName={$oldName}, newName={$newName}<br />\n";
+ // Get raw template code
+ $rawData = $this->getRawTemplateData();
+
+ // Replace it
+ $rawData = str_replace($oldName, $newName, $rawData);
+
+ // Set the code back
+ $this->setRawTemplateData($rawData);
+ }
}
// [EOF]
-<!-- A compileable template for emergency messages //-->
-
{?header:title="Problem in application framework detected!"?}
-{?navigation?}
+<div id="emergency_exit message_box">
+ $content[message]
+</div>
- <div id="emergency_exit message_box">
- $content[message]
+<div id="emergency_exit backtrace_box">
+ <div id="backtrace_header">
+ File inclusion backtrace:
</div>
-
- <div id="emergency_exit backtrace_box">
- <div id="backtrace_header">
- File inclusion backtrace:
- </div>
- <div id="backtrace_content">
- $content[backtrace]
- </div>
+ <div id="backtrace_content">
+ $content[backtrace]
</div>
+</div>
- <div id="stats_box">
- <div id="stats_header">
- Statistics
- </div>
- <div id="stats_objects">
- Total objects: $content[total_objects]
- </div>
- <div id="stats_includes">
- Loaded class files: $content[total_includes]
- <span class="hint">(Including exception and interfaces.)</span>
- </div>
+<div id="stats_box">
+ <div id="stats_header">
+ Statistics
+ </div>
+ <div id="stats_objects">
+ Total objects: $content[total_objects]
+ </div>
+ <div id="stats_includes">
+ Loaded class files: $content[total_includes]
+ <span class="hint">(Including exception and interfaces.)</span>
</div>
+</div>
{?footer_msg:footer_msg="Please contact the support and supply the full above message, if you think you are not qualified to fix this problem."?}