Zenpage - Create albumobject from albumname in codeblock

fretzl Administrator, Developer
On a Zenpage page I'm tying to get a random image from a specific album.
The name of the album/folder is put in a codeblock as plain text.
I then use the `printCustomSizedImage()` function to display the random image.
This is what I have so far:

`
$albumname = getCodeblock(2,$_zp_current_zenpage_page);
$albumobj = new Album($_zp_gallery,$albumname);
$randomImage = getRandomImagesAlbum($albumobj);
makeImageCurrent($randomImage);
printCustomSizedImage(NULL, NULL, 512, 546, ... etc);
`
The $albumobj is only created if I hardcode the albumname
(i.e. `$albumobj = new Album($_zp_gallery,"");`)

I just can't figure out what's wrong :-(

Comments

  • acrylian Administrator, Developer
    Sure the value get from getCodeblock is correct?
  • fretzl Administrator, Developer
    Let's say the input in the codeblock is for example testalbum
    If I `echo $albumname;` I also get testalbum
  • acrylian Administrator, Developer
    That's weird then and does not really make sense... No idea right now, that should actually work..
  • You should have got an error if the album was not created. Did it provide any clues?

    Did you look at the page html of the echo? You cannot really trust what the browser shows, there might be markup or such included.
  • fretzl Administrator, Developer
    The posted code does work (without errors) but it shows random images from the entire gallery.
    Of course I should have mentioned this, sorry.

    Only if I hardcode an albumname does it show random images from that specific album.
  • acrylian Administrator, Developer
    Hm, for the function it is really meaningless where the value comes from. I will try later as well. Before that, just to be sure you are not confusing yourself: the option defines the root album so that means all sub albums are used as well.
  • fretzl Administrator, Developer
    Thanks.
    There are no subalbums.
  • acrylian Administrator, Developer
    I just tried with trunk and Zenpage theme. I used a top-level album with 3 images and reloaded the page dozens of times. I always got only images from it. So I am sadly not able to reproduce it using the whole gallery as there are 8 albums and 3 dynamic ones additionally.
  • fretzl Administrator, Developer
    Much appreciated!

    I'll investigate further.
  • You did say that the album object was created only if you hardcoded then name. Is that the case, or is an object being created?

    Similar question for the image object. Is one created?

    My speculation is that the answere to both these is that the object is not created. If `makeImageCurrent($image)` is not passed an object it does nothing, so whatever `$_zp_current_image` was will not have been changed. Probably somewhere else this variable is being setup to some image from the album in general.
  • fretzl Administrator, Developer
    If change this:
    `$albumobj = new Album($_zp_gallery,$albumname);`
    to this:
    `$albumobj = new Album($_zp_gallery,"testalbum");`
    then it works.(i.e. only images from the specified album are shown)

    I also checked if an albumobject and an imageobject were created by using:
    `if (is_object($albumobj)) echo "something";`
    and
    `if (is_object($_zp_current_image)) echo "something else";`
    They both were.

    I now see different results on different installs:
    On one PC it works with the SVN Development and SVN Trunk.
    PHP version: 5.3.0 MySql version: 5.1.37

    On another it does not work with the Nightly Trunk.
    PHP version: 5.3.6 MySql version: 5.1.49
    Note that "not working" means that images from the entire gallery are shown.
  • So, I guess the next test is as follows:

    first make a test `$albumname=="testalbum"` just to be sure that they are not somehow different.

    Then check to see if the two versions both fail on the PC that has the Nightly Trunk.

    But I suspect so. If you are using todays' SVN Trunc and last night's Trunk nightly then there is only one change to the `isImagePage()` function. So it would not be Zenphoto code that makes the difference.
  • fretzl Administrator, Developer
    Well, the first test allready failed.

    `
    $albumname = getCodeblock(2,$_zp_current_zenpage_page);
    if($albumname=="testalbum") echo "OK";
    `
    does not output OK.

    EDIT: That is on the PC with the Nightly Trunk
  • So the codeblock does not contain the string `"testablum"`. Try `echo html_encode($albumname);` and see what is really there.
  • fretzl Administrator, Developer
    `echo html_encode($albumname);` outputs testalbum
  • acrylian Administrator, Developer
    That's weird, why does it work for me out of the box?
  • Well, there seems some difference otherwise the equal test would come up true. As to what, I really do not know. But if $albumname is really not equal to "testalbum" then that does explain why the rest does not work.
  • fretzl Administrator, Developer
    If I put the albumname in another codeblock it suddenly works!
    The echoed checks are also correct.
    I then put the albumname back in the original codeblock it also works.
    Guess that must have been a very persistent browser cache.

    Now this might be something:
    If I leave all codeblocks empty it still shows random images of the entire gallery ??
  • acrylian Administrator, Developer
    Maybe funny cache tricks again?

    Yes, if you don't set a root album it uses the whole gallery. We once had a php issue with NULL vs empty, so on some servers it triggered wrong somehow.

    Try adding a check if the code block is empty so it is not used.
  • fretzl Administrator, Developer
    Thanks!
    if you don't set a root album it uses the whole gallery...
    Learned something again ;-)
Sign In or Register to comment.