3 // Edit list of available text filters
5 require_once('../config.php');
6 require_once($CFG->libdir
.'/adminlib.php');
7 require_once($CFG->libdir
.'/tablelib.php');
10 define('FILTER_TABLE','filter_administration_table');
12 $adminroot = admin_get_root();
13 admin_externalpage_setup('managefilters', $adminroot);
15 // get values from page
16 $params = new object();
17 $params->action
= optional_param('action', '', PARAM_ACTION
);
18 $params->filterpath
= optional_param('filterpath', '', PARAM_PATH
);
19 $params->cachetext
= optional_param('cachetext', 0, PARAM_INT
);
20 $params->filterall
= optional_param('filterall', 0, PARAM_BOOL
);
21 $params->filteruploadedfiles
= optional_param('filteruploadedfiles', 0, PARAM_INT
);
22 $params->filtermatchoneperpage
= optional_param('filtermatchoneperpage', 0, PARAM_BOOL
);
23 $params->filtermatchonepertext
= optional_param('filtermatchonepertext', 0, PARAM_BOOL
);
25 // some basic information
27 $myurl = "$url?sesskey=" . sesskey();
28 $img = "$CFG->pixpath/t";
30 // get translated strings for use on page
32 $txt->managefilters
= get_string('managefilters');
33 $txt->administration
= get_string('administration');
34 $txt->configuration
= get_string('configuration');
35 $txt->name
= get_string('name');
36 $txt->hide
= get_string('hide');
37 $txt->show
= get_string('show');
38 $txt->hideshow
= "$txt->hide/$txt->show";
39 $txt->settings
= get_string('settings');
40 $txt->up
= get_string('up');
41 $txt->down
= get_string('down');
42 $txt->updown
= "$txt->up/$txt->down";
43 $txt->cachetext
= get_string('cachetext', 'admin');
44 $txt->configcachetext
= get_string('configcachetext', 'admin');
45 $txt->filteruploadedfiles
= get_string('filteruploadedfiles','admin');
46 $txt->configfilteruploadedfiles
= get_string('configfilteruploadedfiles','admin');
47 $txt->filterall
= get_string('filterall','admin');
48 $txt->filtermatchoneperpage
= get_string('filtermatchoneperpage','admin');
49 $txt->filtermatchonepertext
= get_string('filtermatchonepertext','admin');
50 $txt->configfilterall
= get_string('configfilterall','admin');
51 $txt->configfiltermatchoneperpage
= get_string('configfiltermatchoneperpage','admin');
52 $txt->configfiltermatchonepertext
= get_string('configfiltermatchonepertext','admin');
53 $txt->cachecontrols
= get_string('cachecontrols');
54 $txt->yes
= get_string('yes');
55 $txt->no
= get_string('no');
56 $txt->none
= get_string('none');
57 $txt->allfiles
= get_string('allfiles');
58 $txt->htmlfilesonly
= get_string('htmlfilesonly');
60 // get a list of possible filters (and translate name if possible)
61 // note filters can be in the dedicated filters area OR in their
63 $installedfilters = array();
64 $filtersettings = array();
65 $filterlocations = array('mod','filter');
66 foreach ($filterlocations as $filterlocation) {
67 $plugins = get_list_of_plugins($filterlocation);
68 foreach ($plugins as $plugin) {
69 $pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
70 $settingspath = "$CFG->dirroot/$filterlocation/$plugin/filterconfig.html";
71 if (is_readable($pluginpath)) {
72 $name = trim(get_string("filtername", $plugin));
73 if (empty($name) or ($name == '[[filtername]]')) {
74 $name = ucfirst($plugin);
76 $installedfilters["$filterlocation/$plugin"] = $name;
77 if (is_readable($settingspath)) {
78 $filtersettings[] = "$filterlocation/$plugin";
84 // get all the currently selected filters
85 if (!empty($CFG->textfilters
)) {
86 $oldactivefilters = explode(',', $CFG->textfilters
);
87 $oldactivefilters = array_unique($oldactivefilters);
89 $oldactivefilters = array();
92 // take this opportunity to clean up filters
93 $activefilters = array();
94 foreach ($oldactivefilters as $oldactivefilter) {
95 if (!empty($oldactivefilter) and array_key_exists($oldactivefilter, $installedfilters)) {
96 $activefilters[] = $oldactivefilter;
100 //======================
102 //======================
104 if ($params->action
=="") {
105 // store cleaned active filers in db
106 set_config('textfilters', implode(',', $activefilters));
107 } elseif (($params->action
=="hide") and confirm_sesskey()) {
108 $key=array_search($params->filterpath
, $activefilters);
109 // check filterpath is valid
111 // ignore it - doubleclick??
114 unset($activefilters[$key]);
115 set_config('textfilters', implode(',', $activefilters));
117 } elseif (($params->action
=="show") and confirm_sesskey()) {
118 // check filterpath is valid
119 if (!array_key_exists($params->filterpath
, $installedfilters)) {
120 error("Filter $params->filterpath is not currently installed", $url);
121 } elseif (array_search($params->filterpath
,$activefilters)) {
122 // filterpath is already active - doubleclick??
124 // add it to installed filters
125 $activefilters[] = $params->filterpath
;
126 $activefilters = array_unique($activefilters);
127 set_config('textfilters', implode(',', $activefilters));
129 } elseif (($params->action
=="down") and confirm_sesskey()) {
130 $key=array_search($params->filterpath
, $activefilters);
131 // check filterpath is valid
133 error("Filter $params->filterpath is not currently active", $url);
134 } elseif ($key>=(count($activefilters)-1)) {
135 // cannot be moved any further down - doubleclick??
138 $fsave = $activefilters[$key];
139 $activefilters[$key] = $activefilters[$key+
1];
140 $activefilters[$key+
1] = $fsave;
141 set_config('textfilters', implode(',', $activefilters));
143 } elseif (($params->action
=="up") and confirm_sesskey()) {
144 $key=array_search($params->filterpath
, $activefilters);
145 // check filterpath is valid
147 error("Filter $params->filterpath is not currently active", $url);
149 //cannot be moved any further up - doubleclick??
152 $fsave = $activefilters[$key];
153 $activefilters[$key] = $activefilters[$key-1];
154 $activefilters[$key-1] = $fsave;
155 set_config('textfilters', implode(',', $activefilters));
157 } elseif (($params->action
=="config") and confirm_sesskey()) {
158 set_config('cachetext', $params->cachetext
);
159 set_config('filteruploadedfiles', $params->filteruploadedfiles
);
160 set_config('filterall', $params->filterall
);
161 set_config('filtermatchoneperpage', $params->filtermatchoneperpage
);
162 set_config('filtermatchonepertext', $params->filtermatchonepertext
);
165 //======================
166 // Build Display Objects
167 //======================
169 // construct the display array with installed filters
170 // at the top in the right order
171 $displayfilters = array();
172 foreach ($activefilters as $activefilter) {
173 $name = $installedfilters[$activefilter];
174 $displayfilters[$activefilter] = $name;
176 foreach ($installedfilters as $key => $filter) {
177 if (!array_key_exists($key, $displayfilters)) {
178 $displayfilters[$key] = $filter;
182 // construct the flexible table ready to display
183 $table = new flexible_table(FILTER_TABLE
);
184 $table->define_columns(array('name', 'hideshow', 'order', 'settings'));
185 $table->define_headers(array($txt->name
, $txt->hideshow
, $txt->updown
, $txt->settings
));
186 $table->define_baseurl("$CFG->wwwroot/$CFG->admin/filters.php");
187 $table->set_attribute('id', 'filters');
188 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
191 // iterate through filters adding to display table
193 $activefilterscount = count($activefilters);
194 foreach ($displayfilters as $path => $name) {
195 $upath = urlencode($path);
196 // get hide/show link
197 if (in_array($path, $activefilters)) {
198 $hideshow = "<a href=\"$myurl&action=hide&filterpath=$upath\">";
199 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"$txt->hide\" /></a>";
201 $displayname = "<span>$name</span>";
204 $hideshow = "<a href=\"$myurl&action=show&filterpath=$upath\">";
205 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"$txt->show\" /></a>";
207 $displayname = "<span class=\"dimmed_text\">$name</span>";
210 // get up/down link (only if not hidden)
213 if ($updowncount>1) {
214 $updown .= "<a href=\"$myurl&action=up&filterpath=$upath\">";
215 $updown .= "<img src=\"$img/up.gif\" alt=\"$txt->up\" /></a> ";
218 $updown .= "<img src=\"$CFG->pixpath/spacer.gif\" class=\"icon\" alt=\"\" /> ";
220 if ($updowncount<$activefilterscount) {
221 $updown .= "<a href=\"$myurl&action=down&filterpath=$upath\">";
222 $updown .= "<img src=\"$img/down.gif\" alt=\"$txt->down\" /></a>";
225 $updown .= "<img src=\"$CFG->pixpath/spacer.gif\" class=\"icon\" alt=\"\" />";
230 // settings link (if defined)
232 if (in_array($path, $filtersettings)) {
233 $settings = "<a href=\"filter.php?filter=" . urlencode($path) . "\">";
234 $settings .= "{$txt->settings}</a>";
237 // write data into the table object
238 $table->add_data(array($displayname, $hideshow, $updown, $settings));
241 // build options list for cache lifetime
242 $seconds = array(604800,86400,43200,10800,7200,3600,2700,1800,900,600,540,480,420,360,300,240,180,120,60,30,0);
243 unset($lifetimeoptions);
244 foreach ($seconds as $second) {
245 if ($second>=86400) {
246 $options[$second] = get_string('numdays','',$second/86400);
248 elseif ($second>=3600) {
249 $options[$second] = get_string('numhours','',$second/3600);
251 elseif ($second>=60) {
252 $options[$second] = get_string('numminutes','',$second/60);
254 elseif ($second>=1) {
255 $options[$second] = get_string('numseconds','',$second);
258 $options[$second] = get_string('no');
262 //==============================
264 //==============================
266 admin_externalpage_print_header($adminroot);
268 print_heading_with_help($txt->managefilters
, 'filters');
270 // print the table of all the filters
271 $table->print_html();
273 // cache control table has been removed
275 admin_externalpage_print_footer($adminroot);