]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Project continued with rewrites:
[mailer.git] / inc / functions.php
index 7702331fc7ce559c380a422473a7917a616cdea1..d69c1abdd066a742f6ed1a9188be63ec04e3d6b6 100644 (file)
@@ -89,27 +89,26 @@ 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);
 
        // 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
@@ -1290,46 +1289,94 @@ 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) {
+       // 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));
+
+       // 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[$search] . ',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[$search] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - AFTER!');
+               } // END - if
+       } 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
@@ -1873,8 +1920,9 @@ function encodeUrl ($url, $outputMode = '0') {
                        $separator = '?';
                } // END - if
 
-               // Add it to URL
+               // Is the session id set?
                if (session_id() != '') {
+                       // Then add it to URL
                        $url .= $separator . session_name() . '=' . session_id();
                } // END - if
        } // END - if
@@ -1885,10 +1933,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
@@ -2157,7 +2210,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();
@@ -2409,6 +2462,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 +2517,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);