3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * Processes actions from the admin_setting_managefilters object (defined in
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31 * @package administration
34 require_once(dirname(__FILE__
) . '/../config.php');
35 require_once($CFG->libdir
. '/adminlib.php');
37 $action = optional_param('action', '', PARAM_ALPHANUMEXT
);
38 $filterpath = optional_param('filterpath', '', PARAM_SAFEDIR
);
41 $systemcontext = context_system
::instance();
42 require_capability('moodle/site:config', $systemcontext);
44 $returnurl = "$CFG->wwwroot/$CFG->admin/filters.php";
45 admin_externalpage_setup('managefilters');
47 $filters = filter_get_global_states();
49 // In case any new filters have been installed, but not put in the table yet.
50 $fitlernames = filter_get_all_installed();
51 $newfilters = $fitlernames;
52 foreach ($filters as $filter => $notused) {
53 unset($newfilters[$filter]);
56 /// Process actions ============================================================
59 if ($action !== 'delete' and !isset($filters[$filterpath]) and !isset($newfilters[$filterpath])) {
60 throw new moodle_exception('filternotinstalled', 'error', $returnurl, $filterpath);
63 if (!confirm_sesskey()) {
71 if ($newstate = optional_param('newstate', '', PARAM_INT
)) {
72 filter_set_global_state($filterpath, $newstate);
73 if ($newstate == TEXTFILTER_DISABLED
) {
74 filter_set_applies_to_strings($filterpath, false);
76 unset($newfilters[$filterpath]);
81 $applytostrings = optional_param('stringstoo', false, PARAM_BOOL
);
82 filter_set_applies_to_strings($filterpath, $applytostrings);
86 if (isset($filters[$filterpath])) {
87 filter_set_global_state($filterpath, $filters[$filterpath]->active
, 1);
92 if (isset($filters[$filterpath])) {
93 $oldpos = $filters[$filterpath]->sortorder
;
94 filter_set_global_state($filterpath, $filters[$filterpath]->active
, -1);
99 // Add any missing filters to the DB table.
100 foreach ($newfilters as $filter => $notused) {
101 filter_set_global_state($filter, TEXTFILTER_DISABLED
);
104 // Reset caches and return
106 core_plugin_manager
::reset_caches();
107 reset_text_filters_cache();
108 redirect($returnurl);
111 /// End of process actions =====================================================
113 /// Print the page heading.
114 echo $OUTPUT->header();
115 echo $OUTPUT->heading(get_string('filtersettings', 'admin'));
117 $activechoices = array(
118 TEXTFILTER_DISABLED
=> get_string('disabled', 'filters'),
119 TEXTFILTER_OFF
=> get_string('offbutavailable', 'filters'),
120 TEXTFILTER_ON
=> get_string('on', 'filters'),
122 $applytochoices = array(
123 0 => get_string('content', 'filters'),
124 1 => get_string('contentandheadings', 'filters'),
127 $filters = filter_get_global_states();
129 // In case any new filters have been installed, but not put in the table yet.
130 $filternames = filter_get_all_installed();
131 $newfilters = $filternames;
132 foreach ($filters as $filter => $notused) {
133 unset($newfilters[$filter]);
135 $stringfilters = filter_get_string_filters();
137 $table = new html_table();
138 $table->head
= array(get_string('filter'), get_string('isactive', 'filters'),
139 get_string('order'), get_string('applyto', 'filters'), get_string('settings'), get_string('uninstallplugin', 'core_admin'));
140 $table->colclasses
= array ('leftalign', 'leftalign', 'centeralign', 'leftalign', 'leftalign', 'leftalign');
141 $table->attributes
['class'] = 'admintable generaltable';
142 $table->id
= 'filterssetting';
143 $table->data
= array();
146 foreach ($filters as $filter => $filterinfo) {
147 if ($filterinfo->active
!= TEXTFILTER_DISABLED
) {
148 $lastactive = $filter;
152 // iterate through filters adding to display table
154 foreach ($filters as $filter => $filterinfo) {
155 $applytostrings = isset($stringfilters[$filter]) && $filterinfo->active
!= TEXTFILTER_DISABLED
;
156 $row = get_table_row($filterinfo, $firstrow, $filter == $lastactive, $applytostrings);
157 $table->data
[] = $row;
158 if ($filterinfo->active
== TEXTFILTER_DISABLED
) {
159 $table->rowclasses
[] = 'dimmed_text';
161 $table->rowclasses
[] = '';
165 foreach ($newfilters as $filter => $filtername) {
166 $filterinfo = new stdClass
;
167 $filterinfo->filter
= $filter;
168 $filterinfo->active
= TEXTFILTER_DISABLED
;
169 $row = get_table_row($filterinfo, false, false, false);
170 $table->data
[] = $row;
171 $table->rowclasses
[] = 'dimmed_text';
174 echo html_writer
::table($table);
175 echo '<p class="filtersettingnote">' . get_string('filterallwarning', 'filters') . '</p>';
176 echo $OUTPUT->footer();
178 /// Display helper functions ===================================================
180 function filters_action_url($filterpath, $action) {
181 if ($action === 'delete') {
182 return core_plugin_manager
::instance()->get_uninstall_url('filter_'.$filterpath, 'manage');
184 return new moodle_url('/admin/filters.php', array('sesskey'=>sesskey(), 'filterpath'=>$filterpath, 'action'=>$action));
187 function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) {
188 global $CFG, $OUTPUT, $activechoices, $applytochoices, $filternames; //TODO: this is sloppy coding style!!
190 $filter = $filterinfo->filter
;
193 if (!empty($filternames[$filter])) {
194 $row[] = $filternames[$filter];
196 $row[] = '<span class="error">' . get_string('filemissing', '', $filter) . '</span>';
200 $select = new single_select(filters_action_url($filter, 'setstate'), 'newstate', $activechoices, $filterinfo->active
, null, 'active' . $filter);
201 $select->set_label(get_string('isactive', 'filters'), array('class' => 'accesshide'));
202 $row[] = $OUTPUT->render($select);
206 $spacer = '<img src="' . $OUTPUT->pix_url('spacer') . '" class="iconsmall" alt="" />';
207 if ($filterinfo->active
!= TEXTFILTER_DISABLED
) {
209 $updown .= $OUTPUT->action_icon(filters_action_url($filter, 'up'), new pix_icon('t/up', get_string('up'), '', array('class' => 'iconsmall')));
213 if (!$islastactive) {
214 $updown .= $OUTPUT->action_icon(filters_action_url($filter, 'down'), new pix_icon('t/down', get_string('down'), '', array('class' => 'iconsmall')));
222 $select = new single_select(filters_action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, $applytostrings, null, 'applyto' . $filter);
223 $select->set_label(get_string('applyto', 'filters'), array('class' => 'accesshide'));
224 $select->disabled
= $filterinfo->active
== TEXTFILTER_DISABLED
;
225 $row[] = $OUTPUT->render($select);
227 // Settings link, if required
228 if (filter_has_global_settings($filter)) {
229 $row[] = '<a href="' . $CFG->wwwroot
. '/' . $CFG->admin
. '/settings.php?section=filtersetting' . $filter . '">' . get_string('settings') . '</a>';
235 $row[] = '<a href="' . filters_action_url($filter, 'delete') . '">' . get_string('uninstallplugin', 'core_admin') . '</a>';