WordPress.org

Ready to get started?Download WordPress

Forums

better convert_smilies routine? (5 posts)

  1. _ck_
    Member
    Posted 7 years ago #

    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!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

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

  3. _ck_
    Member
    Posted 7 years ago #

    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!

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

    http://lists.automattic.com/mailman/listinfo/wp-hackers

    Or to submit code to the project:

    http://trac.wordpress.org/

  5. _ck_
    Member
    Posted 7 years ago #

    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"
    http://www.coffee2code.com/archives/2005/03/29/plugin-preserve-code-formatting/

Topic Closed

This topic has been closed to new replies.

About this Topic