Skip to content

Commit

Permalink
filters: MDL-7336 redo global settings page to use the new libs
Browse files Browse the repository at this point in the history
Note: ->stringfilters update not done yet.
  • Loading branch information
tjhunt committed Apr 13, 2009
1 parent ccc161f commit 456c8cc
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 162 deletions.
171 changes: 102 additions & 69 deletions admin/filters.php
Original file line number Diff line number Diff line change
@@ -1,102 +1,135 @@
<?php // $Id$

require_once('../config.php');
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////

$action = optional_param('action', '', PARAM_ACTION);
/**
* Processes actions from the admin_setting_managefilters object (defined in
* adminlib.php).
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package administration
*//** */

require_once(dirname(__FILE__) . '/../config.php');

$action = optional_param('action', '', PARAM_ACTION);
$filterpath = optional_param('filterpath', '', PARAM_PATH);

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $systemcontext);

$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managefilters";

if (!confirm_sesskey()) {
redirect($returnurl);
}

// get a list of installed filters
$installedfilters = array();
$filterlocations = array('mod','filter');
foreach ($filterlocations as $filterlocation) {
$plugins = get_list_of_plugins($filterlocation);
foreach ($plugins as $plugin) {
$pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
if (is_readable($pluginpath)) {
$installedfilters["$filterlocation/$plugin"] = "$filterlocation/$plugin";
}
}
}
$filters = filter_get_global_states();

// get all the currently selected filters
if (!empty($CFG->textfilters)) {
$activefilters = explode(',', $CFG->textfilters);
} else {
$activefilters = array();
// In case any new filters have been installed, but not put in the table yet.
$fitlernames = filter_get_all_installed();
$newfilters = $fitlernames;
foreach ($filters as $filter => $notused) {
unset($newfilters[$filter]);
}

//======================
// Process Actions
//======================
if (!isset($filters[$filterpath]) && !isset($newfilters[$filterpath])) {
throw new moodle_exception('filternotinstalled', 'error', $returnurl, $filterpath);
}

switch ($action) {

case 'hide':
$key=array_search($filterpath, $activefilters);
// check filterpath is valid
if ($key===false) {
break;
}
// just delete it
unset($activefilters[$key]);
break;

case 'show':
// check filterpath is valid
if (!array_key_exists($filterpath, $installedfilters)) {
print_error('filternotinstalled', 'error', $url, $filterpath);
} elseif (array_search($filterpath,$activefilters)) {
// filterpath is already active - doubleclick??
} else {
// add it to installed filters
$activefilters[] = $filterpath;
$activefilters = array_unique($activefilters);
case 'setstate':
if ($newstate = optional_param('newstate', '', PARAM_INTEGER)) {
filter_set_global_state($filterpath, $newstate);
unset($newfilters[$filterpath]);
}
break;

case 'down':
$key=array_search($filterpath, $activefilters);
// check filterpath is valid
if ($key===false) {
print_error("filternotactive", 'error', $url, $filterpath );
} elseif ($key>=(count($activefilters)-1)) {
// cannot be moved any further down - doubleclick??
} else {
// swap with $key+1
$fsave = $activefilters[$key];
$activefilters[$key] = $activefilters[$key+1];
$activefilters[$key+1] = $fsave;
if (isset($filters[$filterpath])) {
$oldpos = $filters[$filterpath]->sortorder;
if ($oldpos <= count($filters)) {
filter_set_global_state($filterpath, $filters[$filterpath]->active, $oldpos + 1);
}
}
break;

case 'up':
$key=array_search($filterpath, $activefilters);
// check filterpath is valid
if ($key===false) {
print_error("filternotactive", 'error', $url, $filterpath );
} elseif ($key<1) {
//cannot be moved any further up - doubleclick??
} else {
// swap with $key-1
$fsave = $activefilters[$key];
$activefilters[$key] = $activefilters[$key-1];
$activefilters[$key-1] = $fsave;
if (isset($filters[$filterpath])) {
$oldpos = $filters[$filterpath]->sortorder;
if ($oldpos >= 1) {
filter_set_global_state($filterpath, $filters[$filterpath]->active, $oldpos - 1);
}
}
break;

case 'delete':
$filtername = $fitlernames[$filterpath];
if (substr($filterpath, 0, 4) == 'mod/') {
$mod = basename($filterpath);
$a = new stdClass;
$a->filter = $filtername;
$a->module = get_string('modulename', $mod);
print_error('cannotdeletemodfilter', 'admin', admin_url('qtypes.php'), $a);
}

// If not yet confirmed, display a confirmation message.
if (!optional_param('confirm', '', PARAM_BOOL)) {
$title = get_string('deletefilterareyousure', 'admin', $filtername);
print_header($title, $title);
print_heading($title);
notice_yesno(get_string('deletefilterareyousuremessage', 'admin', $filtername),
admin_url('filters.php?action=delete&amp;filterpath=' . $delete . '&amp;confirm=1&amp;sesskey=' . sesskey()),
$returnurl, NULL, NULL, 'post', 'get');
print_footer('empty');
exit;
}

// Do the deletion.
$title = get_string('deletingfilter', 'admin', $filtername);
print_header($title, $title);
print_heading($title);

// Delete all data for this plugin.
filter_delete_all_data($filterpath);

$a = new stdClass;
$a->fitler = $filtername;
$a->directory = $filterparth;
print_box(get_string('deletefilterfiles', 'admin', $a), 'generalbox', 'notice');
print_continue($returnurl);
admin_externalpage_print_footer();
exit;
}

// save, reset cache and return
set_config('textfilters', implode(',', $activefilters));
// Add any missing filters to the DB table.
foreach ($newfilters as $filter => $notused) {
filter_set_global_state($filter, TEXTFILTER_DISABLED);
}

// Reset caches and return
reset_text_filters_cache();
redirect($returnurl);

?>
5 changes: 5 additions & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$string['calendarexportsalt'] = 'Calendar export salt';
$string['calendarsettings'] = 'Calendar';
$string['cannotdeletemissingqtype'] = 'You cannot delete the missing question type. It is needed by the system.';
$string['cannotdeletemodfilter'] = 'You cannot uninstall the \'$a->filter\' because it is part of the \'$a->module\' module.';
$string['cannotdeleteqtypeinuse'] = 'You cannot delete the question type \'$a\'. There are questions of this type in the question bank.';
$string['cannotdeleteqtypeneeded'] = 'You cannot delete the question type \'$a\'. There are other question types installed that rely on it.';
$string['cfgwwwrootwarning'] = 'You have defined &#36;CFG->wwwroot incorrectly in your config.php file. It does not match the URL you are using to access this page. Please correct it, or you will experience strange bugs like <a href=\'http://tracker.moodle.org/browse/MDL-11061\'>MDL-11061</a>.';
Expand Down Expand Up @@ -334,11 +335,15 @@
$string['defaultuserroleid'] = 'Default role for all users';
$string['defaultvalues'] = 'Default values';
$string['deleteerrors'] = 'Delete errors';
$string['deletefilterareyousure'] = 'Are you sure you want to delete the filter \'$a\'';
$string['deletefilterareyousuremessage'] = 'You are about to completely delete the filter \'$a\'. Are you sure you want to uninstall it?';
$string['deletefilterfiles'] = 'All data associated with the filter \'$a->filter\' has been deleted from the database. To complete the deletion (and to prevent the filter from re-installing itself), you should now delete this directory from your server: $a->directory';
$string['deleteincompleteusers'] = 'Delete incomplete users after';
$string['deleteqtypeareyousure'] = 'Are you sure you want to delete the question type \'$a\'';
$string['deleteqtypeareyousuremessage'] = 'You are about to completely delete the question type \'$a\'. Are you sure you want to uninstall it?';
$string['deleteunconfirmed'] = 'Delete not fully setup users after';
$string['deleteuser'] = 'Delete user';
$string['deletingfilter'] = 'Deleting filter \'$a\'';
$string['deletingqtype'] = 'Deleting question type \'$a\'';
$string['density'] = 'Density';
$string['denyemailaddresses'] = 'Denied email domains';
Expand Down
7 changes: 7 additions & 0 deletions lang/en_utf8/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
$string['anyfield'] = 'any field';
$string['anyrole'] = 'any role';
$string['anyvalue'] = 'any value';
$string['applyto'] = 'Apply to';
$string['categoryrole'] = 'Category role';
$string['tablenosave'] = 'Changes in table above are saved automatically.';
$string['content'] = 'Content';
$string['contentandheadings'] = 'Content and headings';
$string['contains'] = 'contains';
$string['courserole'] = 'Course role';
$string['courserolelabel'] = '$a->label is $a->rolename in $a->coursename from $a->categoryname';
$string['courserolelabelerror'] = '$a->label error: course $a->coursename does not exist';
$string['datelabelisafter'] = '$a->label is after $a->after';
$string['datelabelisbefore'] = '$a->label is before $a->before';
$string['datelabelisbetween'] = '$a->label is between $a->after and $a->before';
$string['disabled'] = 'Disabled';
$string['doesnotcontain'] = 'doesn\'t contain';
$string['endswith'] = 'ends with';
$string['firstaccess'] = 'First access';
$string['globalrolelabel'] = '$a->label is $a->value';
$string['isactive'] = 'Active?';
$string['isanyvalue'] = 'is any value';
$string['isafter'] = 'is after';
$string['isbefore'] = 'is before';
Expand All @@ -28,6 +33,8 @@
$string['isnotequalto'] = 'isn\'t equal to';
$string['isnotdefined'] = 'isn\'t defined';
$string['newfilter'] = 'New filter';
$string['offbutavailable'] = 'Off, but available';
$string['on'] = 'On';
$string['profilelabel'] = '$a->label: $a->profile $a->operator $a->value';
$string['profilelabelnovalue'] = '$a->label: $a->profile $a->operator';
$string['removeall'] = 'Remove all filters';
Expand Down
Loading

0 comments on commit 456c8cc

Please sign in to comment.