X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=2a74c533cf6beaaa92d10b48105ee7fbd8ec10fa;hb=596c8ab32594401ca84abfbfe35513ddfff31bec;hp=2afef01eabf53df9410f4f2497abf5c523f16a08;hpb=d3ea83baa3f2607db46c26f7d8527c84b994f116;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 2afef01eab..2a74c533cf 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -64,7 +64,7 @@ function addFatalMessage ($F, $L, $message, $extra = '') { array_push($GLOBALS['fatal_messages'], $message); // Log fatal messages away - logDebugMessage($F, $L, 'Fatal error message: ' . $message); + logDebugMessage($F, $L, 'Fatal error message: ' . compileCode($message)); } // Getter for total fatal message count @@ -72,7 +72,7 @@ function getTotalFatalErrors () { // Init count $count = '0'; - // Do we have at least the first entry? + // Is there at least the first entry? if (!empty($GLOBALS['fatal_messages'][0])) { // Get total count $count = count($GLOBALS['fatal_messages']); @@ -192,7 +192,7 @@ function translateYesNo ($yn) { // Translates the american decimal dot into a german comma // OPPOMENT: convertCommaToDot() -function translateComma ($dotted, $cut = true, $max = '0') { +function translateComma ($dotted, $cut = TRUE, $max = '0') { // First, cast all to double, due to PHP changes $dotted = (double) $dotted; @@ -210,7 +210,7 @@ function translateComma ($dotted, $cut = true, $max = '0') { } // END - if // Cut zeros off? - if (($cut === true) && ($max == '0')) { + if (($cut === TRUE) && ($max == '0')) { // Test for commata if in cut-mode $com = explode('.', $dotted); if (count($com) < 2) { @@ -306,7 +306,7 @@ function translateMenuVisibleLocked ($content, $prefix = '') { break; default: // Please report this - reportBug(__FUNCTION__, __LINE__, 'Unsupported visible value detected. content=
' . print_r($content, true) . '
'); + reportBug(__FUNCTION__, __LINE__, 'Unsupported visible value detected. content=
' . print_r($content, TRUE) . '
'); break; } // END - switch @@ -321,7 +321,7 @@ function translateMenuVisibleLocked ($content, $prefix = '') { break; default: // Please report this - reportBug(__FUNCTION__, __LINE__, 'Unsupported locked value detected. content=
' . print_r($content, true) . '
'); + reportBug(__FUNCTION__, __LINE__, 'Unsupported locked value detected. content=
' . print_r($content, TRUE) . '
'); break; } // END - switch @@ -330,11 +330,17 @@ function translateMenuVisibleLocked ($content, $prefix = '') { } // Generates an URL for the dereferer -function generateDerefererUrl ($url) { +function generateDereferrerUrl ($url) { // Don't de-refer our own links! if (substr($url, 0, strlen(getUrl())) != getUrl()) { - // De-refer this link - $url = '{%url=modules.php?module=loader&url=' . encodeString(compileUriCode($url)) . '%}'; + // Encode URL + $encodedUrl = encodeString(compileUriCode($url)); + + // Log plain URL + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url); + + // De-refer this URL + $url = '{%url=modules.php?module=loader&url=' . $encodedUrl . '&hash=' . encodeHashForCookie(generateHash($url)) . '%}'; } // END - if // Return link @@ -395,7 +401,7 @@ function makeTime ($hours, $minutes, $seconds, $stamp) { } // Redirects to an URL and if neccessarry extends it with own base URL -function redirectToUrl ($url, $allowSpider = true) { +function redirectToUrl ($url, $allowSpider = TRUE) { // Is the output mode -2? if (isAjaxOutputMode()) { // This is always (!) an AJAX request and shall not be redirected @@ -413,7 +419,7 @@ function redirectToUrl ($url, $allowSpider = true) { // Default 'rel' value is external, nofollow is evil from Google and hurts the Internet $rel = ' rel="external"'; - // Do we have internal or external URL? + // Is there internal or external URL? if (substr($url, 0, strlen(getUrl())) == getUrl()) { // Own (=internal) URL $rel = ''; @@ -427,11 +433,11 @@ function redirectToUrl ($url, $allowSpider = true) { // We should not sent a redirect if headers are already sent if (!headers_sent()) { // Load URL when headers are not sent - sendRawRedirect(doFinalCompilation(str_replace('&', '&', $url), false)); + sendRawRedirect(doFinalCompilation(str_replace('&', '&', $url), FALSE)); } else { // Output error message loadInclude('inc/header.php'); - loadTemplate('redirect_url', false, str_replace('&', '&', $url)); + loadTemplate('redirect_url', FALSE, str_replace('&', '&', $url)); loadInclude('inc/footer.php'); } @@ -448,26 +454,26 @@ function redirectToUrl ($url, $allowSpider = true) { * $a_sort - Array, das die Sortiereihenfolge der ersten Elementeben * * $primary_key - Primaerschl.ssel aus $a_sort, nach dem sortiert wird * * $order - Sortiereihenfolge: -1 = a-Z, 0 = keine, 1 = Z-a * - * $nums - true = Als Zahlen sortieren, false = Als Zeichen sortieren * + * $nums - TRUE = Als Zahlen sortieren, FALSE = Als Zeichen sortieren * * * * $a_sort muss Elemente enthalten, deren Wert Schluessel von $array * * sind... Klingt kompliziert, suchen Sie mal mein Beispiel, dann sehen * * Sie, dass es doch nicht so schwer ist! :-) * * * ************************************************************************/ -function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums = false) { +function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums = FALSE) { $temporaryArray = $array; while ($primary_key < count($a_sort)) { foreach ($temporaryArray[$a_sort[$primary_key]] as $key => $value) { foreach ($temporaryArray[$a_sort[$primary_key]] as $key2 => $value2) { - $match = false; - if ($nums === false) { + $match = FALSE; + if ($nums === FALSE) { // Sort byte-by-byte (also numbers will be interpreted as chars! E.g.: "9" > "10") - if (($key != $key2) && (strcmp(strtolower($temporaryArray[$a_sort[$primary_key]][$key]), strtolower($temporaryArray[$a_sort[$primary_key]][$key2])) == $order)) $match = true; + if (($key != $key2) && (strcmp(strtolower($temporaryArray[$a_sort[$primary_key]][$key]), strtolower($temporaryArray[$a_sort[$primary_key]][$key2])) == $order)) $match = TRUE; } elseif ($key != $key2) { // Sort numbers (E.g.: 9 < 10) - if (($temporaryArray[$a_sort[$primary_key]][$key] < $temporaryArray[$a_sort[$primary_key]][$key2]) && ($order == -1)) $match = true; - if (($temporaryArray[$a_sort[$primary_key]][$key] > $temporaryArray[$a_sort[$primary_key]][$key2]) && ($order == 1)) $match = true; + if (($temporaryArray[$a_sort[$primary_key]][$key] < $temporaryArray[$a_sort[$primary_key]][$key2]) && ($order == -1)) $match = TRUE; + if (($temporaryArray[$a_sort[$primary_key]][$key] > $temporaryArray[$a_sort[$primary_key]][$key2]) && ($order == 1)) $match = TRUE; } if ($match) { @@ -547,7 +553,9 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') { $len = $length; } // END - if - if ($len == '0') { + // Smaller 1 is not okay + if ($len < 1) { + // Fix it to 10 $len = 10; } // END - if @@ -559,19 +567,19 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') { } // Does only allow numbers -function bigintval ($num, $castValue = true, $abortOnMismatch = true) { +function bigintval ($num, $castValue = TRUE, $abortOnMismatch = TRUE) { //* DEBUG: */ debugOutput('[' . __FUNCTION__ . ':' . __LINE__ . '] ' . 'num=' . $num . ',castValue=' . intval($castValue) . ',abortOnMismatch=' . intval($abortOnMismatch) . ' - ENTERED!'); // Filter all numbers out $ret = preg_replace('/[^0123456789]/', '', $num); // Shall we cast? - if ($castValue === true) { + if ($castValue === TRUE) { // Cast to biggest numeric type $ret = (double) $ret; } // END - if // Has the whole value changed? - if (('' . $ret . '' != '' . $num . '') && ($abortOnMismatch === true) && (!is_null($num))) { + if (('' . $ret . '' != '' . $num . '') && ($abortOnMismatch === TRUE) && (!is_null($num))) { // Log the values reportBug(__FUNCTION__, __LINE__, 'Problem with number found. ret[' . gettype($ret) . ']=' . $ret . ', num[' . gettype($num) . ']='. $num); } // END - if @@ -586,7 +594,7 @@ function createEpocheTimeFromSelections ($prefix, $postData) { // Initial return value $ret = '0'; - // Do we have a leap year? + // Is there a leap year? $SWITCH = '0'; $TEST = getYear() / 4; $M1 = getMonth(); @@ -624,7 +632,7 @@ function createEpocheTimeFromSelections ($prefix, $postData) { // Creates a 'fancy' human-readable timestamp from a Uni* stamp function createFancyTime ($stamp) { // Get data array with years/months/weeks/days/... - $data = createTimeSelections($stamp, '', '', '', true); + $data = createTimeSelections($stamp, '', '', '', TRUE); $ret = ''; foreach ($data as $k => $v) { if ($v > 0) { @@ -634,7 +642,7 @@ function createFancyTime ($stamp) { } // END - if } // END - foreach - // Do we have something there? + // Is something there? if (strlen($ret) > 0) { // Remove leading commata and space $ret = substr($ret, 2); @@ -672,21 +680,21 @@ function isEmailValid ($email) { } // Function taken from user comments on www.php.net / function isInStringIgnoreCase() -function isUrlValid ($url, $compile = true) { +function isUrlValid ($url, $compile = TRUE) { // Trim URL a little $url = trim(urldecode($url)); //* DEBUG: */ debugOutput($url); // Compile some chars out... - if ($compile === true) { - $url = compileUriCode($url, false, false, false); + if ($compile === TRUE) { + $url = compileUriCode($url, FALSE, FALSE, FALSE); } // END - if //* DEBUG: */ debugOutput($url); // Check for the extension filter if (isExtensionActive('filter')) { // Use the extension's filter set - return FILTER_VALIDATE_URL($url, false); + return FILTER_VALIDATE_URL($url, FALSE); } // END - if /* @@ -697,7 +705,7 @@ function isUrlValid ($url, $compile = true) { } // Generate a hash for extra-security for all passwords -function generateHash ($plainText, $salt = '', $hash = true) { +function generateHash ($plainText, $salt = '', $hash = TRUE) { // Debug output //* DEBUG: */ debugOutput('plainText('.strlen($plainText).')=' . $plainText . ',salt('.strlen($salt).')=' . $salt . ',hash=' . intval($hash)); @@ -705,7 +713,7 @@ function generateHash ($plainText, $salt = '', $hash = true) { // 123 4 43 3 4 432 2 3 32 2 3 32 2 3 3 21 if (((isExtensionInstalledAndOlder('sql_patches', '0.3.6')) && (empty($salt))) || (!isExtensionActive('sql_patches')) || (!isExtensionInstalledAndNewer('other', '0.2.5')) || (strlen($salt) == 32)) { // Extension ext-sql_patches is missing/outdated so we hash the plain text with MD5 - if ($hash === true) { + if ($hash === TRUE) { // Is plain password return md5($plainText); } else { @@ -714,7 +722,7 @@ function generateHash ($plainText, $salt = '', $hash = true) { } } // END - if - // Do we miss an arry element here? + // Is an arry element missing here? if (!isConfigEntrySet('file_hash')) { // Stop here reportBug(__FUNCTION__, __LINE__, 'Missing file_hash in ' . __FUNCTION__ . '.'); @@ -729,7 +737,7 @@ function generateHash ($plainText, $salt = '', $hash = true) { $keys = getSiteKey() . getEncryptSeparator() . getDateKey() . getEncryptSeparator() . getSecretKey() . getEncryptSeparator() . getFileHash() . getEncryptSeparator() . getDateFromRepository() . getEncryptSeparator() . getMasterSalt(); // Additional data - $data = $plainText . getEncryptSeparator() . uniqid(mt_rand(), true) . getEncryptSeparator() . time(); + $data = $plainText . getEncryptSeparator() . uniqid(mt_rand(), TRUE) . getEncryptSeparator() . time(); // Calculate number for generating the code $a = time() + getConfig('_ADD') - 1; @@ -925,7 +933,7 @@ function getCurrentTheme () { // The default theme is 'default'... ;-) $ret = 'default'; - // Do we have ext-theme installed and active or is 'theme' in URL or POST data? + // Is there ext-theme installed and active or is 'theme' in URL or POST data? if (isExtensionActive('theme')) { // Call inner method $ret = getActualTheme(); @@ -1012,7 +1020,7 @@ function debug_get_mailable_backtrace () { // Generates a ***weak*** seed function generateSeed () { - return microtime(true) * 100000; + return microtime(TRUE) * 100000; } // Converts a message code to a human-readable message @@ -1063,7 +1071,7 @@ function getMessageFromErrorCode ($code) { case getCode('LOGIN_EMPTY_PASSWORD'): $message = '{--LOGIN_PASSWORD_IS_EMPTY--}'; break; case getCode('ERROR_MAILID'): - if (isExtensionActive('mailid', true)) { + if (isExtensionActive('mailid', TRUE)) { $message = '{--ERROR_CONFIRMING_MAIL--}'; } else { $message = '{%pipe,generateExtensionInactiveNotInstalledMessage=mailid%}'; @@ -1102,7 +1110,7 @@ function getMessageFromErrorCode ($code) { $content['seconds'] = round(getUrlTlock() - $content['hours'] * 60 * 60 - $content['minutes'] * 60); // Finally contruct the message - $message = loadTemplate('tlock_message', true, $content); + $message = loadTemplate('tlock_message', TRUE, $content); break; default: @@ -1161,7 +1169,7 @@ function isUrlValidSimple ($url) { $pattern['ipg12'] = $http . $ip . $getstring1; // Test all patterns - $reg = false; + $reg = FALSE; foreach ($pattern as $key => $pat) { // Debug regex? if (isDebugRegularExpressionEnabled()) { @@ -1175,7 +1183,7 @@ function isUrlValidSimple ($url) { $reg = ($reg || preg_match(('^' . $pat . '^'), $url)); // Does it match? - if ($reg === true) { + if ($reg === TRUE) { break; } // END - if } // END - foreach @@ -1189,10 +1197,10 @@ function isUrlValidSimple ($url) { // @TODO Rewrite this function to use readFromFile() and writeToFile() function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) { // Initialize some variables - $done = false; + $done = FALSE; $seek++; $next = -1; - $found = false; + $found = FALSE; // Is the file there and read-/write-able? if ((isFileReadable($FQFN)) && (is_writeable($FQFN))) { @@ -1210,7 +1218,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 // Is the resource again valid? if (is_resource($fp_tmp)) { // Mark temporary file as readable - $GLOBALS['file_readable'][$tmp] = true; + $GLOBALS['file_readable'][$tmp] = TRUE; // Start reading while (!feof($fp)) { @@ -1219,7 +1227,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 if (isInString($search, $line)) { $next = '0'; - $found = true; + $found = TRUE; } // END - if if ($next > -1) { @@ -1239,17 +1247,17 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 fclose($fp_tmp); // Finished writing tmp file - $done = true; + $done = TRUE; } // END - if // Close source file fclose($fp); - if (($done === true) && ($found === true)) { + if (($done === TRUE) && ($found === TRUE)) { // Copy back tmp file and delete tmp :-) copyFileVerified($tmp, $FQFN, 0644); return removeFile($tmp); - } elseif ($found === false) { + } elseif ($found === FALSE) { outputHtml('CHANGE: 404!'); } else { outputHtml('TMP: UNDONE!'); @@ -1261,18 +1269,18 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 } // An error was detected! - return false; + return FALSE; } // Debug message logger function logDebugMessage ($funcFile, $line, $message, $force=true) { // Is debug mode enabled? - if ((isDebugModeEnabled()) || ($force === true)) { + if ((isDebugModeEnabled()) || ($force === TRUE)) { // Remove CRLF $message = str_replace(array(chr(13), chr(10)), 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) . '|' . basename($funcFile) . '|' . $line . '|' . $message); } // END - if } @@ -1281,12 +1289,12 @@ function handleExtraValues ($filterFunction, $value, $extraValue) { // Default is the value itself $ret = $value; - // Do we have a special filter function? + // Is there a special filter function? if (!empty($filterFunction)) { // Does the filter function exist? if (function_exists($filterFunction)) { - // Do we have extra parameters here? - if (!empty($extraValue)) { + // Is there extra parameters here? + if ((!is_null($extraValue)) && (!empty($extraValue))) { // Put both parameters in one new array by default $args = array($value, $extraValue); @@ -1298,9 +1306,22 @@ function handleExtraValues ($filterFunction, $value, $extraValue) { // Call the multi-parameter call-back $ret = call_user_func_array($filterFunction, $args); + + // Is $ret 'true'? + if ($ret === TRUE) { + // Test passed, so write direct value + $ret = $args; + } // END - if } else { // One parameter call $ret = call_user_func($filterFunction, $value); + //* BUG */ die('ret['.gettype($ret).']=' . $ret . ',value=' . $value.',filterFunction=' . $filterFunction); + + // Is $ret 'true'? + if ($ret === TRUE) { + // Test passed, so write direct value + $ret = $value; + } // END - if } } // END - if } // END - if @@ -1312,7 +1333,7 @@ function handleExtraValues ($filterFunction, $value, $extraValue) { // Converts timestamp selections into a timestamp function convertSelectionsToEpocheTime (array &$postData, array &$content, &$id, &$skip) { // Init test variable - $skip = false; + $skip = FALSE; $test2 = ''; // Get last three chars @@ -1326,7 +1347,7 @@ function convertSelectionsToEpocheTime (array &$postData, array &$content, &$id, // Generate timestamp $postData[$test] = createEpocheTimeFromSelections($test, $postData); array_push($content, sprintf("`%s`='%s'", $test, $postData[$test])); - $GLOBALS['skip_config'][$test] = true; + $GLOBALS['skip_config'][$test] = TRUE; // Remove data from array foreach (array('ye', 'mo', 'we', 'da', 'ho', 'mi', 'se') as $rem) { @@ -1335,7 +1356,7 @@ function convertSelectionsToEpocheTime (array &$postData, array &$content, &$id, // Skip adding unset($id); - $skip = true; + $skip = TRUE; $test2 = $test; } // END - if } // END - if @@ -1345,7 +1366,7 @@ function convertSelectionsToEpocheTime (array &$postData, array &$content, &$id, // OPPOMENT: translateComma() function convertCommaToDot ($str) { // Default float is not a float... ;-) - $float = false; + $float = FALSE; // Which language is selected? switch (getLanguage()) { @@ -1354,12 +1375,12 @@ function convertCommaToDot ($str) { $str = str_replace('.', '', $str); // Replace german commata with decimal dot and cast it - $float = (float)str_replace(',', '.', $str); + $float = (float) str_replace(',', '.', $str); break; default: // US and so on // Remove thousand commatas first and cast - $float = (float)str_replace(',', '', $str); + $float = (float) str_replace(',', '', $str); break; } // END - switch @@ -1384,7 +1405,7 @@ function handleLoginFailures ($accessLevel) { ); // Load template - $OUT = loadTemplate('login_failures', true, $content); + $OUT = loadTemplate('login_failures', TRUE, $content); } // END - if // Reset session data @@ -1397,12 +1418,12 @@ function handleLoginFailures ($accessLevel) { } // Rebuild cache -function rebuildCache ($cache, $inc = '', $force = false) { +function rebuildCache ($cache, $inc = '', $force = FALSE) { // Debug message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force))); // Shall I remove the cache file? - if (isCacheInstanceValid()) { + if ((isExtensionInstalled('cache')) && (isCacheInstanceValid())) { // Rebuild cache if ($GLOBALS['cache_instance']->loadCacheFile($cache)) { // Destroy it @@ -1428,7 +1449,7 @@ function rebuildCache ($cache, $inc = '', $force = false) { } // Determines the real remote address -function determineRealRemoteAddress ($remoteAddr = false) { +function determineRealRemoteAddress ($remoteAddr = FALSE) { // Default is 127.0.0.1 $address = '127.0.0.1'; @@ -1456,7 +1477,7 @@ function determineRealRemoteAddress ($remoteAddr = false) { // Adds a bonus mail to the queue // This is a high-level function! -function addNewBonusMail ($data, $mode = '', $output = true) { +function addNewBonusMail ($data, $mode = '', $output = TRUE) { // Use mode from data if not set and availble ;-) if ((empty($mode)) && (isset($data['mail_mode']))) { $mode = $data['mail_mode']; @@ -1481,10 +1502,10 @@ function addNewBonusMail ($data, $mode = '', $output = true) { ); // Mail inserted into bonus pool - if ($output === true) { + if ($output === TRUE) { displayMessage('{--ADMIN_BONUS_SEND--}'); } // END - if - } elseif ($output === true) { + } elseif ($output === TRUE) { // More entered than can be reached! displayMessage('{--ADMIN_MORE_SELECTED--}'); } else { @@ -1496,7 +1517,7 @@ function addNewBonusMail ($data, $mode = '', $output = true) { // Enables the reset mode and runs it function doReset () { // Enable the reset mode - $GLOBALS['reset_enabled'] = true; + $GLOBALS['reset_enabled'] = TRUE; // Run filters runFilterChain('reset'); @@ -1505,7 +1526,7 @@ function doReset () { // Enables the reset mode (hourly, weekly and monthly) and runs it function doHourly () { // Enable the hourly reset mode - $GLOBALS['hourly_enabled'] = true; + $GLOBALS['hourly_enabled'] = TRUE; // Run filters (one always!) runFilterChain('hourly'); @@ -1603,7 +1624,7 @@ function isExtraTitleSet () { * @param $suffix Suffix for positive matches ($extension will be appended, too) * @return $foundMatches All found positive matches for above criteria */ -function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $addBaseDir = true, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = true, $suffix = '') { +function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '') { // Add default entries we should always exclude array_unshift($excludeArray, '.', '..', '.svn', '.htaccess'); @@ -1617,7 +1638,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad // Read all entries while ($baseFile = readdir($dirPointer)) { // Exclude '.', '..' and entries in $excludeArray automatically - if (in_array($baseFile, $excludeArray, true)) { + if (in_array($baseFile, $excludeArray, TRUE)) { // Exclude them //* DEBUG: */ debugOutput('excluded=' . $baseFile); continue; @@ -1640,7 +1661,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad } // END - if // Skip also files with non-matching prefix genericly - if (($recursive === true) && (isDirectory($FQFN))) { + if (($recursive === TRUE) && (isDirectory($FQFN))) { // Is a redirectory so read it as well $foundMatches = merge_array($foundMatches, getArrayFromDirectory($baseDir . $baseFile . '/', $prefix, $fileIncludeDirs, $addBaseDir, $excludeArray, $extension, $excludePattern, $recursive)); @@ -1672,14 +1693,14 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad // Is the file a PHP script or other? //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'baseDir=' . $baseDir . ',prefix=' . $prefix . ',baseFile=' . $baseFile); - if (($fileExtension == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) { + if (($fileExtension == '.php') || (($fileIncludeDirs === TRUE) && (isDirectory($FQFN)))) { // Is this a valid include file? if ($extension == '.php') { // Remove both for extension name $extName = substr($baseFile, strlen($prefix), -4); // Add file with or without base path - if ($addBaseDir === true) { + if ($addBaseDir === TRUE) { // With base path array_push($foundMatches, $fileName); } else { @@ -1734,14 +1755,14 @@ function mapModuleToTable ($moduleName) { // Add SQL debug data to array for later output function addSqlToDebug ($result, $sqlString, $timing, $F, $L) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS['debug_sql_available'])) { // Check it and cache it in $GLOBALS $GLOBALS['debug_sql_available'] = ((isConfigurationLoaded()) && (isDisplayDebugSqlEnabled())); } // END - if // Don't execute anything here if we don't need or ext-other is missing - if ($GLOBALS['debug_sql_available'] === false) { + if ($GLOBALS['debug_sql_available'] === FALSE) { return; } // END - if @@ -1752,7 +1773,7 @@ function addSqlToDebug ($result, $sqlString, $timing, $F, $L) { } // END - if // Remeber this as profiled (or not, but we don't care here) - $GLOBALS['debug_sqls'][$F][$L][$sqlString] = true; + $GLOBALS['debug_sqls'][$F][$L][$sqlString] = TRUE; // Generate record $record = array( @@ -1837,14 +1858,14 @@ function getModuleFromFileName ($file, $accessLevel) { // Encodes an URL for adding session id, etc. function encodeUrl ($url, $outputMode = '0') { - // Do we have already have a PHPSESSID inside or view.php is called? Then abort here + // Is there already have a PHPSESSID inside or view.php is called? Then abort here if ((isInStringIgnoreCase(session_name(), $url)) || (isRawOutputMode())) { // Raw output mode detected or session_name() found in URL return $url; } // END - if - // Do we have a valid session? - if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === false) || (!isset($_COOKIE[session_name()]))) && (isSpider() === false)) { + // Is there a valid session? + if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === FALSE) || (!isset($_COOKIE[session_name()]))) && (isSpider() === FALSE)) { // Determine right separator $separator = '&'; if (!isInString('?', $url)) { @@ -1864,7 +1885,7 @@ function encodeUrl ($url, $outputMode = '0') { $url = '{?URL?}/' . $url; } // END - if - // Do we have to decode entities? + // Is there to decode entities? if ((!isHtmlOutputMode()) || ($outputMode != '0')) { // Decode them for e.g. JavaScript parts $url = decodeEntities($url); @@ -1880,12 +1901,12 @@ function encodeUrl ($url, $outputMode = '0') { // Simple check for spider function isSpider () { // Get the UA and trim it down - $userAgent = trim(detectUserAgent(true)); + $userAgent = trim(detectUserAgent(TRUE)); // It should not be empty, if so it is better a spider/bot if (empty($userAgent)) { // It is a spider/bot - return true; + return TRUE; } // END - if // Is it a spider? @@ -1900,7 +1921,7 @@ function searchDirsRecursive ($dir, &$last_changed, $lookFor = 'Date') { // RegexPattern to exclude ., .., .revision, .svn, debug.log or .cache in the filenames $excludePattern = '@(\.revision|\.svn|debug\.log|\.cache|config\.php)$@'; - $ds = getArrayFromDirectory($dir, '', false, true, array(), '.php', $excludePattern); + $ds = getArrayFromDirectory($dir, '', FALSE, TRUE, array(), '.php', $excludePattern); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count(ds)='.count($ds)); // Walk through all entries @@ -1988,7 +2009,7 @@ function convertNullToZero ($number) { // Capitalizes a string with underscores, e.g.: some_foo_string will become SomeFooString // Note: This function is cached function capitalizeUnderscoreString ($str) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$str])) { // Init target string $capitalized = ''; @@ -2040,14 +2061,14 @@ function generateAdminMailLinks ($mailType, $mailId) { // Is the mail type supported? if (!empty($table)) { // Query for the mail - $result = SQL_QUERY_ESC("SELECT `id`,`%s` AS `mail_status` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `id`=%s LIMIT 1", + $result = SQL_QUERY_ESC("SELECT `id`, `%s` AS `mail_status` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `id`=%s LIMIT 1", array( $statusColumn, $table, bigintval($mailId) ), __FILE__, __LINE__); - // Do we have one entry there? + // Is there one entry there? if (SQL_NUMROWS($result) == 1) { // Load the entry $content = SQL_FETCHARRAY($result); @@ -2127,7 +2148,7 @@ function detectMultiBytePrefix ($str) { $mbPrefix = ''; // Detect multi-byte (strictly) - if (mb_detect_encoding($str, 'auto', true) !== false) { + if (mb_detect_encoding($str, 'auto', TRUE) !== FALSE) { // With multi-byte encoded string $mbPrefix = 'mb_'; } // END - if @@ -2143,9 +2164,9 @@ function getArrayKeysFromSubStrArray ($heystack, $needles, $offset = 0) { // Now check all entries foreach ($needles as $key => $needle) { - // Do we have found a partial string? + // Is there found a partial string? //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'heystack='.$heystack.',key='.$key.',needle='.$needle.',offset='.$offset); - if (strpos($heystack, $needle, $offset) !== false) { + if (strpos($heystack, $needle, $offset) !== FALSE) { // Add the found key array_push($keys, $key); } // END - if @@ -2162,7 +2183,7 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) { $pointsColumn = 'points'; // Which points, locked or normal? - if ($locked === true) { + if ($locked === TRUE) { $pointsColumn = 'locked_points'; } // END - if @@ -2188,7 +2209,7 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) { function convertBooleanToYesNo ($boolean) { // Default is 'N' $converted = 'N'; - if ($boolean === true) { + if ($boolean === TRUE) { // Set 'Y' $converted = 'Y'; } // END - if @@ -2202,7 +2223,7 @@ function convertStringToBoolean ($str) { // Debug message (to measure how often this function is called) //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'str=' . $str); - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$str])) { // Trim it lower-case for validation $strTrimmed = trim(strtolower($str)); @@ -2235,7 +2256,7 @@ function makeParseableVariable ($varString) { reportBug(__FUNCTION__, __LINE__, 'varString=' . $varString . ' - No dollar sign detected, will not parse it.'); } // END - if - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$varString])) { // Snap them in, if [,] are there $GLOBALS[__FUNCTION__][$varString] = str_replace(array('[', ']'), array("['", "']"), $varString); @@ -2262,6 +2283,136 @@ function removeDoubleDotFromSubject ($subject) { return $subject; } +// Adds a given entry to the database +function memberAddEntries ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $columnIndex = NULL) { + // Is it a member? + if (!isMember()) { + // Then abort here + return FALSE; + } // END - if + + // Set POST data generic userid + setPostRequestElement('userid', getMemberId()); + + // Call inner function + doGenericAddEntries($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $columnIndex); + + // Entry has been added? + if ((!SQL_HASZEROAFFECTED()) && ($GLOBALS['__XML_PARSE_RESULT'] === TRUE)) { + // Display success message + displayMessage('{--MEMBER_ENTRY_ADDED--}'); + } else { + // Display failed message + displayMessage('{--MEMBER_ENTRY_NOT_ADDED--}'); + } +} + +// Edit rows by given id numbers +function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) { + // $tableName must be an array + if ((!is_array($tableName)) || (count($tableName) != 1)) { + // No tableName specified + reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($idColumn)) { + // $idColumn is no array + reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($userIdColumn)) { + // $userIdColumn is no array + reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($editNow)) { + // $editNow is no array + reportBug(__FUNCTION__, __LINE__, 'editNow[]=' . gettype($editNow) . '!=array: userIdColumn=' . $userIdColumn); + } // END - if + + // Shall we change here or list for editing? + if ($editNow[0] === TRUE) { + // Add generic userid field + setPostRequestElement('userid', getMemberId()); + + // Call generic change method + $affected = doGenericEditEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $timeColumns, $editNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles, 'mem_edit'); + + // Was this fine? + if ($affected == countPostSelection($idColumn[0])) { + // All deleted + displayMessage('{--MEMBER_ALL_ENTRIES_EDITED--}'); + } else { + // Some are still there :( + displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_EDITED'), $affected, countPostSelection($idColumn[0]))); + } + } else { + // List for editing + memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn); + } +} + +// Delete rows by given id numbers +function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) { + // Do this only for members + assert(isMember()); + + // $tableName must be an array + if ((!is_array($tableName)) || (count($tableName) != 1)) { + // No tableName specified + reportBug(__FUNCTION__, __LINE__, 'tableName is not given. Please fix your XML,tableName[]=' . gettype($tableName) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($idColumn)) { + // $idColumn is no array + reportBug(__FUNCTION__, __LINE__, 'idColumn[]=' . gettype($idColumn) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($userIdColumn)) { + // $userIdColumn is no array + reportBug(__FUNCTION__, __LINE__, 'userIdColumn[]=' . gettype($userIdColumn) . '!=array: userIdColumn=' . $userIdColumn); + } elseif (!is_array($deleteNow)) { + // $deleteNow is no array + reportBug(__FUNCTION__, __LINE__, 'deleteNow[]=' . gettype($deleteNow) . '!=array: userIdColumn=' . $userIdColumn); + } // END - if + + // Shall we delete here or list for deletion? + if ($deleteNow[0] === TRUE) { + // Add generic userid field + setPostRequestElement('userid', getMemberId()); + + // Call generic function + $affected = doGenericDeleteEntriesConfirm($tableName, $columns, $filterFunctions, $extraValues, $deleteNow, $idColumn, $userIdColumn, $rawUserId, $cacheFiles, 'mem_delete'); + + // Was this fine? + if ($affected == countPostSelection($idColumn[0])) { + // All deleted + displayMessage('{--MEMBER_ALL_ENTRIES_REMOVED--}'); + } else { + // Some are still there :( + displayMessage(sprintf(getMessage('MEMBER_SOME_ENTRIES_NOT_DELETED'), SQL_AFFECTEDROWS(), countPostSelection($idColumn[0]))); + } + } else { + // List for deletion confirmation + memberListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn); + } +} + +// Build a special template list +function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid')) { + // Do this only for logged in member + assert(isMember()); + + // Call inner (general) function + doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId); +} + +// Checks whether given address is IPv4 +function isIp4AddressValid ($address) { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__][$address])) { + // Determine it ... + $GLOBALS[__FUNCTION__][$address] = preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]))/', $address); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$address]; +} + +// ---------------------------------------------------------------------------- +// "Translatation" functions for points_data table +// ---------------------------------------------------------------------------- + // Translates generically some data into a target string function translateGeneric ($messagePrefix, $data) { // Is the method null or empty? @@ -2289,16 +2440,6 @@ function translateGeneric ($messagePrefix, $data) { return $return; } -// Translates task type to a human-readable version -function translateTaskType ($taskType) { - // Return it - return translateGeneric('ADMIN_TASK_TYPE', $taskType); -} - -// ---------------------------------------------------------------------------- -// "Translatation" functions for points_data table -// ---------------------------------------------------------------------------- - // Translates points subject to human-readable function translatePointsSubject ($subject) { // Remove any :x @@ -2338,6 +2479,12 @@ function translatePointsNotifyRecipient ($notifyRecipient) { return translateGeneric('POINTS_NOTIFY_RECIPIENT', $notifyRecipient); } +// Translates task type to a human-readable version +function translateTaskType ($taskType) { + // Return it + return translateGeneric('ADMIN_TASK_TYPE', $taskType); +} + //----------------------------------------------------------------------------- // Automatically re-created functions, all taken from user comments on www.php.net //-----------------------------------------------------------------------------