+function loadTemplate ($template, $return = false, $content = array()) {
+ // @TODO Remove this sanity-check if all is fine
+ if (!is_bool($return)) debug_report_bug('return is not bool (' . gettype($return) . ')');
+
+ // @TODO Try to rewrite all $DATA to $content
+ global $DATA;
+
+ // Do we have cache?
+ if (isTemplateCached($template)) {
+ // Evaluate the cache
+ eval(readTemplateCache($template));
+ } elseif (!isset($GLOBALS['template_eval'][$template])) {
+ // Add more variables which you want to use in your template files
+ $username = getUsername();
+
+ // Make all template names lowercase
+ $template = strtolower($template);
+
+ // Init some data
+ $ret = '';
+ if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = '0';
+
+ // Base directory
+ $basePath = sprintf("%stemplates/%s/html/", getConfig('PATH'), getLanguage());
+ $extraPath = detectExtraTemplatePath($template);;
+
+ ////////////////////////
+ // Generate file name //
+ ////////////////////////
+ $FQFN = $basePath . $extraPath . $template . '.tpl';
+
+ // Does the special template exists?
+ if (!isFileReadable($FQFN)) {
+ // Reset to default template
+ $FQFN = $basePath . $template . '.tpl';
+ } // END - if
+
+ // Now does the final template exists?
+ if (isFileReadable($FQFN)) {
+ // Count the template load
+ incrementConfigEntry('num_templates');
+
+ // The local file does exists so we load it. :)
+ $GLOBALS['tpl_content'] = readFromFile($FQFN);
+
+ // Do we have to compile the code?
+ $ret = '';
+ if ((strpos($GLOBALS['tpl_content'], '$') !== false) || (strpos($GLOBALS['tpl_content'], '{--') !== false) || (strpos($GLOBALS['tpl_content'], '{!') !== false) || (strpos($GLOBALS['tpl_content'], '{?') !== false)) {
+ // Normal HTML output?
+ if (getOutputMode() == '0') {
+ // Add surrounding HTML comments to help finding bugs faster
+ $ret = '<!-- Template ' . $template . " - Start -->\n" . $GLOBALS['tpl_content'] . '<!-- Template ' . $template . " - End -->\n";
+
+ // Prepare eval() command
+ $eval = '$ret = "' . compileCode(escapeQuotes($ret)) . '";';
+ } elseif (substr($template, 0, 3) == 'js_') {
+ // JavaScripts don't like entities and timings
+ $eval = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['tpl_content'])) . '");';
+ } else {
+ // Prepare eval() command, other output doesn't like entities, maybe
+ $eval = '$ret = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'])) . '");';
+ }
+ } else {
+ // Add surrounding HTML comments to help finding bugs faster
+ $ret = '<!-- Template ' . $template . " - Start -->\n" . $GLOBALS['tpl_content'] . '<!-- Template ' . $template . " - End -->\n";
+ $eval = '$ret = "' . escapeQuotes($ret) . '";';
+ } // END - if
+
+ // Cache the eval() command here
+ $GLOBALS['template_eval'][$template] = $eval;
+
+ // Eval the code
+ eval($GLOBALS['template_eval'][$template]);
+ } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
+ // Only admins shall see this warning or when installation mode is active
+ $ret = '<br /><span class="guest_failed">{--TEMPLATE_404--}</span><br />
+(' . $template . ')<br />
+<br />
+{--TEMPLATE_CONTENT--}
+<pre>' . print_r($content, true) . '</pre>
+{--TEMPLATE_DATA--}
+<pre>' . print_r($DATA, true) . '</pre>
+<br /><br />';
+ } else {
+ // No file!
+ $GLOBALS['template_eval'][$template] = '404';
+ }
+ } else {
+ // Eval the code
+ eval($GLOBALS['template_eval'][$template]);
+ }
+
+ // Do we have some content to output or return?
+ if (!empty($ret)) {
+ // Not empty so let's put it out! ;)
+ if ($return === true) {
+ // Return the HTML code
+ return $ret;
+ } else {
+ // Output directly
+ outputHtml($ret);
+ }
+ } elseif (isDebugModeEnabled()) {
+ // Warning, empty output!
+ return 'E:' . $template . ',content=<pre>' . print_r($content, true) . '</pre>';
+ }
+}
+
+// Detects the extra template path from given template name
+function detectExtraTemplatePath ($template) {
+ // Default is empty
+ $extraPath = '';
+
+ // Do we have cache?
+ if (!isset($GLOBALS['extra_path'][$template])) {
+ // Check for admin/guest/member/etc. templates
+ if (substr($template, 0, 6) == 'admin_') {
+ // Admin template found
+ $extraPath = 'admin/';
+ } elseif (substr($template, 0, 6) == 'guest_') {
+ // Guest template found
+ $extraPath = 'guest/';
+ } elseif (substr($template, 0, 7) == 'member_') {
+ // Member template found
+ $extraPath = 'member/';
+ } elseif (substr($template, 0, 7) == 'select_') {
+ // Selection template found
+ $extraPath = 'select/';
+ } elseif (substr($template, 0, 8) == 'install_') {
+ // Installation template found
+ $extraPath = 'install/';
+ } elseif (substr($template, 0, 4) == 'ext_') {
+ // Extension template found
+ $extraPath = 'ext/';
+ } elseif (substr($template, 0, 3) == 'la_') {
+ // 'Logical-area' template found
+ $extraPath = 'la/';
+ } elseif (substr($template, 0, 3) == 'js_') {
+ // JavaScript template found
+ $extraPath = 'js/';
+ } elseif (substr($template, 0, 5) == 'menu_') {
+ // Menu template found
+ $extraPath = 'menu/';
+ } else {
+ // Test for extension
+ $test = substr($template, 0, strpos($template, '_'));
+
+ // Probe for valid extension name
+ if (isExtensionNameValid($test)) {
+ // Set extra path to extension's name
+ $extraPath = $test . '/';
+ } // END - if
+ }
+
+ // Store it in cache
+ $GLOBALS['extra_path'][$template] = $extraPath;
+ } // END - if
+
+ // Return result
+ return $GLOBALS['extra_path'][$template];
+}
+
+// Loads an email template and compiles it
+function loadEmailTemplate ($template, $content = array(), $UID = '0') {
+ global $DATA;