Make WordPress Core


Ignore:
Timestamp:
11/19/2006 07:56:05 AM (19 years ago)
Author:
ryan
Message:

Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes #986

File:
1 edited

Legend:

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

    r4451 r4495  
    6666    $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
    6767    // Space things out a little
    68     $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "\n$1", $pee); 
     68    $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "\n$1", $pee);
    6969    $pee = preg_replace('!(</(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])>)!', "$1\n\n", $pee);
    70     $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 
     70    $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
    7171    $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    72     $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end 
    73     $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 
     72    $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
     73    $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
    7474    $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
    7575    $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
     
    7777    $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
    7878    $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "$1", $pee);
    79     $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); 
     79    $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee);
    8080    if ($br) {
    8181        $pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", "<WPPreserveNewline />", "\\0")', $pee);
     
    8787    $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' ", $pee);
    8888
    89     return $pee; 
     89    return $pee;
    9090}
    9191
     
    127127
    128128function utf8_uri_encode( $utf8_string ) {
    129   $unicode = '';       
    130   $values = array();
    131   $num_octets = 1;
    132        
    133   for ($i = 0; $i < strlen( $utf8_string ); $i++ ) {
    134 
    135     $value = ord( $utf8_string[ $i ] );
    136            
    137     if ( $value < 128 ) {
    138       $unicode .= chr($value);
    139     } else {
    140       if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
    141                
    142       $values[] = $value;
    143      
    144       if ( count( $values ) == $num_octets ) {
    145     if ($num_octets == 3) {
    146       $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
    147     } else {
    148       $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
    149     }
    150 
     129    $unicode = '';
    151130    $values = array();
    152131    $num_octets = 1;
    153       }
    154     }
    155   }
    156 
    157   return $unicode;   
     132
     133    for ($i = 0; $i < strlen( $utf8_string ); $i++ ) {
     134
     135        $value = ord( $utf8_string[ $i ] );
     136
     137        if ( $value < 128 ) {
     138            $unicode .= chr($value);
     139        } else {
     140            if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
     141
     142            $values[] = $value;
     143
     144            if ( count( $values ) == $num_octets ) {
     145    if ($num_octets == 3) {
     146        $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
     147    } else {
     148        $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
     149    }
     150
     151    $values = array();
     152    $num_octets = 1;
     153            }
     154        }
     155    }
     156
     157    return $unicode;
    158158}
    159159
     
    340340}
    341341
    342 function convert_chars($content, $flag = 'obsolete') { 
     342function convert_chars($content, $flag = 'obsolete') {
    343343    // Translation of invalid Unicode references range to valid range
    344344    $wp_htmltranswinuni = array(
     
    406406/*
    407407 balanceTags
    408  
     408
    409409 Balances Tags of string using a modified stack.
    410  
     410
    411411 @param text      Text to be balanced
    412412 @return          Returns balanced text
     
    415415 @date            November 4, 2001
    416416 @license         GPL v2.0
    417  @notes           
    418  @changelog       
     417 @notes
     418 @changelog
    419419 ---  Modified by Scott Reilly (coffee2code) 02 Aug 2004
    420             1.2  ***TODO*** Make better - change loop condition to $text
    421             1.1  Fixed handling of append/stack pop order of end text
    422                   Added Cleaning Hooks
    423             1.0  First Version
     420                        1.2  ***TODO*** Make better - change loop condition to $text
     421                        1.1  Fixed handling of append/stack pop order of end text
     422                                    Added Cleaning Hooks
     423                        1.0  First Version
    424424*/
    425425function balanceTags($text, $is_comment = 0, $force = false) {
     
    447447            $tag = strtolower(substr($regex[1],1));
    448448            // if too many closing tags
    449             if($stacksize <= 0) { 
     449            if($stacksize <= 0) {
    450450                $tag = '';
    451451                //or close to be safe $tag = '/' . $tag;
     
    504504        $newtext .= substr($text,0,$i) . $tag;
    505505        $text = substr($text,$i+$l);
    506     } 
     506    }
    507507
    508508    // Clear Tag Queue
     
    553553
    554554function trailingslashit($string) {
    555     if ( '/' != substr($string, -1)) {
    556         $string .= '/';
    557     }
    558     return $string;
     555        if ( '/' != substr($string, -1)) {
     556                $string .= '/';
     557        }
     558        return $string;
    559559}
    560560
     
    572572function stripslashes_deep($value)
    573573{
    574   $value = is_array($value) ?
    575               array_map('stripslashes_deep', $value) :
    576               stripslashes($value);
    577 
    578   return $value;
     574    $value = is_array($value) ?
     575                            array_map('stripslashes_deep', $value) :
     576                            stripslashes($value);
     577
     578    return $value;
    579579}
    580580
     
    732732}
    733733
    734 function human_time_diff( $from, $to = '' ) {     
     734function human_time_diff( $from, $to = '' ) {
    735735    if ( empty($to) )
    736736        $to = time();
     
    746746        if ($hours <= 1)
    747747            $since = __('1 hour');
    748         else 
     748        else
    749749            $since = sprintf( __('%s hours'), $hours );
    750750    } elseif ($diff >= 86400) {
Note: See TracChangeset for help on using the changeset viewer.