]> git.mxchange.org Git - mailer.git/blob - inc/extensions-functions.php
Again better check
[mailer.git] / inc / extensions-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/25/2009 *
4  * ===================                          Last change: 10/25/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : extensions-functions.php                         *
8  * -------------------------------------------------------------------- *
9  * Short description : Extension management                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Erweiterungen-Management                         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
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         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_mode=' . $ext_mode . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
46         // Loading an extension in same mode, but not test/update, twice is not
47         // good, so is the extension $ext_name already loaded in mode $ext_mode?
48         if ((isset($GLOBALS['loaded_extension'][$ext_name][$ext_mode])) && (!in_array($ext_mode, array('update', 'test')))) {
49                 // If this happens twice, we need the bug report from you, except for updates/tests
50                 reportBug(__FUNCTION__, __LINE__, __FUNCTION__ . '() 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));
51         } // END - if
52
53         // Make sure this situation can only happen once
54         $GLOBALS['loaded_extension'][$ext_name][$ext_mode] = true;
55
56         // Set extension mode
57         setExtensionMode($ext_mode);
58
59         // Set current extension name
60         setCurrentExtensionName($ext_name);
61
62         // By default all extensions are in productive phase
63         enableExtensionProductive();
64
65         if (!empty($ext_ver)) {
66                 // Set current extension version
67                 setCurrentExtensionVersion($ext_ver);
68         } else {
69                 // Set it to 0.0 by default
70                 setCurrentExtensionVersion('0.0.0');
71
72                 // Is the extension installed?
73                 if ((isExtensionInstalled($ext_name)) && ($ext_mode != 'register')) {
74                         // Get extension's version
75                         setCurrentExtensionVersion(getExtensionVersion($ext_name));
76                 } // END - if
77
78                 // In all but test-mode we need these messages to debug! Please report all (together, e.g.)
79                 if (($ext_mode != 'test') && (getCurrentExtensionVersion() == '0.0.0')) {
80                         // Abort here, this must now always be set!
81                         reportBug(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0. ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', dry_run=' . intval($dry_run));
82                 } // END - if
83         }
84
85         // Set dry-run
86         enableExtensionDryRun($dry_run);
87
88         // Init array
89         initIncludePool('extension');
90
91         // Init EXT_UPDATE_DEPENDS if not yet done
92         if (!isExtensionUpdateDependenciesInitialized()) {
93                 // Init here...
94                 initExtensionUpdateDependencies();
95         } // END - if
96
97         // Init current extension name list
98         initExtensionSqls();
99
100         // Is the extension already loaded?
101         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Loading extension ' . $ext_name . ', getExtensionMode()=' . getExtensionMode() . ', getCurrentExtensionVersion()=' . getCurrentExtensionVersion());
102         if ((isExtensionLoaded($ext_name)) && (getExtensionMode() == 'init')) {
103                 // Debug message
104                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
105
106                 // Abort here
107                 return false;
108         } // END - if
109
110         // Is the extension file NOT there?
111         if (!isExtensionNameValid($ext_name)) {
112                 // Debug message
113                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable or the PHP script is deprecated.", $ext_name));
114
115                 // Abort here
116                 return false;
117         } // END - if
118
119         // Load extension's own language file if not in test mode
120         if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
121                 // Load it
122                 loadLanguageFile($ext_name);
123         } // END - if
124
125         // Do we have cache?
126         if (isExtensionFunctionFileReadable($ext_name)) {
127                 // Not yet loaded?
128                 if ((($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') || (!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name]))) && (!isExtensionLibraryLoaded($ext_name))) {
129                         // Construct IFN for functions file
130                         $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
131
132                         // Mark it as loaded
133                         markExtensionLibraryAsLoaded($ext_name);
134
135                         // Download functions file
136                         loadIncludeOnce($funcsInclude);
137                 } // END - if
138         } elseif ((!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) && (isDebugModeEnabled()) && (isHtmlOutputMode()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme') && (getExtensionMode() == 'test')) {
139                 // No functions file is not so good...
140                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
141                         $ext_name,
142                         getExtensionMode()
143                 ));
144         }
145
146         // Load extension's filter library if present
147         loadExtensionFilters($ext_name);
148
149         // Extensions are not deprecated by default
150         setExtensionDeprecated('N');
151
152         // Extensions are not always active by default
153         setExtensionAlwaysActive('N');
154
155         // Include the extension file
156         loadCurrentExtensionInclude();
157
158         // Is this extension deprecated?
159         if ((isExtensionDeprecated()) && (!in_array(getExtensionMode(), array('test', 'update', 'deactivate'))) && (isExtensionActive($ext_name))) {
160                 // Deactivate the extension
161                 doDeactivateExtension($ext_name);
162
163                 // Abort here
164                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name . ' - Extension is deprecated.');
165                 return false;
166         } // END - if
167
168         // Mark it as loaded in normal mode
169         if (getExtensionMode() == '') {
170                 // Mark it now...
171                 markExtensionAsLoaded($ext_name);
172         } // END - if
173
174         // All fine!
175         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension successfully loaded, ext_name=' . $ext_name);
176         return true;
177 }
178
179 // Registers an extension and possible update dependencies
180 function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates = false) {
181         // Set current extension name
182         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . intval($taskId) . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!');
183         setCurrentExtensionName($ext_name);
184
185         // Enable dry-run
186         enableExtensionDryRun($dry_run);
187
188         // By default all extensions are in productive phase
189         enableExtensionProductive();
190
191         // This shall never do a non-admin user or if the extension is active (already installed)
192         if (((!isAdmin()) && (!isInstallationPhase())) || (isExtensionInstalled($ext_name))) {
193                 // Abort here with 'false'
194                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ABORTED: isAdmin()=' . intval(isAdmin()) . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',isExtensionInstalled()=' . intval(isExtensionInstalled($ext_name)));
195                 return false;
196         } // END - if
197
198         // When this extension is already in registration/update phase, all is fine
199         if ((isExtensionRegistrationRunning($ext_name)) || ((isExtensionUpdateRunning($ext_name)) && ($ignoreUpdates === false))) {
200                 // Then abort here with 'true' becaus it is fine
201                 //* 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));
202                 //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!');
203                 return true;
204         } // END - if
205
206         // This registration is running
207         addExtensionRunningRegistration($ext_name);
208
209         // Init EXT_UPDATE_DEPENDS if not yet done
210         if (!isExtensionUpdateDependenciesInitialized()) {
211                 // Init here...
212                 initExtensionUpdateDependencies();
213         } // END - if
214
215         // Is the task id zero? Then we need to auto-fix it here
216         if (($taskId == '0') && (!isInstallationPhase())) {
217                 // Try to find the task
218                 $taskId = determineExtensionTaskId(getCurrentExtensionName());
219
220                 // Still zero and not in dry-run?
221                 if (($taskId == '0') && (!isExtensionDryRun())) {
222                         // Now try to create a new task
223                         $taskId = createNewExtensionTask(getCurrentExtensionName());
224
225                         // Is it still zero?
226                         if ($taskId == '0') {
227                                 // Then request a bug report
228                                 reportBug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
229                                         __FUNCTION__,
230                                         getCurrentExtensionName()
231                                 ));
232                         } // END - if
233                 } // END - if
234         } // END - if
235
236         // Init queries and notes
237         initExtensionSqls();
238         initExtensionNotes();
239
240         // Init variables
241         $ret = false;
242         $processResult = false;
243         initIncludePool('extension');
244
245         // By default we have no failures
246         enableExtensionReportingFailure();
247
248         // Does this extension exists?
249         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - CALLING loadExtension() ...');
250         if (loadExtension(getCurrentExtensionName(), 'register', '0.0.0', isExtensionDryRun())) {
251                 // Set current extension name again
252                 setCurrentExtensionName($ext_name);
253
254                 // And run possible updates
255                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
256                 $history = getExtensionVersionHistory();
257                 foreach ($history as $ext_ver) {
258                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ext_ver);
259                         // Load extension in update mode
260                         loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun());
261
262                         // Add update notes to our output
263                         addExtensionNotes($ext_ver);
264                 } // END - foreach
265
266                 // Does this extension depends on an outstanding update of another update?
267                 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
268                         // Get next update
269                         $ext_update = getExtensionUpdateDependenciesIterator();
270
271                         // Increment here to avoid endless loop
272                         incrementExtensionUpdateIterator();
273
274                         // Check if extension is not installed and not already in registration procedure and if loading it wents finally fine...
275                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isExtensionRegistrationRunning(' . $ext_update . ')=' . intval(isExtensionRegistrationRunning($ext_update)));
276                         if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
277                                 // Set current extension name again
278                                 setCurrentExtensionName($ext_name);
279
280                                 // If versions mismatch update extension first
281                                 $ext_ver = '';
282                                 if (isExtensionInstalled($ext_update)) {
283                                         // Get version only if installed
284                                         $ext_ver = getExtensionVersion($ext_update);
285                                 } // END - if
286
287                                 // Extension version set? If empty the extension is not registered
288                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - EMPTY?');
289                                 if (empty($ext_ver)) {
290                                         // Extension not registered so far so first load task's id...
291                                         $taskId = determineExtensionTaskId($ext_update);
292
293                                         // Entry found?
294                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'taskId=' . $taskId . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - CHECKING!');
295                                         if (($taskId > 0) || (isInstallationPhase())) {
296                                                 // Try to register the extension
297                                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',taskId=' . $taskId . ',isExtensionDryRun()=' . isExtensionDryRun());
298                                                 $processResult = registerExtension($ext_update, $taskId, isExtensionDryRun(), true);
299
300                                                 // Reset extension name
301                                                 setCurrentExtensionName($ext_name);
302                                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',processResult=' . intval($processResult));
303                                         } // END - if
304                                 } elseif ($ext_ver != getCurrentExtensionVersion()) {
305                                         // Ok, update this extension now
306                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
307                                         $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
308                                         $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
309                                         updateExtension($ext_update, $ext_ver, isExtensionDryRun());
310                                         setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
311                                         setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
312                                         unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
313                                         unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
314                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
315
316                                         // All okay!
317                                         $processResult = true;
318                                 } else {
319                                         // Nothing to register / update before...
320                                         $processResult = true;
321                                 }
322                         } else {
323                                 // Required file for update does not exists!
324                                 $processResult = true;
325                                 // But this is fine for the first time...
326                         }
327
328                         // Restore the current extension name
329                         setCurrentExtensionName($ext_name);
330                 } // END - for
331
332                 // Is there no update?
333                 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
334                         // Then test is passed!
335                         $processResult = true;
336                 } // END - if
337
338                 // Switch back to register mode
339                 setExtensionMode('register');
340
341                 // Remains true if extension registration reports no failures
342                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
343                 $processResult = (($processResult === true) && (isExtensionReportingFailure() === false));
344                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
345
346                 // Does everthing before wents ok?
347                 if ($processResult === true) {
348                         // "Dry-run-mode" activated?
349                         if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
350                                 // Init SQLs and transfer ext->generic
351                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
352                                 initSqls();
353                                 setSqlsArray(getExtensionSqls());
354
355                                 // Run installation pre-installation filters
356                                 runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
357
358                                 // Register extension
359                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
360                                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
361                                         // New way, with CSS
362                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
363                                         SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
364                                                 array(
365                                                         getCurrentExtensionName(),
366                                                         getThisExtensionAlwaysActive(),
367                                                         getCurrentExtensionVersion(),
368                                                         getExtensionHasCss()
369                                                 ), __FUNCTION__, __LINE__);
370                                 } else {
371                                         // Old way, no CSS
372                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
373                                         SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`) VALUES ('%s','%s','%s')",
374                                                 array(
375                                                         getCurrentExtensionName(),
376                                                         getThisExtensionAlwaysActive(),
377                                                         getCurrentExtensionVersion()
378                                                 ), __FUNCTION__, __LINE__);
379                                 }
380
381                                 // Use the insert id as extension id and cache it for early usage
382                                 $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
383                                 $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
384
385                                 // Mark it as installed
386                                 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
387
388                                 // Remove cache file(s) if extension is active
389                                 runFilterChain('post_extension_installed', array(
390                                         'pool'     => 'extension',
391                                         'ext_name' => getCurrentExtensionName(),
392                                         'task_id'  => $taskId
393                                 ));
394
395                                 // Re-init queries and notes
396                                 initExtensionSqls(true);
397                                 initExtensionNotes(true);
398
399                                 // In normal mode return a true on success
400                                 $ret = true;
401                         } elseif (isExtensionDryRun() === true) {
402                                 // In  "dry-run" mode do always return a true
403                                 $ret = true;
404                         } else {
405                                 // Extension has been removed for updates, so all is fine!
406                                 $ret = true;
407                         }
408                 } else {
409                         // No, an error occurs while registering extension :-(
410                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
411                         $ret = false;
412                 }
413         } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
414                 // Remove task from system when id and extension's name is valid
415                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
416                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
417                         array(bigintval($taskId)), __FUNCTION__, __LINE__);
418         }
419
420         // @TODO This redirect is still needed to register sql_patches! Please try to avoid it
421         if (($ret === true) && ($dry_run === false) && ($ext_name == 'sql_patches') && (!isInstallationPhase())) {
422                 /*
423                  * This is a really dirty hack to prevent an error about a missing
424                  * configuration entry which should be there after registration of
425                  * ext-sql_patches.
426                  */
427                 redirectToRequestUri();
428         } // END - if
429
430         // Return status code
431         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',processResult=' . intval($processResult) . ',ret=' . intval($ret) . ' - EXIT!');
432         return $ret;
433 }
434
435 // Run SQL queries for given extension id
436 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
437 function doExtensionSqls ($ext_id, $load_mode) {
438         // This shall never do a non-admin user but installation phase is okay
439         if ((!isAdmin()) && (!isInstallationPhase())) {
440                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_id=' . $ext_id. ',load_mode=' . $load_mode . ',isAdmin()=' . intval(isAdmin()) . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ' - ABORT!');
441                 return false;
442         } // END - if
443
444         // Get extension's name
445         $ext_name = getExtensionName($ext_id);
446
447         // Set current SQL name
448         setCurrentExtensionName($ext_name);
449
450         // Init EXT_UPDATE_DEPENDS
451         if (!isExtensionUpdateDependenciesInitialized()) {
452                 // Init here...
453                 initExtensionUpdateDependencies();
454         } // END - if
455
456         // Init array
457         initExtensionSqls(true);
458
459         // By default no SQL has been executed
460         $sqlRan = false;
461
462         // Load extension in detected mode
463         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name[' . $ext_id . ']=' . getCurrentExtensionName() . ',load_mode=' . $load_mode);
464         loadExtension(getCurrentExtensionName(), $load_mode, '0.0.0', false);
465
466         // Init these SQLs
467         initSqls();
468         setSqlsArray(getExtensionSqls());
469
470         // Debug message
471         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls());
472
473         // Do we have entries?
474         if (isSqlsValid()) {
475                 // Run SQL commands...
476                 runFilterChain('run_sqls');
477         } // END - if
478
479         // Run any filters depending on the action here
480         runFilterChain('extension_' . $load_mode);
481
482         // Remove cache file(s) if extension is active
483         if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED()) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate')))) {
484                 // Run filters
485                 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
486         } // END - if
487
488         // Is this the sql_patches?
489         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $ext_id . ',currName=' . getCurrentExtensionName() . ',loadMode=' . $load_mode);
490         if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
491                 // Then redirect to logout
492                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': LOAD!');
493                 redirectToUrl('modules.php?module=admin&amp;logout=1&amp;' . $load_mode . '=sql_patches');
494         } // END - if
495 }
496
497 // Check whether the given extension is installed
498 function isExtensionInstalled ($ext_name) {
499         // We don't like empty extension names here
500         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
501         if (empty($ext_name)) {
502                 // Please fix them all
503                 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty.');
504         } // END - if
505
506         // By default non is installed
507         $isInstalled = false;
508
509         // Check if there is a cache entry
510         if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
511                 // Use cache built from below queries
512                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
513                 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
514         } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
515                 // Found!
516                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - FOUND!');
517                 $isInstalled = true;
518
519                 // Count cache hits
520                 incrementStatsEntry('cache_hits');
521         } elseif (isInstallationPhase()) {
522                 // Extensions are all inactive/not installed during installation
523                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - installation phase detected.');
524         } else {
525                 // Look in database
526                 $ext_id = getExtensionId($ext_name);
527
528                 // Do we have a record?
529                 $isInstalled = ($ext_id > 0);
530
531                 // Log debug message
532                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_id=' . $ext_id . ',isInstalled=' . intval($isInstalled));
533
534                 // Is it installed, then cache the entry
535                 if ($isInstalled === true) {
536                         // Dummy call (get is okay here)
537                         getExtensionId($ext_name, true);
538                 } // END - if
539
540                 // Remember the status
541                 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
542         }
543
544         // Return status
545         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isInstalled=' . intval($isInstalled) . ' - EXIT!');
546         return $isInstalled;
547 }
548
549 // Check if given extension is active
550 function isExtensionActive ($ext_name) {
551         if (isInstallationPhase()) {
552                 // Extensions are all inactive during installation
553                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extensions are always inactive while installation phase. ext_name=' . $ext_name);
554                 return false;
555         } elseif (empty($ext_name)) {
556                 // Empty extension names must befixed
557                 reportBug(__FUNCTION__, __LINE__, 'Empty extension name provided.');
558         } elseif (!isExtensionInstalled($ext_name)) {
559                 // Not installed extensions are always inactive
560                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not installed extensions are always inactive. ext_name=' . $ext_name);
561                 return false;
562         }
563
564         // Not active is the default
565         $data['ext_active'] = 'N';
566
567         // Check cache
568         if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
569                 // Load from cache
570                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE! ext_name=' . $ext_name);
571                 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
572
573                 // Count cache hits
574                 incrementStatsEntry('cache_hits');
575         } elseif (isExtensionLoaded($ext_name)) {
576                 // @TODO Extension is loaded, what next?
577                 reportBug(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
578         } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
579                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DB! ext_name=' . $ext_name);
580                 // Load from database
581                 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
582                         array($ext_name), __FUNCTION__, __LINE__);
583
584                 // Entry found?
585                 if (SQL_NUMROWS($result) == 1) {
586                         // Load entry
587                         $data = SQL_FETCHARRAY($result);
588                 } // END - if
589
590                 // Free result
591                 SQL_FREERESULT($result);
592
593                 // Write cache array
594                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . '[DB]: ' . $data['ext_active']);
595                 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
596         } else {
597                 // Extension not active!
598                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': Not active!');
599                 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
600         }
601
602         // Debug message
603         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',active=' . $data['ext_active']);
604
605         // Is this extension activated? (For admins we always have active extensions...)
606         return ($data['ext_active'] == 'Y');
607 }
608
609 // Get version from extensions
610 function getExtensionVersion ($ext_name, $force = false) {
611         // By default no extension is found
612         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
613         $data['ext_version'] = 'false';
614
615         // Empty extension name should be fixed!
616         if (empty($ext_name)) {
617                 // Please report this bug!
618                 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty which is not allowed here.');
619         } // END - if
620
621         // Extensions are all inactive during installation
622         if (isInstallationPhase()) {
623                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',force=' . intval($force) . ' - Installation phase detected, returning empty version.');
624                 return '';
625         } // END - if
626
627         // Is the cache written?
628         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - Checking cache ...');
629         if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
630                 // Load data from cache
631                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
632                 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
633
634                 // Count cache hits
635                 incrementStatsEntry('cache_hits');
636         } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (!isHtmlOutputMode())) {
637                 // Load from database
638                 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
639                         array($ext_name), __FUNCTION__, __LINE__);
640                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': DB - '.SQL_NUMROWS($result).'');
641
642                 // Is the extension there?
643                 if (SQL_NUMROWS($result) == 1) {
644                         // Load entry
645                         $data = SQL_FETCHARRAY($result);
646
647                         // Set cache
648                         $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
649                 } elseif (isDebugModeEnabled()) {
650                         // Not found, may happen while an extension is uninstalled
651                         logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot find extension %s in database!", $ext_name));
652                 }
653
654                 // Free result
655                 SQL_FREERESULT($result);
656         }
657
658         // Extension version should not be invalid
659         if (($data['ext_version'] == 'false') && ($force === false)) {
660                 // Please report this trouble
661                 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> has empty version!", $ext_name));
662         } // END - if
663
664         // Return result
665         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_version=' . $data['ext_version']);
666         return $data['ext_version'];
667 }
668
669 // Updates a given extension with current extension version to latest version
670 function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependencies = false) {
671         // Only admins are allowed to update extensions
672         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
673         if ((!isAdmin()) || (empty($ext_name))) {
674                 // Called as non-admin or empty extension
675                 reportBug(__FUNCTION__, __LINE__, 'Called as non-admin (isAdmin()=' . intval(isAdmin()) . '), or empty extension name. ext_name=' . $ext_name);
676         } // END - if
677
678         // Set current SQL name
679         setCurrentExtensionName($ext_name);
680
681         // Is this extension update already running?
682         if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($dry_run === false)) {
683                 // This is fine but needs logging ATM
684                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
685                 //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, please investigate!');
686                 return true;
687         } // END - if
688
689         // Init arrays
690         initExtensionSqls();
691         initExtensionNotes();
692         initIncludePool('extension');
693
694         // Load extension in test mode
695         loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
696
697         // Save version history
698         $history = getExtensionVersionHistory();
699
700         // Remove old SQLs array to prevent possible bugs
701         initExtensionSqls();
702
703         // Check if version is updated
704         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, getCurrentExtensionName() . '/' . $ext_name . ':' . getThisExtensionVersion() . '/' . $ext_ver . '/' . intval(is_array($history)));
705         if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
706                 // Search for starting point (-1 for making 0.0 -> 0.0.0 switch work)
707                 $start = -1;
708                 if ($ext_ver != '0.0') {
709                         $start = array_search($ext_ver, $history);
710                 } // END - if
711
712                 // And load SQL queries in order of version history
713                 for ($idx = ($start + 1); $idx < count($history); $idx++) {
714                         // Set extension version
715                         $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
716
717                         // Load again...
718                         loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
719
720                         // Get all depencies
721                         $depencies = getExtensionUpdateDependencies();
722
723                         // Nothing to apply?
724                         if (count($depencies) > 0) {
725                                 // Apply all extension depencies
726                                 foreach ($depencies as $ext_depend) {
727                                         // Did we already update/register this?
728                                         if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
729                                                 // Set it as current
730                                                 setCurrentExtensionName($ext_depend);
731
732                                                 // Mark it as already updated before we update it
733                                                 $GLOBALS['ext_updated'][$ext_depend] = true;
734
735                                                 // Is the extension there?
736                                                 if (isExtensionInstalled($ext_depend)) {
737                                                         // Update another extension first!
738                                                         $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun(), true);
739                                                 } else {
740                                                         // Register new extension
741                                                         $processResult = registerExtension($ext_depend, 0, isExtensionDryRun());
742                                                 }
743                                         } // END - if
744                                 } // END - foreach
745
746                                 // Set name back
747                                 setCurrentExtensionName($ext_name);
748
749                                 // Set extension version here
750                                 setCurrentExtensionVersion($ext_ver);
751                         } // END - if
752
753                         // Add notes
754                         addExtensionNotes($history[$idx]);
755                 } // END - for
756
757                 // In real-mode execute any existing includes
758                 if (isExtensionDryRun() === false) {
759                         $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
760                         runFilterChain('load_includes', 'extension');
761                         setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
762                         unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
763                 } // END - if
764
765                 // Init these SQLs
766                 initSqls();
767                 setSqlsArray(getExtensionSqls());
768
769                 // Run SQLs
770                 runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
771
772                 if (isExtensionDryRun() === false) {
773                         // Run filters on success extension update
774                         runFilterChain('extension_update', getCurrentExtensionName());
775                 } // END - if
776         } // END - if
777
778         //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!');
779 }
780
781 // Output verbose SQL table for extension
782 function addExtensionVerboseSqlTable ($title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}') {
783         // Empty title?
784         if (empty($title)) {
785                 // Then abort here
786                 reportBug(__FUNCTION__, __LINE__, 'title is empty.');
787         } // END - if
788
789         // Init variables
790         $OUT = '';
791
792         // Do we have queries?
793         if (isVerboseSqlEnabled()) {
794                 // Do we have entries?
795                 if (countExtensionSqls() > 0) {
796                         // Init counter
797                         $idx = 0;
798                         // Get all SQLs
799                         foreach (getExtensionSqls() as $sqls) {
800                                 // New array format is recursive
801                                 foreach ($sqls as $sql) {
802                                         // Trim out spaces
803                                         $sql = trim($sql);
804
805                                         // Output command if set
806                                         if (!empty($sql)) {
807                                                 // Prepare output for template
808                                                 $content = array(
809                                                         'i'   => ($idx + 1),
810                                                         'sql' => str_replace(array('{', '}'), array('&#123;', '&#125;'), encodeEntities($sql))
811                                                 );
812
813                                                 // Load row template
814                                                 $OUT .= loadTemplate('admin_extension_sql_row', true, $content);
815
816                                                 // Count up
817                                                 $idx++;
818                                         } // END - if
819                                 } // END - foreach
820                         } // END - foreach
821
822                         // Prepare content for template
823                         $content = array(
824                                 'title'  => $title,
825                                 'rows'   => $OUT
826                         );
827
828                         // Load main template
829                         $OUT = loadTemplate('admin_extension_sql_table', true, $content);
830                 } else {
831                         // No addional SQL commands to run
832                         $OUT = displayMessage('{--ADMIN_EXTENSION_VERBOSE_SQLS_404--}', true);
833                 }
834         } // END - if
835
836         // Return output
837         return $OUT;
838 }
839
840 // Get extension name from id
841 function getExtensionName ($ext_id) {
842         // Init extension name
843         $data['ext_name'] = '';
844
845         // Is cache there?
846         if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
847                 // Load from cache
848                 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
849
850                 // Count cache hits
851                 incrementStatsEntry('cache_hits');
852         } elseif (!isExtensionActive('cache')) {
853                 // Load from database
854                 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
855                         array(bigintval($ext_id)), __FUNCTION__, __LINE__);
856
857                 // Is the entry there?
858                 if (SQL_NUMROWS($result) == 1) {
859                         // Get the extension's name from database
860                         $data = SQL_FETCHARRAY($result);
861                 } // END - if
862
863                 // Free result
864                 SQL_FREERESULT($result);
865         }
866
867         // Did we find some extension?
868         if (empty($data['ext_name'])) {
869                 // We should fix these all!
870                 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty. ext_id=' . $ext_id);
871         } // END - if
872
873         // Return the extension name
874         return $data['ext_name'];
875 }
876
877 // Get extension id from name
878 function getExtensionId ($ext_name) {
879         // Init id number
880         $data['ext_id'] = '0';
881
882         // Do we have cache?
883         if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
884                 // Load from cache
885                 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
886
887                 // Count cache hits
888                 incrementStatsEntry('cache_hits');
889         } else {
890                 // Load from database
891                 $result = SQL_QUERY_ESC("SELECT `id` AS `ext_id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
892                         array($ext_name), __FUNCTION__, __LINE__);
893
894                 // Is the entry there?
895                 if (SQL_NUMROWS($result) == 1) {
896                         // Get the extension's id from database
897                         $data = SQL_FETCHARRAY($result);
898                 } // END - if
899
900                 // Free result
901                 SQL_FREERESULT($result);
902
903                 // Cache it
904                 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
905         }
906
907         // Return value
908         return $data['ext_id'];
909 }
910
911 // Determines whether the given extension name is valid
912 function isExtensionNameValid ($ext_name) {
913         // Do we have cache?
914         if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
915                 // Generate include file name
916                 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
917
918                 // Is there a file in inc/extensions/ ?
919                 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
920         } // END - if
921
922         // Return result
923         return $GLOBALS['ext_name_valid'][$ext_name];
924 }
925
926 // Determines whether the given extension id is valid
927 function isExtensionIdValid ($ext_id) {
928         // Default is nothing valid
929         $isValid = false;
930
931         // Check in cache then in database
932         if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
933                 // Valid!
934                 $isValid = true;
935
936                 // Count cache hits
937                 incrementStatsEntry('cache_hits');
938         } else {
939                 // Query database
940                 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
941         }
942
943         // Return result
944         return $isValid;
945 }
946
947 // Activate given extension
948 function doActivateExtension ($ext_name) {
949         // Is the extension installed?
950         if (!isExtensionInstalled($ext_name)) {
951                 // Non-installed extensions cannot be activated
952                 reportBug(__FUNCTION__, __LINE__, 'Tried to activate non-installed extension ' . $ext_name);
953         } // END - if
954
955         // Activate the extension
956         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
957                 array($ext_name), __FUNCTION__, __LINE__);
958
959         // Then run all queries
960         doExtensionSqls(getExtensionId($ext_name), 'activate');
961 }
962
963 // Deactivate given extension
964 function doDeactivateExtension ($ext_name) {
965         // Is the extension installed?
966         if (!isExtensionInstalled($ext_name)) {
967                 // Non-installed extensions cannot be activated
968                 reportBug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name . ',getExtensionMode()=' . getExtensionMode());
969         } // END - if
970
971         // Activate the extension
972         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
973                 array($ext_name), __FUNCTION__, __LINE__);
974
975         // Then run all queries
976         doExtensionSqls(getExtensionId($ext_name), 'deactivate');
977
978         // Create new task (we ignore the task id here)
979         createExtensionDeactivationTask($ext_name);
980
981         // Rebuild cache
982         rebuildCache('extension', 'extension');
983
984         // Notify the admin
985         sendAdminNotification(
986                 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
987                 'admin_extension_deactivated',
988                 array('ext_name' => $ext_name)
989         );
990 }
991
992 // Checks whether the extension is older than given
993 function isExtensionOlder ($ext_name, $ext_ver) {
994         // Get current extension version
995         $currVersion = getExtensionVersion($ext_name);
996
997         // Remove all dots from both versions
998         $currVersion = str_replace('.', '', $currVersion);
999         $ext_ver = str_replace('.', '', $ext_ver);
1000
1001         // Now compare both and return the result
1002         return ($currVersion < $ext_ver);
1003 }
1004
1005 // Creates a new task for updated extension
1006 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
1007         // Create subject line
1008         $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
1009
1010         // Get task id
1011         $taskId = determineTaskIdBySubject($subject);
1012
1013         // Is the extension there?
1014         if (isExtensionInstalled($ext_name)) {
1015                 // Check if task is not there
1016                 if ($taskId == '0') {
1017                         // Create extension update-task
1018                         $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
1019                 } // END - if
1020         } else {
1021                 // Extension not there! :-(
1022                 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1023         }
1024
1025         // Return task id
1026         return $taskId;
1027 }
1028
1029 // Creates a new task for newly installed extension
1030 function createNewExtensionTask ($ext_name) {
1031         // Generate subject line
1032         $subject = sprintf("[%s:]", $ext_name);
1033
1034         // Get task id
1035         $taskId = determineTaskIdBySubject($subject);
1036
1037         // Not installed and do we have created a task for the admin?
1038         if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1039                 // Set default message if ext-foo is missing
1040                 $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
1041
1042                 // Template file
1043                 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1044                         getPath(),
1045                         getLanguage(),
1046                         $ext_name
1047                 );
1048
1049                 // Load text for task if found
1050                 if (isFileReadable($FQFN)) {
1051                         // Load extension's description template (but do not compile the code)
1052                         $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1053                 } else {
1054                         // Write this in debug.log as well
1055                         logDebugMessage(__FUNCTION__, __LINE__, $message);
1056                 }
1057
1058                 // Task not created so it's a brand-new extension which we need to register and create a task for!
1059                 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1060         } // END - if
1061
1062         // Return task id
1063         return $taskId;
1064 }
1065
1066 // Creates a task for automatically deactivated (deprecated) extension
1067 function createExtensionDeactivationTask ($ext_name) {
1068         // Create subject line
1069         $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1070
1071         // Get task id
1072         $taskId = determineTaskIdBySubject($subject);
1073
1074         // Not installed and do we have created a task for the admin?
1075         if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1076                 // Task not created so add it
1077                 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1078         } // END - if
1079
1080         // Return task id
1081         return $taskId;
1082 }
1083
1084 // Determines the task id for given extension
1085 function determineExtensionTaskId ($ext_name) {
1086         // Default is not found
1087         $data['task_id'] = '0';
1088
1089         // Search for extension task's id
1090         $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1091                 array($ext_name), __FUNCTION__, __LINE__);
1092
1093         // Entry found?
1094         if (SQL_NUMROWS($result) == 1) {
1095                 // Task found so load task's id and register extension...
1096                 $data = SQL_FETCHARRAY($result);
1097         } // END - if
1098
1099         // Free result
1100         SQL_FREERESULT($result);
1101
1102         // Return it
1103         return $data['task_id'];
1104 }
1105
1106 // Determines the task id for given subject
1107 function determineTaskIdBySubject ($subject) {
1108         // Default is not found
1109         $data['task_id'] = '0';
1110
1111         // Search for task id
1112         $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1113                 array($subject), __FUNCTION__, __LINE__);
1114
1115         // Entry found?
1116         if (SQL_NUMROWS($result) == 1) {
1117                 // Task found so load task's id and register extension...
1118                 $data = SQL_FETCHARRAY($result);
1119         } // END - if
1120
1121         // Free result
1122         SQL_FREERESULT($result);
1123
1124         // Return it
1125         return $data['task_id'];
1126 }
1127
1128 // Add updates notes for given version
1129 function addExtensionNotes ($ext_ver) {
1130         // Init notes/content
1131         $out = '';
1132         $content = array();
1133
1134         // Is do we have verbose output enabled?
1135         if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1136                 // Update notes found?
1137                 if ((isExtensionUpdateNoteSet($ext_ver)) && ($ext_ver != '0.0.0')) {
1138                         // Update notes found
1139                         $content = array(
1140                                 'ver'   => $ext_ver,
1141                                 'notes' => getExtensionUpdateNotes($ext_ver)
1142                         );
1143
1144                         // Reset them
1145                         setExtensionUpdateNotes('', $ext_ver);
1146                 } elseif ($ext_ver == '0.0.0') {
1147                         // Is the extension productive?
1148                         if (isExtensionProductive(getCurrentExtensionName())) {
1149                                 // Initial release
1150                                 $content = array(
1151                                         'ver'   => $ext_ver,
1152                                         'notes' => '{--INITIAL_RELEASE--}'
1153                                 );
1154                         } else {
1155                                 // Not productive
1156                                 $content = array(
1157                                         'ver'   => $ext_ver,
1158                                         'notes' => '{--DEVELOPER_RELEASE--}'
1159                                 );
1160                         }
1161                 } else {
1162                         // No update notes found
1163                         $content = array(
1164                                 'ver'   => $ext_ver,
1165                                 'notes' => '{--NO_UPDATE_NOTICES--}'
1166                         );
1167                 }
1168
1169                 // Load template
1170                 $out = loadTemplate('admin_extension_notes', true, $content);
1171         } // END - if
1172
1173         // Add the notes
1174         appendExtensionNotes($out);
1175 }
1176
1177 // Getter for CSS files array
1178 function getExtensionCssFiles () {
1179         // By default no additional CSS files are found
1180         $cssFiles = array();
1181
1182         // Is the array there?
1183         if (isset($GLOBALS['css_files'])) {
1184                 // Then use it
1185                 $cssFiles = $GLOBALS['css_files'];
1186         } // END - if
1187
1188         // Return array
1189         return $cssFiles;
1190 }
1191
1192 // Init CSS files array
1193 function initExtensionCssFiles () {
1194         // Simply init it
1195         $GLOBALS['css_files'] = array();
1196 }
1197
1198 // Add new entry
1199 function addExtensionCssFile ($file) {
1200         // Is the array there?
1201         if (!isset($GLOBALS['css_files'])) {
1202                 // Then auto-init them
1203                 initExtensionCssFiles();
1204         } // END - if
1205
1206         // Add the entry
1207         array_push($GLOBALS['css_files'], $file);
1208 }
1209
1210 // Setter for EXT_ALWAYS_ACTIVE flag
1211 function setExtensionAlwaysActive ($active) {
1212         $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1213 }
1214
1215 // Getter for EXT_ALWAYS_ACTIVE flag
1216 function getThisExtensionAlwaysActive () {
1217         return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1218 }
1219
1220 // Checks whether the current extension is always active
1221 function isThisExtensionAlwaysActive () {
1222         return (getThisExtensionAlwaysActive() == 'Y');
1223 }
1224
1225 // Setter for EXT_VERSION flag
1226 function setThisExtensionVersion ($ext_version) {
1227         $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1228 }
1229
1230 // Getter for EXT_VERSION flag
1231 function getThisExtensionVersion () {
1232         return $GLOBALS['ext_version'][getCurrentExtensionName()];
1233 }
1234
1235 // Setter for EXT_DEPRECATED flag
1236 function setExtensionDeprecated ($deprecated) {
1237         $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1238 }
1239
1240 // Getter for EXT_DEPRECATED flag
1241 function isExtensionDeprecated ($ext_name = NULL) {
1242         // Default is from current (NULL) extension
1243         $isDeprecated = ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1244
1245         // Is ext_name set?
1246         if (!is_null($ext_name)) {
1247                 // Then use it instead
1248                 $isDeprecated = ((isset($GLOBALS['ext_deprecated'][$ext_name])) && ($GLOBALS['ext_deprecated'][$ext_name] == 'Y'));
1249         } // END - if
1250
1251         // Return it
1252         return $isDeprecated;
1253 }
1254
1255 // Setter for EXT_UPDATE_DEPENDS flag
1256 function addExtensionDependency ($updateDepends) {
1257         // Is the update depency empty? (NEED TO BE FIXED!)
1258         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - ENTERED!');
1259         if (empty($updateDepends)) {
1260                 // Please report this bug!
1261                 reportBug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1262         } // END - if
1263
1264         // Is it not yet added?
1265         if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1266                 /*
1267                  * Double-adding happens when the extension and an update of the same
1268                  * extension requires the same other extension again.
1269                  */
1270                 logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
1271                 return;
1272         } // END - if
1273
1274         // Add it to the list of extension update depencies map
1275         array_push($GLOBALS['ext_update_depends'][getCurrentExtensionName()], $updateDepends);
1276
1277         // Init array
1278         if ((!isset($GLOBALS['ext_running_updates'][getCurrentExtensionName()])) || (!is_array($GLOBALS['ext_running_updates'][getCurrentExtensionName()]))) {
1279                 $GLOBALS['ext_running_updates'][getCurrentExtensionName()] = array();
1280         } // END - if
1281
1282         // Remember it in the list of running updates
1283         array_push($GLOBALS['ext_running_updates'][getCurrentExtensionName()], $updateDepends);
1284         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - EXIT!');
1285 }
1286
1287 // Getter for running updates
1288 function getExtensionUpdatesRunning () {
1289         return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1290 }
1291
1292 // Checks whether the given extension registration is in progress
1293 function isExtensionRegistrationRunning ($ext_name) {
1294         // Simply check it
1295         $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1296
1297         // Return it
1298         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1299         return $isRunning;
1300 }
1301
1302 // Init EXT_UPDATE_DEPENDS flag
1303 function initExtensionUpdateDependencies () {
1304         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1305
1306         // Init update depency map automatically if not found
1307         if (isExtensionUpdateDependenciesInitialized()) {
1308                 // We need these bug reports as well...
1309                 reportBug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1310         } // END - if
1311
1312         $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1313
1314         // Init running updates array
1315         initExtensionRuningUpdates();
1316
1317         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1318 }
1319
1320 // Adds an extension as "registration in progress"
1321 function addExtensionRunningRegistration ($ext_name) {
1322         // Is it running?
1323         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1324         if (isExtensionRegistrationRunning($ext_name)) {
1325                 // This is really bad and should not be quietly ignored
1326                 reportBug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1327         } // END - if
1328
1329         // Then add it!
1330         array_push($GLOBALS['ext_register_running'], $ext_name);
1331         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1332 }
1333
1334 // Checks whether EXT_UPDATE_DEPENDS is initialized
1335 function isExtensionUpdateDependenciesInitialized () {
1336         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1337         return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1338 }
1339
1340 // Checks whether an update is already running for given extension
1341 function isExtensionUpdateRunning ($ext_name, $ignoreDependencies = false) {
1342         // Current and given extensions means whole array
1343         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
1344         if ($ext_name == getCurrentExtensionName()) {
1345                 // Default is not found
1346                 $isRunning = false;
1347
1348                 // Walk through whole array
1349                 foreach ($GLOBALS['ext_running_updates'] as $ext1 => $depends) {
1350                         // Is it found?
1351                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',depends=' . print_r($depends, true));
1352                         if (($ext1 == $ext_name) || ((in_array($ext_name, $depends)) && ($ignoreDependencies === false))) {
1353                                 // Found
1354                                 $isRunning = true;
1355                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=true - FOUND!');
1356                                 break;
1357                         } // END - if
1358                 } // END - foreach
1359
1360                 // Return result
1361                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - ALT-EXIT!');
1362                 return $isRunning;
1363         } // END - if
1364
1365         // Simply check it
1366         $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1367
1368         // Return it
1369         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - EXIT!');
1370         return $isRunning;
1371 }
1372
1373 // Initializes the list of running updates
1374 function initExtensionRuningUpdates () {
1375         // Auto-init ext_running_updates
1376         if (!isset($GLOBALS['ext_running_updates'])) {
1377                 $GLOBALS['ext_running_updates'] = array();
1378                 $GLOBALS['ext_register_running'] = array();
1379         } // END - if
1380 }
1381
1382 // Getter for EXT_UPDATE_DEPENDS flag
1383 function getExtensionUpdateDependencies () {
1384         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1385         return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1386 }
1387
1388 // Getter for next iterator depency
1389 function getExtensionUpdateDependenciesIterator () {
1390         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1391         return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1392 }
1393
1394 // Counter for extension update depencies
1395 function countExtensionUpdateDependencies () {
1396         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1397         return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1398 }
1399
1400 // Removes given extension from update denpency list
1401 function removeExtensionDependency ($ext_name) {
1402         // Look it up
1403         $key = array_search($ext_name, getExtensionUpdateDependencies());
1404
1405         // Debug message
1406         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',key[' . gettype($key) . ']=' . $key);
1407
1408         // Is it valid?
1409         if ($key !== false) {
1410                 // Then remove it
1411                 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1412
1413                 // And sort the array
1414                 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1415         } // END - if
1416 }
1417
1418 // Init iterator for update depencies
1419 function initExtensionUpdateIterator () {
1420         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1421         $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1422 }
1423
1424 // Getter for depency iterator
1425 function getExtensionUpdateIterator () {
1426         // Auto-init iterator
1427         if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) {
1428                 // Initialize update iterator
1429                 initExtensionUpdateIterator();
1430         } // END - if
1431
1432         // Return it
1433         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1434         return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1435 }
1436
1437 // Increments the update iterator
1438 function incrementExtensionUpdateIterator () {
1439         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1440         $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1441 }
1442
1443 // Setter for EXT_REPORTS_FAILURE flag
1444 function enableExtensionReportingFailure ($reportsFailure = false) {
1445         $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1446 }
1447
1448 // Getter for EXT_REPORTS_FAILURE flag
1449 function isExtensionReportingFailure () {
1450         return $GLOBALS['ext_reports_failure'];
1451 }
1452
1453 // Setter for EXT_VER_HISTORY flag
1454 function setExtensionVersionHistory ($versionHistory) {
1455         $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1456 }
1457
1458 // Getter for EXT_VER_HISTORY array
1459 function getExtensionVersionHistory () {
1460         // Is it set?
1461         if (!isset($GLOBALS['ext_ver_history'][getCurrentExtensionName()])) {
1462                 // Then abort here to a avoid an ugly "Undefined index" error
1463                 reportBug(__FUNCTION__, __LINE__, 'Extension ext-' . getCurrentExtensionName() . ' has no history set! Is this extension empty?');
1464         } // END - if
1465
1466         // Return the history
1467         return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1468 }
1469
1470 // Setter for EXT_UPDATE_NOTICES
1471 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1472         //
1473         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . '/' . getCurrentExtensionVersion() . ',updateNotes(length)=' . strlen($updateNotes));
1474         if (empty($ext_ver)) {
1475                 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1476         } else {
1477                 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1478         }
1479 }
1480
1481 // Getter for EXT_UPDATE_NOTICES
1482 function getExtensionUpdateNotes ($ext_ver) {
1483         return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1484 }
1485
1486 // Checks if ext_update_notes is set
1487 function isExtensionUpdateNoteSet ($ext_ver) {
1488         return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1489 }
1490
1491 // Init extension notice
1492 function initExtensionNotes ($force = false) {
1493         // Is it already initialized?
1494         if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1495                 // This is mostly not wanted, so please report it
1496                 reportBug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1497         } // END - if
1498
1499         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1500         $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1501 }
1502
1503 // Append extension notice
1504 function appendExtensionNotes ($notes) {
1505         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes(length)=' . strlen($notes));
1506         $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1507 }
1508
1509 // Getter for extension notes
1510 function getExtensionNotes () {
1511         return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1512 }
1513
1514 // Setter for current extension name
1515 function setCurrentExtensionName ($ext_name) {
1516         $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1517 }
1518
1519 // Getter for current extension name
1520 function getCurrentExtensionName () {
1521         if (!isset($GLOBALS['curr_extension_name'])) {
1522                 // Not set!
1523                 reportBug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1524         } // END - if
1525
1526         // Return it
1527         return $GLOBALS['curr_extension_name'];
1528 }
1529
1530 // Init SQLs array for current extension
1531 function initExtensionSqls ($force = false) {
1532         // Auto-init the array or if forced
1533         if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1534                 // Set the array
1535                 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1536
1537                 // Initialize the generic array
1538                 initSqls();
1539         } // END - if
1540 }
1541
1542 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1543 function addExtensionSql ($sql) {
1544         // Is is the array there?
1545         if ((!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()])) || (!is_array($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()]))) {
1546                 // Init array
1547                 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()] = array();
1548         } // END - if
1549
1550         // Add it
1551         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1552         array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql);
1553 }
1554
1555 // Getter for SQLs array for current extension
1556 function getExtensionSqls () {
1557         // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1558         if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1559                 // Not found, should not happen
1560                 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1561                         getCurrentExtensionName()
1562                 ));
1563         } // END - if
1564
1565         // Return the array
1566         return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1567 }
1568
1569 // Count SQLs for current extension
1570 function countExtensionSqls () {
1571         // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1572         if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1573                 // Not found, should not happen
1574                 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1575                         getCurrentExtensionName()
1576                 ));
1577         } // END - if
1578
1579         // Count them all
1580         return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1581 }
1582
1583 // Removes SQLs for current extension
1584 function unsetExtensionSqls () {
1585         unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1586 }
1587
1588 // Auto-initializes the removal list
1589 function initExtensionRemovalList () {
1590         // Is the remove list there?
1591         if (!isset($GLOBALS['ext_update_remove'])) {
1592                 // Then create it
1593                 $GLOBALS['ext_update_remove'] = array();
1594         } // END - if
1595 }
1596
1597 // Checks whether the current extension is on the removal list
1598 function isExtensionOnRemovalList () {
1599         // Init removal list
1600         initExtensionRemovalList();
1601
1602         // Is it there?
1603         return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1604 }
1605
1606 // Adds the current extension to the removal list
1607 function addCurrentExtensionToRemovalList () {
1608         // Simply add it
1609         array_push($GLOBALS['ext_update_remove'], getCurrentExtensionName());
1610 }
1611
1612 // Getter for removal list
1613 function getExtensionRemovalList () {
1614         // Return the removal list
1615         return $GLOBALS['ext_update_remove'];
1616 }
1617
1618 // Redirects if the provided extension is not installed
1619 function redirectOnUninstalledExtension ($ext_name) {
1620         // So is the extension there?
1621         if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1622                 // Redirect to index
1623                 redirectToUrl('modules.php?module=index&amp;code=' . getCode('EXTENSION_PROBLEM') . '&amp;ext=' . $ext_name);
1624         } // END - if
1625 }
1626
1627 // Filter for initialization of all extensions by loading them in 'init' mode
1628 function FILTER_INIT_EXTENSIONS () {
1629         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTERED!');
1630         // Init notification pool
1631         initIncludePool('notify');
1632
1633         // Do we have some entries?
1634         if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1635                 // Load all found extensions if found
1636                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1637                 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1638                         // Load it
1639                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
1640                         loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1641                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
1642                 } // END - foreach
1643                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1644         } // END - if
1645
1646         // Run any notifications
1647         runFilterChain('load_includes', 'notify');
1648
1649         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1650 }
1651
1652 // Setter for extension mode
1653 function setExtensionMode ($ext_mode) {
1654         $GLOBALS['ext_mode'] = (string) $ext_mode;
1655 }
1656
1657 // Getter for extension mode
1658 function getExtensionMode () {
1659         return $GLOBALS['ext_mode'];
1660 }
1661
1662 // Setter for dry-run
1663 function enableExtensionDryRun ($dry_run = true) {
1664         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry_run='.intval($dry_run));
1665         $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1666 }
1667
1668 // Getter for dry-run
1669 function isExtensionDryRun () {
1670         return $GLOBALS['ext_dry_run'];
1671 }
1672
1673 // Setter for current extension version
1674 function setCurrentExtensionVersion ($ext_ver) {
1675         // ext_ver should never be empty in other modes than 'test'
1676         if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1677                 // Please report all these messages
1678                 reportBug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1679         } // END - if
1680
1681         // Add version
1682         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1683         $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1684 }
1685
1686 // Getter for current extension version
1687 function getCurrentExtensionVersion () {
1688         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1689         return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1690 }
1691
1692 // Remove the extension from cache array
1693 function removeExtensionFromArray () {
1694         // "Cache" this name
1695         $ext_name = getCurrentExtensionName();
1696
1697         // Now loop through the whole cache
1698         foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1699                 // Is it an element?
1700                 if (isset($cacheArray[$ext_name])) {
1701                         // Array element
1702                         unset($cacheArray[$ext_name]);
1703                         $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1704                 } else {
1705                         // Maybe in array?
1706                         $key = array_search($ext_name, $cacheArray);
1707
1708                         // Is it there?
1709                         if ($key !== false) {
1710                                 // Found, so remove it
1711                                 unset($cacheArray[$key]);
1712                                 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1713                         } // END - if
1714                 }
1715         } // END - foreach
1716
1717         // Remove from other caches as well
1718         unset($GLOBALS['ext_is_installed'][$ext_name]);
1719         unset($GLOBALS['loaded_extension'][$ext_name]);
1720 }
1721
1722 // "Getter" for 'extension has a CSS file' (with same name, of course)
1723 function getExtensionHasCss () {
1724         // Do we have cache?
1725         if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
1726                 // Construct FQFN for check
1727                 $FQFN = sprintf("%stheme/%s/css/%s.css",
1728                         getPath(),
1729                         getCurrentTheme(),
1730                         getCurrentExtensionName()
1731                 );
1732
1733                 // Is it there?
1734                 $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
1735         } // END - if
1736
1737         // Return it
1738         return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
1739 }
1740
1741 // Checks whether the given extension has a language file
1742 function ifExtensionHasLanguageFile ($ext_name) {
1743         // Do we have cache?
1744         if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1745                 // Count cache hits
1746                 incrementStatsEntry('cache_hits');
1747         } else {
1748                 // Determine it and put it in cache
1749                 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
1750         }
1751
1752         // Return result
1753         return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1754 }
1755
1756 // Load current extension's include file
1757 function loadCurrentExtensionInclude () {
1758         // Is it readable?
1759         if (!isExtensionIncludeReadable()) {
1760                 // Not readable
1761                 reportBug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1762         } // END - if
1763
1764         // Generate INC name
1765         $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1766
1767         // Load it
1768         loadInclude($INC);
1769 }
1770
1771 // Checks whether an extension is readable
1772 function isExtensionIncludeReadable ($ext_name = '') {
1773         // If empty, use current
1774         if (empty($ext_name)) {
1775                 $ext_name = getCurrentExtensionName();
1776         } // END - if
1777
1778         // Array found?
1779         if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1780                 // Generate INC name
1781                 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1782
1783                 // Is it readable?
1784                 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1785         } // END - if
1786
1787         // Return result
1788         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1789         return $GLOBALS['ext_inc_readable'][$ext_name];
1790 }
1791
1792 // Checks if an extension's function file is readable
1793 function isExtensionFunctionFileReadable ($ext_name) {
1794         // Is cache there?
1795         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1796         if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1797                 // Just count cache hits
1798                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1799                 incrementStatsEntry('cache_hits');
1800         } else {
1801                 // Construct IFN for functions file
1802                 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1803
1804                 // Is this include there?
1805                 $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
1806
1807                 // And put in cache, converted
1808                 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
1809         }
1810
1811         // Return result
1812         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1813         return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1814 }
1815
1816 // Adds a CREATE TABLE statement if the requested table is not there
1817 function addCreateTableSql ($tableName, $sql, $comment) {
1818         // Is the table not there?
1819         if (!isSqlTableCreated($tableName)) {
1820                 // Is not found, so add it
1821                 addExtensionSql('CREATE TABLE
1822         `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
1823 ENGINE = {?_TABLE_TYPE?}
1824 CHARACTER SET utf8
1825 COLLATE utf8_general_ci
1826 COMMENT ' . chr(39) . $comment . chr(39));
1827         } else {
1828                 // Is already there, which should not happen
1829                 reportBug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1830         }
1831 }
1832
1833 // Adds a DROP TABLE statement if the requested tabled is there
1834 function addDropTableSql ($tableName) {
1835         // Is the table there?
1836         if (isSqlTableCreated($tableName)) {
1837                 // Then add it, non-existing tables can be ignored because it will
1838                 // happen with every newly installed extension.
1839                 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1840
1841                 // Mark it as gone
1842                 $GLOBALS['isSqlTableCreated'][$tableName] = false;
1843         } // END - if
1844 }
1845
1846 // Adds an admin menu to the SQL queue of the menu entry is not found
1847 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1848         // Now check if this menu is there
1849         if (!isMenuActionValid('admin', $action, $what)) {
1850                 // Is what null?
1851                 if (is_null($what)) {
1852                         // Add main menu
1853                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1854                                 $action,
1855                                 $title,
1856                                 $descr,
1857                                 bigintval($sort)
1858                         );
1859                 } else {
1860                         // Add sub menu
1861                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1862                                 $action,
1863                                 $what,
1864                                 $title,
1865                                 $descr,
1866                                 bigintval($sort)
1867                         );
1868                 }
1869
1870                 // Add it to the queue
1871                 addExtensionSql($sql);
1872         } elseif (isDebugModeEnabled()) {
1873                 // Double menus should be located and fixed!
1874                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1875         }
1876 }
1877
1878 // Adds a guest menu to the SQL queue if the menu entry is not found
1879 function addGuestMenuSql ($action, $what, $title, $sort) {
1880         // Now check if this menu is there
1881         if (!isMenuActionValid('guest', $action, $what)) {
1882                 // Is what null?
1883                 if (is_null($what)) {
1884                         // Add main menu
1885                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1886                                 $action,
1887                                 $title,
1888                                 bigintval($sort)
1889                         );
1890                 } else {
1891                         // Add sub menu
1892                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1893                                 $action,
1894                                 $what,
1895                                 $title,
1896                                 bigintval($sort)
1897                         );
1898                 }
1899
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 guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1905         }
1906 }
1907
1908 // Adds a member menu to the SQL queue if the menu entry is not found
1909 function addMemberMenuSql ($action, $what, $title, $sort) {
1910         // Now check if this menu is there
1911         if (!isMenuActionValid('member', $action, $what)) {
1912                 // Is what null?
1913                 if (is_null($what)) {
1914                         // Add main menu
1915                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1916                                 $action,
1917                                 $title,
1918                                 bigintval($sort)
1919                         );
1920                 } else {
1921                         // Add sub menu
1922                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1923                                 $action,
1924                                 $what,
1925                                 $title,
1926                                 bigintval($sort)
1927                         );
1928                 }
1929
1930                 // Add it to the queue
1931                 addExtensionSql($sql);
1932         } elseif (isDebugModeEnabled()) {
1933                 // Double menus should be located and fixed!
1934                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1935         }
1936 }
1937
1938 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1939 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1940         // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1941         if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1942                 // Is what null?
1943                 if (is_null($what)) {
1944                         // Add main menu
1945                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1946                                 $action,
1947                                 $title,
1948                                 $active,
1949                                 bigintval($sort)
1950                         );
1951                 } else {
1952                         // Add sub menu
1953                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1954                                 $action,
1955                                 $what,
1956                                 $title,
1957                                 $active,
1958                                 bigintval($sort)
1959                         );
1960                 }
1961
1962                 // Add it to the queue
1963                 addExtensionSql($sql);
1964         } elseif (isDebugModeEnabled()) {
1965                 // Double menus should be located and fixed!
1966                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1967         }
1968 }
1969
1970 // Add configuration entry if not found for actual extension
1971 function addConfigAddSql ($columnName, $columnSql) {
1972         // Is the column there?
1973         if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1974                 // Not found, so add it
1975                 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1976         } elseif (isDebugModeEnabled()) {
1977                 // Add debug line
1978                 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
1979         }
1980 }
1981
1982 // Drop configuration entry if found for actual extension
1983 function addConfigDropSql ($columnName) {
1984         // Is the column there?
1985         if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1986                 // Found, so add it
1987                 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
1988         } elseif (isDebugModeEnabled()) {
1989                 // Add debug line, reportBug() would cause some extenion updates fail
1990                 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
1991         }
1992 }
1993
1994 // Change configuration entry for actual extension
1995 function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
1996         // Add the SQL statement
1997         addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
1998 }
1999
2000 // Enables/disables productive mode for current extension (used only while
2001 // registration).
2002 // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
2003 function enableExtensionProductive ($isProductive = true) {
2004         // Log debug message
2005         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',isProductive=', intval($isProductive));
2006
2007         // Set it
2008         $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
2009 }
2010
2011 // Checks whether the extension is in productive phase. If not set, development
2012 // phase (=false) is assumed.
2013 function isExtensionProductive ($ext_name = '') {
2014         // Is the extension name empty? Then use current
2015         if (empty($ext_name)) {
2016                 // Get current extension name
2017                 $ext_name = getCurrentExtensionName();
2018         } // END - if
2019         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
2020
2021         // Do we have cache?
2022         if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
2023                 // Load extension only if not yet loaded
2024                 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
2025                         // Load extension in test mode
2026                         loadExtension($ext_name, 'test');
2027                 } // END - if
2028
2029                 // Determine it
2030                 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
2031         } // END - if
2032
2033         // Return result
2034         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isProductive=', intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!');
2035         return $GLOBALS[__FUNCTION__][$ext_name];
2036 }
2037
2038 // Mark extension file as loaded
2039 function markExtensionAsLoaded ($ext_name) {
2040         // Is it already loaded?
2041         if (isExtensionLoaded($ext_name)) {
2042                 // Then abort here
2043                 reportBug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
2044         } // END - if
2045
2046         // Mark it
2047         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_loaded=true');
2048         $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
2049 }
2050
2051 // Determine whether the given extension is already loaded
2052 function isExtensionLoaded ($ext_name) {
2053         // Is it there?
2054         return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
2055 }
2056
2057 // Mark extension's library file as loaded
2058 function markExtensionLibraryAsLoaded ($ext_name) {
2059         // Is it already loaded?
2060         if (isExtensionLibraryLoaded($ext_name)) {
2061                 // Then abort here
2062                 reportBug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
2063         } // END - if
2064
2065         // Mark it
2066         $GLOBALS['ext_loaded']['library'][$ext_name] = true;
2067 }
2068
2069 // Determine whether the given extension's library is already loaded
2070 function isExtensionLibraryLoaded ($ext_name) {
2071         // Is it there?
2072         return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));
2073 }
2074
2075 // [EOF]
2076 ?>