]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Fix for missing array element 'mails_sent'
[mailer.git] / inc / functions.php
index a14ad083909ab1b1ff0ecffa1f698fdce9626594..a5cd6edc6a4f1693989386c4089a80f128eb5a55 100644 (file)
@@ -92,7 +92,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
        } // END - if
 
        // Set from header
-       if ((!isInStringIgnoreCase('@', $toEmail)) && ($toEmail > 0)) {
+       if ((!isInString('@', $toEmail)) && ($toEmail > 0)) {
                // Does the user exist?
                if ((isExtensionActive('user')) && (fetchUserData($toEmail))) {
                        // Get the email
@@ -295,7 +295,7 @@ function generateDateTime ($time, $mode = '0') {
                                default:
                                        logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
                                        break;
-                       }
+                       } // END - switch
                        break;
 
                default: // Default is the US date / time format!
@@ -594,26 +594,26 @@ function redirectToUrl ($url, $allowSpider = true) {
  *                                                                      *
  ************************************************************************/
 function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums = false) {
-       $dummy = $array;
+       $temporaryArray = $array;
        while ($primary_key < count($a_sort)) {
-               foreach ($dummy[$a_sort[$primary_key]] as $key => $value) {
-                       foreach ($dummy[$a_sort[$primary_key]] as $key2 => $value2) {
+               foreach ($temporaryArray[$a_sort[$primary_key]] as $key => $value) {
+                       foreach ($temporaryArray[$a_sort[$primary_key]] as $key2 => $value2) {
                                $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($dummy[$a_sort[$primary_key]][$key]), strtolower($dummy[$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 (($dummy[$a_sort[$primary_key]][$key] < $dummy[$a_sort[$primary_key]][$key2]) && ($order == -1)) $match = true;
-                                       if (($dummy[$a_sort[$primary_key]][$key] > $dummy[$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) {
                                        // We have found two different values, so let's sort whole array
-                                       foreach ($dummy as $sort_key => $sort_val) {
-                                               $t                       = $dummy[$sort_key][$key];
-                                               $dummy[$sort_key][$key]  = $dummy[$sort_key][$key2];
-                                               $dummy[$sort_key][$key2] = $t;
+                                       foreach ($temporaryArray as $sort_key => $sort_val) {
+                                               $t                       = $temporaryArray[$sort_key][$key];
+                                               $temporaryArray[$sort_key][$key]  = $temporaryArray[$sort_key][$key2];
+                                               $temporaryArray[$sort_key][$key2] = $t;
                                                unset($t);
                                        } // END - foreach
                                } // END - if
@@ -625,7 +625,7 @@ function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums
        } // END - while
 
        // Write back sorted array
-       $array = $dummy;
+       $array = $temporaryArray;
 }
 
 
@@ -645,7 +645,7 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') {
        if (isConfigEntrySet('file_hash')) {
                $keys .= getEncryptSeperator() . getFileHash();
        } // END - if
-       $keys .= getEncryptSeperator() . getDateFromPatchTime();
+       $keys .= getEncryptSeperator() . getDateFromRepository();
        if (isConfigEntrySet('master_salt')) {
                $keys .= getEncryptSeperator() . getMasterSalt();
        } // END - if
@@ -676,7 +676,7 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') {
        }
 
        // Create number from hash
-       $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(getRandNo() - $a + sqrt(getConfig('_ADD'))) / pi();
+       $rcode = hexdec(substr($saltedHash, getSaltLength(), 9)) / abs(getRandNo() - $a + sqrt(getConfig('_ADD'))) / pi();
 
        // At least 10 numbers shall be secure enought!
        if (isExtensionActive('other')) {
@@ -689,8 +689,8 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') {
                $len = 10;
        } // END - if
 
-       // Cut off requested counts of number
-       $return = substr(str_replace('.', '', $rcode), 0, $len);
+       // Cut off requested counts of number, but skip first digit (which is mostly a zero)
+       $return = substr($rcode, (strpos($rcode, '.') + 1), $len);
 
        // Done building code
        return $return;
@@ -890,7 +890,7 @@ function generateHash ($plainText, $salt = '', $hash = true) {
                $server = $_SERVER['PHP_SELF'] . getEncryptSeperator() . detectUserAgent() . getEncryptSeperator() . getenv('SERVER_SOFTWARE') . getEncryptSeperator() . detectRealIpAddress() . getEncryptSeperator() . detectRemoteAddr();
 
                // Build key string
-               $keys   = getSiteKey() . getEncryptSeperator() . getDateKey() . getEncryptSeperator() . getSecretKey() . getEncryptSeperator() . getFileHash() . getEncryptSeperator() . getDateFromPatchTime() . getEncryptSeperator() . getMasterSalt();
+               $keys   = getSiteKey() . getEncryptSeperator() . getDateKey() . getEncryptSeperator() . getSecretKey() . getEncryptSeperator() . getFileHash() . getEncryptSeperator() . getDateFromRepository() . getEncryptSeperator() . getMasterSalt();
 
                // Additional data
                $data = $plainText . getEncryptSeperator() . uniqid(mt_rand(), true) . getEncryptSeperator() . time();
@@ -1358,7 +1358,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0
                                        // Read from source file
                                        $line = fgets ($fp, 1024);
 
-                                       if (strpos($line, $search) > -1) {
+                                       if (isInString($search, $line)) {
                                                $next = '0';
                                                $found = true;
                                        } // END - if
@@ -1465,7 +1465,7 @@ function handleExtraValues ($filterFunction, $value, $extraValue) {
 }
 
 // Converts timestamp selections into a timestamp
-function convertSelectionsToEpocheTime (array &$postData, array &$DATA, &$id, &$skip) {
+function convertSelectionsToEpocheTime (array &$postData, array &$content, &$id, &$skip) {
        // Init test variable
        $skip  = false;
        $test2 = '';
@@ -1480,7 +1480,7 @@ function convertSelectionsToEpocheTime (array &$postData, array &$DATA, &$id, &$
                if ((isset($postData[$test.'_ye'])) && (isset($postData[$test.'_mo'])) && (isset($postData[$test.'_we'])) && (isset($postData[$test.'_da'])) && (isset($postData[$test.'_ho'])) && (isset($postData[$test.'_mi'])) && (isset($postData[$test.'_se'])) && ($test != $test2)) {
                        // Generate timestamp
                        $postData[$test] = createEpocheTimeFromSelections($test, $postData);
-                       $DATA[] = sprintf("`%s`='%s'", $test, $postData[$test]);
+                       $content[] = sprintf("`%s`='%s'", $test, $postData[$test]);
                        $GLOBALS['skip_config'][$test] = true;
 
                        // Remove data from array
@@ -1553,7 +1553,7 @@ function handleLoginFailures ($accessLevel) {
 // Rebuild cache
 function rebuildCache ($cache, $inc = '', $force = false) {
        // Debug message
-       /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force)));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force)));
 
        // Shall I remove the cache file?
        if (isCacheInstanceValid()) {
@@ -1690,7 +1690,7 @@ function determineReferalId () {
        }
 
        // Set cookie when default refid > 0
-       if (!isSessionVariableSet('refid') || (!isValidUserId(getReferalId())) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) {
+       if ((!isSessionVariableSet('refid')) || (!isValidUserId(getReferalId())) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) {
                // Default is not found
                $found = false;
 
@@ -1721,11 +1721,12 @@ function determineReferalId () {
                // Set cookie
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Saving refid to session (' . getReferalId() . ') #1');
                setSession('refid', getReferalId());
-       } elseif (!isReferalIdValid()) {
+       } elseif ((!isReferalIdValid()) || (!fetchUserData(getReferalId()))) {
                // Not valid!
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not valid referal id (' . getReferalId() . '), setting NULL in session');
+               setReferalId(NULL);
                setSession('refid', NULL);
-       } elseif ((!isSessionVariableSet('refid')) && (isValidUserId(getReferalId()))) {
+       } else {
                // Set it from GLOBALS array in session
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Saving refid to session (' . getReferalId() . ') #2');
                setSession('refid', getReferalId());
@@ -2061,7 +2062,7 @@ 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
-       if ((strpos($url, session_name()) !== false) || (isRawOutputMode())) {
+       if ((isInStringIgnoreCase(session_name(), $url)) || (isRawOutputMode())) {
                // Raw output mode detected or session_name() found in URL
                return $url;
        } // END - if
@@ -2071,7 +2072,7 @@ function encodeUrl ($url, $outputMode = '0') {
                // Invalid session
                // Determine right seperator
                $seperator = '&amp;';
-               if (strpos($url, '?') === false) {
+               if (!isInString('?', $url)) {
                        // No question mark
                        $seperator = '?';
                } elseif ((!isHtmlOutputMode()) || ($outputMode != '0')) {
@@ -2098,7 +2099,7 @@ function encodeUrl ($url, $outputMode = '0') {
 // Simple check for spider
 function isSpider () {
        // Get the UA and trim it down
-       $userAgent = trim(strtolower(detectUserAgent(true)));
+       $userAgent = trim(detectUserAgent(true));
 
        // It should not be empty, if so it is better a spider/bot
        if (empty($userAgent)) {
@@ -2107,7 +2108,7 @@ function isSpider () {
        } // END - if
 
        // Is it a spider?
-       return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false) || (strpos($userAgent, 'archiver') !== false));
+       return ((isInStringIgnoreCase('spider', $userAgent)) || (isInStringIgnoreCase('slurp', $userAgent)) || (isInStringIgnoreCase('bot', $userAgent)) || (isInStringIgnoreCase('archiver', $userAgent)));
 }
 
 // Function to search for the last modified file
@@ -2251,7 +2252,7 @@ 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,