From 8253a8e3e0d4fa8a5987e8119c69fa8d290107be Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 17 Apr 2014 23:40:38 +0200 Subject: [PATCH] Added missing functions logSqlError() and loadPageHeader()/loadPageFooter(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- inc/sql-functions.php | 41 +++++++++++++-- inc/template-functions.php | 102 +++++++++++++++++++++++++++++-------- 2 files changed, 117 insertions(+), 26 deletions(-) diff --git a/inc/sql-functions.php b/inc/sql-functions.php index 5686a79ff5..ede7d72f89 100644 --- a/inc/sql-functions.php +++ b/inc/sql-functions.php @@ -10,11 +10,6 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : SQL-Funktionen fuer Queries * * -------------------------------------------------------------------- * - * $Revision:: $ * - * $Date:: $ * - * $Tag:: 0.2.1-FINAL $ * - * $Author:: $ * - * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * @@ -782,5 +777,41 @@ WHERE ); } +// Log SQL errors to debug.log in installation phase or call reportBug() +function logSqlError ($file, $line, $message) { + // Remember plain error in last_sql_error + setSqlError($file, $line, $message); + + // Is login set? + if (!empty($GLOBALS['mysql']['login'])) { + // Secure login name in message + $message = str_replace($GLOBALS['mysql']['login'], '***', $message); + } // END - if + + // Is database password set? + if (!empty($GLOBALS['mysql']['password'])) { + // Secure password in message + $message = str_replace($GLOBALS['mysql']['password'], '***', $message); + } // END - if + + // Is database name set? + if (!empty($GLOBALS['mysql']['dbase'])) { + // Secure database name in message + $message = str_replace($GLOBALS['mysql']['dbase'], '***', $message); + } // END - if + + // Is there installation phase? + if (isInstaller()) { + /* + * In installation phase, we don't want SQL errors abort e.g. connection + * tests, so just log it away. + */ + logDebugMessage($file, $line, $message); + } else { + // Regular mode, then call reportBug() + reportBug($file, $line, $message); + } +} + // [EOF] ?> diff --git a/inc/template-functions.php b/inc/template-functions.php index cc04cdeb79..caa72894e6 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -10,11 +10,6 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Template-Funktionen * * -------------------------------------------------------------------- * - * $Revision:: $ * - * $Date:: $ * - * $Tag:: 0.2.1-FINAL $ * - * $Author:: $ * - * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * @@ -356,11 +351,11 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC } elseif (substr($template, 0, 3) == 'js_') { // JavaScripts don't like entities, dollar signs and timings //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!'); - $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '");'; + $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '");'; } elseif (isAjaxOutputMode()) { // AJAX (JSON content) //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!'); - $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '";'; + $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '";'; } else { // Prepare eval() command, other output doesn't like entities, maybe //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!'); @@ -374,11 +369,11 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC } elseif (isAjaxOutputMode()) { // AJAX (JSON content) //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!'); - $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '";'; + $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '";'; } else { // JavaScript again //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!'); - $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '");'; + $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '");'; } // END - if } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) { // Only admins shall see this warning or when installation mode is active @@ -649,9 +644,13 @@ function compileCode ($code, $full = TRUE, $compileCode = TRUE) { // Compiles the code function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) { + //* DIE: */ reportBug(__FUNCTION__, __LINE__, 'Called with ' . strlen($code) . ' code length.'); + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called with code()=' . strlen($code) . ',full=' . intval($full) . ',compileCode=' . intval($compileCode)); + // Is the code a string or shall we not compile? if ((!is_string($code)) || ($compileCode === FALSE)) { // Silently return it + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code[]= ' . gettype($code) . ' is not a string or compileCode(' . intval($compileCode) . ') is FALSE.'); return $code; } // END - if @@ -663,17 +662,19 @@ function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) { $secChars = $GLOBALS['security_chars']; } // END - if - // Compile more through a filter - $code = runFilterChain('compile_code', $code); - // First compile these chars array_unshift($secChars['to'] , '{--' , '--}'); array_unshift($secChars['from'], '{%message,', '%}' ); - // Compile QUOT and other non-HTML codes + // Replace QUOT and other non-HTML codes + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - before str_replace() ...'); $code = str_replace($secChars['to'], $secChars['from'], $code); + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - after str_replace() ...'); + + // Compile the prepared code through a filter chain + $code = runFilterChain('compile_code', $code); - // Find $content[bla][blub] entries + // Find all $content[bla][blub] entries preg_match_all('/\$content((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches); //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Second regex gave ' . count($matches[0]) . ' matches.'); @@ -760,10 +761,17 @@ function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) { } // END - if } // END - if - // Replace {COMPILE_DOLLAR} back to dollar sign - $code = str_replace('{COMPILE_DOLLAR}', '$', $code); + // Add 'COMPILE_DOLLAR' again + array_push($secChars['to'] , '{COMPILE_DOLLAR}'); + array_push($secChars['from'], '$'); + + // Replace QUOT and other non-HTML codes + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - before str_replace() ...'); + $code = str_replace($secChars['to'], $secChars['from'], $code); + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - after str_replace() ...'); // Finally return it + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Exiting with code()=' . strlen($code)); return $code; } @@ -1191,7 +1199,7 @@ function app_exit ($file, $line, $message) { } // Load header - loadIncludeOnce('inc/header.php'); + loadPageHeader(); // Rewrite message for output $message = sprintf( @@ -1207,14 +1215,14 @@ function app_exit ($file, $line, $message) { $OUT = loadTemplate('ajax_app_exit_message', TRUE, $message); // Output it as JSON encoded - outputHtml(encodeJson(array('reply_content' => urlencode(doFinalCompilation($OUT))))); + outputHtml(encodeJson(array('reply_content' => urlencode(doFinalCompilation(compileRawCode($OUT)))))); } else { // Load the message template loadTemplate('app_exit_message', FALSE, $message); } // Load footer - loadIncludeOnce('inc/footer.php'); + loadPageFooter(); } // Display parsing time and number of SQL queries in footer @@ -1316,7 +1324,7 @@ function reportBug ($file, $line, $message = '', $sendEmail = TRUE) { } // END - if // Is there HTML/CSS/AJAX mode while debug-mode is enabled? - if ((isDebugModeEnabled()) && ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode()))) { + if (((isDebugModeEnabled()) || (isInstaller())) && ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode()))) { // And abort here app_exit($file, $line, $debug); } elseif (isAjaxOutputMode()) { @@ -1336,7 +1344,7 @@ function reportBug ($file, $line, $message = '', $sendEmail = TRUE) { sendAjaxContent(TRUE); // Include footer - loadIncludeOnce('inc/footer.php'); + loadPageFooter(); } else { // Raw/image output mode and all other modes doesn't work well with text ... die(); @@ -2467,5 +2475,57 @@ function generateDayMonthYearSelectionBox ($day, $month, $year) { 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 + + // 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 +} + +// 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] ?> -- 2.39.2