X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=ad6274eb2e55316f7536b78fd9c03c0fb880784a;hb=0fada672e2066043b76ed5d57f852f451a49a3a3;hp=ba6ccc37101dcfc574e6145d1cc3728bbadb3811;hpb=c6017cf76200e2a5e68bd1984fa2d31f0e3be9d8;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index ba6ccc3710..ad6274eb2e 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -105,7 +105,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
// Is the webmaster!
$toEmail = getWebmaster();
}
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail}
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'TO=' . $toEmail);
// Check for PHPMailer or debug-mode
if ((!checkPhpMailerUsage()) || (isDebugModeEnabled())) {
@@ -640,14 +640,14 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') {
// Build key string
$keys = getSiteKey() . getEncryptSeperator() . getDateKey();
if (isConfigEntrySet('secret_key')) {
- $keys .= getEncryptSeperator().getSecretKey();
+ $keys .= getEncryptSeperator() . getSecretKey();
} // END - if
if (isConfigEntrySet('file_hash')) {
- $keys .= getEncryptSeperator().getFileHash();
+ $keys .= getEncryptSeperator() . getFileHash();
} // END - if
$keys .= getEncryptSeperator() . getDateFromPatchTime();
if (isConfigEntrySet('master_salt')) {
- $keys .= getEncryptSeperator().getMasterSalt();
+ $keys .= getEncryptSeperator() . getMasterSalt();
} // END - if
// Build string from misc data
@@ -670,22 +670,21 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') {
if (isConfigEntrySet('master_salt')) {
// Generate hash with master salt from modula of number with the prime number and other data
$saltedHash = generateHash(($a % getPrime()) . getEncryptSeperator() . $server . getEncryptSeperator() . $keys . getEncryptSeperator() . $data . getEncryptSeperator() . getDateKey() . getEncryptSeperator() . $a, getMasterSalt());
-
- // Create number from hash
- $rcode = hexdec(substr($saltedHash, strlen(getMasterSalt()), 9)) / abs(getRandNo() - $a + sqrt(getConfig('_ADD'))) / pi();
} else {
// Generate hash with "hash of site key" from modula of number with the prime number and other data
$saltedHash = generateHash(($a % getPrime()) . getEncryptSeperator() . $server . getEncryptSeperator() . $keys . getEncryptSeperator() . $data . getEncryptSeperator() . getDateKey() . getEncryptSeperator() . $a, substr(sha1(getSiteKey()), 0, getSaltLength()));
-
- // Create number from hash
- $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(getRandNo() - $a + sqrt(getConfig('_ADD'))) / pi();
}
+ // Create number from hash
+ $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(getRandNo() - $a + sqrt(getConfig('_ADD'))) / pi();
+
// At least 10 numbers shall be secure enought!
- $len = getCodeLength();
- if ($len == '0') {
+ if (isExtensionActive('other')) {
+ $len = getCodeLength();
+ } else {
$len = $length;
} // END - if
+
if ($len == '0') {
$len = 10;
} // END - if
@@ -1318,8 +1317,10 @@ function isUrlValidSimple ($url) {
$reg = ($reg || preg_match(('^' . $pat . '^'), $url));
// Does it match?
- if ($reg === true) break;
- }
+ if ($reg === true) {
+ break;
+ } // END - if
+ } // END - foreach
// Return true/false
return $reg;
@@ -1327,7 +1328,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, $DATA, $seek=0) {
+function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
// Initialize some variables
$done = false;
$seek++;
@@ -1357,7 +1358,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
// Read from source file
$line = fgets ($fp, 1024);
- if (strpos($line, $search) > -1) {
+ if (strpos($line, $search) > -1) {
$next = '0';
$found = true;
} // END - if
@@ -1365,7 +1366,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
if ($next > -1) {
if ($next === $seek) {
$next = -1;
- $line = $prefix . $DATA . $suffix . "\n";
+ $line = $prefix . $inserted . $suffix . "\n";
} else {
$next++;
}
@@ -1570,7 +1571,7 @@ function rebuildCache ($cache, $inc = '', $force = false) {
// Is the include there?
if (isIncludeReadable($inc)) {
// And rebuild it from scratch
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "inc={$inc} - LOADED!
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inc=' . $inc . ' - LOADED!');
loadInclude($inc);
} else {
// Include not found
@@ -1745,7 +1746,7 @@ function shutdown () {
SQL_CLOSE(__FUNCTION__, __LINE__);
} elseif (!isInstallationPhase()) {
// No database link
- addFatalMessage(__FUNCTION__, __LINE__, '{--NO_DB_LINK_SHUTDOWN--}');
+ debug_report_bug(__FUNCTION__, __LINE__, 'Database link is already down, while shutdown is running.');
}
// Stop executing here
@@ -1989,7 +1990,7 @@ function initCacheInstance () {
// Did it work?
if ($GLOBALS['cache_instance']->getStatusCode() != 'done') {
// Failed to initialize cache sustem
- addFatalMessage(__FUNCTION__, __LINE__, '(' . __LINE__ . '): {--CACHE_CANNOT_INITIALIZE--}');
+ debug_report_bug(__FUNCTION__, __LINE__, 'Cache system returned with unexpected error. getStatusCode()=' . $GLOBALS['cache_instance']->getStatusCode());
} // END - if
}
@@ -2150,7 +2151,7 @@ function handleFieldWithBraces ($field) {
return $field;
}
-// Converts a userid so it can be used in SQL queries
+// Converts a zero or NULL to word 'NULL'
function makeZeroToNull ($number) {
// Is it a valid username?
if ((!is_null($number)) && ($number > 0)) {
@@ -2165,6 +2166,18 @@ function makeZeroToNull ($number) {
return $number;
}
+// Converts NULL into number zero
+function makeNullToZero ($number) {
+ // Is this a NULL?
+ if ((is_null($number)) || (empty($number))) {
+ // Simply set it
+ $number = '0';
+ } // END - if
+
+ // Return it
+ return $number;
+}
+
// Capitalizes a string with underscores, e.g.: some_foo_string will become SomeFooString
// Note: This function is cached
function capitalizeUnderscoreString ($str) {
@@ -2221,13 +2234,26 @@ function generateAdminMailLinks ($mailType, $mailId) {
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",
- array($statusColumn, $table, bigintval($mailId)), __FILE__, __LINE__);
+ array(
+ $statusColumn,
+ $table,
+ bigintval($mailId)
+ ), __FILE__, __LINE__);
// Do we have one entry there?
if (SQL_NUMROWS($result) == 1) {
// Load the entry
$content = SQL_FETCHARRAY($result);
- die('Unfinished area:
'.__FUNCTION__.':
content=
'.print_r($content, true).''); + + // Add output and type + $content['type'] = $mailType; + $content['__output'] = ''; + + // Filter all data + $content = runFilterChain('generate_admin_mail_links', $content); + + // Get output back + $OUT = $content['__output']; } // END - if // Free result @@ -2240,7 +2266,7 @@ function generateAdminMailLinks ($mailType, $mailId) { /** - * determine if a string can represent a number in hexadecimal + * Determine if a string can represent a number in hexadecimal * * @param $hex A string to check if it is hex-encoded * @return $foo True if the string is a hex, otherwise false @@ -2260,9 +2286,14 @@ function isHexadecimal ($hex) { return ($hex == dechex(hexdec($hex))); } -// Replace "\r" with "[r]" and "\n" 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. +/** + * Replace "\r" with "[r]" and "\n" 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. + * + * @param $str String to overwork + * @return $str Overworked string + */ function replaceReturnNewLine ($str) { return str_replace("\r", '[r]', str_replace("\n", '[n] ', $str)); @@ -2300,7 +2331,7 @@ function detectMultiBytePrefix ($str) { } // Searches the given array for a sub-string match and returns all found keys in an array -function getArrayKeysFromSubStrArray ($heystack, array $needles, $offset = 0) { +function getArrayKeysFromSubStrArray ($heystack, $needles, $offset = 0) { // Init array for all found keys $keys = array(); @@ -2320,6 +2351,7 @@ function getArrayKeysFromSubStrArray ($heystack, array $needles, $offset = 0) { // Determines database column name from given subject and locked function determinePointsColumnFromSubjectLocked ($subject, $locked) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ' - ENTERED!'); // Default is 'normal' points $pointsColumn = 'points'; @@ -2342,6 +2374,7 @@ function determinePointsColumnFromSubjectLocked ($subject, $locked) { $pointsColumn = $filterData['column']; // Return it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'subject=' . $subject . ',locked=' . intval($locked) . ',pointsColumn=' . $pointsColumn . ' - EXIT!'); return $pointsColumn; } @@ -2391,6 +2424,39 @@ function translateTaskType ($taskType) { return $message; } +// Translates points subject to human-readable +function translatePointsSubject ($subject) { + // Construct message id + $messageId = 'POINTS_SUBJECT_' . strtoupper($subject) . ''; + + // Is the message id there? + if (isMessageIdValid($messageId)) { + // Then construct message + $message = '{--' . $messageId . '--}'; + } else { + // Else it is an unknown task type + $message = '{%message,POINTS_SUBJECT_UNKNOWN=' . $subject . '%}'; + } // END - if + + // Return message + return $message; +} + +// "Translates" 'true' to true and 'false' to false +function convertStringToBoolean ($str) { + // Trim it lower-case for validation + $str = trim(strtolower($str)); + + // Is it valid? + if (!in_array($str, array('true', 'false'))) { + // Not valid! + debug_report_bug(__FUNCTION__, __LINE__, 'str=' . $str . ' is not true/false'); + } // END - if + + // Return it + return (($str == 'true') ? true : false); +} + //----------------------------------------------------------------------------- // Automatically re-created functions, all taken from user comments on www.php.net //-----------------------------------------------------------------------------