Opened 19 years ago
Closed 19 years ago
#2444 closed defect (bug) (fixed)
Smilies don't parse properly in comments and posts
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 2.1 | Priority: | normal |
Severity: | minor | Version: | 2.0.2 |
Component: | Administration | Keywords: | smilies smiley has-patch |
Focuses: | Cc: |
Description
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)
Change History (10)
#2
@
19 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
@
19 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
@
19 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
@
19 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; }
#6
@
19 years ago
- Keywords has-patch added; rich text editor removed
Added a patch to make smilies also appear on the start of a line.
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: