filters: MDL-7336 settings page for setting the local enabled/disabled state
authortjhunt <tjhunt>
Mon, 13 Apr 2009 07:12:41 +0000 (07:12 +0000)
committertjhunt <tjhunt>
Mon, 13 Apr 2009 07:12:41 +0000 (07:12 +0000)
admin/settings/frontpage.php
filter/manage.php [new file with mode: 0644]
lang/en_utf8/admin.php
lang/en_utf8/error.php
lang/en_utf8/filters.php
lang/en_utf8/help/localfiltersettings.html [new file with mode: 0644]
lib/filterlib.php
lib/moodlelib.php
theme/standard/styles_layout.css

index 7376ce19a05334060a1a83383a1f8416c07b4fa7..93069394bfcdafd32e7458e893751d86c11bb8a8 100644 (file)
@@ -63,6 +63,8 @@ if (get_site()) { //do not use during installation
 
         $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.'&amp;wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
diff --git a/filter/manage.php b/filter/manage.php
new file mode 100644 (file)
index 0000000..05bd69b
--- /dev/null
@@ -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);
+?>
index 243a69c6a258d1ef2488aed17b27232b8c1e2a03..86c18d23c81129fb4dee37c8d8dd3a0006276cd4 100644 (file)
@@ -422,6 +422,7 @@ $string['filestoredinhelp'] = 'Where the file will be stored';
 $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';
@@ -432,6 +433,7 @@ $string['framename'] = 'Frame name';
 $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';
index 023f984183e9eef60f4115d6c7bfdbe33f7e4716..4edf48799457eb5270d51e58a31279c7ad1dfc4b 100644 (file)
@@ -40,6 +40,7 @@ $string['cannotcreateuploaddir'] = 'Cannot create upload folder. The site admini
 $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';
@@ -347,6 +348,7 @@ $string['noguest'] = 'No guests here!';
 $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';
index 06fd8ceab85f6b446c73ed3011f328e6f88da39a..7ba975133f7a49596341d204a81cd9382b211d26 100644 (file)
@@ -18,10 +18,12 @@ $string['courserolelabelerror'] = '$a->label error: course $a->coursename does n
 $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?';
@@ -34,6 +36,8 @@ $string['isequalto'] = 'is equal to';
 $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';
diff --git a/lang/en_utf8/help/localfiltersettings.html b/lang/en_utf8/help/localfiltersettings.html
new file mode 100644 (file)
index 0000000..175a7f2
--- /dev/null
@@ -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>
\ No newline at end of file
index 9844b37df2a3a8617afebdb02a7cfa06be7004bf..7a7a1f9595ab8c00bf3e2f067d08399cc70bc1d7 100644 (file)
@@ -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.
@@ -308,8 +337,9 @@ class filterobject {
  * @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) != '[[') {
@@ -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);
     }
 }
 
@@ -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;
             }
         }
@@ -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.
index 04774bda6fdd4f9de4817f4ca7ff1371daf653e9..e46cda2bc4488c2658e3a560e51fd0c440bd0e83 100644 (file)
@@ -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;
index 43b2c0fa6ca161f8e2fa32ea9d6ef8700a3d728f..e2b8531783915978fb32db4b57b2ed6bc7fd29f3 100644 (file)
@@ -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,
@@ -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,