summaryrefslogtreecommitdiff
path: root/admin/plugins.php
blob: 5aca875832b7cab6c4014fc18e71f246ec5cd805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Bitweaver\Liberty;

require_once '../../kernel/includes/setup_inc.php';
use Bitweaver\KernelTools;

include_once KERNEL_PKG_INCLUDE_PATH.'simple_form_functions_lib.php';

$gBitSystem->verifyPermission( 'p_admin' );

// this will clear out all plugin settings in the database. scanAllPlugins
// below will then reload all plugins and set them to their default setup.
if( !empty( $_REQUEST['reset_all_plugins'] ) ) {
	// because of include_once scenarios in scanAllPlugins, you need two complete page refreshes afternuking the plugin settings
	if( $_REQUEST['reset_all_plugins'] == 'refresh' ) {
		KernelTools::bit_redirect( LIBERTY_PKG_URL."admin/plugins.php" );
	} else {
		$gBitUser->verifyTicket();
		//$gBitSystem->storeConfig( 'default_format', PLUGIN_GUID_TIKIWIKI, LIBERTY_PKG_NAME );
		$gLibertySystem->resetAllPluginSettings();

		// this scanAllPlugins is required. who knows why this stuff is so resilient
		$gLibertySystem->scanAllPlugins();
		KernelTools::bit_redirect( LIBERTY_PKG_URL."admin/plugins.php?reset_all_plugins=refresh" );
	}
}

// Since the normal startup only loads the plugins marked active
// We need to load the rest of them here so that we can display them all
$gLibertySystem->scanAllPlugins();

if( isset( $_REQUEST['pluginsave'] ) && !empty( $_REQUEST['pluginsave'] ) ) {
	if( !empty( $_REQUEST['default_format'] ) && !empty( $_REQUEST['PLUGINS'][$_REQUEST['default_format']][0] ) ) {
		$gLibertySystem->setActivePlugins( $_REQUEST['PLUGINS'] );
		$gBitSystem->storeConfig( 'default_format', $_REQUEST['default_format'], LIBERTY_PKG_NAME );
		$gBitSmarty->assign( 'default_format',$_REQUEST['default_format'] );
	} else {
		$gBitSmarty->assign( 'errorMsg', 'You cannot disable the default format');
	}
	$gBitSystem->storeConfig( 'content_allow_html', !empty( $_REQUEST['content_allow_html'] ) ? $_REQUEST['content_allow_html'] : null, LIBERTY_PKG_NAME );
	$gBitSystem->storeConfig( 'content_force_allow_html', !empty( $_REQUEST['content_force_allow_html'] ) ? $_REQUEST['content_force_allow_html'] : null, LIBERTY_PKG_NAME );
}

// Sort the plugins to avoild splitting tables
foreach( $gLibertySystem->mPlugins as $guid => $plugin ) {
// since plugins can be in other packages, they can't use package constants. here we re-interpret URLs
	if( !empty( $plugin['plugin_settings_url'] ) && strpos( $plugin['plugin_settings_url'], "/" ) !== 0 ) {
		$parts = explode( "/", $plugin['plugin_settings_url'] );
		$gLibertySystem->mPlugins[$guid]['plugin_settings_url'] = constant( strtoupper( $parts[0] )."_PKG_URL" ).str_replace( $parts[0]."/", "", $plugin['plugin_settings_url'] );
	}

	$types[ucfirst( $plugin['plugin_type'] )] = $plugin['plugin_type'];
	$typeSort[$guid] = $plugin['plugin_type'];
	$guidSort[$guid] = $plugin['plugin_guid'];
}
array_multisort( $typeSort, SORT_ASC, $guidSort, SORT_ASC, $gLibertySystem->mPlugins );
$gBitSmarty->assign( 'gLibertySystem', $gLibertySystem );
ksort( $types );
$gBitSmarty->assign( 'pluginTypes', $types );

$gBitSystem->display( 'bitpackage:liberty/admin_plugins.tpl', KernelTools::tra( 'Liberty Plugins' ), [ 'display_mode' => 'admin' ] );