2 /************************************************************************
3 * MXChange v0.2.1 Start: 06/26/2004 *
4 * =============== Last change: 07/01/2005 *
6 * -------------------------------------------------------------------- *
7 * File : load_extensions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Load all extensions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Alle Erweiterungen laden *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 global $EXT_CSS_FILES;
41 $EXT_CSS_FILES = array();
44 // Skip loading extensions
45 if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return;
47 // Load default sql_patches extension if present
48 if (FILE_READABLE(PATH."inc/extensions/ext-sql_patches.php")) {
51 require_once(PATH."inc/extensions/ext-sql_patches.php");
52 $cacheArray['active_extensions'] = array('sql_patches' => 'Y'); // KEEP THIS ALWAYS ACTIVE!
54 // Initialize array for "always keep active extensions"
55 $cacheArray['active_extensions'] = array();
61 if (EXT_IS_ACTIVE("cache")) {
62 // Load cache extension alone
63 include_once(PATH."inc/libs/cache_functions.php");
65 include_once(PATH."inc/extensions/ext-cache.php");
66 switch($cacheInstance->cache_file("extensions", true)) {
67 case true : $cacheMode = "load"; break;
68 case false: $cacheMode = "init"; break;
71 // Do not recreate cache file when it's switched off!
72 if (($cacheMode == "init") && ($_CONFIG['cache_exts'] == "N")) $cacheMode = "skip";
75 if ($cacheMode == "load") include(PATH."inc/language/cache_".GET_LANGUAGE().".php");
77 // Cache extension not active
81 if ($cacheMode == "load") {
82 // Re-initialize handler
83 $cacheInstance->cache_file("extensions", true);
85 // Load extension data from cache file
86 $EXT_DUMMY = $cacheInstance->cache_load();
88 // Begin with the cache preparation of extensions
90 foreach ($EXT_DUMMY['ext_name'] as $k => $name) {
91 // Load functions file
92 if ($EXT_DUMMY['ext_funcs'][$k] == "Y") {
93 require_once(PATH."inc/libs/".$name."_functions.php");
97 if ($EXT_DUMMY['ext_lang'][$k] == "Y") {
98 $INC = sprintf("%sinc/language/%s_%s.php", PATH, $name, GET_LANGUAGE());
99 if (FILE_READABLE($INC)) require_once($INC);
103 if ($EXT_DUMMY['ext_css'][$k] == "Y") $EXT_CSS_FILES[] = "".$name.".css";
105 // Load extension file itself
106 if (($EXT_DUMMY['ext_active'][$k] == "Y") || ($EXT_DUMMY['ext_keep'][$k] == "Y") || (IS_ADMIN())) {
107 require_once(PATH."inc/extensions/ext-".$name.".php");
111 $EXT_DUMMY['ext_version'][$name] = $EXT_DUMMY['ext_version'][$k];
112 unset($EXT_DUMMY['ext_version'][$k]);
113 // Extension is active
114 $EXT_DUMMY['ext_active'][$name] = $EXT_DUMMY['ext_active'][$k];
115 unset($EXT_DUMMY['ext_active'][$k]);
117 $EXT_DUMMY['ext_menu'][$name] = $EXT_DUMMY['ext_menu'][$k];
118 unset($EXT_DUMMY['ext_menu'][$k]);
120 $EXT_DUMMY['ext_id'][$name] = $EXT_DUMMY['ext_id'][$k];
121 $id = $EXT_DUMMY['ext_id'][$name];
122 unset($EXT_DUMMY['ext_id'][$k]);
125 $EXT_NAMES[$id] = $name;
127 // Mark it as active extension
128 $cacheArray['active_extensions']['$name'] = $EXT_DUMMY['ext_keep'][$k];
129 unset($EXT_DUMMY['ext_keep'][$k]);
131 // Remove unneccessary data from memory
132 unset($EXT_DUMMY['ext_lang'][$k]);
133 unset($EXT_DUMMY['ext_css'][$k]);
134 unset($EXT_DUMMY['ext_funcs'][$k]);
137 // Write dummy array back
138 $EXT_DUMMY['ext_name'] = $EXT_NAMES;
142 $cacheInstance->cache_close();
144 // Loading cache is done so let's free some memory!
145 unset($EXT_DUMMY['ext_lang']);
146 unset($EXT_DUMMY['ext_keep']);
147 unset($EXT_DUMMY['ext_css']);
148 unset($EXT_DUMMY['ext_funcs']);
149 $cacheArray['extensions'] = $EXT_DUMMY;
152 // No database load needed
153 $res_ext_crt = false;
155 // Load more cache files (like admins)
156 require_once(PATH."inc/load_cache.php");
158 // If current user is not admin load only activated extensions
159 // The admin shall use every available extension for testing purposes
160 if ((!IS_ADMIN()) && ($cacheMode != "init")) $ADD = " WHERE ext_active='Y'";
162 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
163 // Query with CSS file from DB
164 $res_ext_crt = SQL_QUERY("SELECT id, ext_name, ext_lang_file, ext_has_css, ext_active, ext_version
165 FROM "._MYSQL_PREFIX."_extensions".$ADD."
166 ORDER BY ext_name", __FILE__, __LINE__);
168 // Old obsulete query string
169 $res_ext_crt = SQL_QUERY("SELECT id, ext_name, ext_lang_file, ext_name, ext_active, ext_version
170 FROM "._MYSQL_PREFIX."_extensions".$ADD."
171 ORDER BY ext_name", __FILE__, __LINE__);
175 // Array for removed but not uninstalled extensions
178 // At least one found?
179 if ((SQL_NUMROWS($res_ext_crt) > 0) && (($cacheMode == "init") || ($cacheMode == "no")) && ($CSS != "1") && ($CSS != "-1")) {
180 // Load theme management
181 require_once(PATH."inc/theme-manager.php");
183 // If we need to init the cache init it now
184 if ($cacheMode == "init") $cacheInstance->cache_init("EXTENSIONS");
186 // Extensions are registered so we load them
187 while (list($EXT_ID, $name, $lang, $css, $active, $version) = SQL_FETCHROW($res_ext_crt)) {
190 if (MODULE_HAS_MENU($name, true)) {
195 $file1 = sprintf("%sinc/extensions/ext-%s.php", PATH, $name);
196 $file2 = $file1; $EXT_CSS = "N"; $EXT_ALWAYS_ACTIVE = "N";
198 // Special functions file
199 $file3 = sprintf("%sinc/libs/%s_functions.php", PATH, $name);
201 // Does the extension file exists?
202 if (FILE_READABLE($file1)) {
203 // If there's no language file specified we don't need to load one... ;-)
205 // Create language file
206 $file2 = sprintf("%sinc/language/%s_%s.php", PATH, $lang, GET_LANGUAGE());
209 if (FILE_READABLE($file3)) {
210 // Special functions file
212 require_once($file3);
214 // Don't load functions file
218 // Do we need a language file?
219 if (($file1 != $file2) && (FILE_READABLE($file2))) {
220 // Load language file
224 // Don't load language file
229 if ($name != "sql_patches") {
230 // Load extension's file
231 include_once($file1);
233 // KEEP sql_patches ALWAYS ACTIVE!
234 $EXT_ALWAYS_ACTIVE = "Y";
238 $CSS_FILE = sprintf("%stheme/%s/css/%s.css", PATH, GET_CURR_THEME(), $name);
239 if (FILE_READABLE($CSS_FILE)) {
240 // CSS file for extension was found (use only relative path for now!)
241 $EXT_CSS_FILES[] = $name.".css";
243 // Don't load CSS file
249 if ($cacheMode == "init") {
250 $cacheInstance->add_row(array(
256 'ext_funcs' => $funcs,
257 'ext_active' => $active,
258 'ext_version' => $version,
259 'ext_keep' => $EXT_ALWAYS_ACTIVE,
261 } elseif ($cacheMode == "no") {
262 // Remember this value for later usage
263 $cacheArray['active_extensions'][$name] = $EXT_ALWAYS_ACTIVE;
265 } elseif (!FILE_READABLE($file1)) {
266 // Deleted extension file so we mark it for removal from DB
271 if ($cacheMode == "init") {
273 $cacheInstance->cache_close();
275 // Load more cache files (like admins)
276 require_once(PATH."inc/load_cache.php");
281 SQL_FREERESULT($res_ext_crt);
283 // Load include files
284 if (!empty($INC_POOL[0])) {
285 foreach ($INC_POOL as $inc) {
290 // Uninstall extensions that are no longer in our system
291 if (!empty($DEL[0])) {
292 // Remove extensions from two tables: extension registry and tasks table
293 foreach ($DEL as $name) {
294 // First remove entry from extensions table
295 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
296 array($name), __FILE__, __LINE__);
298 // Remove (maybe?) found tasks (main task and possible updates
299 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE subject LIKE '[%s:] %' AND (task_type='EXTENSION' OR task_type='EXTENSION_UPDATE')",
300 array($name), __FILE__, __LINE__);
303 // I think it's not neccessary to run the optimization function here
304 // because we didn't delete so much data from database. Can you aggree?