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://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.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.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.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 loadCurrentExtensionInclude();
160 // Is this extension deprecated?
161 if (isExtensionDeprecated()) {
162 // Deactivate the extension
163 doDeactivateExtension($ext_name);
166 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name);
170 // Mark it as loaded in normal mode
171 if (getExtensionMode() == '') {
173 markExtensionAsLoaded($ext_name);
177 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension successfully loaded, ext_name=' . $ext_name);
181 // Registers an extension and possible update dependencies
182 function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates = false) {
183 // Set current extension name
184 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
185 setCurrentExtensionName($ext_name);
188 enableExtensionDryRun($dry_run);
190 // By default all extensions are in productive phase
191 enableExtensionProductive();
193 // This shall never do a non-admin user or if the extension is active (already installed)
194 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
195 // Abort here with 'false'
199 // When this extension is already in registration/update phase, all is fine
200 if ((isExtensionRegistrationRunning($ext_name)) || ((isExtensionUpdateRunning($ext_name)) && ($ignoreUpdates === false))) {
201 // Then abort here with 'true' becaus it is fine
202 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in registration/update phase, all fine,taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates));
203 ///* BUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!');
207 // This registration is running
208 addExtensionRunningRegistration($ext_name);
210 // Init EXT_UPDATE_DEPENDS if not yet done
211 if (!isExtensionUpdateDependenciesInitialized()) {
213 initExtensionUpdateDependencies();
216 // Is the task id zero? Then we need to auto-fix it here
217 if ($taskId == '0') {
218 // Try to find the task
219 $taskId = determineExtensionTaskId(getCurrentExtensionName());
221 // Still zero and not in dry-run?
222 if (($taskId == '0') && (!isExtensionDryRun())) {
223 // Now try to create a new task
224 $taskId = createNewExtensionTask(getCurrentExtensionName());
227 if ($taskId == '0') {
228 // Then request a bug report
229 debug_report_bug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
231 getCurrentExtensionName()
237 // Init queries and notes
239 initExtensionNotes();
243 $processResult = false;
244 initIncludePool('extension');
246 // By default we have no failures
247 enableExtensionReportingFailure();
249 // Does this extension exists?
250 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
251 if (loadExtension(getCurrentExtensionName(), 'register', '0.0.0', isExtensionDryRun())) {
252 // Set current extension name again
253 setCurrentExtensionName($ext_name);
255 // And run possible updates
256 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
257 $history = getExtensionVersionHistory();
258 foreach ($history as $ext_ver) {
259 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ext_ver);
260 // Load extension in update mode
261 loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun());
263 // Add update notes to our output
264 addExtensionNotes($ext_ver);
267 // Does this extension depends on an outstanding update of another update?
268 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
270 $ext_update = getExtensionUpdateDependenciesIterator();
272 // Increment here to avoid endless loop
273 incrementExtensionUpdateIterator();
275 // Check if extension is not installed and not already in registration procedure and if loading it wents finally fine...
276 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isExtensionRegistrationRunning(' . $ext_update . ')=' . intval(isExtensionRegistrationRunning($ext_update)));
277 if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
278 // Set current extension name again
279 setCurrentExtensionName($ext_name);
281 // If versions mismatch update extension first
283 if (isExtensionInstalled($ext_update)) {
284 // Get version only if installed
285 $ext_ver = getExtensionVersion($ext_update);
288 // Extension version set? If empty the extension is not registered
289 if (empty($ext_ver)) {
290 // Extension not registered so far so first load task's id...
291 $taskId = determineExtensionTaskId($ext_update);
295 // Try to register the extension
296 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',taskId=' . $taskId . ',isExtensionDryRun()=' . isExtensionDryRun());
297 $processResult = registerExtension($ext_update, $taskId, isExtensionDryRun(), true);
299 // Reset extension name
300 setCurrentExtensionName($ext_name);
301 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',processResult=' . intval($processResult));
303 } elseif ($ext_ver != getCurrentExtensionVersion()) {
304 // Ok, update this extension now
305 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
306 $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
307 $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
308 updateExtension($ext_update, $ext_ver, isExtensionDryRun());
309 setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
310 setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
311 unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
312 unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
313 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
316 $processResult = true;
318 // Nothing to register / update before...
319 $processResult = true;
322 // Required file for update does not exists!
323 $processResult = true;
324 // But this is fine for the first time...
327 // Restore the current extension name
328 setCurrentExtensionName($ext_name);
331 // Is there no update?
332 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
333 // Then test is passed!
334 $processResult = true;
337 // Switch back to register mode
338 setExtensionMode('register');
340 // Remains true if extension registration reports no failures
341 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
342 $processResult = (($processResult === true) && (isExtensionReportingFailure() === false));
343 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
345 // Does everthing before wents ok?
346 if ($processResult === true) {
347 // "Dry-run-mode" activated?
348 if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
349 // Init SQLs and transfer ext->generic
350 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
352 setSqlsArray(getExtensionSqls());
354 // Run installation pre-installation filters
355 runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
357 // Register extension
358 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
359 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
361 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
362 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
364 getCurrentExtensionName(),
365 getThisExtensionAlwaysActive(),
366 getCurrentExtensionVersion(),
368 ), __FUNCTION__, __LINE__);
371 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
372 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`) VALUES ('%s','%s','%s')",
374 getCurrentExtensionName(),
375 getThisExtensionAlwaysActive(),
376 getCurrentExtensionVersion()
377 ), __FUNCTION__, __LINE__);
380 // Use the insert id as extension id and cache it for early usage
381 $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
382 $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
384 // Mark it as installed
385 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
387 // Remove cache file(s) if extension is active
388 runFilterChain('post_extension_installed', array(
389 'pool' => 'extension',
390 'ext_name' => getCurrentExtensionName(),
394 // Re-init queries and notes
395 initExtensionSqls(true);
396 initExtensionNotes(true);
398 // In normal mode return a true on success
400 } elseif (isExtensionDryRun() === true) {
401 // In "dry-run" mode do always return a true
404 // Extension has been removed for updates, so all is fine!
408 // No, an error occurs while registering extension :-(
409 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
412 } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
413 // Remove task from system when id and extension's name is valid
414 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
415 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
416 array(bigintval($taskId)), __FUNCTION__, __LINE__);
419 // Return status code
420 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',processResult=' . intval($processResult) . ' - EXIT!');
424 // Run SQL queries for given extension id
425 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
426 function doExtensionSqls ($ext_id, $load_mode) {
427 // This shall never do a non-admin user!
432 // Get extension's name
433 $ext_name = getExtensionName($ext_id);
435 // Set current SQL name
436 setCurrentExtensionName($ext_name);
438 // Init EXT_UPDATE_DEPENDS
439 if (!isExtensionUpdateDependenciesInitialized()) {
441 initExtensionUpdateDependencies();
445 initExtensionSqls(true);
447 // By default no SQL has been executed
450 // Load extension in detected mode
451 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name[' . $ext_id . ']=' . getCurrentExtensionName() . ',load_mode=' . $load_mode);
452 loadExtension(getCurrentExtensionName(), $load_mode, '0.0.0', false);
456 setSqlsArray(getExtensionSqls());
459 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls());
461 // Do we have entries?
463 // Run SQL commands...
464 runFilterChain('run_sqls');
467 // Run any filters depending on the action here
468 runFilterChain('extension_' . $load_mode);
470 // Remove cache file(s) if extension is active
471 if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED())) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
473 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
476 // Is this the sql_patches?
477 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $ext_id . ',currName=' . getCurrentExtensionName() . ',loadMode=' . $load_mode);
478 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
479 // Then redirect to logout
480 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': LOAD!');
481 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
485 // Check wether the given extension is installed
486 function isExtensionInstalled ($ext_name) {
487 // We don't like empty extension names here
488 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
489 if (empty($ext_name)) {
490 // Please fix them all
491 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty.');
494 // By default non is installed
495 $isInstalled = false;
497 // Check if there is a cache entry
498 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
499 // Use cache built from below queries
500 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
501 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
502 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
504 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - FOUND!');
508 incrementStatsEntry('cache_hits');
509 } elseif ((isInstallationPhase())) {
510 // Extensions are all inactive/not installed during installation
511 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - installion phase');
514 $ext_id = getExtensionId($ext_name);
516 // Do we have a record?
517 $isInstalled = ($ext_id > 0);
520 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_id=' . $ext_id . ',isInstalled=' . intval($isInstalled));
522 // Is it installed, then cache the entry
523 if ($isInstalled === true) {
524 // Dummy call (get is okay here)
525 getExtensionId($ext_name, true);
528 // Remember the status
529 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
533 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isInstalled=' . intval($isInstalled) . ' - EXIT!');
537 // Check if given extension is active
538 function isExtensionActive ($ext_name) {
539 if (isInstallationPhase()) {
540 // Extensions are all inactive during installation
542 } elseif (empty($ext_name)) {
543 // Empty extension names must befixed
544 debug_report_bug(__FUNCTION__, __LINE__, 'Empty extension name provided.');
545 } elseif (!isExtensionInstalled($ext_name)) {
546 // Not installed extensions are always inactive
550 // Not active is the default
551 $data['ext_active'] = 'N';
554 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
556 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE! ext_name=' . $ext_name);
557 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
560 incrementStatsEntry('cache_hits');
561 } elseif (isExtensionLoaded($ext_name)) {
562 // @TODO Extension is loaded, what next?
563 debug_report_bug(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
564 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
565 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DB! ext_name=' . $ext_name);
566 // Load from database
567 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
568 array($ext_name), __FUNCTION__, __LINE__);
571 if (SQL_NUMROWS($result) == 1) {
573 $data = SQL_FETCHARRAY($result);
577 SQL_FREERESULT($result);
580 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . '[DB]: ' . $data['ext_active']);
581 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
583 // Extension not active!
584 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': Not active!');
585 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
589 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',active=' . $data['ext_active']);
591 // Is this extension activated? (For admins we always have active extensions...)
592 return ($data['ext_active'] == 'Y');
595 // Get version from extensions
596 function getExtensionVersion ($ext_name, $force = false) {
597 // By default no extension is found
598 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
599 $data['ext_version'] = 'false';
601 // Empty extension name should be fixed!
602 if (empty($ext_name)) {
603 // Please report this bug!
604 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty which is not allowed here.');
607 // Extensions are all inactive during installation
608 if (isInstallationPhase()) {
612 // Is the cache written?
613 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - Checking cache ...');
614 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
615 // Load data from cache
616 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
617 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
620 incrementStatsEntry('cache_hits');
621 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (!isHtmlOutputMode())) {
622 // Load from database
623 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
624 array($ext_name), __FUNCTION__, __LINE__);
625 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': DB - '.SQL_NUMROWS($result).'');
627 // Is the extension there?
628 if (SQL_NUMROWS($result) == 1) {
630 $data = SQL_FETCHARRAY($result);
633 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
634 } elseif (isDebugModeEnabled()) {
635 // Not found, may happen while an extension is uninstalled
636 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot find extension %s in database!", $ext_name));
640 SQL_FREERESULT($result);
643 // Extension version should not be invalid
644 if (($data['ext_version'] == 'false') && ($force === false)) {
645 // Please report this trouble
646 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> has empty version!", $ext_name));
650 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_version=' . $data['ext_version']);
651 return $data['ext_version'];
654 // Updates a given extension with current extension version to latest version
655 function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependencies = false) {
656 // Only admins are allowed to update extensions
657 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
658 if ((!isAdmin()) || (empty($ext_name))) {
659 // Called as non-admin or empty extension
660 debug_report_bug(__FUNCTION__, __LINE__, 'Called as non-admin (isAdmin()=' . intval(isAdmin()) . '), or empty extension name. ext_name=' . $ext_name);
663 // Set current SQL name
664 setCurrentExtensionName($ext_name);
666 // Is this extension update already running?
667 if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($dry_run === false)) {
668 // This is fine but needs logging ATM
669 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
670 ///* BUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, please investigate!');
676 initExtensionNotes();
677 initIncludePool('extension');
679 // Load extension in test mode
680 loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
682 // Save version history
683 $history = getExtensionVersionHistory();
685 // Remove old SQLs array to prevent possible bugs
688 // Check if version is updated
689 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, getCurrentExtensionName() . '/' . $ext_name . ':' . getThisExtensionVersion() . '/' . $ext_ver . '/' . intval(is_array($history)));
690 if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
691 // Search for starting point (-1 for making 0.0 -> 0.0.0 switch work)
693 if ($ext_ver != '0.0') {
694 $start = array_search($ext_ver, $history);
697 // And load SQL queries in order of version history
698 for ($idx = ($start + 1); $idx < count($history); $idx++) {
699 // Set extension version
700 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
703 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
706 $depencies = getExtensionUpdateDependencies();
709 if (count($depencies) > 0) {
710 // Apply all extension depencies
711 foreach ($depencies as $ext_depend) {
712 // Did we already update/register this?
713 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
715 setCurrentExtensionName($ext_depend);
717 // Mark it as already updated before we update it
718 $GLOBALS['ext_updated'][$ext_depend] = true;
720 // Is the extension there?
721 if (isExtensionInstalled($ext_depend)) {
722 // Update another extension first!
723 $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun(), true);
725 // Register new extension
726 $processResult = registerExtension($ext_depend, 0, isExtensionDryRun());
732 setCurrentExtensionName($ext_name);
734 // Set extension version here
735 setCurrentExtensionVersion($ext_ver);
739 addExtensionNotes($history[$idx]);
742 // In real-mode execute any existing includes
743 if (isExtensionDryRun() === false) {
744 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
745 runFilterChain('load_includes', 'extension');
746 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
747 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
752 setSqlsArray(getExtensionSqls());
755 runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
757 if (isExtensionDryRun() === false) {
758 // Run filters on success extension update
759 runFilterChain('extension_update', getCurrentExtensionName());
763 //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!');
766 // Output verbose SQL table for extension
767 function addExtensionVerboseSqlTable ($title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}') {
771 debug_report_bug(__FUNCTION__, __LINE__, 'title is empty.');
777 // Do we have queries?
778 if (isVerboseSqlEnabled()) {
779 // Do we have entries?
780 if (countExtensionSqls() > 0) {
784 foreach (getExtensionSqls() as $sqls) {
785 // New array format is recursive
786 foreach ($sqls as $sql) {
790 // Output command if set
792 // Prepare output for template
795 'sql' => str_replace('{', '{', str_replace('}', '}', encodeEntities($sql)))
799 $OUT .= loadTemplate('admin_extension_sql_row', true, $content);
807 // Prepare content for template
813 // Load main template
814 $OUT = loadTemplate('admin_extension_sql_table', true, $content);
816 // No addional SQL commands to run
817 $OUT = displayMessage('{--ADMIN_NO_ADDITIONAL_SQLS--}', true);
825 // Get extension name from id
826 function getExtensionName ($ext_id) {
827 // Init extension name
828 $data['ext_name'] = '';
831 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
833 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
836 incrementStatsEntry('cache_hits');
837 } elseif (!isExtensionActive('cache')) {
838 // Load from database
839 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
840 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
842 // Is the entry there?
843 if (SQL_NUMROWS($result) == 1) {
844 // Get the extension's name from database
845 $data = SQL_FETCHARRAY($result);
849 SQL_FREERESULT($result);
852 // Did we find some extension?
853 if (empty($data['ext_name'])) {
854 // We should fix these all!
855 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty. ext_id=' . $ext_id);
858 // Return the extension name
859 return $data['ext_name'];
862 // Get extension id from name
863 function getExtensionId ($ext_name) {
865 $data['ext_id'] = '0';
868 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
870 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
873 incrementStatsEntry('cache_hits');
875 // Load from database
876 $result = SQL_QUERY_ESC("SELECT `id` AS `ext_id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
877 array($ext_name), __FUNCTION__, __LINE__);
879 // Is the entry there?
880 if (SQL_NUMROWS($result) == 1) {
881 // Get the extension's id from database
882 $data = SQL_FETCHARRAY($result);
886 SQL_FREERESULT($result);
889 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
893 return $data['ext_id'];
896 // Determines wether the given extension name is valid
897 function isExtensionNameValid ($ext_name) {
899 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
900 // Generate include file name
901 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
903 // Is there a file in inc/extensions/ ?
904 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
908 return $GLOBALS['ext_name_valid'][$ext_name];
911 // Determines wether the given extension id is valid
912 function isExtensionIdValid ($ext_id) {
913 // Default is nothing valid
916 // Check in cache then in database
917 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
922 incrementStatsEntry('cache_hits');
925 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
932 // Activate given extension
933 function doActivateExtension ($ext_name) {
934 // Is the extension installed?
935 if (!isExtensionInstalled($ext_name)) {
936 // Non-installed extensions cannot be activated
937 debug_report_bug(__FUNCTION__, __LINE__, 'Tried to activate non-installed extension ' . $ext_name);
940 // Activate the extension
941 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
942 array($ext_name), __FUNCTION__, __LINE__);
944 // Then run all queries
945 doExtensionSqls(getExtensionId($ext_name), 'activate');
948 // Deactivate given extension
949 function doDeactivateExtension ($ext_name) {
950 // Is the extension installed?
951 if (!isExtensionInstalled($ext_name)) {
952 // Non-installed extensions cannot be activated
953 debug_report_bug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name);
956 // Activate the extension
957 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
958 array($ext_name), __FUNCTION__, __LINE__);
960 // Then run all queries
961 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
963 // Create new task (we ignore the task id here)
964 createExtensionDeactivationTask($ext_name);
967 sendAdminNotification(
968 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
969 'admin_extension_deactivated',
970 array('ext_name' => $ext_name)
974 // Checks wether the extension is older than given
975 function isExtensionOlder ($ext_name, $ext_ver) {
976 // Get current extension version
977 $currVersion = getExtensionVersion($ext_name);
979 // Remove all dots from both versions
980 $currVersion = str_replace('.', '', $currVersion);
981 $ext_ver = str_replace('.', '', $ext_ver);
983 // Now compare both and return the result
984 return ($currVersion < $ext_ver);
987 // Creates a new task for updated extension
988 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
989 // Create subject line
990 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
993 $taskId = determineTaskIdBySubject($subject);
995 // Is the extension there?
996 if (isExtensionInstalled($ext_name)) {
997 // Check if task is not there
998 if ($taskId == '0') {
999 // Create extension update-task
1000 $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
1003 // Extension not there! :-(
1004 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1011 // Creates a new task for newly installed extension
1012 function createNewExtensionTask ($ext_name) {
1013 // Generate subject line
1014 $subject = sprintf("[%s:]", $ext_name);
1017 $taskId = determineTaskIdBySubject($subject);
1019 // Not installed and do we have created a task for the admin?
1020 if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1021 // Set default message if ext-foo is missing
1022 $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
1025 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1031 // Load text for task if found
1032 if (isFileReadable($FQFN)) {
1033 // Load extension's description template (but do not compile the code)
1034 $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1036 // Write this in debug.log as well
1037 logDebugMessage(__FUNCTION__, __LINE__, $message);
1040 // Task not created so it's a brand-new extension which we need to register and create a task for!
1041 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1048 // Creates a task for automatically deactivated (deprecated) extension
1049 function createExtensionDeactivationTask ($ext_name) {
1050 // Create subject line
1051 $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1054 $taskId = determineTaskIdBySubject($subject);
1056 // Not installed and do we have created a task for the admin?
1057 if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1058 // Task not created so add it
1059 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1066 // Determines the task id for given extension
1067 function determineExtensionTaskId ($ext_name) {
1068 // Default is not found
1069 $data['task_id'] = '0';
1071 // Search for extension task's id
1072 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1073 array($ext_name), __FUNCTION__, __LINE__);
1076 if (SQL_NUMROWS($result) == 1) {
1077 // Task found so load task's id and register extension...
1078 $data = SQL_FETCHARRAY($result);
1082 SQL_FREERESULT($result);
1085 return $data['task_id'];
1088 // Determines the task id for given subject
1089 function determineTaskIdBySubject ($subject) {
1090 // Default is not found
1091 $data['task_id'] = '0';
1093 // Search for task id
1094 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1095 array($subject), __FUNCTION__, __LINE__);
1098 if (SQL_NUMROWS($result) == 1) {
1099 // Task found so load task's id and register extension...
1100 $data = SQL_FETCHARRAY($result);
1104 SQL_FREERESULT($result);
1107 return $data['task_id'];
1110 // Add updates notes for given version
1111 function addExtensionNotes ($ext_ver) {
1112 // Init notes/content
1116 // Is do we have verbose output enabled?
1117 if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1118 // Update notes found?
1119 if ((isExtensionUpdateNoteSet($ext_ver)) && ($ext_ver != '0.0.0')) {
1120 // Update notes found
1123 'notes' => getExtensionUpdateNotes($ext_ver)
1127 setExtensionUpdateNotes('', $ext_ver);
1128 } elseif ($ext_ver == '0.0.0') {
1129 // Is the extension productive?
1130 if (isExtensionProductive(getCurrentExtensionName())) {
1134 'notes' => '{--INITIAL_RELEASE--}'
1140 'notes' => '{--DEVELOPER_RELEASE--}'
1144 // No update notes found
1147 'notes' => '{--NO_UPDATE_NOTES--}'
1152 $out = loadTemplate('admin_extension_notes', true, $content);
1156 appendExtensionNotes($out);
1159 // Getter for CSS files array
1160 function getExtensionCssFiles () {
1161 // By default no additional CSS files are found
1162 $cssFiles = array();
1164 // Is the array there?
1165 if (isset($GLOBALS['css_files'])) {
1167 $cssFiles = $GLOBALS['css_files'];
1174 // Init CSS files array
1175 function initExtensionCssFiles () {
1177 $GLOBALS['css_files'] = array();
1181 function addExtensionCssFile ($file) {
1182 // Is the array there?
1183 if (!isset($GLOBALS['css_files'])) {
1184 // Then auto-init them
1185 initExtensionCssFiles();
1189 $GLOBALS['css_files'][] = $file;
1192 // Setter for EXT_ALWAYS_ACTIVE flag
1193 function setExtensionAlwaysActive ($active) {
1194 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1197 // Getter for EXT_ALWAYS_ACTIVE flag
1198 function getThisExtensionAlwaysActive () {
1199 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1202 // Checks wether the current extension is always active
1203 function isThisExtensionAlwaysActive () {
1204 return (getThisExtensionAlwaysActive() == 'Y');
1207 // Setter for EXT_VERSION flag
1208 function setThisExtensionVersion ($ext_version) {
1209 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1212 // Getter for EXT_VERSION flag
1213 function getThisExtensionVersion () {
1214 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1217 // Setter for EXT_DEPRECATED flag
1218 function setExtensionDeprecated ($deprecated) {
1219 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1222 // Getter for EXT_DEPRECATED flag
1223 function isExtensionDeprecated () {
1224 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1227 // Setter for EXT_UPDATE_DEPENDS flag
1228 function addExtensionDependency ($updateDepends) {
1229 // Is the update depency empty? (NEED TO BE FIXED!)
1230 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - ENTERED!');
1231 if (empty($updateDepends)) {
1232 // Please report this bug!
1233 debug_report_bug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1236 // Is it not yet added?
1237 if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1239 * Double-adding happens when the extension and an update of the same
1240 * extension requires the same other extension again.
1242 logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
1246 // Add it to the list of extension update depencies map
1247 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1249 // Remember it in the list of running updates
1250 $GLOBALS['ext_running_updates'][getCurrentExtensionName()][] = $updateDepends;
1251 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - EXIT!');
1254 // Getter for running updates
1255 function getExtensionUpdatesRunning () {
1256 return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1259 // Checks wether the given extension registration is in progress
1260 function isExtensionRegistrationRunning ($ext_name) {
1262 $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1265 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1269 // Init EXT_UPDATE_DEPENDS flag
1270 function initExtensionUpdateDependencies () {
1271 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1273 // Init update depency map automatically if not found
1274 if (isExtensionUpdateDependenciesInitialized()) {
1275 // We need these bug reports as well...
1276 debug_report_bug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1279 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1281 // Init running updates array
1282 initExtensionRuningUpdates();
1284 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1287 // Adds an extension as "registration in progress"
1288 function addExtensionRunningRegistration ($ext_name) {
1290 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1291 if (isExtensionRegistrationRunning($ext_name)) {
1292 // This is really bad and should not be quietly ignored
1293 debug_report_bug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1297 $GLOBALS['ext_register_running'][] = $ext_name;
1298 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1301 // Checks wether EXT_UPDATE_DEPENDS is initialized
1302 function isExtensionUpdateDependenciesInitialized () {
1303 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1304 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1307 // Checks wether an update is already running for given extension
1308 function isExtensionUpdateRunning ($ext_name, $ignoreDependencies = false) {
1309 // Current and given extensions means whole array
1310 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
1311 if ($ext_name == getCurrentExtensionName()) {
1312 // Default is not found
1315 // Walk through whole array
1316 foreach ($GLOBALS['ext_running_updates'] as $ext1=>$depends) {
1318 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',depends=' . print_r($depends, true));
1319 if (($ext1 == $ext_name) || ((in_array($ext_name, $depends)) && ($ignoreDependencies === false))) {
1322 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=true - FOUND!');
1328 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - ALT-EXIT!');
1333 $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1336 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - EXIT!');
1340 // Initializes the list of running updates
1341 function initExtensionRuningUpdates () {
1342 // Auto-init ext_running_updates
1343 if (!isset($GLOBALS['ext_running_updates'])) {
1344 $GLOBALS['ext_running_updates'] = array();
1345 $GLOBALS['ext_register_running'] = array();
1349 // Getter for EXT_UPDATE_DEPENDS flag
1350 function getExtensionUpdateDependencies () {
1351 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1352 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1355 // Getter for next iterator depency
1356 function getExtensionUpdateDependenciesIterator () {
1357 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1358 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1361 // Counter for extension update depencies
1362 function countExtensionUpdateDependencies () {
1363 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1364 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1367 // Removes given extension from update denpency list
1368 function removeExtensionDependency ($ext_name) {
1370 $key = array_search($ext_name, getExtensionUpdateDependencies());
1373 if ($key !== false) {
1375 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1377 // And sort the array
1378 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1382 // Init iterator for update depencies
1383 function initExtensionUpdateIterator () {
1384 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1385 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1388 // Getter for depency iterator
1389 function getExtensionUpdateIterator () {
1390 // Auto-init iterator
1391 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1394 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1395 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1398 // Increments the update iterator
1399 function incrementExtensionUpdateIterator () {
1400 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1401 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1404 // Setter for EXT_REPORTS_FAILURE flag
1405 function enableExtensionReportingFailure ($reportsFailure = false) {
1406 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1409 // Getter for EXT_REPORTS_FAILURE flag
1410 function isExtensionReportingFailure () {
1411 return $GLOBALS['ext_reports_failure'];
1414 // Setter for EXT_VER_HISTORY flag
1415 function setExtensionVersionHistory ($versionHistory) {
1416 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1419 // Getter for EXT_VER_HISTORY array
1420 function getExtensionVersionHistory () {
1421 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1424 // Setter for EXT_UPDATE_NOTES
1425 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1427 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . '/' . getCurrentExtensionVersion() . ',updateNotes()=' . strlen($updateNotes));
1428 if (empty($ext_ver)) {
1429 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1431 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1435 // Getter for EXT_UPDATE_NOTES
1436 function getExtensionUpdateNotes ($ext_ver) {
1437 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1440 // Checks if ext_update_notes is set
1441 function isExtensionUpdateNoteSet ($ext_ver) {
1442 return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1445 // Init extension notice
1446 function initExtensionNotes ($force = false) {
1447 // Is it already initialized?
1448 if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1449 // This is mostly not wanted, so please report it
1450 debug_report_bug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1453 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1454 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1457 // Append extension notice
1458 function appendExtensionNotes ($notes) {
1459 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes()=' . strlen($notes));
1460 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1463 // Getter for extension notes
1464 function getExtensionNotes () {
1465 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1468 // Setter for current extension name
1469 function setCurrentExtensionName ($ext_name) {
1470 $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1473 // Getter for current extension name
1474 function getCurrentExtensionName () {
1475 if (!isset($GLOBALS['curr_extension_name'])) {
1477 debug_report_bug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1481 return $GLOBALS['curr_extension_name'];
1484 // Init SQLs array for current extension
1485 function initExtensionSqls ($force = false) {
1486 // Auto-init the array or if forced
1487 if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1489 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1491 // Initialize the generic array
1496 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1497 function addExtensionSql ($sql) {
1499 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1500 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1503 // Getter for SQLs array for current extension
1504 function getExtensionSqls () {
1505 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1506 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1507 // Not found, should not happen
1508 debug_report_bug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1509 getCurrentExtensionName()
1514 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1517 // Count SQLs for current extension
1518 function countExtensionSqls () {
1519 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1520 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1521 // Not found, should not happen
1522 debug_report_bug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1523 getCurrentExtensionName()
1528 return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1531 // Removes SQLs for current extension
1532 function unsetExtensionSqls () {
1533 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1536 // Auto-initializes the removal list
1537 function initExtensionRemovalList () {
1538 // Is the remove list there?
1539 if (!isset($GLOBALS['ext_update_remove'])) {
1541 $GLOBALS['ext_update_remove'] = array();
1545 // Checks wether the current extension is on the removal list
1546 function isExtensionOnRemovalList () {
1547 // Init removal list
1548 initExtensionRemovalList();
1551 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1554 // Adds the current extension to the removal list
1555 function addCurrentExtensionToRemovalList () {
1557 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1560 // Getter for removal list
1561 function getExtensionRemovalList () {
1562 // Return the removal list
1563 return $GLOBALS['ext_update_remove'];
1566 // Redirects if the provided extension is not installed
1567 function redirectOnUninstalledExtension ($ext_name) {
1568 // So is the extension there?
1569 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1570 // Redirect to index
1571 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1575 // Filter for initialization of all extensions by loading them in 'init' mode
1576 function FILTER_INIT_EXTENSIONS () {
1577 // Do we have some entries?
1578 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTRY!');
1579 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1580 // Load all found extensions if found
1581 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1582 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1584 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
1585 loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1586 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
1588 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1590 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1593 // Setter for extension mode
1594 function setExtensionMode ($ext_mode) {
1595 $GLOBALS['ext_mode'] = (string) $ext_mode;
1598 // Getter for extension mode
1599 function getExtensionMode () {
1600 return $GLOBALS['ext_mode'];
1603 // Setter for dry-run
1604 function enableExtensionDryRun ($dry_run = true) {
1605 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry_run='.intval($dry_run));
1606 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1609 // Getter for dry-run
1610 function isExtensionDryRun () {
1611 return $GLOBALS['ext_dry_run'];
1614 // Setter for current extension version
1615 function setCurrentExtensionVersion ($ext_ver) {
1616 // ext_ver should never be empty in other modes than 'test'
1617 if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1618 // Please report all these messages
1619 debug_report_bug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1623 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1624 $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1627 // Getter for current extension version
1628 function getCurrentExtensionVersion () {
1629 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1630 return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1633 // Remove the extension from cache array
1634 function removeExtensionFromArray () {
1635 // "Cache" this name
1636 $ext_name = getCurrentExtensionName();
1638 // Now loop through the whole cache
1639 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1640 // Is it an element?
1641 if (isset($cacheArray[$ext_name])) {
1643 unset($cacheArray[$ext_name]);
1644 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1647 $key = array_search($ext_name, $cacheArray);
1650 if ($key !== false) {
1651 // Found, so remove it
1652 unset($cacheArray[$key]);
1653 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1658 // Remove from other caches as well
1659 unset($GLOBALS['ext_is_installed'][$ext_name]);
1660 unset($GLOBALS['loaded_extension'][$ext_name]);
1663 // "Getter" for 'extension has a CSS file' (with same name, of course)
1664 function getExtensionHasCss () {
1665 // Do we have cache?
1666 if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
1667 // Construct FQFN for check
1668 $FQFN = sprintf("%stheme/%s/css/%s.css",
1671 getCurrentExtensionName()
1675 $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
1679 return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
1682 // Checks wether the given extension has a language file
1683 function ifExtensionHasLanguageFile ($ext_name) {
1684 // Do we have cache?
1685 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1687 incrementStatsEntry('cache_hits');
1689 // Determine it and put it in cache
1690 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
1694 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1697 // Load current extension's include file
1698 function loadCurrentExtensionInclude () {
1700 if (!isExtensionIncludeReadable()) {
1702 debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1705 // Generate INC name
1706 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1712 // Checks wether an extension is readable
1713 function isExtensionIncludeReadable ($ext_name = '') {
1714 // If empty, use current
1715 if (empty($ext_name)) {
1716 $ext_name = getCurrentExtensionName();
1720 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1721 // Generate INC name
1722 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1725 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1729 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1730 return $GLOBALS['ext_inc_readable'][$ext_name];
1733 // Checks if an extension's function file is readable
1734 function isExtensionFunctionFileReadable ($ext_name) {
1736 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1737 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1738 // Just count cache hits
1739 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1740 incrementStatsEntry('cache_hits');
1742 // Construct IFN for functions file
1743 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1745 // Is this include there?
1746 $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
1748 // And put in cache, converted
1749 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
1753 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1754 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1757 // Adds a CREATE TABLE statement if the requested table is not there
1758 function addCreateTableSql ($tableName, $sql, $comment) {
1759 // Is the table not there?
1760 if (!isSqlTableCreated($tableName)) {
1761 // Is not found, so add it
1762 addExtensionSql('CREATE TABLE
1763 `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
1764 ENGINE = {?_TABLE_TYPE?}
1766 COLLATE utf8_general_ci
1767 COMMENT ' . "'" . $comment . "'");
1769 // Is already there, which should not happen
1770 debug_report_bug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1774 // Adds a DROP TABLE statement if the requested tabled is there
1775 function addDropTableSql ($tableName) {
1776 // Is the table there?
1777 if (isSqlTableCreated($tableName)) {
1778 // Then add it, non-existing tables can be ignored because it will
1779 // happen with every newly installed extension.
1780 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1783 $GLOBALS['isSqlTableCreated'][$tableName] = false;
1787 // Adds an admin menu to the SQL queue of the menu entry is not found
1788 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1789 // Now check if this menu is there
1790 if (!isMenuActionValid('admin', $action, $what)) {
1792 if (is_null($what)) {
1794 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1802 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1811 // Add it to the queue
1812 addExtensionSql($sql);
1813 } elseif (isDebugModeEnabled()) {
1814 // Double menus should be located and fixed!
1815 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1819 // Adds a guest menu to the SQL queue if the menu entry is not found
1820 function addGuestMenuSql ($action, $what, $title, $sort) {
1821 // Now check if this menu is there
1822 if (!isMenuActionValid('guest', $action, $what)) {
1824 if (is_null($what)) {
1826 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1833 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1841 // Add it to the queue
1842 addExtensionSql($sql);
1843 } elseif (isDebugModeEnabled()) {
1844 // Double menus should be located and fixed!
1845 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1849 // Adds a member menu to the SQL queue if the menu entry is not found
1850 function addMemberMenuSql ($action, $what, $title, $sort) {
1851 // Now check if this menu is there
1852 if (!isMenuActionValid('member', $action, $what)) {
1854 if (is_null($what)) {
1856 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1863 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1871 // Add it to the queue
1872 addExtensionSql($sql);
1873 } elseif (isDebugModeEnabled()) {
1874 // Double menus should be located and fixed!
1875 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1879 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1880 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1881 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1882 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1884 if (is_null($what)) {
1886 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1894 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1903 // Add it to the queue
1904 addExtensionSql($sql);
1905 } elseif (isDebugModeEnabled()) {
1906 // Double menus should be located and fixed!
1907 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1911 // Add configuration entry if not found for actual extension
1912 function addConfigAddSql ($columnName, $columnSql) {
1913 // Is the column there?
1914 if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1915 // Not found, so add it
1916 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1917 } elseif (isDebugModeEnabled()) {
1919 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
1923 // Drop configuration entry if found for actual extension
1924 function addConfigDropSql ($columnName) {
1925 // Is the column there?
1926 if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1928 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
1929 } elseif (isDebugModeEnabled()) {
1930 // Add debug line, debug_report_bug() would cause some extenion updates fail
1931 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
1935 // Change configuration entry for actual extension
1936 function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
1937 // Add the SQL statement
1938 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
1941 // Enables/disables productive mode for current extension (used only while
1943 // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
1944 function enableExtensionProductive ($isProductive = true) {
1945 // Log debug message
1946 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',isProductive=', intval($isProductive));
1949 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1952 // Checks wether the extension is in productive phase. If not set, development
1953 // phase (=false) is assumed.
1954 function isExtensionProductive ($ext_name = '') {
1955 // Is the extension name empty? Then use current
1956 if (empty($ext_name)) {
1957 // Get current extension name
1958 $ext_name = getCurrentExtensionName();
1960 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
1962 // Do we have cache?
1963 if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
1964 // Load extension only if not yet loaded
1965 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
1966 // Load extension in test mode
1967 loadExtension($ext_name, 'test');
1971 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
1975 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isProductive=', intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!');
1976 return $GLOBALS[__FUNCTION__][$ext_name];
1979 // Mark extension file as loaded
1980 function markExtensionAsLoaded ($ext_name) {
1981 // Is it already loaded?
1982 if (isExtensionLoaded($ext_name)) {
1984 debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
1988 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_loaded=true');
1989 $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
1992 // Determine wether the given extension is already loaded
1993 function isExtensionLoaded ($ext_name) {
1995 return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
1998 // Mark extension's library file as loaded
1999 function markExtensionLibraryAsLoaded ($ext_name) {
2000 // Is it already loaded?
2001 if (isExtensionLibraryLoaded($ext_name)) {
2003 debug_report_bug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
2007 $GLOBALS['ext_loaded']['library'][$ext_name] = true;
2010 // Determine wether the given extension's library is already loaded
2011 function isExtensionLibraryLoaded ($ext_name) {
2013 return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));