743f97281f7ba3a345559218d5eba0316139385f
[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  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Load the extension and maybe found language and function files.
46 function loadExtension ($ext_name, $ext_mode = 'init', $ext_ver = '', $dry_run = false) {
47         // Set current extension name
48         setCurrentExtensionName($ext_name);
49
50         // Set current extension version
51         setCurrentExtensionVersion($ext_ver);
52
53         // Set extension mode
54         setExtensionMode($ext_mode);
55
56         // Set dry-run
57         enableExtensionDryRun($dry_run);
58
59         // Init array
60         initIncludePool('extension');
61
62         // Init EXT_UPDATE_DEPENDS
63         initExtensionUpdateDependencies();
64
65         // Init current extension name list
66         initExtensionSqls();
67
68         // Is the extension already loaded?
69         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode=".getExtensionMode().", ver=".getCurrentExtensionVersion()."");
70         if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (getExtensionMode() == 'init')) {
71                 // Debug message
72                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
73
74                 // Abort here
75                 return false;
76         } // END - if
77
78         // Is the extension file NOT there?
79         if (!isExtensionNameValid($ext_name)) {
80                 // Debug message
81                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable.", $ext_name));
82
83                 // Abort here
84                 return false;
85         } // END - if
86
87         // Load extension's own language file if not in test mode
88         if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
89                 // Load it
90                 loadLanguageFile($ext_name);
91         } // END - if
92
93         // Do we have cache?
94         if (isExtensionFunctionFileReadable($ext_name)) {
95                 // Not yet loaded?
96                 if ((($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') || (!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name]))) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name]))) {
97                         // Construct FQFN for functions file
98                         $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
99
100                         // Mark it as loaded
101                         $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
102
103                         // Download functions file
104                         loadIncludeOnce($funcsInclude);
105                 } // END - if
106         } elseif ((!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) && (isDebugModeEnabled()) && (getOutputMode() == '0') && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme') && (getExtensionMode() == 'test')) {
107                 // No functions file is not so good...
108                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
109                         $ext_name,
110                         getExtensionMode()
111                 ));
112         }
113
114         // Extensions are not deprecated by default
115         setExtensionDeprecated('N');
116
117         // Extensions are not always active by default
118         setExtensionAlwaysActive('N');
119
120         // Extension update notes
121         setExtensionUpdateNotes('');
122
123         // Include the extension file
124         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Extension loaded.");
125         loadExtensionInclude();
126
127         // Is this extension deprecated?
128         if (isExtensionDeprecated()) {
129                 // Deactivate the extension
130                 doDeactivateExtension($ext_name);
131
132                 // Abort here
133                 return false;
134         } // END - if
135
136         // Mark it as loaded in normal mode
137         if (getExtensionMode() == '') {
138                 // Mark it now...
139                 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
140         } // END - if
141
142         // All fine!
143         return true;
144 }
145
146 // Registeres an extension and possible update depencies
147 function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = true) {
148         // Set current extension name
149         setCurrentExtensionName($ext_name);
150
151         // Enable dry-run
152         enableExtensionDryRun($dry_run);
153
154         // By default all extensions are in productive phase
155         enableExtensionProductive();
156
157         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
158         // This shall never do a non-admin user or if the extension is active (already installed)
159         if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
160                 return false;
161         } // END - if
162
163         // When this extension is already in install/update phase, all is fine
164         if (isExtensionRegisterRunning($ext_name)) {
165                 // Then abort here which is fine
166                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ALREADY!");
167                 return true;
168         } // END - if
169
170         // This registration is running
171         addExtensionRunningRegistration($ext_name);
172
173         // Init EXT_UPDATE_DEPENDS
174         initExtensionUpdateDependencies();
175
176         // Is the task id zero? Then we need to auto-fix it here
177         if ($task_id == '0') {
178                 // Try to find the task
179                 $task_id = determineExtensionTaskId(getCurrentExtensionName());
180
181                 // Still zero and not in dry-run?
182                 if (($task_id == '0') && (!getExtensionDryRun())) {
183                         // Then request a bug report
184                         debug_report_bug(sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
185                                 __FUNCTION__,
186                                 getCurrentExtensionName()
187                         ));
188                 } // END - if
189         } // END - if
190
191         // Init queries and notes
192         initExtensionSqls();
193         initExtensionNotes();
194
195         // Init variables
196         $ret = false;
197         $test = false;
198         initIncludePool('extension');
199
200         // By default we have no failures
201         setExtensionReportsFailure(false);
202
203         // Does this extension exists?
204         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
205         if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
206                 // Set current extension name again
207                 setCurrentExtensionName($ext_name);
208
209                 // And run possible updates
210                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
211                 $history = getExtensionVersionHistory();
212                 foreach ($history as $ver) {
213                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName().", ext_ver={$ver}");
214                         // Load extension in update mode
215                         loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
216
217                         // Add update notes to our output
218                         addExtensionNotes($ver);
219                 } // END - foreach
220
221                 // Does this extension depends on an outstanding update of another update?
222                 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
223                         // Get next update
224                         $ext_update = getExtensionUpdateDependenciesIterator();
225
226                         // Increment here to avoid endless loop
227                         incrementExtensionUpdateIterator();
228
229                         // Check for required file
230                         if ((!isExtensionInstalled($ext_update)) && (loadExtension($ext_update, 'register', '', getExtensionDryRun()))) {
231                                 // Set current extension name again
232                                 setCurrentExtensionName($ext_name);
233
234                                 // If versions mismatch update extension first
235                                 $ext_ver = '';
236                                 if (isExtensionInstalled($ext_update)) {
237                                         // Get version only if installed
238                                         $ext_ver = getExtensionVersion($ext_update);
239                                 } // END - if
240
241                                 // Extension version set? If empty the extension is not registered
242                                 if (empty($ext_ver)) {
243                                         // Extension not registered so far so first load task's id...
244                                         $task = determineExtensionTaskId($ext_update);
245
246                                         // Entry found?
247                                         if ($task > 0) {
248                                                 // Try to register the extension
249                                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().":ext_update=".$ext_update.",taskId=".$task."");
250                                                 $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
251
252                                                 // Reset extension name
253                                                 setCurrentExtensionName($ext_name);
254                                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test);
255                                         } // END - if
256                                 } elseif ($ext_ver != getCurrentExtensionVersion()) {
257                                         // Ok, update this extension now
258                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
259                                         $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
260                                         $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
261                                         updateExtension($ext_update, $ext_ver, getExtensionDryRun());
262                                         setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
263                                         setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
264                                         unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
265                                         unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
266                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
267
268                                         // All okay!
269                                         $test = true;
270                                 } else {
271                                         // Nothing to register / update before...
272                                         $test = true;
273                                 }
274                         } else {
275                                 // Required file for update does not exists!
276                                 $test = true;
277                                 // But this is fine for the first time...
278                         }
279
280                         // Restore the current extension name
281                         setCurrentExtensionName($ext_name);
282                 } // END - for
283
284                 // Is there no update?
285                 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
286                         // Then test is passed!
287                         $test = true;
288                 } // END - if
289
290                 // Switch back to register mode
291                 setExtensionMode('register');
292
293                 // Remains true if extension registration reports no failures
294                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
295                 $test = (($test === true) && (getExtensionReportsFailure() === false));
296                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
297
298                 // Does everthing before wents ok?
299                 if ($test === true) {
300                         // "Dry-run-mode" activated?
301                         if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
302                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName());
303                                 // Init SQLs and transfer ext->generic
304                                 initSqls();
305                                 setSqlsArray(getExtensionSqls());
306
307                                 // Run installation pre-installation filters
308                                 runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
309
310                                 // Register extension
311                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "insert=".getCurrentExtensionName().'/'.getCurrentExtensionVersion()." - INSERT!");
312                                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
313                                         // New way, with CSS
314                                         SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
315                                                 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion(), getExtensionHasCss()), __FUNCTION__, __LINE__);
316                                 } else {
317                                         // Old way, no CSS
318                                         SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
319                                                 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion()), __FUNCTION__, __LINE__);
320                                 }
321
322                                 // Remove cache file(s) if extension is active
323                                 runFilterChain('post_extension_installed', array(
324                                         'pool'     => 'extension',
325                                         'ext_name' => getCurrentExtensionName(),
326                                         'task_id'  => $task_id
327                                 ));
328
329                                 // Remove all SQL commands
330                                 unsetSqls();
331
332                                 // Mark it as installed
333                                 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
334
335                                 // In normal mode return a true on success
336                                 $ret = true;
337                         } elseif (getExtensionDryRun() === true) {
338                                 // In  "dry-run" mode return array with all SQL commands
339                                 $ret = getExtensionSqls();
340
341                                 // Remove all SQL commands
342                                 unsetSqls();
343                         } else {
344                                 // Extension has been removed for updates, so all is fine!
345                                 $ret = true;
346                         }
347                 } else {
348                         // No, an error occurs while registering extension :-(
349                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
350                         $ret = false;
351                 }
352         } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
353                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
354                 // Remove task from system when id and extension's name is valid
355                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
356                         array(bigintval($task_id)), __FUNCTION__, __LINE__);
357         }
358
359         // Is this the sql_patches?
360         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
361         if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
362                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
363                 if ($logout === true) {
364                         // Then redirect to logout
365                         redirectToUrl('modules.php?module=admin&amp;logout=1&amp;' . getExtensionMode() . '=sql_patches');
366                 } else {
367                         // Add temporary filter
368                         registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
369                         $GLOBALS['ext_load_mode'] = getExtensionMode();
370                 }
371         } // END - if
372
373         // Return status code
374         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
375         //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
376         return $ret;
377 }
378
379 // Run SQL queries for given extension id
380 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
381 function doExtensionSqls ($ext_id, $load_mode) {
382         // This shall never do a non-admin user!
383         if (!isAdmin()) return false;
384
385         // Get extension's name
386         $ext_name = getExtensionName($ext_id);
387
388         // Set current SQL name
389         setCurrentExtensionName($ext_name);
390
391         // Init EXT_UPDATE_DEPENDS
392         initExtensionUpdateDependencies();
393
394         // Init array
395         initExtensionSqls();
396
397         // By default no SQL has been executed
398         $sqlRan = false;
399
400         // Load extension in detected mode
401         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
402         loadExtension(getCurrentExtensionName(), $load_mode, '', false);
403
404         // Init these SQLs
405         initSqls();
406         setSqlsArray(getExtensionSqls());
407
408         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
409         if (isSqlsValid()) {
410                 // Run SQL commands...
411                 runFilterChain('run_sqls');
412         } // END - if
413
414         // Run any filters depending on the action here
415         runFilterChain('extension_' . $load_mode);
416
417         // Remove cache file(s) if extension is active
418         if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
419                 // Run filters
420                 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
421         } // END - if
422
423         // Is this the sql_patches?
424         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
425         if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
426                 // Then redirect to logout
427                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
428                 redirectToUrl('modules.php?module=admin&amp;logout=1&amp;' . $load_mode . '=sql_patches');
429         } // END - if
430 }
431
432 // Check wether the given extension is installed
433 function isExtensionInstalled ($ext_name) {
434         // We don't like empty extension names here
435         if (empty($ext_name)) {
436                 // Please fix them all
437                 debug_report_bug(__FUNCTION__.': ext_name is empty.');
438         } // END - if
439
440         // By default non is installed
441         $isInstalled = false;
442
443         // Check if there is a cache entry
444         if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
445                 // Use cache built from below queries
446                 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
447         } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
448                 // Found!
449                 $isInstalled = true;
450
451                 // Count cache hits
452                 incrementStatsEntry('cache_hits');
453         } elseif ((isInstallationPhase())) {
454                 // Extensions are all inactive/not installed during installation
455         } else {
456                 // Look in database
457                 $ext_id = getExtensionId($ext_name);
458
459                 // Do we have a record?
460                 $isInstalled = ($ext_id > 0);
461
462                 // Is it installed, then cache the entry
463                 if ($isInstalled === true) {
464                         // Dummy call (get is okay here)
465                         getExtensionId($ext_name, true);
466                 } // END - if
467
468                 // Remember the status
469                 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
470         }
471
472         // Return status
473         return $isInstalled;
474 }
475
476 // Check if given extension is active
477 function isExtensionActive ($ext_name) {
478         // Extensions are all inactive during installation
479         if ((isInstallationPhase()) || (empty($ext_name))) return false;
480
481         // Not active is the default
482         $data['ext_active'] = 'N';
483
484         // Check cache
485         if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
486                 // Load from cache
487                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
488                 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
489
490                 // Count cache hits
491                 incrementStatsEntry('cache_hits');
492         } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
493                 // @TODO Extension is loaded, what next?
494                 app_die(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
495         } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
496                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
497                 // Load from database
498                 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
499                         array($ext_name), __FUNCTION__, __LINE__);
500
501                 // Entry found?
502                 if (SQL_NUMROWS($result) == 1) {
503                         // Load entry
504                         $data = SQL_FETCHARRAY($result);
505                 } // END - if
506
507                 // Free result
508                 SQL_FREERESULT($result);
509
510                 // Write cache array
511                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: ".$data['ext_active']."");
512                 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
513         } else {
514                 // Extension not active!
515                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!");
516                 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
517         }
518
519         // Debug message
520         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.",active=".$data['ext_active']."");
521
522         // Is this extension activated? (For admins we always have active extensions...)
523         return ($data['ext_active'] == 'Y');
524 }
525
526 // Get version from extensions
527 function getExtensionVersion ($ext_name, $force = false) {
528         // By default no extension is found
529         $data['ext_version'] = 'false';
530
531         // Empty extension name should be fixed!
532         if (empty($ext_name)) {
533                 // Please report this bug!
534                 debug_report_bug(__FUNCTION__ . ': ext_name is empty which is not allowed here.');
535         } // END - if
536
537         // Extensions are all inactive during installation
538         if (isInstallationPhase()) return '';
539         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name=".$ext_name."");
540
541         // Is the cache written?
542         if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
543                 // Load data from cache
544                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': CACHE!');
545                 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
546
547                 // Count cache hits
548                 incrementStatsEntry('cache_hits');
549         } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != 0)) {
550                 // Load from database
551                 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
552                         array($ext_name), __FUNCTION__, __LINE__);
553                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': DB - '.SQL_NUMROWS($result).'');
554
555                 // Is the extension there?
556                 if (SQL_NUMROWS($result) == 1) {
557                         // Load entry
558                         $data = SQL_FETCHARRAY($result);
559                 } elseif (isDebugModeEnabled()) {
560                         // Not found, please report all
561                         debug_report_bug(sprintf(": Cannot find extension %s in database!", $ext_name));
562                 }
563
564                 // Free result
565                 SQL_FREERESULT($result);
566
567                 // Set cache
568                 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
569         }
570
571         // Extension version should not be invalid
572         if (($data['ext_version'] == 'false') && ($force === false)) {
573                 // Please report this trouble
574                 debug_report_bug(sprintf("Extension <strong>%s</strong> has empty version!", $ext_name));
575         } // END - if
576
577         // Return result
578         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$data['ext_version']}");
579         return $data['ext_version'];
580 }
581
582 // Updates a given extension with current extension version to latest version
583 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
584         // Only admins are allowed to update extensions
585         if ((!isAdmin()) || (empty($ext_name))) return false;
586
587         // Set current SQL name
588         setCurrentExtensionName($ext_name);
589
590         // Init arrays
591         initExtensionSqls();
592         initExtensionNotes();
593         initIncludePool('extension');
594
595         // Load extension in test mode
596         loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
597
598         // Save version history
599         $history = getExtensionVersionHistory();
600
601         // Remove old SQLs array to prevent possible bugs
602         initExtensionSqls();
603
604         // Check if version is updated
605         //* DEBUG: */ print getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)).'<br />';
606         if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
607                 // Search for starting point
608                 $start = array_search($ext_ver, $history);
609
610                 // And load SQL queries in order of version history
611                 for ($idx = ($start + 1); $idx < count($history); $idx++) {
612                         // Set extension version
613                         $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
614
615                         // Load again...
616                         loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
617
618                         // Get all depencies
619                         $depencies = getExtensionUpdateDependencies();
620
621                         // Nothing to apply?
622                         if (count($depencies) > 0) {
623                                 // Apply all extension depencies
624                                 foreach ($depencies as $ext_depend) {
625                                         // Did we already update/register this?
626                                         if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
627                                                 // Set it as current
628                                                 setCurrentExtensionName($ext_depend);
629
630                                                 // Mark it as already updated before we update it
631                                                 $GLOBALS['ext_updated'][$ext_depend] = true;
632
633                                                 // Is the extension there?
634                                                 if (isExtensionInstalled($ext_depend)) {
635                                                         // Update another extension first!
636                                                         $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
637                                                 } else {
638                                                         // Register new extension
639                                                         $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
640                                                 }
641                                         } // END - if
642                                 } // END - foreach
643
644                                 // Set name back
645                                 setCurrentExtensionName($ext_name);
646                         } // END - if
647
648                         // Add notes
649                         addExtensionNotes($history[$idx]);
650                 } // END - for
651
652                 // In real-mode execute any existing includes
653                 if (getExtensionDryRun() === false) {
654                         $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
655                         runFilterChain('load_includes', 'extension');
656                         setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
657                         unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
658                 } // END - if
659
660                 // Init these SQLs
661                 initSqls();
662                 setSqlsArray(getExtensionSqls());
663
664                 // Run SQLs
665                 runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
666
667                 if (getExtensionDryRun() === false) {
668                         // Run filters on success extension update
669                         runFilterChain('extension_update', getCurrentExtensionName());
670                 } // END - if
671         } // END - if
672 }
673
674 // Output verbose SQL table for extension
675 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
676         // Empty title?
677         if (empty($title)) {
678                 // Then fix it to default
679                 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
680         } // END - if
681
682         // Init variables
683         $OUT = '';
684
685         // Do we have queries?
686         if ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
687                 // Init switch color
688                 $SW = 2;
689
690                 // Get all SQLs
691                 foreach (getExtensionSqls() as $sqls) {
692                         // New array format is recursive
693                         foreach ($sqls as $idx => $sql) {
694                                 // Trim out spaces
695                                 $sql = trim($sql);
696
697                                 // Output command if set
698                                 if (!empty($sql)) {
699                                         // Prepare output for template
700                                         $content = array(
701                                                 'sw'  => $SW,
702                                                 'i'   => ($idx+1),
703                                                 'sql' => $sql
704                                         );
705
706                                         // Load row template
707                                         $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
708
709                                         // Switch color
710                                         $SW = 3 - $SW;
711                                 } // END - if
712                         } // END - foreach
713                 } // END - foreach
714
715                 // Prepare content for template
716                 $content = array(
717                         'width'  => $width,
718                         'dashed' => $dashed,
719                         'title'  => $title,
720                         'rows'   => $OUT
721                 );
722
723                 // Load main template
724                 $OUT = loadTemplate('admin_ext_sql_table', true, $content);
725         } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
726                 // No addional SQL commands to run
727                 $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
728         } // END - if
729
730         // Return output
731         return $OUT;
732 }
733
734 // Get extension name from id
735 function getExtensionName ($ext_id) {
736         // Init extension name
737         $data['ext_name'] = '';
738
739         // Is cache there?
740         if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
741                 // Load from cache
742                 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
743
744                 // Count cache hits
745                 incrementStatsEntry('cache_hits');
746         } elseif (!isExtensionActive('cache')) {
747                 // Load from database
748                 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
749                         array(bigintval($ext_id)), __FUNCTION__, __LINE__);
750
751                 // Is the entry there?
752                 if (SQL_NUMROWS($result) == 1) {
753                         // Get the extension's name from database
754                         $data = SQL_FETCHARRAY($result);
755                 } // END - if
756
757                 // Free result
758                 SQL_FREERESULT($result);
759         }
760
761         // Did we find some extension?
762         if (empty($data['ext_name'])) {
763                 // We should fix these all!
764                 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
765         } // END - if
766
767         // Return the extension name
768         return $data['ext_name'];
769 }
770
771 // Get extension id from name
772 function getExtensionId ($ext_name) {
773         // Init id number
774         $data['ext_id'] = '0';
775
776         // Do we have cache?
777         if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
778                 // Load from cache
779                 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
780
781                 // Count cache hits
782                 incrementStatsEntry('cache_hits');
783         } else {
784                 // Load from database
785                 $result = SQL_QUERY_ESC("SELECT `id` AS ext_id FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
786                         array($ext_name), __FUNCTION__, __LINE__);
787
788                 // Is the entry there?
789                 if (SQL_NUMROWS($result) == 1) {
790                         // Get the extension's id from database
791                         $data = SQL_FETCHARRAY($result);
792                 } // END - if
793
794                 // Free result
795                 SQL_FREERESULT($result);
796
797                 // Cache it
798                 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
799         }
800
801         // Return value
802         return $data['ext_id'];
803 }
804
805 // Determines wether the given extension name is valid
806 function isExtensionNameValid ($ext_name) {
807         // Do we have cache?
808         if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
809                 // Generate include file name
810                 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
811
812                 // Is there a file in inc/extensions/ ?
813                 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
814         } // END - if
815
816         // Return result
817         return $GLOBALS['ext_name_valid'][$ext_name];
818 }
819
820 // Determines wether the given extension id is valid
821 function isExtensionIdValid ($ext_id) {
822         // Default is nothing valid
823         $isValid = false;
824
825         // Check in cache then in database
826         if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
827                 // Valid!
828                 $isValid = true;
829
830                 // Count cache hits
831                 incrementStatsEntry('cache_hits');
832         } else {
833                 // Query database
834                 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
835         }
836
837         // Return result
838         return $isValid;
839 }
840
841 // Activate given extension
842 function doActivateExtension ($ext_name) {
843         // Activate the extension
844         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
845                 array($ext_name), __FUNCTION__, __LINE__);
846
847         // Extension has been activated?
848         if (SQL_AFFECTEDROWS() == 1) {
849                 // Then run all queries
850                 doExtensionSqls(getExtensionId($ext_name), 'activate');
851         } // END - if
852 }
853
854 // Deactivate given extension
855 function doDeactivateExtension($ext_name) {
856         // Activate the extension
857         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
858                 array($ext_name), __FUNCTION__, __LINE__);
859
860         // Extension has been activated?
861         if (SQL_AFFECTEDROWS() == 1) {
862                 // Then run all queries
863                 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
864
865                 // Create new task
866                 createExtensionDeactivationTask($ext_name);
867
868                 // Notify the admin
869                 sendAdminNotification(
870                         getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
871                         'admin_ext_deactivated',
872                         array('ext_name' => $ext_name)
873                 );
874         } // END - if
875 }
876
877 // Checks wether the extension is older than given
878 function isExtensionOlder ($ext_name, $ext_ver) {
879         // Get current extension version
880         $currVersion = getExtensionVersion($ext_name);
881
882         // Remove all dots from both versions
883         $currVersion = str_replace('.', '', $currVersion);
884         $ext_ver = str_replace('.', '', $ext_ver);
885
886         // Now compare both and return the result
887         return ($currVersion < $ext_ver);
888 }
889
890 // Creates a new task for updated extension
891 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
892         // Create subject line
893         $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
894
895         // Is the extension there?
896         if (isExtensionInstalled($ext_name)) {
897                 // Check if task is not there
898                 if (determineTaskIdBySubject($subject) == '0') {
899                         // Create extension update-task
900                         createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
901                 } // END - if
902         } else {
903                 // Extension not there! :-(
904                 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
905         }
906 }
907
908 // Creates a new task for newly installed extension
909 function createNewExtensionTask ($adminId, $subject, $ext) {
910         // Not installed and do we have created a task for the admin?
911         if ((determineTaskIdBySubject($subject) == '0') && (!isExtensionInstalled($ext))) {
912                 // Set default message if ext-foo is missing
913                 $message = getMaskedMessage('ADMIN_EXT_TEXT_FILE_MISSING', $ext);
914
915                 // Template file
916                 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
917                         getConfig('PATH'),
918                         getLanguage(),
919                         $ext
920                 );
921
922                 // Load text for task if found
923                 if (isFileReadable($tpl)) {
924                         // Load extension's own text template (HTML!)
925                         $message = loadTemplate('ext_' . $ext, true);
926                 } else {
927                         // Write this in debug.log as well
928                         logDebugMessage(__FUNCTION__, __LINE__, $message);
929                 }
930
931                 // Task not created so it's a brand-new extension which we need to register and create a task for!
932                 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
933         } // END - if
934 }
935
936 // Creates a task for automatically deactivated (deprecated) extension
937 function createExtensionDeactivationTask ($ext) {
938         // Create subject line
939         $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
940
941         // Not installed and do we have created a task for the admin?
942         if ((determineTaskIdBySubject($subject) == '0') && (getExtensionVersion($ext) != '')) {
943                 // Task not created so add it
944                 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
945         } // END - if
946 }
947
948 // Checks if the module has a menu
949 function ifModuleHasMenu ($mod, $forceDb = false) {
950         // All is false by default
951         $ret = false;
952
953         // Extension installed and newer than or has version 0.1.2?
954         if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
955                 // Cache version is okay, so let's check the cache!
956                 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
957                         // Check module cache and count hit
958                         $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
959                         incrementStatsEntry('cache_hits');
960                 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
961                         // Check cache and count hit
962                         $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
963                         incrementStatsEntry('cache_hits');
964                 } else {
965                         // Admin/guest/member/sponsor modules have always a menu!
966                         $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor'));
967                 }
968         } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
969                 // Check database for entry
970                 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
971                         array($mod), __FUNCTION__, __LINE__);
972
973                 // Entry found?
974                 if (SQL_NUMROWS($result) == 1) {
975                         // Load "has_menu" column
976                         $data = SQL_FETCHARRAY($result);
977
978                         // Fake cache... ;-)
979                         $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu'];
980
981                         // Does it have a menu?
982                         $ret = ($data['has_menu'] == 'Y');
983                 } // END  - if
984
985                 // Free memory
986                 SQL_FREERESULT($result);
987         } elseif (!isExtensionInstalled('sql_patches')) {
988                 // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered?
989                 $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu!
990         } else {
991                 // Unsupported state!
992                 logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached.');
993         }
994
995         // Return status
996         return $ret;
997 }
998
999 // Determines the task id for given extension
1000 function determineExtensionTaskId ($ext_name) {
1001         // Default is not found
1002         $data['task_id'] = '0';
1003
1004         // Search for extension task's id
1005         $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1006                 array($ext_name), __FUNCTION__, __LINE__);
1007
1008         // Entry found?
1009         if (SQL_NUMROWS($result) == 1) {
1010                 // Task found so load task's id and register extension...
1011                 $data = SQL_FETCHARRAY($result);
1012         } // END - if
1013
1014         // Free result
1015         SQL_FREERESULT($result);
1016
1017         // Return it
1018         return $data['task_id'];
1019 }
1020
1021 // Determines the task id for given subject
1022 function determineTaskIdBySubject ($subject) {
1023         // Default is not found
1024         $data['task_id'] = '0';
1025
1026         // Search for task id
1027         $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1028                 array($subject), __FUNCTION__, __LINE__);
1029
1030         // Entry found?
1031         if (SQL_NUMROWS($result) == 1) {
1032                 // Task found so load task's id and register extension...
1033                 $data = SQL_FETCHARRAY($result);
1034         } // END - if
1035
1036         // Free result
1037         SQL_FREERESULT($result);
1038
1039         // Return it
1040         return $data['task_id'];
1041 }
1042
1043 // Add updates notes for given version
1044 function addExtensionNotes ($ver) {
1045         // Init notes/content
1046         $out = ''; $content = array();
1047
1048         // Is do we have verbose output enabled?
1049         if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
1050                 // Update notes found?
1051                 if (getExtensionUpdateNotes($ver) != '') {
1052                         // Update notes found
1053                         $content = array(
1054                                 'ver'   => $ver,
1055                                 'notes' => getExtensionUpdateNotes($ver)
1056                         );
1057
1058                         // Reset them
1059                         setExtensionUpdateNotes('', $ver);
1060                 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1061                         // Initial release
1062                         $content = array(
1063                                 'ver'   => $ver,
1064                                 'notes' => getMessage('INITIAL_RELEASE')
1065                         );
1066                 } else {
1067                         // No update notes found!
1068                         $content = array(
1069                                 'ver'   => $ver,
1070                                 'notes' => getMessage('NO_UPDATE_NOTES')
1071                         );
1072                 }
1073
1074                 // Load template
1075                 $out = loadTemplate('admin_ext_notes', true, $content);
1076         } // END - if
1077
1078         // Add the notes
1079         appendExtensionNotes($out);
1080 }
1081
1082 // Getter for CSS files array
1083 function getExtensionCssFiles () {
1084         // By default no additional CSS files are found
1085         $cssFiles = array();
1086
1087         // Is the array there?
1088         if (isset($GLOBALS['css_files'])) {
1089                 // Then use it
1090                 $cssFiles = $GLOBALS['css_files'];
1091         } // END - if
1092
1093         // Return array
1094         return $cssFiles;
1095 }
1096
1097 // Init CSS files array
1098 function initExtensionCssFiles () {
1099         // Simply init it
1100         $GLOBALS['css_files'] = array();
1101 }
1102
1103 // Add new entry
1104 function addExtensionCssFile ($file) {
1105         // Is the array there?
1106         if (!isset($GLOBALS['css_files'])) {
1107                 // Then auto-init them
1108                 initExtensionCssFiles();
1109         } // END - if
1110
1111         // Add the entry
1112         $GLOBALS['css_files'][] = $file;
1113 }
1114
1115 // Setter for EXT_ALWAYS_ACTIVE flag
1116 function setExtensionAlwaysActive ($active) {
1117         $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1118 }
1119
1120 // Getter for EXT_ALWAYS_ACTIVE flag
1121 function getExtensionAlwaysActive () {
1122         return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1123 }
1124
1125 // Setter for EXT_VERSION flag
1126 function setThisExtensionVersion ($version) {
1127         $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1128 }
1129
1130 // Getter for EXT_VERSION flag
1131 function getThisExtensionVersion () {
1132         return $GLOBALS['ext_version'][getCurrentExtensionName()];
1133 }
1134
1135 // Setter for EXT_DEPRECATED flag
1136 function setExtensionDeprecated ($deprecated) {
1137         $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1138 }
1139
1140 // Getter for EXT_DEPRECATED flag
1141 function isExtensionDeprecated () {
1142         return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1143 }
1144
1145 // Setter for EXT_UPDATE_DEPENDS flag
1146 function addExtensionUpdateDependency ($updateDepends) {
1147         // Is the update depency empty? (NEED TO BE FIXED!)
1148         if (empty($updateDepends)) {
1149                 // Please report this bug!
1150                 debug_report_bug('updateDepends is left empty!');
1151         } // END - if
1152
1153         // Is it not yet added?
1154         if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1155                 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1156                 // Add it to the list of extension update depencies map
1157                 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1158
1159                 // Remember it in the list of running updates
1160                 $GLOBALS['ext_running_updates'][] = $updateDepends;
1161         } // END - if
1162 }
1163
1164 // Checks wether the given extension registration is in progress
1165 function isExtensionRegisterRunning ($ext_name) {
1166         return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1167 }
1168
1169 // Init EXT_UPDATE_DEPENDS flag
1170 function initExtensionUpdateDependencies () {
1171         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1172
1173         // Init update depency map automatically if not found
1174         if (!isExtensionUpdateDependenciesInitialized()) {
1175                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1176                 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1177         } // END - if
1178
1179         // Init running updates array
1180         initExtensionRuningUpdates();
1181 }
1182
1183 // Adds an extension as "registration in progress"
1184 function addExtensionRunningRegistration ($ext_name) {
1185         // Is it running?
1186         if (!isExtensionRegisterRunning($ext_name)) {
1187                 // Then add it!
1188                 $GLOBALS['ext_register_running'][] = $ext_name;
1189         } // END - if
1190 }
1191
1192 // Checks wether EXT_UPDATE_DEPENDS is initialized
1193 function isExtensionUpdateDependenciesInitialized () {
1194         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1195         return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1196 }
1197
1198 // Initializes the list of running updates
1199 function initExtensionRuningUpdates () {
1200         // Auto-init ext_running_updates
1201         if (!isset($GLOBALS['ext_running_updates'])) {
1202                 $GLOBALS['ext_running_updates'] = array();
1203                 $GLOBALS['ext_register_running'] = array();
1204         } // END - if
1205 }
1206
1207 // Getter for EXT_UPDATE_DEPENDS flag
1208 function getExtensionUpdateDependencies () {
1209         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1210         return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1211 }
1212
1213 // Getter for next iterator depency
1214 function getExtensionUpdateDependenciesIterator () {
1215         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1216         return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1217 }
1218
1219 // Counter for extension update depencies
1220 function countExtensionUpdateDependencies () {
1221         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1222         return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1223 }
1224
1225 // Removes given extension from update denpency list
1226 function removeExtensionUpdateDependency ($ext_name) {
1227         // Look it up
1228         $key = array_search($ext_name, getExtensionUpdateDependencies());
1229
1230         // Is it valid?
1231         if ($key !== false) {
1232                 // Then remove it
1233                 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1234
1235                 // And sort the array
1236                 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1237         } // END - if
1238 }
1239
1240 // Init iterator for update depencies
1241 function initExtensionUpdateIterator () {
1242         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1243         $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1244 }
1245
1246 // Getter for depency iterator
1247 function getExtensionUpdateIterator () {
1248         // Auto-init iterator
1249         if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1250
1251         // Return it
1252         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1253         return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1254 }
1255
1256 // Increments the update iterator
1257 function incrementExtensionUpdateIterator () {
1258         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1259         $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1260 }
1261
1262 // Setter for EXT_REPORTS_FAILURE flag
1263 function setExtensionReportsFailure ($reportsFailure) {
1264         $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1265 }
1266
1267 // Getter for EXT_REPORTS_FAILURE flag
1268 function getExtensionReportsFailure () {
1269         return $GLOBALS['ext_reports_failure'];
1270 }
1271
1272 // Setter for EXT_VER_HISTORY flag
1273 function setExtensionVersionHistory ($verHistory) {
1274         $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1275 }
1276
1277 // Getter for EXT_VER_HISTORY array
1278 function getExtensionVersionHistory () {
1279         return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1280 }
1281
1282 // Setter for EXT_UPDATE_NOTES
1283 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1284         //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1285         if (empty($ver)) {
1286                 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1287         } else {
1288                 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1289         }
1290 }
1291
1292 // Getter for EXT_UPDATE_NOTES
1293 function getExtensionUpdateNotes ($ver) {
1294         return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1295 }
1296
1297 // Init extension notice
1298 function initExtensionNotes () {
1299         $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1300 }
1301
1302 // Append extension notice
1303 function appendExtensionNotes ($notes) {
1304         $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1305 }
1306
1307 // Getter for extension notes
1308 function getExtensionNotes () {
1309         return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1310 }
1311
1312 // Setter for current extension name
1313 function setCurrentExtensionName ($ext_name) {
1314         $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1315 }
1316
1317 // Getter for current extension name
1318 function getCurrentExtensionName () {
1319         if (isset($GLOBALS['curr_ext_name'])) {
1320                 return $GLOBALS['curr_ext_name'];
1321         } // END - if
1322
1323         // Not set!
1324         debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1325 }
1326
1327 // Init SQLs array for current extension
1328 function initExtensionSqls () {
1329         // Auto-init the array now...
1330         if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1331                 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1332         } // END - if
1333 }
1334
1335 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1336 function addExtensionSql ($sql) {
1337         // Add it
1338         $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1339 }
1340
1341 // Getter for SQLs array for current extension
1342 function getExtensionSqls () {
1343         // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1344         if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1345                 // Not found, should not happen
1346                 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1347                         getCurrentExtensionName()
1348                 ));
1349         } // END - if
1350
1351         // Return the array
1352         return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1353 }
1354
1355 // Removes SQLs for current extension
1356 function unsetExtensionSqls () {
1357         unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1358 }
1359
1360 // Auto-initializes the removal list
1361 function initExtensionRemovalList () {
1362         // Is the remove list there?
1363         if (!isset($GLOBALS['ext_update_remove'])) {
1364                 // Then create it
1365                 $GLOBALS['ext_update_remove'] = array();
1366         } // END - if
1367 }
1368
1369 // Checks wether the current extension is on the removal list
1370 function isExtensionOnRemovalList () {
1371         // Init removal list
1372         initExtensionRemovalList();
1373
1374         // Is it there?
1375         return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1376 }
1377
1378 // Adds the current extension to the removal list
1379 function addCurrentExtensionToRemovalList () {
1380         // Simply add it
1381         $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1382 }
1383
1384 // Getter for removal list
1385 function getExtensionRemovalList () {
1386         // Return the removal list
1387         return $GLOBALS['ext_update_remove'];
1388 }
1389
1390 // Redirects if the provided extension is not installed
1391 function redirectOnUninstalledExtension ($ext_name) {
1392         // So is the extension there?
1393         if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1394                 // Redirect to index
1395                 redirectToUrl('modules.php?module=index&amp;code=' . getCode('EXTENSION_PROBLEM') . '&amp;ext=' . $ext_name);
1396         } // END - if
1397 }
1398
1399 // Filter for initialization of all extensions by loading them in 'init' mode
1400 function FILTER_INIT_EXTENSIONS () {
1401         // Do we have some entries?
1402         //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1403         if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1404                 // Load all found extensions if found
1405                 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1406                 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1407                         // Load it
1408                         //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1409                         loadExtension($ext_name, 'init');
1410                         //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1411                 } // END - foreach
1412                 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1413         } // END - if
1414         //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1415 }
1416
1417 // Setter for extension mode
1418 function setExtensionMode ($ext_mode) {
1419         $GLOBALS['ext_mode'] = (string) $ext_mode;
1420 }
1421
1422 // Getter for extension mode
1423 function getExtensionMode () {
1424         return $GLOBALS['ext_mode'];
1425 }
1426
1427 // Setter for dry-run
1428 function enableExtensionDryRun ($dry_run = true) {
1429         //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1430         $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1431 }
1432
1433 // Getter for dry-run
1434 function getExtensionDryRun () {
1435         return $GLOBALS['ext_dry_run'];
1436 }
1437
1438 // Setter for current extension version
1439 function setCurrentExtensionVersion ($ext_ver) {
1440         if (empty($ext_ver)) {
1441                 // 0.0 is okay here
1442                 $GLOBALS['ext_current_version'] = '0.0';
1443         } else {
1444                 // Add version
1445                 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1446         }
1447 }
1448
1449 // Getter for current extension version
1450 function getCurrentExtensionVersion () {
1451         return $GLOBALS['ext_current_version'];
1452 }
1453
1454 // Remove the extension from cache array
1455 function removeExtensionFromArray () {
1456         // "Cache" this name
1457         $ext_name = getCurrentExtensionName();
1458
1459         // Now loop through the whole cache
1460         foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1461                 // Is it an element?
1462                 if (isset($cacheArray[$ext_name])) {
1463                         // Array element
1464                         unset($cacheArray[$ext_name]);
1465                         $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1466                 } else {
1467                         // Maybe in array?
1468                         $key = array_search($ext_name, $cacheArray);
1469
1470                         // Is it there?
1471                         if ($key !== false) {
1472                                 // Found, so remove it
1473                                 unset($cacheArray[$key]);
1474                                 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1475                         } // END - if
1476                 }
1477         } // END - foreach
1478 }
1479
1480 // "Getter" for 'extension has a CSS file' (with same name, of course)
1481 function getExtensionHasCss () {
1482         // Default is no CSS
1483         $hasCss = 'N';
1484
1485         // Construct FQFN for check
1486         $FQFN = sprintf("%stheme/%s/css/%s.css",
1487                 getConfig('PATH'),
1488                 getCurrentTheme(),
1489                 getCurrentExtensionName()
1490         );
1491
1492         // Is it there?
1493         if (isFileReadable($FQFN)) {
1494                 // Readable, so it is there...
1495                 $hasCss = 'Y';
1496         } // END - if
1497
1498         // Return it
1499         return $hasCss;
1500 }
1501
1502 // Checks wether the given extension has a language file
1503 function ifExtensionHasLanguageFile ($ext_name) {
1504         // Default is no language file
1505         $hasLanguage = false;
1506
1507         // Do we have cache?
1508         if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1509                 // Then use it
1510                 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1511
1512                 // Count cache hits
1513                 incrementStatsEntry('cache_hits');
1514         } else {
1515                 // Not readable is default
1516                 $readable = 'N';
1517
1518                 // Is the language file readable for this extension?
1519                 if (isLanguageIncludeReadable($ext_name)) {
1520                         // Readable
1521                         $readable = 'Y';
1522                 } // END - if
1523
1524                 // Put it in cache
1525                 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1526         }
1527
1528         // Return result
1529         return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1530 }
1531
1532 // Load an extension's include file
1533 function loadExtensionInclude () {
1534         // Is it readable?
1535         if (!isExtensionIncludeReadable()) {
1536                 // Not readable
1537                 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1538         } // END - if
1539
1540         // Generate INC name
1541         $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1542
1543         // Load it
1544         loadInclude($INC);
1545 }
1546
1547 // Checks wether an extension is readable
1548 function isExtensionIncludeReadable ($ext_name = '') {
1549         // If empty, use current
1550         if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1551
1552         // Array found?
1553         if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1554                 // Generate INC name
1555                 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1556
1557                 // Is it readable?
1558                 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1559         } // END - if
1560
1561         // Return result
1562         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1563         return $GLOBALS['ext_inc_readable'][$ext_name];
1564 }
1565
1566 // Checks if an extension's function file is readable
1567 function isExtensionFunctionFileReadable ($ext_name) {
1568         if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1569                 // Just count cache hits
1570                 incrementStatsEntry('cache_hits');
1571         } else {
1572                 // Construct FQFN for functions file
1573                 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1574
1575                 // Is this include there?
1576                 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1577                         // Cache it!
1578                         $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1579                 } else {
1580                         // Cache it!
1581                         $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1582                 }
1583         }
1584
1585         // Return result
1586         return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1587 }
1588
1589 // Adds an admin menu to the SQL queue of the menu entry is not found
1590 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1591         // Now check if this menu is there
1592         if (!isMenuActionValid('admin', $action, $what)) {
1593                 // Is what null?
1594                 if (is_null($what)) {
1595                         // Add main menu
1596                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1597                                 $action,
1598                                 $title,
1599                                 $descr,
1600                                 bigintval($sort)
1601                         );
1602                 } else {
1603                         // Add sub menu
1604                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1605                                 $action,
1606                                 $what,
1607                                 $title,
1608                                 $descr,
1609                                 bigintval($sort)
1610                         );
1611                 }
1612
1613                 // Add it to the queue
1614                 addExtensionSql($sql);
1615         } elseif (isDebugModeEnabled()) {
1616                 // Double menus should be located and fixed!
1617                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what));
1618         }
1619 }
1620
1621 // Adds a guest menu to the SQL queue if the menu entry is not found
1622 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1623         // Now check if this menu is there
1624         if (!isMenuActionValid('guest', $action, $what)) {
1625                 // Is what null?
1626                 if (is_null($what)) {
1627                         // Add main menu
1628                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1629                                 $action,
1630                                 $title,
1631                                 $visible,
1632                                 $locked,
1633                                 bigintval($sort)
1634                         );
1635                 } else {
1636                         // Add sub menu
1637                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1638                                 $action,
1639                                 $what,
1640                                 $title,
1641                                 $visible,
1642                                 $locked,
1643                                 bigintval($sort)
1644                         );
1645                 }
1646
1647                 // Add it to the queue
1648                 addExtensionSql($sql);
1649         } elseif (isDebugModeEnabled()) {
1650                 // Double menus should be located and fixed!
1651                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what));
1652         }
1653 }
1654
1655 // Adds a member menu to the SQL queue if the menu entry is not found
1656 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1657         // Now check if this menu is there
1658         if (!isMenuActionValid('member', $action, $what)) {
1659                 // Is what null?
1660                 if (is_null($what)) {
1661                         // Add main menu
1662                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1663                                 $action,
1664                                 $title,
1665                                 $visible,
1666                                 $locked,
1667                                 bigintval($sort)
1668                         );
1669                 } else {
1670                         // Add sub menu
1671                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1672                                 $action,
1673                                 $what,
1674                                 $title,
1675                                 $visible,
1676                                 $locked,
1677                                 bigintval($sort)
1678                         );
1679                 }
1680
1681                 // Add it to the queue
1682                 addExtensionSql($sql);
1683         } elseif (isDebugModeEnabled()) {
1684                 // Double menus should be located and fixed!
1685                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what));
1686         }
1687 }
1688
1689 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1690 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1691         // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1692         if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1693                 // Is what null?
1694                 if (is_null($what)) {
1695                         // Add main menu
1696                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1697                                 $action,
1698                                 $title,
1699                                 $active,
1700                                 bigintval($sort)
1701                         );
1702                 } else {
1703                         // Add sub menu
1704                         $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1705                                 $action,
1706                                 $what,
1707                                 $title,
1708                                 $active,
1709                                 bigintval($sort)
1710                         );
1711                 }
1712
1713                 // Add it to the queue
1714                 addExtensionSql($sql);
1715         } elseif (isDebugModeEnabled()) {
1716                 // Double menus should be located and fixed!
1717                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what));
1718         }
1719 }
1720
1721 // Enables/disables productive mode for current extension (used only while
1722 // registration).
1723 function enableExtensionProductive ($isProductive = true) {
1724         $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1725 }
1726
1727 // Checks wether the extension is in productive phase. If not set, development
1728 // phase (=false) is assumed.
1729 function isExtensionProductive () {
1730         return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));
1731 }
1732
1733 // [EOF]
1734 ?>