View Single Post
Old 11-30-2007, 07:01 PM   #6 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,053
Thanks: 115
Tanax is on a distinguished road
Default

Index.php
Located in root folder

So finally, the last piece of script!
The script that pulls everything together, and uses all the classes and everything!

Let's see how it looks:

PHP Code:
    include('config.php');
    
    
// Loads the default HTML page.
    
$page $tpl->load('index');
    
    
// Initiate the array of content.
    
$array = array();
    
    
// Gets the current folder from the URL.
    
$gallery->getFolder();
    
    
// Gets the current page from the URL.
    
$gallery->getPage();
    
    
// Gets the current picID from the URL.
    
$gallery->getPicture();
    
    
// Sets the folder to load picture from, based on what the current folder is set in the URL.
    
$gallery->setPicFolder();
    
    
// Gets the total amount of pictures from the current picFolder.
    
$gallery->getTotalPics();
    
    
// Gets the total amount of pages based on how many pictures there exists in the picFolder.
    
$gallery->getTotalPages();
    
    
// Gets the first image on the current page based on what page the user is viewing.
    
$gallery->getFirstImage();
    
    
// Gets the folder links.
    
$totalFolders $gallery->printFolders();
    
    
// Checks if there isn't any folders.
    
$noFolders $gallery->getFolders();
    
    
// Assigns the key "folders" the value of the returned value from the folder links.
    
$array['folders'] = $totalFolders;
    
    
// If the user is viewing the index.
    
if(!$gallery->is_set('folder')) {
        
        
        
$content 'Welcome to the gallery! Click on one of the folders to the left in order to view the images!';
        
$content .= $noFolders;
        
$array['title'] = 'Gallery | Index';
                
    }
    
    
// If the user is viewing the gallery.
    
elseif(!$gallery->is_set('pic')) {
        
        
        
$pages $gallery->printPageLinks();    
        
$images $gallery->printImages();

        
$array['title'] = 'Gallery | ' .$gallery->getValue('folder');    
        
$page $tpl->load('gallery');


    }
    
    
// If the user is viewing a picture.
    
elseif($gallery->is_set('pic')) {
            
        
        
$image $gallery->printImage();
        
        
$array['title'] = 'Gallery | ' .$gallery->getValue('folder'). ' | Picture ' .$gallery->getValue('pic');
        
        
        
$page $tpl->load('view');
            
    }
    
    
    
// Assigns values in the array.
    
$array['image'] = $image;
    
$array['pagelinks'] = $pages;
    
$array['images'] = $images;
    
$array['content'] = $content;
    
    
// Outputs the page.
    
$tpl->output($page$array); 
First thing we do, is include our config file. We then load the index.tpl file for our template.

After that we set a bunch of variables. You should be able to read the comments in the code to see what they do.

Actually, everything is pretty explained in the code.
Just read the comments.

One thing though. We do not parse the site until the very end of the script.
Because if the user is viewing a gallery, we load another file instead of the index.tpl.
And if they're viewing an image, we load another file.

Also one other thing!
You can see, $image variable only exists if the user is viewing a special picture. But we still assign that to the $array in the end, and outputs it with the loaded file.

The way it works is, that if the value is empty, it won't echo out anything, and we haven't included {image} in any other .tpl file than the one the viewer is using when viewing a specific picture, which is view.tpl



I really hope you've learned something about at least something.
It's really a MAJOR tutorial, and probably most of you won't bother reading through the whole thing.

But if you do read through it, maybe you can come up with a way so the functions in the gallery class only returns DATA, and no actual HTML output. And then you can decide exactly how to format the things, within the templatefiles.

But that's for you to figure out!


NOTE!
The images in the different folders, have to be named in numeric order, such as:
0
1
2
3
4
5

The fileformat can be other than .jpg, but all images must have same fileformat!
You can just edit the fileformat in the config.php


Signing out, hope you had a nice read.
Thanks
// Tanax
Attached Files
File Type: php gallery.php (16.5 KB, 471 views)
File Type: php template.php (1.1 KB, 395 views)
File Type: php config.php (2.1 KB, 486 views)
File Type: xml desc.xml (679 Bytes, 353 views)
File Type: php index.php (2.4 KB, 532 views)

Last edited by Tanax : 11-30-2007 at 07:58 PM.
Tanax is offline  
Reply With Quote
The Following 4 Users Say Thank You to Tanax For This Useful Post:
Gibou (11-30-2007), iflashlord (05-03-2009), Nor (12-04-2007), Wildhoney (11-30-2007)