getNextAlbumURL?

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

  • I might be able to fiddle around with it. To start with, in classes.php, there are two functions:

    ` 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....

    :)
  • So maybe:

    `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?
  • Nope. That won't work. It doesn't do anything with $nextalbum. Back to the drawing board.
  • How about:

    `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));

    }`
  • Well, I messed a bit more with it. I think I'm going to need some remedial zenphoto schooling on context.

    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?
  • trisweb Administrator
    In theory, you wouldn't put that on the front page, eh Craig? It would go on album.php, where the context should already be ZP_ALBUM.

    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.
  • That's what I thought. I'll put it in album.php and see how it goes. Thanks!
  • OK. So. Placing it in Album.php, see here at: http://www.thinkdreams.com/devzen/index.php?album=cayman1996

    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.`
  • OK. So I'm making progress. I found a nifty little debugclass function, and stuck it in the customfunctions file (OK, so I'm learning). Anyway, it returns the contents of the object, one property of which is the next album. Now. How do I display the property for "name" in that object which is stored in $nextalbum using PHP? I tried $nextalbum->name but that doesn't seem to return anything useful.

    `<?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));

    }

    ?>`
  • trisweb Administrator
    `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));

    }`

    Just get the name inside the `urlencode()`, that should work :-)

    I'm not actually testing this, working on other things at the moment, sorry. ;-)
  • trisweb Administrator
    Wait, you're saying `$nextalbum->name` didn't work? It should...
  • Nope. I've tried the below as well:

    `// 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);

    }`
  • OK. Using this:

    `// 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.
  • @Stephane.

    I'm working on it. I'm close, it's doing something, just not exactly what I want.

    :)
  • trisweb Administrator
    Copied and checked into SVN. Looks like you may have been calling the wrong function (`getNextImageURL()` vs `getNextAlbumURL()`) which was simply returning nothing as it was in the wrong context (I debugged that for a while before realizing it... I'm guessing the same name confusion caused your bug?). It seems to be working perfectly.

    See the functions at the bottom of this changeset, exactly as you had written them :-)
  • I copied the functions and put them directly in my template-functions.php.

    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.
  • OK. Here's the bizarre part:

    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.
  • trisweb Administrator
    Well just so you know, it's actually returning nothing vs. something -- here's your HTML output:

    `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 »"); ?>`
  • And there you have it. That works. And I learned something. Thanks Tris. I'll let Stephane know too. I assume since it's now in CVS those functions will live on, correct?

    Thanks again.
    :)
  • I added it to the wiki under Developer Reference>Theme Function Reference here.
  • trisweb Administrator
    They will indeed live on. Thanks for writing them!
  • Fantastic. Sorry, I haven't had time to test your work, I've been quite busy, but I'll try it asap!
Sign In or Register to comment.