]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Referal system refactured (and some parts fixed), wrapper function introduced:
[mailer.git] / inc / functions.php
index e2fdb65381aba41d1264c934cfe0079386fd1a23..08fa13dc1783c29bcdaf8fe0502ea790e97c86d1 100644 (file)
@@ -105,7 +105,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
                // Is the webmaster!
                $toEmail = getWebmaster();
        }
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail}<br />");
+       //* 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
@@ -1570,7 +1569,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!<br />");
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inc=' . $inc . ' - LOADED!');
                                loadInclude($inc);
                        } else {
                                // Include not found
@@ -1745,7 +1744,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 +1988,7 @@ function initCacheInstance () {
        // Did it work?
        if ($GLOBALS['cache_instance']->getStatusCode() != 'done') {
                // Failed to initialize cache sustem
-               addFatalMessage(__FUNCTION__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_CANNOT_INITIALIZE--}');
+               debug_report_bug(__FUNCTION__, __LINE__, 'Cache system returned with unexpected error. getStatusCode()=' . $GLOBALS['cache_instance']->getStatusCode());
        } // END - if
 }
 
@@ -2221,13 +2220,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:<br />'.__FUNCTION__.':<br />content=<pre>'.print_r($content, true).'</pre>');
+
+                       // 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 +2252,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 +2272,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));
@@ -2320,6 +2337,7 @@ function getArrayKeysFromSubStrArray ($heystack, $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 +2360,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 +2410,24 @@ 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