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['cache_array']['extension']['ext_func'][$ext_name]))) && (!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 // By default all extensions are in productive phase
154 enableExtensionProductive();
156 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
157 // This shall never do a non-admin user or if the extension is active (already installed)
158 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
162 // When this extension is already in install/update phase, all is fine
163 if (isExtensionRegisterRunning($ext_name)) {
164 // Then abort here which is fine
165 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ALREADY!");
169 // This registration is running
170 addExtensionRunningRegistration($ext_name);
172 // Init EXT_UPDATE_DEPENDS
173 initExtensionUpdateDependencies();
175 // Is the task id zero? Then we need to auto-fix it here
177 // Try to find the task
178 $task_id = determineExtensionTaskId(getCurrentExtensionName());
180 // Still zero and not in dry-run?
181 if (($task_id == 0) && (!getExtensionDryRun())) {
182 // Then request a bug report
183 debug_report_bug(sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
185 getCurrentExtensionName()
190 // Init queries and notes
192 initExtensionNotes();
197 initIncludePool('extension');
199 // By default we have no failures
200 setExtensionReportsFailure(false);
202 // Does this extension exists?
203 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
204 if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
205 // Set current extension name again
206 setCurrentExtensionName($ext_name);
208 // And run possible updates
209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
210 $history = getExtensionVersionHistory();
211 foreach ($history as $ver) {
212 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName().", ext_ver={$ver}");
213 // Load extension in update mode
214 loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
216 // Add update notes to our output
217 addExtensionNotes($ver);
220 // Does this extension depends on an outstanding update of another update?
221 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
223 $ext_update = getExtensionUpdateDependenciesIterator();
225 // Increment here to avoid endless loop
226 incrementExtensionUpdateIterator();
228 // Check for required file
229 if (loadExtension($ext_update, 'register', '', getExtensionDryRun())) {
230 // Set current extension name again
231 setCurrentExtensionName($ext_name);
233 // If versions mismatch update extension first
235 if (isExtensionInstalled($ext_update)) {
236 // Get version only if installed
237 $ext_ver = getExtensionVersion($ext_update);
240 // Extension version set? If empty the extension is not registered
241 if (empty($ext_ver)) {
242 // Extension not registered so far so first load task's id...
243 $task = determineExtensionTaskId($ext_update);
247 // Try to register the extension
248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().":ext_update=".$ext_update.",taskId=".$task."");
249 $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
251 // Reset extension name
252 setCurrentExtensionName($ext_name);
253 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test);
255 } elseif ($ext_ver != getCurrentExtensionVersion()) {
256 // Ok, update this extension now
257 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().",ext_update=".$ext_update.",ext_ver=".$ext_ver."/".getCurrentExtensionVersion()."");
258 $GLOBALS['ext_backup'][$ext_update][$ext_ver] = getCurrentExtensionName();
259 updateExtension($ext_update, $ext_ver, getExtensionDryRun());
260 setCurrentExtensionName($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
261 unset($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
262 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
267 // Nothing to register / update before...
271 // Required file for update does not exists!
273 // But this is fine for the first time...
276 // Restore the current extension name
277 setCurrentExtensionName($ext_name);
280 // Is there no update?
281 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
282 // Then test is passed!
286 // Switch back to register mode
287 setExtensionMode('register');
289 // Remains true if extension registration reports no failures
290 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
291 $test = (($test === true) && (getExtensionReportsFailure() === false));
292 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
294 // Does everthing before wents ok?
295 if ($test === true) {
296 // "Dry-run-mode" activated?
297 if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
298 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName());
299 // Init SQLs and transfer ext->generic
301 setSqlsArray(getExtensionSqls());
303 // Run installation pre-installation filters
304 runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
306 // Register extension
307 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "insert=".getCurrentExtensionName().'/'.getCurrentExtensionVersion()." - INSERT!");
308 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
310 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
311 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion(), getExtensionHasCss()), __FUNCTION__, __LINE__);
314 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
315 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion()), __FUNCTION__, __LINE__);
318 // Remove cache file(s) if extension is active
319 runFilterChain('post_extension_installed', array(
320 'pool' => 'extension',
321 'ext_name' => getCurrentExtensionName(),
322 'task_id' => $task_id
325 // Remove all SQL commands
328 // Mark it as installed
329 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
331 // In normal mode return a true on success
333 } elseif (getExtensionDryRun() === true) {
334 // In "dry-run" mode return array with all SQL commands
335 $ret = getExtensionSqls();
337 // Remove all SQL commands
340 // Extension has been removed for updates, so all is fine!
344 // No, an error occurs while registering extension :-(
345 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
348 } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
349 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
350 // Remove task from system when id and extension's name is valid
351 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
352 array(bigintval($task_id)), __FUNCTION__, __LINE__);
355 // Is this the sql_patches?
356 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
357 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
358 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
359 if ($logout === true) {
360 // Then redirect to logout
361 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
363 // Add temporary filter
364 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
365 $GLOBALS['ext_load_mode'] = getExtensionMode();
369 // Return status code
370 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
371 //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
375 // Run SQL queries for given extension id
376 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
377 function doExtensionSqls ($ext_id, $load_mode) {
378 // This shall never do a non-admin user!
379 if (!isAdmin()) return false;
381 // Get extension's name
382 $ext_name = getExtensionName($ext_id);
384 // Set current SQL name
385 setCurrentExtensionName($ext_name);
387 // Init EXT_UPDATE_DEPENDS
388 initExtensionUpdateDependencies();
393 // By default no SQL has been executed
396 // Load extension in detected mode
397 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
398 loadExtension(getCurrentExtensionName(), $load_mode, '', false);
402 setSqlsArray(getExtensionSqls());
404 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
406 // Run SQL commands...
407 runFilterChain('run_sqls');
410 // Run any filters depending on the action here
411 runFilterChain('extension_' . $load_mode);
413 // Remove cache file(s) if extension is active
414 if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
416 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
419 // Is this the sql_patches?
420 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
421 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
422 // Then redirect to logout
423 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
424 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
428 // Check wether the given extension is installed
429 function isExtensionInstalled ($ext_name) {
430 // We don't like empty extension names here
431 if (empty($ext_name)) {
432 // Please fix them all
433 debug_report_bug(__FUNCTION__.': ext_name is empty.');
436 // By default non is installed
437 $isInstalled = false;
439 // Check if there is a cache entry
440 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
441 // Use cache built from below queries
442 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
443 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
448 incrementStatsEntry('cache_hits');
449 } elseif ((isInstallationPhase())) {
450 // Extensions are all inactive/not installed during installation
453 $ext_id = getExtensionId($ext_name);
455 // Do we have a record?
456 $isInstalled = ($ext_id > 0);
458 // Is it installed, then cache the entry
459 if ($isInstalled === true) {
460 // Dummy call (get is okay here)
461 getExtensionId($ext_name, true);
464 // Remember the status
465 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
472 // Check if given extension is active
473 function isExtensionActive ($ext_name) {
474 // Extensions are all inactive during installation
475 if ((isInstallationPhase()) || (empty($ext_name))) return false;
477 // Not active is the default
481 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
483 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
484 $active = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
487 incrementStatsEntry('cache_hits');
488 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
489 // @TODO Extension is loaded, what next?
490 app_die(__FUNCTION__, __LINE__, "LOADED:$ext_name");
491 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
492 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
493 // Load from database
494 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
495 array($ext_name), __FUNCTION__, __LINE__);
498 if (SQL_NUMROWS($result) == 1) {
500 list($active) = SQL_FETCHROW($result);
504 SQL_FREERESULT($result);
507 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: {$active}");
508 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $active;
510 // Extension not active!
511 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!");
512 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
516 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name={$ext_name},active={$active}");
518 // Is this extension activated? (For admins we always have active extensions...)
519 return ($active == 'Y');
522 // Get version from extensions
523 function getExtensionVersion ($ext_name) {
524 // By default no extension is found
525 $ext_ver = 'invalid';
527 // Empty extension name should be fixed!
528 if (empty($ext_name)) {
529 // Please report this bug!
530 debug_report_bug(__FUNCTION__ . ': ext_name is empty which is not allowed here.');
533 // Extensions are all inactive during installation
534 if (isInstallationPhase()) return '';
535 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name={$ext_name}");
537 // Is the cache written?
538 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
539 // Load data from cache
540 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": CACHE!");
541 $ext_ver = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
544 incrementStatsEntry('cache_hits');
545 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != 0)) {
546 // Load from database
547 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
548 array($ext_name), __FUNCTION__, __LINE__);
549 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
551 // Is the extension there?
552 if (SQL_NUMROWS($result) == 1) {
554 list($ext_ver) = SQL_FETCHROW($result);
555 } elseif (isDebugModeEnabled()) {
557 logDebugMessage(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
561 SQL_FREERESULT($result);
564 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $ext_ver;
567 // Extension version should not be invalid
568 if ($ext_ver == 'invalid') {
569 // Please report this trouble
570 debug_report_bug(sprintf("Extension <strong>%s</strong> has empty version!", $ext_name));
574 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$ext_ver}");
578 // Updates a given extension with current extension version to latest version
579 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
580 // Only admins are allowed to update extensions
581 if ((!isAdmin()) || (empty($ext_name))) return false;
583 // Set current SQL name
584 setCurrentExtensionName($ext_name);
588 initExtensionNotes();
589 initIncludePool('extension');
591 // Load extension in test mode
592 loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
594 // Save version history
595 $history = getExtensionVersionHistory();
597 // Remove old SQLs array to prevent possible bugs
600 // Check if version is updated
601 //* DEBUG: */ print getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)).'<br />';
602 if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
603 // Search for starting point
604 $start = array_search($ext_ver, $history);
606 // And load SQL queries in order of version history
607 for ($idx = ($start + 1); $idx < count($history); $idx++) {
608 // Set extension version
609 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
612 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
615 $depencies = getExtensionUpdateDependencies();
618 if (count($depencies) > 0) {
619 // Apply all extension depencies
620 foreach ($depencies as $ext_depend) {
621 // Did we already update/register this?
622 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
624 setCurrentExtensionName($ext_depend);
626 // Mark it as already updated before we update it
627 $GLOBALS['ext_updated'][$ext_depend] = true;
629 // Is the extension there?
630 if (isExtensionInstalled($ext_depend)) {
631 // Update another extension first!
632 $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
634 // Register new extension
635 $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
641 setCurrentExtensionName($ext_name);
645 addExtensionNotes($history[$idx]);
648 // In real-mode execute any existing includes
649 if (getExtensionDryRun() === false) {
650 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
651 runFilterChain('load_includes', 'extension');
652 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
653 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
658 setSqlsArray(getExtensionSqls());
661 runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
663 if (getExtensionDryRun() === false) {
664 // Run filters on success extension update
665 runFilterChain('extension_update', getCurrentExtensionName());
670 // Output verbose SQL table for extension
671 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
674 // Then fix it to default
675 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
681 // Do we have queries?
682 if ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
687 foreach (getExtensionSqls() as $sqls) {
688 // New array format is recursive
689 foreach ($sqls as $idx => $sql) {
693 // Output command if set
695 // Prepare output for template
703 $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
711 // Prepare content for template
719 // Load main template
720 $OUT = loadTemplate('admin_ext_sql_table', true, $content);
721 } elseif ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
722 // No addional SQL commands to run
723 $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
730 // Get extension name from id
731 function getExtensionName ($ext_id) {
732 // Init extension name
736 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
738 $ret = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
741 incrementStatsEntry('cache_hits');
742 } elseif (!isExtensionActive('cache')) {
743 // Load from database
744 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
745 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
747 // Is the entry there?
748 if (SQL_NUMROWS($result) == 1) {
749 // Get the extension's name from database
750 list($ret) = SQL_FETCHROW($result);
754 SQL_FREERESULT($result);
757 // Did we find some extension?
759 // We should fix these all!
760 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
763 // Return the extension name
767 // Get extension id from name
768 function getExtensionId ($ext_name) {
773 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
775 $ret = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
778 incrementStatsEntry('cache_hits');
780 // Load from database
781 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
782 array($ext_name), __FUNCTION__, __LINE__);
784 // Is the entry there?
785 if (SQL_NUMROWS($result) == 1) {
786 // Get the extension's id from database
787 list($ret) = SQL_FETCHROW($result);
791 SQL_FREERESULT($result);
794 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
801 // Determines wether the given extension name is valid
802 function isExtensionNameValid ($ext_name) {
804 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
805 // Generate include file name
806 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
808 // Is there a file in inc/extensions/ ?
809 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
813 return $GLOBALS['ext_name_valid'][$ext_name];
816 // Determines wether the given extension id is valid
817 function isExtensionIdValid ($ext_id) {
818 // Default is nothing valid
821 // Check in cache then in database
822 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
827 incrementStatsEntry('cache_hits');
830 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
837 // Activate given extension
838 function doActivateExtension ($ext_name) {
839 // Activate the extension
840 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
841 array($ext_name), __FUNCTION__, __LINE__);
843 // Extension has been activated?
844 if (SQL_AFFECTEDROWS() == 1) {
845 // Then run all queries
846 doExtensionSqls(getExtensionId($ext_name), 'activate');
850 // Deactivate given extension
851 function doDeactivateExtension($ext_name) {
852 // Activate the extension
853 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
854 array($ext_name), __FUNCTION__, __LINE__);
856 // Extension has been activated?
857 if (SQL_AFFECTEDROWS() == 1) {
858 // Then run all queries
859 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
862 createExtensionDeactivationTask($ext_name);
865 sendAdminNotification(
866 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
867 'admin_ext_deactivated',
868 array('ext_name' => $ext_name)
873 // Checks wether the extension is older than given
874 function isExtensionOlder ($ext_name, $ext_ver) {
875 // Get current extension version
876 $currVersion = getExtensionVersion($ext_name);
878 // Remove all dots from both versions
879 $currVersion = str_replace('.', '', $currVersion);
880 $ext_ver = str_replace('.', '', $ext_ver);
882 // Now compare both and return the result
883 return ($currVersion < $ext_ver);
886 // Creates a new task for updated extension
887 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
888 // Create subject line
889 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
891 // Is the extension there?
892 if (isExtensionInstalled($ext_name)) {
893 // Check if task is not there
894 if (determineTaskIdBySubject($subject) == 0) {
895 // Create extension update-task
896 createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
899 // Extension not there! :-(
900 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
904 // Creates a new task for newly installed extension
905 function createNewExtensionTask ($adminId, $subject, $ext) {
906 // Not installed and do we have created a task for the admin?
907 if ((determineTaskIdBySubject($subject) == 0) && (!isExtensionInstalled($ext))) {
908 // Set default message if ext-foo is missing
909 $message = sprintf(getMessage('ADMIN_EXT_TEXT_FILE_MISSING'), $ext);
912 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
918 // Load text for task if found
919 if (isFileReadable($tpl)) {
920 // Load extension's own text template (HTML!)
921 $message = loadTemplate('ext_' . $ext, true);
923 // Write this in debug.log as well
924 logDebugMessage(__FUNCTION__, __LINE__, $message);
927 // Task not created so it's a brand-new extension which we need to register and create a task for!
928 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
932 // Creates a task for automatically deactivated (deprecated) extension
933 function createExtensionDeactivationTask ($ext) {
934 // Create subject line
935 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
937 // Not installed and do we have created a task for the admin?
938 if ((determineTaskIdBySubject($subject) == 0) && (getExtensionVersion($ext) != '')) {
939 // Task not created so add it
940 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
944 // Checks if the module has a menu
945 function ifModuleHasMenu ($mod, $forceDb = false) {
946 // All is false by default
949 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "mod={$mod},cache=".getExtensionVersion('cache'));
950 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
951 // Cache version is okay, so let's check the cache!
952 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
953 // Check module cache and count hit
954 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
955 incrementStatsEntry('cache_hits');
956 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
957 // Check cache and count hit
958 $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
959 incrementStatsEntry('cache_hits');
960 } elseif ($mod == 'admin') {
961 // Admin module has always a menu!
964 } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
965 // Check database for entry
966 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
967 array($mod), __FUNCTION__, __LINE__);
970 if (SQL_NUMROWS($result) == 1) {
971 // Load "has_menu" column
972 list($has_menu) = SQL_FETCHROW($result);
975 $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $has_menu;
977 // Does it have a menu?
978 $ret = ($has_menu == 'Y');
982 SQL_FREERESULT($result);
983 } elseif (!isExtensionInstalled('sql_patches')) {
984 // No sql_patches installed, so maybe in admin area or no admin registered?
985 $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu!
989 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().intval($ret));
993 // Determines the task id for given extension
994 function determineExtensionTaskId ($ext_name) {
995 // Default is not found
998 // Search for extension task's id
999 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1000 array($ext_name), __FUNCTION__, __LINE__);
1003 if (SQL_NUMROWS($result) == 1) {
1004 // Task found so load task's id and register extension...
1005 list($task_id) = SQL_FETCHROW($result);
1009 SQL_FREERESULT($result);
1015 // Determines the task id for given subject
1016 function determineTaskIdBySubject ($subject) {
1017 // Default is not found
1020 // Search for task id
1021 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1022 array($subject), __FUNCTION__, __LINE__);
1025 if (SQL_NUMROWS($result) == 1) {
1026 // Task found so load task's id and register extension...
1027 list($task_id) = SQL_FETCHROW($result);
1031 SQL_FREERESULT($result);
1037 // Add updates notes for given version
1038 function addExtensionNotes ($ver) {
1039 // Init notes/content
1040 $out = ''; $content = array();
1042 // Is do we have verbose output enabled?
1043 if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
1044 // Update notes found?
1045 if (getExtensionUpdateNotes($ver) != '') {
1046 // Update notes found
1049 'notes' => getExtensionUpdateNotes($ver)
1053 setExtensionUpdateNotes('', $ver);
1054 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1058 'notes' => getMessage('INITIAL_RELEASE')
1061 // No update notes found!
1064 'notes' => getMessage('NO_UPDATE_NOTES')
1069 $out = loadTemplate('admin_ext_notes', true, $content);
1073 appendExtensionNotes($out);
1076 // Getter for CSS files array
1077 function getExtensionCssFiles () {
1078 // By default no additional CSS files are found
1079 $cssFiles = array();
1081 // Is the array there?
1082 if (isset($GLOBALS['css_files'])) {
1084 $cssFiles = $GLOBALS['css_files'];
1091 // Init CSS files array
1092 function initExtensionCssFiles () {
1094 $GLOBALS['css_files'] = array();
1098 function addExtensionCssFile ($file) {
1099 // Is the array there?
1100 if (!isset($GLOBALS['css_files'])) {
1101 // Then auto-init them
1102 initExtensionCssFiles();
1106 $GLOBALS['css_files'][] = $file;
1109 // Setter for EXT_ALWAYS_ACTIVE flag
1110 function setExtensionAlwaysActive ($active) {
1111 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1114 // Getter for EXT_ALWAYS_ACTIVE flag
1115 function getExtensionAlwaysActive () {
1116 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1119 // Setter for EXT_VERSION flag
1120 function setThisExtensionVersion ($version) {
1121 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1124 // Getter for EXT_VERSION flag
1125 function getThisExtensionVersion () {
1126 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1129 // Setter for EXT_DEPRECATED flag
1130 function setExtensionDeprecated ($deprecated) {
1131 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1134 // Getter for EXT_DEPRECATED flag
1135 function isExtensionDeprecated () {
1136 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1139 // Setter for EXT_UPDATE_DEPENDS flag
1140 function addExtensionUpdateDependency ($updateDepends) {
1141 // Is the update depency empty? (NEED TO BE FIXED!)
1142 if (empty($updateDepends)) {
1143 // Please report this bug!
1144 debug_report_bug("updateDepends is left empty!");
1147 // Is it not yet added?
1148 if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1149 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1150 // Add it to the list of extension update depencies map
1151 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1153 // Remember it in the list of running updates
1154 $GLOBALS['ext_running_updates'][] = $updateDepends;
1158 // Checks wether the given extension registration is in progress
1159 function isExtensionRegisterRunning ($ext_name) {
1160 return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1163 // Init EXT_UPDATE_DEPENDS flag
1164 function initExtensionUpdateDependencies () {
1165 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1167 // Init update depency map automatically if not found
1168 if (!isExtensionUpdateDependenciesInitialized()) {
1169 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1170 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1173 // Init running updates array
1174 initExtensionRuningUpdates();
1177 // Adds an extension as "registration in progress"
1178 function addExtensionRunningRegistration ($ext_name) {
1180 if (!isExtensionRegisterRunning($ext_name)) {
1182 $GLOBALS['ext_register_running'][] = $ext_name;
1186 // Checks wether EXT_UPDATE_DEPENDS is initialized
1187 function isExtensionUpdateDependenciesInitialized () {
1188 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1189 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1192 // Initializes the list of running updates
1193 function initExtensionRuningUpdates () {
1194 // Auto-init ext_running_updates
1195 if (!isset($GLOBALS['ext_running_updates'])) {
1196 $GLOBALS['ext_running_updates'] = array();
1197 $GLOBALS['ext_register_running'] = array();
1201 // Getter for EXT_UPDATE_DEPENDS flag
1202 function getExtensionUpdateDependencies () {
1203 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1204 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1207 // Getter for next iterator depency
1208 function getExtensionUpdateDependenciesIterator () {
1209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1210 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1213 // Counter for extension update depencies
1214 function countExtensionUpdateDependencies () {
1215 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1216 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1219 // Removes given extension from update denpency list
1220 function removeExtensionUpdateDependency ($ext_name) {
1222 $key = array_search($ext_name, getExtensionUpdateDependencies());
1225 if ($key !== false) {
1227 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1229 // And sort the array
1230 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1234 // Init iterator for update depencies
1235 function initExtensionUpdateIterator () {
1236 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1237 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = 0;
1240 // Getter for depency iterator
1241 function getExtensionUpdateIterator () {
1242 // Auto-init iterator
1243 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1246 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1247 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1250 // Increments the update iterator
1251 function incrementExtensionUpdateIterator () {
1252 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1253 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1256 // Setter for EXT_REPORTS_FAILURE flag
1257 function setExtensionReportsFailure ($reportsFailure) {
1258 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1261 // Getter for EXT_REPORTS_FAILURE flag
1262 function getExtensionReportsFailure () {
1263 return $GLOBALS['ext_reports_failure'];
1266 // Setter for EXT_VER_HISTORY flag
1267 function setExtensionVersionHistory ($verHistory) {
1268 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1271 // Getter for EXT_VER_HISTORY array
1272 function getExtensionVersionHistory () {
1273 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1276 // Setter for EXT_UPDATE_NOTES
1277 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1278 //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1280 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1282 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1286 // Getter for EXT_UPDATE_NOTES
1287 function getExtensionUpdateNotes ($ver) {
1288 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1291 // Init extension notice
1292 function initExtensionNotes () {
1293 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1296 // Append extension notice
1297 function appendExtensionNotes ($notes) {
1298 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1301 // Getter for extension notes
1302 function getExtensionNotes () {
1303 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1306 // Setter for current extension name
1307 function setCurrentExtensionName ($ext_name) {
1308 $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1311 // Getter for current extension name
1312 function getCurrentExtensionName () {
1313 if (isset($GLOBALS['curr_ext_name'])) {
1314 return $GLOBALS['curr_ext_name'];
1318 debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1321 // Init SQLs array for current extension
1322 function initExtensionSqls () {
1323 // Auto-init the array now...
1324 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1325 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1329 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1330 function addExtensionSql ($sql) {
1332 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1335 // Getter for SQLs array for current extension
1336 function getExtensionSqls () {
1337 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1338 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1339 // Not found, should not happen
1340 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1341 getCurrentExtensionName()
1346 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1349 // Removes SQLs for current extension
1350 function unsetExtensionSqls () {
1351 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1354 // Auto-initializes the removal list
1355 function initExtensionRemovalList () {
1356 // Is the remove list there?
1357 if (!isset($GLOBALS['ext_update_remove'])) {
1359 $GLOBALS['ext_update_remove'] = array();
1363 // Checks wether the current extension is on the removal list
1364 function isExtensionOnRemovalList () {
1365 // Init removal list
1366 initExtensionRemovalList();
1369 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1372 // Adds the current extension to the removal list
1373 function addCurrentExtensionToRemovalList () {
1375 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1378 // Getter for removal list
1379 function getExtensionRemovalList () {
1380 // Return the removal list
1381 return $GLOBALS['ext_update_remove'];
1384 // Redirects if the provided extension is not installed
1385 function redirectOnUninstalledExtension ($ext_name) {
1386 // So is the extension there?
1387 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1388 // Redirect to index
1389 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1393 // Filter for initialization of all extensions by loading them in 'init' mode
1394 function FILTER_INIT_EXTENSIONS () {
1395 // Do we have some entries?
1396 //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1397 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1398 // Load all found extensions if found
1399 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1400 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1402 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1403 loadExtension($ext_name, 'init');
1404 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1406 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1408 //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1411 // Setter for extension mode
1412 function setExtensionMode ($ext_mode) {
1413 $GLOBALS['ext_mode'] = (string) $ext_mode;
1416 // Getter for extension mode
1417 function getExtensionMode () {
1418 return $GLOBALS['ext_mode'];
1421 // Setter for dry-run
1422 function enableExtensionDryRun ($dry_run = true) {
1423 //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1424 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1427 // Getter for dry-run
1428 function getExtensionDryRun () {
1429 return $GLOBALS['ext_dry_run'];
1432 // Setter for current extension version
1433 function setCurrentExtensionVersion ($ext_ver) {
1434 if (empty($ext_ver)) {
1436 $GLOBALS['ext_current_version'] = '0.0';
1439 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1443 // Getter for current extension version
1444 function getCurrentExtensionVersion () {
1445 return $GLOBALS['ext_current_version'];
1448 // Remove the extension from global cache array
1449 function removeExtensionFromArray () {
1450 // "Cache" this name
1451 $ext_name = getCurrentExtensionName();
1453 // Now loop through the whole cache
1454 foreach ($GLOBALS['cache_array']['extension'] as $cacheName=>$cacheArray) {
1455 // Is it an element?
1456 if (isset($cacheArray[$ext_name])) {
1458 unset($cacheArray[$ext_name]);
1459 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1462 $key = array_search($ext_name, $cacheArray);
1465 if ($key !== false) {
1466 // Found, so remove it
1467 unset($cacheArray[$key]);
1468 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1474 // "Getter" for 'extension has a CSS file' (with same name, of course)
1475 function getExtensionHasCss () {
1476 // Default is no CSS
1479 // Construct FQFN for check
1480 $FQFN = sprintf("%stheme/%s/css/%s.css",
1483 getCurrentExtensionName()
1487 if (isFileReadable($FQFN)) {
1488 // Readable, so it is there...
1496 // Checks wether the given extension has a language file
1497 function ifExtensionHasLanguageFile ($ext_name) {
1498 // Default is no language file
1499 $hasLanguage = false;
1501 // Do we have cache?
1502 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1504 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1507 incrementStatsEntry('cache_hits');
1509 // Not readable is default
1512 // Is the language file readable for this extension?
1513 if (isLanguageIncludeReadable($ext_name)) {
1519 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1523 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1526 // Load an extension's include file
1527 function loadExtensionInclude () {
1529 if (!isExtensionIncludeReadable()) {
1531 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1534 // Generate INC name
1535 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1541 // Checks wether an extension is readable
1542 function isExtensionIncludeReadable ($ext_name = '') {
1543 // If empty, use current
1544 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1547 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1548 // Generate INC name
1549 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1552 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1556 //* DEBUG: */ print __FUNCTION__.': '.$ext_name.'='.intval($GLOBALS['ext_inc_readable'][$ext_name]).'<br />';
1557 return $GLOBALS['ext_inc_readable'][$ext_name];
1560 // Checks if an extension's function file is readable
1561 function isExtensionFunctionFileReadable ($ext_name) {
1562 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1563 // Just count cache hits
1564 incrementStatsEntry('cache_hits');
1566 // Construct FQFN for functions file
1567 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1569 // Is this include there?
1570 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1572 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1575 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1580 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1583 // Adds an admin menu to the SQL queue of the menu entry is not found
1584 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1585 // Now check if this menu is there
1586 if (!isMenuActionValid('admin', $action, $what)) {
1588 if (is_null($what)) {
1590 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1598 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1607 // Add it to the queue
1608 addExtensionSql($sql);
1609 } elseif (isDebugModeEnabled()) {
1610 // Double menus should be located and fixed!
1611 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what));
1615 // Adds a guest menu to the SQL queue if the menu entry is not found
1616 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1617 // Now check if this menu is there
1618 if (!isMenuActionValid('guest', $action, $what)) {
1620 if (is_null($what)) {
1622 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1631 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1641 // Add it to the queue
1642 addExtensionSql($sql);
1643 } elseif (isDebugModeEnabled()) {
1644 // Double menus should be located and fixed!
1645 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what));
1649 // Adds a member menu to the SQL queue if the menu entry is not found
1650 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1651 // Now check if this menu is there
1652 if (!isMenuActionValid('member', $action, $what)) {
1654 if (is_null($what)) {
1656 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1665 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1675 // Add it to the queue
1676 addExtensionSql($sql);
1677 } elseif (isDebugModeEnabled()) {
1678 // Double menus should be located and fixed!
1679 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what));
1683 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1684 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1685 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1686 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1688 if (is_null($what)) {
1690 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1698 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1707 // Add it to the queue
1708 addExtensionSql($sql);
1709 } elseif (isDebugModeEnabled()) {
1710 // Double menus should be located and fixed!
1711 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what));
1715 // Enables/disables productive mode for current extension (used only while
1717 function enableExtensionProductive ($isProductive = true) {
1718 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1721 // Checks wether the extension is in productive phase. If not set, development
1722 // phase (=false) is assumed.
1723 function isExtensionProductive () {
1724 return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));