Filters fit between the raw text in a node and the HTML output. They allow you to replace text selectively. Uses include automatic conversion of emoticons into graphics and filtering HTML content from users' submissions.
If you notice some filters are causing conflicts in the output, you can rearrange them .
", array("%url" => url("admin/system/filters/order")));
case 'admin/system/filters/order':
return t("
Because of the flexible filtering system, you might encounter a situation where one filter prevents another from doing its job. For example: a word in an URL gets converted into a glossary term, before the URL can be converted in a clickable link. When this happens, you will need to rearrange the order in which filters get executed.
Filters are executed from top-to-bottom. You can use the weight column to rearrange them: heavier filters 'sink' to the bottom. Standard HTML filtering is always run first.
");
case 'filter#long-tip':
case 'filter#short-tip':
switch (variable_get("filter_html", FILTER_HTML_DONOTHING)) {
case 0:
return t("All HTML tags allowed");
break;
case 1:
if ($allowed_html = variable_get("allowed_html", " ")) {
return t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html);
} else {
return t("No HTML tags allowed");
}
break;
case 2:
return t("No HTML tags allowed");
break;
}
break;
}
}
/**
* Implementation of hook_link().
*/
function filter_link($type) {
if ($type == 'system') {
menu('admin/system/filters', t('filters'), user_access('administer site configuration') ? 'filter_admin' : MENU_DENIED, 5);
menu('admin/system/filters/order', t('ordering'), user_access('administer site configuration') ? 'filter_admin' : MENU_DENIED, 5);
menu('filter/tips', t('compose tips'), 'filter_tips_long', 0, MENU_HIDE);
}
}
function filter_admin_order() {
$edit = $_POST["edit"];
$op = $_POST["op"];
if ($op == t("Save configuration")) {
foreach ($edit as $module => $filter) {
db_query("UPDATE {filters} SET weight = %d WHERE module = '%s'", $filter["weight"], $module);
}
}
// Get list (with forced refresh)
filter_refresh();
$filters = filter_list();
$header = array(t('name'), t('weight'));
$rows = array();
// Standard HTML filters are always run first, we add a dummy row to indicate this
$rows[] = array(t("HTML filtering"), array("data" => t("locked")));
foreach ($filters as $module => $filter) {
$name = module_invoke($module, "filter", "name");
$rows[] = array($name, array("data" => form_weight(NULL, $module ."][weight", $filter["weight"])));
}
$form = theme("table", $header, $rows);
$form .= form_submit(t("Save configuration"));
$output = form($form);
return $output;
}
function filter_admin_settings() {
system_settings_save();
filter_refresh();
$form = filter_default_settings();
$form .= implode("\n", module_invoke_all("filter", "settings"));
$output = system_settings_form($form);
return $output;
}
function filter_admin() {
switch (arg(3)) {
case "order":
$output = filter_admin_order();
break;
default:
$output = filter_admin_settings();
break;
}
print theme("page", $output);
}
function filter_refresh() {
$modules = module_list();
$filters = filter_list();
// Update list in database
db_query("DELETE FROM {filters}");
foreach ($modules as $module) {
if (module_hook($module, "filter")) {
$weight = $filters[$module]["weight"];
db_query("INSERT INTO {filters} (module, weight) VALUES ('%s', %d)", $module, $weight);
}
}
filter_list(1);
}
function filter_list($force = 0) {
static $filters;
if (!is_array($filters) || $force) {
$filters = array();
$result = db_query("SELECT * FROM {filters} ORDER BY weight ASC");
while ($filter = db_fetch_array($result)) {
// Fail-safe in case a module was deleted/changed without disabling it
if (module_hook($filter["module"], "filter")) {
$filters[$filter["module"]] = $filter;
}
}
}
return $filters;
}
function check_output($text) {
if (isset($text)) {
// Filter content on output:
$filters = filter_list();
// Give filters the chance to escape HTML-like data such as code or formulas
// (from this point on, the input can be treated as HTML)
if (variable_get("filter_html", FILTER_HTML_DONOTHING) != FILTER_HTML_ESCAPE) {
foreach ($filters as $module => $filter) {
$text = module_invoke($module, "filter", "prepare", $text);
}
}
// HTML handling is done before all regular filtering activities
$text = filter_default($text);
// Regular filtering
foreach ($filters as $module => $filter) {
$text = module_invoke($module, "filter", "process", $text);
}
/*
** If only inline elements are used and no block level elements, we
** replace all newlines with HTML line breaks.
*/
if (strip_tags($text, '