forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilters.php
173 lines (140 loc) · 5.56 KB
/
filters.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?PHP // $Id$
// Allows the admin to create, delete and rename course categories
require_once("../config.php");
optional_variable($iselect);
optional_variable($uselect);
optional_variable($add);
optional_variable($remove);
optional_variable($up);
optional_variable($down);
require_login();
if (!isadmin()) {
error("Only administrators can use this page!");
}
if (!$site = get_site()) {
error("Site isn't defined!");
}
/// Print headings
$stradministration = get_string("administration");
$strconfiguration = get_string("configuration");
$strmanagefilters = get_string("managefilters");
$strversion = get_string("version");
$strsettings = get_string("settings");
$strup = get_string("up");
$strdown = get_string("down");
$stractive = get_string("active");
$strinactive = get_string("inactive");
$strcachetext = get_string("cachetext", "admin");
$strconfigcachetext = get_string("configcachetext", 'admin');
$strfilteruploadedfiles = get_string("filteruploadedfiles", "admin");
$strfilterall = get_string("filterall", "admin");
$strconfigfilteruploadedfiles = get_string("configfilteruploadedfiles", 'admin');
$strconfigfilterall = get_string("configfilterall", "admin");
print_header("$site->shortname: $strmanagefilters", "$site->fullname",
"<a href=\"index.php\">$stradministration</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> $strmanagefilters");
print_heading($strmanagefilters);
/// Make a list of all available filters and the best names for them we can find
$allfilters = array();
$filterlocations = array("mod", "filter");
foreach ($filterlocations as $filterlocation) {
$plugins = get_list_of_plugins($filterlocation);
foreach ($plugins as $key => $plugin) {
if (is_readable("$CFG->dirroot/$filterlocation/$plugin/filter.php")) {
$name = trim(get_string("filtername", $plugin));
if (empty($name) or $name == "[[filtername]]") {
$name = $plugin;
}
$allfilters["$filterlocation/$plugin"] = $name;
}
}
}
/// Make an array of all the currently installed filters
$installedfilters = array();
if (!empty($CFG->textfilters)) {
$installedfilters = explode(',',$CFG->textfilters);
// Do a little cleanup for robustness
foreach ($installedfilters as $key => $installedfilter) {
if (empty($installedfilter)) {
unset($installedfilters[$key]);
set_config("textfilters", implode(',', $installedfilters));
}
}
}
$selectedfilter = "none";
/// If data submitted, then process and store.
if (!empty($options)) {
if (($config = data_submitted()) && confirm_sesskey()) {
unset($config->options);
unset($config->sesskey);
foreach ($config as $name => $value) {
set_config($name, $value);
}
}
}
if (!empty($add) and !empty($uselect) and confirm_sesskey()) {
$selectedfilter = $uselect;
if (!in_array($selectedfilter, $installedfilters)) {
$installedfilters[] = $selectedfilter;
set_config("textfilters", implode(',', $installedfilters));
}
} else if (!empty($remove) and !empty($iselect) and confirm_sesskey()) {
$selectedfilter = $iselect;
foreach ($installedfilters as $key => $installedfilter) {
if ($installedfilter == $selectedfilter) {
unset($installedfilters[$key]);
}
}
set_config("textfilters", implode(',', $installedfilters));
} else if ((!empty($up) or !empty($down)) and !empty($iselect) and confirm_sesskey()) {
if (!empty($up)) {
if ($allfilters[$iselect]) {
foreach ($installedfilters as $key => $installedfilter) {
if ($installedfilter == $iselect) {
$movefilter = $key;
break;
}
$swapfilter = $key;
}
}
}
if (!empty($down)) {
if ($allfilters[$iselect]) {
$choosenext = false;
foreach ($installedfilters as $key => $installedfilter) {
if ($choosenext) {
$swapfilter = $key;
break;
}
if ($installedfilter == $iselect) {
$movefilter = $key;
$choosenext = true;
}
}
}
}
if (isset($swapfilter) and isset($movefilter)) {
$tempfilter = $installedfilters[$swapfilter];
$installedfilters[$swapfilter] = $installedfilters[$movefilter];
$installedfilters[$movefilter] = $tempfilter;
set_config("textfilters", implode(',', $installedfilters));
}
$selectedfilter = $iselect;
}
/// Make an array of all the currently uninstalled filters
$uninstalledfilters = array();
foreach ($allfilters as $filter => $name) {
$installed = false;
foreach ($installedfilters as $installedfilter) {
if ($installedfilter == $filter) {
$installed = true;
}
}
if (!$installed) {
$uninstalledfilters[] = $filter;
}
}
/// Print the current form
include("filters.html");
print_footer();
?>