From 0f74bb01ffee1465b96e71a8ce02b8c7a68c67b0 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 13 Apr 2009 07:12:41 +0000 Subject: [PATCH] filters: MDL-7336 settings page for setting the local enabled/disabled state --- admin/settings/frontpage.php | 2 + filter/manage.php | 184 +++++++++++++++++++++ lang/en_utf8/admin.php | 2 + lang/en_utf8/error.php | 2 + lang/en_utf8/filters.php | 4 + lang/en_utf8/help/localfiltersettings.html | 8 + lib/filterlib.php | 54 +++++- lib/moodlelib.php | 2 +- theme/standard/styles_layout.css | 2 + 9 files changed, 253 insertions(+), 7 deletions(-) create mode 100644 filter/manage.php create mode 100644 lang/en_utf8/help/localfiltersettings.html diff --git a/admin/settings/frontpage.php b/admin/settings/frontpage.php index 7376ce19a0..93069394bf 100644 --- a/admin/settings/frontpage.php +++ b/admin/settings/frontpage.php @@ -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.'&wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext)); diff --git a/filter/manage.php b/filter/manage.php new file mode 100644 index 0000000000..05bd69b95f --- /dev/null +++ b/filter/manage.php @@ -0,0 +1,184 @@ +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 '

' . get_string('nofiltersenabled', 'filters') . "

\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 '
'; + echo "\n
\n"; + echo ''; + + $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 = '' . $strsettings . ''; + } + $row[] = $settings; + } + + $table->data[] = $row; + } + + print_table($table); + echo '
' . "\n"; + echo ''; + echo "\n
\n"; + echo "
\n"; + echo "
\n"; + +} + +/// Appropriate back link. +if (!$isfrontpage && ($url = get_context_url($context))) { + echo ''; +} + +print_footer($course); +?> diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 243a69c6a2..86c18d23c8 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -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'; diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 023f984183..4edf487994 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -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'; diff --git a/lang/en_utf8/filters.php b/lang/en_utf8/filters.php index 06fd8ceab8..7ba975133f 100644 --- a/lang/en_utf8/filters.php +++ b/lang/en_utf8/filters.php @@ -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 index 0000000000..175a7f20a1 --- /dev/null +++ b/lang/en_utf8/help/localfiltersettings.html @@ -0,0 +1,8 @@ +

Filter settings

+ +

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.

+ +

Some filters may also let you set local settings, in which case there will be +a 'Settings' link next to their name.

\ No newline at end of file diff --git a/lib/filterlib.php b/lib/filterlib.php index 9844b37df2..7a7a1f9595 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -1,5 +1,34 @@ 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. diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 04774bda6f..e46cda2bc4 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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; diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 43b2c0fa6c..e2b8531783 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -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, -- 2.39.5