Make WordPress Core

Ticket #6297: balance-tags-with-more-r7392.patch

File balance-tags-with-more-r7392.patch, 3.2 KB (added by tellyworth, 17 years ago)
  • wp-includes/default-filters.php

     
    6969}
    7070
    7171// Places to balance tags on input
    72 $filters = array('content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content');
     72$filters = array('excerpt_save_pre', 'comment_save_pre', 'pre_comment_content');
    7373foreach ( $filters as $filter ) {
    7474        add_filter( $filter, 'balanceTags', 50);
    7575}
     76add_filter( 'content_save_pre', 'balanceTagsWithPages', 50 );
    7677
    7778// Format strings for display.
    7879$filters = array('comment_author', 'term_name', 'link_name', 'link_description',
  • wp-includes/post.php

     
    124124 * @param string $post {@internal Missing Description}}
    125125 * @return array {@internal Missing Description}}
    126126 */
    127 function get_extended($post) {
     127function get_extended($post, $strip_whitespace = true) {
    128128        //Match the new style more links
    129129        if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) {
    130130                list($main, $extended) = explode($matches[0], $post, 2);
     131                $delim = '<!--more' . $matches[1] . '-->';
    131132        } else {
    132133                $main = $post;
    133134                $extended = '';
     135                $delim = '';
    134136        }
    135137
    136138        // Strip leading and trailing whitespace
    137         $main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main);
    138         $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended);
     139        if ( $strip_whitespace ) {
     140                $main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main);
     141                $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended);
     142        }
     143       
     144        return array('main' => $main, 'extended' => $extended, 'delimiter' => $delim);
     145}
    139146
    140         return array('main' => $main, 'extended' => $extended);
     147/**
     148 * split_nextpage() - split post text into pages separated by <!--nextpage-->
     149 *
     150 * {@internal Missing Long Description}}
     151 *
     152 * @package WordPress
     153 * @subpackage Post
     154 * @since 2.5
     155 *
     156 * @param string $post {@internal Missing Description}}
     157 * @return array {@internal Missing Description}}
     158 */
     159function split_nextpage($text, $include_delim = false) {
     160        $flags = 0;
     161        if ( $include_delim )
     162                $flags = PREG_SPLIT_DELIM_CAPTURE;
     163
     164        return preg_split('/(<!--nextpage-->)/', $text, -1, $flags);
    141165}
    142166
    143167/**
  • wp-includes/formatting.php

     
    436436        return force_balance_tags( $text );
    437437}
    438438
     439// like balanceTags, but separately balance each portion (as split by the more and nextpage tags)
     440function balanceTagsWithPages( $text, $force = false ) {
     441        if ( !$force && get_option('use_balanceTags') == 0 )
     442                return $text;
     443
     444        $parts = get_extended( $text, false );
     445
     446        $slices = split_nextpage( $parts['main'], true );
     447        if ( $parts['delimiter'] )
     448                $slices[] = $parts['delimiter'];
     449        $slices = array_merge( $slices, split_nextpage( $parts['extended'], true ) );
     450
     451        $out = '';
     452        foreach ( $slices as $slice )
     453                $out .= force_balance_tags($slice);
     454
     455        return $out;
     456}
     457
    439458/*
    440459 force_balance_tags
    441460