Page 1 of 1

Image upload failed

Posted: Sun Jun 03, 2012 3:53 pm
by sammywg
Hi there,

it's not the first entry in my blog I've wrote, but the first one after the last update to 1.7-alpha1. Runs on PHP 5.2.6. If I click to "Add media data" (or something like this, I use the german language version) the only result is this fatal error message:

Code: Select all

Fatal error: Uncaught exception 'ErrorException' with message 'Serendipity error: in_array(): Wrong datatype for second argument' in /home/www/servers/foo/pages/include/compat.inc.php:106 Stack trace: #0 [internal function]: errorToExceptionHandler('2', NULL) #1 /home/www/servers/foo/pages/plugins/serendipity_event_imageselectorplus/serendipity_event_imageselectorplus.php(293): in_array('backend_image_a...', Object(serendipity_property_bag), Array, NULL) #2 /home/www/servers/foo/pages/include/plugin_api.inc.php(1073): serendipity_event_imageselectorplus->event_hook('backend_image_a...', Array, NULL) #3 /home/www/servers/foo/pages/include/functions_smarty.inc.php(554): serendipity_plugin_api::hook_event(Array, Object(Smarty_Internal_Template)) #4 /home/www/servers/foo/pages/templates_c/terrafirma/40/e9/30/40e93062dcdae313196b39ed34e16a56aacc9bcc.file.media_upload.tpl.php(295): serendipity_smarty_hookPlugin(Object(S in /home/www/servers/foo/pages/include/compat.inc.php on line 106
Does exists a short fix for this problem? Looks as triggered by a template bug, but I'm not sure.

Thanks for help.

Sammy

Re: Image upload failed

Posted: Sun Jun 03, 2012 4:12 pm
by blog.brockha.us
If this really is a template bug, there is no "short fix", as we don't know your template.

But it might help to put this line to your serendipity_config_local.inc.php:

$serendipity['production']=true;

This will let S9Y behave a little more nice on this types of problems. If your template worked before, the chances are high, that it will again with this small change. :)

Re: Image upload failed

Posted: Mon Jun 04, 2012 10:13 am
by Timbalu
These exception messages look quite confusing, but they tell you exactly where to look for...
I think it recommends this line ~293

Code: Select all

echo '<option value="'. $cat['categoryid'] .'"'. (in_array($cat['categoryid'], $selected) ? ' selected="selected"' : '') .'>'. str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] .'</option>' . "\n";
in the additional_plugin serendipity_event_imageselectorplus.php.

I can't see where $selected, the second argument, is defined...
This could be $serendipity['GET']['category']; for example.
So adding a line before the foreach loop could look like

Code: Select all

$selected = $serendipity['GET']['category'] ? $serendipity['GET']['category'] : '';
Can you please try this?

I even think just doing a simple replace of the first with

Code: Select all

echo '<option value="'. $cat['categoryid'] .'"'. (($cat['categoryid'] == $serendipity['GET']['category']) ? ' selected="selected"' : '') .'>'. str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] .'</option>' . "\n";
would suffice best.

Re: Image upload failed

Posted: Tue Jun 05, 2012 2:57 pm
by garvinhicking
Hi!

Good catch; that var doesn't exist. I'm afraid there could be a lot of other places where in_array() does no explicit type check or variable existing check. Do you know if the smarty/error exception handler can be finetuned to simply ignore such notices? IMHO for an untyped scripting language like PHP, errors like these should never make the whole process choke...

(I updated the plugin to remove that check)

Regards,
Garvin

Re: Image upload failed

Posted: Tue Jun 05, 2012 3:11 pm
by Timbalu
Hi Garvin

Well, hmm, no, I assume. We can disable NOTICE exceptions at all, but...
Remember this is a more strict setting, as using an Alpha version, where production = false.
Which is good in my eyes!
IMHO NULL is an error not a notice, btw...

Why didn't you change imageselectorplus to?:

Code: Select all

'. (($cat['categoryid'] == $serendipity['GET']['category']) ? ' selected="selected"' : '') .'

Re: Image upload failed

Posted: Fri Jun 15, 2012 2:40 pm
by sammywg
Sometimes it is not the best idea to use the newest code - on the other hand is it not that unknown to find strange bugs.

First, yes, it is a bug in the alpha release, a downgrade to the last stable version fixed the problem completely. So I think you know which sections are edited from stable to head and are probably also affected.

Second: thanks for help to Garvin :) (and Kris for his hands on the machine).

Garvin: If you need more specific details on the local installation, please ask Kris for a tarball.

Regards,
Sammy