Skip to content
Snippets Groups Projects
Commit da38e1b6 authored by Steven Wittens's avatar Steven Wittens
Browse files

- Store correct format id instead of 0 for anonymous users (+ code cleanup)

parent 13e52fe3
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -669,12 +669,18 @@ function _filter_list_cmp($a, $b) { ...@@ -669,12 +669,18 @@ function _filter_list_cmp($a, $b) {
return strcmp($a->name, $b->name); return strcmp($a->name, $b->name);
} }
/**
* Resolve a format id, including the default format.
*/
function filter_resolve_format($format) {
return $format == FILTER_FORMAT_DEFAULT ? variable_get('filter_default_format', 1) : $format;
}
/** /**
* Check if text in a certain input format is allowed to be cached. * Check if text in a certain input format is allowed to be cached.
*/ */
function filter_format_allowcache($format) { function filter_format_allowcache($format) {
static $cache = array(); static $cache = array();
$format = filter_resolve_format($format);
if (!isset($cache[$format])) { if (!isset($cache[$format])) {
$cache[$format] = db_result(db_query('SELECT cache FROM {filter_formats} WHERE format = %d', $format)); $cache[$format] = db_result(db_query('SELECT cache FROM {filter_formats} WHERE format = %d', $format));
} }
...@@ -735,9 +741,7 @@ function filter_list_format($format) { ...@@ -735,9 +741,7 @@ function filter_list_format($format) {
function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) { function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
// When $check = true, do an access check on $format. // When $check = true, do an access check on $format.
if (isset($text) && (!$check || filter_access($format))) { if (isset($text) && (!$check || filter_access($format))) {
if ($format == FILTER_FORMAT_DEFAULT) { $format = filter_resolve_format($format);
$format = variable_get('filter_default_format', 1);
}
// Check for a cached version of this piece of text. // Check for a cached version of this piece of text.
$id = 'filter:'. $format .':'. md5($text); $id = 'filter:'. $format .':'. md5($text);
...@@ -790,9 +794,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) { ...@@ -790,9 +794,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
* HTML for the form element. * HTML for the form element.
*/ */
function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) { function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
if ($value == FILTER_FORMAT_DEFAULT) { $format = filter_resolve_format($format);
$value = variable_get('filter_default_format', 1);
}
$formats = filter_formats(); $formats = filter_formats();
$extra = l(t('More information about formatting options'), 'filter/tips'); $extra = l(t('More information about formatting options'), 'filter/tips');
...@@ -821,10 +823,9 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = ...@@ -821,10 +823,9 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
else { else {
// Only one format available: use a hidden form item and only show tips. // Only one format available: use a hidden form item and only show tips.
$format = array_shift($formats); $format = array_shift($formats);
$form['format'][$format->name] = array('#type' => 'value', '#value' => $format->format); $form[$format->format] = array('#type' => 'value', '#value' => $format->format, '#parents' => $parents);
$tips = _filter_tips(variable_get('filter_default_format', 1), false); $tips = _filter_tips(variable_get('filter_default_format', 1), false);
$form['format']['guidelines'] = array( $form['format']['guidelines'] = array(
'#type' => 'markup',
'#title' => t('Formatting guidelines'), '#title' => t('Formatting guidelines'),
'#value' => theme('filter_tips', $tips, false, $extra), '#value' => theme('filter_tips', $tips, false, $extra),
); );
...@@ -846,7 +847,8 @@ function filter_form_validate($form) { ...@@ -846,7 +847,8 @@ function filter_form_validate($form) {
* Returns true if the user is allowed to access this format. * Returns true if the user is allowed to access this format.
*/ */
function filter_access($format) { function filter_access($format) {
if (user_access('administer filters') || ($format == FILTER_FORMAT_DEFAULT) || ($format == variable_get('filter_default_format', 1))) { $format = filter_resolve_format($format);
if (user_access('administer filters') || ($format == variable_get('filter_default_format', 1))) {
return true; return true;
} }
else { else {
......
...@@ -669,12 +669,18 @@ function _filter_list_cmp($a, $b) { ...@@ -669,12 +669,18 @@ function _filter_list_cmp($a, $b) {
return strcmp($a->name, $b->name); return strcmp($a->name, $b->name);
} }
/**
* Resolve a format id, including the default format.
*/
function filter_resolve_format($format) {
return $format == FILTER_FORMAT_DEFAULT ? variable_get('filter_default_format', 1) : $format;
}
/** /**
* Check if text in a certain input format is allowed to be cached. * Check if text in a certain input format is allowed to be cached.
*/ */
function filter_format_allowcache($format) { function filter_format_allowcache($format) {
static $cache = array(); static $cache = array();
$format = filter_resolve_format($format);
if (!isset($cache[$format])) { if (!isset($cache[$format])) {
$cache[$format] = db_result(db_query('SELECT cache FROM {filter_formats} WHERE format = %d', $format)); $cache[$format] = db_result(db_query('SELECT cache FROM {filter_formats} WHERE format = %d', $format));
} }
...@@ -735,9 +741,7 @@ function filter_list_format($format) { ...@@ -735,9 +741,7 @@ function filter_list_format($format) {
function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) { function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
// When $check = true, do an access check on $format. // When $check = true, do an access check on $format.
if (isset($text) && (!$check || filter_access($format))) { if (isset($text) && (!$check || filter_access($format))) {
if ($format == FILTER_FORMAT_DEFAULT) { $format = filter_resolve_format($format);
$format = variable_get('filter_default_format', 1);
}
// Check for a cached version of this piece of text. // Check for a cached version of this piece of text.
$id = 'filter:'. $format .':'. md5($text); $id = 'filter:'. $format .':'. md5($text);
...@@ -790,9 +794,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) { ...@@ -790,9 +794,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
* HTML for the form element. * HTML for the form element.
*/ */
function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) { function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
if ($value == FILTER_FORMAT_DEFAULT) { $format = filter_resolve_format($format);
$value = variable_get('filter_default_format', 1);
}
$formats = filter_formats(); $formats = filter_formats();
$extra = l(t('More information about formatting options'), 'filter/tips'); $extra = l(t('More information about formatting options'), 'filter/tips');
...@@ -821,10 +823,9 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = ...@@ -821,10 +823,9 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
else { else {
// Only one format available: use a hidden form item and only show tips. // Only one format available: use a hidden form item and only show tips.
$format = array_shift($formats); $format = array_shift($formats);
$form['format'][$format->name] = array('#type' => 'value', '#value' => $format->format); $form[$format->format] = array('#type' => 'value', '#value' => $format->format, '#parents' => $parents);
$tips = _filter_tips(variable_get('filter_default_format', 1), false); $tips = _filter_tips(variable_get('filter_default_format', 1), false);
$form['format']['guidelines'] = array( $form['format']['guidelines'] = array(
'#type' => 'markup',
'#title' => t('Formatting guidelines'), '#title' => t('Formatting guidelines'),
'#value' => theme('filter_tips', $tips, false, $extra), '#value' => theme('filter_tips', $tips, false, $extra),
); );
...@@ -846,7 +847,8 @@ function filter_form_validate($form) { ...@@ -846,7 +847,8 @@ function filter_form_validate($form) {
* Returns true if the user is allowed to access this format. * Returns true if the user is allowed to access this format.
*/ */
function filter_access($format) { function filter_access($format) {
if (user_access('administer filters') || ($format == FILTER_FORMAT_DEFAULT) || ($format == variable_get('filter_default_format', 1))) { $format = filter_resolve_format($format);
if (user_access('administer filters') || ($format == variable_get('filter_default_format', 1))) {
return true; return true;
} }
else { else {
......
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