debug_report_bug() should be used as a replacement for app_die() calls
[mailer.git] / inc / functions.php
index 9a6014a05b515e9197cc8299bf1b50e8c4e45c5f..305ee3f8aa02f6b18964bd1878aa3fb6aac2c7cb 100644 (file)
@@ -85,7 +85,7 @@ function outputHtml ($htmlCode, $newLine = true) {
 
                        default:
                                // Huh, something goes wrong or maybe you have edited config.php ???
-                               app_die(__FUNCTION__, __LINE__, '<strong>{--FATAL_ERROR--}:</strong> {--LANG_NO_RENDER_DIRECT--}');
+                               debug_report_bug(__FUNCTION__, __LINE__, '<strong>{--FATAL_ERROR--}:</strong> {--LANG_NO_RENDER_DIRECT--}');
                                break;
                } // END - switch
        } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['header'])) || (count($GLOBALS['header']) == 0))) {
@@ -162,7 +162,7 @@ function compileFinalOutput () {
                // Was that eval okay?
                if (empty($newContent)) {
                        // Something went wrong!
-                       debug_report_bug('Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
+                       debug_report_bug(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
                } // END - if
 
                // Use it again
@@ -256,7 +256,7 @@ function getTotalFatalErrors () {
 // Load a template file and return it's content (only it's name; do not use ' or ")
 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) . ')');
+       if (!is_bool($return)) debug_report_bug(__FUNCTION__, __LINE__, 'return is not bool (' . gettype($return) . ')');
 
        // @TODO Try to rewrite all $DATA to $content
        global $DATA;
@@ -839,7 +839,7 @@ function translateGender ($gender) {
                case 'C': $ret = getMessage('GENDER_C'); break;
                default:
                        // Please report bugs on unknown genders
-                       debug_report_bug(sprintf("Unknown gender %s detected.", $gender));
+                       debug_report_bug(__FUNCTION__, __LINE__, sprintf("Unknown gender %s detected.", $gender));
                        break;
        } // END - switch
 
@@ -864,7 +864,7 @@ function translateUserStatus ($status) {
 
                default:
                        // Please report all unknown status
-                       debug_report_bug(sprintf("Unknown status %s detected.", $status));
+                       debug_report_bug(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
                        break;
        } // END - switch
 
@@ -954,7 +954,7 @@ function redirectToUrl ($URL, $allowSpider = true) {
        } // END - if
 
        // Three different ways to debug...
-       //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
+       //* DEBUG: */ debug_report_bug(__FUNCTION__, __LINE__, sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
        //* DEBUG: */ die($URL);
 
@@ -993,7 +993,7 @@ function redirectToConfiguredUrl ($configEntry) {
        // Is this URL set?
        if (is_null($URL)) {
                // Then abort here
-               debug_report_bug(sprintf("Configuration entry %s is not set!", $configEntry));
+               debug_report_bug(__FUNCTION__, __LINE__, sprintf("Configuration entry %s is not set!", $configEntry));
        } // END - if
 
        // Load the URL
@@ -1341,7 +1341,7 @@ function bigintval ($num, $castValue = true, $abortOnMismatch = true) {
        // Has the whole value changed?
        if (('' . $ret . '' != '' . $num . '') && ($abortOnMismatch === true)) {
                // Log the values
-               debug_report_bug('Problem with number found. ret=' . $ret . ', num='. $num);
+               debug_report_bug(__FUNCTION__, __LINE__, 'Problem with number found. ret=' . $ret . ', num='. $num);
        } // END - if
 
        // Return result
@@ -1353,7 +1353,7 @@ function generateImageOrCode ($img_code, $headerSent = true) {
        // Is the code size oversized or shouldn't we display it?
        if ((strlen($img_code) > 6) || (empty($img_code)) || (getConfig('code_length') == '0')) {
                // Stop execution of function here because of over-sized code length
-               debug_report_bug('img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
+               debug_report_bug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
        } elseif ($headerSent === false) {
                // Return an HTML code here
                return '<img src="{%url=img.php?code=' . $img_code . '%}" alt="Image" />';
@@ -2074,7 +2074,7 @@ function isUrlValid ($URL, $compile=true) {
 // Generate a list of administrative links to a given userid
 function generateMemberAdminActionLinks ($userid, $status = '') {
        // Make sure userid is a number
-       if ($userid != bigintval($userid)) debug_report_bug('userid is not a number!');
+       if ($userid != bigintval($userid)) debug_report_bug(__FUNCTION__, __LINE__, 'userid is not a number!');
 
        // Define all main targets
        $targetArray = array('del_user', 'edit_user', 'lock_user', 'add_points', 'sub_points');
@@ -2155,7 +2155,7 @@ function generateHash ($plainText, $salt = '', $hash = true) {
        // Do we miss an arry element here?
        if (!isConfigEntrySet('file_hash')) {
                // Stop here
-               debug_report_bug('Missing file_hash in ' . __FUNCTION__ . '.');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Missing file_hash in ' . __FUNCTION__ . '.');
        } // END - if
 
        // When the salt is empty build a new one, else use the first x configured characters as the salt
@@ -2377,7 +2377,7 @@ function app_die ($F, $L, $message) {
                loadIncludeOnce('inc/footer.php');
        } else {
                // Script tried to kill itself twice
-               debug_report_bug('Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
+               die('['.__FUNCTION__.':'.__LINE__.']: Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
        }
 }
 
@@ -2526,7 +2526,7 @@ function debug_get_mailable_backtrace () {
 }
 
 // Output a debug backtrace to the user
-function debug_report_bug ($message = '', $sendEmail = true) {
+function debug_report_bug ($F, $L, $message = '', $sendEmail = true) {
        // Is this already called?
        if (isset($GLOBALS[__FUNCTION__])) {
                // Other backtrace
@@ -2549,7 +2549,7 @@ function debug_report_bug ($message = '', $sendEmail = true) {
                );
 
                // @TODO Add a little more infos here
-               logDebugMessage(__FUNCTION__, __LINE__, strip_tags($message));
+               logDebugMessage($F, $L, strip_tags($message));
        } // END - if
 
        // Add output
@@ -2571,7 +2571,7 @@ function debug_report_bug ($message = '', $sendEmail = true) {
        } // END - if
 
        // And abort here
-       app_die(__FUNCTION__, __LINE__, $debug);
+       app_die($F, $L, $debug);
 }
 
 // Generates a ***weak*** seed
@@ -2633,7 +2633,7 @@ function getMessageFromErrorCode ($code) {
                case getCode('URL_TLOCK'):
                        // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ?
                        $result = SQL_QUERY_ESC("SELECT `timestamp` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
-                               array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
+                               array(bigintval(getRequestParameter('id'))), __FUNCTION__, __LINE__);
 
                        // Load timestamp from last order
                        list($timestamp) = SQL_FETCHROW($result);
@@ -2855,8 +2855,8 @@ function logDebugMessage ($funcFile, $line, $message, $force=true) {
                // Remove CRLF
                $message = str_replace("\r", '', str_replace("\n", '', $message));
 
-               // Log this message away, we better don't call app_die() here to prevent an endless loop
-               $fp = fopen(getConfig('CACHE_PATH') . 'debug.log', 'a') or die(__FUNCTION__.'['.__LINE__.']: Cannot write logfile debug.log!');
+               // Log this message away
+               $fp = fopen(getConfig('CACHE_PATH') . 'debug.log', 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write logfile debug.log!');
                fwrite($fp, date('d.m.Y|H:i:s', time()) . '|' . getModule(false) . '|' . basename($funcFile) . '|' . $line . '|' . $message . "\n");
                fclose($fp);
        } // END - if
@@ -3150,10 +3150,10 @@ function shutdown () {
        // Check if not in installation phase and the link is up
        if ((!isInstallationPhase()) && (SQL_IS_LINK_UP())) {
                // Close link
-               SQL_CLOSE(__FILE__, __LINE__);
+               SQL_CLOSE(__FUNCTION__, __LINE__);
        } elseif (!isInstallationPhase()) {
                // No database link
-               addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK_SHUTDOWN'));
+               addFatalMessage(__FUNCTION__, __LINE__, getMessage('NO_DB_LINK_SHUTDOWN'));
        }
 
        // Stop executing here
@@ -3168,7 +3168,7 @@ function initMemberId () {
 // Setter for member id
 function setMemberId ($memberid) {
        // We should not set member id to zero
-       if ($memberid == '0') debug_report_bug('Userid should not be set zero.');
+       if ($memberid == '0') debug_report_bug(__FUNCTION__, __LINE__, 'Userid should not be set zero.');
 
        // Set it secured
        $GLOBALS['member_id'] = bigintval($memberid);
@@ -3221,7 +3221,7 @@ function getExtraTitle () {
        // Is the extra title set?
        if (!isExtraTitleSet()) {
                // No, then abort here
-               debug_report_bug('extra_title is not set!');
+               debug_report_bug(__FUNCTION__, __LINE__, 'extra_title is not set!');
        } // END - if
 
        // Return it
@@ -3316,7 +3316,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
        $files = array();
 
        // Open directory
-       $dirPointer = opendir(getConfig('PATH') . $baseDir) or app_die(__FUNCTION__, __LINE__, 'Cannot read directory ' . basename($baseDir) . '.');
+       $dirPointer = opendir(getConfig('PATH') . $baseDir) or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot read directory ' . basename($baseDir) . '.');
 
        // Read all entries
        while ($baseFile = readdir($dirPointer)) {
@@ -3390,7 +3390,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
                                }
                        } else {
                                // We found .php file but should not search for them, why?
-                               debug_report_bug('We should find files with extension=' . $extension . ', but we found a PHP script.');
+                               debug_report_bug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script.');
                        }
                } elseif (substr($baseFile, -4, 4) == $extension) {
                        // Other, generic file found
@@ -3469,7 +3469,7 @@ function initCacheInstance () {
        $GLOBALS['cache_instance'] = new CacheSystem();
        if ($GLOBALS['cache_instance']->getStatus() != 'done') {
                // Failed to initialize cache sustem
-               addFatalMessage(__FILE__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMessage('CACHE_CANNOT_INITIALIZE'));
+               addFatalMessage(__FUNCTION__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMessage('CACHE_CANNOT_INITIALIZE'));
        } // END - if
 }
 
@@ -3564,7 +3564,7 @@ function determinePageTitle () {
                $pageTitle = getMessage('NO_CONFIG_FOUND_TITLE');
 
                // Do not add the fatal message in installation mode
-               if ((!isInstalling()) && (!isConfigurationLoaded())) addFatalMessage(__FILE__, __LINE__, getMessage('NO_CONFIG_FOUND'));
+               if ((!isInstalling()) && (!isConfigurationLoaded())) addFatalMessage(__FUNCTION__, __LINE__, getMessage('NO_CONFIG_FOUND'));
        }
 
        // Return title
@@ -3800,7 +3800,7 @@ function getModuleFromFileName ($file, $accessLevel) {
                        break;
 
                default: // Unsupported file name / access level
-                       debug_report_bug('Unsupported file name=' . basename($file) . '/access level=' . $accessLevel);
+                       debug_report_bug(__FUNCTION__, __LINE__, 'Unsupported file name=' . basename($file) . '/access level=' . $accessLevel);
                        break;
        }