[wp-trac] Re: [WordPress Trac] #2444: Smilies don't parse properly
in comments and posts
WordPress Trac
wp-trac at lists.automattic.com
Fri Aug 4 18:11:10 GMT 2006
#2444: Smilies don't parse properly in comments and posts
---------------------------------------------+------------------------------
Reporter: ecb29 | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone: 2.1
Component: Administration | Version: 2.0.2
Severity: minor | Resolution:
Keywords: smilies smiley rich text editor |
---------------------------------------------+------------------------------
Changes (by _ck_):
* milestone: 2.5 => 2.1
* summary: Smilies don't parse => Smilies don't parse properly in
comments and posts
Comment:
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;
}
}}}
----
--
Ticket URL: <http://trac.wordpress.org/ticket/2444>
WordPress Trac <http://wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list