]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Extension ext-coupon continued, naming convention, many improvements:
[mailer.git] / inc / functions.php
index 119c23891de8d87676deec8a70a5d493a2f3a2ee..be1223d7b40a3a7ca61983734dae43382adf51bc 100644 (file)
@@ -241,13 +241,18 @@ function sendRawEmail ($toEmail, $subject, $message, $headers) {
 }
 
 // Generate a password in a specified length or use default password length
-function generatePassword ($length = '0') {
+function generatePassword ($length = '0', $exclude =  array()) {
        // Auto-fix invalid length of zero
-       if ($length == '0') $length = getPassLen();
+       if ($length == '0') {
+               $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);
+
        // Start creating password
        $PASS = '';
        for ($i = '0'; $i < $length; $i++) {
@@ -293,6 +298,7 @@ function generateDateTime ($time, $mode = '0') {
                                case '4': $ret = date('d.m.Y|H:i:s', $time); break;
                                case '5': $ret = date('d-m-Y (l-F-T)', $time); break;
                                case '6': $ret = date('Ymd', $time); break;
+                               case '7': $ret = date('Y-m-d H:i:s', $time); break; // Compatible with MySQL TIMESTAMP
                                default:
                                        logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
                                        break;
@@ -308,6 +314,7 @@ function generateDateTime ($time, $mode = '0') {
                                case '4': $ret = date('d.m.Y|H:i:s', $time); break;
                                case '5': $ret = date('d-m-Y (l-F-T)', $time); break;
                                case '6': $ret = date('Ymd', $time); break;
+                               case '7': $ret = date('Y-m-d H:i:s', $time); break; // Compatible with MySQL TIMESTAMP
                                default:
                                        logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
                                        break;
@@ -346,14 +353,18 @@ function translateComma ($dotted, $cut = true, $max = '0') {
        // First, cast all to double, due to PHP changes
        $dotted = (double) $dotted;
 
-       // Default is 3 you can change this in admin area "Misc -> Misc Options"
-       if (!isConfigEntrySet('max_comma')) setConfigEntry('max_comma', 3);
+       // Default is 3 you can change this in admin area "Settings -> Misc Options"
+       if (!isConfigEntrySet('max_comma')) {
+               setConfigEntry('max_comma', 3);
+       } // END - if
 
        // Use from config is default
        $maxComma = getConfig('max_comma');
 
        // Use from parameter?
-       if ($max > 0) $maxComma = $max;
+       if ($max > 0) {
+               $maxComma = $max;
+       } // END - if
 
        // Cut zeros off?
        if (($cut === true) && ($max == '0')) {
@@ -467,22 +478,22 @@ function translateMenuVisibleLocked ($content, $prefix = '') {
 }
 
 // Generates an URL for the dereferer
-function generateDerefererUrl ($URL) {
+function generateDerefererUrl ($url) {
        // Don't de-refer our own links!
-       if (substr($URL, 0, strlen(getUrl())) != getUrl()) {
+       if (substr($url, 0, strlen(getUrl())) != getUrl()) {
                // De-refer this link
-               $URL = '{%url=modules.php?module=loader&amp;url=' . encodeString(compileUriCode($URL)) . '%}';
+               $url = '{%url=modules.php?module=loader&amp;url=' . encodeString(compileUriCode($url)) . '%}';
        } // END - if
 
        // Return link
-       return $URL;
+       return $url;
 }
 
 // Generates an URL for the frametester
-function generateFrametesterUrl ($URL) {
+function generateFrametesterUrl ($url) {
        // Prepare frametester URL
        $frametesterUrl = sprintf("{%%url=modules.php?module=frametester&amp;url=%s%%}",
-               encodeString(compileUriCode($URL))
+               encodeString(compileUriCode($url))
        );
 
        // Return the new URL
@@ -529,38 +540,31 @@ function makeTime ($hours, $minutes, $seconds, $stamp) {
 }
 
 // Redirects to an URL and if neccessarry extends it with own base URL
-function redirectToUrl ($URL, $allowSpider = true) {
+function redirectToUrl ($url, $allowSpider = true) {
        // Remove {%url=
-       if (substr($URL, 0, 6) == '{%url=') $URL = substr($URL, 6, -2);
+       if (substr($url, 0, 6) == '{%url=') {
+               $url = substr($url, 6, -2);
+       } // END - if
 
        // Compile out codes
-       eval('$URL = "' . compileRawCode(encodeUrl($URL)) . '";');
+       eval('$url = "' . compileRawCode(encodeUrl($url)) . '";');
 
        // Default 'rel' value is external, nofollow is evil from Google and hurts the Internet
        $rel = ' rel="external"';
 
        // Do we have internal or external URL?
-       if (substr($URL, 0, strlen(getUrl())) == getUrl()) {
+       if (substr($url, 0, strlen(getUrl())) == getUrl()) {
                // Own (=internal) URL
                $rel = '';
        } // END - if
 
        // Three different ways to debug...
-       //* DEBUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'URL=' . $URL);
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
-       //* DEBUG: */ die($URL);
-
-       // Simple probe for bots/spiders from search engines
-       if ((isSpider()) && ($allowSpider === true)) {
-               // Set HTTP-Status
-               setHttpStatus('200 OK');
+       //* DEBUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'URL=' . $url);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $url);
+       //* DEBUG: */ die($url);
 
-               // Set content-type here to fix a missing array element
-               setContentType('text/html');
-
-               // Output new location link as anchor
-               outputHtml('<a href="' . $URL . '"' . $rel . '>' . secureString($URL) . '</a>');
-       } elseif (!headers_sent()) {
+       // We should not sent a redirect if headers are already sent
+       if (!headers_sent()) {
                // Clear output buffer
                clearOutputBuffer();
 
@@ -568,11 +572,11 @@ function redirectToUrl ($URL, $allowSpider = true) {
                $GLOBALS['output'] = '';
 
                // Load URL when headers are not sent
-               sendRawRedirect(doFinalCompilation(str_replace('&amp;', '&', $URL), false));
+               sendRawRedirect(doFinalCompilation(str_replace('&amp;', '&', $url), false));
        } else {
                // Output error message
                loadInclude('inc/header.php');
-               loadTemplate('redirect_url', false, str_replace('&amp;', '&', $URL));
+               loadTemplate('redirect_url', false, str_replace('&amp;', '&', $url));
                loadInclude('inc/footer.php');
        }
 
@@ -634,9 +638,9 @@ function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums
 
 //
 // Deprecated : $length (still has one reference in this function)
-// Optional   : $DATA
+// Optional   : $extraData
 //
-function generateRandomCode ($length, $code, $userid, $DATA = '') {
+function generateRandomCode ($length, $code, $userid, $extraData = '') {
        // Build server string
        $server = $_SERVER['PHP_SELF'] . getEncryptSeperator() . detectUserAgent() . getEncryptSeperator() . getenv('SERVER_SOFTWARE') . getEncryptSeperator() . detectRealIpAddress() . getEncryptSeperator() . detectRemoteAddr();
 
@@ -654,7 +658,7 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') {
        } // END - if
 
        // Build string from misc data
-       $data   = $code . getEncryptSeperator() . $userid . getEncryptSeperator() . $DATA;
+       $data  = $code . getEncryptSeperator() . $userid . getEncryptSeperator() . $extraData;
 
        // Add more additional data
        if (isSessionVariableSet('u_hash')) {
@@ -722,7 +726,7 @@ function bigintval ($num, $castValue = true, $abortOnMismatch = true) {
 }
 
 // Creates a Uni* timestamp from given selection data and prefix
-function createTimestampFromSelections ($prefix, $postData) {
+function createEpocheTimeFromSelections ($prefix, $postData) {
        // Initial return value
        $ret = '0';
 
@@ -732,7 +736,9 @@ function createTimestampFromSelections ($prefix, $postData) {
        $M1   = getMonth();
 
        // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
-       if ((floor($TEST) == $TEST) && ($M1 == '02') && ($postData[$prefix . '_mo'] > '02'))  $SWITCH = getOneDay();
+       if ((floor($TEST) == $TEST) && ($M1 == '02') && ($postData[$prefix . '_mo'] > '02'))  {
+               $SWITCH = getOneDay();
+       } // END - if
 
        // First add years...
        $ret += $postData[$prefix . '_ye'] * (31536000 + $SWITCH);
@@ -840,24 +846,26 @@ function isEmailValid ($email) {
 }
 
 // Function taken from user comments on www.php.net / function isInStringIgnoreCase()
-function isUrlValid ($URL, $compile=true) {
+function isUrlValid ($url, $compile=true) {
        // Trim URL a little
-       $URL = trim(urldecode($URL));
-       //* DEBUG: */ debugOutput($URL);
+       $url = trim(urldecode($url));
+       //* DEBUG: */ debugOutput($url);
 
        // Compile some chars out...
-       if ($compile === true) $URL = compileUriCode($URL, false, false, false);
-       //* DEBUG: */ debugOutput($URL);
+       if ($compile === true) {
+               $url = compileUriCode($url, false, false, false);
+       } // END - if
+       //* DEBUG: */ debugOutput($url);
 
        // Check for the extension filter
        if (isExtensionActive('filter')) {
                // Use the extension's filter set
-               return FILTER_VALIDATE_URL($URL, false);
+               return FILTER_VALIDATE_URL($url, false);
        } // END - if
 
        // If not installed, perform a simple test. Just make it sure there is always a http:// or
        // https:// in front of the URLs
-       return isUrlValidSimple($URL);
+       return isUrlValidSimple($url);
 }
 
 // Generate a hash for extra-security for all passwords
@@ -918,7 +926,7 @@ function generateHash ($plainText, $salt = '', $hash = true) {
                // Sanity check on salt
                if (strlen($salt) != getSaltLength()) {
                        // Not the same!
-                       debug_report_bug(__FUNCTION__, __LINE__, 'salt length mismatch! ('.strlen($salt).'/'.getSaltLength().')');
+                       debug_report_bug(__FUNCTION__, __LINE__, 'salt length mismatch! (' . strlen($salt) . '/' . getSaltLength() . ')');
                } // END - if
        }
 
@@ -1463,7 +1471,7 @@ function handleExtraValues ($filterFunction, $value, $extraValue) {
 }
 
 // Converts timestamp selections into a timestamp
-function convertSelectionsToTimestamp (&$postData, &$DATA, &$id, &$skip) {
+function convertSelectionsToEpocheTime (array &$postData, array &$DATA, &$id, &$skip) {
        // Init test variable
        $skip  = false;
        $test2 = '';
@@ -1477,7 +1485,7 @@ function convertSelectionsToTimestamp (&$postData, &$DATA, &$id, &$skip) {
                $test = substr($id, 0, -3);
                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] = createTimestampFromSelections($test, $postData);
+                       $postData[$test] = createEpocheTimeFromSelections($test, $postData);
                        $DATA[] = sprintf("`%s`='%s'", $test, $postData[$test]);
                        $GLOBALS['skip_config'][$test] = true;
 
@@ -2217,7 +2225,7 @@ function generateAdminMailLinks ($mailType, $mailId) {
                if (SQL_NUMROWS($result) == 1) {
                        // Load the entry
                        $content = SQL_FETCHARRAY($result);
-                       die(__FUNCTION__.':<br />content=<pre>'.print_r($content, true).'</pre>');
+                       die('Unfinished area:<br />'.__FUNCTION__.':<br />content=<pre>'.print_r($content, true).'</pre>');
                } // END - if
 
                // Free result
@@ -2289,6 +2297,52 @@ function detectMultiBytePrefix ($str) {
        return $mbPrefix;
 }
 
+// Searches the given array for a sub-string match and returns all found keys in an array
+function getArrayKeysFromSubStrArray ($heystack, array $needles, $offset = 0) {
+       // Init array for all found keys
+       $keys = array();
+
+       // Now check all entries
+       foreach ($needles as $key => $needle) {
+               // Do we have found a partial string?
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'heystack='.$heystack.',key='.$key.',needle='.$needle.',offset='.$offset);
+               if (strpos($heystack, $needle, $offset) !== false) {
+                       // Add the found key
+                       $keys[] = $key;
+               } // END - if
+       } // END - foreach
+
+       // Return the array
+       return $keys;
+}
+
+// Determines database column name from given subject and locked
+function determinePointsColumnFromSubjectLocked ($subject, $locked) {
+       // Default is 'normal' points
+       $pointsColumn = 'points';
+
+       // Which points, locked or normal?
+       if ($locked === true) {
+               $pointsColumn = 'locked_points';
+       } // END - if
+
+       // Prepare array for filter
+       $filterData = array(
+               'subject' => $subject,
+               'locked'  => $locked,
+               'column'  => $pointsColumn
+       );
+
+       // Run the filter
+       $filterData = runFilterChain('determine_points_column_name', $filterData);
+
+       // Extract column name from array
+       $pointsColumn = $filterData['column'];
+
+       // Return it
+       return $pointsColumn;
+}
+
 //-----------------------------------------------------------------------------
 // Automatically re-created functions, all taken from user comments on www.php.net
 //-----------------------------------------------------------------------------