2 /************************************************************************
3 * MXChange v0.2.1 Start: 03/25/2004 *
4 * =============== Last change: 09/29/2004 *
6 * -------------------------------------------------------------------- *
7 * File : extensions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Extension management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Erweiterungen-Management *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
45 // Load the extension and maybe found language and function files.
46 function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "", $EXT_VER = "", $dry_run = false) {
52 // Is the extension already loaded?
53 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode={$EXT_LOAD_MODE}, ver={$EXT_VER}.");
54 if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (empty($EXT_LOAD_MODE))) {
56 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
60 // Construct include filename and FQFN for extension file
61 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
62 $FQFN = constant('PATH') . $INC;
64 // Is the extension file NOT there?
65 if (!INCLUDE_READABLE($INC)) {
67 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s not found.", $ext_name));
73 // Construct FQFN for language file
74 $langInclude = sprintf("inc/language/%s_%s.php", $ext_name, GET_LANGUAGE());
76 // Is this include there?
77 if ((FILE_READABLE($langInclude)) && (!isset($GLOBALS['ext_loaded']['lang'][$ext_name]))) {
79 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Language loaded.");
80 $GLOBALS['ext_loaded']['lang'][$ext_name] = true;
81 LOAD_INC_ONCE($langInclude);
84 // Construct FQFN for functions file
85 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
87 // Is this include there?
88 if ((FILE_READABLE($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name]))) {
90 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Functions loaded.");
91 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
92 LOAD_INC_ONCE($funcsInclude);
95 // Extensions are not deprecated by default
96 EXT_SET_DEPRECATED("N");
98 // Extensions are not always active by default
99 EXT_SET_ALWAYS_ACTIVE("N");
101 // By default an extension update does not depend on other extensions
102 EXT_SET_UPDATE_DEPENDS("");
104 // Extension update notes
105 EXT_SET_UPDATE_NOTES("");
107 // Include the extension file
108 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Extension loaded.");
111 // Is this extension deprecated?
112 if (EXT_GET_DEPRECATED() == "Y") {
113 // Deactivate the extension
114 DEACTIVATE_EXTENSION($ext_name);
120 // Mark it as loaded in normal mode
121 if (empty($EXT_LOAD_MODE)) {
123 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
130 // Registeres an extension and possible update depencies
131 function EXTENSION_REGISTER ($ext_name, $task_id, $dry_run = false, $logout = true) {
135 // This shall never do a non-admin user!
136 if (!IS_ADMIN()) return false;
138 // Is this extension already installed?
139 if (EXT_IS_ACTIVE($ext_name)) return false;
141 // Is the task id zero? Then we need to auto-fix it here
143 // Try to find the task
144 $task_id = DETERMINE_EXTENSION_TASK_ID($ext_name);
146 // Still zero and not in dry-run?
147 if (($task_id == 0) && (!$dry_run)) {
148 // Then request a bug report
149 debug_report_bug(sprintf("%s: task_id is still zero after DETERMINE_EXTENSION_TASK_ID(%s)",
164 // By default we have no failures
165 EXT_SET_REPORTS_FAILURE(false);
167 // Does this extension exists?
168 if (LOAD_EXTENSION($ext_name, "register", "", $dry_run)) {
169 // And run possible updates
170 $history = EXT_GET_VER_HISTORY();
171 foreach ($history as $ver) {
172 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ext_name={$ext_name}, ext_ver={$ver}");
173 // Load extension in update mode
174 LOAD_EXTENSION($ext_name, "update", $ver, $dry_run);
176 // Add update notes to our output
177 $NOTES .= ADD_EXTENSION_NOTES($ver);
180 // Does this extension depends on an outstanding update of another update?
181 if (EXT_GET_UPDATE_DEPENDS() != "") {
182 // Backup SQL commands and clear current
186 $ext_update = EXT_GET_UPDATE_DEPENDS();
188 // Check for required file
189 if (LOAD_EXTENSION($ext_update, "register", "", $dry_run)) {
190 // If versions mismatch update extension first
191 $ext_ver = GET_EXT_VERSION($ext_update);
193 // Extension version set? If empty the extension is not registered
194 if (empty($ext_ver)) {
195 // Extension not registered so far so first load task's ID...
196 $task = DETERMINE_EXTENSION_TASK_ID($ext_update);
200 // Try to register the extension
201 $test = EXTENSION_REGISTER($ext_update, $task, $dry_run, false);
203 } elseif ($ext_ver != EXT_GET_VERSION()) {
204 // Ok, update this extension now
205 EXTENSION_UPDATE($ext_update, $ext_ver, $dry_run);
210 // Nothing to register / update before...
214 // Required file for update does not exists!
216 // But this is fine for the first time...
219 // Finally restore previous SQLs
220 SET_SQLS($SQLs2); unset($SQLs2);
222 // Does not depend on an other extension
226 // Switch back to register mode
227 $EXT_LOAD_MODE = "register";
229 // Remains true if extension registration reports no failures
230 $test = (($test === true) && (EXT_GET_REPORTS_FAILURE() === false));
232 // Does everthing before wents ok?
234 // "Dry-run-mode" activated?
236 // Run installation pre-installation filters
237 runFilterChain('pre_extension_installed', array('dry_run' => $dry_run));
239 // Register extension
240 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_extensions` (ext_name, ext_active, ext_version) VALUES ('%s','%s','%s')",
241 array($ext_name, EXT_GET_ALWAYS_ACTIVE(), EXT_GET_VERSION()), __FILE__, __LINE__);
243 // Remove cache file(s) if extension is active
244 runFilterChain('post_extension_installed', array('ext_name' => $ext_name, 'task_id' => $task_id, 'inc_pool' => $INC_POOL));
246 // In normal mode return a true on success
249 // Rewrite SQL command to keep { and } inside
250 foreach (GET_SQLS() as $key => $sql) {
251 $sql = str_replace('{', "{", str_replace('}', "}", $sql));
252 SET_SQL_KEY($key, $sql);
255 // In "dry-run" mode return array with all SQL commands
258 // Remove all SQL commands
262 // No, an error occurs while registering extension :-(
265 } elseif (($task_id > 0) && (!empty($ext_name))) {
266 // Remove task from system when id and extension's name is valid
267 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s AND `status`='NEW' LIMIT 1",
268 array(bigintval($task_id)), __FILE__, __LINE__);
271 // Is this the sql_patches?
272 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":{$ext_name}/{$EXT_LOAD_MODE}");
273 if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove")) && (!$dry_run) && ($test)) {
274 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": LOAD!");
275 if ($logout === true) {
276 // Then redirect to logout
277 LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
279 // Add temporary filter
280 REGISTER_FILTER('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
281 $GLOBALS['ext_load_mode'] = $EXT_LOAD_MODE;
285 // Return status code
289 // Run SQL queries for given extension id
290 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
291 function EXTENSION_RUN_SQLS ($ext_id, $load_mode) {
292 // This shall never do a non-admin user!
293 if (!IS_ADMIN()) return false;
298 // By default no SQL has been executed
301 // Get extension's name
302 $ext_name = GET_EXT_NAME($ext_id);
303 // If it is not set then maybe there is no extension for that ID number
304 if (empty($ext_name)) return false;
306 // Load extension in detected mode
307 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]={$ext_name}");
308 LOAD_EXTENSION($ext_name, $load_mode, "", false);
310 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":SQLs::count=".COUNT_SQLS()."");
311 if ((IS_SQLS_VALID() && (COUNT_SQLS() > 0))) {
312 // Run SQL commands...
313 runFilterChain('run_sqls');
316 if ($load_mode == "remove") {
317 // Delete this extension (remember to remove it from your server *before* you click on welcome!
318 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
319 array($ext_name), __FILE__, __LINE__);
323 // Remove cache file(s) if extension is active
324 if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == "activate") || ($load_mode == "deactivate"))) {
326 runFilterChain('post_extension_run_sql', $ext_name);
329 // Is this the sql_patches?
330 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": {$ext_id}/{$ext_name}/{$load_mode}");
331 if (($ext_name == "sql_patches") && (($load_mode == "register") || ($load_mode == "remove"))) {
332 // Then redirect to logout
333 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": LOAD!");
334 LOAD_URL("modules.php?module=admin&logout=1&".$load_mode."=sql_patches");
338 // Check if given extension is active
339 function EXT_IS_ACTIVE ($ext_name) {
340 // Extensions are all inactive during installation
341 if ((!isInstalled()) || (isInstalling()) || (empty($ext_name))) return false;
343 // Not active is the default
347 if (isset($GLOBALS['cache_array']['extensions']['ext_active'][$ext_name])) {
349 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
350 $active = $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name];
353 incrementConfigEntry('cache_hits');
354 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
355 // Extension is loaded!
356 die("LOADED:$ext_name");
357 } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
358 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
359 // Load from database
360 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
361 array($ext_name), __FILE__, __LINE__);
364 if (SQL_NUMROWS($result) == 1) {
366 list($active) = SQL_FETCHROW($result);
370 SQL_FREERESULT($result);
373 //* DEBUG: */ echo $ext_name."[DB]: {$active}");
374 $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name] = $active;
376 // Extension not active!
377 //* DEBUG: */ echo $ext_name.": Not active!");
378 $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name] = "N";
382 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, " ext_name={$ext_name},active={$active}");
384 // Is this extension activated? (For admins we always have active extensions...)
385 return ($active == "Y");
387 // Get version from extensions
388 function GET_EXT_VERSION ($ext_name) {
389 // By default no extension is found
392 // Extensions are all inactive during installation
393 if ((!isInstalled()) || (isInstalling())) return "";
394 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
396 // Is the cache written?
397 if (isset($GLOBALS['cache_array']['extensions']['ext_version'][$ext_name])) {
398 // Load data from cache
399 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": CACHE!");
400 $ext_ver = $GLOBALS['cache_array']['extensions']['ext_version'][$ext_name];
403 incrementConfigEntry('cache_hits');
404 } elseif (!isCacheInstanceValid()) {
405 // Load from database
406 $result = SQL_QUERY_ESC("SELECT ext_version FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
407 array($ext_name), __FILE__, __LINE__);
408 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
410 // Is the extension there?
411 if (SQL_NUMROWS($result) == 1) {
413 list($ext_ver) = SQL_FETCHROW($result);
417 SQL_FREERESULT($result);
420 $GLOBALS['cache_array']['extensions']['ext_version'][$ext_name] = $ext_ver;
424 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
428 // Updates a given extension with current extension version to latest version
429 function EXTENSION_UPDATE ($ext_name, $ext_ver, $dry_run = false) {
430 // This shall never do a non-admin user!
441 // Only admins are allowed to update extensions
442 if ((!IS_ADMIN()) || (empty($ext_name))) return false;
444 // Load extension in test mode
445 LOAD_EXTENSION($ext_name, "test", $ext_ver, $dry_run);
447 // Save version history
448 $history = EXT_GET_VER_HISTORY();
450 // Remove old SQLs array to prevent possible bugs
453 // Check if version is updated
454 if (((EXT_GET_VERSION() != $ext_ver) || ($dry_run)) && (is_array($history))) {
455 // Search for starting point
456 $start = array_search($ext_ver, $history);
458 // And load SQL queries in order of version history
459 for ($idx = ($start + 1); $idx < count($history); $idx++) {
460 // Set extension version
461 $GLOBALS['cache_array']['update_ver'][$ext_name] = $history[$idx];
464 LOAD_EXTENSION($ext_name, "update", $GLOBALS['cache_array']['update_ver'][$ext_name], $dry_run);
466 if (EXT_GET_UPDATE_DEPENDS() != "") {
467 // Backup current SQL queries
468 $GLOBALS['cache_array']['update_sqls'][$ext_name] = GET_SQLS();
470 // Is the extension there?
471 if (GET_EXT_VERSION(EXT_GET_UPDATE_DEPENDS()) != "") {
472 // Update another extension first!
473 $test = EXTENSION_UPDATE(EXT_GET_UPDATE_DEPENDS(), GET_EXT_VERSION(EXT_GET_UPDATE_DEPENDS()), $dry_run);
475 // Register new extension
476 $test = EXTENSION_REGISTER(EXT_GET_UPDATE_DEPENDS(), 0, $dry_run, false);
479 // Restore previous SQL queries
480 SET_SQLS($GLOBALS['cache_array']['update_sqls'][$ext_name]);
481 unset($GLOBALS['cache_array']['update_sqls'][$ext_name]);
485 $NOTES .= ADD_EXTENSION_NOTES($GLOBALS['cache_array']['update_ver'][$ext_name]);
488 // In real-mode execute any existing includes
490 $GLOBALS['cache_array']['inc_pool'][$ext_name] = $INC_POOL;
491 runFilterChain('load_includes', $INC_POOL);
492 $INC_POOL = $GLOBALS['cache_array']['inc_pool'][$ext_name];
493 unset($GLOBALS['cache_array']['inc_pool'][$ext_name]);
497 runFilterChain('run_sqls', array('dry_run' => $dry_run));
501 CREATE_EXTENSION_UPDATE_TASK(GET_CURRENT_ADMIN_ID(), $ext_name, $GLOBALS['cache_array']['update_ver'][$ext_name], SQL_ESCAPE($NOTES));
503 // Update extension's version
504 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
505 array($GLOBALS['cache_array']['update_ver'][$ext_name], $ext_name), __FILE__, __LINE__);
509 unset($GLOBALS['cache_array']['update_ver'][$ext_name]);
511 // Run filters on success extension update
512 runFilterChain('extension_update', $ext_name);
517 // Output verbose SQL table for extension
518 function EXTENSION_VERBOSE_TABLE ($queries = array(), $title = "", $dashed = "", $switch = false, $width = "100%") {
521 // Then fix it to default
522 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
525 // Are there some queries in $queries?
526 if (count($queries) > 0) {
527 // Then use them instead!
535 // Do we have queries?
536 if ((IS_SQLS_VALID()) && (GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
537 foreach (GET_SQLS() as $idx => $sql) {
541 // Output command if set
543 // Prepare output for template
551 $OUT .= LOAD_TEMPLATE("admin_ext_sql_row", true, $content);
553 // Switch color and count up
559 // Prepare content for template
567 // Load main template
568 $OUT = LOAD_TEMPLATE("admin_ext_sql_table", true, $content);
569 } elseif ((GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
570 // No addional SQL commands to run
571 $OUT = LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
578 // Get extension name from id
579 function GET_EXT_NAME ($ext_id) {
580 // Init extension name
584 if (isset($GLOBALS['cache_array']['extensions']['ext_name'][$ext_id])) {
586 $ret = $GLOBALS['cache_array']['extensions']['ext_name'][$ext_id];
589 incrementConfigEntry('cache_hits');
590 } elseif (!EXT_IS_ACTIVE("cache")) {
591 // Load from database
592 $result = SQL_QUERY_ESC("SELECT ext_name FROM `{!_MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
593 array(bigintval($ext_id)), __FILE__, __LINE__);
594 list($ret) = SQL_FETCHROW($result);
595 SQL_FREERESULT($result);
600 // Get extension id from name
601 function GET_EXT_ID ($ext_name) {
604 if (isset($GLOBALS['cache_array']['extensions']['ext_id'][$ext_name])) {
606 $ret = $GLOBALS['cache_array']['extensions']['ext_id'][$ext_name];
609 incrementConfigEntry('cache_hits');
610 } elseif (!EXT_IS_ACTIVE("cache")) {
611 // Load from database
612 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
613 array($ext_name), __FILE__, __LINE__);
614 list($ret) = SQL_FETCHROW($result);
615 SQL_FREERESULT($result);
622 // Activate given extension
623 function ACTIVATE_EXTENSION ($ext_name) {
624 // Activate the extension
625 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='Y' WHERE ext_name='%s' LIMIT 1",
626 array($ext_name), __FILE__, __LINE__);
628 // Extension has been activated?
629 if (SQL_AFFECTEDROWS() == 1) {
630 // Then run all queries
631 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "activate");
635 // Deactivate given extension
636 function DEACTIVATE_EXTENSION($ext_name) {
637 // Activate the extension
638 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='N' WHERE ext_name='%s' LIMIT 1",
639 array($ext_name), __FILE__, __LINE__);
641 // Extension has been activated?
642 if (SQL_AFFECTEDROWS() == 1) {
643 // Then run all queries
644 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "deactivate");
647 CREATE_EXTENSION_DEACTIVATION_TASK($ext_name);
650 SEND_ADMIN_NOTIFICATION(
651 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
652 "admin_ext_deactivated",
653 array('ext_name' => $ext_name)
658 // Checks wether the extension is older than given
659 function EXT_VERSION_IS_OLDER ($ext_name, $ext_ver) {
660 // Get current extension version
661 $currVersion = GET_EXT_VERSION($ext_name);
663 // Remove all dots from both versions
664 $currVersion = str_replace(".", "", $currVersion);
665 $ext_ver = str_replace(".", "", $ext_ver);
667 // Now compare both and return the result
668 return ($currVersion < $ext_ver);
671 // Creates a new task for updated extension
672 function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $ext_name, $ext_ver, $notes) {
673 // Create subject line
674 $subject = "[UPDATE-".$ext_name."-".$ext_ver.":] {--ADMIN_UPDATE_EXT_SUBJ--}";
676 // Is the extension there?
677 if (GET_EXT_VERSION($ext_name) != "") {
678 // Check if task is not there
679 if (DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) {
680 // Task not created so it's a brand-new extension which we need to register and create a task for!
681 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','EXTENSION_UPDATE','%s','%s', UNIX_TIMESTAMP())",
682 array($admin_id, $subject, $notes), __FILE__, __LINE__);
687 // Creates a new task for newly installed extension
688 function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
689 // Not installed and do we have created a task for the admin?
690 if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) == "")) {
692 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
698 // Load text for task
699 if (FILE_READABLE($tpl)) {
700 // Load extension's own text template (HTML!)
701 $msg = LOAD_TEMPLATE("ext_".$ext, true);
703 // Load default message
704 $msg = LOAD_TEMPLATE("admin_new_ext", "", 0);
707 // Task not created so it's a brand-new extension which we need to register and create a task for!
708 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
709 VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
714 ), __FILE__, __LINE__, true, false
719 // Creates a task for automatically deactivated (deprecated) extension
720 function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
721 // Create subject line
722 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
724 // Not installed and do we have created a task for the admin?
725 if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) != "")) {
726 // Task not created so add it
727 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
728 VALUES (0,0,'NEW','EXTENSION_DEACTIVATION','%s','%s',UNIX_TIMESTAMP())",
731 SQL_ESCAPE(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
732 ), __FILE__, __LINE__, true, false
737 // Checks if the module has a menu
738 function MODULE_HAS_MENU ($mod, $forceDb = false) {
739 // All is false by default
742 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):mod={$mod},cache=".GET_EXT_VERSION("cache")."<br />\n";
743 if (GET_EXT_VERSION("cache") >= "0.1.2") {
744 // Cache version is okay, so let's check the cache!
745 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
746 // Check module cache and count hit
747 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == "Y");
748 incrementConfigEntry('cache_hits');
749 } elseif (isset($GLOBALS['cache_array']['extensions']['ext_menu'][$mod])) {
750 // Check cache and count hit
751 $ret = ($GLOBALS['cache_array']['extensions']['ext_menu'][$mod] == "Y");
752 incrementConfigEntry('cache_hits');
753 } elseif ((IS_ADMIN()) && ($mod == "admin")) {
754 // Admin module has always a menu!
757 } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ((!EXT_IS_ACTIVE("cache")) || ($forceDb === true))) {
758 // Check database for entry
759 $result = SQL_QUERY_ESC("SELECT has_menu FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1",
760 array($mod), __FILE__, __LINE__);
763 if (SQL_NUMROWS($result) == 1) {
764 // Load "has_menu" column
765 list($has_menu) = SQL_FETCHROW($result);
768 $GLOBALS['cache_array']['extensions']['ext_menu'][$mod] = $has_menu;
770 // Does it have a menu?
771 $ret = ($has_menu == "Y");
775 SQL_FREERESULT($result);
776 } elseif (GET_EXT_VERSION("sql_patches") == "") {
777 // No sql_patches installed, so maybe in admin area or no admin registered?
778 $ret = (((IS_ADMIN()) || (!isAdminRegistered())) && ($mod == "admin")); // Then there is a menu!
782 //* DEBUG: */ var_dump($ret);
786 // Determines the task id for given extension
787 function DETERMINE_EXTENSION_TASK_ID ($ext_name) {
788 // Default is not found
791 // Search for extension task's id
792 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE task_type='EXTENSION' AND subject='[%s:]' LIMIT 1",
793 array($ext_name), __FILE__, __LINE__);
796 if (SQL_NUMROWS($result) == 1) {
797 // Task found so load task's ID and register extension...
798 list($task_id) = SQL_FETCHROW($result);
802 SQL_FREERESULT($result);
808 // Determines the task id for given subject
809 function DETERMINE_TASK_ID_BY_SUBJECT ($subject) {
810 // Default is not found
813 // Search for task id
814 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE subject LIKE '%s%%' LIMIT 1",
815 array($subject), __FILE__, __LINE__);
818 if (SQL_NUMROWS($result) == 1) {
819 // Task found so load task's ID and register extension...
820 list($task_id) = SQL_FETCHROW($result);
824 SQL_FREERESULT($result);
830 // Add updates notes for given version
831 function ADD_EXTENSION_NOTES ($ver) {
832 // Init notes/content
833 $out = ""; $content = array();
835 // Is do we have verbose output enabled?
836 if ((getConfig('verbose_sql') == "Y") || (!EXT_IS_ACTIVE("sql_patches"))) {
838 // Update notes found?
839 if (EXT_GET_UPDATE_NOTES() != "") {
840 // Update notes found
843 'notes' => EXT_GET_UPDATE_NOTES()
845 EXT_SET_UPDATE_NOTES("");
846 } elseif (($ver == "0.0") || ($ver == "0.0.0")) {
850 'notes' => getMessage('INITIAL_RELEASE')
853 // No update notes found!
856 'notes' => getMessage('NO_UPDATE_NOTES')
861 $out = LOAD_TEMPLATE("admin_ext_notes", true, $content);
868 // Getter for CSS files array
869 function EXT_GET_CSS_FILES () {
870 // By default no additional CSS files are found
873 // Is the array there?
874 if (isset($GLOBALS['css_files'])) {
876 $cssFiles = $GLOBALS['css_files'];
883 // Init CSS files array
884 function EXT_INIT_CSS_FILES () {
886 $GLOBALS['css_files'] = array();
890 function EXT_ADD_CSS_FILE ($file) {
891 // Is the array there?
892 if (!isset($GLOBALS['css_files'])) {
893 // Then auto-init them
894 EXT_INIT_CSS_FILES();
898 $GLOBALS['css_files'][] = $file;
901 // Setter for EXT_ALWAYS_ACTIVE flag
902 function EXT_SET_ALWAYS_ACTIVE ($active) {
903 $GLOBALS['ext_always_active'] = $active;
906 // Getter for EXT_ALWAYS_ACTIVE flag
907 function EXT_GET_ALWAYS_ACTIVE () {
908 return $GLOBALS['ext_always_active'];
911 // Setter for EXT_VERSION flag
912 function EXT_SET_VERSION ($version) {
913 $GLOBALS['ext_version'] = $version;
916 // Getter for EXT_VERSION flag
917 function EXT_GET_VERSION () {
918 return $GLOBALS['ext_version'];
921 // Setter for EXT_DEPRECATED flag
922 function EXT_SET_DEPRECATED ($deprecated) {
923 $GLOBALS['ext_deprecated'] = $deprecated;
926 // Getter for EXT_DEPRECATED flag
927 function EXT_GET_DEPRECATED () {
928 return $GLOBALS['ext_deprecated'];
931 // Setter for EXT_UPDATE_DEPENDS flag
932 function EXT_SET_UPDATE_DEPENDS ($updateDepends) {
933 $GLOBALS['ext_update_depends'] = $updateDepends;
936 // Getter for EXT_UPDATE_DEPENDS flag
937 function EXT_GET_UPDATE_DEPENDS () {
938 return $GLOBALS['ext_update_depends'];
941 // Setter for EXT_REPORTS_FAILURE flag
942 function EXT_SET_REPORTS_FAILURE ($reportsFailure) {
943 $GLOBALS['ext_reports_failure'] = $reportsFailure;
946 // Getter for EXT_REPORTS_FAILURE flag
947 function EXT_GET_REPORTS_FAILURE () {
948 return $GLOBALS['ext_reports_failure'];
951 // Setter for EXT_VER_HISTORY flag
952 function EXT_SET_VER_HISTORY ($verHistory) {
953 $GLOBALS['ext_ver_history'] = (array) $verHistory;
956 // Getter for EXT_VER_HISTORY flag
957 function EXT_GET_VER_HISTORY () {
958 return $GLOBALS['ext_ver_history'];
961 // Setter for EXT_UPDATE_NOTES flag
962 function EXT_SET_UPDATE_NOTES ($updateNotes) {
963 $GLOBALS['ext_update_notes'] = (array) $updateNotes;
966 // Getter for EXT_UPDATE_NOTES flag
967 function EXT_GET_UPDATE_NOTES () {
968 return $GLOBALS['ext_update_notes'];