WordPress.org

Plugin Directory

Changeset 449619


Ignore:
Timestamp:
10/10/11 20:03:54 (3 years ago)
Author:
sirzooro
Message:

fix: remove plain urls which starts from www

Location:
comments-cleaner/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • comments-cleaner/trunk/comments-cleaner.php

    r443013 r449619  
    55Description: This plugin removes all HTML tags, BBCode tags and links from added comments. 
    66Author: Daniel Frużyński 
    7 Version: 1.2 
     7Version: 1.3 
    88Author URI: http://www.poradnik-webmastera.com/ 
    99Text Domain: comments-cleaner 
     
    9595            get_option( 'comcln_remove_bbcode_old' ), 
    9696            get_option( 'comcln_remove_links_old' ) ); 
     97    } 
     98     
     99    // These functions are modified copies of WP's make_clickable() and its helper functions 
     100    // Callback to remove URI match. 
     101    function _remove_url_cb( $matches ) { 
     102        $url = $matches[2]; 
     103        $suffix = ''; 
     104         
     105        /** Include parentheses in the URL only if paired **/ 
     106        while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) { 
     107            $suffix = strrchr( $url, ')' ) . $suffix; 
     108            $url = substr( $url, 0, strrpos( $url, ')' ) ); 
     109        } 
     110         
     111        $url = esc_url($url); 
     112        if ( empty($url) ) 
     113            return $matches[0]; 
     114         
     115        return $matches[1] . $suffix; 
     116    } 
     117    // Callback to remove URL match. 
     118    function _remove_web_ftp_cb( $matches ) { 
     119        $ret = ''; 
     120        $dest = $matches[2]; 
     121        $dest = 'http://' . $dest; 
     122        $dest = esc_url($dest); 
     123        if ( empty($dest) ) 
     124            return $matches[0]; 
     125         
     126        // removed trailing [.,;:)] from URL 
     127        if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) { 
     128            $ret = substr($dest, -1); 
     129            $dest = substr($dest, 0, strlen($dest)-1); 
     130        } 
     131        return $matches[1] . $ret; 
     132    } 
     133    // Callback to remove email address match. 
     134    function _remove_email_cb( $matches ) { 
     135        return $matches[1]; 
     136    } 
     137    // Remove plaintext URIs. 
     138    function remove_plaintext_links( $ret ) { 
     139        $ret = ' ' . $ret; 
     140        // in testing, using arrays here was found to be faster 
     141        $save = @ini_set('pcre.recursion_limit', 10000); 
     142        $retval = preg_replace_callback('#(?<!=[\'"])(?<=[*\')+.,;:!&$\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#%~/?@\[\]-]{1,2000}|[\'*(+.,;:!=&$](?![\b\)]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', array( &$this, '_remove_url_cb' ), $ret); 
     143        if ( !is_null( $retval ) ) 
     144            $ret = $retval; 
     145        @ini_set('pcre.recursion_limit', $save); 
     146        $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', array( &$this, '_remove_web_ftp_cb' ), $ret); 
     147        $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', array( &$this, '_remove_email_cb' ), $ret); 
     148        // this one is not in an array because we need it to run last, for cleanup of accidental links within links 
     149        $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret); 
     150        $ret = trim($ret); 
     151        return $ret; 
    97152    } 
    98153     
     
    113168            // Remove plain text links 
    114169            if ( $remove_links ) { 
    115                 $text = preg_replace( '#https?://[^\s]+#i', '', $text ); 
     170                $text = $this->remove_plaintext_links( $text ); 
    116171            } 
    117172        } while ( $text_ori != $text ); 
  • comments-cleaner/trunk/readme.html

    r443015 r449619  
    33<head>   
    44<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
    5 <title>Comments Cleaner 1.2 Readme</title> 
     5<title>Comments Cleaner 1.3 Readme</title> 
    66</head> 
    77<body> 
    8 <h1>Comments Cleaner 1.2 Readme</h1> 
     8<h1>Comments Cleaner 1.3 Readme</h1> 
    99<p>This plugin removes all HTML tags, BBCode tags and links from added comments.</p> 
    1010<p><b>Plugin Homepage:</b> <a href="http://www.poradnik-webmastera.com/projekty/comments_cleaner/">Comments Cleaner</a></p> 
     
    3333 
    3434<h2>Changelog</h2> 
     35<p>1.3</p> 
     36<ul> 
     37<li>Fix: WP makes clickable URLs which starts from &quot;www&quot; - remove them too</li> 
     38</ul> 
    3539<p>1.2</p> 
    3640<ul> 
  • comments-cleaner/trunk/readme.txt

    r443015 r449619  
    44Requires at least: 2.7 
    55Tested up to: 3.2.9 
    6 Stable tag: 1.2 
     6Stable tag: 1.3 
    77 
    88This plugin removes all HTML tags, BBCode tags and links from added comments (including link to author's website) 
     
    3232 
    3333== Changelog == 
     34 
     35= 1.3 = 
     36* Fix: WP makes clickable URLs which starts from "www" - remove them too 
    3437 
    3538= 1.2 = 
Note: See TracChangeset for help on using the changeset viewer.