Fra.nkSteidl.de

Gallery - Subalbum dropdown

How to add a subalbum dropdown list to Gallery 1.x
(developed for Gallery 1.4.1, adapted successfully to Gallery 1.5)

This tutorial is designed for Gallery, a very powerful webbased online gallery.

In the config there's this option:
$gallery->app->showAlbumTree = "yes";
which shows a tree of subalbums on the entry page of the gallery (albums.php).

With increasing numbers of subalbums this tree becomes bigger (taller) than the highlight photo and it's description. This let a page appear cluttered.

This is a way to put those trees into a dropdown box. My favorite is to put it beneath the album title within its background. In the Gallery forum were several solutions discussed, but none was mine. So I put all useful together and changed only the albums.php

First put this code somewhere in the file:
<?php
function printSubAlbumDrop($albumName,$depth=0) 
{
  global $gallery;
  $printedHeader = 0;
  $myAlbum = new Album(false);
  $myAlbum->load($albumName);
  $numPhotos = $myAlbum->numPhotos(1);
  $form_name = (rand()%99);
  for ($i=1; $i <= $numPhotos; $i++) 
     {
    $myName = $myAlbum->getAlbumName($i);
    if ($myName && !$myAlbum->isHidden($i)) 
       {
      $nestedAlbum = new Album();
      $nestedAlbum->load($myName);
      if ($gallery->user->canReadAlbum($nestedAlbum)) 
         {
        $val2 = str_repeat(" - - ", $depth+1);
        $val2 = $val2 . $nestedAlbum->fields['title'];
        if ($depth==0 && !$printedHeader++) 
           {
          $rootAlbum = $gallery->album->getRootAlbumName();
          $pAlbum = new Album();
          $pAlbum->load($rootAlbum);
          $rootAlbumTitle = $pAlbum->fields['title'];
          echo "<td align=left valign=top>";
          echo "<form name='f$form_name' action='view_album.php' style='margin-bottom:0;'>\n";                  
          echo "<select name='SubAlbum' onChange='location.href=f$form_name.SubAlbum.options[selectedIndex].value'>\n";
          echo "<option value=''>" . _("Sub-albums") . ": </option>\n";
          // echo "<option value='".makeAlbumUrl($rootAlbum)."'>".$rootAlbumTitle."</option>\n";
          echo "<OPTION value=''> </OPTION>\n";
           }
        echo "<option value='".makeAlbumUrl($myName)."'>".$val2."</option>\n";
        printSubAlbumDrop($myName,$depth+1); 
         }
      // if ($i == $numPhotos && !$depth)     // This should close the drop down
      //    {                              // but does not work when subalbums
      //   echo "</select></form></td>";        // are mixed with pics
      //    }                               // moved to the code
       }
     }
} // close funtion printSubAlbumDrop

?>
Ok, now we have a function for drawing the dropdownlist. Parameter is a album name, which subalbums should be shown.

The question is, where to put this dropdown list. We could place it where the original subalbums tree was. Find this part of code:
<?php if (!strcmp($gallery->app->showAlbumTree, "yes")) { ?>
  <td align=left valign=top class="albumdesc">
  
<?php echo printChildren($albumName); ?>
	  
  </td>
<? php } ? >
Comment out the "echo printChildren" line and insert these three lines:
<?php
	printSubAlbumDrop($albumName);
	echo "<OPTION value=''> </OPTION>\n";
	echo "</select></form></td>";
?>
Take care of the PHP Tags...

I wanted my dropdown lists beneath the album title, on the same background. OK, look thorugh the code and search for
<!-- End Image Cell -->
<!-- Begin Text Cell -->


afterwards in the code (around 10 lines below) you'll find a line like this:
<?php echo editField($gallery->album, "title", $albumURL) ?>

after this line insert this code:
<?php 
	$albumName=$gallery->album->fields["name"];
	if (!strcmp($gallery->app->showAlbumTree, "yes")) 
	   {
		printSubAlbumDrop($albumName);
		echo "<OPTION value=''> </OPTION>\n";
		echo "</select></form></td>";
	   } 
?>

© by Frank Steidl • eMail: Fr @nkSteidl.de • Homepage: Fra .nkSteidl.de