< < < Click here to go back to the main site

List of available files:

basecode/
    > Gallery.php
    > Photograph.php
    > gallerybuilder.php
    > Video.php
    > GallerySection.php
    > includer.php
    > GalleryItem.php
    > GalleryNavigationData.php
pictures/
templates/
    style/
        > gallery.css
    > footer.txt
    images/
    > header.txt
    > contact.txt
> index.php
> opensource.php
> gpl.txt

Showing source of: ./basecode/GallerySection.php


<?php

    
/***************************************************************************
     * jpbGallery 1.0.0 Copyright (c) 2007 Jean-Philippe Barbeau
     * Contact: jp $at> jpbarbeau $dot> com
     ***************************************************************************
     * This file is part of the jpbGallery project.
     *
     * jpbGallery is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 3 of the License, or
     * (at your option) any later version.
     * 
     * jpbGallery is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     * 
     * You should have received a copy of the GNU General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    -***************************************************************************/
    

    
define('SECTION_ITMS_PER_LINE'4);

    
    class 
GallerySection
    
{
        
        private 
$m_items;
        private 
$m_name;
        
        public function 
__construct($name)
        {
            
$this->m_items = array();
            
$this->m_name $name;
        }
        
        public function 
addItem(GalleryItem $item)
        {
            
/* Adds an item to the list */
            
$this->m_items[] = $item;
        }
        
        public function 
itemCount()
        {
            
/* Returns the total number of items in this section */
            
return count($this->m_items);
        }
        
        public function 
toHTML($baseCounter$maxPhotoId 0$photoid 0)
        {
            
$result "";
            
            if (
$photoid 0)
            {
                
/* Print a single item (photoid) */
                
--$photoid/* Translate into a 0-based numbering system */
                
                
if ($photoid count($this->m_items))
                {
                    
/* If we have such an item ID */
                    
                    
$photo $this->m_items[$photoid];
                    
                    
/* Find the previous photo id */
                    
$prev $photoid $baseCounter 1;
                    if (
$prev 1)
                    {
                        
$prev $maxPhotoId;
                    }
                    
                    
/* Find the next photo id */
                    
$next $photoid $baseCounter;
                    if (
$next $maxPhotoId)
                    {
                        
$next 1;
                    }
                    
                    
/* Get the item's HTML output (full version) */
                    
$result .= $photo->toHTML(new GalleryNavigationData($prev$next));
                }
                
                else
                {
                    
$result .= '<div id="imageholder">Unable to locate the requested gallery item (local_id=' $photoid ').</div>';
                }
            }
            
            else
            {
                
/* Print a list of thumbnails */
                
                
$result .= '<table cellspacing="0" cellpadding="0">';
                
$result .= '<tr><th colspan="' SECTION_ITMS_PER_LINE '">' htmlspecialchars($this->m_name) . '</th></tr>';
                
                for (
$c 0$c count($this->m_items); ++$c)
                {
                    if (
$c SECTION_ITMS_PER_LINE == 0)
                    {
                        if (
$c 0)
                        {
                            
$this->endLine($result);
                        }
                        
                        
$this->startLine($result);
                    }
                    
                    
$result .= '<td><a href="./?photoid=' . ($baseCounter $c) . '" title="Click for a larger view.">';
                    
$result .= $this->m_items[$c]->toHTML(); /* Append this item's HTML output (thumbnail version) */
                    
$result .= '</a></td>';
                }
                
                if (
$c 0)
                {
                    
/* If there has been any output at all, fill the remaining space on
                    -* current line with blank entries and end that line. */
                    
                    
while ($c SECTION_ITMS_PER_LINE != 0)
                    {
                        ++
$c;
                        
$result .= '<td style="background-image: none;"></td>';
                    }
                    
                    
$this->endLine($result);
                }
                
                
$result .= "</table>";
            }
            
            return 
$result;
        }
        
        private function 
startLine(& $str)
        {
            
$str .= "<tr>";
        }
        
        private function 
endLine(& $str)
        {
            
$str .= "</tr>";
        }
        
        public function 
__destruct()
        {
        }
        
    };

?>

< < < Click here to go back to the main site