WordPress.org

Make WordPress Core

Changeset 25055


Ignore:
Timestamp:
08/20/2013 06:07:50 AM (8 years ago)
Author:
dd32
Message:

Remove some PHP4-ness from the antispambot() function, and update it to match some modern coding standards. Props hakre and crrobi01 for initial patches. Fixes #16754

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r25054 r25055  
    14841484 * @since 0.71
    14851485 *
    1486  * @param string $emailaddy Email address.
    1487  * @param int $mailto Optional. Range from 0 to 1. Used for encoding.
     1486 * @param string $email_address Email address.
     1487 * @param int $extra_entrpoy Optional. Range from 0 to 1. Used for encoding.
    14881488 * @return string Converted email address.
    14891489 */
    1490 function antispambot($emailaddy, $mailto=0) {
    1491     $emailNOSPAMaddy = '';
    1492     srand ((float) microtime() * 1000000);
    1493     for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {
    1494         $j = floor(rand(0, 1+$mailto));
    1495         if ($j==0) {
    1496             $emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';';
    1497         } elseif ($j==1) {
    1498             $emailNOSPAMaddy .= substr($emailaddy,$i,1);
    1499         } elseif ($j==2) {
    1500             $emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);
     1490function antispambot( $email_address, $extra_entropy = 0 ) {
     1491    $email_no_spam_address = '';
     1492    for ( $i = 0; $i < strlen( $email_address ); $i++ ) {
     1493        $j = rand( 0, 1 + $extra_entropy );
     1494        if ( $j == 0 ) {
     1495            $email_no_spam_address .= '&#' . ord( substr( $email_address, $i, 1 ) ) . ';';
     1496        } elseif ( $j == 1 ) {
     1497            $email_no_spam_address .= substr( $email_address, $i, 1 );
     1498        } elseif ( $j == 2 ) {
     1499            $email_no_spam_address .= '%' . zeroise( dechex( ord( substr( $email_address, $i, 1 ) ) ), 2 );
    15011500        }
    15021501    }
    1503     $emailNOSPAMaddy = str_replace('@','&#64;',$emailNOSPAMaddy);
    1504     return $emailNOSPAMaddy;
     1502
     1503    $email_no_spam_address = str_replace( '@', '&#64;', $email_no_spam_address );
     1504
     1505    return $email_no_spam_address;
    15051506}
    15061507
Note: See TracChangeset for help on using the changeset viewer.