Plugin Directory

Changeset 703090


Ignore:
Timestamp:
04/24/2013 09:34:00 PM (13 years ago)
Author:
davidlyness
Message:

Committing v1.1.0

Location:
html-cleanup
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • html-cleanup/trunk/html-cleanup.php

    r699897 r703090  
    33Plugin Name: HTML Cleanup
    44Plugin 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.1
     5Description: A plugin to strip out lines of HTML generated by Wordpress and other plugins based on predefined regular expressions.
     6Version: 1.1.0
    77Author: David Lyness
    88Author URI: https://davidlyness.com
     
    1313require_once(__DIR__ . '/settings.php');
    1414
    15 // Do the actual filtering by performing regex search / replace operations
     15// Do the actual filtering by performing regex search & replace operations
    1616function html_cleanup_callback($buffer) {
    1717    $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);
    2522        }
    2623    }
     
    2825}
    2926
    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 function
    31 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
     28html_cleanup_buffer_start();
    3229function html_cleanup_buffer_start() {
    3330    ob_start("html_cleanup_callback");
     
    3734}
    3835
    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
     37register_shutdown_function('html_cleanup_buffer_end');
    4138function html_cleanup_buffer_end() {
    4239    ob_end_flush();
    4340}
    4441
    45 
    4642?>
  • html-cleanup/trunk/readme.txt

    r699895 r703090  
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
    10 Allows you to strip out lines of HTML based on predefined regular expressions.
     10A plugin to strip out lines of HTML generated by Wordpress and other plugins based on predefined regular expressions.
    1111
    1212== Description ==
    1313
    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).
     14This 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").
    1515
    1616For more information on regular expressions, see [regular-expressions.info](http://www.regular-expressions.info).
    1717
    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.
     18If 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.
    1919
    2020== Installation ==
     
    2626== Screenshots ==
    2727
    28 1. The "Settings" page for the 'HTML Cleanup' plugin.
     281. The Settings page for the HTML Cleanup plugin.
    2929
    3030== Changelog ==
     31
     32= 1.1.0 =
     33* HTML Cleanup now parses the entire page rather than just the head and body.
    3134
    3235= 1.0.1 =
  • html-cleanup/trunk/settings.php

    r699310 r703090  
    4444        update_option('cleanup_comment', "on");
    4545    }
    46     add_settings_field('html_cleanup_comment', 'Include comment in page header?', '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');
    4747}
    4848
     
    7070// Output the descriptive text for the plugin's override options on the "Settings" page
    7171function 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>";
    7373    $overrideLink = home_url() . "?cleanupoverride=" . get_option('cleanup_override');
    7474    echo "<p><b>Usage</b>: <a href='" . $overrideLink . "'>" . $overrideLink . "</a></p>";
    75     echo "<p>";
    7675}
    7776
     
    8382// Output the descriptive text for the plugin's comment options on the "Settings" page
    8483function text_html_cleanup_comment_settings() {
    85     echo "<p>By default, the <i>HTML Cleanup</i> plugin 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>";
     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>";
    8685    echo "<p>Once you're happy with how the plugin works, you can uncheck the box below to turn the comment off completely.</p>";
    8786}
Note: See TracChangeset for help on using the changeset viewer.