2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/25/2009 *
4 * =================== Last change: 10/25/2009 *
6 * -------------------------------------------------------------------- *
7 * File : extensions-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Extension management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Erweiterungen-Management *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Load the extension and maybe found language and function files.
44 function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $isDryRun = false) {
45 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_mode=' . $ext_mode . ',ext_ver=' . $ext_ver . ',isDryRun=' . intval($isDryRun) . ' - 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));
53 // Make sure this situation can only happen once
54 $GLOBALS['loaded_extension'][$ext_name][$ext_mode] = true;
57 setExtensionMode($ext_mode);
59 // Set current extension name
60 setCurrentExtensionName($ext_name);
62 // By default all extensions are in productive phase
63 enableExtensionProductive();
65 if (!empty($ext_ver)) {
66 // Set current extension version
67 setCurrentExtensionVersion($ext_ver);
69 // Set it to 0.0 by default
70 setCurrentExtensionVersion('0.0.0');
72 // Is the extension installed?
73 if ((isExtensionInstalled($ext_name)) && ($ext_mode != 'register')) {
74 // Get extension's version
75 setCurrentExtensionVersion(getExtensionVersion($ext_name));
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.0 ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', isDryRun=' . intval($isDryRun));
86 enableExtensionDryRun($isDryRun);
89 initIncludePool('extension');
91 // Init EXT_UPDATE_DEPENDS if not yet done
92 if (!isExtensionUpdateDependenciesInitialized()) {
94 initExtensionUpdateDependencies();
97 // Init current extension name list
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')) {
104 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
110 // Is the extension file NOT there?
111 if (!isExtensionNameValid($ext_name)) {
113 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable or the PHP script is deprecated.", $ext_name));
119 // Load extension's own language file if not in test mode
120 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
122 loadLanguageFile($ext_name);
126 if (isExtensionFunctionFileReadable($ext_name)) {
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);
133 markExtensionLibraryAsLoaded($ext_name);
135 // Download functions file
136 loadIncludeOnce($funcsInclude);
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",
146 // Load extension's filter library if present
147 loadExtensionFilters($ext_name);
149 // Extensions are not deprecated by default
150 setExtensionDeprecated('N');
152 // Extensions are not always active by default
153 setExtensionAlwaysActive('N');
155 // Include the extension file
156 loadCurrentExtensionInclude();
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);
164 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name . ' - Extension is deprecated.');
168 // Mark it as loaded in normal mode
169 if (getExtensionMode() == '') {
171 markExtensionAsLoaded($ext_name);
175 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension successfully loaded, ext_name=' . $ext_name);
179 // Registers an extension and possible update dependencies
180 function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdates = false) {
181 // Set current extension name
182 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . intval($taskId) . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!');
183 setCurrentExtensionName($ext_name);
186 enableExtensionDryRun($isDryRun);
188 // By default all extensions are in productive phase
189 enableExtensionProductive();
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)));
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 . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates));
202 //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!');
206 // This registration is running
207 addExtensionRunningRegistration($ext_name);
209 // Init EXT_UPDATE_DEPENDS if not yet done
210 if (!isExtensionUpdateDependenciesInitialized()) {
212 initExtensionUpdateDependencies();
215 // Is the task id zero? Then we need to auto-fix it here
216 if (((is_null($taskId)) || ($taskId == '0')) && (!isInstallationPhase())) {
217 // Try to find the task
218 $taskId = determineExtensionTaskId(getCurrentExtensionName());
220 // Still zero and not in dry-run?
221 if (((is_null($taskId)) || ($taskId == '0')) && (!isExtensionDryRun())) {
222 // Now try to create a new task
223 $taskId = createNewExtensionTask(getCurrentExtensionName());
226 if ((is_null($taskId)) || ($taskId == '0')) {
227 // Then request a bug report
228 reportBug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
230 getCurrentExtensionName()
236 // Init queries and notes
238 initExtensionNotes();
242 $processResult = false;
243 initIncludePool('extension');
245 // By default we have no failures
246 enableExtensionReportingFailure();
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);
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());
262 // Add update notes to our output
263 addExtensionNotes($ext_ver);
266 // Does this extension depends on an outstanding update of another update?
267 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
269 $ext_update = getExtensionUpdateDependenciesIterator();
271 // Increment here to avoid endless loop
272 incrementExtensionUpdateIterator();
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);
280 // If versions mismatch update extension first
282 if (isExtensionInstalled($ext_update)) {
283 // Get version only if installed
284 $ext_ver = getExtensionVersion($ext_update);
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 $updateTaskId = determineExtensionTaskId($ext_update);
294 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updateTaskId=' . $updateTaskId . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - CHECKING!');
295 if (($updateTaskId > 0) || (isInstallationPhase())) {
296 // Try to register the extension
297 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',updateTaskId=' . $updateTaskId . ',isExtensionDryRun()=' . intval(isExtensionDryRun()));
298 $processResult = registerExtension($ext_update, $updateTaskId, isExtensionDryRun(), true);
300 // Reset extension name
301 setCurrentExtensionName($ext_name);
302 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',processResult=' . intval($processResult));
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());
317 $processResult = true;
319 // Nothing to register / update before...
320 $processResult = true;
323 // Required file for update does not exists!
324 $processResult = true;
325 // But this is fine for the first time...
328 // Restore the current extension name
329 setCurrentExtensionName($ext_name);
332 // Is there no update?
333 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
334 // Then test is passed!
335 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=true,countExtensionUpdateDependencies()=0 - Test passed!');
336 $processResult = true;
339 // Switch back to register mode
340 setExtensionMode('register');
342 // Remains true if extension registration reports no failures
343 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
344 $processResult = (($processResult === true) && (isExtensionReportingFailure() === false));
345 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
347 // Does everthing before wents ok?
348 if ($processResult === true) {
349 // "Dry-run-mode" activated?
350 if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
351 // Init SQLs and transfer ext->generic
352 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
354 setSqlsArray(getExtensionSqls());
356 // Run installation pre-installation filters
357 runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
359 // Register extension
360 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
361 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
363 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
364 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
366 getCurrentExtensionName(),
367 getThisExtensionAlwaysActive(),
368 getCurrentExtensionVersion(),
370 ), __FUNCTION__, __LINE__);
373 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
374 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`) VALUES ('%s','%s','%s')",
376 getCurrentExtensionName(),
377 getThisExtensionAlwaysActive(),
378 getCurrentExtensionVersion()
379 ), __FUNCTION__, __LINE__);
382 // Use the insert id as extension id and cache it for early usage
383 $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
384 $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
386 // Mark it as installed
387 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
389 // Remove cache file(s) if extension is active
390 runFilterChain('post_extension_installed', array(
391 'pool' => 'extension',
392 'ext_name' => getCurrentExtensionName(),
396 // Re-init queries and notes
397 initExtensionSqls(true);
398 initExtensionNotes(true);
400 // In normal mode return a true on success
402 } elseif (isExtensionDryRun() === true) {
403 // In "dry-run" mode do always return a true
406 // Extension has been removed for updates, so all is fine!
410 // No, an error occurs while registering extension :-(
411 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
414 } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
415 // Remove task from system when id and extension's name is valid
416 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
417 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
418 array(bigintval($taskId)), __FUNCTION__, __LINE__);
421 // @TODO This redirect is still needed to register sql_patches! Please try to avoid it
422 if (($ret === true) && ($isDryRun === false) && ($ext_name == 'sql_patches') && (!isInstallationPhase())) {
424 * This is a really dirty hack to prevent an error about a missing
425 * configuration entry which should be there after registration of
428 redirectToRequestUri();
431 // Return status code
432 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult) . ',ret=' . intval($ret) . ' - EXIT!');
436 // Run SQL queries for given extension id
437 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
438 function doExtensionSqls ($ext_id, $load_mode) {
439 // This shall never do a non-admin user but installation phase is okay
440 if ((!isAdmin()) && (!isInstallationPhase())) {
441 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_id=' . $ext_id. ',load_mode=' . $load_mode . ',isAdmin()=' . intval(isAdmin()) . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ' - ABORT!');
445 // Get extension's name
446 $ext_name = getExtensionName($ext_id);
448 // Set current SQL name
449 setCurrentExtensionName($ext_name);
451 // Init EXT_UPDATE_DEPENDS
452 if (!isExtensionUpdateDependenciesInitialized()) {
454 initExtensionUpdateDependencies();
458 initExtensionSqls(true);
460 // By default no SQL has been executed
463 // Load extension in detected mode
464 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name[' . $ext_id . ']=' . getCurrentExtensionName() . ',load_mode=' . $load_mode);
465 loadExtension(getCurrentExtensionName(), $load_mode, '0.0.0', false);
469 setSqlsArray(getExtensionSqls());
472 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls());
474 // Do we have entries?
476 // Run SQL commands...
477 runFilterChain('run_sqls');
480 // Run any filters depending on the action here
481 runFilterChain('extension_' . $load_mode);
483 // Remove cache file(s) if extension is active
484 if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED()) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate')))) {
486 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
489 // Is this the sql_patches?
490 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $ext_id . ',currName=' . getCurrentExtensionName() . ',loadMode=' . $load_mode);
491 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
492 // Then redirect to logout
493 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': LOAD!');
494 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
498 // Check whether the given extension is installed
499 function isExtensionInstalled ($ext_name) {
500 // We don't like empty extension names here
501 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
502 if (empty($ext_name)) {
503 // Please fix them all
504 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty.');
507 // By default non is installed
508 $isInstalled = false;
510 // Check if there is a cache entry
511 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
512 // Use cache built from below queries
513 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
514 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
515 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
517 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - FOUND!');
521 incrementStatsEntry('cache_hits');
522 } elseif (isInstallationPhase()) {
523 // Extensions are all inactive/not installed during installation
524 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - installation phase detected.');
527 $ext_id = getExtensionId($ext_name);
529 // Do we have a record?
530 $isInstalled = ($ext_id > 0);
533 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_id=' . $ext_id . ',isInstalled=' . intval($isInstalled));
535 // Is it installed, then cache the entry
536 if ($isInstalled === true) {
537 // Dummy call (get is okay here)
538 getExtensionId($ext_name, true);
541 // Remember the status
542 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
546 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isInstalled=' . intval($isInstalled) . ' - EXIT!');
550 // Check if given extension is active
551 function isExtensionActive ($ext_name) {
552 if (isInstallationPhase()) {
553 // Extensions are all inactive during installation
554 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extensions are always inactive while installation phase. ext_name=' . $ext_name);
556 } elseif (empty($ext_name)) {
557 // Empty extension names must befixed
558 reportBug(__FUNCTION__, __LINE__, 'Empty extension name provided.');
559 } elseif (!isExtensionInstalled($ext_name)) {
560 // Not installed extensions are always inactive
561 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not installed extensions are always inactive. ext_name=' . $ext_name);
565 // Not active is the default
566 $data['ext_active'] = 'N';
569 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
571 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE! ext_name=' . $ext_name);
572 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
575 incrementStatsEntry('cache_hits');
576 } elseif (isExtensionLoaded($ext_name)) {
577 // @TODO Extension is loaded, what next?
578 reportBug(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
579 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
580 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DB! ext_name=' . $ext_name);
581 // Load from database
582 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
583 array($ext_name), __FUNCTION__, __LINE__);
586 if (SQL_NUMROWS($result) == 1) {
588 $data = SQL_FETCHARRAY($result);
592 SQL_FREERESULT($result);
595 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . '[DB]: ' . $data['ext_active']);
596 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
598 // Extension not active!
599 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': Not active!');
600 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
604 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',active=' . $data['ext_active']);
606 // Is this extension activated? (For admins we always have active extensions...)
607 return ($data['ext_active'] == 'Y');
610 // Get version from extensions
611 function getExtensionVersion ($ext_name, $force = false) {
612 // By default no extension is found
613 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
614 $data['ext_version'] = 'false';
616 // Empty extension name should be fixed!
617 if (empty($ext_name)) {
618 // Please report this bug!
619 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty which is not allowed here.');
622 // Extensions are all inactive during installation
623 if (isInstallationPhase()) {
624 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',force=' . intval($force) . ' - Installation phase detected, returning empty version.');
628 // Is the cache written?
629 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - Checking cache ...');
630 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
631 // Load data from cache
632 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
633 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
636 incrementStatsEntry('cache_hits');
637 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (!isHtmlOutputMode())) {
638 // Load from database
639 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
640 array($ext_name), __FUNCTION__, __LINE__);
641 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': DB - '.SQL_NUMROWS($result).'');
643 // Is the extension there?
644 if (SQL_NUMROWS($result) == 1) {
646 $data = SQL_FETCHARRAY($result);
649 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
650 } elseif (isDebugModeEnabled()) {
651 // Not found, may happen while an extension is uninstalled
652 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot find extension %s in database!", $ext_name));
656 SQL_FREERESULT($result);
659 // Extension version should not be invalid
660 if (($data['ext_version'] == 'false') && ($force === false)) {
661 // Please report this trouble
662 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> has empty version!", $ext_name));
666 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_version=' . $data['ext_version']);
667 return $data['ext_version'];
670 // Updates a given extension with current extension version to latest version
671 function updateExtension ($ext_name, $ext_ver, $isDryRun = false, $ignoreDependencies = false) {
672 // Only admins are allowed to update extensions
673 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',isDryRun=' . intval($isDryRun) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
674 if ((!isAdmin()) || (empty($ext_name))) {
675 // Called as non-admin or empty extension
676 reportBug(__FUNCTION__, __LINE__, 'Called as non-admin (isAdmin()=' . intval(isAdmin()) . '), or empty extension name. ext_name=' . $ext_name);
679 // Set current SQL name
680 setCurrentExtensionName($ext_name);
682 // Is this extension update already running?
683 if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($isDryRun === false)) {
684 // This is fine but needs logging ATM
685 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
686 //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, please investigate!');
692 initExtensionNotes();
693 initIncludePool('extension');
695 // Load extension in test mode
696 loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
698 // Save version history
699 $history = getExtensionVersionHistory();
701 // Remove old SQLs array to prevent possible bugs
704 // Check if version is updated
705 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, getCurrentExtensionName() . '/' . $ext_name . ':' . getThisExtensionVersion() . '/' . $ext_ver . '/' . intval(is_array($history)));
706 if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
707 // Search for starting point (-1 for making 0.0 -> 0.0.0 switch work)
709 if ($ext_ver != '0.0') {
710 $start = array_search($ext_ver, $history);
713 // And load SQL queries in order of version history
714 for ($idx = ($start + 1); $idx < count($history); $idx++) {
715 // Set extension version
716 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
719 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
722 $depencies = getExtensionUpdateDependencies();
725 if (count($depencies) > 0) {
726 // Apply all extension depencies
727 foreach ($depencies as $ext_depend) {
728 // Did we already update/register this?
729 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
731 setCurrentExtensionName($ext_depend);
733 // Mark it as already updated before we update it
734 $GLOBALS['ext_updated'][$ext_depend] = true;
736 // Is the extension there?
737 if (isExtensionInstalled($ext_depend)) {
738 // Update another extension first!
739 $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun(), true);
741 // Register new extension
742 $processResult = registerExtension($ext_depend, NULL, isExtensionDryRun());
748 setCurrentExtensionName($ext_name);
750 // Set extension version here
751 setCurrentExtensionVersion($ext_ver);
755 addExtensionNotes($history[$idx]);
758 // In real-mode execute any existing includes
759 if (isExtensionDryRun() === false) {
760 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
761 runFilterChain('load_includes', 'extension');
762 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
763 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
768 setSqlsArray(getExtensionSqls());
771 runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
773 if (isExtensionDryRun() === false) {
774 // Run filters on success extension update
775 runFilterChain('extension_update', getCurrentExtensionName());
779 //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',isDryRun=' . intval($isDryRun) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!');
782 // Output verbose SQL table for extension
783 function addExtensionVerboseSqlTable ($title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}') {
787 reportBug(__FUNCTION__, __LINE__, 'title is empty.');
793 // Do we have queries?
794 if (isVerboseSqlEnabled()) {
795 // Do we have entries?
796 if (countExtensionSqls() > 0) {
800 foreach (getExtensionSqls() as $sqls) {
801 // New array format is recursive
802 foreach ($sqls as $sql) {
806 // Output command if set
808 // Prepare output for template
811 'sql' => str_replace(array('{', '}'), array('{', '}'), encodeEntities($sql))
815 $OUT .= loadTemplate('admin_extension_sql_row', true, $content);
823 // Prepare content for template
829 // Load main template
830 $OUT = loadTemplate('admin_extension_sql_table', true, $content);
832 // No addional SQL commands to run
833 $OUT = displayMessage('{--ADMIN_EXTENSION_VERBOSE_SQLS_404--}', true);
841 // Get extension name from id
842 function getExtensionName ($ext_id) {
843 // Init extension name
844 $data['ext_name'] = '';
847 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
849 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
852 incrementStatsEntry('cache_hits');
853 } elseif (!isExtensionActive('cache')) {
854 // Load from database
855 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
856 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
858 // Is the entry there?
859 if (SQL_NUMROWS($result) == 1) {
860 // Get the extension's name from database
861 $data = SQL_FETCHARRAY($result);
865 SQL_FREERESULT($result);
868 // Did we find some extension?
869 if (empty($data['ext_name'])) {
870 // We should fix these all!
871 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty. ext_id=' . $ext_id);
874 // Return the extension name
875 return $data['ext_name'];
878 // Get extension id from name
879 function getExtensionId ($ext_name) {
881 $data['ext_id'] = '0';
884 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
886 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
889 incrementStatsEntry('cache_hits');
891 // Load from database
892 $result = SQL_QUERY_ESC("SELECT `id` AS `ext_id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
893 array($ext_name), __FUNCTION__, __LINE__);
895 // Is the entry there?
896 if (SQL_NUMROWS($result) == 1) {
897 // Get the extension's id from database
898 $data = SQL_FETCHARRAY($result);
902 SQL_FREERESULT($result);
905 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
909 return $data['ext_id'];
912 // Determines whether the given extension name is valid
913 function isExtensionNameValid ($ext_name) {
915 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
916 // Generate include file name
917 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
919 // Is there a file in inc/extensions/ ?
920 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
924 return $GLOBALS['ext_name_valid'][$ext_name];
927 // Determines whether the given extension id is valid
928 function isExtensionIdValid ($ext_id) {
929 // Default is nothing valid
932 // Check in cache then in database
933 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
938 incrementStatsEntry('cache_hits');
941 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
948 // Activate given extension
949 function doActivateExtension ($ext_name) {
950 // Is the extension installed?
951 if (!isExtensionInstalled($ext_name)) {
952 // Non-installed extensions cannot be activated
953 reportBug(__FUNCTION__, __LINE__, 'Tried to activate non-installed extension ' . $ext_name);
956 // Activate the extension
957 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
958 array($ext_name), __FUNCTION__, __LINE__);
960 // Then run all queries
961 doExtensionSqls(getExtensionId($ext_name), 'activate');
964 // Deactivate given extension
965 function doDeactivateExtension ($ext_name, $inRebuild = false) {
966 // Is the extension installed?
967 if (!isExtensionInstalled($ext_name)) {
968 // Non-installed extensions cannot be activated
969 reportBug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name . ',getExtensionMode()=' . getExtensionMode());
972 // Activate the extension
973 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
974 array($ext_name), __FUNCTION__, __LINE__);
976 // Then run all queries
977 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
979 // Create new task (we ignore the task id here)
980 createExtensionDeactivationTask($ext_name);
982 // Do not rebuild cache if it is already been rebuild
983 if ($inRebuild === false) {
985 rebuildCache('extension', 'extension');
989 sendAdminNotification(
990 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
991 'admin_extension_deactivated',
992 array('ext_name' => $ext_name)
996 // Checks whether the extension is older than given
997 function isExtensionOlder ($ext_name, $ext_ver) {
998 // Get current extension version
999 $currVersion = getExtensionVersion($ext_name);
1001 // Remove all dots from both versions
1002 $currVersion = str_replace('.', '', $currVersion);
1003 $ext_ver = str_replace('.', '', $ext_ver);
1005 // Now compare both and return the result
1006 return ($currVersion < $ext_ver);
1009 // Creates a new task for updated extension
1010 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
1011 // Create subject line
1012 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
1015 $taskId = determineTaskIdBySubject($subject);
1017 // Is the extension there?
1018 if (isExtensionInstalled($ext_name)) {
1019 // Check if task is not there
1020 if ($taskId == '0') {
1021 // Create extension update-task
1022 $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
1025 // Extension not there! :-(
1026 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1033 // Creates a new task for newly installed extension
1034 function createNewExtensionTask ($ext_name) {
1035 // Generate subject line
1036 $subject = sprintf("[%s:]", $ext_name);
1039 $taskId = determineTaskIdBySubject($subject);
1041 // Not installed and do we have created a task for the admin?
1042 if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1043 // Set default message if ext-foo is missing
1044 $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
1047 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1053 // Load text for task if found
1054 if (isFileReadable($FQFN)) {
1055 // Load extension's description template (but do not compile the code)
1056 $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1058 // Write this in debug.log as well
1059 logDebugMessage(__FUNCTION__, __LINE__, $message);
1062 // Task not created so it's a brand-new extension which we need to register and create a task for!
1063 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1070 // Creates a task for automatically deactivated (deprecated) extension
1071 function createExtensionDeactivationTask ($ext_name) {
1072 // Create subject line
1073 $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1076 $taskId = determineTaskIdBySubject($subject);
1078 // Not installed and do we have created a task for the admin?
1079 if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1080 // Task not created so add it
1081 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1088 // Determines the task id for given extension
1089 function determineExtensionTaskId ($ext_name) {
1090 // Is it installation phase and table task_system is not found?
1091 if ((isInstallationPhase()) && (!ifSqlTableExists('task_system'))) {
1092 // Then return NULL (not found)
1096 // Default is not found
1097 $data['task_id'] = NULL;
1099 // Search for extension task's id
1100 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1101 array($ext_name), __FUNCTION__, __LINE__);
1104 if (SQL_NUMROWS($result) == 1) {
1105 // Task found so load task's id and register extension...
1106 $data = SQL_FETCHARRAY($result);
1110 SQL_FREERESULT($result);
1113 return $data['task_id'];
1116 // Determines the task id for given subject
1117 function determineTaskIdBySubject ($subject) {
1118 // Default is not found
1119 $data['task_id'] = '0';
1121 // Search for task id
1122 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1123 array($subject), __FUNCTION__, __LINE__);
1126 if (SQL_NUMROWS($result) == 1) {
1127 // Task found so load task's id and register extension...
1128 $data = SQL_FETCHARRAY($result);
1132 SQL_FREERESULT($result);
1135 return $data['task_id'];
1138 // Add updates notes for given version
1139 function addExtensionNotes ($ext_ver) {
1140 // Init notes/content
1144 // Is do we have verbose output enabled?
1145 if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1146 // Update notes found?
1147 if ((isExtensionUpdateNoteSet($ext_ver)) && ($ext_ver != '0.0.0')) {
1148 // Update notes found
1151 'notes' => getExtensionUpdateNotes($ext_ver)
1155 setExtensionUpdateNotes('', $ext_ver);
1156 } elseif ($ext_ver == '0.0.0') {
1157 // Is the extension productive?
1158 if (isExtensionProductive(getCurrentExtensionName())) {
1162 'notes' => '{--INITIAL_RELEASE--}'
1168 'notes' => '{--DEVELOPER_RELEASE--}'
1172 // No update notes found
1175 'notes' => '{--NO_UPDATE_NOTICES--}'
1180 $out = loadTemplate('admin_extension_notes', true, $content);
1184 appendExtensionNotes($out);
1187 // Getter for CSS files array
1188 function getExtensionCssFiles () {
1189 // By default no additional CSS files are found
1190 $cssFiles = array();
1192 // Is the array there?
1193 if (isset($GLOBALS['css_files'])) {
1195 $cssFiles = $GLOBALS['css_files'];
1202 // Init CSS files array
1203 function initExtensionCssFiles () {
1205 $GLOBALS['css_files'] = array();
1209 function addExtensionCssFile ($file) {
1210 // Is the array there?
1211 if (!isset($GLOBALS['css_files'])) {
1212 // Then auto-init them
1213 initExtensionCssFiles();
1217 array_push($GLOBALS['css_files'], $file);
1220 // Setter for EXT_ALWAYS_ACTIVE flag
1221 function setExtensionAlwaysActive ($active) {
1222 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1225 // Getter for EXT_ALWAYS_ACTIVE flag
1226 function getThisExtensionAlwaysActive () {
1227 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1230 // Checks whether the current extension is always active
1231 function isThisExtensionAlwaysActive () {
1232 return (getThisExtensionAlwaysActive() == 'Y');
1235 // Setter for EXT_VERSION flag
1236 function setThisExtensionVersion ($ext_version) {
1237 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1240 // Getter for EXT_VERSION flag
1241 function getThisExtensionVersion () {
1242 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1245 // Setter for EXT_DEPRECATED flag
1246 function setExtensionDeprecated ($deprecated) {
1247 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1250 // Getter for EXT_DEPRECATED flag
1251 function isExtensionDeprecated ($ext_name = NULL) {
1252 // Default is from current (NULL) extension
1253 $isDeprecated = ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1256 if (!is_null($ext_name)) {
1257 // Then use it instead
1258 $isDeprecated = ((isset($GLOBALS['ext_deprecated'][$ext_name])) && ($GLOBALS['ext_deprecated'][$ext_name] == 'Y'));
1262 return $isDeprecated;
1265 // Setter for EXT_UPDATE_DEPENDS flag
1266 function addExtensionDependency ($updateDepends) {
1267 // Is the update depency empty? (NEED TO BE FIXED!)
1268 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - ENTERED!');
1269 if (empty($updateDepends)) {
1270 // Please report this bug!
1271 reportBug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1274 // Is it not yet added?
1275 if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1277 * Double-adding happens when the extension and an update of the same
1278 * extension requires the same other extension again.
1280 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
1284 // Add it to the list of extension update depencies map
1285 array_push($GLOBALS['ext_update_depends'][getCurrentExtensionName()], $updateDepends);
1288 if ((!isset($GLOBALS['ext_running_updates'][getCurrentExtensionName()])) || (!is_array($GLOBALS['ext_running_updates'][getCurrentExtensionName()]))) {
1289 $GLOBALS['ext_running_updates'][getCurrentExtensionName()] = array();
1292 // Remember it in the list of running updates
1293 array_push($GLOBALS['ext_running_updates'][getCurrentExtensionName()], $updateDepends);
1294 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - EXIT!');
1297 // Getter for running updates
1298 function getExtensionUpdatesRunning () {
1299 return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1302 // Checks whether the given extension registration is in progress
1303 function isExtensionRegistrationRunning ($ext_name) {
1305 $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1308 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1312 // Init EXT_UPDATE_DEPENDS flag
1313 function initExtensionUpdateDependencies () {
1314 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1316 // Init update depency map automatically if not found
1317 if (isExtensionUpdateDependenciesInitialized()) {
1318 // We need these bug reports as well...
1319 reportBug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1322 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1324 // Init running updates array
1325 initExtensionRuningUpdates();
1327 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1330 // Adds an extension as "registration in progress"
1331 function addExtensionRunningRegistration ($ext_name) {
1333 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1334 if (isExtensionRegistrationRunning($ext_name)) {
1335 // This is really bad and should not be quietly ignored
1336 reportBug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1340 array_push($GLOBALS['ext_register_running'], $ext_name);
1341 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1344 // Checks whether EXT_UPDATE_DEPENDS is initialized
1345 function isExtensionUpdateDependenciesInitialized () {
1346 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1347 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1350 // Checks whether an update is already running for given extension
1351 function isExtensionUpdateRunning ($ext_name, $ignoreDependencies = false) {
1352 // Current and given extensions means whole array
1353 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
1354 if ($ext_name == getCurrentExtensionName()) {
1355 // Default is not found
1358 // Walk through whole array
1359 foreach ($GLOBALS['ext_running_updates'] as $ext1 => $depends) {
1361 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',depends=' . print_r($depends, true));
1362 if (($ext1 == $ext_name) || ((in_array($ext_name, $depends)) && ($ignoreDependencies === false))) {
1365 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=true - FOUND!');
1371 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - ALT-EXIT!');
1376 $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1379 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - EXIT!');
1383 // Initializes the list of running updates
1384 function initExtensionRuningUpdates () {
1385 // Auto-init ext_running_updates
1386 if (!isset($GLOBALS['ext_running_updates'])) {
1387 $GLOBALS['ext_running_updates'] = array();
1388 $GLOBALS['ext_register_running'] = array();
1392 // Getter for EXT_UPDATE_DEPENDS flag
1393 function getExtensionUpdateDependencies () {
1394 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1395 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1398 // Getter for next iterator depency
1399 function getExtensionUpdateDependenciesIterator () {
1400 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1401 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1404 // Counter for extension update depencies
1405 function countExtensionUpdateDependencies () {
1406 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1407 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1410 // Removes given extension from update denpency list
1411 function removeExtensionDependency ($ext_name) {
1413 $key = array_search($ext_name, getExtensionUpdateDependencies());
1416 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',key[' . gettype($key) . ']=' . $key);
1419 if ($key !== false) {
1421 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1423 // And sort the array
1424 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1428 // Init iterator for update depencies
1429 function initExtensionUpdateIterator () {
1430 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1431 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1434 // Getter for depency iterator
1435 function getExtensionUpdateIterator () {
1436 // Auto-init iterator
1437 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) {
1438 // Initialize update iterator
1439 initExtensionUpdateIterator();
1443 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1444 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1447 // Increments the update iterator
1448 function incrementExtensionUpdateIterator () {
1449 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1450 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1453 // Setter for EXT_REPORTS_FAILURE flag
1454 function enableExtensionReportingFailure ($reportsFailure = false) {
1455 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1458 // Getter for EXT_REPORTS_FAILURE flag
1459 function isExtensionReportingFailure () {
1460 return $GLOBALS['ext_reports_failure'];
1463 // Setter for EXT_VER_HISTORY flag
1464 function setExtensionVersionHistory ($versionHistory) {
1465 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1468 // Getter for EXT_VER_HISTORY array
1469 function getExtensionVersionHistory () {
1471 if (!isset($GLOBALS['ext_ver_history'][getCurrentExtensionName()])) {
1472 // Then abort here to a avoid an ugly "Undefined index" error
1473 reportBug(__FUNCTION__, __LINE__, 'Extension ext-' . getCurrentExtensionName() . ' has no history set! Is this extension empty?');
1476 // Return the history
1477 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1480 // Setter for EXT_UPDATE_NOTICES
1481 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1483 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . '/' . getCurrentExtensionVersion() . ',updateNotes(length)=' . strlen($updateNotes));
1484 if (empty($ext_ver)) {
1485 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1487 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1491 // Getter for EXT_UPDATE_NOTICES
1492 function getExtensionUpdateNotes ($ext_ver) {
1493 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1496 // Checks if ext_update_notes is set
1497 function isExtensionUpdateNoteSet ($ext_ver) {
1498 return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1501 // Init extension notice
1502 function initExtensionNotes ($force = false) {
1503 // Is it already initialized?
1504 if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1505 // This is mostly not wanted, so please report it
1506 reportBug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1509 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1510 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1513 // Append extension notice
1514 function appendExtensionNotes ($notes) {
1515 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes(length)=' . strlen($notes));
1516 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1519 // Getter for extension notes
1520 function getExtensionNotes () {
1521 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1524 // Setter for current extension name
1525 function setCurrentExtensionName ($ext_name) {
1526 $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1529 // Getter for current extension name
1530 function getCurrentExtensionName () {
1531 if (!isset($GLOBALS['curr_extension_name'])) {
1533 reportBug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1537 return $GLOBALS['curr_extension_name'];
1540 // Init SQLs array for current extension
1541 function initExtensionSqls ($force = false) {
1542 // Auto-init the array or if forced
1543 if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1545 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1547 // Initialize the generic array
1552 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1553 function addExtensionSql ($sql) {
1554 // Is is the array there?
1555 if ((!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()])) || (!is_array($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()]))) {
1557 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()] = array();
1561 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1562 array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql);
1565 // Getter for SQLs array for current extension
1566 function getExtensionSqls () {
1567 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1568 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1569 // Not found, should not happen
1570 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1571 getCurrentExtensionName()
1576 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1579 // Count SQLs for current extension
1580 function countExtensionSqls () {
1581 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1582 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1583 // Not found, should not happen
1584 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1585 getCurrentExtensionName()
1590 return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1593 // Removes SQLs for current extension
1594 function unsetExtensionSqls () {
1595 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1598 // Auto-initializes the removal list
1599 function initExtensionRemovalList () {
1600 // Is the remove list there?
1601 if (!isset($GLOBALS['ext_update_remove'])) {
1603 $GLOBALS['ext_update_remove'] = array();
1607 // Checks whether the current extension is on the removal list
1608 function isExtensionOnRemovalList () {
1609 // Init removal list
1610 initExtensionRemovalList();
1613 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1616 // Adds the current extension to the removal list
1617 function addCurrentExtensionToRemovalList () {
1619 array_push($GLOBALS['ext_update_remove'], getCurrentExtensionName());
1622 // Getter for removal list
1623 function getExtensionRemovalList () {
1624 // Return the removal list
1625 return $GLOBALS['ext_update_remove'];
1628 // Redirects if the provided extension is not installed
1629 function redirectOnUninstalledExtension ($ext_name) {
1630 // So is the extension there?
1631 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1632 // Redirect to index
1633 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1637 // Filter for initialization of all extensions by loading them in 'init' mode
1638 function FILTER_INIT_EXTENSIONS () {
1639 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTERED!');
1640 // Init notification pool
1641 initIncludePool('notify');
1643 // Do we have some entries?
1644 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1645 // Load all found extensions if found
1646 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1647 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1649 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - START');
1650 loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1651 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - END');
1653 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1656 // Run any notifications
1657 runFilterChain('load_includes', 'notify');
1659 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1662 // Setter for extension mode
1663 function setExtensionMode ($ext_mode) {
1664 $GLOBALS['ext_mode'] = (string) $ext_mode;
1667 // Getter for extension mode
1668 function getExtensionMode () {
1669 return $GLOBALS['ext_mode'];
1672 // Setter for dry-run
1673 function enableExtensionDryRun ($isDryRun = true) {
1674 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',isDryRun='.intval($isDryRun));
1675 $GLOBALS['ext_isDryRun'] = (bool) $isDryRun;
1678 // Getter for dry-run
1679 function isExtensionDryRun () {
1680 return $GLOBALS['ext_isDryRun'];
1683 // Setter for current extension version
1684 function setCurrentExtensionVersion ($ext_ver) {
1685 // ext_ver should never be empty in other modes than 'test'
1686 if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1687 // Please report all these messages
1688 reportBug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1692 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1693 $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1696 // Getter for current extension version
1697 function getCurrentExtensionVersion () {
1698 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1699 return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1702 // Remove the extension from cache array
1703 function removeExtensionFromArray () {
1704 // "Cache" this name
1705 $ext_name = getCurrentExtensionName();
1707 // Now loop through the whole cache
1708 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1709 // Is it an element?
1710 if (isset($cacheArray[$ext_name])) {
1712 unset($cacheArray[$ext_name]);
1713 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1716 $key = array_search($ext_name, $cacheArray);
1719 if ($key !== false) {
1720 // Found, so remove it
1721 unset($cacheArray[$key]);
1722 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1727 // Remove from other caches as well
1728 unset($GLOBALS['ext_is_installed'][$ext_name]);
1729 unset($GLOBALS['loaded_extension'][$ext_name]);
1732 // "Getter" for 'extension has a CSS file' (with same name, of course)
1733 function getExtensionHasCss () {
1734 // Do we have cache?
1735 if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
1736 // Construct FQFN for check
1737 $FQFN = sprintf("%stheme/%s/css/%s.css",
1740 getCurrentExtensionName()
1744 $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
1748 return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
1751 // Checks whether the given extension has a language file
1752 function ifExtensionHasLanguageFile ($ext_name) {
1753 // Do we have cache?
1754 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1756 incrementStatsEntry('cache_hits');
1758 // Determine it and put it in cache
1759 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
1763 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1766 // Load current extension's include file
1767 function loadCurrentExtensionInclude () {
1769 if (!isExtensionIncludeReadable()) {
1771 reportBug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1774 // Generate INC name
1775 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1781 // Checks whether an extension is readable
1782 function isExtensionIncludeReadable ($ext_name = '') {
1783 // If empty, use current
1784 if (empty($ext_name)) {
1785 $ext_name = getCurrentExtensionName();
1789 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1790 // Generate INC name
1791 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1794 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1798 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1799 return $GLOBALS['ext_inc_readable'][$ext_name];
1802 // Checks if an extension's function file is readable
1803 function isExtensionFunctionFileReadable ($ext_name) {
1805 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1806 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1807 // Just count cache hits
1808 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1809 incrementStatsEntry('cache_hits');
1811 // Construct IFN for functions file
1812 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1814 // Is this include there?
1815 $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
1817 // And put in cache, converted
1818 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
1822 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1823 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1826 // Adds a CREATE TABLE statement if the requested table is not there
1827 function addCreateTableSql ($tableName, $sql, $comment) {
1828 // Is the table not there?
1829 if (!ifSqlTableExists($tableName)) {
1830 // Is not found, so add it
1831 addExtensionSql('CREATE TABLE
1832 `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
1833 ENGINE = {?_TABLE_TYPE?}
1835 COLLATE utf8_general_ci
1836 COMMENT ' . chr(39) . $comment . chr(39));
1838 // Is already there, which should not happen
1839 reportBug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1843 // Adds a DROP TABLE statement if the requested tabled is there
1844 function addDropTableSql ($tableName) {
1845 // Is the table there?
1846 if (ifSqlTableExists($tableName)) {
1847 // Then add it, non-existing tables can be ignored because it will
1848 // happen with every newly installed extension.
1849 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1852 $GLOBALS['ifSqlTableExists'][$tableName] = false;
1856 // Adds a RENAME TABLE stament if 'from' table exist and 'to' table not
1857 function addRenameTableSql ($fromTable, $toTable) {
1858 // Is renaming required?
1859 if ((ifSqlTableExists($fromTable)) && (!ifSqlTableExists($toTable))) {
1861 addExtensionSql('RENAME TABLE `{?_MYSQL_PREFIX?}_' . $fromTable . '` TO `{?_MYSQL_PREFIX?}_' . $toTable . '`');
1864 $GLOBALS['ifSqlTableExists'][$fromTable] = false;
1865 $GLOBALS['ifSqlTableExists'][$toTable] = true;
1869 // Adds an admin menu to the SQL queue of the menu entry is not found
1870 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1871 // Now check if this menu is there
1872 if (!isMenuActionValid('admin', $action, $what)) {
1874 if (is_null($what)) {
1876 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1884 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1893 // Add it to the queue
1894 addExtensionSql($sql);
1895 } elseif (isDebugModeEnabled()) {
1896 // Double menus should be located and fixed!
1897 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1901 // Adds a guest menu to the SQL queue if the menu entry is not found
1902 function addGuestMenuSql ($action, $what, $title, $sort) {
1903 // Now check if this menu is there
1904 if (!isMenuActionValid('guest', $action, $what)) {
1906 if (is_null($what)) {
1908 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1915 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1923 // Add it to the queue
1924 addExtensionSql($sql);
1925 } elseif (isDebugModeEnabled()) {
1926 // Double menus should be located and fixed!
1927 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1931 // Adds a member menu to the SQL queue if the menu entry is not found
1932 function addMemberMenuSql ($action, $what, $title, $sort) {
1933 // Now check if this menu is there
1934 if (!isMenuActionValid('member', $action, $what)) {
1936 if (is_null($what)) {
1938 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1945 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1953 // Add it to the queue
1954 addExtensionSql($sql);
1955 } elseif (isDebugModeEnabled()) {
1956 // Double menus should be located and fixed!
1957 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1961 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1962 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1963 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1964 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1966 if (is_null($what)) {
1968 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1976 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1985 // Add it to the queue
1986 addExtensionSql($sql);
1987 } elseif (isDebugModeEnabled()) {
1988 // Double menus should be located and fixed!
1989 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1993 // Add configuration entry if not found for actual extension
1994 function addConfigAddSql ($columnName, $columnSql) {
1995 // Is the column there?
1996 if (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
1997 // Not found, so add it
1998 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1999 } elseif (isDebugModeEnabled()) {
2001 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
2005 // Drop configuration entry if found for actual extension
2006 function addConfigDropSql ($columnName) {
2007 // Is the column there?
2008 if (ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
2010 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
2011 } elseif (isDebugModeEnabled()) {
2012 // Add debug line, reportBug() would cause some extenion updates fail
2013 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
2017 // Change configuration entry for actual extension
2018 function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
2019 // Add the SQL statement
2020 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
2023 // Enables/disables productive mode for current extension (used only while
2025 // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
2026 function enableExtensionProductive ($isProductive = true) {
2027 // Log debug message
2028 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',isProductive=', intval($isProductive));
2031 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
2034 // Checks whether the extension is in productive phase. If not set, development
2035 // phase (=false) is assumed.
2036 function isExtensionProductive ($ext_name = '') {
2037 // Is the extension name empty? Then use current
2038 if (empty($ext_name)) {
2039 // Get current extension name
2040 $ext_name = getCurrentExtensionName();
2042 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
2044 // Do we have cache?
2045 if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
2046 // Load extension only if not yet loaded
2047 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
2048 // Load extension in test mode
2049 loadExtension($ext_name, 'test');
2053 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
2057 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isProductive=', intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!');
2058 return $GLOBALS[__FUNCTION__][$ext_name];
2061 // Mark extension file as loaded
2062 function markExtensionAsLoaded ($ext_name) {
2063 // Is it already loaded?
2064 if (isExtensionLoaded($ext_name)) {
2066 reportBug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
2070 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_loaded=true');
2071 $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
2074 // Determine whether the given extension is already loaded
2075 function isExtensionLoaded ($ext_name) {
2077 return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
2080 // Mark extension's library file as loaded
2081 function markExtensionLibraryAsLoaded ($ext_name) {
2082 // Is it already loaded?
2083 if (isExtensionLibraryLoaded($ext_name)) {
2085 reportBug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
2089 $GLOBALS['ext_loaded']['library'][$ext_name] = true;
2092 // Determine whether the given extension's library is already loaded
2093 function isExtensionLibraryLoaded ($ext_name) {
2095 return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));