Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#2444 closed defect (bug) (fixed)

Smilies don't parse properly in comments and posts

Reported by: ecb29 Owned by:
Milestone: 2.1 Priority: normal
Severity: minor Version: 2.0.2
Component: Administration Keywords: smilies smiley has-patch
Focuses: Cc:


If you create a post consisting of :D :D :D, the first smiley will not parse properly, and wordpress will not allow you to add any whitespace to correct it...

Attachments (2)

2444.diff (2.9 KB) - added by Nazgul 14 years ago.
2444b.diff (2.9 KB) - added by Nazgul 14 years ago.

Download all attachments as: .zip

Change History (10)

#1 @skeltoac
14 years ago

  • Milestone changed from 2.0 to 2.5

The leading space is required whether at the beginning of a post or right after an HTML tag. WordPress will trim the post of leading spaces but you can still start a post with a smiley like so:

<span> :D :D :D</span>

#2 @wezz6400
14 years ago

  • Version changed from 2.0 to 2.0.2

This also goes for comments. Whenever someone starts a line with a smiley it won't get parsed. Someone trying to post a comment on one of my weblogs got confused.

#3 @skeltoac
14 years ago

The emoticon filter and lists will have to be updated to use (?:|\s) instead of the leading space, and a whole lot of preg_replacing will be done. It's an expensive change.

#4 @Nitallica
14 years ago

This has been a bug for a while. I've learned to live with it, but it is a little annoying.

Incidentally, bug #1889 is a duplicate of this bug.

#5 @_ck_
14 years ago

  • Milestone changed from 2.5 to 2.1
  • Summary changed from Smilies don't parse to Smilies don't parse properly in comments and posts

Here's my solution that I came up with to fix smilies in posts and comments. I call it "smarter smilies" :) I don't think the convert_smilies function can be replaced (easily) but you can hack/replace the code with mine.

I am far from a php "expert" but I think the overhead is miminal and fixes the issue not only with default smilies but any smilies set from "more smilies" etc. which may have inconsistant white-space. My code solves smilie detection at the start or end of lines and fixes any padding they may be stored with.

I don't know how / don't care to figure out how to make a diff so I'll leave that to greater minds (and any code optimization along the way.

function prepSmilies($string) {return "/(\s|^)".quotemeta(trim($string))."(\s|$)/";}

function convert_smilies($text) {
	global $wp_smiliessearch, $wp_smiliesreplace;
    $output = '';
	if (get_settings('use_smilies')) {
	$prep_search = array_map('prepSmilies', $wp_smiliessearch);	
		// HTML loop taken from texturize function, could possible be consolidated
		$textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
		$stop = count($textarr);// loop stuff
		for ($i = 0; $i < $stop; $i++) {
			$content = $textarr[$i];			
			if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag
				 // $content = str_replace($wp_smiliessearch, $wp_smiliesreplace, $content);								 
				 $content = preg_replace($prep_search, $wp_smiliesreplace, $content);	
			$output .= $content;
	} else {
		// return default text.
		$output = $text;
	return $output;

14 years ago

#6 @Nazgul
14 years ago

  • Keywords has-patch added; rich text editor removed

Added a patch to make smilies also appear on the start of a line.

14 years ago

#7 @Nazgul
14 years ago

Updated my patch to fix an issue where smileys where at the end of a line.

I also included a fix for #1279, as that needs these changes for an easy fix.

#8 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4283]) Smiley parsing fixes from Nazgul. fixes #2444 #1279

Note: See TracTickets for help on using tickets.