aboutsummaryrefslogtreecommitdiff
path: root/actions/plugins/settings/save.php
blob: 24af3f5fac7d407e83337094e4f0ae0464646d46 (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
<?php
/**
 * Elgg plugin settings save action.
 *
 * @package Elgg
 * @subpackage Core
 */

$params = get_input('params');
$plugin = get_input('plugin');
if (!$plugin_info = load_plugin_manifest($plugin)) {
	register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin));
	forward($_SERVER['HTTP_REFERER']);
}

$plugin_name = $plugin_info['name'];

admin_gatekeeper();

$result = false;

$options = array(
	'plugin' => $plugin,
	'manifest' => $plugin_info,
	'settings' => $params
);

// allow a plugin to override the save action for their settings
if (elgg_action_exist("settings/$plugin/save")) {
	action("settings/$plugin/save");
} else {
	foreach ($params as $k => $v) {
		if (!$result = set_plugin_setting($k, $v, $plugin)) {
			register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin_name));
			forward($_SERVER['HTTP_REFERER']);
			exit;
		}
	}
}

system_message(sprintf(elgg_echo('plugins:settings:save:ok'), $plugin_name));
forward($_SERVER['HTTP_REFERER']);
//
//$trigger = trigger_plugin_hook('plugin:save_settings', $plugin, $options, NULL);
//if ($trigger === NULL) {
//	foreach ($params as $k => $v) {
//		if (!$result = set_plugin_setting($k, $v, $plugin)) {
//			register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin_name));
//			forward($_SERVER['HTTP_REFERER']);
//			exit;
//		}
//	}
//} elseif ($trigger === FALSE) {
//	register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin_name));
//	forward($_SERVER['HTTP_REFERER']);
//}
//
//system_message(sprintf(elgg_echo('plugins:settings:save:ok'), $plugin_name));
//forward($_SERVER['HTTP_REFERER']);