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 * 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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Load the extension and maybe found language and function files.
45 function loadExtension ($ext_name, $ext_mode = 'init', $ext_ver = '', $dry_run = false) {
46 // Set current extension name
47 setCurrentExtensionName($ext_name);
49 // Set current extension version
50 setCurrentExtensionVersion($ext_ver);
53 setExtensionMode($ext_mode);
56 enableExtensionDryRun($dry_run);
59 initIncludePool('extension');
61 // Init EXT_UPDATE_DEPENDS
62 initExtensionUpdateDependencies();
64 // Init current extension name list
67 // Is the extension already loaded?
68 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Loading extension {$ext_name}, mode=".getExtensionMode().", ver=".getCurrentExtensionVersion()."");
69 if ((isset($GLOBALS['ext_loaded']['ext'][$ext_name])) && (getExtensionMode() == 'init')) {
71 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
77 // Is the extension file NOT there?
78 if (!isExtensionNameValid($ext_name)) {
80 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable.", $ext_name));
86 // Load extension's own language file if not in test mode
87 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
89 loadLanguageFile($ext_name);
93 if (isExtensionFunctionFileReadable($ext_name)) {
95 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]))) {
96 // Construct FQFN for functions file
97 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
100 $GLOBALS['ext_loaded']['funcs'][$ext_name] = true;
102 // Download functions file
103 loadIncludeOnce($funcsInclude);
105 } 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')) {
106 // No functions file is not so good...
107 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
113 // Extensions are not deprecated by default
114 setExtensionDeprecated('N');
116 // Extensions are not always active by default
117 setExtensionAlwaysActive('N');
119 // Extension update notes
120 setExtensionUpdateNotes('');
122 // Include the extension file
123 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Extension loaded.");
124 loadExtensionInclude();
126 // Is this extension deprecated?
127 if (isExtensionDeprecated()) {
128 // Deactivate the extension
129 doDeactivateExtension($ext_name);
135 // Mark it as loaded in normal mode
136 if (getExtensionMode() == '') {
138 $GLOBALS['ext_loaded']['ext'][$ext_name] = true;
145 // Registeres an extension and possible update depencies
146 function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = true) {
147 // Set current extension name
148 setCurrentExtensionName($ext_name);
151 enableExtensionDryRun($dry_run);
153 // By default all extensions are in productive phase
154 enableExtensionProductive();
156 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
157 // This shall never do a non-admin user or if the extension is active (already installed)
158 if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
162 // When this extension is already in install/update phase, all is fine
163 if (isExtensionRegisterRunning($ext_name)) {
164 // Then abort here which is fine
165 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ALREADY!");
169 // This registration is running
170 addExtensionRunningRegistration($ext_name);
172 // Init EXT_UPDATE_DEPENDS
173 initExtensionUpdateDependencies();
175 // Is the task id zero? Then we need to auto-fix it here
176 if ($task_id == '0') {
177 // Try to find the task
178 $task_id = determineExtensionTaskId(getCurrentExtensionName());
180 // Still zero and not in dry-run?
181 if (($task_id == '0') && (!getExtensionDryRun())) {
182 // Then request a bug report
183 debug_report_bug(sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
185 getCurrentExtensionName()
190 // Init queries and notes
192 initExtensionNotes();
197 initIncludePool('extension');
199 // By default we have no failures
200 setExtensionReportsFailure(false);
202 // Does this extension exists?
203 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
204 if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
205 // Set current extension name again
206 setCurrentExtensionName($ext_name);
208 // And run possible updates
209 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
210 $history = getExtensionVersionHistory();
211 foreach ($history as $ver) {
212 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName().", ext_ver={$ver}");
213 // Load extension in update mode
214 loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
216 // Add update notes to our output
217 addExtensionNotes($ver);
220 // Does this extension depends on an outstanding update of another update?
221 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
223 $ext_update = getExtensionUpdateDependenciesIterator();
225 // Increment here to avoid endless loop
226 incrementExtensionUpdateIterator();
228 // Check for required file
229 if ((!isExtensionInstalled($ext_update)) && (loadExtension($ext_update, 'register', '', getExtensionDryRun()))) {
230 // Set current extension name again
231 setCurrentExtensionName($ext_name);
233 // If versions mismatch update extension first
235 if (isExtensionInstalled($ext_update)) {
236 // Get version only if installed
237 $ext_ver = getExtensionVersion($ext_update);
240 // Extension version set? If empty the extension is not registered
241 if (empty($ext_ver)) {
242 // Extension not registered so far so first load task's id...
243 $task = determineExtensionTaskId($ext_update);
247 // Try to register the extension
248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().":ext_update=".$ext_update.",taskId=".$task."");
249 $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
251 // Reset extension name
252 setCurrentExtensionName($ext_name);
253 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test);
255 } elseif ($ext_ver != getCurrentExtensionVersion()) {
256 // Ok, update this extension now
257 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
258 $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
259 $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
260 updateExtension($ext_update, $ext_ver, getExtensionDryRun());
261 setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
262 setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
263 unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
264 unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
265 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
270 // Nothing to register / update before...
274 // Required file for update does not exists!
276 // But this is fine for the first time...
279 // Restore the current extension name
280 setCurrentExtensionName($ext_name);
283 // Is there no update?
284 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == '0') {
285 // Then test is passed!
289 // Switch back to register mode
290 setExtensionMode('register');
292 // Remains true if extension registration reports no failures
293 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
294 $test = (($test === true) && (getExtensionReportsFailure() === false));
295 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()); print getCurrentExtensionName().':<pre>'.print_r($test, true).'</pre>';
297 // Does everthing before wents ok?
298 if ($test === true) {
299 // "Dry-run-mode" activated?
300 if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
301 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".getCurrentExtensionName());
302 // Init SQLs and transfer ext->generic
304 setSqlsArray(getExtensionSqls());
306 // Run installation pre-installation filters
307 runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
309 // Register extension
310 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "insert=".getCurrentExtensionName().'/'.getCurrentExtensionVersion()." - INSERT!");
311 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
313 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
314 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion(), getExtensionHasCss()), __FUNCTION__, __LINE__);
317 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
318 array(getCurrentExtensionName(), getExtensionAlwaysActive(), getCurrentExtensionVersion()), __FUNCTION__, __LINE__);
321 // Remove cache file(s) if extension is active
322 runFilterChain('post_extension_installed', array(
323 'pool' => 'extension',
324 'ext_name' => getCurrentExtensionName(),
325 'task_id' => $task_id
328 // Remove all SQL commands
331 // Mark it as installed
332 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
334 // In normal mode return a true on success
336 } elseif (getExtensionDryRun() === true) {
337 // In "dry-run" mode return array with all SQL commands
338 $ret = getExtensionSqls();
340 // Remove all SQL commands
343 // Extension has been removed for updates, so all is fine!
347 // No, an error occurs while registering extension :-(
348 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "".getCurrentExtensionName());
351 } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
352 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
353 // Remove task from system when id and extension's name is valid
354 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
355 array(bigintval($task_id)), __FUNCTION__, __LINE__);
358 // Is this the sql_patches?
359 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ':'.getCurrentExtensionName()."/".getExtensionMode()."");
360 if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
361 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
362 if ($logout === true) {
363 // Then redirect to logout
364 redirectToUrl('modules.php?module=admin&logout=1&' . getExtensionMode() . '=sql_patches');
366 // Add temporary filter
367 registerFilter('shutdown', 'REDIRECT_TO_LOGOUT_SQL_PATCHES', true, true);
368 $GLOBALS['ext_load_mode'] = getExtensionMode();
372 // Return status code
373 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - LEFT!");
374 //* DEBUG: */ print getCurrentExtensionName().':<pre>'.print_r($ret, true).'</pre>';
378 // Run SQL queries for given extension id
379 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
380 function doExtensionSqls ($ext_id, $load_mode) {
381 // This shall never do a non-admin user!
382 if (!isAdmin()) return false;
384 // Get extension's name
385 $ext_name = getExtensionName($ext_id);
387 // Set current SQL name
388 setCurrentExtensionName($ext_name);
390 // Init EXT_UPDATE_DEPENDS
391 initExtensionUpdateDependencies();
396 // By default no SQL has been executed
399 // Load extension in detected mode
400 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":ext_name[{$ext_id}]=".getCurrentExtensionName()."");
401 loadExtension(getCurrentExtensionName(), $load_mode, '', false);
405 setSqlsArray(getExtensionSqls());
407 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ":SQLs::count=".countSqls()."");
409 // Run SQL commands...
410 runFilterChain('run_sqls');
413 // Run any filters depending on the action here
414 runFilterChain('extension_' . $load_mode);
416 // Remove cache file(s) if extension is active
417 if (((isExtensionActive('cache')) && ((SQL_AFFECTEDROWS() == 1)) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate'))) {
419 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
422 // Is this the sql_patches?
423 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": id=".$ext_id.",currName=".getCurrentExtensionName().",loadMode=".$load_mode);
424 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
425 // Then redirect to logout
426 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": LOAD!");
427 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
431 // Check wether the given extension is installed
432 function isExtensionInstalled ($ext_name) {
433 // We don't like empty extension names here
434 if (empty($ext_name)) {
435 // Please fix them all
436 debug_report_bug(__FUNCTION__.': ext_name is empty.');
439 // By default non is installed
440 $isInstalled = false;
442 // Check if there is a cache entry
443 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
444 // Use cache built from below queries
445 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
446 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
451 incrementStatsEntry('cache_hits');
452 } elseif ((isInstallationPhase())) {
453 // Extensions are all inactive/not installed during installation
456 $ext_id = getExtensionId($ext_name);
458 // Do we have a record?
459 $isInstalled = ($ext_id > 0);
461 // Is it installed, then cache the entry
462 if ($isInstalled === true) {
463 // Dummy call (get is okay here)
464 getExtensionId($ext_name, true);
467 // Remember the status
468 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
475 // Check if given extension is active
476 function isExtensionActive ($ext_name) {
477 // Extensions are all inactive during installation
478 if ((isInstallationPhase()) || (empty($ext_name))) return false;
480 // Not active is the default
481 $data['ext_active'] = 'N';
484 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
486 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "CACHE! ext_name={$ext_name}");
487 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
490 incrementStatsEntry('cache_hits');
491 } elseif (isset($GLOBALS['ext_loaded'][$ext_name])) {
492 // @TODO Extension is loaded, what next?
493 app_die(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
494 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
495 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
496 // Load from database
497 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
498 array($ext_name), __FUNCTION__, __LINE__);
501 if (SQL_NUMROWS($result) == 1) {
503 $data = SQL_FETCHARRAY($result);
507 SQL_FREERESULT($result);
510 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name."[DB]: ".$data['ext_active']."");
511 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
513 // Extension not active!
514 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.": Not active!");
515 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
519 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "ext_name=".$ext_name.",active=".$data['ext_active']."");
521 // Is this extension activated? (For admins we always have active extensions...)
522 return ($data['ext_active'] == 'Y');
525 // Get version from extensions
526 function getExtensionVersion ($ext_name, $force = false) {
527 // By default no extension is found
528 $data['ext_version'] = 'false';
530 // Empty extension name should be fixed!
531 if (empty($ext_name)) {
532 // Please report this bug!
533 debug_report_bug(__FUNCTION__ . ': ext_name is empty which is not allowed here.');
536 // Extensions are all inactive during installation
537 if (isInstallationPhase()) return '';
538 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ext_name=".$ext_name."");
540 // Is the cache written?
541 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
542 // Load data from cache
543 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': CACHE!');
544 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
547 incrementStatsEntry('cache_hits');
548 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (getOutputMode() != 0)) {
549 // Load from database
550 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
551 array($ext_name), __FUNCTION__, __LINE__);
552 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': DB - '.SQL_NUMROWS($result).'');
554 // Is the extension there?
555 if (SQL_NUMROWS($result) == 1) {
557 $data = SQL_FETCHARRAY($result);
558 } elseif (isDebugModeEnabled()) {
559 // Not found, please report all
560 debug_report_bug(sprintf(": Cannot find extension %s in database!", $ext_name));
564 SQL_FREERESULT($result);
567 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
570 // Extension version should not be invalid
571 if (($data['ext_version'] == 'false') && ($force === false)) {
572 // Please report this trouble
573 debug_report_bug(sprintf("Extension <strong>%s</strong> has empty version!", $ext_name));
577 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": ret={$data['ext_version']}");
578 return $data['ext_version'];
581 // Updates a given extension with current extension version to latest version
582 function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
583 // Only admins are allowed to update extensions
584 if ((!isAdmin()) || (empty($ext_name))) return false;
586 // Set current SQL name
587 setCurrentExtensionName($ext_name);
591 initExtensionNotes();
592 initIncludePool('extension');
594 // Load extension in test mode
595 loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
597 // Save version history
598 $history = getExtensionVersionHistory();
600 // Remove old SQLs array to prevent possible bugs
603 // Check if version is updated
604 //* DEBUG: */ print getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)).'<br />';
605 if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
606 // Search for starting point
607 $start = array_search($ext_ver, $history);
609 // And load SQL queries in order of version history
610 for ($idx = ($start + 1); $idx < count($history); $idx++) {
611 // Set extension version
612 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
615 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
618 $depencies = getExtensionUpdateDependencies();
621 if (count($depencies) > 0) {
622 // Apply all extension depencies
623 foreach ($depencies as $ext_depend) {
624 // Did we already update/register this?
625 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
627 setCurrentExtensionName($ext_depend);
629 // Mark it as already updated before we update it
630 $GLOBALS['ext_updated'][$ext_depend] = true;
632 // Is the extension there?
633 if (isExtensionInstalled($ext_depend)) {
634 // Update another extension first!
635 $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
637 // Register new extension
638 $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
644 setCurrentExtensionName($ext_name);
648 addExtensionNotes($history[$idx]);
651 // In real-mode execute any existing includes
652 if (getExtensionDryRun() === false) {
653 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
654 runFilterChain('load_includes', 'extension');
655 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
656 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
661 setSqlsArray(getExtensionSqls());
664 runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
666 if (getExtensionDryRun() === false) {
667 // Run filters on success extension update
668 runFilterChain('extension_update', getCurrentExtensionName());
673 // Output verbose SQL table for extension
674 function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false, $width = '100%') {
677 // Then fix it to default
678 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
684 // Do we have queries?
685 if ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
690 foreach (getExtensionSqls() as $sqls) {
691 // New array format is recursive
692 foreach ($sqls as $idx => $sql) {
696 // Output command if set
698 // Prepare output for template
706 $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
714 // Prepare content for template
722 // Load main template
723 $OUT = loadTemplate('admin_ext_sql_table', true, $content);
724 } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
725 // No addional SQL commands to run
726 $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
733 // Get extension name from id
734 function getExtensionName ($ext_id) {
735 // Init extension name
736 $data['ext_name'] = '';
739 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
741 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
744 incrementStatsEntry('cache_hits');
745 } elseif (!isExtensionActive('cache')) {
746 // Load from database
747 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
748 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
750 // Is the entry there?
751 if (SQL_NUMROWS($result) == 1) {
752 // Get the extension's name from database
753 $data = SQL_FETCHARRAY($result);
757 SQL_FREERESULT($result);
760 // Did we find some extension?
761 if (empty($data['ext_name'])) {
762 // We should fix these all!
763 debug_report_bug(__FUNCTION__ . ': ext_name is empty. ext_id=' . $ext_id);
766 // Return the extension name
767 return $data['ext_name'];
770 // Get extension id from name
771 function getExtensionId ($ext_name) {
773 $data['ext_id'] = '0';
776 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
778 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
781 incrementStatsEntry('cache_hits');
783 // Load from database
784 $result = SQL_QUERY_ESC("SELECT `id` AS ext_id FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
785 array($ext_name), __FUNCTION__, __LINE__);
787 // Is the entry there?
788 if (SQL_NUMROWS($result) == 1) {
789 // Get the extension's id from database
790 $data = SQL_FETCHARRAY($result);
794 SQL_FREERESULT($result);
797 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
801 return $data['ext_id'];
804 // Determines wether the given extension name is valid
805 function isExtensionNameValid ($ext_name) {
807 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
808 // Generate include file name
809 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
811 // Is there a file in inc/extensions/ ?
812 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
816 return $GLOBALS['ext_name_valid'][$ext_name];
819 // Determines wether the given extension id is valid
820 function isExtensionIdValid ($ext_id) {
821 // Default is nothing valid
824 // Check in cache then in database
825 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
830 incrementStatsEntry('cache_hits');
833 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
840 // Activate given extension
841 function doActivateExtension ($ext_name) {
842 // Activate the extension
843 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
844 array($ext_name), __FUNCTION__, __LINE__);
846 // Extension has been activated?
847 if (SQL_AFFECTEDROWS() == 1) {
848 // Then run all queries
849 doExtensionSqls(getExtensionId($ext_name), 'activate');
853 // Deactivate given extension
854 function doDeactivateExtension($ext_name) {
855 // Activate the extension
856 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
857 array($ext_name), __FUNCTION__, __LINE__);
859 // Extension has been activated?
860 if (SQL_AFFECTEDROWS() == 1) {
861 // Then run all queries
862 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
865 createExtensionDeactivationTask($ext_name);
868 sendAdminNotification(
869 getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
870 'admin_ext_deactivated',
871 array('ext_name' => $ext_name)
876 // Checks wether the extension is older than given
877 function isExtensionOlder ($ext_name, $ext_ver) {
878 // Get current extension version
879 $currVersion = getExtensionVersion($ext_name);
881 // Remove all dots from both versions
882 $currVersion = str_replace('.', '', $currVersion);
883 $ext_ver = str_replace('.', '', $ext_ver);
885 // Now compare both and return the result
886 return ($currVersion < $ext_ver);
889 // Creates a new task for updated extension
890 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
891 // Create subject line
892 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXT_SUBJ--}';
894 // Is the extension there?
895 if (isExtensionInstalled($ext_name)) {
896 // Check if task is not there
897 if (determineTaskIdBySubject($subject) == '0') {
898 // Create extension update-task
899 createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
902 // Extension not there! :-(
903 debug_report_bug(sprintf("Extension <strong>%s</strong> not found but should be updated?", $ext_name));
907 // Creates a new task for newly installed extension
908 function createNewExtensionTask ($adminId, $subject, $ext) {
909 // Not installed and do we have created a task for the admin?
910 if ((determineTaskIdBySubject($subject) == '0') && (!isExtensionInstalled($ext))) {
911 // Set default message if ext-foo is missing
912 $message = getMaskedMessage('ADMIN_EXT_TEXT_FILE_MISSING', $ext);
915 $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
921 // Load text for task if found
922 if (isFileReadable($tpl)) {
923 // Load extension's own text template (HTML!)
924 $message = loadTemplate('ext_' . $ext, true);
926 // Write this in debug.log as well
927 logDebugMessage(__FUNCTION__, __LINE__, $message);
930 // Task not created so it's a brand-new extension which we need to register and create a task for!
931 createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
935 // Creates a task for automatically deactivated (deprecated) extension
936 function createExtensionDeactivationTask ($ext) {
937 // Create subject line
938 $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
940 // Not installed and do we have created a task for the admin?
941 if ((determineTaskIdBySubject($subject) == '0') && (getExtensionVersion($ext) != '')) {
942 // Task not created so add it
943 createNewTask($subject, SQL_ESCAPE(loadTemplate('task_ext_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
947 // Checks if the module has a menu
948 function ifModuleHasMenu ($mod, $forceDb = false) {
949 // All is false by default
952 // Extension installed and newer than or has version 0.1.2?
953 if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
954 // Cache version is okay, so let's check the cache!
955 if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
956 // Check module cache and count hit
957 $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y');
958 incrementStatsEntry('cache_hits');
959 } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) {
960 // Check cache and count hit
961 $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
962 incrementStatsEntry('cache_hits');
964 // Admin/guest/member/sponsor modules have always a menu!
965 $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor'));
967 } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
968 // Check database for entry
969 $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
970 array($mod), __FUNCTION__, __LINE__);
973 if (SQL_NUMROWS($result) == 1) {
974 // Load "has_menu" column
975 $data = SQL_FETCHARRAY($result);
978 $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu'];
980 // Does it have a menu?
981 $ret = ($data['has_menu'] == 'Y');
985 SQL_FREERESULT($result);
986 } elseif (!isExtensionInstalled('sql_patches')) {
987 // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered?
988 $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu!
990 // Unsupported state!
991 logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached.');
998 // Determines the task id for given extension
999 function determineExtensionTaskId ($ext_name) {
1000 // Default is not found
1001 $data['task_id'] = '0';
1003 // Search for extension task's id
1004 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1005 array($ext_name), __FUNCTION__, __LINE__);
1008 if (SQL_NUMROWS($result) == 1) {
1009 // Task found so load task's id and register extension...
1010 $data = SQL_FETCHARRAY($result);
1014 SQL_FREERESULT($result);
1017 return $data['task_id'];
1020 // Determines the task id for given subject
1021 function determineTaskIdBySubject ($subject) {
1022 // Default is not found
1023 $data['task_id'] = '0';
1025 // Search for task id
1026 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1027 array($subject), __FUNCTION__, __LINE__);
1030 if (SQL_NUMROWS($result) == 1) {
1031 // Task found so load task's id and register extension...
1032 $data = SQL_FETCHARRAY($result);
1036 SQL_FREERESULT($result);
1039 return $data['task_id'];
1042 // Add updates notes for given version
1043 function addExtensionNotes ($ver) {
1044 // Init notes/content
1045 $out = ''; $content = array();
1047 // Is do we have verbose output enabled?
1048 if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
1049 // Update notes found?
1050 if (getExtensionUpdateNotes($ver) != '') {
1051 // Update notes found
1054 'notes' => getExtensionUpdateNotes($ver)
1058 setExtensionUpdateNotes('', $ver);
1059 } elseif (($ver == '0.0') || ($ver == '0.0.0')) {
1063 'notes' => getMessage('INITIAL_RELEASE')
1066 // No update notes found!
1069 'notes' => getMessage('NO_UPDATE_NOTES')
1074 $out = loadTemplate('admin_ext_notes', true, $content);
1078 appendExtensionNotes($out);
1081 // Getter for CSS files array
1082 function getExtensionCssFiles () {
1083 // By default no additional CSS files are found
1084 $cssFiles = array();
1086 // Is the array there?
1087 if (isset($GLOBALS['css_files'])) {
1089 $cssFiles = $GLOBALS['css_files'];
1096 // Init CSS files array
1097 function initExtensionCssFiles () {
1099 $GLOBALS['css_files'] = array();
1103 function addExtensionCssFile ($file) {
1104 // Is the array there?
1105 if (!isset($GLOBALS['css_files'])) {
1106 // Then auto-init them
1107 initExtensionCssFiles();
1111 $GLOBALS['css_files'][] = $file;
1114 // Setter for EXT_ALWAYS_ACTIVE flag
1115 function setExtensionAlwaysActive ($active) {
1116 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1119 // Getter for EXT_ALWAYS_ACTIVE flag
1120 function getExtensionAlwaysActive () {
1121 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1124 // Setter for EXT_VERSION flag
1125 function setThisExtensionVersion ($version) {
1126 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $version;
1129 // Getter for EXT_VERSION flag
1130 function getThisExtensionVersion () {
1131 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1134 // Setter for EXT_DEPRECATED flag
1135 function setExtensionDeprecated ($deprecated) {
1136 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1139 // Getter for EXT_DEPRECATED flag
1140 function isExtensionDeprecated () {
1141 return ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1144 // Setter for EXT_UPDATE_DEPENDS flag
1145 function addExtensionUpdateDependency ($updateDepends) {
1146 // Is the update depency empty? (NEED TO BE FIXED!)
1147 if (empty($updateDepends)) {
1148 // Please report this bug!
1149 debug_report_bug('updateDepends is left empty!');
1152 // Is it not yet added?
1153 if (!in_array($updateDepends, $GLOBALS['ext_running_updates'])) {
1154 //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$updateDepends);
1155 // Add it to the list of extension update depencies map
1156 $GLOBALS['ext_update_depends'][getCurrentExtensionName()][] = (string) $updateDepends;
1158 // Remember it in the list of running updates
1159 $GLOBALS['ext_running_updates'][] = $updateDepends;
1163 // Checks wether the given extension registration is in progress
1164 function isExtensionRegisterRunning ($ext_name) {
1165 return ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1168 // Init EXT_UPDATE_DEPENDS flag
1169 function initExtensionUpdateDependencies () {
1170 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1172 // Init update depency map automatically if not found
1173 if (!isExtensionUpdateDependenciesInitialized()) {
1174 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - INIT!");
1175 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1178 // Init running updates array
1179 initExtensionRuningUpdates();
1182 // Adds an extension as "registration in progress"
1183 function addExtensionRunningRegistration ($ext_name) {
1185 if (!isExtensionRegisterRunning($ext_name)) {
1187 $GLOBALS['ext_register_running'][] = $ext_name;
1191 // Checks wether EXT_UPDATE_DEPENDS is initialized
1192 function isExtensionUpdateDependenciesInitialized () {
1193 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1194 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1197 // Initializes the list of running updates
1198 function initExtensionRuningUpdates () {
1199 // Auto-init ext_running_updates
1200 if (!isset($GLOBALS['ext_running_updates'])) {
1201 $GLOBALS['ext_running_updates'] = array();
1202 $GLOBALS['ext_register_running'] = array();
1206 // Getter for EXT_UPDATE_DEPENDS flag
1207 function getExtensionUpdateDependencies () {
1208 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1209 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1212 // Getter for next iterator depency
1213 function getExtensionUpdateDependenciesIterator () {
1214 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1215 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1218 // Counter for extension update depencies
1219 function countExtensionUpdateDependencies () {
1220 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1221 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1224 // Removes given extension from update denpency list
1225 function removeExtensionUpdateDependency ($ext_name) {
1227 $key = array_search($ext_name, getExtensionUpdateDependencies());
1230 if ($key !== false) {
1232 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1234 // And sort the array
1235 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1239 // Init iterator for update depencies
1240 function initExtensionUpdateIterator () {
1241 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1242 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1245 // Getter for depency iterator
1246 function getExtensionUpdateIterator () {
1247 // Auto-init iterator
1248 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
1251 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1252 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1255 // Increments the update iterator
1256 function incrementExtensionUpdateIterator () {
1257 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
1258 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1261 // Setter for EXT_REPORTS_FAILURE flag
1262 function setExtensionReportsFailure ($reportsFailure) {
1263 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1266 // Getter for EXT_REPORTS_FAILURE flag
1267 function getExtensionReportsFailure () {
1268 return $GLOBALS['ext_reports_failure'];
1271 // Setter for EXT_VER_HISTORY flag
1272 function setExtensionVersionHistory ($verHistory) {
1273 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $verHistory;
1276 // Getter for EXT_VER_HISTORY array
1277 function getExtensionVersionHistory () {
1278 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1281 // Setter for EXT_UPDATE_NOTES
1282 function setExtensionUpdateNotes ($updateNotes, $ver='') {
1283 //* DEBUG: */ print __FUNCTION__.':'.getCurrentExtensionName().'/'.getCurrentExtensionVersion().'/'.$ver.'='.$updateNotes.'<br />';
1285 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1287 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver] = (string) $updateNotes;
1291 // Getter for EXT_UPDATE_NOTES
1292 function getExtensionUpdateNotes ($ver) {
1293 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ver];
1296 // Init extension notice
1297 function initExtensionNotes () {
1298 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1301 // Append extension notice
1302 function appendExtensionNotes ($notes) {
1303 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1306 // Getter for extension notes
1307 function getExtensionNotes () {
1308 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1311 // Setter for current extension name
1312 function setCurrentExtensionName ($ext_name) {
1313 $GLOBALS['curr_ext_name'] = (string) trim($ext_name);
1316 // Getter for current extension name
1317 function getCurrentExtensionName () {
1318 if (isset($GLOBALS['curr_ext_name'])) {
1319 return $GLOBALS['curr_ext_name'];
1323 debug_report_bug(__FUNCTION__.": curr_ext_name not initialized. Please execute initExtensionSqls() before calling this function.");
1326 // Init SQLs array for current extension
1327 function initExtensionSqls () {
1328 // Auto-init the array now...
1329 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1330 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1334 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1335 function addExtensionSql ($sql) {
1337 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()][] = $sql;
1340 // Getter for SQLs array for current extension
1341 function getExtensionSqls () {
1342 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1343 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1344 // Not found, should not happen
1345 debug_report_bug(sprintf("ext_sqls is empty, current extension: %s",
1346 getCurrentExtensionName()
1351 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1354 // Removes SQLs for current extension
1355 function unsetExtensionSqls () {
1356 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1359 // Auto-initializes the removal list
1360 function initExtensionRemovalList () {
1361 // Is the remove list there?
1362 if (!isset($GLOBALS['ext_update_remove'])) {
1364 $GLOBALS['ext_update_remove'] = array();
1368 // Checks wether the current extension is on the removal list
1369 function isExtensionOnRemovalList () {
1370 // Init removal list
1371 initExtensionRemovalList();
1374 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1377 // Adds the current extension to the removal list
1378 function addCurrentExtensionToRemovalList () {
1380 $GLOBALS['ext_update_remove'][] = getCurrentExtensionName();
1383 // Getter for removal list
1384 function getExtensionRemovalList () {
1385 // Return the removal list
1386 return $GLOBALS['ext_update_remove'];
1389 // Redirects if the provided extension is not installed
1390 function redirectOnUninstalledExtension ($ext_name) {
1391 // So is the extension there?
1392 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1393 // Redirect to index
1394 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1398 // Filter for initialization of all extensions by loading them in 'init' mode
1399 function FILTER_INIT_EXTENSIONS () {
1400 // Do we have some entries?
1401 //* DEBUG */ print __FUNCTION__.': ENTRY!<br />';
1402 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1403 // Load all found extensions if found
1404 //* DEBUG */ print __FUNCTION__.': CACHE - START!<br />';
1405 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1407 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START<br />';
1408 loadExtension($ext_name, 'init');
1409 //* DEBUG */ print __FUNCTION__.': '.$ext_name.' - END<br />';
1411 //* DEBUG */ print __FUNCTION__.': CACHE - END!<br />';
1413 //* DEBUG */ print __FUNCTION__.': EXIT!<br />';
1416 // Setter for extension mode
1417 function setExtensionMode ($ext_mode) {
1418 $GLOBALS['ext_mode'] = (string) $ext_mode;
1421 // Getter for extension mode
1422 function getExtensionMode () {
1423 return $GLOBALS['ext_mode'];
1426 // Setter for dry-run
1427 function enableExtensionDryRun ($dry_run = true) {
1428 //* DEBUG: */ print __FUNCTION__.': '.getCurrentExtensionName().'='.intval($dry_run).'<br />';
1429 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1432 // Getter for dry-run
1433 function getExtensionDryRun () {
1434 return $GLOBALS['ext_dry_run'];
1437 // Setter for current extension version
1438 function setCurrentExtensionVersion ($ext_ver) {
1439 if (empty($ext_ver)) {
1441 $GLOBALS['ext_current_version'] = '0.0';
1444 $GLOBALS['ext_current_version'] = (string) $ext_ver;
1448 // Getter for current extension version
1449 function getCurrentExtensionVersion () {
1450 return $GLOBALS['ext_current_version'];
1453 // Remove the extension from cache array
1454 function removeExtensionFromArray () {
1455 // "Cache" this name
1456 $ext_name = getCurrentExtensionName();
1458 // Now loop through the whole cache
1459 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1460 // Is it an element?
1461 if (isset($cacheArray[$ext_name])) {
1463 unset($cacheArray[$ext_name]);
1464 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1467 $key = array_search($ext_name, $cacheArray);
1470 if ($key !== false) {
1471 // Found, so remove it
1472 unset($cacheArray[$key]);
1473 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1479 // "Getter" for 'extension has a CSS file' (with same name, of course)
1480 function getExtensionHasCss () {
1481 // Default is no CSS
1484 // Construct FQFN for check
1485 $FQFN = sprintf("%stheme/%s/css/%s.css",
1488 getCurrentExtensionName()
1492 if (isFileReadable($FQFN)) {
1493 // Readable, so it is there...
1501 // Checks wether the given extension has a language file
1502 function ifExtensionHasLanguageFile ($ext_name) {
1503 // Default is no language file
1504 $hasLanguage = false;
1506 // Do we have cache?
1507 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1509 $hasLanguage = ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1512 incrementStatsEntry('cache_hits');
1514 // Not readable is default
1517 // Is the language file readable for this extension?
1518 if (isLanguageIncludeReadable($ext_name)) {
1524 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = 'Y';
1528 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1531 // Load an extension's include file
1532 function loadExtensionInclude () {
1534 if (!isExtensionIncludeReadable()) {
1536 debug_report_bug('Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1539 // Generate INC name
1540 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1546 // Checks wether an extension is readable
1547 function isExtensionIncludeReadable ($ext_name = '') {
1548 // If empty, use current
1549 if (empty($ext_name)) $ext_name = getCurrentExtensionName();
1552 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1553 // Generate INC name
1554 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1557 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1561 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1562 return $GLOBALS['ext_inc_readable'][$ext_name];
1565 // Checks if an extension's function file is readable
1566 function isExtensionFunctionFileReadable ($ext_name) {
1567 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1568 // Just count cache hits
1569 incrementStatsEntry('cache_hits');
1571 // Construct FQFN for functions file
1572 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1574 // Is this include there?
1575 if ((isFileReadable($funcsInclude)) && (!isset($GLOBALS['ext_loaded']['funcs'][$ext_name])) && (getExtensionMode() == 'test')) {
1577 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'Y';
1580 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = 'N';
1585 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1588 // Adds an admin menu to the SQL queue of the menu entry is not found
1589 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1590 // Now check if this menu is there
1591 if (!isMenuActionValid('admin', $action, $what)) {
1593 if (is_null($what)) {
1595 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1603 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1612 // Add it to the queue
1613 addExtensionSql($sql);
1614 } elseif (isDebugModeEnabled()) {
1615 // Double menus should be located and fixed!
1616 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s, what=%s detected.", $action, $what));
1620 // Adds a guest menu to the SQL queue if the menu entry is not found
1621 function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1622 // Now check if this menu is there
1623 if (!isMenuActionValid('guest', $action, $what)) {
1625 if (is_null($what)) {
1627 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1636 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1646 // Add it to the queue
1647 addExtensionSql($sql);
1648 } elseif (isDebugModeEnabled()) {
1649 // Double menus should be located and fixed!
1650 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s, what=%s detected.", $action, $what));
1654 // Adds a member menu to the SQL queue if the menu entry is not found
1655 function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
1656 // Now check if this menu is there
1657 if (!isMenuActionValid('member', $action, $what)) {
1659 if (is_null($what)) {
1661 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
1670 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
1680 // Add it to the queue
1681 addExtensionSql($sql);
1682 } elseif (isDebugModeEnabled()) {
1683 // Double menus should be located and fixed!
1684 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s, what=%s detected.", $action, $what));
1688 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1689 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1690 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1691 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1693 if (is_null($what)) {
1695 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
1703 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
1712 // Add it to the queue
1713 addExtensionSql($sql);
1714 } elseif (isDebugModeEnabled()) {
1715 // Double menus should be located and fixed!
1716 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s, what=%s detected.", $action, $what));
1720 // Enables/disables productive mode for current extension (used only while
1722 function enableExtensionProductive ($isProductive = true) {
1723 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
1726 // Checks wether the extension is in productive phase. If not set, development
1727 // phase (=false) is assumed.
1728 function isExtensionProductive () {
1729 return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));