Changeset 703090
- Timestamp:
- 04/24/2013 09:34:00 PM (13 years ago)
- Location:
- html-cleanup
- Files:
-
- 4 edited
-
assets/screenshot-1.png (modified) (previous)
-
trunk/html-cleanup.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/settings.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
html-cleanup/trunk/html-cleanup.php
r699897 r703090 3 3 Plugin Name: HTML Cleanup 4 4 Plugin URI: https://davidlyness.com/plugins/html-cleanup 5 Description: A plugin to filter lines of outputted HTML in public pages based on predefined regular expressions.6 Version: 1. 0.15 Description: A plugin to strip out lines of HTML generated by Wordpress and other plugins based on predefined regular expressions. 6 Version: 1.1.0 7 7 Author: David Lyness 8 8 Author URI: https://davidlyness.com … … 13 13 require_once(__DIR__ . '/settings.php'); 14 14 15 // Do the actual filtering by performing regex search /replace operations15 // Do the actual filtering by performing regex search & replace operations 16 16 function html_cleanup_callback($buffer) { 17 17 $cleanupOverride = $_GET['cleanupoverride']; 18 if (!isset($_GET['cleanupoverride']) || $_GET['cleanupoverride'] !== get_option('cleanup_override')) { 19 if (get_option('blacklisted_patterns')) { 20 $badPatterns = split("\r\n", get_option('blacklisted_patterns')); 21 foreach ($badPatterns as $pattern) { 22 $buffer = preg_replace('/.*' . $pattern . '.*/', '', $buffer); 23 } 24 $buffer = preg_replace(array("/\r\n\r\n/", "/\n\n/"), array("\r\n", "\n"), $buffer); // removing lines of HTML introduces unneeded line breaks - this replace operation removes them 18 if ((!is_admin()) && ((!isset($_GET['cleanupoverride'])) || ($_GET['cleanupoverride'] !== get_option('cleanup_override'))) && (get_option('blacklisted_patterns'))) { 19 $badPatterns = split("\r\n", get_option('blacklisted_patterns')); 20 foreach ($badPatterns as $pattern) { 21 $buffer = preg_replace('/.*' . $pattern . '.*(\r*\n)*/', '', $buffer); 25 22 } 26 23 } … … 28 25 } 29 26 30 // Begin filtering content right after <head>, buffering the HTML output of the page so that it can be filtered by the html_cleanup_callback function31 add_action('wp_head', 'html_cleanup_buffer_start', 1);27 // Begin filtering content from the time this script is loaded, buffering the HTML output of the page so that it can be filtered by the html_cleanup_callback function 28 html_cleanup_buffer_start(); 32 29 function html_cleanup_buffer_start() { 33 30 ob_start("html_cleanup_callback"); … … 37 34 } 38 35 39 // End filtering right before </body>40 add_action('wp_footer', 'html_cleanup_buffer_end', 1000);36 // End filtering after entire page has been generated, and perform the necessary filtering 37 register_shutdown_function('html_cleanup_buffer_end'); 41 38 function html_cleanup_buffer_end() { 42 39 ob_end_flush(); 43 40 } 44 41 45 46 42 ?> -
html-cleanup/trunk/readme.txt
r699895 r703090 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 A llows you to strip out lines of HTMLbased on predefined regular expressions.10 A plugin to strip out lines of HTML generated by Wordpress and other plugins based on predefined regular expressions. 11 11 12 12 == Description == 13 13 14 This plugin allows you to specify patterns of HTML that will be removed from the final output. You can define such patterns as normal text (e.g. "penguin" will remove all lines in the output HTML containing "penguin") or as a regular expression (e.g. " <b>.*</b>" will remove all single lines of bold text).14 This plugin allows you to specify patterns of HTML that will be removed from the final output. You can define such patterns as normal text (e.g. "penguin" will remove all lines in the output HTML containing "penguin") or as a regular expression (e.g. "WinterIs(Coming|Here)" will remove all lines of text containing either "WinterIsComing" or "WinterIsHere"). 15 15 16 16 For more information on regular expressions, see [regular-expressions.info](http://www.regular-expressions.info). 17 17 18 If you come across any bugs in the plugin, or if you have any suggestions on how to make it better, contact me using [my website](https://davidlyness.com/contact) or use the Wordpress plugin support forums.18 If you come across any bugs in the plugin, or if you have any suggestions on how to make it better, [contact me directly](https://davidlyness.com/contact) or use the Wordpress plugin support forums. 19 19 20 20 == Installation == … … 26 26 == Screenshots == 27 27 28 1. The "Settings" page for the 'HTML Cleanup'plugin.28 1. The Settings page for the HTML Cleanup plugin. 29 29 30 30 == Changelog == 31 32 = 1.1.0 = 33 * HTML Cleanup now parses the entire page rather than just the head and body. 31 34 32 35 = 1.0.1 = -
html-cleanup/trunk/settings.php
r699310 r703090 44 44 update_option('cleanup_comment', "on"); 45 45 } 46 add_settings_field('html_cleanup_comment', 'In clude comment in pageheader?', 'text_html_cleanup_comment', 'html_cleanup', 'html_cleanup_comment_settings');46 add_settings_field('html_cleanup_comment', 'Insert HTML comment in header?', 'text_html_cleanup_comment', 'html_cleanup', 'html_cleanup_comment_settings'); 47 47 } 48 48 … … 70 70 // Output the descriptive text for the plugin's override options on the "Settings" page 71 71 function text_html_cleanup_override_settings() { 72 echo "<p>You can provide a string of characters that can be specified as a URL parameter to temporarily disable <i>HTML Cleanup</i>'s activity. A string is automatically generated for you- save a blank value in this field to re-generate the override string. It is recommended that you choose a string of characters that is not easily guessable - otherwise visitors to your site could guess the pattern and see all the lines of HTML you are hiding.</p>";72 echo "<p>You can provide a string of characters that, if specified as a URL parameter, will temporarily disable HTML Cleanup's activity. (This is useful for viewing your unfiltered page without disabling HTML Cleanup.) A string is automatically generated for you below - save a blank value in this field to re-generate the override string. It is recommended that you choose a string of characters that is not easily guessable - otherwise visitors to your site could guess the pattern and see all the lines of HTML you are hiding.</p>"; 73 73 $overrideLink = home_url() . "?cleanupoverride=" . get_option('cleanup_override'); 74 74 echo "<p><b>Usage</b>: <a href='" . $overrideLink . "'>" . $overrideLink . "</a></p>"; 75 echo "<p>";76 75 } 77 76 … … 83 82 // Output the descriptive text for the plugin's comment options on the "Settings" page 84 83 function text_html_cleanup_comment_settings() { 85 echo "<p>By default, the <i>HTML Cleanup</i> plugininserts a comment into the header of public pages. This allows you to test the filtering capabilities of the plugin - try specifying <b>3UYbKPTEsahhppWL</b> as a blacklisted pattern above to remove it.</p>";84 echo "<p>By default, HTML Cleanup inserts a comment into the header of public pages. This allows you to test the filtering capabilities of the plugin - try specifying <b>3UYbKPTEsahhppWL</b> as a blacklisted pattern above to remove it.</p>"; 86 85 echo "<p>Once you're happy with how the plugin works, you can uncheck the box below to turn the comment off completely.</p>"; 87 86 }
Note: See TracChangeset
for help on using the changeset viewer.