2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Load the extension and maybe found language and function files.
44 function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0', $dry_run = false) {
45 // Loading an extension in same mode, but not test/update, twice is not
46 // good, so is the extension $ext_name already loaded in mode $ext_mode?
47 if ((isset($GLOBALS['loaded_extension'][$ext_name][$ext_mode])) && (!in_array($ext_mode, array('update', 'test')))) {
48 // If this happens twice, we need the bug report from you, except for updates/tests
49 debug_report_bug(__FUNCTION__, __LINE__, '() is called twice: ext_name=' . $ext_name . ', ext_mode='. $ext_mode . ',ext_sqls=' . print_r(getExtensionSqls(), true) . ', ext_register_running=' . print_r($GLOBALS['ext_register_running'], true) . ', ext_running_updates=' . print_r($GLOBALS['ext_running_updates'], true));
52 // Make sure this situation can only happen once
53 $GLOBALS['loaded_extension'][$ext_name][$ext_mode] = true;
56 setExtensionMode($ext_mode);
58 // Set current extension name
59 setCurrentExtensionName($ext_name);
61 // By default all extensions are in productive phase
62 enableExtensionProductive();
64 if (!empty($ext_ver)) {
65 // Set current extension version
66 setCurrentExtensionVersion($ext_ver);
68 // Set it to 0.0 by default
69 setCurrentExtensionVersion('0.0');
71 // Is the extension installed?
72 if ((isExtensionInstalled($ext_name)) && ($ext_mode != 'register')) {
73 // Get extension's version
74 setCurrentExtensionVersion(getExtensionVersion($ext_name));
77 // In all but test-mode we need these messages to debug! Please report all (together, e.g.)
78 if (($ext_mode != 'test') && (getCurrentExtensionVersion() == '0.0')) {
79 // Abort here, this must now always be set!
80 debug_report_bug(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0. ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', dry_run=' . intval($dry_run));
85 enableExtensionDryRun($dry_run);
88 initIncludePool('extension');
90 // Init EXT_UPDATE_DEPENDS if not yet done
91 if (!isExtensionUpdateDependenciesInitialized()) {
93 initExtensionUpdateDependencies();
96 // Init current extension name list
99 // Is the extension already loaded?
100 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Loading extension ' . $ext_name . ', mode=' . getExtensionMode() . ', ver=' . getCurrentExtensionVersion());
101 if ((isExtensionLoaded($ext_name)) && (getExtensionMode() == 'init')) {
103 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
109 // Is the extension file NOT there?
110 if (!isExtensionNameValid($ext_name)) {
112 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable.", $ext_name));
118 // Load extension's own language file if not in test mode
119 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
121 loadLanguageFile($ext_name);
125 if (isExtensionFunctionFileReadable($ext_name)) {
127 if ((($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') || (!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name]))) && (!isExtensionLibraryLoaded($ext_name))) {
128 // Construct IFN for functions file
129 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
132 markExtensionLibraryAsLoaded($ext_name);
134 // Download functions file
135 loadIncludeOnce($funcsInclude);
137 } elseif ((!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) && (isDebugModeEnabled()) && (isHtmlOutputMode()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme') && (getExtensionMode() == 'test')) {
138 // No functions file is not so good...
139 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
145 // Load extension's filter library if present
146 loadExtensionFilters($ext_name);
148 // Extensions are not deprecated by default
149 setExtensionDeprecated('N');
151 // Extensions are not always active by default
152 setExtensionAlwaysActive('N');
154 // Extension update notes
155 // @TODO Do we still need this? setExtensionUpdateNotes('');
157 // Include the extension file
158 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension loaded.');
159 loadExtensionInclude();
161 // Is this extension deprecated?
162 if (isExtensionDeprecated()) {
163 // Deactivate the extension
164 doDeactivateExtension($ext_name);
170 // Mark it as loaded in normal mode
171 if (getExtensionMode() == '') {
173 markExtensionAsLoaded($ext_name);
180 // Registeres an extension and possible update depencies
181 function registerExtension ($ext_name, $taskId, $dry_run = false, $logout = true) {
182 // Set current extension name
183 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ',logout=' . intval($logout) . ' - ENTERED!');
184 setCurrentExtensionName($ext_name);
187 enableExtensionDryRun($dry_run);
189 // By default all extensions are in productive phase
190 enableExtensionProductive();
192 // This shall never do a non-admin user or if the extension is active (already installed)
193 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
194 // Abort here with 'false'
198 // When this extension is already in registration/update phase, all is fine
199 if ((isExtensionRegistrationRunning($ext_name)) || (isExtensionUpdateRunning($ext_name))) {
200 // Then abort here with 'true' becaus it is fine
201 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ALREADY!');
205 // This registration is running
206 addExtensionRunningRegistration($ext_name);
208 // Init EXT_UPDATE_DEPENDS if not yet done
209 if (!isExtensionUpdateDependenciesInitialized()) {
211 initExtensionUpdateDependencies();
214 // Is the task id zero? Then we need to auto-fix it here
215 if ($taskId == '0') {
216 // Try to find the task
217 $taskId = determineExtensionTaskId(getCurrentExtensionName());
219 // Still zero and not in dry-run?
220 if (($taskId == '0') && (!isExtensionDryRun())) {
221 // Now try to create a new task
222 $taskId = createNewExtensionTask(getCurrentExtensionName());
225 if ($taskId == '0') {
226 // Then request a bug report
227 debug_report_bug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
229 getCurrentExtensionName()
235 // Init queries and notes
237 initExtensionNotes();
242 initIncludePool('extension');
244 // By default we have no failures
245 setExtensionReportsFailure(false);
247 // Does this extension exists?
248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
249 if (loadExtension(getCurrentExtensionName(), 'register', '0.0', isExtensionDryRun())) {
250 // Set current extension name again
251 setCurrentExtensionName($ext_name);
253 // And run possible updates
254 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
255 $history = getExtensionVersionHistory();
256 foreach ($history as $ext_ver) {
257 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ext_ver);
258 // Load extension in update mode
259 loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun());
261 // Add update notes to our output
262 addExtensionNotes($ext_ver);
265 // Does this extension depends on an outstanding update of another update?
266 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
268 $ext_update = getExtensionUpdateDependenciesIterator();
270 // Increment here to avoid endless loop
271 incrementExtensionUpdateIterator();
273 // Check if extension is not installed and not already in registration procedure and if loading it wents finally fine...
274 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isExtensionRegistrationRunning(' . $ext_update . ')=' . intval(isExtensionRegistrationRunning($ext_update)));
275 if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
276 // Set current extension name again
277 setCurrentExtensionName($ext_name);
279 // If versions mismatch update extension first
281 if (isExtensionInstalled($ext_update)) {
282 // Get version only if installed
283 $ext_ver = getExtensionVersion($ext_update);
286 // Extension version set? If empty the extension is not registered
287 if (empty($ext_ver)) {
288 // Extension not registered so far so first load task's id...
289 $task = determineExtensionTaskId($ext_update);
293 // Try to register the extension
294 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ':ext_update=' . $ext_update . ',taskId=' . $task);
295 $test = registerExtension($ext_update, $task, isExtensionDryRun(), false);
297 // Reset extension name
298 setCurrentExtensionName($ext_name);
299 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',test=' . intval($test));
301 } elseif ($ext_ver != getCurrentExtensionVersion()) {
302 // Ok, update this extension now
303 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
304 $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
305 $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
306 updateExtension($ext_update, $ext_ver, isExtensionDryRun());
307 setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
308 setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
309 unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
310 unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
311 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
316 // Nothing to register / update before...
320 // Required file for update does not exists!
322 // But this is fine for the first time...
325 // Restore the current extension name
326 setCurrentExtensionName($ext_name);
329 // Is there no update?
330 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
331 // Then test is passed!
335 // Switch back to register mode
336 setExtensionMode('register');
338 // Remains true if extension registration reports no failures
339 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',test=' . intval($test));
340 $test = (($test === true) && (getExtensionReportsFailure() === false));
341 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',test=' . intval($test));
343 // Does everthing before wents ok?
344 if ($test === true) {
345 // "Dry-run-mode" activated?
346 if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
347 // Init SQLs and transfer ext->generic
348 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
350 setSqlsArray(getExtensionSqls());
352 // Run installation pre-installation filters
353 runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
355 // Register extension
356 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
357 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
359 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
360 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
362 getCurrentExtensionName(),
363 getThisExtensionAlwaysActive(),
364 getCurrentExtensionVersion(),
366 ), __FUNCTION__, __LINE__);
369 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
370 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
372 getCurrentExtensionName(),
373 getThisExtensionAlwaysActive(),
374 getCurrentExtensionVersion()
375 ), __FUNCTION__, __LINE__);
378 // Use the insert id as extension id and cache it for early usage
379 $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
380 $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
382 // Mark it as installed
383 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
385 // Remove cache file(s) if extension is active
386 runFilterChain('post_extension_installed', array(
387 'pool' => 'extension',
388 'ext_name' => getCurrentExtensionName(),
392 // Re-init queries and notes
393 initExtensionSqls(true);
394 initExtensionNotes(true);
396 // In normal mode return a true on success
398 } elseif (isExtensionDryRun() === true) {
399 // In "dry-run" mode do always return a true
402 // Extension has been removed for updates, so all is fine!
406 // No, an error occurs while registering extension :-(
407 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
410 } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
411 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
412 // Remove task from system when id and extension's name is valid
413 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
414 array(bigintval($taskId)), __FUNCTION__, __LINE__);
417 // Is this the sql_patches?
418 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . '/' . getExtensionMode());
419 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!isExtensionDryRun()) && ($test)) {
420 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ': LOAD!');
421 if ($logout === true) {
422 // Then redirect to logout
423 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
425 // Add temporary filter
426 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
427 $GLOBALS['ext_load_mode'] = getExtensionMode();
431 // Return status code
432 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',test=' . intval($test) . ' - EXIT!');
436 // Run SQL queries for given extension id
437 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
438 function doExtensionSqls ($ext_id, $load_mode) {
439 // This shall never do a non-admin user!
440 if (!isAdmin()) return false;
442 // Get extension's name
443 $ext_name = getExtensionName($ext_id);
445 // Set current SQL name
446 setCurrentExtensionName($ext_name);
448 // Init EXT_UPDATE_DEPENDS
449 if (!isExtensionUpdateDependenciesInitialized()) {
451 initExtensionUpdateDependencies();
455 initExtensionSqls(true);
457 // By default no SQL has been executed
460 // Load extension in detected mode
461 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name[' . $ext_id . ']=' . getCurrentExtensionName() . ',load_mode=' . $load_mode);
462 loadExtension(getCurrentExtensionName(), $load_mode, '0.0', false);
466 setSqlsArray(getExtensionSqls());
469 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls());
471 // Do we have entries?
473 // Run SQL commands...
474 runFilterChain('run_sqls');
477 // Run any filters depending on the action here
478 runFilterChain('extension_' . $load_mode);
480 // Remove cache file(s) if extension is active
481 if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED())) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
483 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
486 // Is this the sql_patches?
487 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $ext_id . ',currName=' . getCurrentExtensionName() . ',loadMode=' . $load_mode);
488 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
489 // Then redirect to logout
490 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': LOAD!');
491 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
495 // Check wether the given extension is installed
496 function isExtensionInstalled ($ext_name) {
497 // We don't like empty extension names here
498 if (empty($ext_name)) {
499 // Please fix them all
500 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty.');
503 // By default non is installed
504 $isInstalled = false;
506 // Check if there is a cache entry
507 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
508 // Use cache built from below queries
509 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
510 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
515 incrementStatsEntry('cache_hits');
516 } elseif ((isInstallationPhase())) {
517 // Extensions are all inactive/not installed during installation
520 $ext_id = getExtensionId($ext_name);
523 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' has ext_id=' . $ext_id);
525 // Do we have a record?
526 $isInstalled = ($ext_id > 0);
528 // Is it installed, then cache the entry
529 if ($isInstalled === true) {
530 // Dummy call (get is okay here)
531 getExtensionId($ext_name, true);
534 // Remember the status
535 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
542 // Check if given extension is active
543 function isExtensionActive ($ext_name) {
544 if (isInstallationPhase()) {
545 // Extensions are all inactive during installation
547 } elseif (empty($ext_name)) {
548 // Empty extension names must befixed
549 debug_report_bug(__FUNCTION__, __LINE__, 'Empty extension name provided.');
550 } elseif (!isExtensionInstalled($ext_name)) {
551 // Not installed extensions are always inactive
555 // Not active is the default
556 $data['ext_active'] = 'N';
559 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
561 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE! ext_name=' . $ext_name);
562 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
565 incrementStatsEntry('cache_hits');
566 } elseif (isExtensionLoaded($ext_name)) {
567 // @TODO Extension is loaded, what next?
568 debug_report_bug(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
569 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
570 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DB! ext_name=' . $ext_name);
571 // Load from database
572 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
573 array($ext_name), __FUNCTION__, __LINE__);
576 if (SQL_NUMROWS($result) == 1) {
578 $data = SQL_FETCHARRAY($result);
582 SQL_FREERESULT($result);
585 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . '[DB]: ' . $data['ext_active']);
586 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
588 // Extension not active!
589 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': Not active!');
590 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
594 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',active=' . $data['ext_active']);
596 // Is this extension activated? (For admins we always have active extensions...)
597 return ($data['ext_active'] == 'Y');
600 // Get version from extensions
601 function getExtensionVersion ($ext_name, $force = false) {
602 // By default no extension is found
603 $data['ext_version'] = 'false';
605 // Empty extension name should be fixed!
606 if (empty($ext_name)) {
607 // Please report this bug!
608 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty which is not allowed here.');
611 // Extensions are all inactive during installation
612 if (isInstallationPhase()) return '';
613 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
615 // Is the cache written?
616 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
617 // Load data from cache
618 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': CACHE!');
619 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
622 incrementStatsEntry('cache_hits');
623 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (!isHtmlOutputMode())) {
624 // Load from database
625 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
626 array($ext_name), __FUNCTION__, __LINE__);
627 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': DB - '.SQL_NUMROWS($result).'');
629 // Is the extension there?
630 if (SQL_NUMROWS($result) == 1) {
632 $data = SQL_FETCHARRAY($result);
633 } elseif (isDebugModeEnabled()) {
634 // Not found, please report all
635 debug_report_bug(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
639 SQL_FREERESULT($result);
642 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
645 // Extension version should not be invalid
646 if (($data['ext_version'] == 'false') && ($force === false)) {
647 // Please report this trouble
648 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> has empty version!", $ext_name));
652 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_version=' . $data['ext_version']);
653 return $data['ext_version'];
656 // Updates a given extension with current extension version to latest version
657 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
658 // Only admins are allowed to update extensions
659 if ((!isAdmin()) || (empty($ext_name))) {
663 // Set current SQL name
664 setCurrentExtensionName($ext_name);
668 initExtensionNotes();
669 initIncludePool('extension');
671 // Load extension in test mode
672 loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
674 // Save version history
675 $history = getExtensionVersionHistory();
677 // Remove old SQLs array to prevent possible bugs
680 // Check if version is updated
681 //* DEBUG: */ debugOutput(getCurrentExtensionName() . '/' . $ext_name . ':' . getThisExtensionVersion() . '/' . $ext_ver . '/' . intval(is_array($history)));
682 if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
683 // Search for starting point
684 $start = array_search($ext_ver, $history);
686 // And load SQL queries in order of version history
687 for ($idx = ($start + 1); $idx < count($history); $idx++) {
688 // Set extension version
689 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
692 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
695 $depencies = getExtensionUpdateDependencies();
698 if (count($depencies) > 0) {
699 // Apply all extension depencies
700 foreach ($depencies as $ext_depend) {
701 // Did we already update/register this?
702 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
704 setCurrentExtensionName($ext_depend);
706 // Mark it as already updated before we update it
707 $GLOBALS['ext_updated'][$ext_depend] = true;
709 // Is the extension there?
710 if (isExtensionInstalled($ext_depend)) {
711 // Update another extension first!
712 $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun());
714 // Register new extension
715 $test = registerExtension($ext_depend, 0, isExtensionDryRun(), false);
720 // Set extension version here
721 setCurrentExtensionVersion($ext_ver);
724 setCurrentExtensionName($ext_name);
728 addExtensionNotes($history[$idx]);
731 // In real-mode execute any existing includes
732 if (isExtensionDryRun() === false) {
733 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
734 runFilterChain('load_includes', 'extension');
735 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
736 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
741 setSqlsArray(getExtensionSqls());
744 runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
746 if (isExtensionDryRun() === false) {
747 // Run filters on success extension update
748 runFilterChain('extension_update', getCurrentExtensionName());
753 // Output verbose SQL table for extension
754 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
757 // Then fix it to default
758 $title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}';
764 // Do we have queries?
765 if (isVerboseSqlEnabled()) {
766 // Do we have entries?
767 if (countExtensionSqls() > 0) {
771 foreach (getExtensionSqls() as $sqls) {
772 // New array format is recursive
773 foreach ($sqls as $sql) {
777 // Output command if set
779 // Prepare output for template
782 'sql' => str_replace('{', '{', str_replace('}', '}', encodeEntities($sql)))
786 $OUT .= loadTemplate('admin_extension_sql_row', true, $content);
794 // Prepare content for template
802 // Load main template
803 $OUT = loadTemplate('admin_extension_sql_table', true, $content);
805 // No addional SQL commands to run
806 $OUT = displayMessage('{--ADMIN_NO_ADDITIONAL_SQLS--}', true);
814 // Get extension name from id
815 function getExtensionName ($ext_id) {
816 // Init extension name
817 $data['ext_name'] = '';
820 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
822 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
825 incrementStatsEntry('cache_hits');
826 } elseif (!isExtensionActive('cache')) {
827 // Load from database
828 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
829 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
831 // Is the entry there?
832 if (SQL_NUMROWS($result) == 1) {
833 // Get the extension's name from database
834 $data = SQL_FETCHARRAY($result);
838 SQL_FREERESULT($result);
841 // Did we find some extension?
842 if (empty($data['ext_name'])) {
843 // We should fix these all!
844 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty. ext_id=' . $ext_id);
847 // Return the extension name
848 return $data['ext_name'];
851 // Get extension id from name
852 function getExtensionId ($ext_name) {
854 $data['ext_id'] = '0';
857 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
859 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
862 incrementStatsEntry('cache_hits');
864 // Load from database
865 $result = SQL_QUERY_ESC("SELECT `id` AS ext_id FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
866 array($ext_name), __FUNCTION__, __LINE__);
868 // Is the entry there?
869 if (SQL_NUMROWS($result) == 1) {
870 // Get the extension's id from database
871 $data = SQL_FETCHARRAY($result);
875 SQL_FREERESULT($result);
878 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
882 return $data['ext_id'];
885 // Determines wether the given extension name is valid
886 function isExtensionNameValid ($ext_name) {
888 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
889 // Generate include file name
890 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
892 // Is there a file in inc/extensions/ ?
893 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
897 return $GLOBALS['ext_name_valid'][$ext_name];
900 // Determines wether the given extension id is valid
901 function isExtensionIdValid ($ext_id) {
902 // Default is nothing valid
905 // Check in cache then in database
906 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
911 incrementStatsEntry('cache_hits');
914 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
921 // Activate given extension
922 function doActivateExtension ($ext_name) {
923 // Is the extension installed?
924 if (!isExtensionInstalled($ext_name)) {
925 // Non-installed extensions cannot be activated
926 debug_report_bug(__FUNCTION__, __LINE__, 'Tried to activate non-installed extension ' . $ext_name);
929 // Activate the extension
930 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
931 array($ext_name), __FUNCTION__, __LINE__);
933 // Then run all queries
934 doExtensionSqls(getExtensionId($ext_name), 'activate');
937 // Deactivate given extension
938 function doDeactivateExtension ($ext_name) {
939 // Is the extension installed?
940 if (!isExtensionInstalled($ext_name)) {
941 // Non-installed extensions cannot be activated
942 debug_report_bug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name);
945 // Activate the extension
946 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
947 array($ext_name), __FUNCTION__, __LINE__);
949 // Then run all queries
950 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
952 // Create new task (we ignore the task id here)
953 createExtensionDeactivationTask($ext_name);
956 sendAdminNotification(
957 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
958 'admin_extension_deactivated',
959 array('ext_name' => $ext_name)
963 // Checks wether the extension is older than given
964 function isExtensionOlder ($ext_name, $ext_ver) {
965 // Get current extension version
966 $currVersion = getExtensionVersion($ext_name);
968 // Remove all dots from both versions
969 $currVersion = str_replace('.', '', $currVersion);
970 $ext_ver = str_replace('.', '', $ext_ver);
972 // Now compare both and return the result
973 return ($currVersion < $ext_ver);
976 // Creates a new task for updated extension
977 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
978 // Create subject line
979 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
982 $taskId = determineTaskIdBySubject($subject);
984 // Is the extension there?
985 if (isExtensionInstalled($ext_name)) {
986 // Check if task is not there
987 if ($taskId == '0') {
988 // Create extension update-task
989 $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
992 // Extension not there! :-(
993 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1000 // Creates a new task for newly installed extension
1001 function createNewExtensionTask ($ext_name) {
1002 // Generate subject line
1003 $subject = sprintf("[%s:]", $ext_name);
1006 $taskId = determineTaskIdBySubject($subject);
1008 // Not installed and do we have created a task for the admin?
1009 if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1010 // Set default message if ext-foo is missing
1011 $message = getMaskedMessage('ADMIN_EXTENSION_TEXT_FILE_MISSING', $ext_name);
1014 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1020 // Load text for task if found
1021 if (isFileReadable($FQFN)) {
1022 // Load extension's description template (but do not compile the code)
1023 $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1025 // Write this in debug.log as well
1026 logDebugMessage(__FUNCTION__, __LINE__, $message);
1029 // Task not created so it's a brand-new extension which we need to register and create a task for!
1030 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1037 // Creates a task for automatically deactivated (deprecated) extension
1038 function createExtensionDeactivationTask ($ext_name) {
1039 // Create subject line
1040 $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1043 $taskId = determineTaskIdBySubject($subject);
1045 // Not installed and do we have created a task for the admin?
1046 if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1047 // Task not created so add it
1048 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1055 // Determines the task id for given extension
1056 function determineExtensionTaskId ($ext_name) {
1057 // Default is not found
1058 $data['task_id'] = '0';
1060 // Search for extension task's id
1061 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1062 array($ext_name), __FUNCTION__, __LINE__);
1065 if (SQL_NUMROWS($result) == 1) {
1066 // Task found so load task's id and register extension...
1067 $data = SQL_FETCHARRAY($result);
1071 SQL_FREERESULT($result);
1074 return $data['task_id'];
1077 // Determines the task id for given subject
1078 function determineTaskIdBySubject ($subject) {
1079 // Default is not found
1080 $data['task_id'] = '0';
1082 // Search for task id
1083 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1084 array($subject), __FUNCTION__, __LINE__);
1087 if (SQL_NUMROWS($result) == 1) {
1088 // Task found so load task's id and register extension...
1089 $data = SQL_FETCHARRAY($result);
1093 SQL_FREERESULT($result);
1096 return $data['task_id'];
1099 // Add updates notes for given version
1100 function addExtensionNotes ($ext_ver) {
1101 // Init notes/content
1105 // Is do we have verbose output enabled?
1106 if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1107 // Update notes found?
1108 if (isExtensionUpdateNoteSet($ext_ver)) {
1109 // Update notes found
1112 'notes' => getExtensionUpdateNotes($ext_ver)
1116 setExtensionUpdateNotes('', $ext_ver);
1117 } elseif (in_array($ext_ver, array('0.0', '0.0.0'))) {
1121 'notes' => '{--INITIAL_RELEASE--}'
1124 // No update notes found
1127 'notes' => '{--NO_UPDATE_NOTES--}'
1132 $out = loadTemplate('admin_extension_notes', true, $content);
1136 appendExtensionNotes($out);
1139 // Getter for CSS files array
1140 function getExtensionCssFiles () {
1141 // By default no additional CSS files are found
1142 $cssFiles = array();
1144 // Is the array there?
1145 if (isset($GLOBALS['css_files'])) {
1147 $cssFiles = $GLOBALS['css_files'];
1154 // Init CSS files array
1155 function initExtensionCssFiles () {
1157 $GLOBALS['css_files'] = array();
1161 function addExtensionCssFile ($file) {
1162 // Is the array there?
1163 if (!isset($GLOBALS['css_files'])) {
1164 // Then auto-init them
1165 initExtensionCssFiles();
1169 $GLOBALS['css_files'][] = $file;
1172 // Setter for EXT_ALWAYS_ACTIVE flag
1173 function setExtensionAlwaysActive ($active) {
1174 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1177 // Getter for EXT_ALWAYS_ACTIVE flag
1178 function getThisExtensionAlwaysActive () {
1179 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1182 // Checks wether the current extension is always active
1183 function isThisExtensionAlwaysActive () {
1184 return (getThisExtensionAlwaysActive() == 'Y');
1187 // Setter for EXT_VERSION flag
1188 function setThisExtensionVersion ($ext_version) {
1189 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1192 // Getter for EXT_VERSION flag
1193 function getThisExtensionVersion () {
1194 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1197 // Setter for EXT_DEPRECATED flag
1198 function setExtensionDeprecated ($deprecated) {
1199 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1202 // Getter for EXT_DEPRECATED flag
1203 function isExtensionDeprecated () {
1204 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1207 // Setter for EXT_UPDATE_DEPENDS flag
1208 function addExtensionDependency ($updateDepends) {
1209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ' - ENTERED!');
1210 // Is the update depency empty? (NEED TO BE FIXED!)
1211 if (empty($updateDepends)) {
1212 // Please report this bug!
1213 debug_report_bug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1216 // Is it not yet added?
1217 /* Only for debugging!
1218 if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1219 // Double-adding isn't fine, too
1220 debug_report_bug(__FUNCTION__, __LINE__, '() called twice: updateDepends=' . $updateDepends . ',currentExtension=' . getCurrentExtensionName());
1224 // Add it to the list of extension update depencies map
1225 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1227 // Remember it in the list of running updates
1228 $GLOBALS['ext_running_updates'][getCurrentExtensionName()][] = $updateDepends;
1229 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ' - EXIT!');
1232 // Getter for running updates
1233 function getExtensionUpdatesRunning () {
1234 return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1237 // Checks wether the given extension registration is in progress
1238 function isExtensionRegistrationRunning ($ext_name) {
1240 $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1243 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1247 // Init EXT_UPDATE_DEPENDS flag
1248 function initExtensionUpdateDependencies () {
1249 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1251 // Init update depency map automatically if not found
1252 if (isExtensionUpdateDependenciesInitialized()) {
1253 // We need these bug reports as well...
1254 debug_report_bug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1257 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1259 // Init running updates array
1260 initExtensionRuningUpdates();
1262 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1265 // Adds an extension as "registration in progress"
1266 function addExtensionRunningRegistration ($ext_name) {
1268 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1269 if (isExtensionRegistrationRunning($ext_name)) {
1270 // This is really bad and should not be quietly ignored
1271 debug_report_bug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1275 $GLOBALS['ext_register_running'][] = $ext_name;
1276 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1279 // Checks wether EXT_UPDATE_DEPENDS is initialized
1280 function isExtensionUpdateDependenciesInitialized () {
1281 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1282 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1285 // Checks wether an update is already running for given extension
1286 function isExtensionUpdateRunning ($ext_name) {
1287 // Current and given extensions means whole array
1288 if ($ext_name == getCurrentExtensionName()) {
1289 // Default is not found
1292 // Walk through whole array
1293 foreach ($GLOBALS['ext_running_updates'] as $ext1=>$depends) {
1295 if (($ext1 == $ext_name) || ($isRunning === true)) {
1297 logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=' . intval($isRunning));
1304 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1309 $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1312 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1316 // Initializes the list of running updates
1317 function initExtensionRuningUpdates () {
1318 // Auto-init ext_running_updates
1319 if (!isset($GLOBALS['ext_running_updates'])) {
1320 $GLOBALS['ext_running_updates'] = array();
1321 $GLOBALS['ext_register_running'] = array();
1325 // Getter for EXT_UPDATE_DEPENDS flag
1326 function getExtensionUpdateDependencies () {
1327 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1328 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1331 // Getter for next iterator depency
1332 function getExtensionUpdateDependenciesIterator () {
1333 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1334 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1337 // Counter for extension update depencies
1338 function countExtensionUpdateDependencies () {
1339 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1340 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1343 // Removes given extension from update denpency list
1344 function removeExtensionDependency ($ext_name) {
1346 $key = array_search($ext_name, getExtensionUpdateDependencies());
1349 if ($key !== false) {
1351 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1353 // And sort the array
1354 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1358 // Init iterator for update depencies
1359 function initExtensionUpdateIterator () {
1360 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1361 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1364 // Getter for depency iterator
1365 function getExtensionUpdateIterator () {
1366 // Auto-init iterator
1367 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1370 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1371 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1374 // Increments the update iterator
1375 function incrementExtensionUpdateIterator () {
1376 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1377 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1380 // Setter for EXT_REPORTS_FAILURE flag
1381 function setExtensionReportsFailure ($reportsFailure) {
1382 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1385 // Getter for EXT_REPORTS_FAILURE flag
1386 function getExtensionReportsFailure () {
1387 return $GLOBALS['ext_reports_failure'];
1390 // Setter for EXT_VER_HISTORY flag
1391 function setExtensionVersionHistory ($versionHistory) {
1392 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1395 // Getter for EXT_VER_HISTORY array
1396 function getExtensionVersionHistory () {
1397 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1400 // Setter for EXT_UPDATE_NOTES
1401 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1402 // . '/' . getCurrentExtensionVersion()
1403 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . ',updateNotes()=' . strlen($updateNotes));
1404 if (empty($ext_ver)) {
1405 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1407 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1411 // Getter for EXT_UPDATE_NOTES
1412 function getExtensionUpdateNotes ($ext_ver) {
1413 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1416 // Checks if ext_update_notes is set
1417 function isExtensionUpdateNoteSet ($ext_ver) {
1418 return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1421 // Init extension notice
1422 function initExtensionNotes ($force = false) {
1423 // Is it already initialized?
1424 if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1425 // This is mostly not wanted, so please report it
1426 debug_report_bug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1429 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1430 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1433 // Append extension notice
1434 function appendExtensionNotes ($notes) {
1435 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes()=' . strlen($notes));
1436 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1439 // Getter for extension notes
1440 function getExtensionNotes () {
1441 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1444 // Setter for current extension name
1445 function setCurrentExtensionName ($ext_name) {
1446 $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1449 // Getter for current extension name
1450 function getCurrentExtensionName () {
1451 if (!isset($GLOBALS['curr_extension_name'])) {
1453 debug_report_bug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1457 return $GLOBALS['curr_extension_name'];
1460 // Init SQLs array for current extension
1461 function initExtensionSqls ($force = false) {
1462 // Auto-init the array or if forced
1463 if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1465 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1467 // Initialize the generic array
1472 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1473 function addExtensionSql ($sql) {
1475 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1476 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1479 // Getter for SQLs array for current extension
1480 function getExtensionSqls () {
1481 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1482 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1483 // Not found, should not happen
1484 debug_report_bug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1485 getCurrentExtensionName()
1490 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1493 // Count SQLs for current extension
1494 function countExtensionSqls () {
1495 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1496 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1497 // Not found, should not happen
1498 debug_report_bug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1499 getCurrentExtensionName()
1504 return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1507 // Removes SQLs for current extension
1508 function unsetExtensionSqls () {
1509 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1512 // Auto-initializes the removal list
1513 function initExtensionRemovalList () {
1514 // Is the remove list there?
1515 if (!isset($GLOBALS['ext_update_remove'])) {
1517 $GLOBALS['ext_update_remove'] = array();
1521 // Checks wether the current extension is on the removal list
1522 function isExtensionOnRemovalList () {
1523 // Init removal list
1524 initExtensionRemovalList();
1527 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1530 // Adds the current extension to the removal list
1531 function addCurrentExtensionToRemovalList () {
1533 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1536 // Getter for removal list
1537 function getExtensionRemovalList () {
1538 // Return the removal list
1539 return $GLOBALS['ext_update_remove'];
1542 // Redirects if the provided extension is not installed
1543 function redirectOnUninstalledExtension ($ext_name) {
1544 // So is the extension there?
1545 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1546 // Redirect to index
1547 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1551 // Filter for initialization of all extensions by loading them in 'init' mode
1552 function FILTER_INIT_EXTENSIONS () {
1553 // Do we have some entries?
1554 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTRY!');
1555 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1556 // Load all found extensions if found
1557 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1558 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1560 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
1561 loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1562 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
1564 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1566 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1569 // Setter for extension mode
1570 function setExtensionMode ($ext_mode) {
1571 $GLOBALS['ext_mode'] = (string) $ext_mode;
1574 // Getter for extension mode
1575 function getExtensionMode () {
1576 return $GLOBALS['ext_mode'];
1579 // Setter for dry-run
1580 function enableExtensionDryRun ($dry_run = true) {
1581 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry='.intval($dry_run));
1582 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1585 // Getter for dry-run
1586 function isExtensionDryRun () {
1587 return $GLOBALS['ext_dry_run'];
1590 // Setter for current extension version
1591 function setCurrentExtensionVersion ($ext_ver) {
1592 // ext_ver should never be empty in other modes than 'test'
1593 if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1594 // Please report all these messages
1595 debug_report_bug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1599 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1600 $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1603 // Getter for current extension version
1604 function getCurrentExtensionVersion () {
1605 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1606 return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1609 // Remove the extension from cache array
1610 function removeExtensionFromArray () {
1611 // "Cache" this name
1612 $ext_name = getCurrentExtensionName();
1614 // Now loop through the whole cache
1615 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1616 // Is it an element?
1617 if (isset($cacheArray[$ext_name])) {
1619 unset($cacheArray[$ext_name]);
1620 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1623 $key = array_search($ext_name, $cacheArray);
1626 if ($key !== false) {
1627 // Found, so remove it
1628 unset($cacheArray[$key]);
1629 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1635 // "Getter" for 'extension has a CSS file' (with same name, of course)
1636 function getExtensionHasCss () {
1637 // Default is no CSS
1640 // Construct FQFN for check
1641 $FQFN = sprintf("%stheme/%s/css/%s.css",
1644 getCurrentExtensionName()
1648 if (isFileReadable($FQFN)) {
1649 // Readable, so it is there...
1657 // Checks wether the given extension has a language file
1658 function ifExtensionHasLanguageFile ($ext_name) {
1659 // Do we have cache?
1660 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1662 incrementStatsEntry('cache_hits');
1664 // Not readable is default
1667 // Is the language file readable for this extension?
1668 if (isLanguageIncludeReadable($ext_name)) {
1674 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = $readable;
1678 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1681 // Load an extension's include file
1682 function loadExtensionInclude () {
1684 if (!isExtensionIncludeReadable()) {
1686 debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1689 // Generate INC name
1690 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1696 // Checks wether an extension is readable
1697 function isExtensionIncludeReadable ($ext_name = '') {
1698 // If empty, use current
1699 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1702 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1703 // Generate INC name
1704 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1707 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1711 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1712 return $GLOBALS['ext_inc_readable'][$ext_name];
1715 // Checks if an extension's function file is readable
1716 function isExtensionFunctionFileReadable ($ext_name) {
1718 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1719 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1720 // Just count cache hits
1721 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1722 incrementStatsEntry('cache_hits');
1724 // Construct IFN for functions file
1725 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1727 // Is this include there?
1728 if ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test')) {
1730 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=Y - FOUND!');
1731 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1734 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=N - NOT FOUND!');
1735 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1740 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1741 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1744 // Adds a CREATE TABLE statement if the requested table is not there
1745 function addCreateTableSql ($tableName, $sql) {
1746 // Is the table not there?
1747 if (!isSqlTableCreated($tableName)) {
1748 // Is not found, so add it
1749 addExtensionSql('CREATE TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ' . $sql);
1751 // Is already there, which should not happen
1752 debug_report_bug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1756 // Adds a DROP TABLE statement if the requested tabled is there
1757 function addDropTableSql ($tableName) {
1758 // Is the table there?
1759 if (isSqlTableCreated($tableName)) {
1760 // Then add it, non-existing tables can be ignored because it will
1761 // happen with every newly installed extension.
1762 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1765 $GLOBALS['isSqlTableCreated'][$tableName] = false;
1769 // Adds an admin menu to the SQL queue of the menu entry is not found
1770 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1771 // Now check if this menu is there
1772 if (!isMenuActionValid('admin', $action, $what)) {
1774 if (is_null($what)) {
1776 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1784 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1793 // Add it to the queue
1794 addExtensionSql($sql);
1795 } elseif (isDebugModeEnabled()) {
1796 // Double menus should be located and fixed!
1797 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1801 // Adds a guest menu to the SQL queue if the menu entry is not found
1802 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1803 // Now check if this menu is there
1804 if (!isMenuActionValid('guest', $action, $what)) {
1806 if (is_null($what)) {
1808 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1817 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1827 // Add it to the queue
1828 addExtensionSql($sql);
1829 } elseif (isDebugModeEnabled()) {
1830 // Double menus should be located and fixed!
1831 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s,locked=%s,visible=%s detected.", $action, $what, $title, $locked, $visible));
1835 // Adds a member menu to the SQL queue if the menu entry is not found
1836 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1837 // Now check if this menu is there
1838 if (!isMenuActionValid('member', $action, $what)) {
1840 if (is_null($what)) {
1842 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1851 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1861 // Add it to the queue
1862 addExtensionSql($sql);
1863 } elseif (isDebugModeEnabled()) {
1864 // Double menus should be located and fixed!
1865 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s,visivle=%s,locked=%s detected.", $action, $what, $title, $visible, $locked));
1869 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1870 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1871 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1872 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1874 if (is_null($what)) {
1876 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1884 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1893 // Add it to the queue
1894 addExtensionSql($sql);
1895 } elseif (isDebugModeEnabled()) {
1896 // Double menus should be located and fixed!
1897 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1901 // Add configuration entry if not found for actual extension
1902 function addConfigAddSql ($columnName, $columnSql) {
1903 // Is the column there?
1904 if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1905 // Not found, so add it
1906 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1909 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
1913 // Enables/disables productive mode for current extension (used only while
1915 function enableExtensionProductive ($isProductive = true) {
1916 // Log debug message
1917 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ext_name=%s,isProductive=%d", getCurrentExtensionName(), intval($isProductive)));
1920 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1923 // Checks wether the extension is in productive phase. If not set, development
1924 // phase (=false) is assumed.
1925 function isExtensionProductive ($ext_name = '') {
1926 // Is the extension name empty? Then use current
1927 if (empty($ext_name)) {
1928 // Get current extension name
1929 $ext_name = getCurrentExtensionName();
1932 // Do we have cache?
1933 if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
1934 // Load extension only if not yet loaded
1935 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
1936 // Load extension in test mode
1937 loadExtension($ext_name, 'test');
1941 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
1944 // Log debug message
1945 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ext_name=%s,isProductive=%s", $ext_name, intval($GLOBALS[__FUNCTION__][$ext_name])));
1948 return $GLOBALS[__FUNCTION__][$ext_name];
1951 // Mark extension file as loaded
1952 function markExtensionAsLoaded ($ext_name) {
1953 // Is it already loaded?
1954 if (isExtensionLoaded($ext_name)) {
1956 debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
1960 $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
1963 // Determine wether the given extension is already loaded
1964 function isExtensionLoaded ($ext_name) {
1966 return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
1969 // Mark extension's library file as loaded
1970 function markExtensionLibraryAsLoaded ($ext_name) {
1971 // Is it already loaded?
1972 if (isExtensionLibraryLoaded($ext_name)) {
1974 debug_report_bug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
1978 $GLOBALS['ext_loaded']['library'][$ext_name] = true;
1981 // Determine wether the given extension's library is already loaded
1982 function isExtensionLibraryLoaded ($ext_name) {
1984 return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));