Make WordPress Core


Ignore:
Timestamp:
11/15/2013 02:45:39 AM (11 years ago)
Author:
wonderboymusic
Message:

Don't place smilies inside of pre or code tags. Don't skip smilie after a smilie with an 8 in it. Fix regular expression used for smiley translations to work when there is only one registered emoticon.

Props solarissmoke, soulseekah, mdbitz, yonasy. ht to mdbitz for the Unit Tests and a comprehensive patch.
Fixes #16448, #20124, #25303.

File:
1 edited

Legend:

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

    r26122 r26191  
    17941794 * @return string Converted content with text smilies replaced with images.
    17951795 */
    1796 function convert_smilies($text) {
     1796function convert_smilies( $text ) {
    17971797    global $wp_smiliessearch;
    17981798    $output = '';
    1799     if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) {
     1799    if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
    18001800        // HTML loop taken from texturize function, could possible be consolidated
    1801         $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
    1802         $stop = count($textarr);// loop stuff
    1803         for ($i = 0; $i < $stop; $i++) {
     1801        $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
     1802        $stop = count( $textarr );// loop stuff
     1803
     1804        // Ignore proessing of specific tags
     1805        $tags_to_ignore = 'code|pre|style|script|textarea';
     1806        $ignore_block_element = '';
     1807
     1808        for ( $i = 0; $i < $stop; $i++ ) {
    18041809            $content = $textarr[$i];
    1805             if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag
    1806                 $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content);
     1810
     1811            // If we're in an ignore block, wait until we find its closing tag
     1812            if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) )  {
     1813                $ignore_block_element = $matches[1];
    18071814            }
     1815
     1816            // If it's not a tag and not in ignore block
     1817            if ( '' ==  $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
     1818                $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
     1819            }
     1820
     1821            // did we exit ignore block
     1822            if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content )  {
     1823                $ignore_block_element = '';
     1824            }
     1825
    18081826            $output .= $content;
    18091827        }
Note: See TracChangeset for help on using the changeset viewer.