X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ftemplate-functions.php;h=70ffd792b14765771d5d400daa6a14eb4e8e839c;hb=6b1e55213d76a67e9aa3d9f1e4dcb55e0bbf12ee;hp=dc13d3e1b95e30d8ae7aaab5dcd45c0c7e74afd1;hpb=3082135522e6e32a26061fd2363ddb5354a1272a;p=mailer.git diff --git a/inc/template-functions.php b/inc/template-functions.php index dc13d3e1b9..70ffd792b1 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -16,7 +16,7 @@ * $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 * @@ -144,7 +144,7 @@ function outputHtml ($htmlCode = NULL, $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,6 +180,15 @@ function outputHtml ($htmlCode = NULL, $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.'); @@ -226,26 +235,26 @@ function doFinalCompilation ($code, $insertComments = TRUE, $enableCodes = TRUE) 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($code).'
'.linenumberCode($eval).'
'.lineNumberCode($eval).'
'.linenumberCode($newContent).'
'.lineNumberCode($newContent).'
'.encodeEntities($newContent).'
' . linenumberCode($eval) . '
' . lineNumberCode($eval) . '
'.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 @@ -1322,7 +1293,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 @@ -1333,7 +1304,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), @@ -1344,10 +1315,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()) && ((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 + loadIncludeOnce('inc/footer.php'); } else { // Raw/image output mode and all other modes doesn't work well with text ... die(); @@ -1508,8 +1497,8 @@ function generateExtensionInactiveNotInstalledMessage ($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 @@ -1518,7 +1507,7 @@ function generateExtensionInactiveNotInstalledMessage ($ext_name) { } // Print code with line numbers -function linenumberCode ($code) { +function lineNumberCode ($code) { // By default copy the code $codeE = $code; @@ -1552,7 +1541,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%} '; @@ -1735,12 +1724,12 @@ function sendModeMails ($mod, $modes) { break; case 'password': // Password was changed - $content['message'] = '{--MEMBER_CHANGED_PASS--}' . PHP_EOL; + $content['message'] = '{--MEMBER_CHANGED_PASSWORD--}' . PHP_EOL; break; default: - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode)); - $content['message'] = '{--MEMBER_UNKNOWN_MODE--}' . ': ' . $mode . PHP_EOL . PHP_EOL; + 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 @@ -1759,23 +1748,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 { @@ -1788,15 +1777,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--}'; @@ -1811,6 +1800,9 @@ 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) { + // options must be an array + assert(is_array($options)); + // Default is empty $addKey = ''; @@ -1990,9 +1982,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', $return, $message); + 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_unsaved', TRUE, $message); } // Generates a selection box for (maybe) given gender @@ -2078,6 +2088,71 @@ 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 //----------------------------------------------------------------------------- @@ -2112,7 +2187,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 @@ -2122,13 +2197,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 @@ -2299,69 +2374,63 @@ function doTemplateDereferrerUrl ($templateName, $clear = FALSE, $url = NULL) { return fixEmptyContentToDashes($url); } -// Tries to anonymize some sensitive data (e.g. IP address, user agent, referrer, etc.) -function anonymizeSensitiveData ($data) { - // Trim it - $data = trim($data); +// Load another template and return its content +function doTemplateLoadTemplate ($templateName, $clear = FALSE, $theTemplate, $content = array()) { + // Load "the" template + return loadTemplate($theTemplate, TRUE, $content); +} - // 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); +// Output HTML code for favicon.ico, if found +function doTemplateMetaFavIcon ($templateName, $clear = FALSE) { + // Default is not found + $out = ''; - // Only display first 2 octets - $data = $ipArray[0] . '.' . $ipArray[1] . '.?.?'; - } else { - // Generic data - $data = '{--DATA_IS_HIDDEN--}'; - } + // 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 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(PHP_EOL, '', 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 - } // END - if +// Removes comments with @DEPRECATED +function removeDeprecatedComment ($output) { + // Explode it into pieces ... ;) + $lines = explode(chr(10), $output); - // Set the content again - // @TODO Is this needed for e.g. $GLOBALS['template_content'] ? $this->setRawTemplateData($compactedContent); + // Walk through all + $return = ''; + foreach ($lines as $line) { + // Is there a @DEPRECATED? + if (isInString('@DEPRECATED', $line)) { + // Ignore this line + continue; + } // END - if - // Return compacted content - return $compactedContent; + // Add it + $return .= $line . chr(13); + } // END - foreach + + // Returned cleaned content + return $return; } // [EOF]
'; debug_print_backtrace(); die('