Commit 79a9a4f3 authored by Dries's avatar Dries

- Patch #582378 by sun, David_Rothstein: fixes for the filter system and additional tests.

parent ba790924
......@@ -393,7 +393,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
// parse errors.
if (isset($format)) {
$filters = filter_list_format($format);
if (isset($filters['php_code']) && strpos($text, '<?') !== FALSE) {
if (isset($filters['php_code']) && $filters['php_code']->status && strpos($text, '<?') !== FALSE) {
return $text;
}
}
......
......@@ -135,7 +135,7 @@ function filter_admin_format_form($form, &$form_state, $format) {
}
// Table with filters
$filter_info = filter_get_filters();
$filters = filter_list_format($format->format, TRUE);
$filters = filter_list_format($format->format);
$form['filters'] = array('#type' => 'fieldset',
'#title' => t('Filters'),
......@@ -260,12 +260,12 @@ function filter_admin_configure($form, &$form_state, $format) {
$form['#format'] = $format;
foreach ($filters as $name => $filter) {
if (isset($filter_info[$name]['settings callback']) && function_exists($filter_info[$name]['settings callback'])) {
if ($filter->status && isset($filter_info[$name]['settings callback']) && function_exists($filter_info[$name]['settings callback'])) {
// Pass along stored filter settings and default settings, but also the
// format object and all filters to allow for complex implementations.
$defaults = (isset($filter_info[$name]['default settings']) ? $filter_info[$name]['default settings'] : array());
$settings_form = $filter_info[$name]['settings callback']($form, $form_state, $filters[$name], $defaults, $format, $filters);
if (isset($settings_form) && is_array($settings_form)) {
if (!empty($settings_form)) {
$form['settings'][$name] = array(
'#type' => 'fieldset',
'#title' => check_plain($filter->title),
......@@ -330,9 +330,11 @@ function filter_admin_order($form, &$form_state, $format = NULL) {
$form['weights'] = array('#tree' => TRUE);
foreach ($filters as $id => $filter) {
if ($filter->status) {
$form['names'][$id] = array('#markup' => $filter->title);
$form['weights'][$id] = array('#type' => 'weight', '#default_value' => $filter->weight);
}
}
$form['format'] = array('#type' => 'hidden', '#value' => $format->format);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
......
......@@ -92,12 +92,12 @@
*
* @code
* function mymodule_filter_settings($form, &$form_state, $filter, $defaults) {
* $form['mymodule_url_length'] = array(
* $settings['mymodule_url_length'] = array(
* '#type' => 'textfield',
* '#title' => t('Maximum link text length'),
* '#default_value' => isset($filter->settings['mymodule_url_length']) ? $filter->settings['mymodule_url_length'] : $defaults['mymodule_url_length'],
* );
* return $form;
* return $settings;
* }
* @endcode
*
......
......@@ -191,9 +191,8 @@ function filter_format_save(&$format) {
$return = drupal_write_record('filter_format', $format, 'format');
}
// Get the filters currently active in the format, to add new filters
// to the bottom.
$current = filter_list_format($format->format, TRUE);
// Get the current filters in the format, to add new filters to the bottom.
$current = filter_list_format($format->format);
$filter_info = filter_get_filters();
if (!isset($format->filters)) {
$format->filters = array();
......@@ -506,11 +505,17 @@ function filter_format_allowcache($format_id) {
/**
* Retrieve a list of filters for a given text format.
*
* Note that this function returns all associated filters regardless of whether
* they are enabled or disabled. All functions working with the filter
* information outside of filter administration should test for $filter->status
* before performing actions with the filter.
*
* @param $format_id
* The format ID.
* The format ID to retrieve filters for.
*
* @return
* An array of filter objects assosiated to the given format.
* An array of filter objects associated to the given text format, keyed by
* filter name.
*/
function filter_list_format($format_id) {
$filters = &drupal_static(__FUNCTION__, array());
......@@ -730,7 +735,7 @@ function _filter_tips($format_id, $long = FALSE) {
$filters = filter_list_format($format->format);
$tips[$format->name] = array();
foreach ($filters as $name => $filter) {
if (isset($filter_info[$name]['tips callback']) && function_exists($filter_info[$name]['tips callback'])) {
if ($filter->status && isset($filter_info[$name]['tips callback']) && function_exists($filter_info[$name]['tips callback'])) {
$tip = $filter_info[$name]['tips callback']($filter, $format, $long);
$tips[$format->name][$name] = array('tip' => $tip, 'id' => $name);
}
......@@ -866,7 +871,7 @@ function filter_filter_info() {
* Settings callback for the HTML filter.
*/
function _filter_html_settings($form, &$form_state, $filter, $defaults) {
$form['allowed_html'] = array(
$settings['allowed_html'] = array(
'#type' => 'textfield',
'#title' => t('Allowed HTML tags'),
'#default_value' => isset($filter->settings['allowed_html']) ? $filter->settings['allowed_html'] : $defaults['allowed_html'],
......@@ -874,19 +879,19 @@ function _filter_html_settings($form, &$form_state, $filter, $defaults) {
'#maxlength' => 1024,
'#description' => t('Specify a list of tags which should not be stripped. (Note that JavaScript event attributes are always stripped.)'),
);
$form['filter_html_help'] = array(
$settings['filter_html_help'] = array(
'#type' => 'checkbox',
'#title' => t('Display HTML help'),
'#default_value' => isset($filter->settings['filter_html_help']) ? $filter->settings['filter_html_help'] : $defaults['filter_html_help'],
'#description' => t('If enabled, Drupal will display some basic HTML help in the long filter tips.'),
);
$form['filter_html_nofollow'] = array(
$settings['filter_html_nofollow'] = array(
'#type' => 'checkbox',
'#title' => t('Spam link deterrent'),
'#default_value' => isset($filter->settings['filter_html_nofollow']) ? $filter->settings['filter_html_nofollow'] : $defaults['filter_html_nofollow'],
'#description' => t('If enabled, Drupal will add rel="nofollow" to all links, as a measure to reduce the effectiveness of spam links. Note: this will also prevent valid links from being followed by search engines, therefore it is likely most effective when enabled for anonymous users.'),
);
return $form;
return $settings;
}
/**
......@@ -1012,14 +1017,14 @@ function _filter_html_tips($filter, $format, $long = FALSE) {
* Settings callback for URL filter.
*/
function _filter_url_settings($form, &$form_state, $filter, $defaults) {
$form['filter_url_length'] = array(
$settings['filter_url_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum link text length'),
'#default_value' => isset($filter->settings['filter_url_length']) ? $filter->settings['filter_url_length'] : $defaults['filter_url_length'],
'#maxlength' => 4,
'#description' => t('URLs longer than this number of characters will be truncated to prevent long strings that break formatting. The link itself will be retained; just the text portion of the link will be truncated.'),
);
return $form;
return $settings;
}
/**
......
......@@ -111,7 +111,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
$this->assertTrue(empty($format_filters), t('Database contains values for all filters in the saved format.'));
// Verify filter_list_format().
$filters = filter_list_format($format->format, TRUE);
$filters = filter_list_format($format->format);
$format_filters = $format->filters;
foreach ($filters as $name => $filter) {
$t_args = array('%format' => $format->name, '%filter' => $name);
......@@ -204,6 +204,22 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->assertTrue(filter_access(filter_format_load($full), $this->admin_user), t('Admin user may use Full HTML.'));
$this->assertFalse(filter_access(filter_format_load($full), $this->web_user), t('Web user may not use Full HTML.'));
// Verify that disabled filters are not displayed.
$edit = array();
$edit['filters[filter_url][status]'] = FALSE;
$this->drupalPost('admin/config/content/formats/' . $filtered, $edit, t('Save configuration'));
$this->drupalGet('admin/config/content/formats/' . $filtered . '/configure');
$this->assertNoText(t('Convert URLs into links'), t('Disabled URL filter cannot be configured.'));
$this->drupalGet('admin/config/content/formats/' . $filtered . '/order');
$this->assertNoText(t('Convert URLs into links'), t('Disabled URL filter cannot be re-ordered.'));
$edit = array();
$edit['filters[filter_url][status]'] = 1;
$this->drupalPost('admin/config/content/formats/' . $filtered, $edit, t('Save configuration'));
$this->drupalGet('admin/config/content/formats/' . $filtered . '/configure');
$this->assertText(t('Convert URLs into links'), t('Enabled URL filter can be configured.'));
$this->drupalGet('admin/config/content/formats/' . $filtered . '/order');
$this->assertText(t('Convert URLs into links'), t('Enabled URL filter can be re-ordered.'));
// Add an additional tag.
$edit = array();
$edit['settings[filter_html][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>';
......@@ -243,7 +259,6 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$format = $this->getFormat($edit['name']);
$this->assertNotNull($format, t('Format found in database.'));
if ($format !== NULL) {
$this->assertFieldByName('roles[2]', '', t('Role found.'));
$this->assertFieldByName('filters[' . $second_filter . '][status]', '', t('Line break filter found.'));
$this->assertFieldByName('filters[' . $first_filter . '][status]', '', t('Url filter found.'));
......@@ -251,7 +266,6 @@ class FilterAdminTestCase extends DrupalWebTestCase {
// Delete new filter.
$this->drupalPost('admin/config/content/formats/' . $format->format . '/delete', array(), t('Delete'));
$this->assertRaw(t('Deleted text format %format.', array('%format' => $edit['name'])), t('Format successfully deleted.'));
}
// Allow authenticated users on full HTML.
$format = filter_format_load($full);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment