2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/25/2009 *
4 * =============== Last change: 10/25/2009 *
6 * -------------------------------------------------------------------- *
7 * File : extensions-functions.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 - 2009 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')) {
44 // Load the extension and maybe found language and function files.
45 function loadExtension ($ext_name, $ext_mode = 'init', $ext_ver = '', $dry_run = false) {
46 // Set current extension name
47 setCurrentExtensionName($ext_name);
49 // Set current extension version
50 setCurrentExtensionVersion($ext_ver);
53 setExtensionMode($ext_mode);
56 enableExtensionDryRun($dry_run);
59 initIncludePool('extension');
61 // Init EXT_UPDATE_DEPENDS
62 initExtensionUpdateDependencies();
64 // Init current extension name list
67 // Is the extension already loaded?
68 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode=".getExtensionMode().", ver=".getCurrentExtensionVersion()."");
69 if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (getExtensionMode() == 'init')) {
71 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
77 // Is the extension file NOT there?
78 if (!isExtensionNameValid($ext_name)) {
80 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable.", $ext_name));
86 // Load extension's own language file if not in test mode
87 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
89 loadLanguageFile($ext_name);
93 if (isExtensionFunctionFileReadable($ext_name)) {
95 if (($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name]))) {
96 // Construct FQFN for functions file
97 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
100 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
102 // Download functions file
103 loadIncludeOnce($funcsInclude);
105 } elseif ((!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) && (isDebugModeEnabled()) && (getOutputMode() == '0') && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme') && (getExtensionMode() == 'test')) {
106 // No functions file is not so good...
107 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
113 // Extensions are not deprecated by default
114 setExtensionDeprecated('N');
116 // Extensions are not always active by default
117 setExtensionAlwaysActive('N');
119 // Extension update notes
120 setExtensionUpdateNotes('');
122 // Include the extension file
123 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Extension loaded.");
124 loadExtensionInclude();
126 // Is this extension deprecated?
127 if (isExtensionDeprecated()) {
128 // Deactivate the extension
129 doDeactivateExtension($ext_name);
135 // Mark it as loaded in normal mode
136 if (getExtensionMode() == '') {
138 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
145 // Registeres an extension and possible update depencies
146 function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = true) {
147 // Set current extension name
148 setCurrentExtensionName($ext_name);
151 enableExtensionDryRun($dry_run);
153 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
154 // This shall never do a non-admin user or if the extension is active (already installed)
155 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
159 // When this extension is already in install/update phase, all is fine
160 if (isExtensionRegisterRunning($ext_name)) {
161 // Then abort here which is fine
162 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ALREADY!");
166 // This registration is running
167 addExtensionRunningRegistration($ext_name);
169 // Init EXT_UPDATE_DEPENDS
170 initExtensionUpdateDependencies();
172 // Is the task id zero? Then we need to auto-fix it here
174 // Try to find the task
175 $task_id = determineExtensionTaskId(getCurrentExtensionName());
177 // Still zero and not in dry-run?
178 if (($task_id == 0) && (!getExtensionDryRun())) {
179 // Then request a bug report
180 debug_report_bug(sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
182 getCurrentExtensionName()
187 // Init queries and notes
189 initExtensionNotes();
194 initIncludePool('extension');
196 // By default we have no failures
197 setExtensionReportsFailure(false);
199 // Does this extension exists?
200 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
201 if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
202 // Set current extension name again
203 setCurrentExtensionName($ext_name);
205 // And run possible updates
206 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
207 $history = getExtensionVersionHistory();
208 foreach ($history as $ver) {
209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName().", ext_ver={$ver}");
210 // Load extension in update mode
211 loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
213 // Add update notes to our output
214 addExtensionNotes($ver);
217 // Does this extension depends on an outstanding update of another update?
218 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
220 $ext_update = getExtensionUpdateDependenciesIterator();
222 // Increment here to avoid endless loop
223 incrementExtensionUpdateIterator();
225 // Check for required file
226 if (loadExtension($ext_update, 'register', '', getExtensionDryRun())) {
227 // Set current extension name again
228 setCurrentExtensionName($ext_name);
230 // If versions mismatch update extension first
232 if (isExtensionInstalled($ext_update)) {
233 // Get version only if installed
234 $ext_ver = getExtensionVersion($ext_update);
237 // Extension version set? If empty the extension is not registered
238 if (empty($ext_ver)) {
239 // Extension not registered so far so first load task's ID...
240 $task = determineExtensionTaskId($ext_update);
244 // Try to register the extension
245 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().":ext_update=".$ext_update.",taskId=".$task."");
246 $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
248 // Reset extension name
249 setCurrentExtensionName($ext_name);
250 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test);
252 } elseif ($ext_ver != getCurrentExtensionVersion()) {
253 // Ok, update this extension now
254 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().",ext_update=".$ext_update.",ext_ver=".$ext_ver."/".getCurrentExtensionVersion()."");
255 $GLOBALS['ext_backup'][$ext_update][$ext_ver] = getCurrentExtensionName();
256 updateExtension($ext_update, $ext_ver, getExtensionDryRun());
257 setCurrentExtensionName($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
258 unset($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
259 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
264 // Nothing to register / update before...
268 // Required file for update does not exists!
270 // But this is fine for the first time...
273 // Restore the current extension name
274 setCurrentExtensionName($ext_name);
277 // Is there no update?
278 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
279 // Then test is passed!
283 // Switch back to register mode
284 setExtensionMode('register');
286 // Remains true if extension registration reports no failures
287 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
288 $test = (($test === true) && (getExtensionReportsFailure() === false));
289 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
291 // Does everthing before wents ok?
292 if ($test === true) {
293 // "Dry-run-mode" activated?
294 if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
295 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName());
296 // Init SQLs and transfer ext->generic
298 setSqlsArray(getExtensionSqls());
300 // Run installation pre-installation filters
301 runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
303 // Register extension
304 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "insert=".getCurrentExtensionName().'/'.getCurrentExtensionVersion()." - INSERT!");
305 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
307 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
308 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion(), getExtensionHasCss()), __FUNCTION__, __LINE__);
311 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
312 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion()), __FUNCTION__, __LINE__);
315 // Remove cache file(s) if extension is active
316 runFilterChain('post_extension_installed', array(
317 'pool' => 'extension',
318 'ext_name' => getCurrentExtensionName(),
319 'task_id' => $task_id
322 // Remove all SQL commands
325 // In normal mode return a true on success
327 } elseif (getExtensionDryRun() === true) {
328 // In "dry-run" mode return array with all SQL commands
329 $ret = getExtensionSqls();
331 // Remove all SQL commands
334 // Extension has been removed for updates, so all is fine!
338 // No, an error occurs while registering extension :-(
339 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
342 } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
343 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
344 // Remove task from system when id and extension's name is valid
345 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
346 array(bigintval($task_id)), __FUNCTION__, __LINE__);
349 // Is this the sql_patches?
350 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
351 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
352 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
353 if ($logout === true) {
354 // Then redirect to logout
355 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
357 // Add temporary filter
358 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
359 $GLOBALS['ext_load_mode'] = getExtensionMode();
363 // Return status code
364 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
365 //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
369 // Run SQL queries for given extension id
370 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
371 function doExtensionSqls ($ext_id, $load_mode) {
372 // This shall never do a non-admin user!
373 if (!isAdmin()) return false;
375 // Get extension's name
376 $ext_name = getExtensionName($ext_id);
378 // Set current SQL name
379 setCurrentExtensionName($ext_name);
381 // Init EXT_UPDATE_DEPENDS
382 initExtensionUpdateDependencies();
387 // By default no SQL has been executed
390 // Load extension in detected mode
391 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
392 loadExtension(getCurrentExtensionName(), $load_mode, '', false);
396 setSqlsArray(getExtensionSqls());
398 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
400 // Run SQL commands...
401 runFilterChain('run_sqls');
404 // Run any filters depending on the action here
405 runFilterChain('extension_' . $load_mode);
407 // Remove cache file(s) if extension is active
408 if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
410 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
413 // Is this the sql_patches?
414 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
415 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
416 // Then redirect to logout
417 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
418 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
422 // Check wether the given extension is installed
423 function isExtensionInstalled ($ext_name) {
424 // We don't like empty extension names here
425 if (empty($ext_name)) {
426 // Please fix them all
427 debug_report_bug(__FUNCTION__.': ext_name is empty.');
430 // By default non is installed
431 $isInstalled = false;
433 // Check if there is a cache entry
434 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
439 incrementStatsEntry('cache_hits');
440 } elseif ((isInstallationPhase())) {
441 // Extensions are all inactive/not installed during installation
444 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
445 array($ext_name), __FILE__, __LINE__);
447 // Do we have a record?
448 $isInstalled = (SQL_NUMROWS($result) == 1);
450 // Is it installed, then cache the entry
451 if ($isInstalled === true) {
453 getExtensionId($ext_name, true);
457 SQL_FREERESULT($result);
464 // Check if given extension is active
465 function isExtensionActive ($ext_name) {
466 // Extensions are all inactive during installation
467 if ((isInstallationPhase()) || (empty($ext_name))) return false;
469 // Not active is the default
473 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
475 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
476 $active = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
479 incrementStatsEntry('cache_hits');
480 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
481 // @TODO Extension is loaded, what next?
482 app_die(__FUNCTION__, __LINE__, "LOADED:$ext_name");
483 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
484 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
485 // Load from database
486 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
487 array($ext_name), __FUNCTION__, __LINE__);
490 if (SQL_NUMROWS($result) == 1) {
492 list($active) = SQL_FETCHROW($result);
496 SQL_FREERESULT($result);
499 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: {$active}");
500 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $active;
502 // Extension not active!
503 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!");
504 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
508 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name={$ext_name},active={$active}");
510 // Is this extension activated? (For admins we always have active extensions...)
511 return ($active == 'Y');
514 // Get version from extensions
515 function getExtensionVersion ($ext_name) {
516 // By default no extension is found
517 $ext_ver = 'invalid';
519 // Empty extension name should be fixed!
520 if (empty($ext_name)) {
521 // Please report this bug!
522 debug_report_bug(__FUNCTION__ . ': ext_name is empty which is not allowed here.');
525 // Extensions are all inactive during installation
526 if (isInstallationPhase()) return '';
527 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
529 // Is the cache written?
530 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
531 // Load data from cache
532 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": CACHE!");
533 $ext_ver = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
536 incrementStatsEntry('cache_hits');
537 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != '0')) {
538 // Load from database
539 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
540 array($ext_name), __FUNCTION__, __LINE__);
541 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
543 // Is the extension there?
544 if (SQL_NUMROWS($result) == 1) {
546 list($ext_ver) = SQL_FETCHROW($result);
547 } elseif (isDebugModeEnabled()) {
549 logDebugMessage(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
553 SQL_FREERESULT($result);
556 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $ext_ver;
559 // Extension version should not be invalid
560 if ($ext_ver == 'invalid') {
561 // Please report this trouble
562 debug_report_bug(sprintf("Extension <strong>%s</strong> has empty version!", $ext_name));
566 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
570 // Updates a given extension with current extension version to latest version
571 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
572 // Only admins are allowed to update extensions
573 if ((!isAdmin()) || (empty($ext_name))) return false;
575 // Set current SQL name
576 setCurrentExtensionName($ext_name);
580 initExtensionNotes();
581 initIncludePool('extension');
583 // Load extension in test mode
584 loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
586 // Save version history
587 $history = getExtensionVersionHistory();
589 // Remove old SQLs array to prevent possible bugs
592 // Check if version is updated
593 //* DEBUG: */ print getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)).'<br />';
594 if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
595 // Search for starting point
596 $start = array_search($ext_ver, $history);
598 // And load SQL queries in order of version history
599 for ($idx = ($start + 1); $idx < count($history); $idx++) {
600 // Set extension version
601 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
604 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
607 $depencies = getExtensionUpdateDependencies();
610 if (count($depencies) > 0) {
611 // Apply all extension depencies
612 foreach ($depencies as $ext_depend) {
614 setCurrentExtensionName($ext_depend);
616 // Is the extension there?
617 if (isExtensionInstalled()) {
618 // Update another extension first!
619 $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
621 // Register new extension
622 $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
627 setCurrentExtensionName($ext_name);
631 addExtensionNotes($history[$idx]);
634 // In real-mode execute any existing includes
635 if (getExtensionDryRun() === false) {
636 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
637 runFilterChain('load_includes', 'extension');
638 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
639 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
644 setSqlsArray(getExtensionSqls());
647 runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
649 if (getExtensionDryRun() === false) {
650 // Run filters on success extension update
651 runFilterChain('extension_update', getCurrentExtensionName());
656 // Output verbose SQL table for extension
657 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
660 // Then fix it to default
661 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
667 // Do we have queries?
668 if ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
673 foreach (getExtensionSqls() as $idx => $sqls) {
674 // New array format is recursive
675 foreach ($sqls as $sql) {
679 // Output command if set
681 // Prepare output for template
689 $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
697 // Prepare content for template
705 // Load main template
706 $OUT = loadTemplate('admin_ext_sql_table', true, $content);
707 } elseif ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
708 // No addional SQL commands to run
709 $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
716 // Get extension name from id
717 function getExtensionName ($ext_id) {
718 // Init extension name
722 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
724 $ret = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
727 incrementStatsEntry('cache_hits');
728 } elseif (!isExtensionActive('cache')) {
729 // Load from database
730 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
731 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
733 // Is the entry there?
734 if (SQL_NUMROWS($result) == 1) {
735 // Get the extension's name from database
736 list($ret) = SQL_FETCHROW($result);
740 SQL_FREERESULT($result);
743 // Did we find some extension?
745 // We should fix these all!
746 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
749 // Return the extension name
753 // Get extension id from name
754 function getExtensionId ($ext_name, $forceDb = false) {
758 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
760 $ret = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
763 incrementStatsEntry('cache_hits');
764 } elseif (($forceDb === true) || (!isExtensionActive('cache'))) {
765 // Load from database
766 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
767 array($ext_name), __FUNCTION__, __LINE__);
769 // Is the entry there?
770 if (SQL_NUMROWS($result) == 1) {
771 // Get the extension's id from database
772 list($ret) = SQL_FETCHROW($result);
775 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
779 SQL_FREERESULT($result);
783 // We should fix these all!
784 debug_report_bug(__FUNCTION__ . ': Invalid extension name found. ext_name=' . $ext_name);
791 // Determines wether the given extension name is valid
792 function isExtensionNameValid ($ext_name) {
794 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
795 // Generate include file name
796 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
798 // Is there a file in inc/extensions/ ?
799 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
803 return $GLOBALS['ext_name_valid'][$ext_name];
806 // Determines wether the given extension id is valid
807 function isExtensionIdValid ($ext_id) {
808 // Default is nothing valid
811 // Check in cache then in database
812 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
817 incrementStatsEntry('cache_hits');
820 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
827 // Activate given extension
828 function doActivateExtension ($ext_name) {
829 // Activate the extension
830 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
831 array($ext_name), __FUNCTION__, __LINE__);
833 // Extension has been activated?
834 if (SQL_AFFECTEDROWS() == 1) {
835 // Then run all queries
836 doExtensionSqls(getExtensionId($ext_name), 'activate');
840 // Deactivate given extension
841 function doDeactivateExtension($ext_name) {
842 // Activate the extension
843 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
844 array($ext_name), __FUNCTION__, __LINE__);
846 // Extension has been activated?
847 if (SQL_AFFECTEDROWS() == 1) {
848 // Then run all queries
849 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
852 createExtensionDeactivationTask($ext_name);
855 sendAdminNotification(
856 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
857 'admin_ext_deactivated',
858 array('ext_name' => $ext_name)
863 // Checks wether the extension is older than given
864 function isExtensionOlder ($ext_name, $ext_ver) {
865 // Get current extension version
866 $currVersion = getExtensionVersion($ext_name);
868 // Remove all dots from both versions
869 $currVersion = str_replace('.', '', $currVersion);
870 $ext_ver = str_replace('.', '', $ext_ver);
872 // Now compare both and return the result
873 return ($currVersion < $ext_ver);
876 // Creates a new task for updated extension
877 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
878 // Create subject line
879 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
881 // Is the extension there?
882 if (isExtensionInstalled($ext_name)) {
883 // Check if task is not there
884 if (determineTaskIdBySubject($subject) == 0) {
885 // Create extension update-task
886 createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
889 // Extension not there! :-(
890 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
894 // Creates a new task for newly installed extension
895 function createNewExtensionTask ($adminId, $subject, $ext) {
896 // Not installed and do we have created a task for the admin?
897 if ((determineTaskIdBySubject($subject) == 0) && (!isExtensionInstalled($ext))) {
898 // Set default message if ext-foo is missing
899 $message = sprintf(getMessage('ADMIN_EXT_TEXT_FILE_MISSING'), $ext);
902 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
908 // Load text for task if found
909 if (isFileReadable($tpl)) {
910 // Load extension's own text template (HTML!)
911 $message = loadTemplate('ext_' . $ext, true);
913 // Write this in debug.log as well
914 logDebugMessage(__FUNCTION__, __LINE__, $message);
917 // Task not created so it's a brand-new extension which we need to register and create a task for!
918 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
922 // Creates a task for automatically deactivated (deprecated) extension
923 function createExtensionDeactivationTask ($ext) {
924 // Create subject line
925 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
927 // Not installed and do we have created a task for the admin?
928 if ((determineTaskIdBySubject($subject) == 0) && (getExtensionVersion($ext) != '')) {
929 // Task not created so add it
930 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
934 // Checks if the module has a menu
935 function ifModuleHasMenu ($mod, $forceDb = false) {
936 // All is false by default
939 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "mod={$mod},cache=".getExtensionVersion('cache'));
940 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
941 // Cache version is okay, so let's check the cache!
942 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
943 // Check module cache and count hit
944 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
945 incrementStatsEntry('cache_hits');
946 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
947 // Check cache and count hit
948 $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
949 incrementStatsEntry('cache_hits');
950 } elseif ($mod == 'admin') {
951 // Admin module has always a menu!
954 } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
955 // Check database for entry
956 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
957 array($mod), __FUNCTION__, __LINE__);
960 if (SQL_NUMROWS($result) == 1) {
961 // Load "has_menu" column
962 list($has_menu) = SQL_FETCHROW($result);
965 $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $has_menu;
967 // Does it have a menu?
968 $ret = ($has_menu == 'Y');
972 SQL_FREERESULT($result);
973 } elseif (!isExtensionInstalled('sql_patches')) {
974 // No sql_patches installed, so maybe in admin area or no admin registered?
975 $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu!
979 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().intval($ret));
983 // Determines the task id for given extension
984 function determineExtensionTaskId ($ext_name) {
985 // Default is not found
988 // Search for extension task's id
989 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
990 array($ext_name), __FUNCTION__, __LINE__);
993 if (SQL_NUMROWS($result) == 1) {
994 // Task found so load task's ID and register extension...
995 list($task_id) = SQL_FETCHROW($result);
999 SQL_FREERESULT($result);
1005 // Determines the task id for given subject
1006 function determineTaskIdBySubject ($subject) {
1007 // Default is not found
1010 // Search for task id
1011 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1012 array($subject), __FUNCTION__, __LINE__);
1015 if (SQL_NUMROWS($result) == 1) {
1016 // Task found so load task's ID and register extension...
1017 list($task_id) = SQL_FETCHROW($result);
1021 SQL_FREERESULT($result);
1027 // Add updates notes for given version
1028 function addExtensionNotes ($ver) {
1029 // Init notes/content
1030 $out = ''; $content = array();
1032 // Is do we have verbose output enabled?
1033 if ((getConfig('verbose_sql') == 'Y') || (!isExtensionActive('sql_patches'))) {
1034 // Update notes found?
1035 if (getExtensionUpdateNotes($ver) != '') {
1036 // Update notes found
1039 'notes' => getExtensionUpdateNotes($ver)
1043 setExtensionUpdateNotes('', $ver);
1044 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1048 'notes' => getMessage('INITIAL_RELEASE')
1051 // No update notes found!
1054 'notes' => getMessage('NO_UPDATE_NOTES')
1059 $out = loadTemplate('admin_ext_notes', true, $content);
1063 appendExtensionNotes($out);
1066 // Getter for CSS files array
1067 function getExtensionCssFiles () {
1068 // By default no additional CSS files are found
1069 $cssFiles = array();
1071 // Is the array there?
1072 if (isset($GLOBALS['css_files'])) {
1074 $cssFiles = $GLOBALS['css_files'];
1081 // Init CSS files array
1082 function initExtensionCssFiles () {
1084 $GLOBALS['css_files'] = array();
1088 function addExtensionCssFile ($file) {
1089 // Is the array there?
1090 if (!isset($GLOBALS['css_files'])) {
1091 // Then auto-init them
1092 initExtensionCssFiles();
1096 $GLOBALS['css_files'][] = $file;
1099 // Setter for EXT_ALWAYS_ACTIVE flag
1100 function setExtensionAlwaysActive ($active) {
1101 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1104 // Getter for EXT_ALWAYS_ACTIVE flag
1105 function getExtensionAlwaysActive () {
1106 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1109 // Setter for EXT_VERSION flag
1110 function setThisExtensionVersion ($version) {
1111 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1114 // Getter for EXT_VERSION flag
1115 function getThisExtensionVersion () {
1116 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1119 // Setter for EXT_DEPRECATED flag
1120 function setExtensionDeprecated ($deprecated) {
1121 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1124 // Getter for EXT_DEPRECATED flag
1125 function isExtensionDeprecated () {
1126 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1129 // Setter for EXT_UPDATE_DEPENDS flag
1130 function addExtensionUpdateDependency ($updateDepends) {
1131 // Is the update depency empty? (NEED TO BE FIXED!)
1132 if (empty($updateDepends)) {
1133 // Please report this bug!
1134 debug_report_bug("updateDepends is left empty!");
1137 // Is it not yet added?
1138 if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1139 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1140 // Add it to the list of extension update depencies map
1141 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1143 // Remember it in the list of running updates
1144 $GLOBALS['ext_running_updates'][] = $updateDepends;
1148 // Checks wether the given extension registration is in progress
1149 function isExtensionRegisterRunning ($ext_name) {
1150 return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1153 // Init EXT_UPDATE_DEPENDS flag
1154 function initExtensionUpdateDependencies () {
1155 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1157 // Init update depency map automatically if not found
1158 if (!isExtensionUpdateDependenciesInitialized()) {
1159 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1160 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1163 // Init running updates array
1164 initExtensionRuningUpdates();
1167 // Adds an extension as "registration in progress"
1168 function addExtensionRunningRegistration ($ext_name) {
1170 if (!isExtensionRegisterRunning($ext_name)) {
1172 $GLOBALS['ext_register_running'][] = $ext_name;
1176 // Checks wether EXT_UPDATE_DEPENDS is initialized
1177 function isExtensionUpdateDependenciesInitialized () {
1178 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1179 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1182 // Initializes the list of running updates
1183 function initExtensionRuningUpdates () {
1184 // Auto-init ext_running_updates
1185 if (!isset($GLOBALS['ext_running_updates'])) {
1186 $GLOBALS['ext_running_updates'] = array();
1187 $GLOBALS['ext_register_running'] = array();
1191 // Getter for EXT_UPDATE_DEPENDS flag
1192 function getExtensionUpdateDependencies () {
1193 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1194 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1197 // Getter for next iterator depency
1198 function getExtensionUpdateDependenciesIterator () {
1199 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1200 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1203 // Counter for extension update depencies
1204 function countExtensionUpdateDependencies () {
1205 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1206 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1209 // Removes given extension from update denpency list
1210 function removeExtensionUpdateDependency ($ext_name) {
1212 $key = array_search($ext_name, getExtensionUpdateDependencies());
1215 if ($key !== false) {
1217 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1219 // And sort the array
1220 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1224 // Init iterator for update depencies
1225 function initExtensionUpdateIterator () {
1226 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1227 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = 0;
1230 // Getter for depency iterator
1231 function getExtensionUpdateIterator () {
1232 // Auto-init iterator
1233 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1236 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1237 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1240 // Increments the update iterator
1241 function incrementExtensionUpdateIterator () {
1242 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1243 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1246 // Setter for EXT_REPORTS_FAILURE flag
1247 function setExtensionReportsFailure ($reportsFailure) {
1248 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1251 // Getter for EXT_REPORTS_FAILURE flag
1252 function getExtensionReportsFailure () {
1253 return $GLOBALS['ext_reports_failure'];
1256 // Setter for EXT_VER_HISTORY flag
1257 function setExtensionVersionHistory ($verHistory) {
1258 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1261 // Getter for EXT_VER_HISTORY array
1262 function getExtensionVersionHistory () {
1263 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1266 // Setter for EXT_UPDATE_NOTES
1267 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1268 //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1270 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1272 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1276 // Getter for EXT_UPDATE_NOTES
1277 function getExtensionUpdateNotes ($ver) {
1278 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1281 // Init extension notice
1282 function initExtensionNotes () {
1283 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1286 // Append extension notice
1287 function appendExtensionNotes ($notes) {
1288 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1291 // Getter for extension notes
1292 function getExtensionNotes () {
1293 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1296 // Setter for current extension name
1297 function setCurrentExtensionName ($ext_name) {
1298 $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1301 // Getter for current extension name
1302 function getCurrentExtensionName () {
1303 if (isset($GLOBALS['curr_ext_name'])) {
1304 return $GLOBALS['curr_ext_name'];
1308 debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1311 // Init SQLs array for current extension
1312 function initExtensionSqls () {
1313 // Auto-init the array now...
1314 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1315 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1319 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1320 function addExtensionSql ($sql) {
1322 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1325 // Getter for SQLs array for current extension
1326 function getExtensionSqls () {
1327 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1328 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1329 // Not found, should not happen
1330 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1331 getCurrentExtensionName()
1336 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1339 // Removes SQLs for current extension
1340 function unsetExtensionSqls () {
1341 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1344 // Auto-initializes the removal list
1345 function initExtensionRemovalList () {
1346 // Is the remove list there?
1347 if (!isset($GLOBALS['ext_update_remove'])) {
1349 $GLOBALS['ext_update_remove'] = array();
1353 // Checks wether the current extension is on the removal list
1354 function isExtensionOnRemovalList () {
1355 // Init removal list
1356 initExtensionRemovalList();
1359 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1362 // Adds the current extension to the removal list
1363 function addCurrentExtensionToRemovalList () {
1365 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1368 // Getter for removal list
1369 function getExtensionRemovalList () {
1370 // Return the removal list
1371 return $GLOBALS['ext_update_remove'];
1374 // Redirects if the provided extension is not installed
1375 function redirectOnUninstalledExtension ($ext_name) {
1376 // So is the extension there?
1377 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1378 // Redirect to index
1379 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1383 // Filter for initialization of all extensions by loading them in 'init' mode
1384 function FILTER_INIT_EXTENSIONS () {
1385 // Do we have some entries?
1386 //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1387 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1388 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1389 // Load all found extensions if found
1390 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key=>$ext_name) {
1392 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1393 loadExtension($ext_name, 'init');
1394 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1396 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1398 //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1401 // Setter for extension mode
1402 function setExtensionMode ($ext_mode) {
1403 $GLOBALS['ext_mode'] = (string) $ext_mode;
1406 // Getter for extension mode
1407 function getExtensionMode () {
1408 return $GLOBALS['ext_mode'];
1411 // Setter for dry-run
1412 function enableExtensionDryRun ($dry_run = true) {
1413 //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1414 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1417 // Getter for dry-run
1418 function getExtensionDryRun () {
1419 return $GLOBALS['ext_dry_run'];
1422 // Setter for current extension version
1423 function setCurrentExtensionVersion ($ext_ver) {
1424 if (empty($ext_ver)) {
1426 $GLOBALS['ext_current_version'] = '0.0';
1429 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1433 // Getter for current extension version
1434 function getCurrentExtensionVersion () {
1435 return $GLOBALS['ext_current_version'];
1438 // Remove the extension from global cache array
1439 function removeExtensionFromArray () {
1440 // "Cache" this name
1441 $ext_name = getCurrentExtensionName();
1443 // Now loop through the whole cache
1444 foreach ($GLOBALS['cache_array']['extension'] as $cacheName=>$cacheArray) {
1445 // Is it an element?
1446 if (isset($cacheArray[$ext_name])) {
1448 unset($cacheArray[$ext_name]);
1449 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1452 $key = array_search($ext_name, $cacheArray);
1455 if ($key !== false) {
1456 // Found, so remove it
1457 unset($cacheArray[$key]);
1458 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1464 // "Getter" for 'extension has a CSS file' (with same name, of course)
1465 function getExtensionHasCss () {
1466 // Default is no CSS
1469 // Construct FQFN for check
1470 $FQFN = sprintf("%stheme/%s/css/%s.css",
1473 getCurrentExtensionName()
1477 if (isFileReadable($FQFN)) {
1478 // Readable, so it is there...
1486 // Checks wether the given extension has a language file
1487 function ifExtensionHasLanguageFile ($ext_name) {
1488 // Default is no language file
1489 $hasLanguage = false;
1491 // Do we have cache?
1492 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1494 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1497 incrementStatsEntry('cache_hits');
1499 // Not readable is default
1502 // Is the language file readable for this extension?
1503 if (isLanguageIncludeReadable($ext_name)) {
1509 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1513 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1516 // Load an extension's include file
1517 function loadExtensionInclude () {
1519 if (!isExtensionIncludeReadable()) {
1521 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1524 // Generate INC name
1525 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1531 // Checks wether an extension is readable
1532 function isExtensionIncludeReadable ($ext_name = '') {
1533 // If empty, use current
1534 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1537 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1538 // Generate INC name
1539 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1542 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1546 //* DEBUG: */ print __FUNCTION__.': '.$ext_name.'='.intval($GLOBALS['ext_inc_readable'][$ext_name]).'<br />';
1547 return $GLOBALS['ext_inc_readable'][$ext_name];
1550 // Checks if an extension's function file is readable
1551 function isExtensionFunctionFileReadable ($ext_name) {
1552 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1553 // Just count cache hits
1554 incrementStatsEntry('cache_hits');
1556 // Construct FQFN for functions file
1557 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1559 // Is this include there?
1560 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1562 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1565 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1570 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');