mirror of
https://github.com/moodle/moodle.git
synced 2025-02-19 07:41:02 +01:00
Merge branch 'MDL-32279' of git://github.com/stronk7/moodle
This commit is contained in:
commit
66d9586070
@ -35,14 +35,25 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class filter_glossary extends moodle_text_filter {
|
||||
|
||||
public function setup($page, $context) {
|
||||
// This only requires execution once per request.
|
||||
static $jsinitialised = false;
|
||||
if (empty($jsinitialised)) {
|
||||
$page->requires->yui_module(
|
||||
'moodle-filter_glossary-autolinker',
|
||||
'M.filter_glossary.init_filter_autolinking',
|
||||
array(array('courseid' => 0)));
|
||||
$jsinitialised = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function filter($text, array $options = array()) {
|
||||
global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS, $PAGE;
|
||||
global $CFG, $DB, $GLOSSARY_EXCLUDECONCEPTS;
|
||||
|
||||
// Trivial-cache - keyed on $cachedcontextid
|
||||
static $cachedcontextid;
|
||||
static $conceptlist;
|
||||
|
||||
static $jsinitialised; // To control unique js init
|
||||
static $nothingtodo; // To avoid processing if no glossaries / concepts are found
|
||||
|
||||
// Try to get current course
|
||||
@ -185,16 +196,6 @@ class filter_glossary extends moodle_text_filter {
|
||||
}
|
||||
|
||||
$conceptlist = filter_remove_duplicates($conceptlist);
|
||||
|
||||
if (empty($jsinitialised)) {
|
||||
// Add a JavaScript event to open popup's here. This only ever need to be
|
||||
// added once!
|
||||
$PAGE->requires->yui_module(
|
||||
'moodle-filter_glossary-autolinker',
|
||||
'M.filter_glossary.init_filter_autolinking',
|
||||
array(array('courseid' => $courseid)));
|
||||
$jsinitialised = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($GLOSSARY_EXCLUDECONCEPTS)) {
|
||||
|
4
filter/glossary/yui/autolinker/autolinker.js
vendored
4
filter/glossary/yui/autolinker/autolinker.js
vendored
@ -5,7 +5,6 @@ YUI.add('moodle-filter_glossary-autolinker', function(Y) {
|
||||
POPUPNAME = 'name',
|
||||
POPUPOPTIONS = 'options',
|
||||
TITLE = 'title',
|
||||
COURSEID = 'courseid',
|
||||
WIDTH = 'width',
|
||||
HEIGHT = 'height',
|
||||
MENUBAR = 'menubar',
|
||||
@ -122,8 +121,7 @@ YUI.add('moodle-filter_glossary-autolinker', function(Y) {
|
||||
status : {value : true},
|
||||
directories : {value : false},
|
||||
fullscreen : {value : false},
|
||||
dependent : {value : true},
|
||||
courseid : {value : 1}
|
||||
dependent : {value : true}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
This file describes API changes in core filter API and plugins,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 2.3 ===
|
||||
|
||||
* new setup() method added to moodle_text_filter, invoked before
|
||||
filtering happens, used to add all the requirements to the page
|
||||
(js, css...) and/or other init tasks. See filter/glossary for
|
||||
an example using the API (and MDL-32279 for its justification).
|
||||
|
||||
=== 2.2 ===
|
||||
|
||||
* legacy filters and legacy locations have been deprecated, so any
|
||||
|
@ -222,6 +222,29 @@ class filter_manager {
|
||||
}
|
||||
return implode('-', $hashes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup page with filters requirements and other prepare stuff.
|
||||
*
|
||||
* This method is used by {@see format_text()} and {@see format_string()}
|
||||
* in order to allow filters to setup any page requirement (js, css...)
|
||||
* or perform any action needed to get them prepared before filtering itself
|
||||
* happens by calling to each every active setup() method.
|
||||
*
|
||||
* Note it's executed for each piece of text filtered, so filter implementations
|
||||
* are responsible of controlling the cardinality of the executions that may
|
||||
* be different depending of the stuff to prepare.
|
||||
*
|
||||
* @param moodle_page $page the page we are going to add requirements to.
|
||||
* @param context $context the context which contents are going to be filtered.
|
||||
* @since 2.3
|
||||
*/
|
||||
public function setup_page_for_filters($page, $context) {
|
||||
$filters = $this->get_text_filters($context);
|
||||
foreach ($filters as $filter) {
|
||||
$filter->setup($page, $context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,6 +380,24 @@ abstract class moodle_text_filter {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup page with filter requirements and other prepare stuff.
|
||||
*
|
||||
* Override this method if the filter needs to setup page
|
||||
* requirements or needs other stuff to be executed.
|
||||
*
|
||||
* Note this method is invoked from {@see setup_page_for_filters()}
|
||||
* for each piece of text being filtered, so it is responsible
|
||||
* for controlling its own execution cardinality.
|
||||
*
|
||||
* @param moodle_page $page the page we are going to add requirements to.
|
||||
* @param context $context the context which contents are going to be filtered.
|
||||
* @since 2.3
|
||||
*/
|
||||
public function setup($page, $context) {
|
||||
// Override me, if needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function to actually implement the filtering.
|
||||
*
|
||||
|
@ -1090,6 +1090,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_
|
||||
|
||||
if ($options['filter']) {
|
||||
$filtermanager = filter_manager::instance();
|
||||
$filtermanager->setup_page_for_filters($PAGE, $context); // Setup global stuff filters may have.
|
||||
} else {
|
||||
$filtermanager = new null_filter_manager();
|
||||
}
|
||||
@ -1302,6 +1303,7 @@ function format_string($string, $striplinks = true, $options = NULL) {
|
||||
|
||||
if (!empty($CFG->filterall)) {
|
||||
$string = filter_manager::instance()->filter_string($string, $options['context']);
|
||||
$filtermanager->setup_page_for_filters($PAGE, $options['context']); // Setup global stuff filters may have.
|
||||
}
|
||||
|
||||
// If the site requires it, strip ALL tags from this string
|
||||
|
Loading…
x
Reference in New Issue
Block a user