Index: modules/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter.module,v retrieving revision 1.71 diff -u -r1.71 filter.module --- modules/filter.module 25 Aug 2005 21:14:16 -0000 1.71 +++ modules/filter.module 14 Sep 2005 21:21:26 -0000 @@ -26,24 +26,20 @@ return t('Handles the filtering of content in preparation for display.'); case 'admin/filters': - return t(' -
Input formats define a way of processing user-supplied text in Drupal. Every input format has its own settings of which filters to apply. Possible filters include stripping out malicious HTML and making URLs clickable.
-Users can choose between the available input formats when submitting content.
-Below you can configure which input formats are available to which roles, as well as choose a default input format (used for imported content, for example).
'); + return t('Input formats define a way of processing user-supplied text in Drupal. Every input format has its own settings of which filters to apply. Possible filters include stripping out malicious HTML and making URLs clickable.
+Users can choose between the available input formats when submitting content.
+Below you can configure which input formats are available to which roles, as well as choose a default input format (used for imported content, for example).
'); case 'admin/filters/'. arg(2): - return t(' -Every filter performs one particular change on the user input, for example stripping out malicious HTML or making URLs clickable. Choose which filters you want to apply to text in this input format.
-If you notice some filters are causing conflicts in the output, you can rearrange them.
', array('%configure' => url('admin/filters/'. arg(2) .'/configure'), '%order' => url('admin/filters/'. arg(2) .'/order'))); + return t('Every filter performs one particular change on the user input, for example stripping out malicious HTML or making URLs clickable. Choose which filters you want to apply to text in this input format.
+If you notice some filters are causing conflicts in the output, you can rearrange them.
', array('%configure' => url('admin/filters/'. arg(2) .'/configure'))); case 'admin/filters/'. arg(2) .'/configure': - return t(' -If you cannot find the settings for a certain filter, make sure you\'ve enabled it on the list filters tab first.
', array('%url' => url('admin/filters/'. arg(2) .'/list'))); + return t('If you cannot find the settings for a certain filter, make sure you\'ve enabled it on the view tab first.
', array('%url' => url('admin/filters/'. arg(2)))); case 'admin/filters/'. arg(2) .'/order': - return t(' -Because of the flexible filtering system, you might encounter a situation where one filter prevents another from doing its job. For example: a word in an URL gets converted into a glossary term, before the URL can be converted in a clickable link. When this happens, you will need to rearrange the order in which filters get executed.
-Filters are executed from top-to-bottom. You can use the weight column to rearrange them: heavier filters \'sink\' to the bottom.
'); + return t('Because of the flexible filtering system, you might encounter a situation where one filter prevents another from doing its job. For example: a word in an URL gets converted into a glossary term, before the URL can be converted in a clickable link. When this happens, you will need to rearrange the order in which filters get executed.
+Filters are executed from top-to-bottom. You can use the weight column to rearrange them: heavier filters \'sink\' to the bottom.
'); } } @@ -68,7 +64,7 @@ } $output .= t('This site allows HTML content. While learning all of HTML may feel intimidating, learning how to use a very small number of the most basic HTML "tags" is very easy. This table provides examples for each tag that is enabled on this site.
-For more information see W3C\'s HTML Specifications or use your favorite search engine to find other sites that explain HTML.
'); +For more information see W3C\'s HTML Specifications or use your favorite search engine to find other sites that explain HTML.
'); $tips = array( 'a' => array( t('Anchors are used to make links to other pages.'), ''. variable_get('site_name', 'drupal') .''), 'br' => array( t('By default line break tags are automatically added, so use this tag to add additional ones. Use of this tag is different because it is not used with an open/close pair like all the others. Use the extra " /" inside the tag to maintain XHTML 1.0 compatibility'), t('Text withMost unusual characters can be directly entered without any problems.
-If you do encounter problems, try using HTML character entities. A common example looks like & for an ampersand & character. For a full list of entities see HTML\'s entities page. Some of the available characters include:
'); +If you do encounter problems, try using HTML character entities. A common example looks like & for an ampersand & character. For a full list of entities see HTML\'s entities page. Some of the available characters include:
'); $entities = array( array( t('Ampersand'), '&'), array( t('Greater than'), '>'), @@ -159,27 +155,26 @@ case 0: return t('You may post PHP code. You should include <?php ?> tags.'); case 1: - return t(' -If you know how to script in PHP, Drupal gives you the power to embed any script you like. It will be executed when the page is viewed and dynamically embedded into the page. This gives you amazing flexibility and power, but of course with that comes danger and insecurity if you don\'t write good code. If you are not familiar with PHP, SQL or with the site engine, avoid experimenting with PHP because you can corrupt your database or render your site insecure or even unusable! If you don\'t plan to do fancy stuff with your content then you\'re probably better off with straight HTML.
-Remember that the code within each PHP item must be valid PHP code - including things like correctly terminating statements with a semicolon. It is highly recommended that you develop your code separately using a simple test script on top of a test database before migrating to your production environment.
-Notes:
print
or return
statement to output the actual content for your item.A basic example:
--You want to have a box with the title "Welcome" that you use to greet your visitors. The content for this box could be created by going:
-- print t("Welcome visitor, ... welcome message goes here ..."); --If we are however dealing with a registered user, we can customize the message by using:
-- global $user; - if ($user->uid) { - print t("Welcome $user->name, ... welcome message goes here ..."); - } - else { - print t("Welcome visitor, ... welcome message goes here ..."); - } -
For more in-depth examples, we recommend that you check the existing Drupal code and use it as a starting point, especially for sidebar boxes.
'); + return t('If you know how to script in PHP, Drupal gives you the power to embed any script you like. It will be executed when the page is viewed and dynamically embedded into the page. This gives you amazing flexibility and power, but of course with that comes danger and insecurity if you don\'t write good code. If you are not familiar with PHP, SQL or with the site engine, avoid experimenting with PHP because you can corrupt your database or render your site insecure or even unusable! If you don\'t plan to do fancy stuff with your content then you\'re probably better off with straight HTML.
+Remember that the code within each PHP item must be valid PHP code - including things like correctly terminating statements with a semicolon. It is highly recommended that you develop your code separately using a simple test script on top of a test database before migrating to your production environment.
+Notes:
print
or return
statement to output the actual content for your item.A basic example:
++You want to have a box with the title "Welcome" that you use to greet your visitors. The content for this box could be created by going:
++ print t("Welcome visitor, ... welcome message goes here ..."); ++If we are however dealing with a registered user, we can customize the message by using:
++ global $user; + if ($user->uid) { + print t("Welcome $user->name, ... welcome message goes here ..."); + } + else { + print t("Welcome visitor, ... welcome message goes here ..."); + } +
For more in-depth examples, we recommend that you check the existing Drupal code and use it as a starting point, especially for sidebar boxes.
'); } case 2: @@ -188,7 +183,6 @@ return t('Lines and paragraphs break automatically.'); case 1: return t('Lines and paragraphs are automatically recognized. The <br /> line break, <p> paragraph and </p> close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.'); - break; } } } @@ -204,12 +198,19 @@ $items[] = array('path' => 'admin/filters', 'title' => t('input formats'), 'callback' => 'filter_admin_overview', 'access' => user_access('administer filters')); - + $items[] = array('path' => 'admin/filters/list', 'title' => t('list'), + 'callback' => 'filter_admin_overview', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'access' => user_access('administer filters')); + $items[] = array('path' => 'admin/filters/add', 'title' => t('add input format'), + 'callback' => 'filter_admin_add', + 'type' => MENU_LOCAL_TASK, + 'weight' => 1, + 'access' => user_access('administer filters')); $items[] = array('path' => 'admin/filters/delete', 'title' => t('delete input format'), 'callback' => 'filter_admin_delete', 'type' => MENU_CALLBACK, 'access' => user_access('administer filters')); - $items[] = array('path' => 'filter/tips', 'title' => t('compose tips'), 'callback' => 'filter_tips_long', 'access' => TRUE, 'type' => MENU_SUGGESTED_ITEM); @@ -220,27 +221,26 @@ if (isset($formats[arg(2)])) { $items[] = array('path' => 'admin/filters/'. arg(2), 'title' => t("'%format' input format", array('%format' => $formats[arg(2)]->name)), - 'callback' => 'filter_admin_filters', - 'type' => MENU_CALLBACK, - 'access' => user_access('administer filters')); - - $items[] = array('path' => 'admin/filters/'. arg(2) .'/list', 'title' => t('list'), - 'callback' => 'filter_admin_filters', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 0, - 'access' => user_access('administer filters')); - + 'callback' => 'filter_admin_format', + 'callback arguments' => array('format' => $formats[arg(2)]), + 'type' => MENU_CALLBACK, + 'access' => user_access('administer filters')); + $items[] = array('path' => 'admin/filters/'. arg(2) .'/list', 'title' => t('view'), + 'callback' => 'filter_admin_format', + 'callback arguments' => array('format' => $formats[arg(2)]), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 0, + 'access' => user_access('administer filters')); $items[] = array('path' => 'admin/filters/'. arg(2) .'/configure', 'title' => t('configure'), - 'callback' => 'filter_admin_configure', - 'type' => MENU_LOCAL_TASK, - 'weight' => 1, - 'access' => user_access('administer filters')); - + 'callback' => 'filter_admin_configure', + 'type' => MENU_LOCAL_TASK, + 'weight' => 1, + 'access' => user_access('administer filters')); $items[] = array('path' => 'admin/filters/'. arg(2) .'/order', 'title' => t('rearrange'), - 'callback' => 'filter_admin_order', - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'access' => user_access('administer filters')); + 'callback' => 'filter_admin_order', + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'access' => user_access('administer filters')); } } } @@ -256,43 +256,39 @@ } /** - * Menu callback; allows administrators to set up input formats. + * Displays a list of all input formats and which one is the default */ function filter_admin_overview() { - // Process form submission - switch ($_POST['op']) { - case t('Save input formats'): - filter_admin_save(); - break; - case t('Add input format'): - filter_admin_add(); - break; + + $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; + + // Process form submission to set the default format + if (is_numeric($edit['default'])) { + drupal_set_message(t('Default format updated.')); + variable_set('filter_default_format', $edit['default']); } // Overview of all formats. $formats = filter_formats(); - $roles = user_roles(); $error = false; - $header = array(t('Name'), t('Default')); - foreach ($roles as $name) { - $header[] = $name; - } - $header[] = array('data' => t('Operations'), 'colspan' => 2); + $header = array(t('Default'), t('Name'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2)); $rows = array(); foreach ($formats as $id => $format) { + $roles = array(); + foreach (user_roles() as $rid => $name) { + //prepare a roles array with roles that may access the filter + if (strstr($format->roles, ",$rid,")){ + $roles[] = $name; + } + } $row = array(); $default = ($id == variable_get('filter_default_format', 1)); - $row[] = form_textfield('', "name][$id", $format->name, 15, 255); $row[] = form_radio('', 'default', $id, $default); - - foreach ($roles as $rid => $name) { - $checked = strstr($format->roles, ",$rid,"); - $row[] = form_checkbox('', "roles][$id][$rid", 1, $default || $checked, NULL, $default ? array('disabled' => 'disabled') : NULL); - } - + $row[] = $format->name; + $row[] = $roles ? implode(', ',$roles) : t('No roles may use this format'); $row[] = l(t('configure'), 'admin/filters/'. $id); $row[] = $default ? '' : l('delete', 'admin/filters/delete/'. $id); @@ -300,73 +296,24 @@ } $group = theme('table', $header, $rows); - $group .= form_submit(t('Save input formats')); - $output = 'To add a new input format, type its name here. After it has been added, you can configure its options.
"); - $form = form_textfield(t('Name'), 'name', '', 30, 255); - $form .= form_submit(t('Add input format')); - $group .= form($form); - $output .= ' -
-
- '), 60, 255, t('If "Strip tags" is selected, optionally specify tags which should not be stripped. Javascript event attributes are always stripped.'));
+ $group .= form_textfield(t('Allowed HTML tags'), "allowed_html_$format", variable_get("allowed_html_$format", '
-
-
- '), 64, 255, t('If "Strip tags" is selected, optionally specify tags which should not be stripped. Javascript event attributes are always stripped.'));
$group .= form_checkbox(t('Display HTML help'), "filter_html_help_$format", 1, variable_get("filter_html_help_$format", 1), t('If enabled, Drupal will display some basic HTML help in the long filter tips.'));
$group .= form_radios(t('HTML style attributes'), "filter_style_$format", variable_get("filter_style_$format", FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.'));
$group .= form_checkbox(t('Spam link deterrent'), "filter_html_nofollow_$format", 1, variable_get("filter_html_nofollow_$format", FALSE), 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.'));
- $output .= form_group(t('HTML filter'), $group);
+ $output .= form_group_collapsible(t('HTML filter'), $group, TRUE);
return $output;
}