Skip to content

Commit

Permalink
filters: MDL-7336 settings page for setting the local enabled/disable…
Browse files Browse the repository at this point in the history
…d state
  • Loading branch information
tjhunt committed Apr 13, 2009
1 parent a042675 commit 0f74bb0
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 7 deletions.
2 changes: 2 additions & 0 deletions admin/settings/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

$ADMIN->add('frontpage', new admin_externalpage('frontpageroles', get_string('frontpageroles', 'admin'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . $frontpagecontext->id, 'moodle/role:assign', false, $frontpagecontext));

$ADMIN->add('frontpage', new admin_externalpage('frontpagefilters', get_string('frontpagefilters', 'admin'), "$CFG->wwwroot/filter/manage.php?contextid=" . $frontpagecontext->id, 'moodle/filter:manage', false, $frontpagecontext));

$ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/site:backup', false, $frontpagecontext));

$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
Expand Down
184 changes: 184 additions & 0 deletions filter/manage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php // $Id$

///////////////////////////////////////////////////////////////////////////
// //
// 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 //
// //
///////////////////////////////////////////////////////////////////////////

/**
* Lets users configure which filters are active in a sub-context.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodlecore
*//** */

require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->libdir . '/adminlib.php');

$contextid = required_param('contextid',PARAM_INT);

if (!$context = get_context_instance_by_id($contextid)) {
print_error('wrongcontextid', 'error');
}

// This is a policy decision, rather than something that would be impossible to implement.
if (!in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE))) {
print_error('cannotcustomisefiltersblockuser', 'error');
}

$isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
$contextname = print_context_name($context);

if ($context->contextlevel == CONTEXT_COURSECAT) {
$course = clone($SITE);
} else if ($context->contextlevel == CONTEXT_COURSE) {
$course = $DB->get_record('course', array('id' => $context->instanceid));
} else {
// Must be module context.
$course = $DB->get_record_sql('SELECT c.* FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid WHERE ctx.id = ?',
array(get_parent_contextid($context)));
}
if (!$course) {
print_error('invalidcourse', 'error');
}

/// Check login and permissions.
require_login($course);
require_capability('moodle/filter:manage', $context);

/// Get the list of available filters.
$availablefilters = filter_get_available_in_context($context);
if (!$isfrontpage && empty($availablefilters)) {
print_error('nofiltersenabled', 'error');
}

/// Process any form submission.
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
foreach ($availablefilters as $filter => $filterinfo) {
$newstate = optional_param(str_replace('/', '_', $filter), false, PARAM_INT);
if ($newstate !== false && $newstate != $filterinfo->localstate) {
filter_set_local_state($filter, $context->id, $newstate);
}
}
redirect($CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id, get_string('changessaved'), 1);
}

/// These are needed early because of tabs.php
$assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
$overridableroles = get_overridable_roles($context, ROLENAME_BOTH);

/// Work out an appropriate page title.
$title = get_string('filtersettingsfor', 'filters', $contextname);
$straction = get_string('filters', 'admin'); // Used by tabs.php

/// Print the header and tabs
if ($context->contextlevel == CONTEXT_COURSE and $context->instanceid == SITEID) {
admin_externalpage_setup('frontpagefilters');
admin_externalpage_print_header();
} else {
$currenttab = 'filters';
include_once($CFG->dirroot . '/' . $CFG->admin . '/roles/tabs.php');
}

/// Print heading.
print_heading_with_help($title, 'localfiltersettings');

if (empty($availablefilters)) {
echo '<p class="centerpara">' . get_string('nofiltersenabled', 'filters') . "</p>\n";
} else {
$settingscol = false;
foreach ($availablefilters as $filter => $notused) {
$hassettings = filter_has_local_settings($filter);
$availablefilters[$filter]->hassettings = $hassettings;
$settingscol = $settingscol || $hassettings;
}

$strsettings = get_string('settings');
$stroff = get_string('off', 'filters');
$stron = get_string('on', 'filters');
$strdefaultoff = get_string('defaultx', 'filters', $stroff);
$strdefaulton = get_string('defaultx', 'filters', $stron);
$activechoices = array(
TEXTFILTER_INHERIT => '',
TEXTFILTER_OFF => $stroff,
TEXTFILTER_ON => $stron,
);

echo '<form action="' . $CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id . '" method="post">';
echo "\n<div>\n";
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';

$table = new stdClass;
$table->head = array(get_string('filter'), get_string('isactive', 'filters'));
$table->align = array('left', 'left');
if ($settingscol) {
$table->head[] = $strsettings;
$table->align = 'left';
}
$table->width = ' ';
$table->data = array();

// iterate through filters adding to display table
foreach ($availablefilters as $filter => $filterinfo) {
$row = array();

// Filter name.
$row[] = filter_get_name($filter);

// Default/on/off choice.
if ($filterinfo->inheritedstate == TEXTFILTER_ON) {
$activechoices[TEXTFILTER_INHERIT] = $strdefaulton;
} else {
$activechoices[TEXTFILTER_INHERIT] = $strdefaultoff;
}
$row[] = choose_from_menu($activechoices, str_replace('/', '_', $filter),
$filterinfo->localstate, '', '', '', true);

// Settings link, if required
if ($settingscol) {
$settings = '';
if ($filterinfo->hassettings) {
$settings = '<a href="' . $CFG->wwwroot . '/filter/settings.php?contextid=' .
$context->id . '&amp;filter=' . $filter . '">' . $strsettings . '</a>';
}
$row[] = $settings;
}

$table->data[] = $row;
}

print_table($table);
echo '<div class="buttons">' . "\n";
echo '<input type="submit" name="savechanges" value="' . get_string('savechanges') . '" />';
echo "\n</div>\n";
echo "</div>\n";
echo "</form>\n";

}

/// Appropriate back link.
if (!$isfrontpage && ($url = get_context_url($context))) {
echo '<div class="backlink"><a href="' . $url . '">' .
get_string('backto', '', $contextname) . '</a></div>';
}

print_footer($course);
?>
2 changes: 2 additions & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
$string['filterall'] = 'Filter all strings';
$string['filtermatchoneperpage'] = 'Filter match once per page';
$string['filtermatchonepertext'] = 'Filter match once per text';
$string['filters'] = 'Filters';
$string['filtersettings'] = 'Manage filters';
$string['filtersettingsgeneral'] = 'General filter settings';
$string['filteruploadedfiles'] = 'Filter uploaded files';
Expand All @@ -432,6 +433,7 @@
$string['frontpage'] = 'Front Page';
$string['frontpagebackup'] = 'Front Page backup';
$string['frontpagedefaultrole'] = 'Default frontpage role';
$string['frontpagefilters'] = 'Front page filters';
$string['frontpageloggedin'] = 'Front page items when logged in';
$string['frontpagequestions'] = 'Front Page questions';
$string['frontpageoverrides'] = 'Front Page permission overrides';
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$string['cannotcreateuser'] = 'Error creating user record';
$string['cannotcreateorfindstructs'] = 'Error finding or creating section structures for this course';
$string['cannotcreatepopupwin'] = 'Undefined element - cannot create pop-up window';
$string['cannotcustomisefiltersblockuser'] = 'You cannot customise filters settings in user or block contexts.';
$string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation. This permission is controlled by the capability \"moodle/site:langeditlocal\". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
$string['cannotdeletelangcache'] = 'Language cache cannot be deleted, please fix permissions in dataroot/cache/languages!';
$string['cannotdeletebackupids'] = 'Couldn\'t delete previous backup ids';
Expand Down Expand Up @@ -347,6 +348,7 @@
$string['nologinas'] = 'You are not allowed to login as that user';
$string['noadmins'] = 'No administrators!';
$string['noexistingcategory'] = 'No existing category';
$string['nofiltersenabled'] = 'No filters are enabled.';
$string['notlocalisederrormessage'] = '$a';
$string['nousers'] = 'No such user!';
$string['nonmeaningfulcontent'] = 'Non meaningful content';
Expand Down
4 changes: 4 additions & 0 deletions lang/en_utf8/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
$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['defaultx'] = 'Default ($a)';
$string['disabled'] = 'Disabled';
$string['doesnotcontain'] = 'doesn\'t contain';
$string['endswith'] = 'ends with';
$string['filterallwarning'] = 'Applying filters to headings as well as content can greatly increase the load on your server. Please use that \'Apply to\' settings sparingly. The main use is with the multilang filter.';
$string['filtersettingsfor'] = 'Filter settings for $a';
$string['firstaccess'] = 'First access';
$string['globalrolelabel'] = '$a->label is $a->value';
$string['isactive'] = 'Active?';
Expand All @@ -34,6 +36,8 @@
$string['isnotequalto'] = 'isn\'t equal to';
$string['isnotdefined'] = 'isn\'t defined';
$string['newfilter'] = 'New filter';
$string['nofiltersenabled'] = 'No filter plugins have been enabled on this site.';
$string['off'] = 'Off';
$string['offbutavailable'] = 'Off, but available';
$string['on'] = 'On';
$string['profilelabel'] = '$a->label: $a->profile $a->operator $a->value';
Expand Down
8 changes: 8 additions & 0 deletions lang/en_utf8/help/localfiltersettings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Filter settings</h1>

<p>This page lets you turn filters on or off in a particular part of the site.
This page only gives you access to those filters that the Administrator has
enabled.</p>

<p>Some filters may also let you set local settings, in which case there will be
a 'Settings' link next to their name.</p>
54 changes: 48 additions & 6 deletions lib/filterlib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
<?php // $Id$
// Contains special functions that are particularly useful to filters

///////////////////////////////////////////////////////////////////////////
// //
// 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 //
// //
///////////////////////////////////////////////////////////////////////////

/**
* Library functions for managing text filter plugins.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodlecore
*/

/**
* The states a filter can be in, stored in the filter_active table.
Expand Down Expand Up @@ -308,8 +337,9 @@ function filterobject($phrase, $hreftagbegin='<span class="highlight">',
* @param string $filter the folder name where the filter lives.
* @return string the human-readable name for this filter.
*/
function filter_get_name($filterlocation, $filter) {
switch ($filterlocation) {
function filter_get_name($filter) {
list($type, $filter) = explode('/', $filter);
switch ($type) {
case 'filter':
$strfiltername = get_string('filtername', 'filter_' . $filter);
if (substr($strfiltername, 0, 2) != '[[') {
Expand All @@ -321,12 +351,12 @@ function filter_get_name($filterlocation, $filter) {
case 'mod':
$strfiltername = get_string('filtername', $filter);
if (substr($strfiltername, 0, 2) == '[[') {
$strfiltername .= ' (' . $filterlocation . '/' . $filter . ')';
$strfiltername .= ' (' . $type . '/' . $filter . ')';
}
return $strfiltername;

default:
throw new coding_exception('Unknown filter location ' . $filterlocation);
throw new coding_exception('Unknown filter type ' . $type);
}
}

Expand All @@ -345,7 +375,7 @@ function filter_get_all_installed() {
foreach ($filters as $filter) {
$path = $filterlocation . '/' . $filter;
if (is_readable($CFG->dirroot . '/' . $path . '/filter.php')) {
$strfiltername = filter_get_name($filterlocation, $filter);
$strfiltername = filter_get_name($path);
$filternames[$path] = $strfiltername;
}
}
Expand Down Expand Up @@ -726,6 +756,18 @@ function filter_has_global_settings($filter) {
return is_readable($settingspath);
}

/**
* Does this filter have local (per-context) settings?
*
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @return boolean Whether there should be a 'Settings' link on the manage filters in context page.
*/
function filter_has_local_settings($filter) {
global $CFG;
// TODO
return false;
}

/**
* Certain types of context (block and user) may not have local filter settings.
* the function checks a context to see whether it may have local config.
Expand Down
2 changes: 1 addition & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8372,7 +8372,7 @@ function get_plugin_name($plugin, $type='mod') {
}
break;
case 'filter':
$plugin_name = filter_get_name('filter', $plugin);
$plugin_name = filter_get_name('filter/' . $plugin);
break;
default:
$plugin_name = $plugin;
Expand Down
2 changes: 2 additions & 0 deletions theme/standard/styles_layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ body#admin-modules table.generaltable td.c0
#admin-qtypes #qtypes img.spacer {
width: 16px;
}
#filter-manage .buttons,
#admin-roles-allow .buttons,
#admin-roles-manage .buttons,
#admin-roles-define .buttons,
Expand Down Expand Up @@ -1183,6 +1184,7 @@ body#admin-modules table.generaltable td.c0
#admin-roles-define .mform {
width: 100%;
}
#filter-manage .backlink,
#admin-roles-manage .backlink,
#admin-roles-define .backlink,
#admin-roles-explain .backlink,
Expand Down

0 comments on commit 0f74bb0

Please sign in to comment.