Not sure if I should post this as a suggestion but I think it would be useful to implement a function that allows you to go through albums as you would with images. A function that would mirror getNextImageURL().
This would be very useful for the current theme I am building. Anyone want to give a crack at it?
Comments
` function getNextAlbum() {
if ($this->index == null)
$this->index = array_search($this->name, $this->gallery->getAlbums(0));
return $this->gallery->getAlbum($this->index+1);
}`
`function getPrevAlbum() {
if ($this->index == null)
$this->index = array_search($this->name, $this->gallery->getAlbums(0));
return $this->gallery->getAlbum($this->index-1);
}`
which might be of use.
Looking at the function for getNextImageURL():
`function getNextImageURL() {
if(!in_context(ZP_IMAGE)) return false;
global $_zp_current_album, $_zp_current_image;
$nextimg = $_zp_current_image->getNextImage();
return rewrite_path("/" . urlencode($_zp_current_album->name) . "/" . urlencode($nextimg->getFileName()),
"/index.php?album=" . urlencode($_zp_current_album->name) . "&image=" . urlencode($nextimg->getFileName()));
}`
one could surmise that you can do the same thing in the album context by writing two new functions called getNextAlbumURL() and getPrevAlbumURL() using the above.
Let me see what I can come up with. I just hope my train of thought is leading me down the right path....
`function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
return rewrite_path("/" . urlencode($_zp_current_album->name),
"/index.php?album=" . urlencode($_zp_current_album->name));
}`
I have not tested this. Just posted on the forum, so I don't know if it will work. Comments anyone?
`function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
return rewrite_path("/" . urlencode($nextalbum),
"/index.php?album=" . urlencode($nextalbum));
}`
Here's the link and the error I've got so far.
http://www.thinkdreams.com/devzen/
I'm putting this in index.php, and then changing the context.
Here's my custom function:
`<?php<br />
// Custom getNextAlbumURL Function
function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
return rewrite_path("/" . urlencode($nextalbum),
"/index.php?album=" . urlencode($nextalbum));
}
?>`
This is the snippet from index.php:
`<?php set_context(ZP_ALBUM); ?>
">Next Album
<?php set_context(ZP_INDEX); ?>`
(placed right below the next_album loop)
I configured the zp-config to show only 1 album per page. Hopefully you can see where this is going.
I am not using subalbum organized directories, although this is ZP 1.0.7. I'm using the Sterile theme, so subalbums aren't even being shown. (Thought it might be a bit more complex with subalbums.)
Tristan- might you have any guidance on this matter?
This really is something I should implement in the main codebase, certainly is a useful theme function. You're right about it being more complicated with sub-albums though, and that leads to something I've been wanting to do for a long time--- make the `Gallery` class a subclass of `Album`. Pretty crazy huh? With sub-albums, a Gallery is nothing more than a glorified album, and that way functions that work with albums can work on any level without differentiating. It's a small refactoring that should be done...
In the meantime, your function will work for first-level albums only, and as long as the methods still work, should work seamlessly on sub-albums as well with upgrades to the Album class.
it returns a fun error:
`Not Found
The requested URL /devzen/
Warning: urlencode() expects parameter 1 to be string, object given in .../devzen/themes/sterile/customfunctions.php on line 9
Warning: urlencode() expects parameter 1 to be string, object given in .../devzen/themes/sterile/customfunctions.php on line 10
was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.`
`<?php<br />
function DebugClass($class)
{
$class_vars = get_object_vars($class);
echo "Class contents
";
foreach ($class_vars as $key => $value)
echo "Property Name: ".$key." Property Value: ".$value."
";
}
// Custom getNextAlbumURL Function
function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
DebugClass($nextalbum);
return rewrite_path("/" . urlencode($nextalbum),
"/index.php?album=" . urlencode($nextalbum));
}
?>`
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
DebugClass($nextalbum);
return rewrite_path("/" . urlencode($nextalbum->name),
"/index.php?album=" . urlencode($nextalbum->name));
}`
Just get the name inside the `urlencode()`, that should work :-)
I'm not actually testing this, working on other things at the moment, sorry. ;-)
`// Custom getNextAlbumURL Function
function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
// $nextalbum = $_zp_current_album->getNextAlbum();
// DebugClass($nextalbum);
return rewrite_path("/" . urlencode($_zp_current_album->getNextAlbum()->name),
"/index.php?album=" . urlencode($_zp_current_album->getNextAlbum())->name);
}`
`// Custom getNextAlbumURL Function
function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
// DebugClass($nextalbum);
return rewrite_path("/" . urlencode($nextalbum->name),
"/index.php?album=" . urlencode($nextalbum->name));
}`
I get the current album, not the "next" album.
(turned off the debug class - was choking on the gallery property in the class - which what made me think it wasn't working.)
I am now officially stumped.
http://www.thinkdreams.com/devzen/index.php?album=cayman1996 for reference.
I'm working on it. I'm close, it's doing something, just not exactly what I want.
See the functions at the bottom of this changeset, exactly as you had written them :-)
And it still doesn't return the right data. I checked my album.php, and the line I'm using is:
`">Next Album`
Now, this is placed right after the images loop in the sterile theme album.php. I thought the placement might be wrong.
It's returning "cayman1996" which is the current album, not the "next" album, which in my gallery would be "disney". If I look this information up using the debug class, the property name shows up as disney, it just doesn't display the correct album on the link. It returns cayman1996 on both functions, on the same page. Very strange.
If I add `echo $nextalbum->name;` to the code right before the return rewrite_path statement, it returns the correct information (i.e. disney if you're on the cayman1996 album). Then if I take it away, it reverts back to the current album. It's almost like the rewrite_path is not displaying something right, or maybe the urlencode command maybe?
`function getNextAlbumURL() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
$nextalbum = $_zp_current_album->getNextAlbum();
return rewrite_path("/" . urlencode($nextalbum->name),
"/index.php?album=" . urlencode($nextalbum->name));
}`
The plot thickens. Just for kicks, I put both function calls up there (http://www.thinkdreams.com/devzen/disney). The getNextAlbumURL has the modification above with the echo statement. The getPrevAlbumURL is normal (i.e. without the echo statement inserted.). I pointed it to the Disney album so that you can get an idea of what happens when you have a prev album and a next album. Note the prev album function displays the current album name. The next album function displays the name of the next album correctly.
`Prev Album | Next Album`
Looking at the link code you're using above, this is your problem:
`">Next Album`
Should be
`">Next Album`
Note the echo. getNextAlbumURL() doesn't actually print anything (until you told it to echo the name above) so you have to echo its return value, as in getTitle() and getDescription() etc. I suppose we should have printNext[Prev]AlbumLink() functions...
Also, a useful function for creating any link in zenphoto is `printLink($url, "Link Text")` There are other arguments as well which are optional, check out the code to see.
Here's how I did my links:
`<?php printLink(getPrevAlbumURL(), "« Prev Album"); ?>
| <?php printLink(getNextAlbumURL(), "Next Album »"); ?>`
Thanks again.