Same fix for isActionSet()
[mailer.git] / inc / wrapper-functions.php
index b3c3c1359075475571a31c68efae5c3145b8cdb1..1df653fb9bcd16d13e00ef9d72c7a603d651929a 100644 (file)
@@ -44,6 +44,12 @@ if (!defined('__SECURITY')) {
 
 // Read a given file
 function readFromFile ($FQFN, $sqlPrepare = false) {
+       // Sanity-check if file is there (should be there, but just to make it sure)
+       if (!isFileReadable($FQFN)) {
+               // This should not happen
+               debug_report_bug(__FUNCTION__.': File ' . basename($FQFN) . ' is not readable!');
+       } // END - if
+
        // Load the file
        if (function_exists('file_get_contents')) {
                // Use new function
@@ -278,7 +284,28 @@ function isInstalling () {
 
 // Check wether this script is installed
 function isInstalled () {
-       return ((getConfig('MXCHANGE_INSTALLED') == 'Y') || (isIncludeReadable('inc/cache/config-local.php')));
+       return (
+       (
+               // New config file found and loaded
+               getConfig('MXCHANGE_INSTALLED') == 'Y'
+       ) || (
+               // Fall-back!
+               isIncludeReadable('inc/config.php')
+       ) || (
+               (
+                       // New config file found, but not yet read
+                       isIncludeReadable('inc/cache/config-local.php')
+               ) && (
+                       (
+                               // Only new config file is found
+                               !isIncludeReadable('inc/config.php')
+                       ) || (
+                               // Is installation mode
+                               isInstalling()
+                       )
+               )
+       )
+       );
 }
 
 // Check wether an admin is registered
@@ -298,6 +325,12 @@ function isDebugModeEnabled () {
        return (getConfig('DEBUG_MODE') == 'Y');
 }
 
+// Checks wether we shall debug regular expressions
+function isDebugRegExpressionEnabled () {
+       // Simply check it
+       return (getConfig('DEBUG_REGEX') == 'Y');
+}
+
 // Checks wether the cache instance is valid
 function isCacheInstanceValid () {
        return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
@@ -351,14 +384,14 @@ function sendHeader ($header) {
        } // END - if
 
        // Send the header
-       header($header);
+       header(trim($header));
 }
 
 // Wrapper function for chmod()
 // @TODO Do some more sanity check here
 function changeMode ($FQFN, $mode) {
        // Is the file/directory there?
-       if ((!isFile($FQFN)) && (!isDirectory($FQFN))) {
+       if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
                // Neither, so abort here
                debug_report_bug('Cannot chmod() on ' . basename($FQFN) . '.');
        } // END - if
@@ -367,6 +400,19 @@ function changeMode ($FQFN, $mode) {
        chmod($FQFN, $mode);
 }
 
+// Wrapper for unlink()
+function removeFile ($FQFN) {
+       // Is the file there?
+       if (isFileReadable($FQFN)) {
+               // Yes, so remove it
+               return unlink($FQFN);
+       } // END - if
+
+       // All fine if no file was removed. If we change this to 'false' or rewrite
+       // above if() block it would be to restrictive.
+       return true;
+}
+
 // Wrapper for $_POST['sel']
 function countPostSelection () {
        return countSelection(REQUEST_POST('sel'));
@@ -377,5 +423,175 @@ function isConfigLocalLoaded () {
        return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
 }
 
+// Checks wether a nickname or userid was entered and caches the result
+function isNicknameUsed ($userid) {
+       // Default is false
+       $isUsed = false;
+
+       // Is the cache there
+       if (isset($GLOBALS['cache_probe_nicknames'][$userid])) {
+               // Then use it
+               $isUsed = $GLOBALS['cache_probe_nicknames'][$userid];
+       } else {
+               // Determine it
+               $isUsed = ((EXT_IS_ACTIVE('nickname')) && ((''.round($userid).'') != $userid));
+
+               // And write it to the cache
+               $GLOBALS['cache_probe_nicknames'][$userid] = $isUsed;
+       }
+
+       // Return the result
+       return $isUsed;
+}
+
+// Getter for 'what' value
+function getWhat () {
+       // Default is null
+       $what = null;
+
+       // Is the value set?
+       if (isWhatSet(true)) {
+               // Then use it
+               $what = $GLOBALS['what'];
+       } // END - if
+
+       // Return it
+       return $what;
+}
+
+// Setter for 'what' value
+function setWhat ($newWhat) {
+       $GLOBALS['what'] = SQL_ESCAPE($newWhat);
+}
+
+// Setter for 'what' from configuration
+function setWhatFromConfig ($configEntry) {
+       // Get 'what' from config
+       $what = getConfig($configEntry);
+
+       // Set it
+       setWhat($what);
+}
+
+// Checks wether what is set and optionally aborts on miss
+function isWhatSet ($abortOnMiss =  false) {
+       // Check for it
+       $isset = (isset($GLOBALS['what']));
+
+       // Should we abort here?
+       if (($abortOnMiss === true) && ($isset === false)) {
+               // Output backtrace
+               debug_report_bug('what is empty.');
+       } // END - if
+
+       // Return it
+       return $isset;
+}
+
+// Getter for 'action' value
+function getAction () {
+       // Default is null
+       $action = null;
+
+       // Is the value set?
+       if (isActionSet(true)) {
+               // Then use it
+               $action = $GLOBALS['action'];
+       } // END - if
+
+       // Return it
+       return $action;
+}
+
+// Setter for 'action' value
+function setAction ($newAction) {
+       $GLOBALS['action'] = SQL_ESCAPE($newAction);
+}
+
+// Checks wether action is set and optionally aborts on miss
+function isActionSet ($abortOnMiss =  false) {
+       // Check for it
+       $isset = (isset($GLOBALS['action']));
+
+       // Should we abort here?
+       if (($abortOnMiss === true) && ($isset === false)) {
+               // Output backtrace
+               debug_report_bug('action is empty.');
+       } // END - if
+
+       // Return it
+       return $isset;
+}
+
+// Getter for 'module' value
+function getModule () {
+       // Default is null
+       $module = null;
+
+       // Is the value set?
+       if (isModuleSet(true)) {
+               // Then use it
+               $module = $GLOBALS['module'];
+       } // END - if
+
+       // Return it
+       return $module;
+}
+
+// Setter for 'module' value
+function setModule ($newModule) {
+       $GLOBALS['module'] = SQL_ESCAPE($newModule);
+}
+
+// Checks wether module is set and optionally aborts on miss
+function isModuleSet ($abortOnMiss =  false) {
+       // Check for it
+       $isset = (!empty($GLOBALS['module']));
+
+       // Should we abort here?
+       if (($abortOnMiss === true) && ($isset === false)) {
+               // Output backtrace
+               debug_report_bug('module is empty.');
+       } // END - if
+
+       // Return it
+       return $isset;
+}
+
+// Getter for 'output_mode' value
+function getOutputMode () {
+       // Default is null
+       $output_mode = null;
+
+       // Is the value set?
+       if (isOutputModeSet(true)) {
+               // Then use it
+               $output_mode = $GLOBALS['output_mode'];
+       } // END - if
+
+       // Return it
+       return $output_mode;
+}
+
+// Setter for 'output_mode' value
+function setOutputMode ($newOutputMode) {
+       $GLOBALS['output_mode'] = SQL_ESCAPE($newOutputMode);
+}
+
+// Checks wether output_mode is set and optionally aborts on miss
+function isOutputModeSet ($abortOnMiss =  false) {
+       // Check for it
+       $isset = (isset($GLOBALS['output_mode']));
+
+       // Should we abort here?
+       if (($abortOnMiss === true) && ($isset === false)) {
+               // Output backtrace
+               debug_report_bug('output_mode is empty.');
+       } // END - if
+
+       // Return it
+       return $isset;
+}
+
 // [EOF]
 ?>