X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=f85b4df13e107b501931b6c35c2555f4ac387ff1;hb=adec9e8fa79778d9bc050f092e494272e3f19925;hp=6e3cda3de9dad272524e41e5964431122e6f1cbe;hpb=9642d17a028f3e7fdc57fa12e5dbd7129f166816;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 6e3cda3de9..f85b4df13e 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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__, '{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}'); + debug_report_bug(__FUNCTION__, __LINE__, '{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}'); break; } // END - switch } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['header'])) || (count($GLOBALS['header']) == 0))) { @@ -126,7 +126,7 @@ function sendHttpHeaders () { $now = gmdate('D, d M Y H:i:s') . ' GMT'; // Send HTTP header - sendHeader('HTTP/1.1 200 OK'); + sendHeader('HTTP/1.1 ' . getHttpStatus()); // General headers for no caching sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21 @@ -162,7 +162,7 @@ function compileFinalOutput () { // Was that eval okay? if (empty($newContent)) { // Something went wrong! - debug_report_bug('Evaluation error:
' . linenumberCode($eval) . '
', false); + debug_report_bug(__FUNCTION__, __LINE__, 'Evaluation error:
' . linenumberCode($eval) . '
', 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; @@ -324,9 +324,6 @@ function loadTemplate ($template, $return = false, $content = array()) { // Cache the eval() command here $GLOBALS['template_eval'][$template] = $eval; - - // Eval the code - eval($GLOBALS['template_eval'][$template]); } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) { // Only admins shall see this warning or when installation mode is active $ret = '
{--TEMPLATE_404--}
@@ -341,10 +338,13 @@ function loadTemplate ($template, $return = false, $content = array()) { // No file! $GLOBALS['template_eval'][$template] = '404'; } - } else { + } + + // Code set? + if ((isset($GLOBALS['template_eval'][$template])) && ($GLOBALS['template_eval'][$template] != '404')) { // Eval the code eval($GLOBALS['template_eval'][$template]); - } + } // END - if // Do we have some content to output or return? if (!empty($ret)) { @@ -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 @@ -872,6 +872,34 @@ function translateUserStatus ($status) { return $ret; } +// "Translates" 'visible' and 'locked' to a CSS class +function translateMenuVisibleLocked ($content, $prefix = '') { + // Translate 'visible' and keep an eye on the prefix + switch ($content[$prefix . 'visible']) { + // Should be visible + case 'Y': $content[$prefix . 'visible_css'] = $prefix . 'menu_visible' ; break; + case 'N': $content[$prefix . 'visible_css'] = $prefix . 'menu_invisible'; break; + default: + // Please report this + debug_report_bug('Unsupported visible value detected. content=
'.print_r($content, true).'
'); + break; + } // END - switch + + // Translate 'locked' and keep an eye on the prefix + switch ($content[$prefix . 'locked']) { + // Should be locked + case 'Y': $content[$prefix . 'locked_css'] = $prefix . 'menu_locked' ; break; + case 'N': $content[$prefix . 'locked_css'] = $prefix . 'menu_unlocked'; break; + default: + // Please report this + debug_report_bug('Unsupported locked value detected. content=
'.print_r($content, true).'
'); + break; + } // END - switch + + // Return the resulting array + return $content; +} + // Generates an URL for the dereferer function generateDerefererUrl ($URL) { // Don't de-refer our own links! @@ -954,7 +982,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 +1021,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 +1369,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 +1381,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 'Image'; @@ -2074,7 +2102,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 +2183,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 @@ -2362,10 +2390,7 @@ function app_die ($F, $L, $message) { loadIncludeOnce('inc/header.php'); // Rewrite message for output - $message = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $message); - - // Better log this message away - if ($F != 'debug_report_bug') logDebugMessage($F, $L, $message); + $message = sprintf(getMessage('MAILER_HAS_DIED'), basename($F), $L, $message); // Load the message template loadTemplate('app_die_message', false, $message); @@ -2374,12 +2399,12 @@ 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); } } // Display parsing time and number of SQL queries in footer -function displayParsingTime() { +function displayParsingTime () { // Is the timer started? if (!isset($GLOBALS['startTime'])) { // Abort here @@ -2523,7 +2548,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 @@ -2546,7 +2571,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 @@ -2568,7 +2593,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 @@ -2630,7 +2655,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); @@ -2852,8 +2877,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 @@ -3147,10 +3172,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 @@ -3165,7 +3190,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); @@ -3218,7 +3243,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 @@ -3313,7 +3338,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)) { @@ -3387,7 +3412,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 @@ -3466,7 +3491,7 @@ function initCacheInstance () { $GLOBALS['cache_instance'] = new CacheSystem(); if ($GLOBALS['cache_instance']->getStatus() != 'done') { // Failed to initialize cache sustem - addFatalMessage(__FILE__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_CANNOT_INITIALIZE')); + addFatalMessage(__FUNCTION__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_CANNOT_INITIALIZE')); } // END - if } @@ -3552,16 +3577,16 @@ function determinePageTitle () { $pageTitle = '[-- ' . getConfig('MAIN_TITLE') . ' - ' . getModuleTitle(getModule()) . ' --]'; } elseif ((isInstalled()) && (!isAdminRegistered())) { // Installed but no admin registered - $pageTitle = getMessage('SETUP_OF_MXCHANGE'); + $pageTitle = getMessage('SETUP_OF_MAILER'); } elseif ((!isInstalled()) || (!isAdminRegistered())) { // Installation mode - $pageTitle = getMessage('INSTALLATION_OF_MXCHANGE'); + $pageTitle = getMessage('INSTALLATION_OF_MAILER'); } else { // Configuration not found! $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 @@ -3797,7 +3822,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; }