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";
41 global $EXT_CSS_FILES;
42 $EXT_CSS_FILES = array();
45 // Skip loading extensions
46 if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing'))) return;
48 // Initialize array for "always keep active extensions"
49 $cacheArray['active_extensions'] = array();
51 // By default no cache is set
57 if (EXT_IS_ACTIVE("cache")) {
58 // Load cache extension alone
59 LOAD_EXTENSION("cache");
61 // Check extension cache
62 switch (($cacheInstance->loadCacheFile("extensions", true)) && ($cacheInstance->extensionVersionMatches("sql_patches"))) {
63 case true : $cacheMode = "load"; break;
64 case false: $cacheMode = "init"; break;
67 // Do we need to init the cache?
68 if (($cacheMode == "init") && ($_CONFIG['cache_exts'] == "Y")) {
70 $cacheInstance->init("EXTENSIONS");
71 $cacheInstance->storeExtensionVersion("sql_patches");
72 } elseif ($_CONFIG['cache_exts'] == "N") {
73 // Cache will not be created for extensions
79 if ($cacheMode == "load") {
83 // Re-initialize handler
84 $cacheInstance->loadCacheFile("extensions", true);
86 // Load extension data from cache file
87 $EXT_DUMMY = $cacheInstance->getArrayFromCache();
89 // Is the cache file fine?
90 if (!isset($EXT_DUMMY['ext_name'])) {
91 // Cache file is damaged so kill it
92 $cacheInstance->destroyCacheFile();
94 // Skip any further execution
98 // Begin with the cache preparation of extensions
100 foreach ($EXT_DUMMY['ext_name'] as $k => $name) {
102 if ($EXT_DUMMY['ext_css'][$k] == "Y") $EXT_CSS_FILES[] = "".$name.".css";
104 // Load extension file itself
105 if (($EXT_DUMMY['ext_active'][$k] == "Y") || ($EXT_DUMMY['ext_keep'][$k] == "Y") || (IS_ADMIN())) {
110 $EXT_DUMMY['ext_version'][$name] = $EXT_DUMMY['ext_version'][$k];
111 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]);
118 $EXT_DUMMY['ext_menu'][$name] = $EXT_DUMMY['ext_menu'][$k];
119 unset($EXT_DUMMY['ext_menu'][$k]);
122 $EXT_DUMMY['ext_id'][$name] = $EXT_DUMMY['ext_id'][$k];
123 $id = $EXT_DUMMY['ext_id'][$name];
124 unset($EXT_DUMMY['ext_id'][$k]);
127 $EXT_NAMES[$id] = $name;
129 // Add deprecated flag (defaults to "not deprecated")
130 $EXT_DUMMY['ext_deprecated'][$name] = "N";
132 // Mark it as active extension
133 $cacheArray['active_extensions']['$name'] = $EXT_DUMMY['ext_keep'][$k];
134 unset($EXT_DUMMY['ext_keep'][$k]);
136 // Remove unneccessary data from memory
137 unset($EXT_DUMMY['ext_css'][$k]);
140 // Write dummy array back
141 $EXT_DUMMY['ext_name'] = $EXT_NAMES;
144 // Loading cache is done so let's free some memory!
145 unset($EXT_DUMMY['ext_keep']);
146 unset($EXT_DUMMY['ext_css']);
147 $cacheArray['extensions'] = $EXT_DUMMY;
150 // No database load needed
151 $res_ext_crt = false;
153 // Load more cache files (like admins)
154 require_once(PATH."inc/load_cache.php");
156 // Load all extension files
157 foreach ($EXT_POOL as $ext) {
158 LOAD_EXTENSION($ext);
164 // If current user is not admin load only activated extensions. But load
165 // them all if we are going to init the cache files. The admin shall use
166 // every available extension for testing purposes.
167 if ((!IS_ADMIN()) && ($cacheMode != "init")) $ADD = " WHERE ext_active='Y'";
169 if (GET_EXT_VERSION("sql_patches") >= "0.0.6") {
170 // Query with CSS file from DB
171 $res_ext_crt = SQL_QUERY("SELECT id AS ext_id, ext_name, ext_has_css AS ext_css, ext_active, ext_version
172 FROM "._MYSQL_PREFIX."_extensions".$ADD."
173 ORDER BY ext_name", __FILE__, __LINE__);
175 // Old obsolete query string
176 $res_ext_crt = SQL_QUERY("SELECT id AS ext_id, ext_name, ext_name, ext_active, ext_version
177 FROM "._MYSQL_PREFIX."_extensions".$ADD."
178 ORDER BY ext_name", __FILE__, __LINE__);
182 // Array for removed but not uninstalled extensions
185 // At least one found?
186 if ((SQL_NUMROWS($res_ext_crt) > 0) && ((($cacheMode == "init") && ($CSS != "1") && ($CSS != "-1")) || ($cacheMode == "no"))) {
187 // Load theme management
188 require_once(PATH."inc/theme-manager.php");
190 // Extensions are registered so we load them
191 while ($content = SQL_FETCHARRAY($res_ext_crt)) {
193 $content['ext_menu'] = "N";
194 if (MODULE_HAS_MENU($content['ext_name'], true)) {
195 $content['ext_menu'] = "Y";
199 $file1 = sprintf("%sinc/extensions/ext-%s.php", PATH, $content['ext_name']);
200 $EXT_CSS = "N"; $EXT_ALWAYS_ACTIVE = "N";
202 // Does the extension file exists?
203 if (FILE_READABLE($file1)) {
204 // By default no extension is always active, except sql_patches
205 $EXT_ALWAYS_ACTIVE = "N";
208 if (($content['ext_name'] != "sql_patches") && (($content['ext_name'] == "cache") || (!EXT_IS_ACTIVE("cache")))) {
210 LOAD_EXTENSION($content['ext_name']);
212 // Keep sql_patches always active
213 $EXT_ALWAYS_ACTIVE = "Y";
216 // Transfer EXT_ALWAYS_ACTIVE flag
217 $content['ext_keep'] = $EXT_ALWAYS_ACTIVE;
219 // CSS file handling:
220 if ((!isset($content['ext_css'])) || ($content['ext_css'] == "Y")) {
221 // Create FQFN for the CSS file
222 $CSS_FILE = sprintf("%stheme/%s/css/%s.css", PATH, GET_CURR_THEME(), $content['ext_name']);
224 // Is the file there?
225 if (FILE_READABLE($CSS_FILE)) {
226 // CSS file for extension was found (use only relative path for now!)
227 $EXT_CSS_FILES[] = $content['ext_name'].".css";
228 $content['ext_css'] = "Y";
230 // Don't load CSS file
231 $content['ext_css'] = "N";
236 if ($cacheMode == "init") {
238 $cacheInstance->addRow($content);
239 } elseif ($cacheMode == "no") {
240 // Remember this value for later usage
241 $cacheArray['active_extensions'][$content['ext_name']] = $EXT_ALWAYS_ACTIVE;
243 } elseif (!FILE_READABLE($file1)) {
244 // Deleted extension file so we mark it for removal from DB
245 $DEL[] = $content['ext_name'];
249 if ($cacheMode == "init") {
251 $cacheInstance->finalize();
253 // Load more cache files (like admins)
254 require_once(PATH."inc/load_cache.php");
258 SQL_FREERESULT($res_ext_crt);
261 // Load include files if found
262 if (!empty($INC_POOL[0])) {
263 foreach ($INC_POOL as $inc) {
271 // Uninstall extensions that are no longer in our system
272 if (!empty($DEL[0])) {
273 // Remove extensions from two tables: extension registry and tasks table
274 foreach ($DEL as $del_ext) {
275 // First remove entry from extensions table
276 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
277 array($del_ext), __FILE__, __LINE__);
279 // Remove (maybe?) found tasks (main task and possible updates
280 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE subject LIKE '[%s:]%%' AND (task_type='EXTENSION' OR task_type='EXTENSION_UPDATE')",
281 array($del_ext), __FILE__, __LINE__);
284 // I think it's not neccessary to run the optimization function here
285 // because we didn't delete so much data from database. Can you aggree?