getTotalFatalErrors() is now the right name
[mailer.git] / inc / functions.php
index e25fce111139915ff13934aeaf5e26894a8bb0f5..f1af163a8fc4899f4833b7ca4dc85fce765f3224 100644 (file)
@@ -59,43 +59,6 @@ function IS_INC_WRITEABLE($inc) {
        }
 }
 
-// Open a table (you may want to add some header stuff here)
-// @DEPRECATED
-function OPEN_TABLE ($PERCENT = "", $CLASS = "", $ALIGN="left", $VALIGN="", $td_only=false) {
-       global $table_cnt;
-
-       // Count tables so we can generate CSS classes for every table... :-)
-       if (empty($CLASS)) {
-               // Class is empty so count one up and create a class
-               $table_cnt++; $CLASS = "class".$table_cnt;
-       }
-       $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\"";
-
-       // Shall I add the classes to TABLE and TD or only to TD?
-       if (!$td_only) $OUT .= " class=\"".$CLASS."\"";
-
-       // Width is given
-       if (!empty($PERCENT)) $OUT .= " width=\"".$PERCENT."\"";
-
-       // Horizonal align
-       if (!empty($ALIGN)) $OUT .=" align=\"".$ALIGN."\"";
-
-       // Vertical align is given
-       if (!empty($VALIGN))  $OUT .= " valign=\"".$VALIGN."\"";
-       $OUT .= ">\n<TR>\n<TD";
-       if (!empty($ALIGN)) $OUT .=" align=\"".$ALIGN."\"";
-       $OUT .= " class=\"".$CLASS."\">";
-       OUTPUT_HTML($OUT);
-}
-
-// Close a table (you may want to add some footer stuff here)
-// @DEPRECATED
-function CLOSE_TABLE( $ADD="") {
-       OUTPUT_HTML("  </TD>\n</TR>");
-       if (!empty($ADD)) OUTPUT_HTML($ADD);
-       OUTPUT_HTML("</TABLE>");
-}
-
 // Output HTML code directly or "render" it. You addionally switch the new-line character off
 function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
        // Some global variables
@@ -135,7 +98,7 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
                default:
                        // Huh, something goes wrong or maybe you have edited config.php ???
                        DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid renderer %s detected.", OUTPUT_MODE));
-                       MXCHANGE_DIE("<strong>".FATAL_ERROR.":</strong> ".LANG_NO_RENDER_DIRECT);
+                       mxchange_die("<strong>{!FATAL_ERROR!}:</strong> {!LANG_NO_RENDER_DIRECT!}");
                        break;
                }
        } elseif ((_OB_CACHING == "on") && ($footer == 1)) {
@@ -144,18 +107,15 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
                        // Log this error
                        DEBUG_LOG(__FUNCTION__, __LINE__, "Headers already sent! We need debug backtrace here.");
 
-                       // Output debug trace
-                       print("<stron>Headers are already sent!</strong><br />\n");
-                       print("Please report this error at <a href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a>:<pre>");
-                       debug_print_backtrace();
-                       die("</pre>Thank you for your help finding bugs.");
+                       // Trigger an user error
+                       trigger_error("Headers are already sent!");
                } // END - if
 
                // Output cached HTML code
                $OUTPUT = ob_get_contents();
 
                // Clear output buffer for later output
-               ob_end_clean();
+               clearOutputBuffer();
 
                // Send HTTP header
                header("HTTP/1.1 200");
@@ -171,7 +131,7 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
                header("Connection: Close");
 
                // Extension "rewrite" installed?
-               if ((EXT_IS_ACTIVE("rewrite")) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
+               if ((EXT_IS_ACTIVE("rewrite")) && ($CSS != "1") && ($CSS != "-1")) {
                        $OUTPUT = REWRITE_LINKS($OUTPUT);
                } // END - if
 
@@ -194,7 +154,7 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
                OUTPUT_RAW($OUTPUT);
        } elseif ((OUTPUT_MODE == "render") && (!empty($OUTPUT))) {
                // Rewrite links when rewrite extension is active
-               if ((EXT_IS_ACTIVE("rewrite")) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
+               if ((EXT_IS_ACTIVE("rewrite")) && ($CSS != "1") && ($CSS != "-1")) {
                        $OUTPUT = REWRITE_LINKS($OUTPUT);
                } // END - if
 
@@ -239,7 +199,7 @@ function addFatalMessage ($message, $extra="") {
 }
 
 // Getter for total fatal message count
-function getTotalFatalMessages () {
+function getTotalFatalErrors () {
        global $FATAL;
 
        // Init coun
@@ -817,12 +777,9 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        if (getConfig('auto_purge') == 0) {
                // Will never expire!
                $EXPIRATION = MAIL_WILL_NEVER_EXPIRE;
-       } elseif (function_exists('CREATE_FANCY_TIME')) {
+       } else {
                // Create nice date string
                $EXPIRATION = CREATE_FANCY_TIME(getConfig('auto_purge'));
-       } else {
-               // Display days only
-               $EXPIRATION = round(getConfig('auto_purge')/60/60/24)." "._DAYS;
        }
 
        // Is content an array?
@@ -926,6 +883,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        if (empty($newContent)) {
                // Compiling failed
                $newContent = "Compiler error for template {$template}!\nUncompiled content:\n".$tmpl_file;
+               // Add last error if the required function exists
                if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
        } // END - if
 
@@ -969,7 +927,7 @@ function LOAD_URL($URL, $addUrlData=true) {
 
        // Clear it only if there is content
        if (!empty($OUTPUT)) {
-               ob_end_clean();
+               clearOutputBuffer();
        } // END - if
 
        // Add some data to URL if cookies are not accepted
@@ -989,15 +947,31 @@ function LOAD_URL($URL, $addUrlData=true) {
                debug_print_backtrace();
                die("</pre>URL={$URL}");
                */
-               @header ("Location: ".str_replace("&amp;", "&", $URL));
+               header ("Location: ".str_replace("&amp;", "&", $URL));
        } else {
                // Output error message
-               include(PATH."inc/header.php");
+               require(PATH."inc/header.php");
                LOAD_TEMPLATE("redirect_url", false, str_replace("&amp;", "&", $URL));
-               include(PATH."inc/footer.php");
+               require(PATH."inc/footer.php");
        }
        exit();
 }
+
+// Wrapper for LOAD_URL but URL comes from a configuration entry
+function LOAD_CONFIGURED_URL ($configEntry) {
+       // Get the URL
+       $URL = getConfig($configEntry);
+
+       // Is this URL set?
+       if (is_null($URL)) {
+               // Then abort here
+               trigger_error(sprintf("Configuration entry %s is not set!", $configEntry));
+       } // END - if
+
+       // Load the URL
+       LOAD_URL($URL);
+}
+
 //
 function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
        global $SEC_CHARS, $URL_CHARS;
@@ -2265,13 +2239,14 @@ function FIX_DELETED_COOKIES ($cookies) {
 
 // Output error messages in a fasioned way and die...
 function mxchange_die ($msg) {
-       global $footer;
+       // Load header
+       require_once(PATH."inc/header.php");
 
        // Load the message template
        LOAD_TEMPLATE("admin_settings_saved", false, $msg);
 
        // Load footer
-       include(PATH."inc/footer.php");
+       require(PATH."inc/footer.php");
 
        // Exit explicitly
        exit;
@@ -2890,7 +2865,7 @@ function getConfig ($entry) {
        return $value;
 }
 
-// @TODO Rewrite all language constants to the function getLanguage().
+// @TODO Rewrite all language constants to this function.
 // "Getter" for language strings
 function getMessage ($messageId) {
        // Default is not found!
@@ -3059,6 +3034,15 @@ function GEN_ERROR_CODE_FROM_ACCOUNT_STATUS ($status) {
        return $ERROR;
 }
 
+// Clears the output buffer. This function does *NOT* backup sent content.
+function clearOutputBuffer () {
+       // Trigger an error on failure
+       if (!ob_end_clean()) {
+               // Failed!
+               trigger_error(__FUNCTION__.": Failed to clean output buffer.");
+       } // END - if
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////