This makes filters more plugginable, becuase with this lang file name, get_string will look for the filter name in filter/myfilter/lang/en_utf8/filter_myfilter.php.
To do this, there is a new function filter_get_name in filterlib that contains the logic.
Also, a new function filter_get_all_installed to replace the logic for getting all filters that was duplicated in three places.
filter_get_name no longer does such a nice fall-back if the name is missing, to encourage people to supply the right string. The fallback now looks like '[[filtername]] (filter/tidy)'.
} else {
$activefilters = explode(',', $CFG->textfilters);
}
- $filterlocations = array('mod','filter');
- foreach ($filterlocations as $filterlocation) {
- $filters = get_list_of_plugins($filterlocation);
-
- $filterbyname = array();
-
- foreach ($filters as $filter) {
- $strfiltername = get_string('filtername', $filter);
- // Deal with filters which are lacking the language string
- if ($strfiltername == '[[filtername]]') {
- $textlib = textlib_get_instance();
- $strfiltername = $textlib->strtotitle($filter);
- }
- $filterbyname[$strfiltername] = "$filterlocation/$filter";
- }
- ksort($filterbyname);
-
- foreach ($filterbyname as $strfiltername=>$filterfull) {
- if (file_exists("$CFG->dirroot/$filterfull/filtersettings.php")) {
- $settings = new admin_settingpage('filtersetting'.str_replace('/', '', $filterfull), $strfiltername, 'moodle/site:config', !in_array($filterfull, $activefilters));
- if ($ADMIN->fulltree) {
- include("$CFG->dirroot/$filterfull/filtersettings.php");
- }
- $ADMIN->add('filtersettings', $settings);
+ $filternames = filter_get_all_installed();
+ foreach ($filternames as $filterpath => $strfiltername) {
+ if (file_exists("$CFG->dirroot/$filterpath/filtersettings.php")) {
+ $settings = new admin_settingpage('filtersetting'.str_replace('/', '', $filterpath),
+ $strfiltername, 'moodle/site:config', !in_array($filterpath, $activefilters));
+ if ($ADMIN->fulltree) {
+ include("$CFG->dirroot/$filterpath/filtersettings.php");
}
+ $ADMIN->add('filtersettings', $settings);
}
}
- $catname =get_string('portfolios', 'portfolio');
+ $catname = get_string('portfolios', 'portfolio');
$manage = get_string('manageportfolios', 'portfolio');
$url = "$CFG->wwwroot/$CFG->admin/portfolio.php";
--- /dev/null
+<?php // $Id$
+// Language string for filter/myfilter.
+
+$string['filtername'] = 'HTML tidy';
return true;
}
+ $filternames = filter_get_all_installed();
$textlib = textlib_get_instance();
- $filterlocations = array('mod','filter');
- foreach ($filterlocations as $filterlocation) {
- $plugins = get_list_of_plugins($filterlocation);
- foreach ($plugins as $plugin) {
- if (strpos($plugin, $query) !== false) {
- return true;
- }
- $name = get_string('filtername', $plugin);
- if (strpos($textlib->strtolower($name), $query) !== false) {
- return true;
- }
+ foreach ($filternames as $path => $strfiltername) {
+ if (strpos($textlib->strtolower($strfiltername), $query) !== false) {
+ return true;
+ }
+ list($type, $filter) = explode('/', $path);
+ if (strpos($filter, $query) !== false) {
+ return true;
}
}
return false;
// get a list of possible filters (and translate name if possible)
// note filters can be in the dedicated filters area OR in their
// associated modules
- $installedfilters = array();
+ $installedfilters = filter_get_all_installed();
$filtersettings_new = array();
- $filterlocations = array('mod','filter');
- foreach ($filterlocations as $filterlocation) {
- $plugins = get_list_of_plugins($filterlocation);
- foreach ($plugins as $plugin) {
- $pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
- $settingspath_new = "$CFG->dirroot/$filterlocation/$plugin/filtersettings.php";
- if (is_readable($pluginpath)) {
- $name = trim(get_string("filtername", $plugin));
- if (empty($name) or ($name == '[[filtername]]')) {
- $textlib = textlib_get_instance();
- $name = $textlib->strtotitle($plugin);
- }
- $installedfilters["$filterlocation/$plugin"] = $name;
- if (is_readable($settingspath_new)) {
- $filtersettings_new[] = "$filterlocation/$plugin";
- }
- }
+ foreach ($installedfilters as $path => $strfiltername) {
+ $settingspath_new = $CFG->dirroot . '/' . $path . '/filtersettings.php';
+ if (is_readable($settingspath_new)) {
+ $filtersettings_new[] = $path;
}
}
}
}
- // construct the display array with installed filters
- // at the top in the right order
+ // Get the list of all filters, and pull the active filters
+ // to the top.
$displayfilters = array();
foreach ($activefilters as $activefilter) {
$name = $installedfilters[$activefilter];
/// Define one exclusive separator that we'll use in the temp saved tags
/// keys. It must be something rare enough to avoid having matches with
/// filterobjects. MDL-18165
-define ('EXCL_SEPARATOR', '-%-');
+define('EXCL_SEPARATOR', '-%-');
/**
* This is just a little object to define a phrase and some instructions
}
}
+/**
+ * Look up the name of this filter in the most appropriate location.
+ * If $filterlocation = 'mod' then does get_string('filtername', $filter);
+ * else if $filterlocation = 'filter' then does get_string('filtername', 'filter_' . $filter);
+ * with a fallback to get_string('filtername', $filter) for backwards compatibility.
+ * These are the only two options supported at the moment.
+ * @param string $filterlocation 'filter' or 'mod'.
+ * @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) {
+ case 'filter':
+ $strfiltername = get_string('filtername', 'filter_' . $filter);
+ if (substr($strfiltername, 0, 2) != '[[') {
+ // found a valid string.
+ return $strfiltername;
+ }
+ // Fall through to try the legacy location.
+
+ case 'mod':
+ $strfiltername = get_string('filtername', $filter);
+ if (substr($strfiltername, 0, 2) == '[[') {
+ $strfiltername .= ' (' . $filterlocation . '/' . $filter . ')';
+ }
+ return $strfiltername;
+
+ default:
+ throw new coding_exception('Unknown filter location ' . $filterlocation);
+ }
+}
+
+/**
+ * Get the names of all the filters installed in this Moodle.
+ * @return array path => filter name from the appropriate lang file. e.g.
+ * array('mod/glossary' => 'Glossary Auto-linking', 'filter/tex' => 'TeX Notation');
+ * sorted in alphabetical order of name.
+ */
+function filter_get_all_installed() {
+ global $CFG;
+ $filternames = array();
+ $filterlocations = array('mod', 'filter');
+ foreach ($filterlocations as $filterlocation) {
+ $filters = get_list_of_plugins($filterlocation);
+ foreach ($filters as $filter) {
+ $path = $filterlocation . '/' . $filter;
+ if (is_readable($CFG->dirroot . '/' . $path . '/filter.php')) {
+ $strfiltername = filter_get_name($filterlocation, $filter);
+ $filternames[$path] = $strfiltername;
+ }
+ }
+ }
+ asort($filternames, SORT_LOCALE_STRING);
+ return $filternames;
+}
+
/**
* Process phrases intelligently found within a HTML text (such as adding links)
*
* param ignoretagsopen an array of opening tags that we should ignore while filtering
* param ignoretagsclose an array of corresponding closing tags
**/
-function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsclose=NULL) {
+function filter_phrases($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsclose=NULL) {
global $CFG;
return $text;
-
}
-
-
function filter_remove_duplicates($linkarray) {
$concepts = array(); // keep a record of concepts as we cycle through
}
break;
case 'filter':
- $plugin_name = trim(get_string('filtername', $plugin));
- if (empty($plugin_name) or ($plugin_name == '[[filtername]]')) {
- $textlib = textlib_get_instance();
- $plugin_name = $textlib->strtotitle($plugin);
- }
+ $plugin_name = filter_get_name('filter', $plugin);
break;
default:
$plugin_name = $plugin;