}
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);
+ }
+ }
}
/**
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.
*
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();
}
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