Commit 6764b73f authored by Dries's avatar Dries

- Patch #570930 by sun: allow to retrieve all filters (including disabled) in a text format.

parent 5e590b9e
...@@ -118,7 +118,8 @@ function filter_admin_format_form(&$form_state, $format) { ...@@ -118,7 +118,8 @@ function filter_admin_format_form(&$form_state, $format) {
$form['default_format'] = array('#type' => 'hidden', '#value' => 1); $form['default_format'] = array('#type' => 'hidden', '#value' => 1);
} }
$form['name'] = array('#type' => 'textfield', $form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'), '#title' => t('Name'),
'#default_value' => $format->name, '#default_value' => $format->name,
'#description' => t('Specify a unique name for this text format.'), '#description' => t('Specify a unique name for this text format.'),
...@@ -144,7 +145,7 @@ function filter_admin_format_form(&$form_state, $format) { ...@@ -144,7 +145,7 @@ function filter_admin_format_form(&$form_state, $format) {
} }
// Table with filters // Table with filters
$filter_info = filter_get_filters(); $filter_info = filter_get_filters();
$filters = filter_list_format($format->format); $filters = filter_list_format($format->format, TRUE);
$form['filters'] = array('#type' => 'fieldset', $form['filters'] = array('#type' => 'fieldset',
'#title' => t('Filters'), '#title' => t('Filters'),
...@@ -152,10 +153,10 @@ function filter_admin_format_form(&$form_state, $format) { ...@@ -152,10 +153,10 @@ function filter_admin_format_form(&$form_state, $format) {
'#tree' => TRUE, '#tree' => TRUE,
); );
foreach ($filter_info as $name => $filter) { foreach ($filter_info as $name => $filter) {
$form['filters'][$name] = array( $form['filters'][$name]['status'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $filter['title'], '#title' => $filter['title'],
'#default_value' => isset($filters[$name]), '#default_value' => !empty($filters[$name]->status),
'#description' => $filter['description'], '#description' => $filter['description'],
); );
} }
......
...@@ -70,6 +70,13 @@ function filter_theme() { ...@@ -70,6 +70,13 @@ function filter_theme() {
* Implement hook_menu(). * Implement hook_menu().
*/ */
function filter_menu() { function filter_menu() {
$items['filter/tips'] = array(
'title' => 'Compose tips',
'page callback' => 'filter_tips_long',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'file' => 'filter.pages.inc',
);
$items['admin/config/content/formats'] = array( $items['admin/config/content/formats'] = array(
'title' => 'Text formats', 'title' => 'Text formats',
'description' => 'Configure how content input by users is filtered, including allowed HTML tags. Also allows enabling of module-provided filters.', 'description' => 'Configure how content input by users is filtered, including allowed HTML tags. Also allows enabling of module-provided filters.',
...@@ -90,13 +97,6 @@ function filter_menu() { ...@@ -90,13 +97,6 @@ function filter_menu() {
'weight' => 1, 'weight' => 1,
'file' => 'filter.admin.inc', 'file' => 'filter.admin.inc',
); );
$items['filter/tips'] = array(
'title' => 'Compose tips',
'page callback' => 'filter_tips_long',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'file' => 'filter.pages.inc',
);
$items['admin/config/content/formats/%filter_format'] = array( $items['admin/config/content/formats/%filter_format'] = array(
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'title callback' => 'filter_admin_format_title', 'title callback' => 'filter_admin_format_title',
...@@ -185,15 +185,14 @@ function filter_format_save($format) { ...@@ -185,15 +185,14 @@ function filter_format_save($format) {
// to the bottom. // to the bottom.
$current = filter_list_format($format->format); $current = filter_list_format($format->format);
$filters = $format->filters; $filters = $format->filters;
foreach ($filters as $name => $filter) {
foreach ($filters as $name => $status) {
$fields = array(); $fields = array();
// Add new filters to the bottom. // Add new filters to the bottom.
$fields['weight'] = isset($current[$name]->weight) ? $current[$name]->weight : 10; $fields['weight'] = isset($current[$name]->weight) ? $current[$name]->weight : 10;
$fields['status'] = $status; $fields['status'] = $filter['status'];
// Only update settings if there are any. // Only update settings if there are any.
if (!empty($format->settings[$name])) { if (!empty($filter['settings'])) {
$fields['settings'] = serialize($format->settings[$name]); $fields['settings'] = serialize($filter['settings']);
} }
db_merge('filter') db_merge('filter')
->key(array( ->key(array(
...@@ -211,6 +210,8 @@ function filter_format_save($format) { ...@@ -211,6 +210,8 @@ function filter_format_save($format) {
module_invoke_all('filter_format_update', $format); module_invoke_all('filter_format_update', $format);
} }
// Clear the filter cache whenever a text format is saved.
drupal_static_reset('filter_list_format');
cache_clear_all($format->format . ':', 'cache_filter', TRUE); cache_clear_all($format->format . ':', 'cache_filter', TRUE);
return $return; return $return;
...@@ -386,6 +387,7 @@ function _filter_html_escape_tips($filter, $format, $long = FALSE) { ...@@ -386,6 +387,7 @@ function _filter_html_escape_tips($filter, $format, $long = FALSE) {
/** /**
* @} End of "Tips callback for filters". * @} End of "Tips callback for filters".
*/ */
/** /**
* Retrieve a list of text formats. * Retrieve a list of text formats.
*/ */
...@@ -472,47 +474,52 @@ function filter_format_allowcache($format) { ...@@ -472,47 +474,52 @@ function filter_format_allowcache($format) {
} }
/** /**
* Retrieve a list of filters for a certain format. * Retrieve a list of filters for a given text format.
* *
* @param $format * @param $format
* The format ID. * The format ID.
* @param $include_disabled
* (optional) Boolean whether to retrieve all filters associated with the
* given format, including those that are disabled. Defaults to FALSE.
* @return * @return
* An array of filter objects assosiated to the given format. * An array of filter objects assosiated to the given format.
*/ */
function filter_list_format($format) { function filter_list_format($format, $include_disabled = FALSE) {
static $filters = array(); $filters = &drupal_static(__FUNCTION__, array());
$filter_info = filter_get_filters(); $filter_info = filter_get_filters();
if (!isset($filters[$format])) { if (!isset($filters[$format]) || $include_disabled) {
$filters[$format] = array(); $format_filters = array();
$result = db_select('filter', 'filter') $query = db_select('filter', 'filter')
->fields('filter') ->fields('filter')
->condition('format', $format) ->condition('format', $format)
->condition('status', 1)
->orderBy('weight') ->orderBy('weight')
->orderBy('module') ->orderBy('module')
->orderBy('name') ->orderBy('name');
->execute(); if (!$include_disabled) {
foreach ($result as $filter) { $query->condition('status', 1);
if (isset($filter_info[$filter->name])) { }
$filter->title = $filter_info[$filter->name]['title']; $result = $query->execute()->fetchAllAssoc('name');
foreach ($result as $name => $filter) {
if (isset($filter_info[$name])) {
$filter->title = $filter_info[$name]['title'];
// Unpack stored filter settings. // Unpack stored filter settings.
if (isset($filter->settings)) { $filter->settings = (isset($filter->settings) ? unserialize($filter->settings) : array());
$filter->settings = unserialize($filter->settings);
}
else {
$filter->settings = array();
}
// Apply default filter settings. // Apply default filter settings.
if (isset($filter_info[$filter->name]['default settings'])) { if (isset($filter_info[$name]['default settings'])) {
$filter->settings = array_merge($filter_info[$filter->name]['default settings'], $filter->settings); $filter->settings = array_merge($filter_info[$name]['default settings'], $filter->settings);
} }
$filters[$format][$filter->name] = $filter; $format_filters[$name] = $filter;
} }
} }
// Prevent statically caching of disabled filters.
if ($include_disabled) {
return $format_filters;
}
$filters[$format] = $format_filters;
} }
return $filters[$format]; return isset($filters[$format]) ? $filters[$format] : array();
} }
/** /**
......
...@@ -65,8 +65,8 @@ class FilterAdminTestCase extends DrupalWebTestCase { ...@@ -65,8 +65,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$edit = array(); $edit = array();
$edit['name'] = $this->randomName(); $edit['name'] = $this->randomName();
$edit['roles[2]'] = 1; $edit['roles[2]'] = 1;
$edit['filters[' . $second_filter . ']'] = TRUE; $edit['filters[' . $second_filter . '][status]'] = TRUE;
$edit['filters[' . $first_filter . ']'] = TRUE; $edit['filters[' . $first_filter . '][status]'] = TRUE;
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New filter created.')); $this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New filter created.'));
...@@ -75,8 +75,8 @@ class FilterAdminTestCase extends DrupalWebTestCase { ...@@ -75,8 +75,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
if ($format !== NULL) { if ($format !== NULL) {
$this->assertFieldByName('roles[2]', '', t('Role found.')); $this->assertFieldByName('roles[2]', '', t('Role found.'));
$this->assertFieldByName('filters[' . $second_filter . ']', '', t('Line break filter found.')); $this->assertFieldByName('filters[' . $second_filter . '][status]', '', t('Line break filter found.'));
$this->assertFieldByName('filters[' . $first_filter . ']', '', t('Url filter found.')); $this->assertFieldByName('filters[' . $first_filter . '][status]', '', t('Url filter found.'));
// Delete new filter. // Delete new filter.
$this->drupalPost('admin/config/content/formats/' . $format->format . '/delete', array(), t('Delete')); $this->drupalPost('admin/config/content/formats/' . $format->format . '/delete', array(), t('Delete'));
......
...@@ -538,14 +538,13 @@ function forum_block_view($delta = '') { ...@@ -538,14 +538,13 @@ function forum_block_view($delta = '') {
break; break;
} }
$cache_keys[] = 'forum'; $cache_keys = array_merge(array('forum', $delta), drupal_render_cid_parts());
$cache_keys[] = $delta; // Cache based on the altered query. Enables us to cache with node access enabled.
// Cache based on the altered query. Enables us to cache with node access enabled. $query->preExecute();
$query->preExecute(); $cache_keys[] = md5(serialize(array((string) $query, $query->getArguments())));
$cache_keys[] = md5(serialize(array((string) $query, $query->getArguments())));
$block['subject'] = $title;
$block['subject'] = $title; $block['content'] = array(
$block['content'] = array(
'#access' => user_access('access content'), '#access' => user_access('access content'),
'#pre_render' => array('forum_block_view_pre_render'), '#pre_render' => array('forum_block_view_pre_render'),
'#cache' => array( '#cache' => array(
...@@ -553,8 +552,8 @@ function forum_block_view($delta = '') { ...@@ -553,8 +552,8 @@ function forum_block_view($delta = '') {
'expire' => CACHE_TEMPORARY, 'expire' => CACHE_TEMPORARY,
), ),
'#query' => $query, '#query' => $query,
); );
return $block; return $block;
} }
/** /**
......
...@@ -471,7 +471,7 @@ class SearchCommentTestCase extends DrupalWebTestCase { ...@@ -471,7 +471,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL); variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL);
// Enable check_plain() for 'Filtered HTML' text format. // Enable check_plain() for 'Filtered HTML' text format.
$edit = array( $edit = array(
'filters[filter_html_escape]' => 1, 'filters[filter_html_escape][status]' => 1,
); );
$this->drupalPost('admin/config/content/formats/1', $edit, t('Save configuration')); $this->drupalPost('admin/config/content/formats/1', $edit, t('Save configuration'));
// Allow anonymous users to search content. // Allow anonymous users to search content.
......
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