php warnings from emoji functions

SteveX
SteveX
@ultrajam
10 years ago
2,589 posts
We are getting many writes of the same two warnings to the error log:
Quote: PHP Warning: preg_match_all() expects parameter 2 to be string, array given in /......./modules/jrCore-release-5.3.4/lib/util.php on line 1200
Quote:PHP Warning: preg_match_all() expects parameter 2 to be string, array given in /......./modules/jrCore-release-5.3.4/lib/util.php on line 1191
Do you see these too?

I'm wondering if these are from editor fields in my custom modules.

Thanks


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 07/17/16 02:41:25AM
michael
@michael
10 years ago
7,839 posts
not seeing them, but would chuck a fdebug() in there at the top of that function to see where its coming from.

CURRENTLY:
function jrCore_strip_emoji($string, $replace = true)
{
    $pattern = '/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1FFFF}][\x{FE00}-\x{FEFF}]?/u';
    if ($replace) {
        if (preg_match_all($pattern, $string, $_match)) {

add in
function jrCore_strip_emoji($string, $replace = true)
{
if(is_array($string)){
$_debug = array(
  'what' => "trying to figure out what is passing an array in here.....hmmmm...."
 '$string' => $string
);
fdebug($_debug);
}

    $pattern = '/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1FFFF}][\x{FE00}-\x{FEFF}]?/u';
    if ($replace) {
        if (preg_match_all($pattern, $string, $_match)) {


Then potter around like you normally do until the error triggers again. That should provide some hints as to where its coming from in the debug_log.

I'll keep an eye out for it here too. (cleared my logs and will watch them.)
SteveX
SteveX
@ultrajam
10 years ago
2,589 posts
Thanks Michael, I'll give that a try tomorrow.

I'm seeing about 200 per minute so if you aren't seeing them they must be caused by our custom modules.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
SteveX
SteveX
@ultrajam
10 years ago
2,589 posts
So in the debug log, I get a wide range of different values for $string including the following

A pair of arrays: $_conf and $_mods
All language strings
The $_user array
The html for the debug log ACP page
empty

The log generally reads (2016-04-14T09:22:40+01:00.0.51098300 : 0.035)-(mem: 1310720)-(pid: 20210)-(ip: 164.11.187.83)-(user: )-(uri: GET /core/debug_log)
Sometimes the username is there but usually not.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
SteveX
SteveX
@ultrajam
10 years ago
2,589 posts
It looks like jrCore_replace_emoji is run twice each time I click on the Error Log tab or the Debug log tab.

The first value is an array containing $_conf and $_mods, and the second value is the $_user array.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
michael
@michael
10 years ago
7,839 posts
looking now. thanks.
michael
@michael
10 years ago
7,839 posts
The full function for jrCore_replace_emoji() is this:
function jrCore_replace_emoji($string)
{
    if (is_string($string) && preg_match_all('/!!emoji!!([0-9]*)!!emoji!!/i', $string, $_match)) {
        $_id = array();
        foreach ($_match[0] as $e) {
            $_id[] = (int) str_ireplace('!!emoji!!', '', $e);
        }
        if (count($_id) > 0) {
            $tbl = jrCore_db_table_name('jrCore', 'emoji');
            $req = "SELECT CONCAT('!!emoji!!', emoji_id, '!!emoji!!') AS emoji_id, emoji_value FROM {$tbl} WHERE emoji_id IN(" . implode(',', $_id) . ")";
            $_rt = jrCore_db_query($req, 'emoji_id', false, 'emoji_value', false, null, false);
            if ($_rt && is_array($_rt)) {
                $string = str_ireplace(array_keys($_rt), $_rt, $string);
            }
        }
    }
    return $string;
}
It only runs if the $string is a string.

So the internals shouldn't be running at all. Think you have your php.ini warnings set to show.

I can move the two phrases out, so the string check is a wrapper and the preg match only fires if its a string though. It will be in the next release.

Thanks.
michael
@michael
10 years ago
7,839 posts
Next version of that function will read:
function jrCore_replace_emoji($string)
{
    if (is_string($string)) {
        if (preg_match_all('/!!emoji!!([0-9]*)!!emoji!!/i', $string, $_match)) {
            $_id = array();
            foreach ($_match[0] as $e) {
                $_id[] = (int) str_ireplace('!!emoji!!', '', $e);
            }
            if (count($_id) > 0) {
                $tbl = jrCore_db_table_name('jrCore', 'emoji');
                $req = "SELECT CONCAT('!!emoji!!', emoji_id, '!!emoji!!') AS emoji_id, emoji_value FROM {$tbl} WHERE emoji_id IN(" . implode(',', $_id) . ")";
                $_rt = jrCore_db_query($req, 'emoji_id', false, 'emoji_value', false, null, false);
                if ($_rt && is_array($_rt)) {
                    $string = str_ireplace(array_keys($_rt), $_rt, $string);
                }
            }
        }
    }

    return $string;
}
Check that its a string before passing it to preg_match_all()
SteveX
SteveX
@ultrajam
10 years ago
2,589 posts
Thanks Michael :)

FYI, looks like you have a different version of that function to me. My jrCore 5.3.4 function has no is_string check.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
michael
@michael
10 years ago
7,839 posts
You'll have one too as soon as the next core is released ;)
SteveX
SteveX
@ultrajam
10 years ago
2,589 posts
I look forward to that, everybody loves string checks ;)

The Goodies: Everybody loves string! clip


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

Tags