Added encryption stuff + rewrote sendWernisApiRequest() to handle the decryption.
[mailer.git] / inc / wrapper-functions.php
index 9eee082a5fb26ac7d776654bca2d5d5ffd5d958c..ab921c4b4f0752a52a4cfc376ae54f528d27748e 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Wrapper-Funktionen                               *
  * -------------------------------------------------------------------- *
- * $Revision::                                                        $ *
- * $Date::                                                            $ *
- * $Tag:: 0.2.1-FINAL                                                 $ *
- * $Author::                                                          $ *
- * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -66,7 +61,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 or cannot change CHMOD to 0644.", basename($FQFN)));
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf('File %s not writeable or cannot change CHMOD to 0644.', basename($FQFN)));
 
                // Failed! :(
                return FALSE;
@@ -157,10 +152,10 @@ function merge_array ($array1, $array2, $keepIndex = FALSE) {
                reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
        } elseif (!is_array($array1)) {
                // Left one is not an array
-               reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
+               reportBug(__FUNCTION__, __LINE__, sprintf('array1 is not an array. array != %s', gettype($array1)));
        } elseif (!is_array($array2)) {
                // Right one is not an array
-               reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
+               reportBug(__FUNCTION__, __LINE__, sprintf('array2 is not an array. array != %s', gettype($array2)));
        }
 
        // Maintain index of array2?
@@ -527,7 +522,7 @@ function isDebugBuildMailsEnabled () {
 }
 
 // Checks whether the cache instance is valid
-function isCacheInstanceValid () {
+function isValidCacheInstance () {
        // Is there cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
@@ -1004,6 +999,9 @@ function setAdminMd5 ($adminMd5) {
        // Set session
        $status = setSession('admin_md5', $adminMd5);
 
+       // Remove cache to get correct results
+       unset($GLOBALS['isAdmin']);
+
        // Return status
        return $status;
 }
@@ -1085,7 +1083,7 @@ function getUserDataArray () {
 
 // Checks if the user data is valid, this may indicate that the user has logged
 // in, but you should use isMember() if you want to find that out.
-function isUserDataValid () {
+function isValidUserData () {
        // User id should not be zero so abort here
        if (!isCurrentUserIdSet()) {
                // Debug message, may be noisy
@@ -1261,6 +1259,8 @@ function getHttpStatus () {
  * @access  private
  */
 function sendRawRedirect ($url) {
+       //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
+
        // Clear output buffer
        clearOutputBuffer();
 
@@ -1278,6 +1278,7 @@ function sendRawRedirect ($url) {
 
        // Revert entity &
        $url = str_replace('&', '&', $url);
+       //* DEBUG-DIE */ die(__METHOD__ . ':url=' . $url);
 
        // check if running on IIS < 6 with CGI-PHP
        if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
@@ -1421,30 +1422,6 @@ function encodeEntities ($str) {
        return $str;
 }
 
-// "Getter" for date from patch_ctime
-function getDateFromRepository () {
-       // Is it cached?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Then set it
-               $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
-// "Getter" for date/time from patch_ctime
-function getDateTimeFromRepository () {
-       // Is it cached?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Then set it
-               $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // Getter for current year (default)
 function getYear ($timestamp = NULL) {
        // Is it cached?
@@ -1793,6 +1770,18 @@ function getCachePath () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for cache_extension
+function getCacheExtension () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('CACHE_EXTENSION');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // "Getter" for WRITE_FOOTER
 function getWriteFooter () {
        // Is there cache?
@@ -1901,6 +1890,18 @@ function getTableType () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for db_type
+function getDbType () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('_DB_TYPE');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // "Getter" for salt_length
 function getSaltLength () {
        // Is there cache?
@@ -1949,18 +1950,6 @@ function getTitle () {
        return $GLOBALS[__FUNCTION__];
 }
 
-// "Getter" for curr_svn_revision
-function getCurrentRepositoryRevision () {
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__])) {
-               // Determine it
-               $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
-       } // END - if
-
-       // Return cache
-       return $GLOBALS[__FUNCTION__];
-}
-
 // "Getter" for server_url
 function getServerUrl () {
        // Is there cache?
@@ -3502,7 +3491,7 @@ function shift_array (&$array, $value, $key = '0') {
 // Wrapper for str_pad() with left padding zeros
 function padLeftZero ($str, $amount = 2) {
        // Is str_pad() there?
-       if (function_exists('str_pad')) {
+       if (!function_exists('str_pad')) {
                // Use prependZeros()
                return prependZeros($str, $amount);
        } else {
@@ -3556,5 +3545,48 @@ function ifSubjectHasReferralSuffix ($subject) {
        return $GLOBALS[__FUNCTION__][$subject];
 }
 
+// Converts an API response to an associative array
+function convertApiResponseToArray ($responseString, $keyDelimiter, $valueDelimiter) {
+       // Explode for key delimiter
+       $keys = explode($keyDelimiter, $responseString);
+
+       // Init returned array and "walk" through all entries
+       $returned = array();
+       foreach ($keys as $keyValue) {
+               // Explode it
+               $parts = explode($valueDelimiter, $keyValue);
+
+               // Count must be 2
+               assert(count($parts) == 2);
+
+               // Then add both: 0=key, 1=value
+               $returned[sqlEscapeString($parts[0])] = sqlEscapeString($parts[1]);
+       } // END - if
+
+       // Return finished array
+       return $returned;
+}
+
+// Getter for full (generic) hash file name
+function getGenericHashFileName () {
+       // Return result
+       return sprintf('%s%s.%s%s', getPath(), getCachePath(), getFileHash(), getCacheExtension());
+}
+
+// "Compiles" the given value and sets it in given key
+function setSessionCompiled ($key, $value) {
+       // Debug message
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key[]=' . gettype($key) . ',value[]=' . gettype($value));
+
+       // Is the value not an array?
+       if (!is_array($value)) {
+               // "Compile" the value
+               $value = doFinalCompilation(compileRawCode($value));
+       } // END - if
+
+       // And set it
+       return setSession($key, $value);
+}
+
 // [EOF]
 ?>