X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=faecd19e7d1811d8ed10f2eacb03232503f0e332;hb=60822fcfed13786d1e7d86b10faecda6d2195def;hp=5fae9029ade664d4af5dfd37be0eec38f98d5d70;hpb=7052cc3bd3ca07281078acbbce6ce595d753def1;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 5fae9029ad..faecd19e7d 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -70,15 +70,17 @@ function addFatalMessage ($F, $L, $message, $extra = '') { // Getter for total fatal message count function getTotalFatalErrors () { // Init count - $count = '0'; + $count = 0; // Is there at least the first entry? if (!empty($GLOBALS['fatal_messages'][0])) { // Get total count $count = count($GLOBALS['fatal_messages']); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count=' . $count . ' - FROM ARRAY'); } // END - if // Return value + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count=' . $count . ' - EXIT!'); return $count; } @@ -648,7 +650,7 @@ function createFancyTime ($stamp) { } // END - foreach // Is something there? - if (strlen($ret) > 0) { + if (!empty($ret)) { // Remove leading commata and space $ret = substr($ret, 2); } else { @@ -799,7 +801,9 @@ function scrambleString ($str) { } // Compare both lengths and abort if different - if (strlen($str) != count($scrambleNums)) return $str; + if (strlen($str) != count($scrambleNums)) { + return $str; + } // END - if // Scramble string here //* DEBUG: */ debugOutput('***Original=' . $str.'***
'); @@ -904,7 +908,7 @@ function encodeHashForCookie ($passHash) { $mod = substr($mod, 0, 2); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'idx=' . $idx . ',part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')'); - $mod = str_repeat('0', (2 - strlen($mod))) . $mod; + $mod = str_pad($mod, 2, '0', STR_PAD_LEFT); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*'); $start += 2; $newHash .= $mod; @@ -1207,7 +1211,7 @@ function isUrlValidSimple ($url) { // Wtites data to a config.php-style file // @TODO Rewrite this function to use readFromFile() and writeToFile() -function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) { +function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek = 0) { // Initialize some variables $done = FALSE; $seek++; @@ -1235,7 +1239,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 // Start reading while (!feof($fp)) { // Read from source file - $line = fgets ($fp, 1024); + $line = fgets($fp, 1024); if (isInString($search, $line)) { $next = '0'; @@ -1266,18 +1270,22 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 fclose($fp); if (($done === TRUE) && ($found === TRUE)) { - // Copy back tmp file and delete tmp :-) + // Copy back temporary->FQFN file and ... copyFileVerified($tmp, $FQFN, 0644); + + // ... delete temporay file :-) return removeFile($tmp); } elseif ($found === FALSE) { - outputHtml('CHANGE: 404!'); + // Entry not found + logDebugMessage(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' cannot be changed: comment=' . $comment . ',prefix=' . $prefix . ',inserted=' . $inserted . ',seek=' . $seek . ' - 404!'); } else { - outputHtml('TMP: UNDONE!'); + // Temporary file not fully written + logDebugMessage(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' cannot be changed: comment=' . $comment . ',prefix=' . $prefix . ',inserted=' . $inserted . ',seek=' . $seek . ' - Temporary file unfinished!'); } } } else { // File not found, not readable or writeable - reportBug(__FUNCTION__, __LINE__, 'File not readable/writeable. file=' . basename($FQFN)); + reportBug(__FUNCTION__, __LINE__, 'File not readable/writeable. file=' . basename($FQFN) . ',comment=' . $comment . ',prefix=' . $prefix . ',inserted=' . $inserted . ',seek=' . $seek); } // An error was detected! @@ -1292,7 +1300,7 @@ function logDebugMessage ($funcFile, $line, $message, $force=true) { $message = str_replace(array(chr(13), PHP_EOL), array('', ''), $message); // Log this message away - appendLineToFile(getPath() . getCachePath() . 'debug.log', generateDateTime(time(), '4') . '|' . getModule(FALSE) . '|' . basename($funcFile) . '|' . $line . '|' . $message); + appendLineToFile(getPath() . getCachePath() . 'debug.log', generateDateTime(time(), '4') . '|' . getModule(FALSE) . ':' . getExtraModule() . '|' . basename($funcFile) . '|' . $line . '|' . $message); } // END - if } @@ -1343,7 +1351,7 @@ function handleExtraValues ($filterFunction, $value, $extraValue) { } // Tries to determine if call-back functions and/or extra values shall be parsed -function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $userIdColumn, $search) { +function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $userIdColumn, $search, $id = NULL) { // Debug mode enabled? if (isDebugModeEnabled()) { // Debug message @@ -1351,14 +1359,14 @@ function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $u } // END - if // Send data through the filter function if found - if ($key == $userIdColumn[0]) { + if ($key === $userIdColumn[0]) { // Is the userid, we have to process it with convertZeroToNull() $entries = convertZeroToNull($entries); } elseif ((!empty($filterFunctions[$key])) && (isset($extraValues[$key]))) { // Debug mode enabled? if (isDebugModeEnabled()) { // Then log it - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$search] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - BEFORE!'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$key] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - BEFORE!'); } // END - if // Filter function + extra value set @@ -1367,8 +1375,26 @@ function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $u // Debug mode enabled? if (isDebugModeEnabled()) { // Then log it - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$search] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - AFTER!'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$key] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - AFTER!'); + } // END - if + } elseif ((!empty($filterFunctions[$search])) && (!empty($extraValues[$search]))) { + // Debug mode enabled? + if (isDebugModeEnabled()) { + // Then log it + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$search] . ',key=' . $key . ',search=' . $search . ',entries[' . gettype($entries) . ']=' . $entries . ' - BEFORE!'); + } // END - if + + // Handle extra values + $entries = handleExtraValues($filterFunctions[$search], $entries, $extraValues[$search]); + + // Debug mode enabled? + if (isDebugModeEnabled()) { + // Then log it + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$search] . ',key=' . $key . ',search=' . $search . ',entries[' . gettype($entries) . ']=' . $entries . ' - AFTER!'); } // END - if + + // Make sure entries is not bool, then something went wrong + assert(!is_bool($entries)); } elseif (!empty($filterFunctions[$search])) { // Debug mode enabled? if (isDebugModeEnabled()) { @@ -1600,8 +1626,8 @@ function doShutdown () { // Call the filter chain 'shutdown' runFilterChain('shutdown', NULL); - // Check if not in installation phase and the link is up - if ((!isInstallationPhase()) && (SQL_IS_LINK_UP())) { + // Check if link is up + if (SQL_IS_LINK_UP()) { // Close link SQL_CLOSE(__FUNCTION__, __LINE__); } elseif (!isInstallationPhase()) { @@ -1808,7 +1834,6 @@ function mapModuleToTable ($moduleName) { case 'login': // ... and 'login' the member's menu $moduleName = 'member'; break; - // Anything else will not be mapped, silently. } // END - switch @@ -2060,13 +2085,10 @@ function convertZeroToNull ($number) { // Converts a NULL to zero function convertNullToZero ($number) { // Is it a valid username? - if ((!is_null($number)) && (!empty($number)) && ($number > 0)) { - // Always secure it - $number = bigintval($number); - } else { + if ((is_null($number)) || (empty($number)) || ($number < 1)) { // Is not valid or zero $number = '0'; - } + } // END - if // Return it return $number; @@ -2301,7 +2323,7 @@ function convertStringToBoolean ($str) { } // END - if // Determine it - $GLOBALS[__FUNCTION__][$str] = (($strTrimmed == 'true') ? true : false); + $GLOBALS[__FUNCTION__][$str] = ($strTrimmed == 'true'); } // END - if // Return cache