[freetag] constantly generates PHP warning in the log

Creating and modifying plugins.
Post Reply
User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

[freetag] constantly generates PHP warning in the log

Post by wesley » Thu Jul 10, 2014 5:32 am

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?
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post by garvinhicking » Thu Jul 10, 2014 11:19 am

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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

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

Post by wesley » Fri Jul 11, 2014 4:14 am

The revised code seems to work. The error hasn't been showing up since.
I make s9y plugins, too.
My s9y blog depends on them. :)

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post by garvinhicking » Fri Jul 11, 2014 12:02 pm

Cool, thanks! Committed!
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Lux
Regular
Posts: 761
Joined: Fri Aug 12, 2005 4:36 pm
Location: Grüt, Zürich, Switzerland
Contact:

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

Post by Lux » Wed Jul 16, 2014 7:59 am

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

User avatar
yellowled
Regular
Posts: 7072
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany
Contact:

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

Post by yellowled » Wed Jul 16, 2014 9:24 am

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
amazon Wishlist - Serendipity-Podcast (German only, sorry)

User avatar
Lux
Regular
Posts: 761
Joined: Fri Aug 12, 2005 4:36 pm
Location: Grüt, Zürich, Switzerland
Contact:

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

Post by Lux » Wed Jul 16, 2014 9:43 am

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

Post Reply