Support » Plugins » better convert_smilies routine?

  • I was wondering if anyone has already attempted to make better convert_smilies code before I dive into it (in formatting.php for v2.1) WP’s current code is rather weak but at least it checks for tags.

    There is a wide variance in how people try to pad spaces before and after a smiley, especially in the “more smilies” package.

    What annoys me is if someone tries to leave a smilie at the start or end of the comment without whitespace it will fail. It’s just not natural human instinct to put a space before (or after) if not “needed”.

    With regex it’s easy to do compares like [$|\s] but I have to study the function first to see if that’s acceptable.

    Some programs like Vbulletin seem to do smilies much better, so before I waste alot of time duplicating someone’s effort, is there anything else already out there?

    Thanks for any feedback!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    You can edit the characters that make the smilies by editing vars.php. Leading spaces and all.

    No I wanted something more universal for the more smilies plugin etc. where the smilies templates can vary widely with whitespace.

    Plus with stripped whitespace you have to be more careful about replaements so you don’t trash someones code or other weird comment.

    I think I came up with something with only a slight performance hit. I’m an amatuer so I’ll need a php pro to tell me what they think.

    add this before/changed to convert_smilies

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

    function convert_smilies($text) {
    global $wp_smiliessearch, $wp_smiliesreplace;
    $prep_search = array_map('prepSmilies', $wp_smiliessearch);

    and then change the content replacement call to

    $content = preg_replace($prep_search, $wp_smiliesreplace, $content);

    seems to test really well for me. If a user manually types a smilie without whitespace before or after it at the start or end of a line, it still works. Otherwise the insert smilie clicks still insert the spaces before and after for best formatting.

    I don’t see where the default routine skips formatting between “code” tags??? If that is missing it needs to be added!

    Les Bessant


    keeper of the Tiggers

    Probably the best place to discuss this is the wp-hackers mailing list:

    Or to submit code to the project:

    Thanks for the suggestion, I didn’t even know they existed. But I absolutely detest mailing lists in this day and age. That’s what forums were invented for! Mailing lists are good for one-way announcements…

    I will attempt to submit the suggestion to trac though.

    I found a nice plugin that handles “code” and “pre” rather well and deactivates the smilies so it solves all “preserve code formatting”

    Plugin: Preserve Code Formatting

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘better convert_smilies routine?’ is closed to new replies.