3 require_once('../config.php');
5 $action = optional_param('action', '', PARAM_ACTION
);
6 $filterpath = optional_param('filterpath', '', PARAM_PATH
);
9 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
));
11 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managefilters";
13 if (!confirm_sesskey()) {
17 // get a list of installed filters
18 $installedfilters = array();
19 $filterlocations = array('mod','filter');
20 foreach ($filterlocations as $filterlocation) {
21 $plugins = get_list_of_plugins($filterlocation);
22 foreach ($plugins as $plugin) {
23 $pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
24 if (is_readable($pluginpath)) {
25 $installedfilters["$filterlocation/$plugin"] = "$filterlocation/$plugin";
30 // get all the currently selected filters
31 if (!empty($CFG->textfilters
)) {
32 $activefilters = explode(',', $CFG->textfilters
);
34 $activefilters = array();
37 //======================
39 //======================
44 $key=array_search($filterpath, $activefilters);
45 // check filterpath is valid
50 unset($activefilters[$key]);
54 // check filterpath is valid
55 if (!array_key_exists($filterpath, $installedfilters)) {
56 error("Filter $filterpath is not currently installed", $url);
57 } elseif (array_search($filterpath,$activefilters)) {
58 // filterpath is already active - doubleclick??
60 // add it to installed filters
61 $activefilters[] = $filterpath;
62 $activefilters = array_unique($activefilters);
67 $key=array_search($filterpath, $activefilters);
68 // check filterpath is valid
70 error("Filter $filterpath is not currently active", $url);
71 } elseif ($key>=(count($activefilters)-1)) {
72 // cannot be moved any further down - doubleclick??
75 $fsave = $activefilters[$key];
76 $activefilters[$key] = $activefilters[$key+
1];
77 $activefilters[$key+
1] = $fsave;
82 $key=array_search($filterpath, $activefilters);
83 // check filterpath is valid
85 error("Filter $filterpath is not currently active", $url);
87 //cannot be moved any further up - doubleclick??
90 $fsave = $activefilters[$key];
91 $activefilters[$key] = $activefilters[$key-1];
92 $activefilters[$key-1] = $fsave;
97 // save, reset cache and return
98 set_config('textfilters', implode(',', $activefilters));
99 reset_text_filters_cache();
100 redirect($returnurl);