]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Extension ext-surfbar continued:
[mailer.git] / inc / functions.php
index c72f7eb7f65de7009edeb2cfd41a98b544e8eb43..91ef0668200e4cdceaf4e7e274243fad32a2841c 100644 (file)
@@ -1245,7 +1245,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0
                                        if ($next > -1) {
                                                if ($next === $seek) {
                                                        $next = -1;
-                                                       $line = $prefix . $inserted . $suffix . chr(10);
+                                                       $line = $prefix . $inserted . $suffix . PHP_EOL;
                                                } else {
                                                        $next++;
                                                }
@@ -1289,7 +1289,7 @@ function logDebugMessage ($funcFile, $line, $message, $force=true) {
        // Is debug mode enabled?
        if ((isDebugModeEnabled()) || ($force === TRUE)) {
                // Remove CRLF
-               $message = str_replace(array(chr(13), chr(10)), array('', ''), $message);
+               $message = str_replace(array(chr(13), PHP_EOL), array('', ''), $message);
 
                // Log this message away
                appendLineToFile(getPath() . getCachePath() . 'debug.log', generateDateTime(time(), '4') . '|' . getModule(FALSE) . '|' . basename($funcFile) . '|' . $line . '|' . $message);
@@ -1343,9 +1343,12 @@ function handleExtraValues ($filterFunction, $value, $extraValue) {
 }
 
 // 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));
+function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $userIdColumn, $search, $id = NULL) {
+       // Debug mode enabled?
+       if (isDebugModeEnabled()) {
+               // 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));
+       } // END - if
 
        // Send data through the filter function if found
        if ($key == $userIdColumn[0]) {
@@ -1355,7 +1358,7 @@ function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $u
                // 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!');
+                       /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$key] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - BEFORE!');
                } // END - if
 
                // Filter function + extra value set
@@ -1364,8 +1367,26 @@ function doHandleExtraValues ($filterFunctions, $extraValues, $key, $entries, $u
                // 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!');
+                       /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',filterFunctions=' . $filterFunctions[$key] . ',extraValues=' . $extraValues[$key] . ',key=' . $key . ',id=' . $id . ',entries[' . gettype($entries) . ']=' . $entries . ' - AFTER!');
+               } // END - if
+       } elseif ((!empty($filterFunctions[$search])) && (!empty($extraValues[$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, $extraValues[$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 . ' - AFTER!');
+               } // END - if
+
+               // Make sure entries is not bool, then something went wrong
+               assert(!is_bool($entries));
        } elseif (!empty($filterFunctions[$search])) {
                // Debug mode enabled?
                if (isDebugModeEnabled()) {
@@ -1925,7 +1946,7 @@ function encodeUrl ($url, $outputMode = '0') {
        } // END - if
 
        // Is there a valid session?
-       if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === FALSE) || (!isset($_COOKIE[session_name()]))) && (isSpider() === FALSE)) {
+       if ((!isSessionValid()) && (!isSpider())) {
                // Determine right separator
                $separator = '&';
                if (!isInString('?', $url)) {
@@ -1933,11 +1954,8 @@ function encodeUrl ($url, $outputMode = '0') {
                        $separator = '?';
                } // END - if
 
-               // Is the session id set?
-               if (session_id() != '') {
-                       // Then add it to URL
-                       $url .= $separator . session_name() . '=' . session_id();
-               } // END - if
+               // Then add it to URL
+               $url .= $separator . session_name() . '=' . session_id();
        } // END - if
 
        // Add {?URL?} ?
@@ -2060,13 +2078,10 @@ function convertZeroToNull ($number) {
 // Converts a NULL to zero
 function convertNullToZero ($number) {
        // Is it a valid username?
-       if ((!is_null($number)) && (!empty($number)) && ($number > 0)) {
-               // Always secure it
-               $number = bigintval($number);
-       } else {
+       if ((is_null($number)) || (empty($number)) || ($number < 1)) {
                // Is not valid or zero
                $number = '0';
-       }
+       } // END - if
 
        // Return it
        return $number;
@@ -2181,7 +2196,7 @@ function isHexadecimal ($hex) {
 }
 
 /**
- * Replace chr(13) with "[r]" and chr(10) with "[n]" and add a final new-line to make
+ * Replace chr(13) with "[r]" and PHP_EOL 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.
  *
@@ -2189,7 +2204,7 @@ function isHexadecimal ($hex) {
  * @return     $str    Overworked string
  */
 function replaceReturnNewLine ($str) {
-       return str_replace(array(chr(13), chr(10)), array('[r]', '[n]'), $str);
+       return str_replace(array(chr(13), PHP_EOL), array('[r]', '[n]'), $str);
 }
 
 // Converts a given string by splitting it up with given delimiter similar to
@@ -2301,7 +2316,7 @@ function convertStringToBoolean ($str) {
                } // END - if
 
                // Determine it
-               $GLOBALS[__FUNCTION__][$str] = (($strTrimmed == 'true') ? true : false);
+               $GLOBALS[__FUNCTION__][$str] = ($strTrimmed == 'true');
        } // END - if
 
        // Return cache
@@ -2374,7 +2389,7 @@ function memberAddEntries ($tableName, $columns = array(), $filterFunctions = ar
 }
 
 // Edit rows by given id numbers
-function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) {
+function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $timeColumns = array(), $editNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array(), $content = array()) {
        // $tableName must be an array
        if ((!is_array($tableName)) || (count($tableName) != 1)) {
                // No tableName specified
@@ -2408,12 +2423,12 @@ function memberEditEntriesConfirm ($tableName, $columns = array(), $filterFuncti
                }
        } else {
                // List for editing
-               memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
+               memberListBuilder('edit', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content);
        }
 }
 
 // Delete rows by given id numbers
-function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array()) {
+function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunctions = array(), $extraValues = array(), $deleteNow = array(FALSE), $idColumn = array('id'), $userIdColumn = array('userid'), $rawUserId = array('userid'), $cacheFiles = array(), $content = array()) {
        // Do this only for members
        assert(isMember());
 
@@ -2450,17 +2465,18 @@ function memberDeleteEntriesConfirm ($tableName, $columns = array(), $filterFunc
                }
        } else {
                // List for deletion confirmation
-               memberListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
+               memberListBuilder('delete', $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUSerId, $content);
        }
 }
 
 // Build a special template list
-function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid')) {
+// @TODO cacheFiles is not yet supported
+function memberListBuilder ($listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId = array('userid'), $content = array()) {
        // Do this only for logged in member
        assert(isMember());
 
        // Call inner (general) function
-       doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId);
+       doGenericListBuilder('member', $listType, $tableName, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $rawUserId, $content);
 }
 
 // Checks whether given address is IPv4