A permanent link to the first photo in an album?

pcc

Joined: 2008-01-01
Posts: 6
Posted: Tue, 2008-01-01 06:27

I may be going about this completely wrong, but I'm trying to make a
"one photo a day" photoblog out of gallery2. I like this plan better
than using, say wordpress. Anyway, I've made a simplified version of
the Siriux theme to display nothing but the photo. I retained the
"click on the right" navigation, and made a little button to bring
up all the usual picture info, comments, etc.

What I'm missing is a permanent URL that always brings up the latest
added photo. I'd like "next" and all the other features to still work
too. Perhaps the only way to do this is a tiny page that redirects to
the right URL. That'd be okay too, but I'm still new with G2 and I
think it would take me weeks to figure it out by myself. Any help?

--Thanks in advance, Paul

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2008-01-01 08:19

Without seeing your photoblog it is hard to see what you are after. But I would use the image block module and use the recent image parameter. Somthing like this in the template file:
{g->block type="imageblock.ImageBlock" blocks="recentImage" maxSize=50} You could change the maxSize and make sure that you have the defaults in the imageblock admin page set or add the other parameters you need.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
pcc

Joined: 2008-01-01
Posts: 6
Posted: Tue, 2008-01-01 17:12

Thanks a bunch for the reply Dave. I guess I didn't do a good job of describing what I need, I'll try again. I don't think seeing my not-quite-ready site will really help.

When someone comes to my site, whatever.com, I want to show them the first photo in my "daily" album. I want this page to have some info and navigation, but it will be hidden until they click on the right thing or hover over the right spot.

In order to do this, I've modified a theme so that the photo page displays a single photo and hides all the nav and info until they click on a button. I have this page working acceptably.

The problem I'm trying to solve is that when they come to my site, they see the list of albums. What I want, is for them to be automatically redirected to the photo page of the first photo in my "daily" album. If there's a magical URL parameter that means "show the first image" then I can easily setup a redirect to take them to that URL. If there is no magical URL parameter, then what I think I need is a tiny PHP page that figures out what the right URL is and redirects them to that page.

So, what would a tiny standalone PHP file look like to do that? Here's my stab at pseudo-code that I think I need:

include_once "a bunch of gallery files";
$album = $g->get_album_by_name("daily");
$image = $album->get_first_image();
$url = $image->get_url();
header("Location: $url");

If I can get someone to help me turn that into actual gallery code, that'd be wonderful.

--Paul

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2008-01-05 17:57

I'll have a go at sorting this out in the next few days, as I need something similar myself.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sun, 2008-01-13 12:25

This script (call it latest.php, and put it in the same folder as gallery's main.php) will redirect to the last uploaded picture in an album (you need to know the album id):

<?php
/* Adjust the path to point to your gallery2 folder */
require_once('embed.php');
$dailyGalleryId = 21194;

$ret = GalleryEmbed::init(array('fullInit' => true));
check($ret);

$query = "SELECT [GalleryPhotoItem::id] 
		FROM [GalleryPhotoItem] INNER JOIN [GalleryChildEntity]  
		WHERE [GalleryPhotoItem::id] = [GalleryChildEntity::id]
		AND [GalleryChildEntity::parentId] = $dailyGalleryId
		ORDER BY [GalleryPhotoItem::id] DESC 
		LIMIT 0,1";
list($ret, $searchResults) = $gallery->search($query,array());
check($ret);
if ($result = $searchResults->nextResult()) {
    $itemId = $result[0];
} else {
    die ("none"); //insert link to default picture here
}

$Url = "main.php?g2_view=core.DownloadItem&g2_itemId=$itemId";
/*note would be nicer to use:
$urlgen =& $gallery->getUrlGenerator();
$mainUrl = $urlgen->generateUrl(...
but this doesn't change the script name back to main.php from latest.php
*/
header("Location:$Url", TRUE, 307 );

$ret = GalleryEmbed::done();
check($ret);

function check($ret) {
    if ($ret) die($ret->getAsHtml());
}
?>

Put the albumId in the variable in line 4.

Note: this will only work if the browser has permissions to view the original uploaded image - it won't show derivatives, or originals with watermarks.

If instead of the image (only) you wand the gallery page for that picture, change DownloadItem to ShowItem (line 23).

 
pcc

Joined: 2008-01-01
Posts: 6
Posted: Sun, 2008-01-13 18:48

Thanks!! You are the man! alecmyers++

--Paul

 
rbeuker

Joined: 2006-01-26
Posts: 3
Posted: Sun, 2008-01-13 20:34

wow, great! Thx a lot :-)

Would it be also possible to display the *thumbnail* of the latest picture?

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Mon, 2008-01-14 12:21

For thumbnails instead, nsert these four lines:

list($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds(array($itemId));
check($ret);
$item = $thumbnails[$itemId];
$itemId = $item->getId();

before the line

$Url = "main.php?g2_view=core.DownloadItem&g2_itemId=$itemId";