More rewrites of constants and fix for loading mass-included scripts by GET_DIR_AS_AR...
[mailer.git] / inc / functions.php
index f353494c6dfd451aeb50a8a1e3dffcfbb00861bd..7d96a7ed02e20f7a8627474bd08c1c7a6bafe269 100644 (file)
@@ -356,7 +356,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
 
                // Add surrounding HTML comments to help finding bugs faster
                $ret = "<!-- Template ".$template." - Start -->\n".$ret."<!-- Template ".$template." - End -->\n";
-       } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isBooleanConstantAndTrue('mxchange_installed')))) {
+       } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
                // Only admins shall see this warning or when installation mode is active
                $ret = "<br /><span class=\"guest_failed\">".TEMPLATE_404."</span><br />
 (".basename($FQFN).")<br />
@@ -925,6 +925,7 @@ function LOAD_URL ($URL, $addUrlData=true) {
 
        // Get output buffer
        //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
+       DEBUG_LOG(__FUNCTION__, __LINE__, $URL);
        $OUTPUT = ob_get_contents();
 
        // Clear it only if there is content
@@ -2377,7 +2378,7 @@ function GET_CURR_THEME() {
                        // Fix it to default
                        $ret = "default";
                } // END - if
-       } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isInstalling()) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) {
+       } elseif ((!isInstalled()) && ((isInstalling()) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) {
                // Prepare FQFN for checking
                $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), REQUEST_GET(('theme')));
 
@@ -2982,13 +2983,13 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
        $INCs = array();
 
        // Open directory
-       $dirPointer = opendir($baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
+       $dirPointer = opendir(constant('PATH') . $baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
 
        // Read all entries
        while ($baseFile = readdir($dirPointer)) {
                // Load file only if extension is active
-               // Make full path
-               $FQFN = $baseDir.$baseFile;
+               $INC = $baseDir.$baseFile;
+               $FQFN = constant('PATH') . $INC;
 
                // Is this a valid reset file?
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}<br />\n";
@@ -3002,10 +3003,10 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
                        // Is the extension valid and active?
                        if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
                                // Then add this file
-                               $INCs[] = $FQFN;
+                               $INCs[] = $INC;
                        } elseif ($extId == 0) {
                                // Add non-extension files as well
-                               $INCs[] = $FQFN;
+                               $INCs[] = $INC;
                        }
                } // END - if
        } // END - while
@@ -3029,7 +3030,7 @@ function RESET_ADD_INCLUDES () {
        } // END - if
 
        // Get more daily reset scripts
-       $INC_POOL = GET_DIR_AS_ARRAY(constant('PATH')."inc/reset/", "reset_");
+       $INC_POOL = GET_DIR_AS_ARRAY("inc/reset/", "reset_");
 
        // Update database
        if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time());
@@ -3040,7 +3041,7 @@ function RESET_ADD_INCLUDES () {
        // Has it changed?
        if (getConfig('last_week') != $currWeek) {
                // Include weekly reset scripts
-               $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/weekly/", "weekly_"));
+               $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/weekly/", "weekly_"));
 
                // Update config
                if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek);
@@ -3052,7 +3053,7 @@ function RESET_ADD_INCLUDES () {
        // Has it changed?
        if (getConfig('last_month') != $currMonth) {
                // Include monthly reset scripts
-               $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/monthly/", "monthly_"));
+               $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/monthly/", "monthly_"));
 
                // Update config
                if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth);
@@ -3392,6 +3393,16 @@ function isInstalling () {
        return (isset($GLOBALS['mxchange_installing']));
 }
 
+// Check wether this script is installed
+function isInstalled () {
+       return isBooleanConstantAndTrue('mxchange_installed');
+}
+
+// Check wether an admin is registered
+function isAdminRegistered () {
+       return isBooleanConstantAndTrue('admin_registered');
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////