Page 1 of 1

[freetag] constantly generates PHP warning in the log

Posted: Thu Jul 10, 2014 5:32 am
by wesley
While troubleshooting for a fatal error caused by SPARTACUS (for some reason, the php file was slightly corrupted), I noticed another string of errors stemming from the freetag plugin in the Apache server log:

Code: Select all

PHP Warning: explode() expects parameter 2 to be string, array given in (path)/serendipity_event_freetag.php on line 1037, referer: (site)/plugin/tag/(tag name)/
This seems to be generated quite often, but not always when a page is loaded.
Looking at the code, it seems to be related to the line that goes like this:

Code: Select all

if (!empty($this->tags['show'])) {
    if (is_array($this->tags['show'])) {
        $showtag = array_map('serendipity_db_escape_string', $this->tags['show']);
    } else {
        $showtag = serendipity_db_escape_string($this->tags['show']);
    }
} else if (!empty($serendipity['GET']['tag'])) {
    $showtag = serendipity_db_escape_string(urldecode($serendipity['GET']['tag']));
}
$arr_showtag = explode(';', $showtag);
The code may pass array_map() to $showtag, but explode() doesn't seems to like this. I wonder why it's coded this way, and would there be a way to avoid generating the errors in the log?

Re: [freetag] constantly generates PHP warning in the log

Posted: Thu Jul 10, 2014 11:19 am
by garvinhicking
Hi!

Hm I believe this is an actual flaw in the logic; if the array_map is used, explode isn't used.

I would suggest rewriting it to:

Code: Select all

if (!empty($this->tags['show'])) {
    if (is_array($this->tags['show'])) {
        $showtag = array_map('serendipity_db_escape_string', $this->tags['show']);
    } else {
        $showtag = serendipity_db_escape_string($this->tags['show']);
    }
} else if (!empty($serendipity['GET']['tag'])) {
    $showtag = serendipity_db_escape_string(urldecode($serendipity['GET']['tag']));
}

if (is_array($showtag)) {
    $arr_showtag = $showtag;
} else {
    $arr_showtag = explode(';', $showtag);
}
Can you test this? If it works, I'd commit it to the plugin repo...

Thanks,
Garvin

Re: [freetag] constantly generates PHP warning in the log

Posted: Fri Jul 11, 2014 4:14 am
by wesley
The revised code seems to work. The error hasn't been showing up since.

Re: [freetag] constantly generates PHP warning in the log

Posted: Fri Jul 11, 2014 12:02 pm
by garvinhicking
Cool, thanks! Committed!

Re: [freetag] constantly generates PHP warning in the log

Posted: Wed Jul 16, 2014 7:59 am
by Lux
garvinhicking wrote:Can you test this? If it works, I'd commit it to the plugin repo...
With 2.0 beta I do not see a clickable list of tags below my article any more.

Can you please check?

BTW:

Cheers

Dirk

Re: [freetag] constantly generates PHP warning in the log

Posted: Wed Jul 16, 2014 9:24 am
by yellowled
Lux wrote:With 2.0 beta I do not see a clickable list of tags below my article any more.
Might be http://board.s9y.org/viewtopic.php?p=10440023 (German).

YL

Re: [freetag] constantly generates PHP warning in the log

Posted: Wed Jul 16, 2014 9:43 am
by Lux
yellowled wrote:
Lux wrote:With 2.0 beta I do not see a clickable list of tags below my article any more.
Might be http://board.s9y.org/viewtopic.php?p=10440023 (German).
Looks like, I will answer there.

Cheers

Dirk