e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

emoticon/smiley in chatbox #4265

Open ericc-dream opened 3 years ago

ericc-dream commented 3 years ago

Bug Description

I'm using the chatbox2 which is a (old) replacement for the default chatbox that I have updated to work with e107 v2 I realized a few days ago that : when I put a single emoticon/smiley in a message, it's works ok, the bbcode is replaced by the expected image but when I add some text after, the first emoticon isn't replaced and its bbcode is displayed

How to Reproduce

I think that the problem exist also with the default chat, so create a new message with: an emoticon and " ." and send it

Expected Behavior

to have the bbcode of the emoticon replaced by its image

Additional Information

The issue is in ~/e107_handlers/e_parse_class.php

    function filterEmotes($text)
    {
        if(empty($text))
        {
            return '';
        }
        if(!empty($this->singleSearch) && (strlen($text) < 12) && in_array($text, $this->singleSearch)) // just one emoticon with no space, line-break or html tags around it.
        {
            return str_replace($this->singleSearch,$this->singleReplace,$text);
        }
        return str_replace($this->search, $this->replace, $text);
    }

array "$this->singleSearch" contain just the list of bbcode array "$this->search" contain some variations of the bbcode : with a space, a ">" or a "newline" (\n) in front, but not the bbcode alone, so when the emoticon is at the beginning of the message with some characters after, this array is used and the bbcode isn't replaced

Proposed solution

        $text = " " . $text;
        return trim(str_replace($this->search, $this->replace, $text));

2° add the bbcode alone in array "$this->search" 3° don't use "$this->search" but "$this->singleSearch" , only ..... but there is probably a reason for the "formatting" of array "$this->search" that I don't see !

Moc commented 2 years ago

Related https://github.com/e107inc/e107/issues/2059