--- /dev/null
+<?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 //
+// //
+///////////////////////////////////////////////////////////////////////////
+
+/**
+ * A Moodle form base class for editing local filter settings.
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package moodlecore
+ *//** */
+require_once($CFG->libdir . '/formslib.php');
+
+abstract class filter_local_settings_form extends moodleform {
+ protected $filter;
+ protected $context;
+
+ public function __construct($submiturl, $filter, $context) {
+ $this->filter = $filter;
+ $this->context = $context;
+ parent::moodleform($submiturl);
+ }
+
+ /**
+ * Build the form definition. Rather than overriding this method, you
+ * should probably override definition_inner instead.
+ *
+ * This method adds the necessary hidden fields and submit buttons,
+ * and calls definition_inner to insert the custom controls in the appropriate place.
+ */
+ public function definition() {
+ $mform =& $this->_form;
+
+ $this->definition_inner($mform);
+
+ $mform->addElement('hidden', 'contextid');
+ $mform->setType('contextid', PARAM_INT);
+ $mform->setDefault('contextid', $this->context->id);
+
+ $mform->addElement('hidden', 'filter');
+ $mform->setType('filter', PARAM_ALPHAEXT);
+ $mform->setDefault('filter', $this->filter);
+
+ $this->add_action_buttons();
+ }
+
+ /**
+ * Override this method to add your form controls.
+ * @param $mform the form we are building. $this->_form, but passed in for convinience.
+ */
+ abstract protected function definition_inner($mform);
+
+ /**
+ * Override this method to save the settings to the database. The default
+ * implementation will probalby be sufficient for most simple cases.
+ * @param object $data the form data that was submitted.
+ */
+ public function save_changes($data) {
+ $data = (array) $data;
+ unset($data['filter']);
+ unset($data['contextid']);
+ foreach ($data as $name => $value) {
+ if ($value !== '') {
+ filter_set_local_config($this->filter, $this->context->id, $name, $value);
+ } else {
+ filter_unset_local_config($this->filter, $this->context->id, $name);
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
require_once($CFG->libdir . '/adminlib.php');
$contextid = required_param('contextid',PARAM_INT);
+$forfilter = optional_param('filter', '', PARAM_SAFEPATH);
if (!$context = get_context_instance_by_id($contextid)) {
print_error('wrongcontextid', 'error');
$isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID;
$contextname = print_context_name($context);
+$baseurl = $CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id;
if ($context->contextlevel == CONTEXT_COURSECAT) {
$course = clone($SITE);
print_error('nofiltersenabled', 'error');
}
+// If we are handling local settings for a particular filter, start processing.
+if ($forfilter) {
+ if (!filter_has_local_settings($forfilter)) {
+ print_error('filterdoesnothavelocalconfig', 'error', $forfilter);
+ }
+ require_once($CFG->dirroot . '/filter/local_settings_form.php');
+ require_once($CFG->dirroot . '/' . $forfilter . '/filterlocalsettings.php');
+ $formname = basename($forfilter) . '_filter_local_settings_form';
+ $settingsform = new $formname($CFG->wwwroot . '/filter/manage.php', $forfilter, $context);
+ if ($settingsform->is_cancelled()) {
+ redirect($baseurl);
+ } else if ($data = $settingsform->get_data()) {
+ $settingsform->save_changes($data);
+ redirect($baseurl);
+ }
+}
+
/// Process any form submission.
-if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
+if ($forfilter == '' && 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) {
$overridableroles = get_overridable_roles($context, ROLENAME_BOTH);
/// Work out an appropriate page title.
-$title = get_string('filtersettingsfor', 'filters', $contextname);
+if ($forfilter) {
+ $a = new stdClass;
+ $a->filter = filter_get_name($forfilter);
+ $a->context = $contextname;
+ $title = get_string('filtersettingsforin', 'filters', $a);
+} else {
+ $title = get_string('filtersettingsin', 'filters', $contextname);
+}
$straction = get_string('filters', 'admin'); // Used by tabs.php
/// Print the header and tabs
if (empty($availablefilters)) {
echo '<p class="centerpara">' . get_string('nofiltersenabled', 'filters') . "</p>\n";
+} else if ($forfilter) {
+ $current = filter_get_local_config($forfilter, $contextid);
+ $settingsform->set_data((object) $current);
+ $settingsform->display();
} else {
$settingscol = false;
foreach ($availablefilters as $filter => $notused) {
TEXTFILTER_ON => $stron,
);
- echo '<form action="' . $CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id . '" method="post">';
+ echo '<form action="' . $baseurl . '" method="post">';
echo "\n<div>\n";
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
$table->align = array('left', 'left');
if ($settingscol) {
$table->head[] = $strsettings;
- $table->align = 'left';
+ $table->align[] = 'left';
}
$table->width = ' ';
$table->data = array();
if ($settingscol) {
$settings = '';
if ($filterinfo->hassettings) {
- $settings = '<a href="' . $CFG->wwwroot . '/filter/settings.php?contextid=' .
- $context->id . '&filter=' . $filter . '">' . $strsettings . '</a>';
+ $settings = '<a href="' . $baseurl . '&filter=' . $filter . '">' . $strsettings . '</a>';
}
$row[] = $settings;
}
$string['filenotfound'] = 'Sorry, the requested file could not be found';
$string['filenotreadable'] = 'File is not readable';
$string['filemismatch'] = 'Non-core file name mismatch. The file \"$a->current\" should be $a->file';
+$string['filterdoesnothavelocalconfig'] = 'The filter $a does not allow local configuration.';
$string['filternotinstalled'] = 'Filter $a is not currently installed';
$string['filternotactive'] = 'Filter $a is not currently active';
$string['forumblockingtoomanyposts'] = 'You have exceeded the posting threshold set for this forum';
$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['filtersettingsforin'] = 'Filter settings for $a->filter in $a->context';
+$string['filtersettingsin'] = 'Filter settings in $a';
$string['firstaccess'] = 'First access';
$string['globalrolelabel'] = '$a->label is $a->value';
$string['isactive'] = 'Active?';
protected static $singletoninstance;
protected function __construct() {
- $stringfilternames = filter_get_string_filters();
+ $this->stringfilternames = filter_get_string_filters();
}
/**
}
}
+/**
+ * Remove a particular local config variable for a filter in a context.
+ * @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
+ * @param integer $contextid The id of the context to get the local config for.
+ * @param string $name the setting name.
+ */
+function filter_unset_local_config($filter, $contextid, $name) {
+ global $DB;
+ $DB->delete_records('filter_config', array('filter' => $filter, 'contextid' => $contextid, 'name' => $name));
+}
+
/**
* Get local config variables for a filter in a context. Normally (when your
* filter is running) you don't need to call this, becuase the config is fetched
*/
function filter_has_local_settings($filter) {
global $CFG;
- // TODO
- return false;
+ $settingspath = $CFG->dirroot . '/' . $filter . '/filterlocalsettings.php';
+ return is_readable($settingspath);
}
/**