summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2009-08-14 08:06:23 (GMT)
committerDries Buytaert2009-08-14 08:06:23 (GMT)
commit2dd0b6ff5dc85c03d91c0df6caf55a1200eee744 (patch)
tree64305e9abe20d0ab016ccf007a136b5b66546d4b
parent173f0249a5a973482ef11027ede2a5e95c3eaaed (diff)
- Patch #548308 by dropcube: remove hook_filter_tips() as part of the hook_filter() refactoring.
-rw-r--r--modules/filter/filter.module221
-rw-r--r--modules/php/php.module51
2 files changed, 137 insertions, 135 deletions
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index a1c793d..945a905 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -166,126 +166,127 @@ function filter_cron() {
}
/**
- * 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", '<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>')) {
- switch ($long) {
- case 0:
- return t('Allowed HTML tags: @tags', array('@tags' => $allowed_html));
- case 1:
- $output = '<p>' . t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)) . '</p>';
- if (!variable_get("filter_html_help_$format", 1)) {
- return $output;
- }
-
- $output .= '<p>' . 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.') . '</p>';
- $output .= '<p>' . t('For more information see W3C\'s <a href="@html-specifications">HTML Specifications</a> or use your favorite search engine to find other sites that explain HTML.', array('@html-specifications' => 'http://www.w3.org/TR/html/')) . '</p>';
- $tips = array(
- 'a' => array( t('Anchors are used to make links to other pages.'), '<a href="' . $base_url . '">' . variable_get('site_name', 'Drupal') . '</a>'),
- '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 <br />line break')),
- 'p' => array( t('By default paragraph tags are automatically added, so use this tag to add additional ones.'), '<p>' . t('Paragraph one.') . '</p> <p>' . t('Paragraph two.') . '</p>'),
- 'strong' => array( t('Strong'), '<strong>' . t('Strong') . '</strong>'),
- 'em' => array( t('Emphasized'), '<em>' . t('Emphasized') . '</em>'),
- 'cite' => array( t('Cited'), '<cite>' . t('Cited') . '</cite>'),
- 'code' => array( t('Coded text used to show programming source code'), '<code>' . t('Coded') . '</code>'),
- 'b' => array( t('Bolded'), '<b>' . t('Bolded') . '</b>'),
- 'u' => array( t('Underlined'), '<u>' . t('Underlined') . '</u>'),
- 'i' => array( t('Italicized'), '<i>' . t('Italicized') . '</i>'),
- 'sup' => array( t('Superscripted'), t('<sup>Super</sup>scripted')),
- 'sub' => array( t('Subscripted'), t('<sub>Sub</sub>scripted')),
- 'pre' => array( t('Preformatted'), '<pre>' . t('Preformatted') . '</pre>'),
- 'abbr' => array( t('Abbreviation'), t('<abbr title="Abbreviation">Abbrev.</abbr>')),
- 'acronym' => array( t('Acronym'), t('<acronym title="Three-Letter Acronym">TLA</acronym>')),
- 'blockquote' => array( t('Block quoted'), '<blockquote>' . t('Block quoted') . '</blockquote>'),
- 'q' => array( t('Quoted inline'), '<q>' . t('Quoted inline') . '</q>'),
- // Assumes and describes tr, td, th.
- 'table' => array( t('Table'), '<table> <tr><th>' . t('Table header') . '</th></tr> <tr><td>' . t('Table cell') . '</td></tr> </table>'),
- 'tr' => NULL, 'td' => NULL, 'th' => NULL,
- 'del' => array( t('Deleted'), '<del>' . t('Deleted') . '</del>'),
- 'ins' => array( t('Inserted'), '<ins>' . t('Inserted') . '</ins>'),
- // Assumes and describes li.
- 'ol' => array( t('Ordered list - use the &lt;li&gt; to begin each list item'), '<ol> <li>' . t('First item') . '</li> <li>' . t('Second item') . '</li> </ol>'),
- 'ul' => array( t('Unordered list - use the &lt;li&gt; to begin each list item'), '<ul> <li>' . t('First item') . '</li> <li>' . t('Second item') . '</li> </ul>'),
- 'li' => NULL,
- // Assumes and describes dt and dd.
- 'dl' => array( t('Definition lists are similar to other HTML lists. &lt;dl&gt; begins the definition list, &lt;dt&gt; begins the definition term and &lt;dd&gt; begins the definition description.'), '<dl> <dt>' . t('First term') . '</dt> <dd>' . t('First definition') . '</dd> <dt>' . t('Second term') . '</dt> <dd>' . t('Second definition') . '</dd> </dl>'),
- 'dt' => NULL, 'dd' => NULL,
- 'h1' => array( t('Heading'), '<h1>' . t('Title') . '</h1>'),
- 'h2' => array( t('Heading'), '<h2>' . t('Subtitle') . '</h2>'),
- 'h3' => array( t('Heading'), '<h3>' . t('Subtitle three') . '</h3>'),
- 'h4' => array( t('Heading'), '<h4>' . t('Subtitle four') . '</h4>'),
- 'h5' => array( t('Heading'), '<h5>' . t('Subtitle five') . '</h5>'),
- 'h6' => array( t('Heading'), '<h6>' . t('Subtitle six') . '</h6>')
- );
- $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' => '<code>' . check_plain($tips[$tag][1]) . '</code>', '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 .= '<p>' . t('Most unusual characters can be directly entered without any problems.') . '</p>';
- $output .= '<p>' . t('If you do encounter problems, try using HTML character entities. A common example looks like &amp;amp; for an ampersand &amp; character. For a full list of entities see HTML\'s <a href="@html-entities">entities</a> page. Some of the available characters include:', array('@html-entities' => 'http://www.w3.org/TR/html4/sgml/entities.html')) . '</p>';
-
- $entities = array(
- array( t('Ampersand'), '&amp;'),
- array( t('Greater than'), '&gt;'),
- array( t('Less than'), '&lt;'),
- array( t('Quotation mark'), '&quot;'),
+ if ($allowed_html = variable_get("allowed_html_$format", '<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>')) {
+ if ($long) {
+ $output = '<p>' . t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)) . '</p>';
+ if (!variable_get("filter_html_help_$format", 1)) {
+ return $output;
+ }
+
+ $output .= '<p>' . 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.') . '</p>';
+ $output .= '<p>' . t('For more information see W3C\'s <a href="@html-specifications">HTML Specifications</a> or use your favorite search engine to find other sites that explain HTML.', array('@html-specifications' => 'http://www.w3.org/TR/html/')) . '</p>';
+ $tips = array(
+ 'a' => array( t('Anchors are used to make links to other pages.'), '<a href="' . $base_url . '">' . variable_get('site_name', 'Drupal') . '</a>'),
+ '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 <br />line break')),
+ 'p' => array( t('By default paragraph tags are automatically added, so use this tag to add additional ones.'), '<p>' . t('Paragraph one.') . '</p> <p>' . t('Paragraph two.') . '</p>'),
+ 'strong' => array( t('Strong'), '<strong>' . t('Strong') . '</strong>'),
+ 'em' => array( t('Emphasized'), '<em>' . t('Emphasized') . '</em>'),
+ 'cite' => array( t('Cited'), '<cite>' . t('Cited') . '</cite>'),
+ 'code' => array( t('Coded text used to show programming source code'), '<code>' . t('Coded') . '</code>'),
+ 'b' => array( t('Bolded'), '<b>' . t('Bolded') . '</b>'),
+ 'u' => array( t('Underlined'), '<u>' . t('Underlined') . '</u>'),
+ 'i' => array( t('Italicized'), '<i>' . t('Italicized') . '</i>'),
+ 'sup' => array( t('Superscripted'), t('<sup>Super</sup>scripted')),
+ 'sub' => array( t('Subscripted'), t('<sub>Sub</sub>scripted')),
+ 'pre' => array( t('Preformatted'), '<pre>' . t('Preformatted') . '</pre>'),
+ 'abbr' => array( t('Abbreviation'), t('<abbr title="Abbreviation">Abbrev.</abbr>')),
+ 'acronym' => array( t('Acronym'), t('<acronym title="Three-Letter Acronym">TLA</acronym>')),
+ 'blockquote' => array( t('Block quoted'), '<blockquote>' . t('Block quoted') . '</blockquote>'),
+ 'q' => array( t('Quoted inline'), '<q>' . t('Quoted inline') . '</q>'),
+ // Assumes and describes tr, td, th.
+ 'table' => array( t('Table'), '<table> <tr><th>' . t('Table header') . '</th></tr> <tr><td>' . t('Table cell') . '</td></tr> </table>'),
+ 'tr' => NULL, 'td' => NULL, 'th' => NULL,
+ 'del' => array( t('Deleted'), '<del>' . t('Deleted') . '</del>'),
+ 'ins' => array( t('Inserted'), '<ins>' . t('Inserted') . '</ins>'),
+ // Assumes and describes li.
+ 'ol' => array( t('Ordered list - use the &lt;li&gt; to begin each list item'), '<ol> <li>' . t('First item') . '</li> <li>' . t('Second item') . '</li> </ol>'),
+ 'ul' => array( t('Unordered list - use the &lt;li&gt; to begin each list item'), '<ul> <li>' . t('First item') . '</li> <li>' . t('Second item') . '</li> </ul>'),
+ 'li' => NULL,
+ // Assumes and describes dt and dd.
+ 'dl' => array( t('Definition lists are similar to other HTML lists. &lt;dl&gt; begins the definition list, &lt;dt&gt; begins the definition term and &lt;dd&gt; begins the definition description.'), '<dl> <dt>' . t('First term') . '</dt> <dd>' . t('First definition') . '</dd> <dt>' . t('Second term') . '</dt> <dd>' . t('Second definition') . '</dd> </dl>'),
+ 'dt' => NULL, 'dd' => NULL,
+ 'h1' => array( t('Heading'), '<h1>' . t('Title') . '</h1>'),
+ 'h2' => array( t('Heading'), '<h2>' . t('Subtitle') . '</h2>'),
+ 'h3' => array( t('Heading'), '<h3>' . t('Subtitle three') . '</h3>'),
+ 'h4' => array( t('Heading'), '<h4>' . t('Subtitle four') . '</h4>'),
+ 'h5' => array( t('Heading'), '<h5>' . t('Subtitle five') . '</h5>'),
+ 'h6' => array( t('Heading'), '<h6>' . t('Subtitle six') . '</h6>')
+ );
+ $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' => '<code>' . check_plain($tips[$tag][1]) . '</code>', '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' => '<code>' . check_plain($entity[1]) . '</code>', '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;
-
- case 1:
- switch ($long) {
- case 0:
- return t('Lines and paragraphs break automatically.');
- case 1:
- return t('Lines and paragraphs are automatically recognized. The &lt;br /&gt; line break, &lt;p&gt; paragraph and &lt;/p&gt; close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.');
+ $output .= theme('table', $header, $rows);
+
+ $output .= '<p>' . t('Most unusual characters can be directly entered without any problems.') . '</p>';
+ $output .= '<p>' . t('If you do encounter problems, try using HTML character entities. A common example looks like &amp;amp; for an ampersand &amp; character. For a full list of entities see HTML\'s <a href="@html-entities">entities</a> page. Some of the available characters include:', array('@html-entities' => 'http://www.w3.org/TR/html4/sgml/entities.html')) . '</p>';
+
+ $entities = array(
+ array( t('Ampersand'), '&amp;'),
+ array( t('Greater than'), '&gt;'),
+ array( t('Less than'), '&lt;'),
+ array( t('Quotation mark'), '&quot;'),
+ );
+ $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' => '<code>' . check_plain($entity[1]) . '</code>', 'class' => 'type'),
+ array('data' => $entity[1], 'class' => 'get')
+ );
}
- break;
+ $output .= theme('table', $header, $rows);
+ return $output;
+ }
+
+ else {
+ return t('Allowed HTML tags: @tags', array('@tags' => $allowed_html));
+ }
+ }
+}
- case 2:
- return t('Web page addresses and e-mail addresses turn into links automatically.');
- break;
+function _filter_autop_tips($format, $long = FALSE) {
+ if ($long) {
+ return t('Lines and paragraphs are automatically recognized. The &lt;br /&gt; line break, &lt;p&gt; paragraph and &lt;/p&gt; 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.');
+ }
+}
- case 4:
- return t('No HTML tags allowed.');
- break;
+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.
*/
function filter_formats($index = NULL) {
@@ -571,7 +572,9 @@ function _filter_tips($format, $long = FALSE) {
$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);
}
}
diff --git a/modules/php/php.module b/modules/php/php.module
index 3599644..8552c15 100644
--- a/modules/php/php.module
+++ b/modules/php/php.module
@@ -78,33 +78,29 @@ function php_eval($code) {
}
/**
- * 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 &lt;?php ?&gt; tags.');
- case 1:
- $output = '<h4>' . t('Using custom PHP code') . '</h4>';
- $output .= '<p>' . 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.') . '</p>';
- $output .= '<p>' . 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.') . '</p>';
- $output .= '<p>' . t('Notes:') . '</p>';
- $output .= '<ul><li>' . t('Remember to double-check each line for syntax and logic errors <strong>before</strong> saving.') . '</li>';
- $output .= '<li>' . t('Statements must be correctly terminated with semicolons.') . '</li>';
- $output .= '<li>' . t('Global variables used within your PHP code retain their values after your script executes.') . '</li>';
- $output .= '<li>' . t('<code>register_globals</code> is <strong>turned off</strong>. If you need to use forms, understand and use the functions in <a href="@formapi">the Drupal Form API</a>.', array('@formapi' => url('http://api.drupal.org/api/group/form_api/7'))) . '</li>';
- $output .= '<li>' . t('Use a <code>print</code> or <code>return</code> statement in your code to output content.') . '</li>';
- $output .= '<li>' . t('Develop and test your PHP code using a separate test script and sample database before deploying on a production site.') . '</li>';
- $output .= '<li>' . t('Consider including your custom PHP code within a site-specific module or <code>template.php</code> file rather than embedding it directly into a post or block.') . '</li>';
- $output .= '<li>' . t('Be aware that the ability to embed PHP code within content is provided by the PHP Filter module. If this module is disabled or deleted, then blocks and posts with embedded PHP may display, rather than execute, the PHP code.') . '</li></ul>';
- $output .= '<p>' . t('A basic example: <em>Creating a "Welcome" block that greets visitors with a simple message.</em>') . '</p>';
- $output .= '<ul><li>' . t('<p>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:</p>
+ if ($long) {
+ $output = '<h4>' . t('Using custom PHP code') . '</h4>';
+ $output .= '<p>' . 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.') . '</p>';
+ $output .= '<p>' . 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.') . '</p>';
+ $output .= '<p>' . t('Notes:') . '</p>';
+ $output .= '<ul><li>' . t('Remember to double-check each line for syntax and logic errors <strong>before</strong> saving.') . '</li>';
+ $output .= '<li>' . t('Statements must be correctly terminated with semicolons.') . '</li>';
+ $output .= '<li>' . t('Global variables used within your PHP code retain their values after your script executes.') . '</li>';
+ $output .= '<li>' . t('<code>register_globals</code> is <strong>turned off</strong>. If you need to use forms, understand and use the functions in <a href="@formapi">the Drupal Form API</a>.', array('@formapi' => url('http://api.drupal.org/api/group/form_api/7'))) . '</li>';
+ $output .= '<li>' . t('Use a <code>print</code> or <code>return</code> statement in your code to output content.') . '</li>';
+ $output .= '<li>' . t('Develop and test your PHP code using a separate test script and sample database before deploying on a production site.') . '</li>';
+ $output .= '<li>' . t('Consider including your custom PHP code within a site-specific module or <code>template.php</code> file rather than embedding it directly into a post or block.') . '</li>';
+ $output .= '<li>' . t('Be aware that the ability to embed PHP code within content is provided by the PHP Filter module. If this module is disabled or deleted, then blocks and posts with embedded PHP may display, rather than execute, the PHP code.') . '</li></ul>';
+ $output .= '<p>' . t('A basic example: <em>Creating a "Welcome" block that greets visitors with a simple message.</em>') . '</p>';
+ $output .= '<ul><li>' . t('<p>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:</p>
<pre>
print t(\'Welcome visitor! Thank you for visiting.\');
</pre>') . '</li>';
- $output .= '<li>' . t('<p>To display the name of a registered user, use this instead:</p>
+ $output .= '<li>' . t('<p>To display the name of a registered user, use this instead:</p>
<pre>
global $user;
if ($user->uid) {
@@ -114,9 +110,11 @@ else {
print t(\'Welcome visitor! Thank you for visiting.\');
}
</pre>') . '</li></ul>';
- $output .= '<p>' . t('<a href="@drupal">Drupal.org</a> offers <a href="@php-snippets">some example PHP snippets</a>, 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'))) . '</p>';
- return $output;
- }
+ $output .= '<p>' . t('<a href="@drupal">Drupal.org</a> offers <a href="@php-snippets">some example PHP snippets</a>, 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'))) . '</p>';
+ return $output;
+ }
+ else {
+ return t('You may post PHP code. You should include &lt;?php ?&gt; tags.');
}
}
@@ -133,7 +131,8 @@ function php_filter_info() {
'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'
)
);
}