Fixes for sending pool
[mailer.git] / inc / load_extensions.php
index 88e4a469f22e6b7f85a59edfb104f3f5955b9cfb..bc9a4a5bb4c4cdfe24efc839c990a9a14c289d2c 100644 (file)
@@ -32,8 +32,7 @@
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
@@ -43,10 +42,10 @@ $EXT_CSS_FILES = array();
 $ADD = "";
 
 // Skip loading extensions
-if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return;
+if ((!defined('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return;
 
 // Load default sql_patches extension if present
-if (file_exists(PATH."inc/extensions/ext-sql_patches.php") && is_readable(PATH."inc/extensions/ext-sql_patches.php")) {
+if (FILE_READABLE(PATH."inc/extensions/ext-sql_patches.php")) {
        // Load it...
        $EXT_LOAD_MODE = "";
        require_once(PATH."inc/extensions/ext-sql_patches.php");
@@ -80,16 +79,15 @@ if (EXT_IS_ACTIVE("cache")) {
 }
 
 if ($cacheMode == "load") {
-       // Load more cache files (like admins)
-       require_once(PATH."inc/load_cache.php");
-
        // Re-initialize handler
        $cacheInstance->cache_file("extensions", true);
 
        // Load extension data from cache file
        $EXT_DUMMY = $cacheInstance->cache_load();
+
+       // Begin with the cache preparation of extensions
        $EXT_NAMES = array();
-       foreach ($EXT_DUMMY['ext_name'] as $k=>$name) {
+       foreach ($EXT_DUMMY['ext_name'] as $k => $name) {
                // Load functions file
                if ($EXT_DUMMY['ext_funcs'][$k] == "Y") {
                        require_once(PATH."inc/libs/".$name."_functions.php");
@@ -98,7 +96,7 @@ if ($cacheMode == "load") {
                // Load Language file
                if ($EXT_DUMMY['ext_lang'][$k] == "Y") {
                        $INC = sprintf("%sinc/language/%s_%s.php", PATH, $name, GET_LANGUAGE());
-                       if (file_exists($INC)) require_once($INC);
+                       if (FILE_READABLE($INC)) require_once($INC);
                } // END - if
 
                // Load CSS file
@@ -153,6 +151,9 @@ if ($cacheMode == "load") {
 
        // No database load needed
        $res_ext_crt = false;
+
+       // Load more cache files (like admins)
+       require_once(PATH."inc/load_cache.php");
 } else {
        // If current user is not admin load only activated extensions
        // The admin shall use every available extension for testing purposes
@@ -186,7 +187,7 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode ==
        while (list($EXT_ID, $name, $lang, $css, $active, $version) = SQL_FETCHROW($res_ext_crt)) {
                // Get menu entry
                $menu = "N";
-               if (MODULE_HAS_MENU($name)) {
+               if (MODULE_HAS_MENU($name, true)) {
                        $menu = "Y";
                } // END - if
 
@@ -198,14 +199,14 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode ==
                $file3 = sprintf("%sinc/libs/%s_functions.php", PATH, $name);
 
                // Does the extension file exists?
-               if (file_exists($file1) && is_readable($file1)) {
+               if (FILE_READABLE($file1)) {
                        // If there's no language file specified we don't need to load one... ;-)
                        if (!empty($lang)) {
                                // Create language file
                                $file2 = sprintf("%sinc/language/%s_%s.php", PATH, $lang, GET_LANGUAGE());
                        }
 
-                       if (file_exists($file3) && is_readable($file3)) {
+                       if (FILE_READABLE($file3)) {
                                // Special functions file
                                $funcs = "Y";
                                require_once($file3);
@@ -215,7 +216,7 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode ==
                        }
 
                        // Do we need a language file?
-                       if (($file1 != $file2) && (file_exists($file2)) && (is_readable($file2))) {
+                       if (($file1 != $file2) && (FILE_READABLE($file2))) {
                                // Load language file
                                $lang = "Y";
                                include($file2);
@@ -235,7 +236,7 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode ==
 
                        if ($css == "Y") {
                                $CSS_FILE = sprintf("%stheme/%s/css/%s.css", PATH, GET_CURR_THEME(), $name);
-                               if (file_exists($CSS_FILE)) {
+                               if (FILE_READABLE($CSS_FILE)) {
                                        // CSS file for extension was found (use only relative path for now!)
                                        $EXT_CSS_FILES[] = $name.".css";
                                } else {
@@ -261,7 +262,7 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode ==
                                // Remember this value for later usage
                                $cacheArray['active_extensions'][$name] = $EXT_ALWAYS_ACTIVE;
                        }
-               } elseif (!file_exists($file1)) {
+               } elseif (!FILE_READABLE($file1)) {
                        // Deleted extension file so we mark it for removal from DB
                        $DEL[] = $name;
                }
@@ -274,10 +275,10 @@ if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode ==
                // Load more cache files (like admins)
                require_once(PATH."inc/load_cache.php");
        } // END - if
-}
 
-// Free memory
-SQL_FREERESULT($res_ext_crt);
+       // Free memory
+       SQL_FREERESULT($res_ext_crt);
+}
 
 // Load include files
 if (!empty($INC_POOL[0])) {
@@ -291,12 +292,12 @@ if (!empty($DEL[0])) {
        // Remove extensions from two tables: extension registry and tasks table
        foreach ($DEL as $name) {
                // First remove entry from extensions table
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
-                array($name), __FILE__, __LINE__);
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
+                       array($name), __FILE__, __LINE__);
 
                // Remove (maybe?) found tasks (main task and possible updates
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE subject LIKE '[%s:] %' AND (task_type='EXTENSION' OR task_type='EXTENSION_UPDATE')",
-                array($name), __FILE__, __LINE__);
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE subject LIKE '[%s:] %' AND (task_type='EXTENSION' OR task_type='EXTENSION_UPDATE')",
+                       array($name), __FILE__, __LINE__);
        } // END - foreach
 
        // I think it's not neccessary to run the optimization function here