I just recently switched my installation of zenphoto to a new server that's running PHP5, and I think that transition is what caused this.
I'm getting the error on my page:
Fatal error: Call to a member function on a non-object in /home/ballenty2/www/cubistmediagroup.com/clientzen2/zp-core/template-functions.php on line 1185
It looks like this is being called when next_image() is being called, and specifically this line:
`$_zp_images = $_zp_current_album->getImages($all ? 0 : ($imagePage), $firstPageCount, $sorttype);`
I am using a slightly out of date version of ZP, but I can't upgrade (I've hacked the hell out of this install, everything I've done would be impossible to transition to the new version). This is the whole next_image() function:
` function next_image($all=false, $firstPageCount=0, $sorttype=null, $overridePassword=false) {
global $_zp_images, $_zp_current_image, $_zp_current_album, $_zp_page, $_zp_current_image_restore, $_zp_conf_vars, $_zp_current_search, $_zp_gallery;
if (!$overridePassword) { if (checkforPassword()) { return false; } }
$imagePageOffset = getTotalPages(true) - 1; /* gives us the count of pages for album thumbs */
if ($all) {
$imagePage = 1;
} else {
$_zp_conf_vars['images_first_page'] = $firstPageCount; /* save this so pagination can see it */
$imagePage = $_zp_page - $imagePageOffset;
}
if ($firstPageCount > 0) {
$imagePage = $imagePage + 1; /* can share with last album page */
}
if ($imagePage <= 0) {<br />
return false; /* we are on an album page */
}
if (is_null($_zp_images)) {
if (in_context(ZP_SEARCH)) {
$searchtype = true;
$_zp_images = $_zp_current_search->getImages($all ? 0 : ($imagePage), $firstPageCount);
} else {
$_zp_images = $_zp_current_album->getImages($all ? 0 : ($imagePage), $firstPageCount, $sorttype);
}
if (empty($_zp_images)) { return false; }
$_zp_current_image_restore = $_zp_current_image;
if (in_context(ZP_SEARCH)) {
$img = array_shift($_zp_images);
$_zp_current_image = new Image(new Album($_zp_gallery, $img['folder']), $img['filename']);
} else {
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
}
save_context();
add_context(ZP_IMAGE);
return true;
} else if (empty($_zp_images)) {
$_zp_images = NULL;
$_zp_current_image = $_zp_current_image_restore;
restore_context();
return false;
} else {
if (in_context(ZP_SEARCH)) {
$img = array_shift($_zp_images);
$_zp_current_image = new Image(new Album($_zp_gallery, $img['folder']), $img['filename']);
} else {
$_zp_current_image = new Image($_zp_current_album, array_shift($_zp_images));
}
return true;
}
}`
I'm not too familiar with OOP, especially with PHP, so I'm having trouble figuring out what's happening. I think the main issue is with $_zp_current_album. Is it not being defined correctly somehow?
Comments
I'm running ZP version 1.1.5, so I'm only barely behind in terms of official version.
I see $_zp_current_album being created here, in functions-controller.php:
`function zp_load_album($folder, $force_nocache=false) {
global $_zp_current_album, $_zp_gallery;
$_zp_current_album = new Album($_zp_gallery, $folder, !$force_nocache);
if (!$_zp_current_album->exists) return false;
set_context(ZP_ALBUM | ZP_INDEX);
return $_zp_current_album;
}`
And here in template_functions.php:
`function next_album($all=false, $sorttype=null) {
global $_zp_albums, $_zp_gallery, $_zp_current_album, $_zp_page, $_zp_current_album_restore, $_zp_current_search;
if (checkforPassword()) { return false; }
if (is_null($_zp_albums)) {
if (in_context(ZP_SEARCH)) {
$_zp_albums = $_zp_current_search-> getAlbums($all ? 0 : $_zp_page);
} else if (in_context(ZP_ALBUM)) {
$_zp_albums = $_zp_current_album->getSubAlbums($all ? 0 : $_zp_page, $sorttype);
} else {
$_zp_albums = $_zp_gallery->getAlbums($all ? 0 : $_zp_page, $sorttype);
}
if (empty($_zp_albums)) { return false; }
$_zp_current_album_restore = $_zp_current_album;
$_zp_current_album = new Album($_zp_gallery, array_shift($_zp_albums));
save_context();
add_context(ZP_ALBUM);
return true;
} else if (empty($_zp_albums)) {
$_zp_albums = NULL;
$_zp_current_album = $_zp_current_album_restore;
restore_context();
return false;
} else {
$_zp_current_album = new Album($_zp_gallery, array_shift($_zp_albums));
return true;
}
}`
These seem to be the only places that it is defined.
Any help is appreciated, and if you can't help, I understand. I figured I'd ask here because the team here surely has a better hold on the workings of the project than I do.
If you can't explicitly help, could you just explain to me, generally, what the error means, or what I should try to look for?
What you are seeing is the `next_image()` loop being called when the `$_zp_current_album` global has not been set. This could be a flaw in the theme--calling the function from the wrong place. What theme "page" is being loaded? index.php, album.php, or image.php?
`$_zp_current_album` is set in the `next_album()` loop and when an album or image page is loaded.
The error only occur when viewing a sub-album (as in, [zp album folder]->[first level folder]->[subalbum]) -OR- when viewing any other page of an album beyond the first (as in, when there's more than XX items on a page, you can view the next page).
On a top level album, on its first page of items, everything works smoothly.
*EDIT*
I'm working through this...through some deductive reasoning and experimentation, I've found that it's not sub-album specific or "Page 2" specific; it's got to do with whether or not the album has a sub-album displayed on that page.
subalbum on page = no error
no subalbum on page = error
hm.
The problem was a separate while loop calling next_album() in album.php. Killed the second while loop if there were no subalbums.
Thanks for the help, it guided me to where I should be looking.