nliautaud / pico-pages-images

A plugin to get images corresponding to the current page in Pico CMS
MIT License
14 stars 8 forks source link

Notice: Undefined offset: 4 in D:\xampp\htdocs\pico\plugins\PicoPagesImages.php on line 85 #4

Closed tcicit closed 7 years ago

tcicit commented 7 years ago

The plugin works so far quite well. But I get the following error with each picture in the list.

Notice: Undefined offset: 4 in D:\xampp\htdocs\pico\plugins\PicoPagesImages.php on line 85

nliautaud commented 7 years ago

Thanks for the report.

Note : related to #2 and reported in picocms/picocms.github.io/pull/13

https://github.com/nliautaud/pico-pages-images/blob/c4ed30891534fb2e9a5ae6e53f68403e841a497f/PicoPagesImages.php#L83-L85

I just saw that array_pad return [0], [1], [2], [3] and [mime] 😫 . So no offset 4 to be used with list. https://secure.php.net/manual/en/function.getimagesize.php#example-3516

Mime isn't used anyway, so the fix should be, for line 85 :

list($width, $height, $type, $size) = array_pad($imagesize, 4, ''); 

Could you test that ?

tcicit commented 7 years ago

Ok this is working. My quick and ugly solution was the following.

if( !isset( $imagesize[0])) { $imagesize[0] = 0; } if( !isset( $imagesize[1])) { $imagesize[1] = 0; } if( !isset( $imagesize[2])) { $imagesize[2] = 0; } if( !isset( $imagesize[3])) { $imagesize[3] = 0; } if( !isset( $imagesize[4])) { $imagesize[4] = 0; }

But I'm not a PHP programmer.

nliautaud commented 7 years ago

Great, but couldn't you use the change I gave above for the line 85 ?

tcicit commented 7 years ago

Yes :-) everything is OK

At the moment I am working on a small template for a gallery and use your plugin. Nice work :-) https://github.com/tcicit/pico-gallery

nliautaud commented 7 years ago

Wonderful, I apply the changes 😃