1 (edited by movietajm 2020-10-01 15:27:37)

Topic: Juicebox and PHP 7.x [SOLVED]

Hi. I have been running Juicebox Pro with PHP 5.6 for several years and now it was time to upgrade. So I discovered that if I use PHP 7.0 or PHP 7.1 everything works perfect but if I use PHP 7.2, 7.3 och 7.4 I get this message on the gallery:
"Juicebox Error: Config XML file not found." If I change back to 7.1 the gallery works again?

Re: Juicebox and PHP 7.x [SOLVED]

That's very strange...

With the exception of the Download Button (showDownloadButton="TRUE") and Password Protection (usePassword="TRUE"), Juicebox-Pro does not need or use PHP at all.

I have just uploaded two test galleries to my own web space (one with both the Download Button and Password Protection and one with neither) and they both run fine under PHP 7.2.33, 7.3.22 and PHP 7.4.10.

I think there must be something else going on when you switch PHP versions as PHP is not required for a gallery's configuration file to be found.

If possible, please post back with a link to the gallery in question (under PHP 7.2, PHP 7.3 or PHP 7.4) so that I can see the problem for myself and investigate further.

Thank you.

Re: Juicebox and PHP 7.x [SOLVED]

Ok thx. I have made testmaps here for you:

https://zeerux.com/php-test-71      working! (check https://zeerux.com/php-test-71/info.php)
https://zeerux.com/php-test-74      not working! (check https://zeerux.com/php-test-74/info.php)

(its the exact same folders, I have used modified the .htaccess for specified php-versions.

Re: Juicebox and PHP 7.x [SOLVED]

Thank you for the links to your galleries.

I see that you are using a custom PHP file (named 'config.php')  to dynamically generate your gallery's XML data.
The problem lies somewhere within this file (which is not part of the Juicebox package).
There is something within this file that is not compatible with PHP 7.2 onwards.

Unfortunately, I do not have access to your 'config.php' file to inspect its code but opening it directly in a browser reveals the following warning:

Warning:  count(): Parameter must be an array or an object that implements Countable in config.php on line 10

Your use of the PHP count() function (whatever it may be) on line 10 is listed in the 'Backward incompatible changes' on the 'Migrating from PHP 7.1.x to PHP 7.2.x' support page here.

An E_WARNING will now be emitted when attempting to count() non-countable types (this includes the sizeof() alias function).

In order for your 'config.php' file to be compatible with PHP 7.2 onwards, you'll need to find a new PHP method to count whatever it is that you are counting.

I hope this points you in the right direction.
If you continue to experience difficulties, then please zip and upload your 'config.php' file somewhere (and provide a download link) so that I can inspect the code and hopefully help further.
Thank you.

Re: Juicebox and PHP 7.x [SOLVED]

Ok, thx mate. Here is the code!

<?php
header("Content-type: application/xml");
function GetDirArray($folder)
{
    $handle=opendir($folder);
    while ($file=readdir($handle))
    {
        if ($file!="." && $file!="..")
        {
            $ret[count($ret)]=$file;
        }
    }
    closedir($handle);
    sort($ret);
    return $ret;
}
$gallery=GetDirArray('images');
$gallery=array_reverse($gallery);
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<juiceboxgallery useFlickr="false" maxThumbColumns="7" captionPosition="BELOW_IMAGE" buttonBarPosition="OVERLAY_IMAGE" galleryTitlePosition="NONE" backgroundColor="rgba(18,18,18,1)" topBackColor="rgba(0,0,0,0.5)" thumbFrameColor="rgba(204,204,204,1)" thumbHoverFrameWidth="3" thumbSelectedFrameWidth="5" topAreaHeight="5" stagePadding="10" showOpenButton="true" showExpandButton="false" showThumbsButton="true" showImageOverlay="ALWAYS" showOverlayOnLoad="true" showImageNumber="false" maxCaptionHeight="45" captionHAlign="CENTER" showSplashPage="NEVER" showInfoButton="false" screenMode="LARGE" showSmallPagingText="false" showSmallThumbsButton="false" showSmallThumbsOnLoad="false" backButtonUseIcon="true" showImageNav="ALWAYS" captionBackColor="rgba(0,0,0,0.4)" useLargeImages="false" resizeOnImport="true" maxImageWidth="2048" maxImageHeight="1536" showNavButtons="false" flickrShowTitle="false" showAutoPlayButton="false" useFullscreenExpand="false" useThumbDots="false" expandInNewPage="TRUE" showThumbsOnLoad="true" galleryTitle="The Neighbourhood Gallery" enableDirectLinks="false" imageNavPosition="IMAGE" thumbNavPosition="CENTER" buttonBarHAlign="RIGHT">';
for ($i=0; $i<sizeof($gallery); $i++)
{
    echo '<image imageURL="images/'.$gallery[$i].'" thumbURL="images/'.$gallery[$i].'" linkURL="" linkTarget="">';
    echo '<title><![CDATA[' . pathinfo($gallery[$i], PATHINFO_FILENAME) . ']]></title>';
    echo '<caption></caption>';
    echo '</image>';
}
echo '</juiceboxgallery>';
?>

Re: Juicebox and PHP 7.x [SOLVED]

Just changing the line:

$ret[count($ret)]=$file;

... to:

$ret[]=$file;

... should hopefully resolve your problem (and be backwards compatible with older versions of PHP).

Edit:
In fact, here's an alternative one-liner for the entire GetDirArray function:

function GetDirArray($folder)
{
    return array_diff(scandir($folder), array('.', '..'));
}

Re: Juicebox and PHP 7.x [SOLVED]

Omg! Thx so much mate for this help! Now it works with php 7.4. I changed this code:

$ret[count($ret)]=$file;

to

$ret[]=$file;

The other code made the gallery to behave weird =).

Thx again! =) Im closing this one! Have a nice weekend!

Re: Juicebox and PHP 7.x [SOLVED]

The other code should work fine. (I tested it myself under PHP 7.4.10 before posting it.)  Maybe scandir() has been disabled in your web server's PHP configuration.
Anyhow, I'm glad that my other suggestion worked for you.
Thank you for posting back to let me know. It's most appreciated!