; list dynamic albums | code | Bert Simons | Portfolio

code /

list dynamic albums

This shows up a list of only dynamic albums:

 

One exception though..shows only dynamic albums as a list that are not nested more then 2 levels deep eg:

zenphoto/albums/thedynamicalbum or zenphoto/albums/subalbum/thedynamicalbum

code adapted from original ZENphoto code, credits to the ZENphoto team:

 

<?php printDynamicAlbumList("list"); ?>

and the code to put in the customfunctions.php file that you call with an include on the page were you want to use the function:

 

<?php
function printDynamicAlbumList($option1,$option2,$id,$active,$class,$active2) {
// check if parameters are used
if ($id != "") { $id = " id='".$id."'"; }
if ($active1 != "") { $active1 = " id='".$active1."'"; }
if ($class != "") { $class = " class='".$class."'"; }
if ($active2 != "") { $active2 = " id='".$active2."'"; }
if (getOption('mod_rewrite')) 
{ $albumlinkpath = WEBPATH."/"; }
else 
{ $albumlinkpath = ""; }
// main album query
$sql = "SELECT id, parentid, dynamic, folder,title FROM ". prefix('albums') ." WHERE `show` = 1 ORDER BY sort_order";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
    {
    $number++;
        $idnr[$number] = $row['id']; 
    $parentid[$number] = $row['parentid']; 
    $folder[$number] = $row['folder'];
    $title[$number] = $row['title'];
    $dynamic[$number] =$row['dynamic'];
    $album[$number]= new Album($_zp_gallery, $folder[$number]);
//show image count
    switch($option2) {
    case "count": 
    // count images in the albums
    $sql = "SELECT COUNT(id) FROM ". prefix('images') ." WHERE albumid = $idnr[$number]";
    $result2 = query($sql);
    $count = mysql_result($result2, 0);
    $imagecount[$number] = " (".$count.")"; 
    }
    }
// open main albums list
echo "";
/* main album loop start */     
for ($nr = 1;$nr <= $number; $nr++)
    {
     if ($parentid[$nr] === NULL ) // check if album is main album
        { 
        if ($imagecount[$nr] == " (0)") // prevent "(0)" behind main albums if you only have subalbums with images
            { $imagecount[$nr] = ""; }
        // if check if the album is the currently selected album
        if ($title[$nr] === getAlbumTitle()) { 
 
if($dynamic[$nr]=='1'){ 
$_zp_dynamic_album=$album[$nr];
$data = $_zp_dynamic_album->data;//used to get custom data 'notlisted' from album to hide this dynamic album from the list
$custom_data = $data[custom_data];// 
$_zp_current_search = $_zp_dynamic_album->getSearchEngine();
$images = $_zp_current_search->getSearchImages();
$first=$images[0][filename];
$folder2=$images[0][folder];
 
if (substr_count($custom_data,"notlisted")!=1){
echo "            <a href='".$albumlinkpath.$folder[$nr]."'>".htmlspecialchars($title[$nr])."</a>".$imagecount[$nr]."&nbsp;&nbsp;";
 
//echo "<a href='".$folder2."/".$first."'>".htmlspecialchars($title[$nr2])."</a>".$imagecount[$nr2]."&nbsp;&nbsp;";
}
}
}   
else 
             { if($dynamic[$nr]=='1'){ 
$_zp_dynamic_album=$album[$nr];
$data = $_zp_dynamic_album->data;//used to get custom data 'notlisted' from album
$custom_data = $data[custom_data];// to hide this dynamic album from the list
 
$_zp_current_search = $_zp_dynamic_album->getSearchEngine();
$images = $_zp_current_search->getSearchImages();
$first=$images[0][filename];
$folder2=$images[0][folder];
 
if (substr_count($custom_data,"notlisted")!=1){
echo "            <a href='".$albumlinkpath.$folder[$nr]."'>".htmlspecialchars($title[$nr])."</a>".$imagecount[$nr]."&nbsp;&nbsp;";
 
//echo "<a href='".$folder2."/".$first."'>".htmlspecialchars($title[$nr])."</a>".$imagecount[$nr]."&nbsp;&nbsp;";
}
}
  }                                       
        /*  open sublist for subalbums */
        // check if any subalbums are available. If then open sublist for subalums
        for ($nr2 = 1;$nr2 <= $number; $nr2++)
            {
            if ($idnr[$nr] === $parentid[$nr2]) 
               { echo ""; break; }
            }  
        // subalbum subloop start             
        for ($nr2 = 1;$nr2 <= $number; $nr2++)
            {     
            // check if any subalbums are available                  
            if ($idnr[$nr] === $parentid[$nr2]) 
               {      
               if ($imagecount[$nr2] == " (0)") // prevent "(0)" behind main albums if you only have subalbums with images
                    { $imagecount[$nr2] = ""; }
                // if check if the subalbum is the currently selected album
                if ($title[$nr2] === getAlbumTitle()) 
                    { if($dynamic[$nr2]=='1'){$_zp_dynamic_album=$album[$nr2];
$data = $_zp_dynamic_album->data;//used to get custom data 'notlisted' from album
$custom_data = $data[custom_data];// to hide this dynamic album from the list
 
$_zp_current_search = $_zp_dynamic_album->getSearchEngine();
$images = $_zp_current_search->getSearchImages();
$first=$images[0][filename];
$folder2=$images[0][folder];
 
if (substr_count($custom_data,"notlisted")!=1){
echo "            <a href='".$albumlinkpath.$folder[$nr2]."'>".htmlspecialchars($title[$nr2])."</a>".$imagecount[$nr2]."&nbsp;&nbsp;";
 
//echo "<a href='".$folder2."/".$first."'>".htmlspecialchars($title[$nr2])."</a>".$imagecount[$nr2]."&nbsp;&nbsp;";
}
 
}
}
                else 
                    {  
     
if($dynamic[$nr2]=='1'){ 
 
$_zp_dynamic_album=$album[$nr2];
$data = $_zp_dynamic_album->data;//used to get custom data 'notlisted' from album
$custom_data = $data[custom_data];// to hide this dynamic album from the list
 
$_zp_current_search = $_zp_dynamic_album->getSearchEngine();
$images = $_zp_current_search->getSearchImages();
$first=$images[0][filename];
$folder2=$images[0][folder];
 
if (substr_count($custom_data,"notlisted")!=1){
echo "            <a href='".$albumlinkpath.$folder[$nr2]."'>".htmlspecialchars($title[$nr2])."</a>".$imagecount[$nr2]."&nbsp;&nbsp;";
 
//echo "<a href='".$folder2."/".$first."'>".htmlspecialchars($title[$nr2])."</a>".$imagecount[$nr2]."&nbsp;&nbsp;";
}
 
}     
                    }                                       
                }                 
            } // subalbum loop end 
        // close subalbums sublist (only printed if there are subalbums) 
        for ($nr2 = 1;$nr2 <= $number; $nr2++)
            {              
            if ($idnr[$nr] === $parentid[$nr2]) 
               { echo "        "; break; }
            }  
        echo "    "; // close main album list item
        } // close main album check
    } // main album loop end
echo ""; // close main album list
break; 
 }  
; ?>

Tags: