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 * -------------------------------------------------------------------- *
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 // Load the extension and maybe found language and function files.
41 function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "", $EXT_VER = "", $dry_run = false) {
47 // Is the extension already loaded?
48 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode={$EXT_LOAD_MODE}, ver={$EXT_VER}.");
49 if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (empty($EXT_LOAD_MODE))) {
51 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
55 // Construct include filename and FQFN for extension file
56 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
57 $FQFN = constant('PATH') . $INC;
59 // Is the extension file NOT there?
60 if (!INCLUDE_READABLE($INC)) {
62 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s not found.", $ext_name));
68 // Construct FQFN for language file
69 $langInclude = sprintf("inc/language/%s_%s.php", $ext_name, GET_LANGUAGE());
71 // Is this include there?
72 if ((FILE_READABLE($langInclude)) && (!isset($GLOBALS['ext_loaded']['lang'][$ext_name]))) {
74 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Language loaded.");
75 $GLOBALS['ext_loaded']['lang'][$ext_name] = true;
76 LOAD_INC_ONCE($langInclude);
79 // Construct FQFN for functions file
80 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
82 // Is this include there?
83 if ((FILE_READABLE($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name]))) {
85 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Functions loaded.");
86 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
87 LOAD_INC_ONCE($funcsInclude);
90 // Extensions are not deprecated by default
91 EXT_SET_DEPRECATED("N");
93 // Extensions are not always active by default
94 EXT_SET_ALWAYS_ACTIVE("N");
96 // By default an extension update does not depend on other extensions
97 EXT_SET_UPDATE_DEPENDS("");
99 // Extension update notes
100 EXT_SET_UPDATE_NOTES("");
102 // Include the extension file
103 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Extension loaded.");
106 // Is this extension deprecated?
107 if (EXT_GET_DEPRECATED() == "Y") {
108 // Deactivate the extension
109 DEACTIVATE_EXTENSION($ext_name);
115 // Mark it as loaded in normal mode
116 if (empty($EXT_LOAD_MODE)) {
118 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
125 // Registeres an extension and possible update depencies
126 function EXTENSION_REGISTER ($ext_name, $task_id, $dry_run = false, $logout = true) {
130 // This shall never do a non-admin user!
131 if (!IS_ADMIN()) return false;
133 // Is this extension already installed?
134 if (EXT_IS_ACTIVE($ext_name)) return false;
144 // By default we have no failures
145 EXT_SET_REPORTS_FAILURE(false);
147 // Does this extension exists?
148 if (LOAD_EXTENSION($ext_name, "register", "", $dry_run)) {
149 // And run possible updates
150 $history = EXT_GET_VER_HISTORY();
151 foreach ($history as $ver) {
152 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ext_name={$ext_name}, ext_ver={$ver}");
153 // Load extension in update mode
154 LOAD_EXTENSION($ext_name, "update", $ver, $dry_run);
156 // Add update notes to our output
157 $NOTES .= ADD_EXTENSION_NOTES($ver);
160 // Does this extension depends on an outstanding update of another update?
161 if (EXT_GET_UPDATE_DEPENDS() != "") {
162 // Backup SQL commands and clear current
166 $ext_update = EXT_GET_UPDATE_DEPENDS();
168 // Check for required file
169 if (LOAD_EXTENSION($ext_update, "register", "", $dry_run)) {
170 // If versions mismatch update extension first
171 $ext_ver = GET_EXT_VERSION($ext_update);
173 // Extension version set? If empty the extension is not registered
174 if (empty($ext_ver)) {
175 // Extension not registered so far so first load task's ID...
176 $task = DETERMINE_EXTENSION_TASK_ID($ext_update);
180 // Try to register the extension
181 $test = EXTENSION_REGISTER($ext_update, $task, $dry_run, false);
183 } elseif ($ext_ver != EXT_GET_VERSION()) {
184 // Ok, update this extension now
185 EXTENSION_UPDATE($ext_update, $ext_ver, $dry_run);
190 // Nothing to register / update before...
194 // Required file for update does not exists!
196 // But this is fine for the first time...
199 // Finally restore previous SQLs
200 SET_SQLS($SQLs2); unset($SQLs2);
202 // Does not depend on an other extension
206 // Switch back to register mode
207 $EXT_LOAD_MODE = "register";
209 // Remains true if extension registration reports no failures
210 $test = (($test === true) && (EXT_GET_REPORTS_FAILURE() === false));
212 // Does everthing before wents ok?
214 // "Dry-run-mode" activated?
216 // Run installation pre-installation filters
217 runFilterChain('pre_extension_installed', array('dry_run' => $dry_run));
219 // Register extension
220 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_extensions` (ext_name, ext_active, ext_version) VALUES ('%s','%s','%s')",
221 array($ext_name, EXT_GET_ALWAYS_ACTIVE(), EXT_GET_VERSION()), __FILE__, __LINE__);
223 // Remove cache file(s) if extension is active
224 runFilterChain('post_extension_installed', array('ext_name' => $ext_name, 'task_id' => $task_id, 'inc_pool' => $INC_POOL));
226 // In normal mode return a true on success
229 // Rewrite SQL command to keep { and } inside
230 foreach (GET_SQLS() as $key => $sql) {
231 $sql = str_replace('{', "{", str_replace('}', "}", $sql));
232 SET_SQL_KEY($key, $sql);
235 // In "dry-run" mode return array with all SQL commands
238 // Remove all SQL commands
242 // No, an error occurs while registering extension :-(
245 } elseif (($task_id > 0) && (!empty($ext_name))) {
246 // Remove task from system when id and extension's name is valid
247 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s AND `status`='NEW' LIMIT 1",
248 array(bigintval($task_id)), __FILE__, __LINE__);
251 // Is this the sql_patches?
252 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":{$ext_name}/{$EXT_LOAD_MODE}");
253 if (($ext_name == "sql_patches") && (($EXT_LOAD_MODE == "register") || ($EXT_LOAD_MODE == "remove")) && (!$dry_run) && ($test)) {
254 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": LOAD!");
255 if ($logout === true) {
256 // Then redirect to logout
257 LOAD_URL("modules.php?module=admin&logout=1&".$EXT_LOAD_MODE."=sql_patches");
259 // Add temporary filter
260 REGISTER_FILTER('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
261 $GLOBALS['ext_load_mode'] = $EXT_LOAD_MODE;
265 // Return status code
269 // Run SQL queries for given extension id
270 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
271 function EXTENSION_RUN_SQLS ($ext_id, $load_mode) {
272 // This shall never do a non-admin user!
273 if (!IS_ADMIN()) return false;
278 // By default no SQL has been executed
281 // Get extension's name
282 $ext_name = GET_EXT_NAME($ext_id);
283 // If it is not set then maybe there is no extension for that ID number
284 if (empty($ext_name)) return false;
286 // Load extension in detected mode
287 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]={$ext_name}");
288 LOAD_EXTENSION($ext_name, $load_mode, "", false);
290 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ":SQLs::count=".COUNT_SQLS()."");
291 if ((IS_SQLS_VALID() && (COUNT_SQLS() > 0))) {
292 // Run SQL commands...
293 runFilterChain('run_sqls');
296 if ($load_mode == "remove") {
297 // Delete this extension (remember to remove it from your server *before* you click on welcome!
298 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
299 array($ext_name), __FILE__, __LINE__);
303 // Remove cache file(s) if extension is active
304 if (((EXT_IS_ACTIVE("cache")) || (GET_EXT_VERSION("cache") != "")) && (((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == "activate") || ($load_mode == "deactivate"))) {
306 runFilterChain('post_extension_run_sql', $ext_name);
309 // Is this the sql_patches?
310 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": {$ext_id}/{$ext_name}/{$load_mode}");
311 if (($ext_name == "sql_patches") && (($load_mode == "register") || ($load_mode == "remove"))) {
312 // Then redirect to logout
313 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": LOAD!");
314 LOAD_URL("modules.php?module=admin&logout=1&".$load_mode."=sql_patches");
318 // Check if given extension is active
319 function EXT_IS_ACTIVE ($ext_name) {
320 // Extensions are all inactive during installation
321 if ((!isInstalled()) || (isInstalling()) || (empty($ext_name))) return false;
323 // Not active is the default
327 if (isset($GLOBALS['cache_array']['extensions']['ext_active'][$ext_name])) {
329 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
330 $active = $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name];
333 incrementConfigEntry('cache_hits');
334 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
335 // Extension is loaded!
336 die("LOADED:$ext_name");
337 } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
338 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
339 // Load from database
340 $result = SQL_QUERY_ESC("SELECT ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
341 array($ext_name), __FILE__, __LINE__);
344 if (SQL_NUMROWS($result) == 1) {
346 list($active) = SQL_FETCHROW($result);
350 SQL_FREERESULT($result);
353 //* DEBUG: */ echo $ext_name."[DB]: {$active}");
354 $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name] = $active;
356 // Extension not active!
357 //* DEBUG: */ echo $ext_name.": Not active!");
358 $GLOBALS['cache_array']['extensions']['ext_active'][$ext_name] = "N";
362 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, " ext_name={$ext_name},active={$active}");
364 // Is this extension activated? (For admins we always have active extensions...)
365 return ($active == "Y");
367 // Get version from extensions
368 function GET_EXT_VERSION ($ext_name) {
369 // By default no extension is found
372 // Extensions are all inactive during installation
373 if ((!isInstalled()) || (isInstalling())) return "";
374 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
376 // Is the cache written?
377 if (isset($GLOBALS['cache_array']['extensions']['ext_version'][$ext_name])) {
378 // Load data from cache
379 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": CACHE!");
380 $ext_ver = $GLOBALS['cache_array']['extensions']['ext_version'][$ext_name];
383 incrementConfigEntry('cache_hits');
384 } elseif (!isCacheInstanceValid()) {
385 // Load from database
386 $result = SQL_QUERY_ESC("SELECT ext_version FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
387 array($ext_name), __FILE__, __LINE__);
388 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
390 // Is the extension there?
391 if (SQL_NUMROWS($result) == 1) {
393 list($ext_ver) = SQL_FETCHROW($result);
397 SQL_FREERESULT($result);
400 $GLOBALS['cache_array']['extensions']['ext_version'][$ext_name] = $ext_ver;
404 //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
408 // Updates a given extension with current extension version to latest version
409 function EXTENSION_UPDATE ($ext_name, $ext_ver, $dry_run = false) {
410 // This shall never do a non-admin user!
421 // Only admins are allowed to update extensions
422 if ((!IS_ADMIN()) || (empty($ext_name))) return false;
424 // Load extension in test mode
425 LOAD_EXTENSION($ext_name, "test", $ext_ver, $dry_run);
427 // Save version history
428 $history = EXT_GET_VER_HISTORY();
430 // Remove old SQLs array to prevent possible bugs
433 // Check if version is updated
434 if (((EXT_GET_VERSION() != $ext_ver) || ($dry_run)) && (is_array($history))) {
435 // Search for starting point
436 $start = array_search($ext_ver, $history);
438 // And load SQL queries in order of version history
439 for ($idx = ($start + 1); $idx < sizeof($history); $idx++) {
440 // Set extension version
441 $GLOBALS['cache_array']['update_ver'][$ext_name] = $history[$idx];
444 LOAD_EXTENSION($ext_name, "update", $GLOBALS['cache_array']['update_ver'][$ext_name], $dry_run);
446 if (EXT_GET_UPDATE_DEPENDS() != "") {
447 // Backup current SQL queries
448 $GLOBALS['cache_array']['update_sqls'][$ext_name] = GET_SQLS();
450 // Is the extension there?
451 if (GET_EXT_VERSION(EXT_GET_UPDATE_DEPENDS()) != "") {
452 // Update another extension first!
453 $test = EXTENSION_UPDATE(EXT_GET_UPDATE_DEPENDS(), GET_EXT_VERSION(EXT_GET_UPDATE_DEPENDS()), $dry_run);
455 // Register new extension
456 $test = EXTENSION_REGISTER(EXT_GET_UPDATE_DEPENDS(), 0, $dry_run, false);
459 // Restore previous SQL queries
460 SET_SQLS($GLOBALS['cache_array']['update_sqls'][$ext_name]);
461 unset($GLOBALS['cache_array']['update_sqls'][$ext_name]);
465 $NOTES .= ADD_EXTENSION_NOTES($GLOBALS['cache_array']['update_ver'][$ext_name]);
468 // In real-mode execute any existing includes
470 $GLOBALS['cache_array']['inc_pool'][$ext_name] = $INC_POOL;
471 runFilterChain('load_includes', $INC_POOL);
472 $INC_POOL = $GLOBALS['cache_array']['inc_pool'][$ext_name];
473 unset($GLOBALS['cache_array']['inc_pool'][$ext_name]);
477 runFilterChain('run_sqls', array('dry_run' => $dry_run));
481 CREATE_EXTENSION_UPDATE_TASK(GET_CURRENT_ADMIN_ID(), $ext_name, $GLOBALS['cache_array']['update_ver'][$ext_name], SQL_ESCAPE($NOTES));
483 // Update extension's version
484 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
485 array($GLOBALS['cache_array']['update_ver'][$ext_name], $ext_name), __FILE__, __LINE__);
489 unset($GLOBALS['cache_array']['update_ver'][$ext_name]);
491 // Run filters on success extension update
492 runFilterChain('extension_update', $ext_name);
497 // Output verbose SQL table for extension
498 function EXTENSION_VERBOSE_TABLE ($queries = array(), $title = "", $dashed = "", $switch = false, $width = "100%") {
501 // Then fix it to default
502 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
505 // Are there some queries in $queries?
506 if (count($queries) > 0) {
507 // Then use them instead!
515 // Do we have queries?
516 if ((IS_SQLS_VALID()) && (GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
517 foreach (GET_SQLS() as $idx => $sql) {
521 // Output command if set
523 // Prepare output for template
531 $OUT .= LOAD_TEMPLATE("admin_ext_sql_row", true, $content);
533 // Switch color and count up
539 // Prepare content for template
547 // Load main template
548 $OUT = LOAD_TEMPLATE("admin_ext_sql_table", true, $content);
549 } elseif ((GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
550 // No addional SQL commands to run
551 $OUT = LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
558 // Get extension name from id
559 function GET_EXT_NAME ($ext_id) {
560 // Init extension name
564 if (isset($GLOBALS['cache_array']['extensions']['ext_name'][$ext_id])) {
566 $ret = $GLOBALS['cache_array']['extensions']['ext_name'][$ext_id];
569 incrementConfigEntry('cache_hits');
570 } elseif (!EXT_IS_ACTIVE("cache")) {
571 // Load from database
572 $result = SQL_QUERY_ESC("SELECT ext_name FROM `{!_MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
573 array(bigintval($ext_id)), __FILE__, __LINE__);
574 list($ret) = SQL_FETCHROW($result);
575 SQL_FREERESULT($result);
580 // Get extension id from name
581 function GET_EXT_ID ($ext_name) {
584 if (isset($GLOBALS['cache_array']['extensions']['ext_id'][$ext_name])) {
586 $ret = $GLOBALS['cache_array']['extensions']['ext_id'][$ext_name];
589 incrementConfigEntry('cache_hits');
590 } elseif (!EXT_IS_ACTIVE("cache")) {
591 // Load from database
592 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
593 array($ext_name), __FILE__, __LINE__);
594 list($ret) = SQL_FETCHROW($result);
595 SQL_FREERESULT($result);
602 // Activate given extension
603 function ACTIVATE_EXTENSION ($ext_name) {
604 // Activate the extension
605 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='Y' WHERE ext_name='%s' LIMIT 1",
606 array($ext_name), __FILE__, __LINE__);
608 // Extension has been activated?
609 if (SQL_AFFECTEDROWS() == 1) {
610 // Then run all queries
611 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "activate");
615 // Deactivate given extension
616 function DEACTIVATE_EXTENSION($ext_name) {
617 // Activate the extension
618 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='N' WHERE ext_name='%s' LIMIT 1",
619 array($ext_name), __FILE__, __LINE__);
621 // Extension has been activated?
622 if (SQL_AFFECTEDROWS() == 1) {
623 // Then run all queries
624 EXTENSION_RUN_SQLS(GET_EXT_ID($ext_name), "deactivate");
627 CREATE_EXTENSION_DEACTIVATION_TASK($ext_name);
630 SEND_ADMIN_NOTIFICATION(
631 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
632 "admin_ext_deactivated",
633 array('ext_name' => $ext_name)
638 // Checks wether the extension is older than given
639 function EXT_VERSION_IS_OLDER ($ext_name, $ext_ver) {
640 // Get current extension version
641 $currVersion = GET_EXT_VERSION($ext_name);
643 // Remove all dots from both versions
644 $currVersion = str_replace(".", "", $currVersion);
645 $ext_ver = str_replace(".", "", $ext_ver);
647 // Now compare both and return the result
648 return ($currVersion < $ext_ver);
651 // Creates a new task for updated extension
652 function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $ext_name, $ext_ver, $notes) {
653 // Create subject line
654 $subject = "[UPDATE-".$ext_name."-".$ext_ver.":] {--ADMIN_UPDATE_EXT_SUBJ--}";
656 // Is the extension there?
657 if (GET_EXT_VERSION($ext_name) != "") {
658 // Check if task is not there
659 if (DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) {
660 // Task not created so it's a brand-new extension which we need to register and create a task for!
661 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())",
662 array($admin_id, $subject, $notes), __FILE__, __LINE__);
667 // Creates a new task for newly installed extension
668 function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
669 // Not installed and do we have created a task for the admin?
670 if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) == "")) {
672 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
678 // Load text for task
679 if (FILE_READABLE($tpl)) {
680 // Load extension's own text template (HTML!)
681 $msg = LOAD_TEMPLATE("ext_".$ext, true);
683 // Load default message
684 $msg = LOAD_TEMPLATE("admin_new_ext", "", 0);
687 // Task not created so it's a brand-new extension which we need to register and create a task for!
688 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
689 VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
694 ), __FILE__, __LINE__, true, false
699 // Creates a task for automatically deactivated (deprecated) extension
700 function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
701 // Create subject line
702 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
704 // Not installed and do we have created a task for the admin?
705 if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) != "")) {
706 // Task not created so add it
707 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
708 VALUES (0,0,'NEW','EXTENSION_DEACTIVATION','%s','%s',UNIX_TIMESTAMP())",
711 SQL_ESCAPE(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
712 ), __FILE__, __LINE__, true, false
717 // Checks if the module has a menu
718 function MODULE_HAS_MENU ($mod, $forceDb = false) {
719 // All is false by default
722 //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):mod={$mod},cache=".GET_EXT_VERSION("cache")."<br />\n";
723 if (GET_EXT_VERSION("cache") >= "0.1.2") {
724 // Cache version is okay, so let's check the cache!
725 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
726 // Check module cache and count hit
727 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == "Y");
728 incrementConfigEntry('cache_hits');
729 } elseif (isset($GLOBALS['cache_array']['extensions']['ext_menu'][$mod])) {
730 // Check cache and count hit
731 $ret = ($GLOBALS['cache_array']['extensions']['ext_menu'][$mod] == "Y");
732 incrementConfigEntry('cache_hits');
733 } elseif ((IS_ADMIN()) && ($mod == "admin")) {
734 // Admin module has always a menu!
737 } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ((!EXT_IS_ACTIVE("cache")) || ($forceDb === true))) {
738 // Check database for entry
739 $result = SQL_QUERY_ESC("SELECT has_menu FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1",
740 array($mod), __FILE__, __LINE__);
743 if (SQL_NUMROWS($result) == 1) {
744 // Load "has_menu" column
745 list($has_menu) = SQL_FETCHROW($result);
748 $GLOBALS['cache_array']['extensions']['ext_menu'][$mod] = $has_menu;
750 // Does it have a menu?
751 $ret = ($has_menu == "Y");
755 SQL_FREERESULT($result);
756 } elseif (GET_EXT_VERSION("sql_patches") == "") {
757 // No sql_patches installed, so maybe in admin area or no admin registered?
758 $ret = (((IS_ADMIN()) || (!isAdminRegistered())) && ($mod == "admin")); // Then there is a menu!
762 //* DEBUG: */ var_dump($ret);
766 // Determines the task id for given extension
767 function DETERMINE_EXTENSION_TASK_ID ($ext_name) {
768 // Default is not found
771 // Search for extension task's id
772 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE task_type='EXTENSION' AND subject='[%s:]' LIMIT 1",
773 array($ext_name), __FILE__, __LINE__);
776 if (SQL_NUMROWS($result) == 1) {
777 // Task found so load task's ID and register extension...
778 list($task_id) = SQL_FETCHROW($result);
782 SQL_FREERESULT($result);
788 // Determines the task id for given subject
789 function DETERMINE_TASK_ID_BY_SUBJECT ($subject) {
790 // Default is not found
793 // Search for task id
794 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE subject LIKE '%s%%' LIMIT 1",
795 array($subject), __FILE__, __LINE__);
798 if (SQL_NUMROWS($result) == 1) {
799 // Task found so load task's ID and register extension...
800 list($task_id) = SQL_FETCHROW($result);
804 SQL_FREERESULT($result);
810 // Add updates notes for given version
811 function ADD_EXTENSION_NOTES ($ver) {
812 // Init notes/content
813 $out = ""; $content = array();
815 // Is do we have verbose output enabled?
816 if ((getConfig('verbose_sql') == "Y") || (!EXT_IS_ACTIVE("sql_patches"))) {
818 // Update notes found?
819 if (EXT_GET_UPDATE_NOTES() != "") {
820 // Update notes found
823 'notes' => EXT_GET_UPDATE_NOTES()
825 EXT_SET_UPDATE_NOTES("");
826 } elseif (($ver == "0.0") || ($ver == "0.0.0")) {
830 'notes' => getMessage('INITIAL_RELEASE')
833 // No update notes found!
836 'notes' => getMessage('NO_UPDATE_NOTES')
841 $out = LOAD_TEMPLATE("admin_ext_notes", true, $content);
848 // Getter for CSS files array
849 function EXT_GET_CSS_FILES () {
850 // By default no additional CSS files are found
853 // Is the array there?
854 if (isset($GLOBALS['css_files'])) {
856 $cssFiles = $GLOBALS['css_files'];
863 // Init CSS files array
864 function EXT_INIT_CSS_FILES () {
866 $GLOBALS['css_files'] = array();
870 function EXT_ADD_CSS_FILE ($file) {
871 // Is the array there?
872 if (!isset($GLOBALS['css_files'])) {
873 // Then auto-init them
874 EXT_INIT_CSS_FILES();
878 $GLOBALS['css_files'][] = $file;
881 // Setter for EXT_ALWAYS_ACTIVE flag
882 function EXT_SET_ALWAYS_ACTIVE ($active) {
883 $GLOBALS['ext_always_active'] = $active;
886 // Getter for EXT_ALWAYS_ACTIVE flag
887 function EXT_GET_ALWAYS_ACTIVE () {
888 return $GLOBALS['ext_always_active'];
891 // Setter for EXT_VERSION flag
892 function EXT_SET_VERSION ($version) {
893 $GLOBALS['ext_version'] = $version;
896 // Getter for EXT_VERSION flag
897 function EXT_GET_VERSION () {
898 return $GLOBALS['ext_version'];
901 // Setter for EXT_DEPRECATED flag
902 function EXT_SET_DEPRECATED ($deprecated) {
903 $GLOBALS['ext_deprecated'] = $deprecated;
906 // Getter for EXT_DEPRECATED flag
907 function EXT_GET_DEPRECATED () {
908 return $GLOBALS['ext_deprecated'];
911 // Setter for EXT_UPDATE_DEPENDS flag
912 function EXT_SET_UPDATE_DEPENDS ($updateDepends) {
913 $GLOBALS['ext_update_depends'] = $updateDepends;
916 // Getter for EXT_UPDATE_DEPENDS flag
917 function EXT_GET_UPDATE_DEPENDS () {
918 return $GLOBALS['ext_update_depends'];
921 // Setter for EXT_REPORTS_FAILURE flag
922 function EXT_SET_REPORTS_FAILURE ($reportsFailure) {
923 $GLOBALS['ext_reports_failure'] = $reportsFailure;
926 // Getter for EXT_REPORTS_FAILURE flag
927 function EXT_GET_REPORTS_FAILURE () {
928 return $GLOBALS['ext_reports_failure'];
931 // Setter for EXT_VER_HISTORY flag
932 function EXT_SET_VER_HISTORY ($verHistory) {
933 $GLOBALS['ext_ver_history'] = (array) $verHistory;
936 // Getter for EXT_VER_HISTORY flag
937 function EXT_GET_VER_HISTORY () {
938 return $GLOBALS['ext_ver_history'];
941 // Setter for EXT_UPDATE_NOTES flag
942 function EXT_SET_UPDATE_NOTES ($updateNotes) {
943 $GLOBALS['ext_update_notes'] = (array) $updateNotes;
946 // Getter for EXT_UPDATE_NOTES flag
947 function EXT_GET_UPDATE_NOTES () {
948 return $GLOBALS['ext_update_notes'];