X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=faecd19e7d1811d8ed10f2eacb03232503f0e332;hb=60822fcfed13786d1e7d86b10faecda6d2195def;hp=321eddfaf5b202ee83831f3d022567d043277528;hpb=74a607e3879faefdc2ca152605cb533806b98e83;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 321eddfaf5..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; } @@ -89,27 +91,29 @@ function generatePassword ($length = '0', $exclude = array()) { $length = getPassLen(); } // END - if - // Initialize array with all allowed chars - $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/,.'); - // Exclude some entries - $ABC = array_diff($ABC, $exclude); + $localAbc = array_diff($GLOBALS['_abc'], $exclude); + + // $localAbc must have at least 10 entries + assert(count($localAbc) >= 10); // Start creating password - $PASS = ''; - for ($i = '0'; $i < $length; $i++) { - $PASS .= $ABC[mt_rand(0, count($ABC) -1)]; - } // END - for + $password = ''; + while (strlen($password) < $length) { + $password .= $localAbc[mt_rand(0, count($localAbc) -1)]; + } // END - while - // When the size is below 40 we can also add additional security by scrambling - // it. Otherwise we may corrupt hashes - if (strlen($PASS) <= 40) { + /* + * When the size is below 40 we can also add additional security by + * scrambling it. Otherwise the hash may corrupted.. + */ + if (strlen($password) <= 40) { // Also scramble the password - $PASS = scrambleString($PASS); + $password = scrambleString($password); } // END - if // Return the password - return $PASS; + return $password; } // Generates a human-readable timestamp from the Uni* stamp @@ -332,15 +336,18 @@ function translateMenuVisibleLocked ($content, $prefix = '') { // Generates an URL for the dereferer function generateDereferrerUrl ($url) { // Don't de-refer our own links! - if (substr($url, 0, strlen(getUrl())) != getUrl()) { + if ((!empty($url)) && (substr($url, 0, strlen(getUrl())) != getUrl())) { // Encode URL $encodedUrl = encodeString(compileUriCode($url)); - // Log plain URL - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url); + // Generate hash + $hash = generateHash($url . getSiteKey() . getDateKey()); + + // Log plain URL and hash + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url . ',hash=' . $hash . '(' . strlen($hash) . ')'); // De-refer this URL - $url = '{%url=modules.php?module=loader&url=' . $encodedUrl . '&hash=' . encodeHashForCookie(generateHash($url)) . '%}'; + $url = '{%url=modules.php?module=loader&url=' . $encodedUrl . '&hash=' . encodeHashForCookie($hash) . '&salt=' . substr($hash, 0, getSaltLength()) . '%}'; } // END - if // Return link @@ -643,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 { @@ -707,7 +714,7 @@ function isUrlValid ($url, $compile = TRUE) { // Generate a hash for extra-security for all passwords function generateHash ($plainText, $salt = '', $hash = TRUE) { // Debug output - //* DEBUG: */ debugOutput('plainText('.strlen($plainText).')=' . $plainText . ',salt('.strlen($salt).')=' . $salt . ',hash=' . intval($hash)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'plainText('.strlen($plainText).')=' . $plainText . ',salt('.strlen($salt).')=' . $salt . ',hash=' . intval($hash)); // Is the required extension 'sql_patches' there and a salt is not given? // 123 4 43 3 4 432 2 3 32 2 3 32 2 3 3 21 @@ -744,20 +751,20 @@ function generateHash ($plainText, $salt = '', $hash = TRUE) { // Generate SHA1 sum from modula of number and the prime number $sha1 = sha1(($a % getPrime()) . $server . getEncryptSeparator() . $keys . getEncryptSeparator() . $data . getEncryptSeparator() . getDateKey() . getEncryptSeparator() . $a); - //* DEBUG: */ debugOutput('SHA1=' . $sha1.' ('.strlen($sha1).')
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SHA1=' . $sha1.' ('.strlen($sha1).')'); $sha1 = scrambleString($sha1); - //* DEBUG: */ debugOutput('Scrambled=' . $sha1.' ('.strlen($sha1).')
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Scrambled=' . $sha1.' ('.strlen($sha1).')'); //* DEBUG: */ $sha1b = descrambleString($sha1); - //* DEBUG: */ debugOutput('Descrambled=' . $sha1b.' ('.strlen($sha1b).')
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Descrambled=' . $sha1b.' ('.strlen($sha1b).')'); // Generate the password salt string $salt = substr($sha1, 0, getSaltLength()); - //* DEBUG: */ debugOutput($salt.' ('.strlen($salt).')
'); + //* DEBUG: */ debugOutput($salt.' ('.strlen($salt).')'); } else { // Use given salt - //* DEBUG: */ debugOutput('salt=' . $salt); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt=' . $salt); $salt = substr($salt, 0, getSaltLength()); - //* DEBUG: */ debugOutput('salt=' . $salt . '(' . strlen($salt) . '/' . getSaltLength() . ')
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt=' . $salt . '(' . strlen($salt) . '/' . getSaltLength() . ')'); // Sanity check on salt if (strlen($salt) != getSaltLength()) { @@ -770,7 +777,7 @@ function generateHash ($plainText, $salt = '', $hash = TRUE) { $finalHash = $salt . sha1($salt . $plainText); // Debug output - //* DEBUG: */ debugOutput('finalHash('.strlen($finalHash).')=' . $finalHash); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'finalHash('.strlen($finalHash).')=' . $finalHash); // Return hash return $finalHash; @@ -794,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.'***
'); @@ -875,32 +884,39 @@ function encodeHashForCookie ($passHash) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '/' . strlen(getSecretKey())); if ((strlen($passHash) != 49) || (strlen(getSecretKey()) != 40)) { // Both keys must have same length so return unencrypted - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '!=49/' . strlen(getSecretKey()) . '!=40'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '!=49/' . strlen(getSecretKey()) . '!=40 - EXIT!'); return $ret; } // END - if $newHash = ''; $start = 9; //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'passHash=' . $passHash . '(' . strlen($passHash) . ')'); for ($idx = 0; $idx < 20; $idx++) { - $part1 = hexdec(substr($passHash, ($idx * 2) + (strlen($passHash) - strlen(getSecretKey())), 2)); + // Get hash parts and convert them (00-FF) to matching ASCII value (0-255) + $part1 = hexdec(substr($passHash , $start, 2)); $part2 = hexdec(substr(getSecretKey(), $start, 2)); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2); + + // Default is hexadecimal of index if both are same $mod = dechex($idx); + // Is part1 larger or part2 than its counter part? if ($part1 > $part2) { + // part1 is larger $mod = dechex(sqrt(($part1 - $part2) * getPrime() / pi())); } elseif ($part2 > $part1) { + // part2 is larger $mod = dechex(sqrt(($part2 - $part1) * getPrime() / pi())); } + $mod = substr($mod, 0, 2); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')'); - $mod = str_repeat(0, (2 - strlen($mod))) . $mod; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'idx=' . $idx . ',part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')'); + $mod = str_pad($mod, 2, '0', STR_PAD_LEFT); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*'); $start += 2; $newHash .= $mod; } // END - for - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $passHash . ',' . $newHash . ' (' . strlen($newHash) . ')'); - $ret = generateHash($newHash, getMasterSalt()); + // Just copy it over, as the master salt is not really helpful here + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $passHash . '(' . strlen($passHash) . '),' . $newHash . ' (' . strlen($newHash) . ')'); + $ret = $newHash; } // END - if // Return result @@ -1195,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++; @@ -1223,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'; @@ -1233,7 +1249,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 if ($next > -1) { if ($next === $seek) { $next = -1; - $line = $prefix . $inserted . $suffix . chr(10); + $line = $prefix . $inserted . $suffix . PHP_EOL; } else { $next++; } @@ -1254,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! @@ -1277,10 +1297,10 @@ function logDebugMessage ($funcFile, $line, $message, $force=true) { // Is debug mode enabled? if ((isDebugModeEnabled()) || ($force === TRUE)) { // Remove CRLF - $message = str_replace(array(chr(13), chr(10)), array('', ''), $message); + $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 } @@ -1290,46 +1310,115 @@ function handleExtraValues ($filterFunction, $value, $extraValue) { $ret = $value; // Is there a special filter function? - if (!empty($filterFunction)) { - // Does the filter function exist? - if (function_exists($filterFunction)) { - // Is there extra parameters here? - if ((!is_null($extraValue)) && (!empty($extraValue))) { - // Put both parameters in one new array by default - $args = array($value, $extraValue); - - // If we have an array simply use it and pre-extend it with our value - if (is_array($extraValue)) { - // Make the new args array - $args = merge_array(array($value), $extraValue); - } // END - if + if ((empty($filterFunction)) || (!function_exists($filterFunction))) { + // Call-back function does not exist or is empty + reportBug(__FUNCTION__, __LINE__, 'Filter function ' . $filterFunction . ' does not exist or is empty: value[' . gettype($value) . ']=' . $value . ',extraValue[' . gettype($extraValue) . ']=' . $extraValue); + } // END - if - // Call the multi-parameter call-back - $ret = call_user_func_array($filterFunction, $args); + // Is there extra parameters here? + if ((!is_null($extraValue)) && (!empty($extraValue))) { + // Put both parameters in one new array by default + $args = array($value, $extraValue); - // 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 - } + // If we have an array simply use it and pre-extend it with our value + if (is_array($extraValue)) { + // Make the new args array + $args = merge_array(array($value), $extraValue); } // END - if - } // END - if + + // 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 + } // Return the value return $ret; } +// Tries to determine if call-back functions and/or extra values shall be parsed +function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $userIdColumn, $search, $id = NULL) { + // Debug mode enabled? + if (isDebugModeEnabled()) { + // Debug message + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',entries=' . $entries . ',userIdColumn=' . $userIdColumn[0] . ',search=' . $search . ',filterFunctions=' . print_r($filterFunctions, TRUE) . ',extraValues=' . print_r($extraValues, TRUE)); + } // END - if + + // Send data through the filter function if found + 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[$key] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - BEFORE!'); + } // END - if + + // Filter function + extra value set + $entries = handleExtraValues($filterFunctions[$key], $entries, $extraValues[$key]); + + // Debug mode enabled? + if (isDebugModeEnabled()) { + // Then log it + /* 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()) { + // 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, NULL); + + // 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)); + } + + // Return value + return $entries; +} + // Converts timestamp selections into a timestamp function convertSelectionsToEpocheTime (array &$postData, array &$content, &$id, &$skip) { // Init test variable @@ -1423,8 +1512,8 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force))); // Shall I remove the cache file? - if ((isExtensionInstalled('cache')) && (isCacheInstanceValid())) { - // Rebuild cache + if ((isExtensionInstalled('cache')) && (isCacheInstanceValid()) && (isHtmlOutputMode())) { + // Rebuild cache only in HTML output-mode if ($GLOBALS['cache_instance']->loadCacheFile($cache)) { // Destroy it $GLOBALS['cache_instance']->removeCacheFile($force); @@ -1537,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()) { @@ -1745,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 @@ -1865,7 +1953,7 @@ function encodeUrl ($url, $outputMode = '0') { } // END - if // Is there a valid session? - if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === FALSE) || (!isset($_COOKIE[session_name()]))) && (isSpider() === FALSE)) { + if ((!isSessionValid()) && (!isSpider())) { // Determine right separator $separator = '&'; if (!isInString('?', $url)) { @@ -1873,10 +1961,8 @@ function encodeUrl ($url, $outputMode = '0') { $separator = '?'; } // END - if - // Add it to URL - if (session_id() != '') { - $url .= $separator . session_name() . '=' . session_id(); - } // END - if + // Then add it to URL + $url .= $separator . session_name() . '=' . session_id(); } // END - if // Add {?URL?} ? @@ -1885,10 +1971,15 @@ function encodeUrl ($url, $outputMode = '0') { $url = '{?URL?}/' . $url; } // END - if + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url . ',isHtmlOutputMode()=' . intval(isHtmlOutputMode()) . ',outputMode=' . $outputMode); + // Is there to decode entities? if ((!isHtmlOutputMode()) || ($outputMode != '0')) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url . ' - BEFORE DECODING'); // Decode them for e.g. JavaScript parts $url = decodeEntities($url); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url . ' - AFTER DECODING'); } // END - if // Debug log @@ -1903,10 +1994,10 @@ function isSpider () { // Get the UA and trim it down $userAgent = trim(detectUserAgent(TRUE)); - // It should not be empty, if so it is better a spider/bot + // It should not be empty, if so it is better a browser if (empty($userAgent)) { - // It is a spider/bot - return TRUE; + // It is a browser that blocks its UA string + return FALSE; } // END - if // Is it a spider? @@ -1994,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; @@ -2115,7 +2203,7 @@ function isHexadecimal ($hex) { } /** - * Replace chr(13) with "[r]" and chr(10) with "[n]" and add a final new-line to make + * Replace chr(13) with "[r]" and PHP_EOL with "[n]" and add a final new-line to make * them visible to the developer. Use this function to debug e.g. buggy HTTP * response handler functions. * @@ -2123,7 +2211,7 @@ function isHexadecimal ($hex) { * @return $str Overworked string */ function replaceReturnNewLine ($str) { - return str_replace(array(chr(13), chr(10)), array('[r]', '[n]'), $str); + return str_replace(array(chr(13), PHP_EOL), array('[r]', '[n]'), $str); } // Converts a given string by splitting it up with given delimiter similar to @@ -2157,7 +2245,7 @@ function detectMultiBytePrefix ($str) { return $mbPrefix; } -// Searches the given array for a sub-string match and returns all found keys in an array +// Searches given array for a sub-string match and returns all found keys in an array function getArrayKeysFromSubStrArray ($heystack, $needles, $offset = 0) { // Init array for all found keys $keys = array(); @@ -2235,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 @@ -2308,7 +2396,7 @@ function memberAddEntries ($tableName, $columns = array(), $filterFunctions = ar } // 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()) { +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(), $content = array()) { // $tableName must be an array if ((!is_array($tableName)) || (count($tableName) != 1)) { // No tableName specified @@ -2342,12 +2430,12 @@ function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFuncti } } else { // List for editing - memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn); + memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content); } } // 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()) { +function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array(), $content = array()) { // Do this only for members assert(isMember()); @@ -2384,17 +2472,18 @@ function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunc } } else { // List for deletion confirmation - memberListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn); + memberListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUSerId, $content); } } // Build a special template list -function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid')) { +// @TODO cacheFiles is not yet supported +function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid'), $content = array()) { // Do this only for logged in member assert(isMember()); // Call inner (general) function - doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId); + doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content); } // Checks whether given address is IPv4 @@ -2409,6 +2498,21 @@ function isIp4AddressValid ($address) { return $GLOBALS[__FUNCTION__][$address]; } +// Returns the string if not empty or FALSE if empty +function validateIsEmpty ($str) { + // Trim it + $trimmed = trim($str); + + // Is the string empty? + if (empty($trimmed)) { + // Then set FALSE + $str = FALSE; + } // END - if + + // Return it + return $str; +} + // ---------------------------------------------------------------------------- // "Translatation" functions for points_data table // ---------------------------------------------------------------------------- @@ -2449,37 +2553,43 @@ function translatePointsSubject ($subject) { return translateGeneric('POINTS_SUBJECT', $subject); } -// "Translates" the given points account type +// "Translates" given points account type function translatePointsAccountType ($accountType) { // Return it return translateGeneric('POINTS_ACCOUNT_TYPE', $accountType); } -// "Translates" the given points "locked mode" +// "Translates" given points "locked mode" function translatePointsLockedMode ($lockedMode) { // Return it return translateGeneric('POINTS_LOCKED_MODE', $lockedMode); } -// "Translates" the given points payment method +// "Translates" given points payment method function translatePointsPaymentMethod ($paymentMethod) { // Return it return translateGeneric('POINTS_PAYMENT_METHOD', $paymentMethod); } -// "Translates" the given points account provider +// "Translates" given points account provider function translatePointsAccountProvider ($accountProvider) { // Return it return translateGeneric('POINTS_ACCOUNT_PROVIDER', $accountProvider); } -// "Translates" the given points notify recipient +// "Translates" given points notify recipient function translatePointsNotifyRecipient ($notifyRecipient) { // Return it return translateGeneric('POINTS_NOTIFY_RECIPIENT', $notifyRecipient); } -// Translates task type to a human-readable version +// "Translates" given mode to a human-readable version +function translatePointsMode ($pointsMode) { + // Return it + return translateGeneric('POINTS_MODE', $pointsMode); +} + +// "Translates" task type to a human-readable version function translateTaskType ($taskType) { // Return it return translateGeneric('ADMIN_TASK_TYPE', $taskType);