Index: modules/php/php.module =================================================================== RCS file: /cvs/drupal/drupal/modules/php/php.module,v retrieving revision 1.16 diff -u -r1.16 php.module --- modules/php/php.module 13 Aug 2009 19:53:20 -0000 1.16 +++ modules/php/php.module 13 Aug 2009 21:26:29 -0000 @@ -78,33 +78,29 @@ } /** - * Implement hook_filter_tips(). + * Tips callback for php filter. */ -function php_filter_tips($delta, $format, $long = FALSE) { +function _php_filter_tips($format, $long = FALSE) { global $base_url; - if ($delta == 0) { - switch ($long) { - case 0: - return t('You may post PHP code. You should include <?php ?> tags.'); - case 1: - $output = '
' . t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') . '
'; - $output .= '' . t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') . '
'; - $output .= '' . t('Notes:') . '
'; - $output .= 'register_globals is turned off. If you need to use forms, understand and use the functions in the Drupal Form API.', array('@formapi' => url('http://api.drupal.org/api/group/form_api/7'))) . 'print or return statement in your code to output content.') . 'template.php file rather than embedding it directly into a post or block.') . '' . t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') . '
'; - $output .= 'Add a custom block to your site, named "Welcome" . With its text format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:
+ if ($long) { + $output = '' . t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') . '
'; + $output .= '' . t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') . '
'; + $output .= '' . t('Notes:') . '
'; + $output .= 'register_globals is turned off. If you need to use forms, understand and use the functions in the Drupal Form API.', array('@formapi' => url('http://api.drupal.org/api/group/form_api/7'))) . 'print or return statement in your code to output content.') . 'template.php file rather than embedding it directly into a post or block.') . '' . t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') . '
'; + $output .= 'Add a custom block to your site, named "Welcome" . With its text format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:
print t(\'Welcome visitor! Thank you for visiting.\');') . '
To display the name of a registered user, use this instead:
+ $output .= 'To display the name of a registered user, use this instead:
global $user;
if ($user->uid) {
@@ -114,9 +110,11 @@
print t(\'Welcome visitor! Thank you for visiting.\');
}
') . '' . t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', array('@drupal' => url('http://drupal.org'), '@php-snippets' => url('http://drupal.org/handbook/customization/php-snippets'))) . '
'; - return $output; - } + $output .= '' . t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', array('@drupal' => url('http://drupal.org'), '@php-snippets' => url('http://drupal.org/handbook/customization/php-snippets'))) . '
'; + return $output; + } + else { + return t('You may post PHP code. You should include <?php ?> tags.'); } } @@ -133,7 +131,8 @@ 'name' => t('PHP evaluator'), 'description' => t('Executes a piece of PHP code. The usage of this filter should be restricted to administrators only!'), 'cache' => FALSE, - 'process callback' => 'php_eval' + 'process callback' => 'php_eval', + 'tips callback' => '_php_filter_tips' ) ); } Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.267 diff -u -r1.267 filter.module --- modules/filter/filter.module 13 Aug 2009 19:53:19 -0000 1.267 +++ modules/filter/filter.module 13 Aug 2009 21:26:28 -0000 @@ -166,125 +166,126 @@ } /** - * Implement hook_filter_tips(). + * @name Tips callbacks for filters. + * @{ + * Filters implemented by the filter.module. */ -function filter_filter_tips($delta, $format, $long = FALSE) { +function _filter_html_tips($format, $long = FALSE) { global $base_url; - switch ($delta) { - case 0: - if ($allowed_html = variable_get("allowed_html_$format", ' -
-
- ')) {
- switch ($long) {
- case 0:
- return t('Allowed HTML tags: @tags', array('@tags' => $allowed_html));
- case 1:
- $output = '
' . t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)) . '
';
- if (!variable_get("filter_html_help_$format", 1)) {
- return $output;
- }
-
- $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.') . '
';
- $output .= '' . t('For more information see W3C\'s HTML Specifications or use your favorite search engine to find other sites that explain HTML.', array('@html-specifications' => 'http://www.w3.org/TR/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 with
line break')),
- 'p' => array( t('By default paragraph tags are automatically added, so use this tag to add additional ones.'), '' . t('Paragraph one.') . '
' . t('Paragraph two.') . '
'),
- 'strong' => array( t('Strong'), '' . t('Strong') . ''),
- 'em' => array( t('Emphasized'), '' . t('Emphasized') . ''),
- 'cite' => array( t('Cited'), '' . t('Cited') . ''),
- 'code' => array( t('Coded text used to show programming source code'), '' . t('Coded') . ''),
- 'b' => array( t('Bolded'), '' . t('Bolded') . ''),
- 'u' => array( t('Underlined'), '' . t('Underlined') . ''),
- 'i' => array( t('Italicized'), '' . t('Italicized') . ''),
- 'sup' => array( t('Superscripted'), t('Superscripted')),
- 'sub' => array( t('Subscripted'), t('Subscripted')),
- 'pre' => array( t('Preformatted'), '' . t('Preformatted') . ''),
- 'abbr' => array( t('Abbreviation'), t('Abbrev.')),
- 'acronym' => array( t('Acronym'), t('TLA')),
- 'blockquote' => array( t('Block quoted'), '' . t('Block quoted') . '
'),
- 'q' => array( t('Quoted inline'), '' . t('Quoted inline') . '
'),
- // Assumes and describes tr, td, th.
- 'table' => array( t('Table'), ' ' . t('Table header') . ' ' . t('Table cell') . '
'),
- 'tr' => NULL, 'td' => NULL, 'th' => NULL,
- 'del' => array( t('Deleted'), '' . t('Deleted') . ''),
- 'ins' => array( t('Inserted'), '' . t('Inserted') . ''),
- // Assumes and describes li.
- 'ol' => array( t('Ordered list - use the <li> to begin each list item'), ' - ' . t('First item') . '
- ' . t('Second item') . '
'),
- 'ul' => array( t('Unordered list - use the <li> to begin each list item'), ' - ' . t('First item') . '
- ' . t('Second item') . '
'),
- 'li' => NULL,
- // Assumes and describes dt and dd.
- 'dl' => array( t('Definition lists are similar to other HTML lists. <dl> begins the definition list, <dt> begins the definition term and <dd> begins the definition description.'), ' - ' . t('First term') . '
- ' . t('First definition') . '
- ' . t('Second term') . '
- ' . t('Second definition') . '
'),
- 'dt' => NULL, 'dd' => NULL,
- 'h1' => array( t('Heading'), '' . t('Title') . '
'),
- 'h2' => array( t('Heading'), '' . t('Subtitle') . '
'),
- 'h3' => array( t('Heading'), '' . t('Subtitle three') . '
'),
- 'h4' => array( t('Heading'), '' . t('Subtitle four') . '
'),
- 'h5' => array( t('Heading'), '' . t('Subtitle five') . '
'),
- 'h6' => array( t('Heading'), '' . t('Subtitle six') . '
')
- );
- $header = array(t('Tag Description'), t('You Type'), t('You Get'));
- preg_match_all('/<([a-z0-9]+)[^a-z0-9]/i', $allowed_html, $out);
- foreach ($out[1] as $tag) {
- if (array_key_exists($tag, $tips)) {
- if ($tips[$tag]) {
- $rows[] = array(
- array('data' => $tips[$tag][0], 'class' => 'description'),
- array('data' => '' . check_plain($tips[$tag][1]) . '', 'class' => 'type'),
- array('data' => $tips[$tag][1], 'class' => 'get')
- );
- }
- }
- else {
- $rows[] = array(
- array('data' => t('No help provided for tag %tag.', array('%tag' => $tag)), 'class' => 'description', 'colspan' => 3),
- );
- }
- }
- $output .= theme('table', $header, $rows);
-
- $output .= '' . t('Most unusual characters can be directly entered without any problems.') . '
';
- $output .= '' . t('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:', array('@html-entities' => 'http://www.w3.org/TR/html4/sgml/entities.html')) . '
';
-
- $entities = array(
- array( t('Ampersand'), '&'),
- array( t('Greater than'), '>'),
- array( t('Less than'), '<'),
- array( t('Quotation mark'), '"'),
+ if ($allowed_html = variable_get("allowed_html_$format", ' -
-
- ')) {
+ if ($long) {
+ $output = '
' . t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)) . '
';
+ if (!variable_get("filter_html_help_$format", 1)) {
+ return $output;
+ }
+
+ $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.') . '
';
+ $output .= '' . t('For more information see W3C\'s HTML Specifications or use your favorite search engine to find other sites that explain HTML.', array('@html-specifications' => 'http://www.w3.org/TR/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 with
line break')),
+ 'p' => array( t('By default paragraph tags are automatically added, so use this tag to add additional ones.'), '' . t('Paragraph one.') . '
' . t('Paragraph two.') . '
'),
+ 'strong' => array( t('Strong'), '' . t('Strong') . ''),
+ 'em' => array( t('Emphasized'), '' . t('Emphasized') . ''),
+ 'cite' => array( t('Cited'), '' . t('Cited') . ''),
+ 'code' => array( t('Coded text used to show programming source code'), '' . t('Coded') . ''),
+ 'b' => array( t('Bolded'), '' . t('Bolded') . ''),
+ 'u' => array( t('Underlined'), '' . t('Underlined') . ''),
+ 'i' => array( t('Italicized'), '' . t('Italicized') . ''),
+ 'sup' => array( t('Superscripted'), t('Superscripted')),
+ 'sub' => array( t('Subscripted'), t('Subscripted')),
+ 'pre' => array( t('Preformatted'), '' . t('Preformatted') . ''),
+ 'abbr' => array( t('Abbreviation'), t('Abbrev.')),
+ 'acronym' => array( t('Acronym'), t('TLA')),
+ 'blockquote' => array( t('Block quoted'), '' . t('Block quoted') . '
'),
+ 'q' => array( t('Quoted inline'), '' . t('Quoted inline') . '
'),
+ // Assumes and describes tr, td, th.
+ 'table' => array( t('Table'), ' ' . t('Table header') . ' ' . t('Table cell') . '
'),
+ 'tr' => NULL, 'td' => NULL, 'th' => NULL,
+ 'del' => array( t('Deleted'), '' . t('Deleted') . ''),
+ 'ins' => array( t('Inserted'), '' . t('Inserted') . ''),
+ // Assumes and describes li.
+ 'ol' => array( t('Ordered list - use the <li> to begin each list item'), ' - ' . t('First item') . '
- ' . t('Second item') . '
'),
+ 'ul' => array( t('Unordered list - use the <li> to begin each list item'), ' - ' . t('First item') . '
- ' . t('Second item') . '
'),
+ 'li' => NULL,
+ // Assumes and describes dt and dd.
+ 'dl' => array( t('Definition lists are similar to other HTML lists. <dl> begins the definition list, <dt> begins the definition term and <dd> begins the definition description.'), ' - ' . t('First term') . '
- ' . t('First definition') . '
- ' . t('Second term') . '
- ' . t('Second definition') . '
'),
+ 'dt' => NULL, 'dd' => NULL,
+ 'h1' => array( t('Heading'), '' . t('Title') . '
'),
+ 'h2' => array( t('Heading'), '' . t('Subtitle') . '
'),
+ 'h3' => array( t('Heading'), '' . t('Subtitle three') . '
'),
+ 'h4' => array( t('Heading'), '' . t('Subtitle four') . '
'),
+ 'h5' => array( t('Heading'), '' . t('Subtitle five') . '
'),
+ 'h6' => array( t('Heading'), '' . t('Subtitle six') . '
')
+ );
+ $header = array(t('Tag Description'), t('You Type'), t('You Get'));
+ preg_match_all('/<([a-z0-9]+)[^a-z0-9]/i', $allowed_html, $out);
+ foreach ($out[1] as $tag) {
+ if (array_key_exists($tag, $tips)) {
+ if ($tips[$tag]) {
+ $rows[] = array(
+ array('data' => $tips[$tag][0], 'class' => 'description'),
+ array('data' => '' . check_plain($tips[$tag][1]) . '', 'class' => 'type'),
+ array('data' => $tips[$tag][1], 'class' => 'get')
);
- $header = array(t('Character Description'), t('You Type'), t('You Get'));
- unset($rows);
- foreach ($entities as $entity) {
- $rows[] = array(
- array('data' => $entity[0], 'class' => 'description'),
- array('data' => '' . check_plain($entity[1]) . '', 'class' => 'type'),
- array('data' => $entity[1], 'class' => 'get')
- );
- }
- $output .= theme('table', $header, $rows);
- return $output;
+ }
+ }
+ else {
+ $rows[] = array(
+ array('data' => t('No help provided for tag %tag.', array('%tag' => $tag)), 'class' => 'description', 'colspan' => 3),
+ );
}
}
- break;
+ $output .= theme('table', $header, $rows);
+
+ $output .= '' . t('Most unusual characters can be directly entered without any problems.') . '
';
+ $output .= '' . t('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:', array('@html-entities' => 'http://www.w3.org/TR/html4/sgml/entities.html')) . '
';
- case 1:
- switch ($long) {
- case 0:
- 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;
-
- case 2:
- return t('Web page addresses and e-mail addresses turn into links automatically.');
- break;
-
- case 4:
- return t('No HTML tags allowed.');
- break;
+ $entities = array(
+ array( t('Ampersand'), '&'),
+ array( t('Greater than'), '>'),
+ array( t('Less than'), '<'),
+ array( t('Quotation mark'), '"'),
+ );
+ $header = array(t('Character Description'), t('You Type'), t('You Get'));
+ unset($rows);
+ foreach ($entities as $entity) {
+ $rows[] = array(
+ array('data' => $entity[0], 'class' => 'description'),
+ array('data' => '' . check_plain($entity[1]) . '', 'class' => 'type'),
+ array('data' => $entity[1], 'class' => 'get')
+ );
+ }
+ $output .= theme('table', $header, $rows);
+ return $output;
+ }
+
+ else {
+ return t('Allowed HTML tags: @tags', array('@tags' => $allowed_html));
+ }
+ }
+}
+function _filter_autop_tips($format, $long = FALSE) {
+ if ($long) {
+ 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.');
+ }
+ else {
+ return t('Lines and paragraphs break automatically.');
}
}
+function _filter_url_tips() {
+ return t('Web page addresses and e-mail addresses turn into links automatically.');
+}
+
+function _filter_html_escape_tips() {
+ return t('No HTML tags allowed.');
+}
+
+/**
+ * @} End of "Tips callback for filters".
+ */
/**
* Retrieve a list of text formats.
*/
@@ -571,7 +572,9 @@
$tips[$format->name] = array();
foreach ($filters as $id => $filter) {
- if ($tip = module_invoke($filter->module, 'filter_tips', $filter->delta, $format->format, $long)) {
+ $filter_info = module_invoke($filter->module, 'filter_info');
+ if (isset($filter_info[$filter->delta]['tips callback']) && drupal_function_exists($filter_info[$filter->delta]['tips callback'])) {
+ $tip = call_user_func($filter_info[$filter->delta]['tips callback'],$format->format, $long);
$tips[$format->name][] = array('tip' => $tip, 'id' => $id);
}
}