2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 06/26/2004 *
\r
4 * =============== Last change: 07/01/2005 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : load_extensions.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Load all extensions *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Alle Erweiterungen laden *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
\r
41 global $EXT_CSS_FILES;
\r
42 $EXT_CSS_FILES = array();
\r
45 // Skip loading extensions
\r
46 if ((!mxchange_installed) || (mxchange_installing)) return;
\r
48 // Load default sql_patches extension if present
\r
49 if (file_exists(PATH."inc/extensions/ext-sql_patches.php") && is_readable(PATH."inc/extensions/ext-sql_patches.php"))
\r
52 $EXT_LOAD_MODE = "";
\r
53 require_once(PATH."inc/extensions/ext-sql_patches.php");
\r
54 $KEEP_ACTIVE = array('sql_patches' => "Y"); // KEEP THIS ALWAYS ACTIVE!
\r
58 // Initialize array for "always keep active extensions"
\r
59 $KEEP_ACTIVE = array();
\r
65 if (EXT_IS_ACTIVE("cache"))
\r
67 // Load cache extension alone
\r
68 include_once(PATH."inc/libs/cache_functions.php");
\r
70 include_once(PATH."inc/extensions/ext-cache.php");
\r
71 switch($CACHE->cache_file("extensions", true))
\r
73 case true : $CACHE_FILE = "load"; break;
\r
74 case false: $CACHE_FILE = "init"; break;
\r
77 // Do not recreate cache file when it's switched off!
\r
78 if (($CACHE_FILE == "init") && ($CONFIG['cache_exts'] == "N")) $CACHE_FILE = "skip";
\r
81 if ($CACHE_FILE == "load") include(PATH."inc/language/cache_".GET_LANGUAGE().".php");
\r
88 if ($CACHE_FILE == "load")
\r
90 // Load more cache files (like admins)
\r
91 require_once(PATH."inc/load_cache.php");
\r
93 // Re-initialize handler
\r
94 $CACHE->cache_file("extensions", true);
\r
96 // Load extension data from cache file
\r
97 $EXT_DUMMY = $CACHE->cache_load();
\r
98 foreach ($EXT_DUMMY['ext_name'] as $k=>$name)
\r
100 // Load functions file
\r
101 if ($EXT_DUMMY['ext_funcs'][$k] == "Y") require_once(PATH."inc/libs/".$name."_functions.php");
\r
103 // Load Language file
\r
104 if ($EXT_DUMMY['ext_lang'][$k] == "Y")
\r
106 $INC = sprintf(PATH."inc/language/%s_%s.php", $name, GET_LANGUAGE());
\r
107 if (file_exists($INC)) require_once($INC);
\r
111 if ($EXT_DUMMY['ext_css'][$k] == "Y") $EXT_CSS_FILES[] = "".$name.".css";
\r
113 // Load extension file itself
\r
114 if (($EXT_DUMMY['ext_active'][$k] == "Y") || ($EXT_DUMMY['ext_keep'][$k] == "Y") || (IS_ADMIN()))
\r
116 require_once(PATH."inc/extensions/ext-".$name.".php");
\r
119 // Transfer version number and active status
\r
120 $EXT_DUMMY['ext_version'][$name] = $EXT_DUMMY['ext_version'][$k];
\r
121 unset($EXT_DUMMY['ext_version'][$k]);
\r
122 $EXT_DUMMY['ext_active'][$name] = $EXT_DUMMY['ext_active'][$k];
\r
123 unset($EXT_DUMMY['ext_active'][$k]);
\r
124 $EXT_DUMMY['ext_menu'][$name] = $EXT_DUMMY['ext_menu'][$k];
\r
125 unset($EXT_DUMMY['ext_menu'][$k]);
\r
126 $KEEP_ACTIVE['$name'] = $EXT_DUMMY['ext_keep'][$k];
\r
127 unset($EXT_DUMMY['ext_keep'][$k]);
\r
128 $k2 = $EXT_DUMMY['ext_id'][$k];
\r
129 $EXT_DUMMY['ext_id'][$k2] = $name;
\r
130 if ($k2 != $k) unset($EXT_DUMMY['ext_id'][$k]);
\r
132 // Remove unneccessary data from memory
\r
133 unset($EXT_DUMMY['ext_lang'][$k]);
\r
134 unset($EXT_DUMMY['ext_css'][$k]);
\r
135 unset($EXT_DUMMY['ext_funcs'][$k]);
\r
138 // Close cache file
\r
139 $CACHE->cache_close();
\r
141 // Loading cache is done so let's free some memory!
\r
142 unset($EXT_DUMMY['ext_lang']);
\r
143 unset($EXT_DUMMY['ext_keep']);
\r
144 unset($EXT_DUMMY['ext_css']);
\r
145 unset($EXT_DUMMY['ext_funcs']);
\r
146 $EXTENSIONS = $EXT_DUMMY;
\r
149 // No database load needed
\r
150 $res_ext_crt = false;
\r
154 // If current user is not admin load only activated extensions
\r
155 // The admin shall use every available extension for testing purposes
\r
156 if (!IS_ADMIN()) $ADD = " WHERE ext_active='Y'";
\r
158 if (GET_EXT_VERSION("sql_patches") >= "0.0.6")
\r
160 // Query with CSS file from DB
\r
161 $res_ext_crt = SQL_QUERY("SELECT id, ext_name, ext_lang_file, ext_has_css, ext_active, ext_version
\r
162 FROM "._MYSQL_PREFIX."_extensions".$ADD."
\r
163 ORDER BY ext_name", __FILE__, __LINE__);
\r
167 // Old obsulete query string
\r
168 $res_ext_crt = SQL_QUERY("SELECT id, ext_name, ext_lang_file, ext_name, ext_active, ext_version
\r
169 FROM "._MYSQL_PREFIX."_extensions".$ADD."
\r
170 ORDER BY ext_name", __FILE__, __LINE__);
\r
174 // Array for removed but not uninstalled extensions
\r
177 // At least one found?
\r
178 if ((SQL_NUMROWS($res_ext_crt) > 0) && (($CACHE_FILE == "init") || ($CACHE_FILE == "no")) && ($CSS != "1") && ($CSS != "-1"))
\r
180 // Load theme management
\r
181 require_once(PATH."inc/theme-manager.php");
\r
183 // If we need to init the cache init it now
\r
184 if ($CACHE_FILE == "init") $CACHE->cache_init("EXTENSIONS");
\r
186 // Extensions are registered so we load them
\r
187 while (list($EXT_ID, $name, $lang, $css, $active, $version) = SQL_FETCHROW($res_ext_crt))
\r
190 $result_menu = SQL_QUERY_ESC("SELECT has_menu FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1",
\r
191 array($name), __FILE__, __LINE__);
\r
192 list($menu) = SQL_FETCHROW($result_menu);
\r
193 //* DEBUG: */ echo "*".$name."/".$menu."*<br>";
\r
195 // An empty menu entry will be interpreted as N (no menu) to avoid problems
\r
196 if (empty($menu)) $menu = "N";
\r
199 $file1 = sprintf(PATH."inc/extensions/ext-%s.php", $name);
\r
200 $file2 = $file1; $EXT_CSS = "N"; $EXT_ALWAYS_ACTIVE = "N";
\r
202 // Special functions file
\r
203 $file3 = sprintf(PATH."inc/libs/%s_functions.php", $name);
\r
205 // Does the extension file exists?
\r
206 if (file_exists($file1) && is_readable($file1))
\r
208 // If there's no language file specified we don't need to load one... ;-)
\r
209 if (!empty($lang)) {
\r
210 // Create language file
\r
211 $file2 = sprintf(PATH."inc/language/%s_%s.php", $lang, GET_LANGUAGE());
\r
214 if (file_exists($file3) && is_readable($file3))
\r
216 // Special functions file
\r
218 require_once($file3);
\r
222 // Don't load functions file
\r
226 // Do we need a language file?
\r
227 if (($file1 != $file2) && (file_exists($file2)) && (is_readable($file2)))
\r
229 // Load language file
\r
235 // Don't load language file
\r
240 if ($name != "sql_patches")
\r
242 // Load extension's file
\r
243 include_once($file1);
\r
247 // KEEP sql_patches ALWAYS ACTIVE!
\r
248 $EXT_ALWAYS_ACTIVE = "Y";
\r
253 $CSS_FILE = PATH."theme/".GET_CURR_THEME()."/css/".$name.".css";
\r
254 if (file_exists($CSS_FILE))
\r
256 // CSS file for extension was found (use only relative path for now!)
\r
257 $EXT_CSS_FILES[] = $name.".css";
\r
261 // Don't load CSS file
\r
267 if ($CACHE_FILE == "init")
\r
269 $CACHE->add_row(array(
\r
270 'ext_id' => $EXT_ID,
\r
271 'ext_name' => $name,
\r
272 'ext_lang' => $lang,
\r
274 'ext_menu' => $menu,
\r
275 'ext_funcs' => $funcs,
\r
276 'ext_active' => $active,
\r
277 'ext_version' => $version,
\r
278 'ext_keep' => $EXT_ALWAYS_ACTIVE,
\r
281 elseif ($CACHE_FILE == "no")
\r
283 // Remember this value for later usage
\r
284 $KEEP_ACTIVE[$name] = $EXT_ALWAYS_ACTIVE;
\r
287 elseif (!file_exists($file1))
\r
289 // Deleted extension file so we mark it for removal from DB
\r
294 if ($CACHE_FILE == "init")
\r
296 // Close cache file
\r
297 $CACHE->cache_close();
\r
299 // Load more cache files (like admins)
\r
300 require_once(PATH."inc/load_cache.php");
\r
305 SQL_FREERESULT($res_ext_crt);
\r
307 // Compile configuration system
\r
311 *foreach ($CONFIG as $k=>$v)
\r
313 * $CONFIG[$k] = COMPILE_CODE($v);
\r
317 // Load include files
\r
318 if (!empty($INC_POOL[0]))
\r
320 foreach ($INC_POOL as $inc)
\r
322 require_once($inc);
\r
326 // Uninstall extensions that are no longer in our system
\r
327 if (!empty($DEL[0]))
\r
329 // Remove extensions from two tables: extension registry and tasks table
\r
330 foreach ($DEL as $name)
\r
332 // First remove entry from extensions table
\r
333 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
\r
334 array($name), __FILE__, __LINE__);
\r
336 // Remove (maybe?) found tasks (main task and possible updates
\r
337 $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')",
\r
338 array($name), __FILE__, __LINE__);
\r
341 // I think it's not neccessary to run the optimization function here
\r
342 // because we didn't delete so much data from database. Can you aggree?
\r