Skip to content
Snippets Groups Projects
Commit 741a2e93 authored by Angie Byron's avatar Angie Byron
Browse files

#401956 by chx and Damien Tournoud: Add an optional filter to turn...

#401956 by chx and Damien Tournoud: Add an optional filter to turn [internal:node/123] into a link to an internal Drupal page.
parent 3b305095
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,8 @@ Drupal 7.0, xxxx-xx-xx (development version)
* Highlight duplicate URL aliases.
* Renamed "input formats" to "text formats".
* Added configurable ability for users to cancel their own accounts.
* Added optional filter that can use [internal:node/123] to link to internal
pages.
- Performance:
* Improved performance on uncached page views by loading multiple core
objects in a single database query.
......
......@@ -281,7 +281,8 @@ function filter_filter_tips($delta, $format, $long = FALSE) {
case 4:
return t('No HTML tags allowed');
break;
case 5:
return t('Use [internal:foo/bar] to get a link to the internal page <em>foo/bar</em>.');
}
}
......@@ -605,7 +606,14 @@ function theme_filter_guidelines($format) {
function filter_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('Limit allowed HTML tags'), 1 => t('Convert line breaks'), 2 => t('Convert URLs into links'), 3 => t('Correct broken HTML'), 4 => t('Escape all HTML'));
return array(
0 => t('Limit allowed HTML tags'),
1 => t('Convert line breaks'),
2 => t('Convert URLs into links'),
3 => t('Correct broken HTML'),
4 => t('Escape all HTML'),
5 => t('Create internal URLs'),
);
case 'description':
switch ($delta) {
......@@ -619,6 +627,8 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
return t('Corrects faulty and chopped off HTML in postings.');
case 4:
return t('Escapes all HTML tags, so they will be visible instead of being effective.');
case 5:
return t('Formats [internal:node/1234] as a URL.');
default:
return;
}
......@@ -635,6 +645,8 @@ function filter_filter($op, $delta = 0, $format = -1, $text = '') {
return _filter_htmlcorrector($text);
case 4:
return trim(check_plain($text));
case 5:
return _filter_internal($text);
default:
return $text;
}
......@@ -853,6 +865,18 @@ function _filter_url_trim($text, $length = NULL) {
return $text;
}
/**
* Turn [internal:foo] into url(foo).
*
* @param $text
* The text to apply the filter on.
* @return
* The filtered text.
*/
function _filter_internal($text) {
return preg_replace('/\[internal:([^\]]+)\]/e', "url('\\1')", $text);
}
/**
* Convert line breaks into <p> and <br> in an intelligent fashion.
* Based on: http://photomatt.net/scripts/autop
......
......@@ -184,7 +184,7 @@ class FilterTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Core filters'),
'description' => t('Filter each filter individually: Convert URLs into links, Convert line breaks, Correct broken HTML, Escape all HTML, Limit allowed HTML tags.'),
'description' => t('Filter each filter individually: Convert URLs into links, Convert line breaks, Correct broken HTML, Escape all HTML, Limit allowed HTML tags, check the internal filter.'),
'group' => t('Filter'),
);
}
......@@ -233,4 +233,11 @@ class FilterTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/settings/filter/delete/' . $format->format, array(), t('Delete'));
}
}
/**
* Unit test for the internal link filter.
*/
function testInternalFilter() {
$this->assertEqual(_filter_internal('[internal:foo/bar] [internal:foo2/bar2]'), url('foo/bar') . ' ' . url('foo2/bar2'), t('The internal filter works'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment