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 // Include the extension file
155 loadCurrentExtensionInclude();
157 // Is this extension deprecated?
158 if ((isExtensionDeprecated()) && (!in_array(getExtensionMode(), array('test', 'update')))) {
159 // Deactivate the extension
160 doDeactivateExtension($ext_name);
163 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name);
167 // Mark it as loaded in normal mode
168 if (getExtensionMode() == '') {
170 markExtensionAsLoaded($ext_name);
174 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension successfully loaded, ext_name=' . $ext_name);
178 // Registers an extension and possible update dependencies
179 function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates = false) {
180 // Set current extension name
181 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
182 setCurrentExtensionName($ext_name);
185 enableExtensionDryRun($dry_run);
187 // By default all extensions are in productive phase
188 enableExtensionProductive();
190 // This shall never do a non-admin user or if the extension is active (already installed)
191 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
192 // Abort here with 'false'
196 // When this extension is already in registration/update phase, all is fine
197 if ((isExtensionRegistrationRunning($ext_name)) || ((isExtensionUpdateRunning($ext_name)) && ($ignoreUpdates === false))) {
198 // Then abort here with 'true' becaus it is fine
199 //* 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));
200 ///* BUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!');
204 // This registration is running
205 addExtensionRunningRegistration($ext_name);
207 // Init EXT_UPDATE_DEPENDS if not yet done
208 if (!isExtensionUpdateDependenciesInitialized()) {
210 initExtensionUpdateDependencies();
213 // Is the task id zero? Then we need to auto-fix it here
214 if ($taskId == '0') {
215 // Try to find the task
216 $taskId = determineExtensionTaskId(getCurrentExtensionName());
218 // Still zero and not in dry-run?
219 if (($taskId == '0') && (!isExtensionDryRun())) {
220 // Now try to create a new task
221 $taskId = createNewExtensionTask(getCurrentExtensionName());
224 if ($taskId == '0') {
225 // Then request a bug report
226 debug_report_bug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
228 getCurrentExtensionName()
234 // Init queries and notes
236 initExtensionNotes();
240 $processResult = false;
241 initIncludePool('extension');
243 // By default we have no failures
244 enableExtensionReportingFailure();
246 // Does this extension exists?
247 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
248 if (loadExtension(getCurrentExtensionName(), 'register', '0.0.0', isExtensionDryRun())) {
249 // Set current extension name again
250 setCurrentExtensionName($ext_name);
252 // And run possible updates
253 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
254 $history = getExtensionVersionHistory();
255 foreach ($history as $ext_ver) {
256 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ext_ver);
257 // Load extension in update mode
258 loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun());
260 // Add update notes to our output
261 addExtensionNotes($ext_ver);
264 // Does this extension depends on an outstanding update of another update?
265 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
267 $ext_update = getExtensionUpdateDependenciesIterator();
269 // Increment here to avoid endless loop
270 incrementExtensionUpdateIterator();
272 // Check if extension is not installed and not already in registration procedure and if loading it wents finally fine...
273 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isExtensionRegistrationRunning(' . $ext_update . ')=' . intval(isExtensionRegistrationRunning($ext_update)));
274 if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
275 // Set current extension name again
276 setCurrentExtensionName($ext_name);
278 // If versions mismatch update extension first
280 if (isExtensionInstalled($ext_update)) {
281 // Get version only if installed
282 $ext_ver = getExtensionVersion($ext_update);
285 // Extension version set? If empty the extension is not registered
286 if (empty($ext_ver)) {
287 // Extension not registered so far so first load task's id...
288 $taskId = determineExtensionTaskId($ext_update);
292 // Try to register the extension
293 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',taskId=' . $taskId . ',isExtensionDryRun()=' . isExtensionDryRun());
294 $processResult = registerExtension($ext_update, $taskId, isExtensionDryRun(), true);
296 // Reset extension name
297 setCurrentExtensionName($ext_name);
298 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',processResult=' . intval($processResult));
300 } elseif ($ext_ver != getCurrentExtensionVersion()) {
301 // Ok, update this extension now
302 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
303 $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
304 $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
305 updateExtension($ext_update, $ext_ver, isExtensionDryRun());
306 setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
307 setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
308 unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
309 unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
310 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
313 $processResult = true;
315 // Nothing to register / update before...
316 $processResult = true;
319 // Required file for update does not exists!
320 $processResult = true;
321 // But this is fine for the first time...
324 // Restore the current extension name
325 setCurrentExtensionName($ext_name);
328 // Is there no update?
329 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
330 // Then test is passed!
331 $processResult = true;
334 // Switch back to register mode
335 setExtensionMode('register');
337 // Remains true if extension registration reports no failures
338 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
339 $processResult = (($processResult === true) && (isExtensionReportingFailure() === false));
340 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
342 // Does everthing before wents ok?
343 if ($processResult === true) {
344 // "Dry-run-mode" activated?
345 if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
346 // Init SQLs and transfer ext->generic
347 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
349 setSqlsArray(getExtensionSqls());
351 // Run installation pre-installation filters
352 runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
354 // Register extension
355 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
356 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
358 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
359 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
361 getCurrentExtensionName(),
362 getThisExtensionAlwaysActive(),
363 getCurrentExtensionVersion(),
365 ), __FUNCTION__, __LINE__);
368 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
369 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`) VALUES ('%s','%s','%s')",
371 getCurrentExtensionName(),
372 getThisExtensionAlwaysActive(),
373 getCurrentExtensionVersion()
374 ), __FUNCTION__, __LINE__);
377 // Use the insert id as extension id and cache it for early usage
378 $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
379 $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
381 // Mark it as installed
382 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
384 // Remove cache file(s) if extension is active
385 runFilterChain('post_extension_installed', array(
386 'pool' => 'extension',
387 'ext_name' => getCurrentExtensionName(),
391 // Re-init queries and notes
392 initExtensionSqls(true);
393 initExtensionNotes(true);
395 // In normal mode return a true on success
397 } elseif (isExtensionDryRun() === true) {
398 // In "dry-run" mode do always return a true
401 // Extension has been removed for updates, so all is fine!
405 // No, an error occurs while registering extension :-(
406 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
409 } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
410 // Remove task from system when id and extension's name is valid
411 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
412 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
413 array(bigintval($taskId)), __FUNCTION__, __LINE__);
416 // Return status code
417 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',processResult=' . intval($processResult) . ' - EXIT!');
421 // Run SQL queries for given extension id
422 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
423 function doExtensionSqls ($ext_id, $load_mode) {
424 // This shall never do a non-admin user!
429 // Get extension's name
430 $ext_name = getExtensionName($ext_id);
432 // Set current SQL name
433 setCurrentExtensionName($ext_name);
435 // Init EXT_UPDATE_DEPENDS
436 if (!isExtensionUpdateDependenciesInitialized()) {
438 initExtensionUpdateDependencies();
442 initExtensionSqls(true);
444 // By default no SQL has been executed
447 // Load extension in detected mode
448 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name[' . $ext_id . ']=' . getCurrentExtensionName() . ',load_mode=' . $load_mode);
449 loadExtension(getCurrentExtensionName(), $load_mode, '0.0.0', false);
453 setSqlsArray(getExtensionSqls());
456 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls());
458 // Do we have entries?
460 // Run SQL commands...
461 runFilterChain('run_sqls');
464 // Run any filters depending on the action here
465 runFilterChain('extension_' . $load_mode);
467 // Remove cache file(s) if extension is active
468 if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED())) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
470 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
473 // Is this the sql_patches?
474 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $ext_id . ',currName=' . getCurrentExtensionName() . ',loadMode=' . $load_mode);
475 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
476 // Then redirect to logout
477 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': LOAD!');
478 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
482 // Check wether the given extension is installed
483 function isExtensionInstalled ($ext_name) {
484 // We don't like empty extension names here
485 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
486 if (empty($ext_name)) {
487 // Please fix them all
488 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty.');
491 // By default non is installed
492 $isInstalled = false;
494 // Check if there is a cache entry
495 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
496 // Use cache built from below queries
497 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
498 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
499 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
501 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - FOUND!');
505 incrementStatsEntry('cache_hits');
506 } elseif ((isInstallationPhase())) {
507 // Extensions are all inactive/not installed during installation
508 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - installion phase');
511 $ext_id = getExtensionId($ext_name);
513 // Do we have a record?
514 $isInstalled = ($ext_id > 0);
517 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_id=' . $ext_id . ',isInstalled=' . intval($isInstalled));
519 // Is it installed, then cache the entry
520 if ($isInstalled === true) {
521 // Dummy call (get is okay here)
522 getExtensionId($ext_name, true);
525 // Remember the status
526 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
530 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isInstalled=' . intval($isInstalled) . ' - EXIT!');
534 // Check if given extension is active
535 function isExtensionActive ($ext_name) {
536 if (isInstallationPhase()) {
537 // Extensions are all inactive during installation
539 } elseif (empty($ext_name)) {
540 // Empty extension names must befixed
541 debug_report_bug(__FUNCTION__, __LINE__, 'Empty extension name provided.');
542 } elseif (!isExtensionInstalled($ext_name)) {
543 // Not installed extensions are always inactive
547 // Not active is the default
548 $data['ext_active'] = 'N';
551 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
553 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE! ext_name=' . $ext_name);
554 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
557 incrementStatsEntry('cache_hits');
558 } elseif (isExtensionLoaded($ext_name)) {
559 // @TODO Extension is loaded, what next?
560 debug_report_bug(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
561 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
562 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DB! ext_name=' . $ext_name);
563 // Load from database
564 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
565 array($ext_name), __FUNCTION__, __LINE__);
568 if (SQL_NUMROWS($result) == 1) {
570 $data = SQL_FETCHARRAY($result);
574 SQL_FREERESULT($result);
577 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . '[DB]: ' . $data['ext_active']);
578 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
580 // Extension not active!
581 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': Not active!');
582 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
586 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',active=' . $data['ext_active']);
588 // Is this extension activated? (For admins we always have active extensions...)
589 return ($data['ext_active'] == 'Y');
592 // Get version from extensions
593 function getExtensionVersion ($ext_name, $force = false) {
594 // By default no extension is found
595 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
596 $data['ext_version'] = 'false';
598 // Empty extension name should be fixed!
599 if (empty($ext_name)) {
600 // Please report this bug!
601 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty which is not allowed here.');
604 // Extensions are all inactive during installation
605 if (isInstallationPhase()) {
609 // Is the cache written?
610 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - Checking cache ...');
611 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
612 // Load data from cache
613 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
614 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
617 incrementStatsEntry('cache_hits');
618 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (!isHtmlOutputMode())) {
619 // Load from database
620 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
621 array($ext_name), __FUNCTION__, __LINE__);
622 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': DB - '.SQL_NUMROWS($result).'');
624 // Is the extension there?
625 if (SQL_NUMROWS($result) == 1) {
627 $data = SQL_FETCHARRAY($result);
630 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
631 } elseif (isDebugModeEnabled()) {
632 // Not found, may happen while an extension is uninstalled
633 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot find extension %s in database!", $ext_name));
637 SQL_FREERESULT($result);
640 // Extension version should not be invalid
641 if (($data['ext_version'] == 'false') && ($force === false)) {
642 // Please report this trouble
643 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> has empty version!", $ext_name));
647 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_version=' . $data['ext_version']);
648 return $data['ext_version'];
651 // Updates a given extension with current extension version to latest version
652 function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependencies = false) {
653 // Only admins are allowed to update extensions
654 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
655 if ((!isAdmin()) || (empty($ext_name))) {
656 // Called as non-admin or empty extension
657 debug_report_bug(__FUNCTION__, __LINE__, 'Called as non-admin (isAdmin()=' . intval(isAdmin()) . '), or empty extension name. ext_name=' . $ext_name);
660 // Set current SQL name
661 setCurrentExtensionName($ext_name);
663 // Is this extension update already running?
664 if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($dry_run === false)) {
665 // This is fine but needs logging ATM
666 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
667 ///* BUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, please investigate!');
673 initExtensionNotes();
674 initIncludePool('extension');
676 // Load extension in test mode
677 loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
679 // Save version history
680 $history = getExtensionVersionHistory();
682 // Remove old SQLs array to prevent possible bugs
685 // Check if version is updated
686 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, getCurrentExtensionName() . '/' . $ext_name . ':' . getThisExtensionVersion() . '/' . $ext_ver . '/' . intval(is_array($history)));
687 if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
688 // Search for starting point (-1 for making 0.0 -> 0.0.0 switch work)
690 if ($ext_ver != '0.0') {
691 $start = array_search($ext_ver, $history);
694 // And load SQL queries in order of version history
695 for ($idx = ($start + 1); $idx < count($history); $idx++) {
696 // Set extension version
697 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
700 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
703 $depencies = getExtensionUpdateDependencies();
706 if (count($depencies) > 0) {
707 // Apply all extension depencies
708 foreach ($depencies as $ext_depend) {
709 // Did we already update/register this?
710 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
712 setCurrentExtensionName($ext_depend);
714 // Mark it as already updated before we update it
715 $GLOBALS['ext_updated'][$ext_depend] = true;
717 // Is the extension there?
718 if (isExtensionInstalled($ext_depend)) {
719 // Update another extension first!
720 $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun(), true);
722 // Register new extension
723 $processResult = registerExtension($ext_depend, 0, isExtensionDryRun());
729 setCurrentExtensionName($ext_name);
731 // Set extension version here
732 setCurrentExtensionVersion($ext_ver);
736 addExtensionNotes($history[$idx]);
739 // In real-mode execute any existing includes
740 if (isExtensionDryRun() === false) {
741 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
742 runFilterChain('load_includes', 'extension');
743 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
744 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
749 setSqlsArray(getExtensionSqls());
752 runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
754 if (isExtensionDryRun() === false) {
755 // Run filters on success extension update
756 runFilterChain('extension_update', getCurrentExtensionName());
760 //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!');
763 // Output verbose SQL table for extension
764 function addExtensionVerboseSqlTable ($title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}') {
768 debug_report_bug(__FUNCTION__, __LINE__, 'title is empty.');
774 // Do we have queries?
775 if (isVerboseSqlEnabled()) {
776 // Do we have entries?
777 if (countExtensionSqls() > 0) {
781 foreach (getExtensionSqls() as $sqls) {
782 // New array format is recursive
783 foreach ($sqls as $sql) {
787 // Output command if set
789 // Prepare output for template
792 'sql' => str_replace('{', '{', str_replace('}', '}', encodeEntities($sql)))
796 $OUT .= loadTemplate('admin_extension_sql_row', true, $content);
804 // Prepare content for template
810 // Load main template
811 $OUT = loadTemplate('admin_extension_sql_table', true, $content);
813 // No addional SQL commands to run
814 $OUT = displayMessage('{--ADMIN_NO_ADDITIONAL_SQLS--}', true);
822 // Get extension name from id
823 function getExtensionName ($ext_id) {
824 // Init extension name
825 $data['ext_name'] = '';
828 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
830 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
833 incrementStatsEntry('cache_hits');
834 } elseif (!isExtensionActive('cache')) {
835 // Load from database
836 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
837 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
839 // Is the entry there?
840 if (SQL_NUMROWS($result) == 1) {
841 // Get the extension's name from database
842 $data = SQL_FETCHARRAY($result);
846 SQL_FREERESULT($result);
849 // Did we find some extension?
850 if (empty($data['ext_name'])) {
851 // We should fix these all!
852 debug_report_bug(__FUNCTION__, __LINE__, 'ext_name is empty. ext_id=' . $ext_id);
855 // Return the extension name
856 return $data['ext_name'];
859 // Get extension id from name
860 function getExtensionId ($ext_name) {
862 $data['ext_id'] = '0';
865 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
867 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
870 incrementStatsEntry('cache_hits');
872 // Load from database
873 $result = SQL_QUERY_ESC("SELECT `id` AS `ext_id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
874 array($ext_name), __FUNCTION__, __LINE__);
876 // Is the entry there?
877 if (SQL_NUMROWS($result) == 1) {
878 // Get the extension's id from database
879 $data = SQL_FETCHARRAY($result);
883 SQL_FREERESULT($result);
886 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
890 return $data['ext_id'];
893 // Determines wether the given extension name is valid
894 function isExtensionNameValid ($ext_name) {
896 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
897 // Generate include file name
898 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
900 // Is there a file in inc/extensions/ ?
901 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
905 return $GLOBALS['ext_name_valid'][$ext_name];
908 // Determines wether the given extension id is valid
909 function isExtensionIdValid ($ext_id) {
910 // Default is nothing valid
913 // Check in cache then in database
914 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
919 incrementStatsEntry('cache_hits');
922 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
929 // Activate given extension
930 function doActivateExtension ($ext_name) {
931 // Is the extension installed?
932 if (!isExtensionInstalled($ext_name)) {
933 // Non-installed extensions cannot be activated
934 debug_report_bug(__FUNCTION__, __LINE__, 'Tried to activate non-installed extension ' . $ext_name);
937 // Activate the extension
938 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
939 array($ext_name), __FUNCTION__, __LINE__);
941 // Then run all queries
942 doExtensionSqls(getExtensionId($ext_name), 'activate');
945 // Deactivate given extension
946 function doDeactivateExtension ($ext_name) {
947 // Is the extension installed?
948 if (!isExtensionInstalled($ext_name)) {
949 // Non-installed extensions cannot be activated
950 debug_report_bug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name . ',getExtensionMode()=' . getExtensionMode());
953 // Activate the extension
954 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
955 array($ext_name), __FUNCTION__, __LINE__);
957 // Then run all queries
958 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
960 // Create new task (we ignore the task id here)
961 createExtensionDeactivationTask($ext_name);
964 sendAdminNotification(
965 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
966 'admin_extension_deactivated',
967 array('ext_name' => $ext_name)
971 // Checks wether the extension is older than given
972 function isExtensionOlder ($ext_name, $ext_ver) {
973 // Get current extension version
974 $currVersion = getExtensionVersion($ext_name);
976 // Remove all dots from both versions
977 $currVersion = str_replace('.', '', $currVersion);
978 $ext_ver = str_replace('.', '', $ext_ver);
980 // Now compare both and return the result
981 return ($currVersion < $ext_ver);
984 // Creates a new task for updated extension
985 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
986 // Create subject line
987 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
990 $taskId = determineTaskIdBySubject($subject);
992 // Is the extension there?
993 if (isExtensionInstalled($ext_name)) {
994 // Check if task is not there
995 if ($taskId == '0') {
996 // Create extension update-task
997 $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
1000 // Extension not there! :-(
1001 debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1008 // Creates a new task for newly installed extension
1009 function createNewExtensionTask ($ext_name) {
1010 // Generate subject line
1011 $subject = sprintf("[%s:]", $ext_name);
1014 $taskId = determineTaskIdBySubject($subject);
1016 // Not installed and do we have created a task for the admin?
1017 if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1018 // Set default message if ext-foo is missing
1019 $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
1022 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1028 // Load text for task if found
1029 if (isFileReadable($FQFN)) {
1030 // Load extension's description template (but do not compile the code)
1031 $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1033 // Write this in debug.log as well
1034 logDebugMessage(__FUNCTION__, __LINE__, $message);
1037 // Task not created so it's a brand-new extension which we need to register and create a task for!
1038 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1045 // Creates a task for automatically deactivated (deprecated) extension
1046 function createExtensionDeactivationTask ($ext_name) {
1047 // Create subject line
1048 $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1051 $taskId = determineTaskIdBySubject($subject);
1053 // Not installed and do we have created a task for the admin?
1054 if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1055 // Task not created so add it
1056 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1063 // Determines the task id for given extension
1064 function determineExtensionTaskId ($ext_name) {
1065 // Default is not found
1066 $data['task_id'] = '0';
1068 // Search for extension task's id
1069 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1070 array($ext_name), __FUNCTION__, __LINE__);
1073 if (SQL_NUMROWS($result) == 1) {
1074 // Task found so load task's id and register extension...
1075 $data = SQL_FETCHARRAY($result);
1079 SQL_FREERESULT($result);
1082 return $data['task_id'];
1085 // Determines the task id for given subject
1086 function determineTaskIdBySubject ($subject) {
1087 // Default is not found
1088 $data['task_id'] = '0';
1090 // Search for task id
1091 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1092 array($subject), __FUNCTION__, __LINE__);
1095 if (SQL_NUMROWS($result) == 1) {
1096 // Task found so load task's id and register extension...
1097 $data = SQL_FETCHARRAY($result);
1101 SQL_FREERESULT($result);
1104 return $data['task_id'];
1107 // Add updates notes for given version
1108 function addExtensionNotes ($ext_ver) {
1109 // Init notes/content
1113 // Is do we have verbose output enabled?
1114 if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1115 // Update notes found?
1116 if ((isExtensionUpdateNoteSet($ext_ver)) && ($ext_ver != '0.0.0')) {
1117 // Update notes found
1120 'notes' => getExtensionUpdateNotes($ext_ver)
1124 setExtensionUpdateNotes('', $ext_ver);
1125 } elseif ($ext_ver == '0.0.0') {
1126 // Is the extension productive?
1127 if (isExtensionProductive(getCurrentExtensionName())) {
1131 'notes' => '{--INITIAL_RELEASE--}'
1137 'notes' => '{--DEVELOPER_RELEASE--}'
1141 // No update notes found
1144 'notes' => '{--NO_UPDATE_NOTES--}'
1149 $out = loadTemplate('admin_extension_notes', true, $content);
1153 appendExtensionNotes($out);
1156 // Getter for CSS files array
1157 function getExtensionCssFiles () {
1158 // By default no additional CSS files are found
1159 $cssFiles = array();
1161 // Is the array there?
1162 if (isset($GLOBALS['css_files'])) {
1164 $cssFiles = $GLOBALS['css_files'];
1171 // Init CSS files array
1172 function initExtensionCssFiles () {
1174 $GLOBALS['css_files'] = array();
1178 function addExtensionCssFile ($file) {
1179 // Is the array there?
1180 if (!isset($GLOBALS['css_files'])) {
1181 // Then auto-init them
1182 initExtensionCssFiles();
1186 $GLOBALS['css_files'][] = $file;
1189 // Setter for EXT_ALWAYS_ACTIVE flag
1190 function setExtensionAlwaysActive ($active) {
1191 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1194 // Getter for EXT_ALWAYS_ACTIVE flag
1195 function getThisExtensionAlwaysActive () {
1196 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1199 // Checks wether the current extension is always active
1200 function isThisExtensionAlwaysActive () {
1201 return (getThisExtensionAlwaysActive() == 'Y');
1204 // Setter for EXT_VERSION flag
1205 function setThisExtensionVersion ($ext_version) {
1206 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1209 // Getter for EXT_VERSION flag
1210 function getThisExtensionVersion () {
1211 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1214 // Setter for EXT_DEPRECATED flag
1215 function setExtensionDeprecated ($deprecated) {
1216 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1219 // Getter for EXT_DEPRECATED flag
1220 function isExtensionDeprecated () {
1221 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1224 // Setter for EXT_UPDATE_DEPENDS flag
1225 function addExtensionDependency ($updateDepends) {
1226 // Is the update depency empty? (NEED TO BE FIXED!)
1227 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - ENTERED!');
1228 if (empty($updateDepends)) {
1229 // Please report this bug!
1230 debug_report_bug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1233 // Is it not yet added?
1234 if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1236 * Double-adding happens when the extension and an update of the same
1237 * extension requires the same other extension again.
1239 logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
1243 // Add it to the list of extension update depencies map
1244 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1246 // Remember it in the list of running updates
1247 $GLOBALS['ext_running_updates'][getCurrentExtensionName()][] = $updateDepends;
1248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - EXIT!');
1251 // Getter for running updates
1252 function getExtensionUpdatesRunning () {
1253 return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1256 // Checks wether the given extension registration is in progress
1257 function isExtensionRegistrationRunning ($ext_name) {
1259 $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1262 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1266 // Init EXT_UPDATE_DEPENDS flag
1267 function initExtensionUpdateDependencies () {
1268 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1270 // Init update depency map automatically if not found
1271 if (isExtensionUpdateDependenciesInitialized()) {
1272 // We need these bug reports as well...
1273 debug_report_bug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1276 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1278 // Init running updates array
1279 initExtensionRuningUpdates();
1281 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1284 // Adds an extension as "registration in progress"
1285 function addExtensionRunningRegistration ($ext_name) {
1287 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1288 if (isExtensionRegistrationRunning($ext_name)) {
1289 // This is really bad and should not be quietly ignored
1290 debug_report_bug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1294 $GLOBALS['ext_register_running'][] = $ext_name;
1295 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1298 // Checks wether EXT_UPDATE_DEPENDS is initialized
1299 function isExtensionUpdateDependenciesInitialized () {
1300 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1301 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1304 // Checks wether an update is already running for given extension
1305 function isExtensionUpdateRunning ($ext_name, $ignoreDependencies = false) {
1306 // Current and given extensions means whole array
1307 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
1308 if ($ext_name == getCurrentExtensionName()) {
1309 // Default is not found
1312 // Walk through whole array
1313 foreach ($GLOBALS['ext_running_updates'] as $ext1=>$depends) {
1315 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',depends=' . print_r($depends, true));
1316 if (($ext1 == $ext_name) || ((in_array($ext_name, $depends)) && ($ignoreDependencies === false))) {
1319 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=true - FOUND!');
1325 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - ALT-EXIT!');
1330 $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1333 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - EXIT!');
1337 // Initializes the list of running updates
1338 function initExtensionRuningUpdates () {
1339 // Auto-init ext_running_updates
1340 if (!isset($GLOBALS['ext_running_updates'])) {
1341 $GLOBALS['ext_running_updates'] = array();
1342 $GLOBALS['ext_register_running'] = array();
1346 // Getter for EXT_UPDATE_DEPENDS flag
1347 function getExtensionUpdateDependencies () {
1348 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1349 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1352 // Getter for next iterator depency
1353 function getExtensionUpdateDependenciesIterator () {
1354 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1355 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1358 // Counter for extension update depencies
1359 function countExtensionUpdateDependencies () {
1360 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1361 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1364 // Removes given extension from update denpency list
1365 function removeExtensionDependency ($ext_name) {
1367 $key = array_search($ext_name, getExtensionUpdateDependencies());
1370 if ($key !== false) {
1372 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1374 // And sort the array
1375 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1379 // Init iterator for update depencies
1380 function initExtensionUpdateIterator () {
1381 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1382 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1385 // Getter for depency iterator
1386 function getExtensionUpdateIterator () {
1387 // Auto-init iterator
1388 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1391 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1392 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1395 // Increments the update iterator
1396 function incrementExtensionUpdateIterator () {
1397 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1398 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1401 // Setter for EXT_REPORTS_FAILURE flag
1402 function enableExtensionReportingFailure ($reportsFailure = false) {
1403 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1406 // Getter for EXT_REPORTS_FAILURE flag
1407 function isExtensionReportingFailure () {
1408 return $GLOBALS['ext_reports_failure'];
1411 // Setter for EXT_VER_HISTORY flag
1412 function setExtensionVersionHistory ($versionHistory) {
1413 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1416 // Getter for EXT_VER_HISTORY array
1417 function getExtensionVersionHistory () {
1418 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1421 // Setter for EXT_UPDATE_NOTES
1422 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1424 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . '/' . getCurrentExtensionVersion() . ',updateNotes()=' . strlen($updateNotes));
1425 if (empty($ext_ver)) {
1426 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1428 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1432 // Getter for EXT_UPDATE_NOTES
1433 function getExtensionUpdateNotes ($ext_ver) {
1434 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1437 // Checks if ext_update_notes is set
1438 function isExtensionUpdateNoteSet ($ext_ver) {
1439 return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1442 // Init extension notice
1443 function initExtensionNotes ($force = false) {
1444 // Is it already initialized?
1445 if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1446 // This is mostly not wanted, so please report it
1447 debug_report_bug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1450 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1451 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1454 // Append extension notice
1455 function appendExtensionNotes ($notes) {
1456 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes()=' . strlen($notes));
1457 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1460 // Getter for extension notes
1461 function getExtensionNotes () {
1462 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1465 // Setter for current extension name
1466 function setCurrentExtensionName ($ext_name) {
1467 $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1470 // Getter for current extension name
1471 function getCurrentExtensionName () {
1472 if (!isset($GLOBALS['curr_extension_name'])) {
1474 debug_report_bug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1478 return $GLOBALS['curr_extension_name'];
1481 // Init SQLs array for current extension
1482 function initExtensionSqls ($force = false) {
1483 // Auto-init the array or if forced
1484 if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1486 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1488 // Initialize the generic array
1493 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1494 function addExtensionSql ($sql) {
1496 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1497 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1500 // Getter for SQLs array for current extension
1501 function getExtensionSqls () {
1502 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1503 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1504 // Not found, should not happen
1505 debug_report_bug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1506 getCurrentExtensionName()
1511 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1514 // Count SQLs for current extension
1515 function countExtensionSqls () {
1516 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1517 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1518 // Not found, should not happen
1519 debug_report_bug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1520 getCurrentExtensionName()
1525 return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1528 // Removes SQLs for current extension
1529 function unsetExtensionSqls () {
1530 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1533 // Auto-initializes the removal list
1534 function initExtensionRemovalList () {
1535 // Is the remove list there?
1536 if (!isset($GLOBALS['ext_update_remove'])) {
1538 $GLOBALS['ext_update_remove'] = array();
1542 // Checks wether the current extension is on the removal list
1543 function isExtensionOnRemovalList () {
1544 // Init removal list
1545 initExtensionRemovalList();
1548 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1551 // Adds the current extension to the removal list
1552 function addCurrentExtensionToRemovalList () {
1554 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1557 // Getter for removal list
1558 function getExtensionRemovalList () {
1559 // Return the removal list
1560 return $GLOBALS['ext_update_remove'];
1563 // Redirects if the provided extension is not installed
1564 function redirectOnUninstalledExtension ($ext_name) {
1565 // So is the extension there?
1566 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1567 // Redirect to index
1568 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1572 // Filter for initialization of all extensions by loading them in 'init' mode
1573 function FILTER_INIT_EXTENSIONS () {
1574 // Do we have some entries?
1575 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTRY!');
1576 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1577 // Load all found extensions if found
1578 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1579 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1581 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
1582 loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1583 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
1585 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1587 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1590 // Setter for extension mode
1591 function setExtensionMode ($ext_mode) {
1592 $GLOBALS['ext_mode'] = (string) $ext_mode;
1595 // Getter for extension mode
1596 function getExtensionMode () {
1597 return $GLOBALS['ext_mode'];
1600 // Setter for dry-run
1601 function enableExtensionDryRun ($dry_run = true) {
1602 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry_run='.intval($dry_run));
1603 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1606 // Getter for dry-run
1607 function isExtensionDryRun () {
1608 return $GLOBALS['ext_dry_run'];
1611 // Setter for current extension version
1612 function setCurrentExtensionVersion ($ext_ver) {
1613 // ext_ver should never be empty in other modes than 'test'
1614 if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1615 // Please report all these messages
1616 debug_report_bug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1620 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1621 $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1624 // Getter for current extension version
1625 function getCurrentExtensionVersion () {
1626 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1627 return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1630 // Remove the extension from cache array
1631 function removeExtensionFromArray () {
1632 // "Cache" this name
1633 $ext_name = getCurrentExtensionName();
1635 // Now loop through the whole cache
1636 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1637 // Is it an element?
1638 if (isset($cacheArray[$ext_name])) {
1640 unset($cacheArray[$ext_name]);
1641 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1644 $key = array_search($ext_name, $cacheArray);
1647 if ($key !== false) {
1648 // Found, so remove it
1649 unset($cacheArray[$key]);
1650 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1655 // Remove from other caches as well
1656 unset($GLOBALS['ext_is_installed'][$ext_name]);
1657 unset($GLOBALS['loaded_extension'][$ext_name]);
1660 // "Getter" for 'extension has a CSS file' (with same name, of course)
1661 function getExtensionHasCss () {
1662 // Do we have cache?
1663 if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
1664 // Construct FQFN for check
1665 $FQFN = sprintf("%stheme/%s/css/%s.css",
1668 getCurrentExtensionName()
1672 $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
1676 return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
1679 // Checks wether the given extension has a language file
1680 function ifExtensionHasLanguageFile ($ext_name) {
1681 // Do we have cache?
1682 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1684 incrementStatsEntry('cache_hits');
1686 // Determine it and put it in cache
1687 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
1691 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1694 // Load current extension's include file
1695 function loadCurrentExtensionInclude () {
1697 if (!isExtensionIncludeReadable()) {
1699 debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1702 // Generate INC name
1703 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1709 // Checks wether an extension is readable
1710 function isExtensionIncludeReadable ($ext_name = '') {
1711 // If empty, use current
1712 if (empty($ext_name)) {
1713 $ext_name = getCurrentExtensionName();
1717 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1718 // Generate INC name
1719 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1722 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1726 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1727 return $GLOBALS['ext_inc_readable'][$ext_name];
1730 // Checks if an extension's function file is readable
1731 function isExtensionFunctionFileReadable ($ext_name) {
1733 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1734 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1735 // Just count cache hits
1736 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1737 incrementStatsEntry('cache_hits');
1739 // Construct IFN for functions file
1740 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1742 // Is this include there?
1743 $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
1745 // And put in cache, converted
1746 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
1750 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1751 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1754 // Adds a CREATE TABLE statement if the requested table is not there
1755 function addCreateTableSql ($tableName, $sql, $comment) {
1756 // Is the table not there?
1757 if (!isSqlTableCreated($tableName)) {
1758 // Is not found, so add it
1759 addExtensionSql('CREATE TABLE
1760 `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
1761 ENGINE = {?_TABLE_TYPE?}
1763 COLLATE utf8_general_ci
1764 COMMENT ' . "'" . $comment . "'");
1766 // Is already there, which should not happen
1767 debug_report_bug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1771 // Adds a DROP TABLE statement if the requested tabled is there
1772 function addDropTableSql ($tableName) {
1773 // Is the table there?
1774 if (isSqlTableCreated($tableName)) {
1775 // Then add it, non-existing tables can be ignored because it will
1776 // happen with every newly installed extension.
1777 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1780 $GLOBALS['isSqlTableCreated'][$tableName] = false;
1784 // Adds an admin menu to the SQL queue of the menu entry is not found
1785 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1786 // Now check if this menu is there
1787 if (!isMenuActionValid('admin', $action, $what)) {
1789 if (is_null($what)) {
1791 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1799 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1808 // Add it to the queue
1809 addExtensionSql($sql);
1810 } elseif (isDebugModeEnabled()) {
1811 // Double menus should be located and fixed!
1812 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1816 // Adds a guest menu to the SQL queue if the menu entry is not found
1817 function addGuestMenuSql ($action, $what, $title, $sort) {
1818 // Now check if this menu is there
1819 if (!isMenuActionValid('guest', $action, $what)) {
1821 if (is_null($what)) {
1823 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1830 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1838 // Add it to the queue
1839 addExtensionSql($sql);
1840 } elseif (isDebugModeEnabled()) {
1841 // Double menus should be located and fixed!
1842 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1846 // Adds a member menu to the SQL queue if the menu entry is not found
1847 function addMemberMenuSql ($action, $what, $title, $sort) {
1848 // Now check if this menu is there
1849 if (!isMenuActionValid('member', $action, $what)) {
1851 if (is_null($what)) {
1853 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1860 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1868 // Add it to the queue
1869 addExtensionSql($sql);
1870 } elseif (isDebugModeEnabled()) {
1871 // Double menus should be located and fixed!
1872 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1876 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1877 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1878 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1879 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1881 if (is_null($what)) {
1883 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1891 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1900 // Add it to the queue
1901 addExtensionSql($sql);
1902 } elseif (isDebugModeEnabled()) {
1903 // Double menus should be located and fixed!
1904 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1908 // Add configuration entry if not found for actual extension
1909 function addConfigAddSql ($columnName, $columnSql) {
1910 // Is the column there?
1911 if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1912 // Not found, so add it
1913 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1914 } elseif (isDebugModeEnabled()) {
1916 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
1920 // Drop configuration entry if found for actual extension
1921 function addConfigDropSql ($columnName) {
1922 // Is the column there?
1923 if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1925 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
1926 } elseif (isDebugModeEnabled()) {
1927 // Add debug line, debug_report_bug() would cause some extenion updates fail
1928 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
1932 // Change configuration entry for actual extension
1933 function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
1934 // Add the SQL statement
1935 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
1938 // Enables/disables productive mode for current extension (used only while
1940 // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
1941 function enableExtensionProductive ($isProductive = true) {
1942 // Log debug message
1943 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',isProductive=', intval($isProductive));
1946 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1949 // Checks wether the extension is in productive phase. If not set, development
1950 // phase (=false) is assumed.
1951 function isExtensionProductive ($ext_name = '') {
1952 // Is the extension name empty? Then use current
1953 if (empty($ext_name)) {
1954 // Get current extension name
1955 $ext_name = getCurrentExtensionName();
1957 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
1959 // Do we have cache?
1960 if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
1961 // Load extension only if not yet loaded
1962 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
1963 // Load extension in test mode
1964 loadExtension($ext_name, 'test');
1968 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
1972 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isProductive=', intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!');
1973 return $GLOBALS[__FUNCTION__][$ext_name];
1976 // Mark extension file as loaded
1977 function markExtensionAsLoaded ($ext_name) {
1978 // Is it already loaded?
1979 if (isExtensionLoaded($ext_name)) {
1981 debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
1985 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_loaded=true');
1986 $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
1989 // Determine wether the given extension is already loaded
1990 function isExtensionLoaded ($ext_name) {
1992 return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
1995 // Mark extension's library file as loaded
1996 function markExtensionLibraryAsLoaded ($ext_name) {
1997 // Is it already loaded?
1998 if (isExtensionLibraryLoaded($ext_name)) {
2000 debug_report_bug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
2004 $GLOBALS['ext_loaded']['library'][$ext_name] = true;
2007 // Determine wether the given extension's library is already loaded
2008 function isExtensionLibraryLoaded ($ext_name) {
2010 return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));