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 admin_externalpage_setup('managefilters');
14 // get values from page
15 $params = new object();
16 $params->action
= optional_param('action', '', PARAM_ACTION
);
17 $params->filterpath
= optional_param('filterpath', '', PARAM_PATH
);
18 $params->cachetext
= optional_param('cachetext', 0, PARAM_INT
);
19 $params->filterall
= optional_param('filterall', 0, PARAM_BOOL
);
20 $params->filteruploadedfiles
= optional_param('filteruploadedfiles', 0, PARAM_INT
);
21 $params->filtermatchoneperpage
= optional_param('filtermatchoneperpage', 0, PARAM_BOOL
);
22 $params->filtermatchonepertext
= optional_param('filtermatchonepertext', 0, PARAM_BOOL
);
24 // some basic information
26 $myurl = "$url?sesskey=" . sesskey();
27 $img = "$CFG->pixpath/t";
29 // get translated strings for use on page
31 $txt->managefilters
= get_string('managefilters');
32 $txt->administration
= get_string('administration');
33 $txt->configuration
= get_string('configuration');
34 $txt->name
= get_string('name');
35 $txt->hide
= get_string('hide');
36 $txt->show
= get_string('show');
37 $txt->hideshow
= "$txt->hide/$txt->show";
38 $txt->settings
= get_string('settings');
39 $txt->up
= get_string('up');
40 $txt->down
= get_string('down');
41 $txt->updown
= "$txt->up/$txt->down";
42 $txt->cachetext
= get_string('cachetext', 'admin');
43 $txt->configcachetext
= get_string('configcachetext', 'admin');
44 $txt->filteruploadedfiles
= get_string('filteruploadedfiles','admin');
45 $txt->configfilteruploadedfiles
= get_string('configfilteruploadedfiles','admin');
46 $txt->filterall
= get_string('filterall','admin');
47 $txt->filtermatchoneperpage
= get_string('filtermatchoneperpage','admin');
48 $txt->filtermatchonepertext
= get_string('filtermatchonepertext','admin');
49 $txt->configfilterall
= get_string('configfilterall','admin');
50 $txt->configfiltermatchoneperpage
= get_string('configfiltermatchoneperpage','admin');
51 $txt->configfiltermatchonepertext
= get_string('configfiltermatchonepertext','admin');
52 $txt->cachecontrols
= get_string('cachecontrols');
53 $txt->yes
= get_string('yes');
54 $txt->no
= get_string('no');
55 $txt->none
= get_string('none');
56 $txt->allfiles
= get_string('allfiles');
57 $txt->htmlfilesonly
= get_string('htmlfilesonly');
59 // get a list of possible filters (and translate name if possible)
60 // note filters can be in the dedicated filters area OR in their
62 $installedfilters = array();
63 $filtersettings = array();
64 $filterlocations = array('mod','filter');
65 foreach ($filterlocations as $filterlocation) {
66 $plugins = get_list_of_plugins($filterlocation);
67 foreach ($plugins as $plugin) {
68 $pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
69 $settingspath = "$CFG->dirroot/$filterlocation/$plugin/filterconfig.html";
70 if (is_readable($pluginpath)) {
71 $name = trim(get_string("filtername", $plugin));
72 if (empty($name) or ($name == '[[filtername]]')) {
73 $name = ucfirst($plugin);
75 $installedfilters["$filterlocation/$plugin"] = $name;
76 if (is_readable($settingspath)) {
77 $filtersettings[] = "$filterlocation/$plugin";
83 // get all the currently selected filters
84 if (!empty($CFG->textfilters
)) {
85 $oldactivefilters = explode(',', $CFG->textfilters
);
86 $oldactivefilters = array_unique($oldactivefilters);
88 $oldactivefilters = array();
91 // take this opportunity to clean up filters
92 $activefilters = array();
93 foreach ($oldactivefilters as $oldactivefilter) {
94 if (!empty($oldactivefilter) and array_key_exists($oldactivefilter, $installedfilters)) {
95 $activefilters[] = $oldactivefilter;
99 //======================
101 //======================
103 if ($params->action
=="") {
104 // store cleaned active filers in db
105 set_config('textfilters', implode(',', $activefilters));
106 } elseif (($params->action
=="hide") and confirm_sesskey()) {
107 $key=array_search($params->filterpath
, $activefilters);
108 // check filterpath is valid
110 // ignore it - doubleclick??
113 unset($activefilters[$key]);
114 set_config('textfilters', implode(',', $activefilters));
116 } elseif (($params->action
=="show") and confirm_sesskey()) {
117 // check filterpath is valid
118 if (!array_key_exists($params->filterpath
, $installedfilters)) {
119 error("Filter $params->filterpath is not currently installed", $url);
120 } elseif (array_search($params->filterpath
,$activefilters)) {
121 // filterpath is already active - doubleclick??
123 // add it to installed filters
124 $activefilters[] = $params->filterpath
;
125 $activefilters = array_unique($activefilters);
126 set_config('textfilters', implode(',', $activefilters));
128 } elseif (($params->action
=="down") and confirm_sesskey()) {
129 $key=array_search($params->filterpath
, $activefilters);
130 // check filterpath is valid
132 error("Filter $params->filterpath is not currently active", $url);
133 } elseif ($key>=(count($activefilters)-1)) {
134 // cannot be moved any further down - doubleclick??
137 $fsave = $activefilters[$key];
138 $activefilters[$key] = $activefilters[$key+
1];
139 $activefilters[$key+
1] = $fsave;
140 set_config('textfilters', implode(',', $activefilters));
142 } elseif (($params->action
=="up") and confirm_sesskey()) {
143 $key=array_search($params->filterpath
, $activefilters);
144 // check filterpath is valid
146 error("Filter $params->filterpath is not currently active", $url);
148 //cannot be moved any further up - doubleclick??
151 $fsave = $activefilters[$key];
152 $activefilters[$key] = $activefilters[$key-1];
153 $activefilters[$key-1] = $fsave;
154 set_config('textfilters', implode(',', $activefilters));
156 } elseif (($params->action
=="config") and confirm_sesskey()) {
157 set_config('cachetext', $params->cachetext
);
158 set_config('filteruploadedfiles', $params->filteruploadedfiles
);
159 set_config('filterall', $params->filterall
);
160 set_config('filtermatchoneperpage', $params->filtermatchoneperpage
);
161 set_config('filtermatchonepertext', $params->filtermatchonepertext
);
164 //======================
165 // Build Display Objects
166 //======================
168 // construct the display array with installed filters
169 // at the top in the right order
170 $displayfilters = array();
171 foreach ($activefilters as $activefilter) {
172 $name = $installedfilters[$activefilter];
173 $displayfilters[$activefilter] = $name;
175 foreach ($installedfilters as $key => $filter) {
176 if (!array_key_exists($key, $displayfilters)) {
177 $displayfilters[$key] = $filter;
181 // construct the flexible table ready to display
182 $table = new flexible_table(FILTER_TABLE
);
183 $table->define_columns(array('name', 'hideshow', 'order', 'settings'));
184 $table->define_headers(array($txt->name
, $txt->hideshow
, $txt->updown
, $txt->settings
));
185 $table->define_baseurl("$CFG->wwwroot/$CFG->admin/filters.php");
186 $table->set_attribute('id', 'filters');
187 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
190 // iterate through filters adding to display table
192 $activefilterscount = count($activefilters);
193 foreach ($displayfilters as $path => $name) {
194 $upath = urlencode($path);
195 // get hide/show link
196 if (in_array($path, $activefilters)) {
197 $hideshow = "<a href=\"$myurl&action=hide&filterpath=$upath\">";
198 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"$txt->hide\" /></a>";
200 $displayname = "<span>$name</span>";
203 $hideshow = "<a href=\"$myurl&action=show&filterpath=$upath\">";
204 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"$txt->show\" /></a>";
206 $displayname = "<span class=\"dimmed_text\">$name</span>";
209 // get up/down link (only if not hidden)
212 if ($updowncount>1) {
213 $updown .= "<a href=\"$myurl&action=up&filterpath=$upath\">";
214 $updown .= "<img src=\"$img/up.gif\" alt=\"$txt->up\" /></a> ";
217 $updown .= "<img src=\"$CFG->pixpath/spacer.gif\" class=\"icon\" alt=\"\" /> ";
219 if ($updowncount<$activefilterscount) {
220 $updown .= "<a href=\"$myurl&action=down&filterpath=$upath\">";
221 $updown .= "<img src=\"$img/down.gif\" alt=\"$txt->down\" /></a>";
224 $updown .= "<img src=\"$CFG->pixpath/spacer.gif\" class=\"icon\" alt=\"\" />";
229 // settings link (if defined)
231 if (in_array($path, $filtersettings)) {
232 $settings = "<a href=\"filter.php?filter=" . urlencode($path) . "\">";
233 $settings .= "{$txt->settings}</a>";
236 // write data into the table object
237 $table->add_data(array($displayname, $hideshow, $updown, $settings));
240 // build options list for cache lifetime
241 $seconds = array(604800,86400,43200,10800,7200,3600,2700,1800,900,600,540,480,420,360,300,240,180,120,60,30,0);
242 unset($lifetimeoptions);
243 foreach ($seconds as $second) {
244 if ($second>=86400) {
245 $options[$second] = get_string('numdays','',$second/86400);
247 elseif ($second>=3600) {
248 $options[$second] = get_string('numhours','',$second/3600);
250 elseif ($second>=60) {
251 $options[$second] = get_string('numminutes','',$second/60);
253 elseif ($second>=1) {
254 $options[$second] = get_string('numseconds','',$second);
257 $options[$second] = get_string('no');
261 //==============================
263 //==============================
265 admin_externalpage_print_header();
267 print_heading_with_help($txt->managefilters
, 'filters');
269 // print the table of all the filters
270 $table->print_html();
272 // cache control table has been removed
274 admin_externalpage_print_footer();