]> git.mxchange.org Git - mailer.git/blobdiff - inc/wrapper-functions.php
Installation NG continued (still not fully working)
[mailer.git] / inc / wrapper-functions.php
index 31e30cbefe98f21f223b82595b9e59b4244f8fe7..e312c565a0b4e2bb68128b12c89709e88792274d 100644 (file)
@@ -46,19 +46,19 @@ function readFromFile ($FQFN) {
        if (!isFileReadable($FQFN)) {
                // This should not happen
                reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
-       } elseif (!isset($GLOBALS['file_content'][$FQFN])) {
-               // Load the file
-               if (function_exists('file_get_contents')) {
-                       // Use new function
-                       $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN);
-               } else {
-                       // Fall-back to implode-file chain
-                       $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN));
-               }
        } // END - if
 
+       // Load the file
+       if (function_exists('file_get_contents')) {
+               // Use new function
+               $fileContent = file_get_contents($FQFN);
+       } else {
+               // Fall-back to implode-file chain
+               $fileContent = implode('', file($FQFN));
+       }
+
        // Return the content
-       return $GLOBALS['file_content'][$FQFN];
+       return $fileContent;
 }
 
 // Writes content to a file
@@ -66,7 +66,7 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
        // Is the file writeable?
        if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
                // Not writeable!
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable or cannot change CHMOD to 0644.", basename($FQFN)));
 
                // Failed! :(
                return FALSE;
@@ -74,7 +74,6 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
 
        // By default all is failed...
        $GLOBALS['file_readable'][$FQFN] = FALSE;
-       unset($GLOBALS['file_content'][$FQFN]);
        $return = FALSE;
 
        // Is the function there?
@@ -89,7 +88,8 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
                }
        } else {
                // Write it with fopen
-               $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
+               $fp = fopen($FQFN, 'w')
+                       or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
 
                // Aquire a lock?
                if ($aquireLock === TRUE) {
@@ -108,9 +108,6 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
        if ($return !== FALSE) {
                // Mark it as readable
                $GLOBALS['file_readable'][$FQFN] = TRUE;
-
-               // Remember content in cache
-               $GLOBALS['file_content'][$FQFN] = $content;
        } // END - if
 
        // Return status
@@ -123,10 +120,7 @@ function clearOutputBuffer () {
        if (isset($GLOBALS[__FUNCTION__])) {
                // This function is called twice
                reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
-       } // END - if
-
-       // Trigger an error on failure
-       if ((ob_get_length() > 0) && (!ob_end_clean())) {
+       } elseif ((ob_get_length() > 0) && (!ob_end_clean())) {
                // Failed!
                reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
        } // END - if
@@ -157,7 +151,7 @@ function decodeEntities ($str, $quote = ENT_NOQUOTES) {
 }
 
 // Merges an array together but only if both are arrays
-function merge_array ($array1, $array2) {
+function merge_array ($array1, $array2, $keepIndex = FALSE) {
        // Are both an array?
        if ((!is_array($array1)) && (!is_array($array2))) {
                // Both are not arrays
@@ -170,8 +164,20 @@ function merge_array ($array1, $array2) {
                reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
        }
 
-       // Merge both together
-       return array_merge($array1, $array2);
+       // Maintain index of array2?
+       if ($keepIndex === TRUE) {
+               // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
+               foreach ($array2 as $key => $value) {
+                       // Add it
+                       $array1[$key] = $value;
+               } // END - foreach
+
+               // Return it
+               return $array1;
+       } else {
+               // Merge both together normally
+               return array_merge($array1, $array2);
+       }
 }
 
 // Check if given FQFN is a readable file
@@ -202,12 +208,12 @@ function isDirectory ($FQFN) {
 }
 
 // "Getter" for the real remote IP number
-function detectRealIpAddress () {
+function detectRealIpAddress ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $remoteAddr = determineRealRemoteAddress();
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
        } // END - if
@@ -217,12 +223,12 @@ function detectRealIpAddress () {
 }
 
 // "Getter" for remote IP number
-function detectRemoteAddr () {
+function detectRemoteAddr ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $remoteAddr = determineRealRemoteAddress(TRUE);
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
        } // END - if
@@ -232,12 +238,12 @@ function detectRemoteAddr () {
 }
 
 // "Getter" for remote hostname
-function detectRemoteHostname () {
+function detectRemoteHostname ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $remoteHost = getenv('REMOTE_HOST');
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
                // Then anonymize it
                $remoteHost = getAnonymousRemoteHost($remoteHost);
        } // END - if
@@ -262,12 +268,12 @@ function detectUserAgent ($alwaysReal = FALSE) {
 }
 
 // "Getter" for referer
-function detectReferer () {
+function detectReferer ($alwaysReal = FALSE) {
        // Get remote ip from environment
        $referer = getenv('HTTP_REFERER');
 
        // Is removeip installed?
-       if (isExtensionActive('removeip')) {
+       if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
                // Then anonymize it
                $referer = getAnonymousReferer($referer);
        } // END - if
@@ -337,9 +343,9 @@ function isInstalled () {
                        // First is config
                        (
                                (
-                                       isConfigEntrySet('MXCHANGE_INSTALLED')
+                                       isConfigEntrySet('MAILER_INSTALLED')
                                ) && (
-                                       getConfig('MXCHANGE_INSTALLED') == 'Y'
+                                       getConfig('MAILER_INSTALLED') == 'Y'
                                )
                        )
                ) || (
@@ -437,6 +443,18 @@ function isDebugRegularExpressionEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Checks whether debugging of build mails is enabled
+function isDebugBuildMailsEnabled () {
+       // Is cache set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Simply check it
+               $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y'));
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Checks whether the cache instance is valid
 function isCacheInstanceValid () {
        // Is there cache?
@@ -585,7 +603,7 @@ function setWhatFromConfig ($configEntry) {
 }
 
 // Checks whether what is set and optionally aborts on miss
-function isWhatSet ($strict =  false) {
+function isWhatSet ($strict = FALSE) {
        // Check for it
        $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
 
@@ -620,7 +638,7 @@ function setAction ($newAction) {
 }
 
 // Checks whether action is set and optionally aborts on miss
-function isActionSet ($strict =  false) {
+function isActionSet ($strict = FALSE) {
        // Check for it
        $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
 
@@ -656,7 +674,7 @@ function setModule ($newModule) {
 }
 
 // Checks whether module is set and optionally aborts on miss
-function isModuleSet ($strict =  false) {
+function isModuleSet ($strict = FALSE) {
        // Check for it
        $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
 
@@ -695,7 +713,7 @@ function setOutputMode ($newOutputMode) {
 }
 
 // Checks whether output_mode is set and optionally aborts on miss
-function isOutputModeSet ($strict =  false) {
+function isOutputModeSet ($strict = FALSE) {
        // Check for it
        $isset = (isset($GLOBALS['__output_mode']));
 
@@ -750,35 +768,35 @@ function redirectToDereferedUrl ($url) {
 }
 
 // Wrapper function for checking if extension is installed and newer or same version
-function isExtensionInstalledAndNewer ($ext_name, $version) {
+function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
        // Is an cache entry found?
-       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
+       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
                // Determine it
-               $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
+               $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
        } else {
                // Cache hits should be incremented twice
                incrementStatsEntry('cache_hits', 2);
        }
 
        // Return it
-       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
-       return $GLOBALS[__FUNCTION__][$ext_name][$version];
+       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
+       return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
 }
 
 // Wrapper function for checking if extension is installed and older than given version
-function isExtensionInstalledAndOlder ($ext_name, $version) {
+function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
        // Is an cache entry found?
-       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) {
+       if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
                // Determine it
-               $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
+               $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
        } else {
                // Cache hits should be incremented twice
                incrementStatsEntry('cache_hits', 2);
        }
 
        // Return it
-       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version]));
-       return $GLOBALS[__FUNCTION__][$ext_name][$version];
+       //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
+       return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
 }
 
 // Set username
@@ -1222,6 +1240,7 @@ function getTotalConfirmedUser () {
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1238,6 +1257,7 @@ function getTotalUnconfirmedUser () {
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1254,6 +1274,7 @@ function getTotalLockedUser () {
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1270,6 +1291,7 @@ function getTotalRandomRefidUser () {
        } // END - if
 
        // Return cached value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
        return $GLOBALS[__FUNCTION__];
 }
 
@@ -1281,7 +1303,7 @@ function isValidUserId ($userid) {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__][$userid])) {
                // Check it out
-               $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0));
+               $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid != 'NULL') && ($userid > 0));
        } // END - if
 
        // Return cache
@@ -1936,79 +1958,6 @@ function getUserMinConfirmed () {
        // Return cache
        return $GLOBALS[__FUNCTION__];
 }
-
-// "Getter" for auto_purge
-function getAutoPurge () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('auto_purge');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for bonus_userid
-function getBonusUserid () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for ap_inactive_time
-function getApInactiveTime () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for ap_dm_timeout
-function getApDmTimeout () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for ap_tasks_time
-function getApTasksTime () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for ap_unconfirmed_time
-function getApUnconfirmedTime () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // "Getter" for points
 function getPoints () {
        // Is there cache?
@@ -2525,6 +2474,42 @@ function isDisplayHomeInIndexEnabled () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// Getter for 'ap_server_name_since'
+function getApServerNameSince () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Getter for 'ap_server_name'
+function getApServerName () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = getConfig('ap_server_name');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether 'ap_server_name' is 'Y'
+function isApServerNameEnabled () {
+       // Is the cache entry set?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // No, so determine it
+               $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y');
+       } // END - if
+
+       // Return cached entry
+       return $GLOBALS[__FUNCTION__];
+}
+
 // Getter for 'admin_menu_javascript'
 function getAdminMenuJavascript () {
        // Is the cache entry set?
@@ -2779,7 +2764,7 @@ function ifUserPointsLocked ($userid) {
 // This function does always add a new-line character to every line.
 function appendLineToFile ($file, $line) {
        $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
-       fwrite($fp, $line . chr(10));
+       fwrite($fp, $line . PHP_EOL);
        fclose($fp);
 }
 
@@ -2817,6 +2802,9 @@ function convertCommaToDotInPostData ($postEntry) {
        // Read and convert given entry
        $postValue = convertCommaToDot(postRequestElement($postEntry));
 
+       // Log message
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
+
        // ... and set it again
        setPostRequestElement($postEntry, $postValue);
 }
@@ -2860,33 +2848,41 @@ function parseFloat ($floatString){
  * Searches a multi-dimensional array (as used in many places) for given
  * key/value pair as taken from user comments from PHP documentation website.
  *
- * @param      $array          An array with one or more dimensions
- * @param      $key            Key to look for
- * @param      $valur          Value to look for
- * @return     $results        Resulted array or empty array if $array is no array
+ * @param      $array                  An array with one or more dimensions
+ * @param      $key                    Key to look for
+ * @param      $value                  Value to look for
+ * @param      $parentIndex    Parent index (ONLY INTERNAL USE!)
+ * @return     $results                Resulted array or empty array if $array is no array
  * @author     sunelbe<at>gmail<dot>com
  * @link       http://de.php.net/manual/en/function.array-search.php#110120
  */
-function search_array ($array, $key, $value) {
+function search_array ($array, $key, $value, $parentIndex = NULL) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
        // Init array result
        $results = array();
 
        // Is $array really an array?
        if (is_array($array)) {
-               // Does key and value match?
-               if (isset($array[$key]) && $array[$key] == $value) {
-                       // Then add it as result
-                       $results[] = $array;
-               } // END - if
-
                // Search for whole array
-               foreach ($array as $subArray) {
-                       // Search recursive and merge again
-                       $results = merge_array($results, search_array($subArray, $key, $value));
+               foreach ($array as $idx => $dummy) {
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx);
+                       // Is dummy an array?
+                       if (is_array($dummy)) {
+                               // Then search again
+                               $subResult = search_array($dummy, $key, $value, $idx);
+                               //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
+
+                               // And merge both
+                               $results = merge_array($results, $subResult, TRUE);
+                       } elseif ((isset($array[$key])) && ($array[$key] == $value)) {
+                               // Is found, so add it
+                               $results[$parentIndex] = $array;
+                       }
                } // END - foreach
        } // END - if
 
        // Return resulting array
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
        return $results;
 }