RewriteRule to remove "albums/"

Hey!

I'm almost done writing a new ZenPhoto theme tailored to showing HTML5 and Flash virtual panoramas. One last thing I need to get working is panorama hotspots. When I open a pano from the album-pano.php page everything works fine - the image-pano.php page is loaded, the title and description of the "image" are shown and the panorama plays in the <div id="#container">. Javascript from Pano2VR targets the #container and puts the panorama there.
http://i.imgur.com/69My6oz.jpg

The problem is that when a user clicks on the door hotspot to go to the next panorama, that is handled by the javascript from Pano2VR which then replaces the contents of #container with the new pano. That's no good, because the name and description of the pano on my page outside of #container remains from the previous one.

I want to use hotspot urls relative to the current image (the whole tour resides in one album) so that I can then rename the album and parent albums without worrying about breaking links, otherwise if I use absolute URLs I'm in for a lot of work if I want to rename a parent album, I'd have to edit every pano's XML file which contains the hotspot URLs.

I think I solved the problem, unfortunately when a user clicks on the door, instead of getting taken to
http://127.0.0.1/zp/Panoramas/House of Karin/Foyer.txt
which works, they get taken to
http://127.0.0.1/zp/albums/Panoramas/House of Karin/Foyer.txt
which does not work, because of the "albums".

Even though the URL in the web browser is
http://127.0.0.1/zp/Panoramas/House of Karin/Porch.txt
(notice no "albums"), getUnprotectedImageURL() indeed shows
/zp/albums/Panoramas/House of Karin/Porch.txt
(with "albums") for this working URL, and getImageURL() shows
/zp/Panoramas/House%20of%20Karin/Porch.txt
I guess the .htaccess file does some magic here.

When a user clicks on a hotspot, the browser URL shows
http://127.0.0.1/zp/albums/Panoramas/House of Karin/Foyer.txt
with "albums", and that shows the contents of the txt file instead of loading the Foyer panorama.
If I remove the "albums/" part from that URL in the browser, it works and shows the pano, not the contents of Foyer.txt

Please help getting htaccess to remove "albums/" from the URL if it contains it.

/zp/.htaccess
`
# htaccess file version 1.4.5;
# Rewrite rules are now handled by PHP code
# See the file "zenphoto-rewrite.txt" for the actual rules
#
# These rules redirect everything not directly accessing a file to the Zenphoto index.php script
#

IndexIgnore *


RewriteEngine On

RewriteBase /zp

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]

RewriteRule ^.*/?$ index.php [L,QSA]


`

Comments

  • acrylian Administrator, Developer
    `http://127.0.0.1/zp/albums/Panoramas/House of Karin/Foyer.txt` is the correct full image url which getUnprotectedImageURL() gets. Just that here the "image" is a "text-object" so the full image is the txt-file.

    What you are looking for is the `image.php` page url. No need for htaccess modifcation should be needed.

    You get that via `getImageURL()` if you are in image context, for example withon the `next_image()` loop. Example of that is in every standard themes' `album.php` page. Or via the object model `$image->getLink()` where `$image` is an image object naturally.
  • Here's a cleaner explanation (because now I understand the problem better):

    Folder structure:
    http://i.imgur.com/645iT2J.png

    I use Pano2VR to display the pano in a div with id #container. The Pano2VR player is written in javascript, and uses XML files to store each panorama's configuration. The XML file must have an XML extension.
    `

    pano.readConfigUrl("<?php echo $panoXML; ?>");

    `
    Now I simplified the process of getting $panoXML:
    `
    $txtFile = pathinfo(getUnprotectedImageURL());
    $panoXML = $txtFile ['dirname'] . '/tour/' . stripSuffix($txtFile ['filename']) . '.xml'; ?>
    `
    so $panoXML returns:
    /zp/albums/Panoramas/House of Karin/tour/Foyer.xml
    It does not work when I remove "albums/" from that path.

    For reference:
    getImageURL: /zp/Panoramas/House%20of%20Karin/Foyer.txt
    getUnprotectedImageURL: /zp/albums/Panoramas/House of Karin/Foyer.txt

    Clicking on any image thumbnail from my album-pano.php page loads the panorama in the image-pano.php page correctly.
    album-pano.php: http://i.imgur.com/hzVQsoC.jpg
    image-pano.php: http://i.imgur.com/EtNGvQn.jpg
    All good.

    The problem are the hotspots. If I use
    `<polyhotspot title="Porch" url="../Porch.txt" (...)`
    I end up getting served the txt file's contents! ZenPhoto gets bypassed. http://i.imgur.com/INxrejN.png (I put the text "porch.txt" inside the file Porch.txt just to see what happens, normally the text files would be empty).
    If I change the hotspot URL to ../Porch.jpg I get served the JPG thumbnail http://i.imgur.com/PDC0g2N.jpg so ZP still gets bypassed.
    However, if I remove the "albums/" from the URL, then ZP handles it correctly! http://i.imgur.com/knFZ4hz.jpg
    So I thought if I use htaccess to forcefully remove "albums/" it would work, except it doesn't, because $panoXML needs albums/ to be there.

    I could use the full path for the hotspot `<polyhotspot title="Porch" url="/zp/Panoramas/House of Karin/Porch.txt"` which works, but if I want to rename the "Panoramas" album or the "House of Karin" album I will have to manually edit all the hotspots!

    I'd be most grateful if you could please advise what to do. Should I try to make a conditional .htaccess rule that doesn't remove "albums/" if an XML file is being called (which is a hacky, workaround way of doing things), or can you recommend some better solution?

    By the way, my .htaccess is the default one that comes with the ZP installation.
  • acrylian Administrator, Developer
    You really don't need to use htaccess. That will have side effects, the actual rewrite handling is not done via that at all but internally.

    `domain.com/albums//` -> full image <image> in the album <album>
    `domain.com//` -> image page of the image <image> of the album <album>

    You request the full image so that gets you the txt file on text objects correctly. If you wish to link hotspot to further panoramas based on text objects you need to link to the image page instead the item itself. I hope I understood the issue correctly.

    You probably have to use the object model directly as within your scripts the right context are not set for normal template functions. Of course since Zenphoto is file system based any renaming of albums or images will require changes afterwards. The names are also the base for the object model.

    I hope that helps for now.
  • Acrylian thank you for taking the time to read through this and answer :)

    I think I understand you, and I think you understood the issue correctly.
    If you wish to link hotspot to further panoramas based on text objects you need to link to the image page instead the item itself. I hope I understood the issue correctly.

    Question is, is it possible to do that without using absolute paths?
    "You have to use the object model directly" I'm not clear on this, could you give a link or example to show what you mean?

    Knowing that if I set the hotspot URL to just `foo`, and that clicking it will result in the URL being `http://127.0.0.1/zp/albums/Panoramas/House of Karin/tour/foo`, and that the same URL without `albums/` would work and save me a lot of time in the future if I rename the parent album, is there anything I could do to keep this independent relative structure?
  • acrylian Administrator, Developer
    I can only cite my post from above:

    What you are looking for is the image.php page url. No need for htaccess modifcation should be needed.

    You get that via getImageURL() if you are in image context, for example withon the next_image() loop. Example of that is in every standard themes' album.php page. Or via the object model $image->getLink() where $image is an image object naturally.

    You should always use these functions as that way you cover possible changes on Zenphoto updates.

    Also take a look:
    http://www.zenphoto.org/news/zenphotos-object-model-framework
    http://www.zenphoto.org/news/zenphotos-global-variables
  • I read those pages several times already. I don't follow how any of that helps if I'm clicking on a link which gets handled by proprietary obfuscated javascript, not by ZenPhoto, and the link should be relative to nothing more than its containing album. The result of the click is this URL
    http://host/zp/albums/Panoramas/Album/image.txt
    That's all I get to work with.

    I got the hotspots working correctly using /zp/.htaccess
    `RewriteRule ^albums/(.*)\.txt $1.txt [NC,R,L]`
    It fulfills my needs and I can rename parent albums of the album containing the individual panorama "images" without having to edit any code.
  • acrylian Administrator, Developer
    Maybe I then did not understand the problem exactly.So you are talking about links within the txt- file then? Those are indeed outside of the "knowledge" of Zenphoto scope then. You can either use absolute or relative paths to achieve it probably. A proper site link example might have helped. But anyway whatever works for you :-)
Sign In or Register to comment.