summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-02-06 19:07:56 +0000
committerDries Buytaert <dries@buytaert.net>2004-02-06 19:07:56 +0000
commitbfba335376c8a15c74ec0e8ec71541193b458073 (patch)
treeea62f98f1dd0f5a2329ec96af6f456db8fb019ac /modules
parent0db96f196a89956e60ad38aaf8fac1dcbdf0fa4c (diff)
downloadbrdo-bfba335376c8a15c74ec0e8ec71541193b458073.tar.gz
brdo-bfba335376c8a15c74ec0e8ec71541193b458073.tar.bz2
- Added the possibility to reorder filters. Patch by UnConeD.
Diffstat (limited to 'modules')
-rw-r--r--modules/filter.module151
-rw-r--r--modules/filter/filter.module151
-rw-r--r--modules/title.module17
3 files changed, 269 insertions, 50 deletions
diff --git a/modules/filter.module b/modules/filter.module
index e41f6d2a4..ca7431882 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -6,7 +6,13 @@ function filter_help($section = "admin/help#filter") {
case 'admin/system/modules#description':
return t("Framework for handling filtering of content.");
case 'admin/system/filters':
- return t("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.");
+ return t("
+<p>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.</p>
+<p>If you notice some filters are causing conflicts in the output, you can <a href=\"%url\">rearrange them</a>.</p>", array("%url" => url("admin/system/filters/order")));
+ case 'admin/system/filters/order':
+ return t("
+<p>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.</p>
+<p>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.</p>");
case 'filter#long-tip':
case 'filter#short-tip':
switch (variable_get("filter_html", 1)) {
@@ -32,17 +38,65 @@ function filter_link($type) {
if ($type == "system") {
if (user_access("administer site configuration")) {
menu("admin/system/filters", t("filters"), "filter_admin", 5);
+ menu("admin/system/filters/order", t("ordering"), "filter_admin", 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("name", "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() {
if (user_access("administer site configuration")) {
- system_settings_save();
-
- $form = implode("\n", module_invoke_all("conf_filters"));
- $output = system_settings_form($form);
+ switch (arg(3)) {
+ case "order":
+ $output = filter_admin_order();
+ break;
+ default:
+ $output = filter_admin_settings();
+ break;
+ }
print theme("page", $output);
}
else {
@@ -50,30 +104,56 @@ function filter_admin() {
}
}
-function filter_conf_filters() {
- $group1 .= form_radios(t("Filter HTML tags"), "filter_html", variable_get("filter_html", 0), array(0 => t("Do not filter"), 1 => t("Strip tags"), 2 => t("Escape tags")), t("How to deal with HTML and PHP tags in user-contributed content. If set to \"Strip tags\", dangerous tags are removed (see below). If set to \"Escape tags\", all HTML is escaped and presented as it was typed."));
- $group1 .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>"), 64, 255, t("If \"Strip tags\" is selected, optionally specify tags which should not be stripped. 'ON*' attributes and unclosed tags are always stripped."));
- $group1 .= form_radios(t("HTML style attributes"), "filter_style", variable_get("filter_style", 1), array(t("Allowed"), t("Removed")), t("If \"Strip tags\" is selected, you can choose whether 'STYLE' attributes are allowed or removed from input."));
- $output .= form_group(t("HTML filtering"), $group1);
+function filter_refresh() {
+ $modules = module_list();
+ $filters = filter_list();
- $group2 .= form_radios(t("Rewrite old URLs"), "rewrite_old_urls", variable_get("rewrite_old_urls", 0), array(t("Disabled"), t("Enabled")), t("The introduction of 'clean URLs' in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal's <code>.htaccess</code> file instead as these will also correct external referrers."));
- $output .= form_group(t("Legacy filtering"), $group2);
+ // Update list in database
+ db_query("DELETE FROM {filters}");
+ foreach ($modules as $module) {
+ if (module_hook($module, "filter")) {
+ $weight = $filters[$module]["weight"];
- return $output;
+ 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:
- $modules = module_list();
+ // Filter content on output:
+ $filters = filter_list();
+
+ // Give filters the chance to escape HTML-like data before being passed to the HTML stripper
+ foreach ($filters as $module => $filter) {
+ $text = module_invoke($module, "filter", "prepare", $text);
+ }
- // Default filters are run first: they determine how to handle HTML
+ // HTML handling is done before all regular filtering activities
$text = filter_default($text);
- foreach ($modules as $name) {
- if (module_hook($name, "filter")) {
- $text = module_invoke($name, "filter", $text);
- }
+ // Regular filtering
+ foreach ($filters as $module => $filter) {
+ $text = module_invoke($module, "filter", "process", $text);
}
/*
@@ -101,10 +181,6 @@ function filter_default($text) {
$text = preg_replace("/\Won[a-z]+\s*=[^>]+?>/i", ">", $text);
}
- if (variable_get("rewrite_old_urls", 0)) {
- $text = filter_old_urls($text);
- }
-
if (variable_get("filter_html", 0) == 2) {
// Escape HTML
$text = htmlspecialchars($text);
@@ -113,6 +189,33 @@ function filter_default($text) {
return trim($text);
}
+function filter_default_settings() {
+ $group = form_radios(t("Filter HTML tags"), "filter_html", variable_get("filter_html", 0), array(0 => t("Do not filter"), 1 => t("Strip tags"), 2 => t("Escape tags")), t("How to deal with HTML and PHP tags in user-contributed content. If set to \"Strip tags\", dangerous tags are removed (see below). If set to \"Escape tags\", all HTML is escaped and presented as it was typed."));
+ $group .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>"), 64, 255, t("If \"Strip tags\" is selected, optionally specify tags which should not be stripped. 'ON*' attributes and unclosed tags are always stripped."));
+ $group .= form_radios(t("HTML style attributes"), "filter_style", variable_get("filter_style", 1), array(t("Allowed"), t("Removed")), t("If \"Strip tags\" is selected, you can choose whether 'STYLE' attributes are allowed or removed from input."));
+ $output .= form_group(t("HTML filtering"), $group);
+
+ return $output;
+}
+
+function filter_filter($op, $text = "") {
+ switch ($op) {
+ case "name":
+ return t("Legacy filtering");
+ case "process":
+ if (variable_get("rewrite_old_urls", 0)) {
+ $text = filter_old_urls($text);
+ }
+ return $text;
+ case "settings":
+ $group = form_radios(t("Rewrite old URLs"), "rewrite_old_urls", variable_get("rewrite_old_urls", 0), array(t("Disabled"), t("Enabled")), t("The introduction of 'clean URLs' in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal's <code>.htaccess</code> file instead as these will also correct external referrers."));
+ $output .= form_group(t("Legacy filtering"), $group);
+ return $output;
+ default:
+ return $text;
+ }
+}
+
function filter_old_urls($text) {
global $base_url;
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index e41f6d2a4..ca7431882 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -6,7 +6,13 @@ function filter_help($section = "admin/help#filter") {
case 'admin/system/modules#description':
return t("Framework for handling filtering of content.");
case 'admin/system/filters':
- return t("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.");
+ return t("
+<p>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.</p>
+<p>If you notice some filters are causing conflicts in the output, you can <a href=\"%url\">rearrange them</a>.</p>", array("%url" => url("admin/system/filters/order")));
+ case 'admin/system/filters/order':
+ return t("
+<p>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.</p>
+<p>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.</p>");
case 'filter#long-tip':
case 'filter#short-tip':
switch (variable_get("filter_html", 1)) {
@@ -32,17 +38,65 @@ function filter_link($type) {
if ($type == "system") {
if (user_access("administer site configuration")) {
menu("admin/system/filters", t("filters"), "filter_admin", 5);
+ menu("admin/system/filters/order", t("ordering"), "filter_admin", 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("name", "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() {
if (user_access("administer site configuration")) {
- system_settings_save();
-
- $form = implode("\n", module_invoke_all("conf_filters"));
- $output = system_settings_form($form);
+ switch (arg(3)) {
+ case "order":
+ $output = filter_admin_order();
+ break;
+ default:
+ $output = filter_admin_settings();
+ break;
+ }
print theme("page", $output);
}
else {
@@ -50,30 +104,56 @@ function filter_admin() {
}
}
-function filter_conf_filters() {
- $group1 .= form_radios(t("Filter HTML tags"), "filter_html", variable_get("filter_html", 0), array(0 => t("Do not filter"), 1 => t("Strip tags"), 2 => t("Escape tags")), t("How to deal with HTML and PHP tags in user-contributed content. If set to \"Strip tags\", dangerous tags are removed (see below). If set to \"Escape tags\", all HTML is escaped and presented as it was typed."));
- $group1 .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>"), 64, 255, t("If \"Strip tags\" is selected, optionally specify tags which should not be stripped. 'ON*' attributes and unclosed tags are always stripped."));
- $group1 .= form_radios(t("HTML style attributes"), "filter_style", variable_get("filter_style", 1), array(t("Allowed"), t("Removed")), t("If \"Strip tags\" is selected, you can choose whether 'STYLE' attributes are allowed or removed from input."));
- $output .= form_group(t("HTML filtering"), $group1);
+function filter_refresh() {
+ $modules = module_list();
+ $filters = filter_list();
- $group2 .= form_radios(t("Rewrite old URLs"), "rewrite_old_urls", variable_get("rewrite_old_urls", 0), array(t("Disabled"), t("Enabled")), t("The introduction of 'clean URLs' in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal's <code>.htaccess</code> file instead as these will also correct external referrers."));
- $output .= form_group(t("Legacy filtering"), $group2);
+ // Update list in database
+ db_query("DELETE FROM {filters}");
+ foreach ($modules as $module) {
+ if (module_hook($module, "filter")) {
+ $weight = $filters[$module]["weight"];
- return $output;
+ 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:
- $modules = module_list();
+ // Filter content on output:
+ $filters = filter_list();
+
+ // Give filters the chance to escape HTML-like data before being passed to the HTML stripper
+ foreach ($filters as $module => $filter) {
+ $text = module_invoke($module, "filter", "prepare", $text);
+ }
- // Default filters are run first: they determine how to handle HTML
+ // HTML handling is done before all regular filtering activities
$text = filter_default($text);
- foreach ($modules as $name) {
- if (module_hook($name, "filter")) {
- $text = module_invoke($name, "filter", $text);
- }
+ // Regular filtering
+ foreach ($filters as $module => $filter) {
+ $text = module_invoke($module, "filter", "process", $text);
}
/*
@@ -101,10 +181,6 @@ function filter_default($text) {
$text = preg_replace("/\Won[a-z]+\s*=[^>]+?>/i", ">", $text);
}
- if (variable_get("rewrite_old_urls", 0)) {
- $text = filter_old_urls($text);
- }
-
if (variable_get("filter_html", 0) == 2) {
// Escape HTML
$text = htmlspecialchars($text);
@@ -113,6 +189,33 @@ function filter_default($text) {
return trim($text);
}
+function filter_default_settings() {
+ $group = form_radios(t("Filter HTML tags"), "filter_html", variable_get("filter_html", 0), array(0 => t("Do not filter"), 1 => t("Strip tags"), 2 => t("Escape tags")), t("How to deal with HTML and PHP tags in user-contributed content. If set to \"Strip tags\", dangerous tags are removed (see below). If set to \"Escape tags\", all HTML is escaped and presented as it was typed."));
+ $group .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>"), 64, 255, t("If \"Strip tags\" is selected, optionally specify tags which should not be stripped. 'ON*' attributes and unclosed tags are always stripped."));
+ $group .= form_radios(t("HTML style attributes"), "filter_style", variable_get("filter_style", 1), array(t("Allowed"), t("Removed")), t("If \"Strip tags\" is selected, you can choose whether 'STYLE' attributes are allowed or removed from input."));
+ $output .= form_group(t("HTML filtering"), $group);
+
+ return $output;
+}
+
+function filter_filter($op, $text = "") {
+ switch ($op) {
+ case "name":
+ return t("Legacy filtering");
+ case "process":
+ if (variable_get("rewrite_old_urls", 0)) {
+ $text = filter_old_urls($text);
+ }
+ return $text;
+ case "settings":
+ $group = form_radios(t("Rewrite old URLs"), "rewrite_old_urls", variable_get("rewrite_old_urls", 0), array(t("Disabled"), t("Enabled")), t("The introduction of 'clean URLs' in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal's <code>.htaccess</code> file instead as these will also correct external referrers."));
+ $output .= form_group(t("Legacy filtering"), $group);
+ return $output;
+ default:
+ return $text;
+ }
+}
+
function filter_old_urls($text) {
global $base_url;
diff --git a/modules/title.module b/modules/title.module
index e109a1851..4fc325c64 100644
--- a/modules/title.module
+++ b/modules/title.module
@@ -64,15 +64,28 @@ function title_page() {
}
}
+function title_filter($op, $text = "") {
+ switch ($op) {
+ case "name":
+ return t("Title filter");
+ case "process":
+ return _title_filter_process($text);
+ case "settings":
+ return _title_filter_settings($text);
+ default:
+ return $text;
+ }
+}
+
// filter [node title|description] links. '|description' is optional.
-function title_filter($text) {
+function _title_filter_process($text) {
$pattern = '\[([^\|\]]+)(?>\|?)(.*?)\]'; // $1 == title: matches at least 1 char up to the first '|' or ']'
// $2 == text: matches all after a following '|' (if there is) up to the next ']'. may include '|'s.
$replacement = 'l("$2" ? "$2" : "$1", "title/". urlencode("$1"))';
return preg_replace("/$pattern/e", $replacement, $text);
}
-function title_conf_filters() {
+function _title_filter_settings() {
return form_group(t("Title filter"), t("Wiki-like [node title|text] links are enabled. These shortcuts generate a link labeled 'text' to the node with the title 'node title'. If you omit '|text', the label becomes 'node title'. You may use a substring of a node title if desired. When multiple matching titles are found, a list of matching nodes will be displayed. If no matching titles are found, a full-text search is returned."));
}