summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-04-03 23:59:48 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-04-03 23:59:48 +0000
commitda38e1b65464420d92aea7843fe19a43130fcbc3 (patch)
tree3fa02cc4817cc4707a0ba5ef73c34babc79e4326 /modules
parent13e52fe352f977d6edb196bb0c196eabf83f2f72 (diff)
downloadbrdo-da38e1b65464420d92aea7843fe19a43130fcbc3.tar.gz
brdo-da38e1b65464420d92aea7843fe19a43130fcbc3.tar.bz2
- Store correct format id instead of 0 for anonymous users (+ code cleanup)
Diffstat (limited to 'modules')
-rw-r--r--modules/filter.module22
-rw-r--r--modules/filter/filter.module22
2 files changed, 24 insertions, 20 deletions
diff --git a/modules/filter.module b/modules/filter.module
index 1a6c9e0cd..1136a402a 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -670,11 +670,17 @@ function _filter_list_cmp($a, $b) {
}
/**
+ * 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.
*/
function filter_format_allowcache($format) {
static $cache = array();
-
+ $format = filter_resolve_format($format);
if (!isset($cache[$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) {
function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
// When $check = true, do an access check on $format.
if (isset($text) && (!$check || filter_access($format))) {
- if ($format == FILTER_FORMAT_DEFAULT) {
- $format = variable_get('filter_default_format', 1);
- }
+ $format = filter_resolve_format($format);
// Check for a cached version of this piece of text.
$id = 'filter:'. $format .':'. md5($text);
@@ -790,9 +794,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
* HTML for the form element.
*/
function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
- if ($value == FILTER_FORMAT_DEFAULT) {
- $value = variable_get('filter_default_format', 1);
- }
+ $format = filter_resolve_format($format);
$formats = filter_formats();
$extra = l(t('More information about formatting options'), 'filter/tips');
@@ -821,10 +823,9 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
else {
// Only one format available: use a hidden form item and only show tips.
$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);
$form['format']['guidelines'] = array(
- '#type' => 'markup',
'#title' => t('Formatting guidelines'),
'#value' => theme('filter_tips', $tips, false, $extra),
);
@@ -846,7 +847,8 @@ function filter_form_validate($form) {
* Returns true if the user is allowed to access this 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;
}
else {
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 1a6c9e0cd..1136a402a 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -670,11 +670,17 @@ function _filter_list_cmp($a, $b) {
}
/**
+ * 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.
*/
function filter_format_allowcache($format) {
static $cache = array();
-
+ $format = filter_resolve_format($format);
if (!isset($cache[$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) {
function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
// When $check = true, do an access check on $format.
if (isset($text) && (!$check || filter_access($format))) {
- if ($format == FILTER_FORMAT_DEFAULT) {
- $format = variable_get('filter_default_format', 1);
- }
+ $format = filter_resolve_format($format);
// Check for a cached version of this piece of text.
$id = 'filter:'. $format .':'. md5($text);
@@ -790,9 +794,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) {
* HTML for the form element.
*/
function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
- if ($value == FILTER_FORMAT_DEFAULT) {
- $value = variable_get('filter_default_format', 1);
- }
+ $format = filter_resolve_format($format);
$formats = filter_formats();
$extra = l(t('More information about formatting options'), 'filter/tips');
@@ -821,10 +823,9 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents =
else {
// Only one format available: use a hidden form item and only show tips.
$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);
$form['format']['guidelines'] = array(
- '#type' => 'markup',
'#title' => t('Formatting guidelines'),
'#value' => theme('filter_tips', $tips, false, $extra),
);
@@ -846,7 +847,8 @@ function filter_form_validate($form) {
* Returns true if the user is allowed to access this 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;
}
else {