X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ftemplate-functions.php;h=caa72894e601397b79899555565c2e7778104e3e;hb=3eb06053f9ae59084815875654465a2fb25829a6;hp=9c7192ab1a5d40132d25ab1f45c122e2a11e93cf;hpb=aae9c624b2577e2ce5995d8a2d260b7b4d16d0ee;p=mailer.git diff --git a/inc/template-functions.php b/inc/template-functions.php index 9c7192ab1a..caa72894e6 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -10,13 +10,8 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Template-Funktionen * * -------------------------------------------------------------------- * - * $Revision:: $ * - * $Date:: $ * - * $Tag:: 0.2.1-FINAL $ * - * $Author:: $ * - * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -41,12 +36,12 @@ if (!defined('__SECURITY')) { } // END - if // Wrapper until we merged to the EL branch -function preCompileCode ($code, $template = '', $compiled = false, $full = true, $overwrite = false) { - return compileCode($code, false, true, $full); +function preCompileCode ($code, $full = TRUE) { + return compileCode($code, $full); } // Setter for 'is_template_html' -function enableTemplateHtml ($enable = true) { +function enableTemplateHtml ($enable = TRUE) { $GLOBALS['is_template_html'] = (bool) $enable; } @@ -56,7 +51,7 @@ function isTemplateHtml () { // Is the output_mode other than 0 (HTML), then no comments are enabled if (!isHtmlOutputMode()) { // No HTML - return false; + return FALSE; } else { // Maybe HTML? return $GLOBALS['is_template_html']; @@ -86,14 +81,14 @@ function initTemplateColorSwitch ($template) { // "Getter" for color switch code function getColorSwitchCode ($template) { // Prepare the code - $code = "{DQUOTE} . doTemplateColorSwitch('" . $template . "', false, false) . {DQUOTE}"; + $code = "{DQUOTE} . doTemplateColorSwitch('" . $template . "', FALSE, FALSE) . {DQUOTE}"; // And return it return $code; } // Output HTML code directly or 'render' it. You addionally switch the new-line character off -function outputHtml ($htmlCode, $newLine = true) { +function outputHtml ($htmlCode = NULL, $newLine = TRUE) { // Init output if (!isset($GLOBALS['__output'])) { $GLOBALS['__output'] = ''; @@ -101,7 +96,7 @@ function outputHtml ($htmlCode, $newLine = true) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getOutputMode()=' . getOutputMode() . ',htmlCode(length)=' . strlen($htmlCode) . ',output(length)=' . strlen($GLOBALS['__output'])); // Is there HTML-Code here? - if (!empty($htmlCode)) { + if ((!is_null($htmlCode)) && (!empty($htmlCode))) { // Yes, so we handle it as you have configured switch (getOutputMode()) { case 'render': @@ -111,16 +106,16 @@ function outputHtml ($htmlCode, $newLine = true) { outputRawCode($htmlCode); // That's why you don't need any \n at the end of your HTML code... :-) - if ($newLine === true) { - outputRawCode(chr(10)); + if ($newLine === TRUE) { + outputRawCode(PHP_EOL); } // END - if } else { // Render mode for old or lame servers... $GLOBALS['__output'] .= $htmlCode; // That's why you don't need any \n at the end of your HTML code... :-) - if ($newLine === true) { - $GLOBALS['__output'] .= chr(10); + if ($newLine === TRUE) { + $GLOBALS['__output'] .= PHP_EOL; } // END - if } break; @@ -134,8 +129,8 @@ function outputHtml ($htmlCode, $newLine = true) { // The same as above... ^ outputRawCode($htmlCode); - if ($newLine === true) { - outputRawCode(chr(10)); + if ($newLine === TRUE) { + outputRawCode(PHP_EOL); } // END - if break; @@ -144,7 +139,7 @@ function outputHtml ($htmlCode, $newLine = true) { reportBug(__FUNCTION__, __LINE__, '{--FATAL_ERROR--}: {--NO_RENDER_DIRECT--}'); break; } // END - switch - } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['http_header'])) || (count($GLOBALS['http_header']) == 0)) && (!isRawOutputMode())) { + } elseif ((getPhpCaching() == 'on') && (!isFilledArray($GLOBALS['http_header'])) && (!isRawOutputMode())) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getPhpCaching()=' . getPhpCaching() . ',isset(http_header)=' . intval(isset($GLOBALS['http_header'])) . ',getScriptOutputMode()=' . getScriptOutputMode() . ''); // Output cached HTML code $GLOBALS['__output'] = ob_get_contents(); @@ -180,12 +175,24 @@ function outputHtml ($htmlCode, $newLine = true) { // Compiles the final output function compileFinalOutput () { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '__output(length)=' . strlen($GLOBALS['__output']) . ',getScriptOutputMode()=' . getScriptOutputMode() . ' - ENTERED!'); + // Is this function called? + if (isset($GLOBALS[__FUNCTION__])) { + // Abort here + reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' causes problems with sent headers.'); + } // END - if + + // Mark this function as called + $GLOBALS[__FUNCTION__] = TRUE; + // Add page header and footer addPageHeaderFooter(); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '__output(length)=' . strlen($GLOBALS['__output']) . ' - After addPageHeaderFooter() call.'); - // Do the final compilation - $GLOBALS['__output'] = compileUriCode(doFinalCompilation($GLOBALS['__output'])); + // Do the final (general) compilation + $GLOBALS['__output'] = doFinalCompilation($GLOBALS['__output']); + + // Compile any other things out + $GLOBALS['__output'] = compileUriCode($GLOBALS['__output']); // Extension 'rewrite' installed? if ((isExtensionActive('rewrite')) && (!isCssOutputMode())) { @@ -218,50 +225,51 @@ function compileFinalOutput () { } // Main compilation loop -function doFinalCompilation ($code, $insertComments = true, $enableCodes = true) { +function doFinalCompilation ($code, $insertComments = TRUE, $enableCodes = TRUE) { // Insert comments? (Only valid with HTML templates, of course) enableTemplateHtml($insertComments); // Init counter - $count = 0; + $totalCompilations = 0; // Compile all out - while (((isInString('{--', $code)) || (isInString('{DQUOTE}', $code)) || (isInString('{?', $code)) || (isInString('{%', $code) !== false)) && ($count < 7)) { + while (((isInString('{--', $code)) || (isInString('{DQUOTE}', $code)) || (isInString('{?', $code)) || (isInString('{%', $code) !== FALSE)) && ($totalCompilations < 7)) { // Init common variables $content = array(); $newContent = ''; // Compile it - //* DEBUG: */ debugOutput('
'.linenumberCode($code).'
'.linenumberCode($eval).'
'.lineNumberCode($code).'
'.lineNumberCode($eval).'
'.linenumberCode($newContent).'
'.lineNumberCode($newContent).'
'.encodeEntities($newContent).'
' . linenumberCode($eval) . '
' . lineNumberCode($eval) . '
' . print_r($content, true) . '
' . print_r($content, TRUE) . '
'.htmlentities($GLOBALS['template_eval']['email'][$template]).'
'.print_r($content, TRUE).'
'; + print '[' . $file . ':' . $line . ':] ' . __FUNCTION__ . '() has already died! Message:' . $message . 'Backtrace:'; debug_print_backtrace(); die(''); } // END - if @@ -1278,7 +1288,7 @@ function reportBug ($F, $L, $message = '', $sendEmail = true) { setHttpStatus('500 Internal Server Error'); // Mark this function as called - $GLOBALS[__FUNCTION__] = true; + $GLOBALS[__FUNCTION__] = TRUE; // Init message $debug = ''; @@ -1291,7 +1301,7 @@ function reportBug ($F, $L, $message = '', $sendEmail = true) { ); // @TODO Add a little more infos here - logDebugMessage($F, $L, strip_tags($message)); + logDebugMessage($file, $line, strip_tags($message)); } // END - if // Add output @@ -1302,7 +1312,7 @@ function reportBug ($F, $L, $message = '', $sendEmail = true) { $debug .= 'Thank you for finding bugs.'; // Send an email? (e.g. not wanted for evaluation errors) - if (($sendEmail === true) && (!isInstallationPhase())) { + if (($sendEmail === TRUE) && (!isInstaller()) && (isAdminRegistered())) { // Prepare content $content = array( 'message' => trim($message), @@ -1313,10 +1323,28 @@ function reportBug ($F, $L, $message = '', $sendEmail = true) { sendAdminNotification('{--REPORT_BUG_SUBJECT--}', 'admin_report_bug', $content); } // END - if - // Is there HTML/CSS/AJAX mode? - if ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode())) { + // Is there HTML/CSS/AJAX mode while debug-mode is enabled? + if (((isDebugModeEnabled()) || (isInstaller())) && ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode()))) { // And abort here - app_exit($F, $L, $debug); + app_exit($file, $line, $debug); + } elseif (isAjaxOutputMode()) { + // Load include (again?) + loadIncludeOnce('inc/ajax-functions.php'); + + // Init AJAX + initAjax(); + + // Set HTTP status to 500 again + setHttpStatus('500 Internal Server Error'); + + // Is AJAX output mode, then output message as JSON + setAjaxReplyContent($debug); + + // Send it out to browser + sendAjaxContent(TRUE); + + // Include footer + loadPageFooter(); } else { // Raw/image output mode and all other modes doesn't work well with text ... die(); @@ -1324,7 +1352,7 @@ function reportBug ($F, $L, $message = '', $sendEmail = true) { } // Compile characters which are allowed in URLs -function compileUriCode ($code, $simple = true) { +function compileUriCode ($code, $simple = TRUE) { // Trim code $test = trim($code); @@ -1361,16 +1389,17 @@ function compileUriCode ($code, $simple = true) { ); // Compile constants - if ($simple === false) { + if ($simple === FALSE) { // Add more 'from' - array_push($charsCompile['from'], '{--', '--}'); + array_unshift($charsCompile['from'], '{--', '--}'); // Add more 'to' - array_push($charsCompile['to'], '".', '."'); + array_unshift($charsCompile['to'], '".', '."'); } // END - if // Compile QUOT and other non-HTML codes $code = str_replace($charsCompile['from'], $charsCompile['to'], $code); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code=' . $code); // Return compiled code return $code; @@ -1392,7 +1421,7 @@ function handleCodeMessage () { $message = getMessageFromErrorCode(getRequestElement('code')); // Load message template - loadTemplate('message', false, $message); + loadTemplate('message', FALSE, $message); } // END - if } @@ -1467,17 +1496,17 @@ function generateExtensionInactiveNotInstalledMessage ($ext_name) { // Is the extension not installed or just deactivated? switch (isExtensionInstalled($ext_name)) { - case true; // Deactivated! + case TRUE; // Deactivated! $message = generateExtensionInactiveMessage($ext_name); break; - case false; // Not installed! + case FALSE; // Not installed! $message = generateExtensionNotInstalledMessage($ext_name); break; default: // Should not happen! - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid state of extension %s detected.", $ext_name)); - $message = sprintf("Invalid state of extension %s detected.", $ext_name); + logDebugMessage(__FUNCTION__, __LINE__, sprintf('Invalid state of extension %s detected.', $ext_name)); + $message = sprintf('Invalid state of extension %s detected.', $ext_name); break; } // END - switch @@ -1486,13 +1515,13 @@ function generateExtensionInactiveNotInstalledMessage ($ext_name) { } // Print code with line numbers -function linenumberCode ($code) { +function lineNumberCode ($code) { // By default copy the code $codeE = $code; if (!is_array($code)) { // We need an array, so try it with the new-line character - $codeE = explode(chr(10), $code); + $codeE = explode(PHP_EOL, $code); } // END - if $count_lines = count($codeE); @@ -1520,7 +1549,7 @@ function determinePageTitle () { $pageTitle = ''; // Config and database connection valid? - if ((isConfigLocalLoaded()) && (isConfigurationLoaded()) && (SQL_IS_LINK_UP()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) { + if ((isConfigLocalLoaded()) && (isConfigurationLoaded()) && (isSqlLinkUp()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) { // Title decoration enabled? if ((isTitleDecorationEnabled()) && (getTitleLeft() != '')) { $pageTitle .= '{%config,trim=title_left%} '; @@ -1540,17 +1569,8 @@ function determinePageTitle () { $pageTitle .= ' {%config,trim=title_middle%} {DQUOTE} . getModuleTitle(getModule()) . {DQUOTE}'; } // END - if - // Add title from what file - $menuMode = ''; - if (getModule() == 'login') { - $menuMode = 'member'; - } elseif (getModule() == 'index') { - $menuMode = 'guest'; - } elseif (getModule() == 'admin') { - $menuMode = 'admin'; - } elseif (getModule() == 'sponsor') { - $menuMode = 'sponsor'; - } + // Get menu mode from module + $menuMode = getMenuModeFromModule(); // Add middle part (always in admin area!) if ((!empty($menuMode)) && ((isWhatTitleEnabled()) || ($menuMode == 'admin'))) { @@ -1603,10 +1623,13 @@ function isTemplateCached ($prefix, $template) { // Flushes non-flushed template cache to disk function flushTemplateCache ($prefix, $template, $eval) { // Is this cache flushed? - if ((isDebuggingTemplateCache() === false) && (isTemplateCached($prefix, $template) === false) && ($eval != '404')) { + if ((isDebugTemplateCacheEnabled() === FALSE) && (isTemplateCached($prefix, $template) === FALSE) && ($eval != '404')) { // Generate FQFN $FQFN = generateCacheFqfn($prefix, $template); + // Compile code another round for better performance and preserve $ signs + $eval = str_replace(array(chr(92), '{DOLLAR}', '{BACK}', '{CONTENT}'), array('', '$', chr(92), '$content'), compileCode(str_replace(array('$content', chr(92)), array('{CONTENT}', '{BACK}'), $eval))); + // Is this a XML template? if ($prefix == 'xml') { // Compact only XML templates as emails needs new-line characters and HTML may contain required "comments" @@ -1614,16 +1637,16 @@ function flushTemplateCache ($prefix, $template, $eval) { } // END - if // And flush it - writeToFile($FQFN, $eval, true); + writeToFile($FQFN, '', TRUE); } // END - if } // Reads a template cache -function readTemplateCache ($prefix, $template) { +function readTemplateCache ($prefix, $template, $content) { // Check it again - if ((isDebuggingTemplateCache()) || (!isTemplateCached($prefix, $template))) { + if ((isDebugTemplateCacheEnabled()) || (!isTemplateCached($prefix, $template))) { // This should not happen - reportBug('Wether debugging of template cache is enabled or template ' . $template . ' is not cached while expected.'); + reportBug(__FUNCTION__, __LINE__, 'Wether debugging of template cache is enabled or template ' . $template . ' is not cached while expected.'); } // END - if // Is it cached? @@ -1631,18 +1654,30 @@ function readTemplateCache ($prefix, $template) { // Generate FQFN $FQFN = generateCacheFqfn($prefix, $template); - // And read from it - $GLOBALS['template_eval'][$prefix][$template] = readFromFile($FQFN); + /* + * And read from it. + * + * WARNING: Do not replace this include() call with loadInclude() as it + * would hide local variables away which is here required to make this + * work. + */ + include($FQFN); + + // Is the template cache valid? + if (!isset($templateContent)) { + // Please clear your cache! + reportBug(__FUNCTION__, __LINE__, 'Template ' . $template . ' uses old structure. Please delete all template cache files and reload.'); + } // END - if } // END - if // And return it - return $GLOBALS['template_eval'][$prefix][$template]; + return $templateContent; } // Escapes quotes (default is only double-quotes) -function escapeQuotes ($str, $single = false) { +function escapeQuotes ($str, $single = FALSE) { // Should we escape all? - if ($single === true) { + if ($single === TRUE) { // Escape all (including null) $str = addslashes($str); } else { @@ -1650,7 +1685,7 @@ function escapeQuotes ($str, $single = false) { $str = str_replace(array("\\'", '"', "\\\\"), array(chr(39), "\\\"", chr(92)), $str); } - // Return the escaped string + // Return the escape'd string return $str; } @@ -1678,7 +1713,7 @@ function sendModeMails ($mod, $modes) { $hash = encodeHashForCookie(getUserData('password')); // Does the hash match or should we change it? - if (($hash == getSession('u_hash')) || (postRequestElement('pass1') == postRequestElement('pass2'))) { + if (($hash == getSession('u_hash')) || (postRequestElement('password1') == postRequestElement('password2'))) { // Load the data $content = getUserDataArray(); @@ -1693,16 +1728,16 @@ function sendModeMails ($mod, $modes) { switch ($mode) { case 'normal': break; // Do not add any special lines case 'email': // Email was changed! - $content['message'] = '{--MEMBER_CHANGED_EMAIL--}' . ': ' . postRequestElement('old_email') . chr(10); + $content['message'] = '{--MEMBER_CHANGED_EMAIL--}' . ': ' . postRequestElement('old_email') . PHP_EOL; break; case 'password': // Password was changed - $content['message'] = '{--MEMBER_CHANGED_PASS--}' . chr(10); + $content['message'] = '{--MEMBER_CHANGED_PASSWORD--}' . PHP_EOL; break; default: - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode)); - $content['message'] = '{--MEMBER_UNKNOWN_MODE--}' . ': ' . $mode . "\n\n"; + logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown mode %s detected.', $mode)); + $content['message'] = '{%message,MEMBER_UNKNOWN_MODE=' . $mode . '%}' . PHP_EOL . PHP_EOL; break; } // END - switch } // END - foreach @@ -1721,23 +1756,23 @@ function sendModeMails ($mod, $modes) { if (isAdminNotificationEnabled()) { // The admin needs to be notified about a profile change $message_admin = 'admin_mydata_notify'; - $sub_adm = '{--ADMIN_CHANGED_DATA--}'; + $subjectAdmin = '{--ADMIN_CHANGED_DATA_SUBJECT--}'; } else { // No mail to admin $message_admin = ''; - $sub_adm = ''; + $subjectAdmin = ''; } // Set subject lines - $sub_mem = '{--MEMBER_CHANGED_DATA--}'; + $subjectMember = '{--MEMBER_CHANGED_DATA--}'; // Output success message $content['message'] = '{--MEMBER_MYDATA_MAIL_SENT--}'; break; default: // Unsupported module! - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod)); - $content['message'] = '{--UNKNOWN_MODULE--}'; + logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unsupported module %s detected.', $mod)); + $content['message'] = '{%message,UNKNOWN_MODULE=' . $mod . '%}'; break; } // END - switch } else { @@ -1750,15 +1785,15 @@ function sendModeMails ($mod, $modes) { } // Send email to user if required - if ((!empty($sub_mem)) && (!empty($message)) && (!empty($content['userid']))) { + if ((!empty($subjectMember)) && (!empty($message)) && (!empty($content['userid']))) { // Send member mail - sendEmail($content['userid'], $sub_mem, $message); + sendEmail($content['userid'], $subjectMember, $message); } // END - if // Send only if no other error has occured - if ((!empty($sub_adm)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) { + if ((!empty($subjectAdmin)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) { // Send admin mail - sendAdminNotification($sub_adm, $message_admin, $content, getMemberId()); + sendAdminNotification($subjectAdmin, $message_admin, $content, getMemberId()); } elseif (isAdminNotificationEnabled()) { // Cannot send mails to admin! $content['message'] = '{--CANNOT_SEND_ADMIN_MAILS--}'; @@ -1772,12 +1807,15 @@ function sendModeMails ($mod, $modes) { } // Generates a 'selection box' from given array -function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = false, $useDefaultAsArray = false) { +function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) { + // options must be an array + assert(is_array($options)); + // Default is empty $addKey = ''; // Use default value as array key? - if ($useDefaultAsArray === true) { + if ($useDefaultAsArray === TRUE) { // Then set it $addKey = '[' . convertNullToZero($default) . ']'; } // END - if @@ -1787,7 +1825,7 @@ function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionCont {--PLEASE_SELECT--}'; // Allow none? - if ($allowNone === true) { + if ($allowNone === TRUE) { // Then add it $OUT .= '{--SELECT_NONE--}'; } // END - if @@ -1815,10 +1853,10 @@ function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionCont // Is a template name given? if (empty($templateName)) { // ... $name template - $OUT .= loadTemplate('select_' . $name . $extraName . '_option', true, $option); + $OUT .= loadTemplate('select_' . $name . $extraName . '_option', TRUE, $option); } else { // ... $templateName template - $OUT .= loadTemplate('select_' . $templateName . $extraName . '_option', true, $option); + $OUT .= loadTemplate('select_' . $templateName . $extraName . '_option', TRUE, $option); } } else { // ... direct HTML code @@ -1837,10 +1875,10 @@ function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionCont // Load template and return it if (empty($templateName)) { // Use name from $name + $extraName - return loadTemplate('select_' . $name . $extraName . '_box', true, $content); + return loadTemplate('select_' . $name . $extraName . '_box', TRUE, $content); } else { // Use name from $templateName + $extraName - return loadTemplate('select_' . $templateName . $extraName . '_box', true, $content); + return loadTemplate('select_' . $templateName . $extraName . '_box', TRUE, $content); } } @@ -1885,7 +1923,7 @@ function addPageHeaderFooter () { // Generates meta description for current module and 'what' value function generateMetaDescriptionCode () { - // Only include from guest area and if sql_patches has correct version + // Only include from guest area and if ext-sql_patches has correct version if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) { // Output it directly $GLOBALS['__page_header'] .= ''; @@ -1901,10 +1939,12 @@ function generateCacheFqfn ($prefix, $template) { if (!isset($GLOBALS['template_cache_fqfn'][$prefix][$template])) { // Generate the FQFN $GLOBALS['template_cache_fqfn'][$prefix][$template] = sprintf( - "%s_compiled/%s/%s.tpl.cache", + '%s%s_compiled/%s/%s%s', + getPath(), getCachePath(), $prefix, - $template + $template, + getCacheExtension() ); } // END - if @@ -1930,7 +1970,7 @@ function fixNullEmptyToDashes ($str, $num) { // Translates the "pool type" into human-readable function translatePoolType ($type) { // Return "translation" - return sprintf("{--POOL_TYPE_%s--}", strtoupper($type)); + return sprintf('{--POOL_TYPE_%s--}', strtoupper($type)); } // "Translates" given time unit @@ -1952,9 +1992,27 @@ function translateTimeUnit ($unit) { } // Displays given message in admin_settings_saved template -function displayMessage ($message, $return = false) { +function displayMessage ($message) { + // Call inner function + outputHtml(returnMessage($message)); +} + +// Returns given message in admin_settings_saved template +function returnMessage ($message) { + // Load the template + return loadTemplate('admin_settings_saved', TRUE, $message); +} + +// Displays given error message in admin_settings_unsaved template +function displayErrorMessage ($message) { + // Load the template + outputHtml(returnErrorMessage($message)); +} + +// Displays given error message in admin_settings_unsaved template +function returnErrorMessage ($message) { // Load the template - return loadTemplate('admin_settings_saved', $return, $message); + return loadTemplate('admin_settings_unsaved', TRUE, $message); } // Generates a selection box for (maybe) given gender @@ -2040,24 +2098,89 @@ function addJavaScriptMenuContent ($menuMode, $mainAction, $action, $what) { return $OUT; } +// Tries to anonymize some sensitive data (e.g. IP address, user agent, referrer, etc.) +function anonymizeSensitiveData ($data) { + // Trim it + $data = trim($data); + + // Is it empty? + if (empty($data)) { + // Then add three dashes + $data = '---'; + } elseif (isUrlValid($data)) { + // Is a referrer, so is it black-listed? + if (isAdmin()) { + // Is admin, has always priority + $data = '[{--ADMIN_TEST_URL--}]'; + } elseif ((isExtensionActive('blacklist')) && (isUrlBlacklisted($data))) { + // Yes, so replace it with text + $data = '{--URL_IS_BLACKLISTED--}'; + } else { + // A member is viewing this referral URL + $data = '[{--MEMBER_TEST_URL--}]'; + } + } elseif (isIp4AddressValid($data)) { + // Is an IPv4 address + $ipArray = explode('.', $data); + + // Only display first 2 octets + $data = $ipArray[0] . '.' . $ipArray[1] . '.?.?'; + } else { + // Generic data + $data = '{--DATA_IS_HIDDEN--}'; + } + + // Return it (hopefully) anonymized + return $data; +} + +/** + * Removes all comments, tabs and new-line characters to compact the content + * + * @param $uncompactedContent The uncompacted content + * @return $compactedContent The compacted content + */ +function compactContent ($uncompactedContent) { + // First, remove all tab/new-line/revert characters + $compactedContent = str_replace(chr(9), '', str_replace(PHP_EOL, '', str_replace(chr(13), '', $uncompactedContent))); + + // Make a space after > + $compactedContent = str_replace(array('>', ' '), array('> ', ' '), $compactedContent); + + // Then regex all comments like away + preg_match_all('//', $compactedContent, $matches); + + // Do we have entries? + if (isset($matches[0][0])) { + // Remove all + foreach ($matches[0] as $match) { + // Remove the match + $compactedContent = str_replace($match, '', $compactedContent); + } // END - foreach + } // END - if + + // Return compacted content + return $compactedContent; +} + //----------------------------------------------------------------------------- // Template helper functions for EL code //----------------------------------------------------------------------------- // Color-switch helper function -function doTemplateColorSwitch ($templateName, $clear = false, $return = true) { +function doTemplateColorSwitch ($templateName, $clear = FALSE, $return = TRUE) { // Is it there? if (!isset($GLOBALS['color_switch'][$templateName])) { // Initialize it initTemplateColorSwitch($templateName); - } elseif ($clear === false) { + } elseif ($clear === FALSE) { // Switch color if called from loadTemplate() //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SWITCH:' . $templateName); $GLOBALS['color_switch'][$templateName] = 3 - $GLOBALS['color_switch'][$templateName]; } // Return CSS class name - if ($return === true) { + if ($return === TRUE) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'RETURN:' . $templateName . '=' . $GLOBALS['color_switch'][$templateName]); return 'switch_sw' . $GLOBALS['color_switch'][$templateName]; } // END - if @@ -2074,7 +2197,7 @@ function doTemplateExtensionRegistrationLink ($templateName, $clear, $ext_name) $OUT = '---'; } elseif (isExtensionProductive($ext_name)) { // Productive code - $OUT = '{--ADMIN_REGISTER_EXTENSION--}'; + $OUT = '{--ADMIN_TASK_REGISTER_EXTENSION--}'; } // Return code @@ -2084,13 +2207,13 @@ function doTemplateExtensionRegistrationLink ($templateName, $clear, $ext_name) // Helper function to create bonus mail admin links function doTemplateAdminBonusMailLinks ($templateName, $clear, $bonusId) { // Call the inner function - return generateAdminMailLinks('bid', $bonusId); + return generateAdminMailLinks('bonus', $bonusId); } // Helper function to create member mail admin links function doTemplateAdminMemberMailLinks ($templateName, $clear, $mailId) { // Call the inner function - return generateAdminMailLinks('mid', $mailId); + return generateAdminMailLinks('normal', $mailId); } // Helper function to create a selection box for YES/NO configuration entries @@ -2132,6 +2255,25 @@ function doTemplateNoYesSelectionBox ($templateName, $clear, $formField) { return $OUT; } +// Helper function to add extra content for guest area (module=index and others) +function doTemplateGuestFooterExtras ($templateName, $clear) { + // Init filter data + $filterData = array( + // Name of used template + 'template' => $templateName, + // Target array for gathered data + '__data' => array(), + // Where the HTML output will go + '__output' => '', + ); + + // Run the filter chain + $filterData = runFilterChain('guest_footer_extras', $filterData); + + // Return output + return $filterData['__output']; +} + // Helper function to add extra content for member area (module=login) function doTemplateMemberFooterExtras ($templateName, $clear) { // Is a member logged in? @@ -2201,7 +2343,7 @@ function doTemplateGetTermsConditionsLink ($templateName, $clear) { } // Template helper function to create selection box for "locked points mode" -function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = false, $default = NULL) { +function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = FALSE, $default = NULL) { // Init array $lockedModes = array( 0 => array('mode' => 'LOCKED'), @@ -2216,7 +2358,7 @@ function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = false, } // Template helper function to create selection box for payment method -function doTemplatePointsPaymentMethodSelectionBox ($templateName, $clear = false, $default = NULL) { +function doTemplatePointsPaymentMethodSelectionBox ($templateName, $clear = FALSE, $default = NULL) { // Init array $paymentMethods = array( 0 => array('method' => 'DIRECT'), @@ -2230,69 +2372,159 @@ function doTemplatePointsPaymentMethodSelectionBox ($templateName, $clear = fals return $content; } -// Tries to anonymize some sensitive data (e.g. IP address, user agent, referrer, etc.) -function anonymizeSensitiveData ($data) { - // Trim it - $data = trim($data); +// Template helper function to create a deferrer code if URL is not empty +function doTemplateDereferrerUrl ($templateName, $clear = FALSE, $url = NULL) { + // Is the URL not NULL and not empty? + if ((!is_null($url)) && (!empty($url))) { + // Set HTML with EL code + $url = '{--ADMIN_TEST_URL--}'; + } // END - if - // Is it empty? - if (empty($data)) { - // Then add three dashes - $data = '---'; - } elseif (isUrlValid($data)) { - // Is a referrer, so is it black-listed? - if (isAdmin()) { - // Is admin, has always priority - $data = '[{--ADMIN_TEST_URL--}]'; - } elseif (isUrlBlacklisted($data)) { - // Yes, so replace it with text - $data = '{--URL_IS_BLACKLISTED--}'; - } else { - // A member is viewing this referral URL - $data = '[{--MEMBER_TEST_URL--}]'; - } - } elseif (isIp4AddressValid($data)) { - // Is an IPv4 address - $ipArray = explode('.', $data); + // Return URL (or content) or dashes if empty + return fixEmptyContentToDashes($url); +} - // Only display first 2 octets - $data = $ipArray[0] . '.' . $ipArray[1] . '.?.?'; +// Load another template and return its content +function doTemplateLoadTemplate ($templateName, $clear = FALSE, $theTemplate, $content = array()) { + // Load "the" template + return loadTemplate($theTemplate, TRUE, $content); +} + +// Output HTML code for favicon.ico, if found +function doTemplateMetaFavIcon ($templateName, $clear = FALSE) { + // Default is not found + $out = ''; + + // Check all common extensions + foreach (array('ico', 'gif', 'png') as $extension) { + // Is the file there? + if (isFileReadable(getPath() . 'favicon.' . $extension)) { + // Then use this and abort + $out = ''; + break; + } // END - if + } // END - while + + // Return code + return $out; +} + +// Helper function to display referral id or hide it depending on settings +function doTemplateDisplayReferralIdContent ($template, $clear = FALSE) { + // Ddisplay the refid or make it editable? + if (isDisplayRefidEnabled()) { + // Load "hide" form template + $out = loadTemplate('guest_register_refid_hide', TRUE); } else { - // Generic data - $data = '{--DATA_IS_HIDDEN--}'; + // Load template to enter it + $out = loadTemplate('guest_register_refid', TRUE); } - // Return it (hopefully) anonymized - return $data; + // Return code + return $out; } -/** - * Removes all commentd, tabs and new-line characters to compact the content - * - * @param $uncompactedContent The uncompacted content - * @return $compactedContent The compacted content - */ -function compactContent ($uncompactedContent) { - // First, remove all tab/new-line/revert characters - $compactedContent = str_replace(chr(9), '', str_replace(chr(10), '', str_replace(chr(13), '', $uncompactedContent))); +// "Getter" for template base path +function getTemplateBasePath ($part) { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$part])) { + // "Build" path + $GLOBALS[__FUNCTION__][$part] = sprintf('%stemplates/%s/%s', getPath(), getLanguage(), $part); + } // END - if - // Then regex all comments like away - preg_match_all('//', $compactedContent, $matches); + // Return cache + return $GLOBALS[__FUNCTION__][$part]; +} - // Do we have entries? - if (isset($matches[0][0])) { - // Remove all - foreach ($matches[0] as $match) { - // Remove the match - $compactedContent = str_replace($match, '', $compactedContent); - } // END - foreach +// Removes comments with @DEPRECATED +function removeDeprecatedComment ($output) { + // Explode it into pieces ... ;) + $lines = explode(chr(10), $output); + + // Walk through all + $return = ''; + foreach ($lines as $line) { + // Is there a @DEPRECATED? + if (isInString('@DEPRECATED', $line)) { + // Ignore this line + continue; + } // END - if + + // Add it + $return .= $line . chr(13); + } // END - foreach + + // Returned cleaned content + return $return; +} + +// Generates a selection box suitable for e.g. birthdays: day, month and year +function generateDayMonthYearSelectionBox ($day, $month, $year) { + // This depends on selected language + switch (getLanguage()) { + case 'de': // German date format + $content = addSelectionBox('da', $day) . addSelectionBox('mo', $month) . addSelectionBox('ye', $year); + break; + + default: // Default is the US date format... :) + $content = addSelectionBox('mo', $month) . addSelectionBox('da', $day) . addSelectionBox('ye', $year); + break; + } // END - switch + + // Return content + return $content; +} + +// Loads page header +function loadPageHeader () { + // Init header + $GLOBALS['__page_header'] = ''; + + // Is the header already sent? + if (($GLOBALS['__header_sent'] != 1) && ($GLOBALS['__header_sent'] != 2)) { + // Set default HTTP status to "200 OK" + setHttpStatus('200 OK'); + + // If not in CSS mode generate the header + if ((!isCssOutputMode()) && (!isAjaxOutputMode()) && (!isImageOutputMode())) { + // Prepare the header for HTML output + loadHtmlHeader(); + } // END - if + + // Closing HEAD tag + if ($GLOBALS['__header_sent'] == '0') { + $GLOBALS['__header_sent'] = 1; + } // END - if } // END - if - // Set the content again - // @TODO Is this needed for e.g. $GLOBALS['template_content'] ? $this->setRawTemplateData($compactedContent); + // Add BODY tag or not? + // @TODO Find a way to not use direct module comparison + if ((!isCssOutputMode()) && (!isRawOutputMode()) && ($GLOBALS['__header_sent'] == 1) && (getModule() != 'frametester') && (!isFramesetModeEnabled())) { + loadTemplate('page_body'); + $GLOBALS['__header_sent'] = 2; + } // END - if +} - // Return compacted content - return $compactedContent; +// Loads page footer and calls doShutdown() +function loadPageFooter () { + // Init page footer + $GLOBALS['__page_footer'] = ''; + + // Footer disabled (e.g. CSS/AJAX/image output) or already sent? + // 1234 5 54 45 5 5 543 3 443 3 443 3 44321 + if ((((!isset($GLOBALS['__footer_sent'])) || (($GLOBALS['__footer_sent'] != 1) && ($GLOBALS['__footer_sent'] != 2))) && (!isCssOutputMode()) && (!isAjaxOutputMode()) && (!isImageOutputMode()))) { + // Run the filter, sweet huh? + runFilterChain('page_footer'); + + // Load page footer + $GLOBALS['__page_footer'] .= loadTemplate('page_footer', TRUE); + } // END - if + + // Footer has been reached + $GLOBALS['__footer_sent'] = 1; + + // Shutdown + doShutdown(); } // [EOF]
'; debug_print_backtrace(); die('