[b]Let op: dit is niet het gehele script![/b]

[code]
<?php

/**
 * index.php
 *
 */

function galleryAutoload($cls_name){
 	require_once str_replace('_','/',$cls_name).'.php';
}

spl_autoload_register('galleryAutoload');


$gallery = new Lib_Gallery();
$gallery->dispatch();



/**
 * Lib/Gallery.php
 *
 */


class Lib_Gallery {
	
	/**
	 * Enter description here...
	 *
	 * @var array
	 */
	protected $options = array(
		'dir' => 'photos/',
		'thumb' => array( // Thumbs options
			'dir' => 'thumbs/', // in the $this->options['dir'] dir
			'size'  => 150
		),
		'medium' => array( // Medium photo size options
			'dir' => 'medium/', // in the $this->options['dir'] dir
			'size' => 500
		),
		'orig' => array( // The origional photos
			'dir' => 'orig/' // in the $this->options['dir'] dir
		),
		'extensions' => array('.jpg','.gif','.png','.jpeg'), // lowercase file extension
		'view_options' => array( // The view options
			'dir' => 'templates/' // The template dir
		),
		'photos_per_page' => 12,
		'gallery_title' => 'My Gallery'
	);
	
	/**
	 * The params parsed from the URL
	 *
	 * @var array
	 */
	protected $urlParams = array();
	
	/**
	 * The view object / template parser
	 *
	 * @var Lib_Template_Interface
	 */
	protected $view;
	
	public function __construct($options=null){
		if(is_array($options)){
			$this->setOptions($options);
		}elseif(!empty($options)){
			throw new InvalidArgumentException('The $options argument must be an array or must be empty');
		}
		$this->urlParams = (array) $_GET;
	}
	
	/**
	 * Set the options recursively
	 *
	 * @param array $options
	 * @param int $level (recursive level)
	 * @return array
	 */
	protected function setOptions(array $options,$level=0){
		$newOptions = array();
		
		foreach($options as $key => $option){
			if(is_array($option)){
				$newOptions[$key] = $this->setOptions($option,$level++);
			}else{
				$newOptions[$key] = $option;
			}
		}
		if($level === 0){
			$this->options = $newOptions;
		}
		return $newOptions;
	}
	
	/**
	 * Set the URL params. 
	 * By default the $this->urlParams is the $_GET array
	 *
	 * @param array $params
	 */
	public function setUrlParams(array $params){
		$this->urlParams = $params;
	}
	
	/**
	 * If you would like to use smarty/dwoo or an other template engine.
	 * you can extend smarty en implement Lib_Template_Interface and use
	 * smarty/dwoo/templatepower
	 *
	 * @param Lib_Template_Interface $view
	 */
	public function setView(Lib_Template_Interface $view){
		$this->view = $view;
	}
	
	/**
	 * Return or show the gallery
	 *
	 * @param bool $return
	 */
	public function dispatch($return = false){
		if(!($this->view instanceof Lib_Template_Interface)){
			$this->view = new Lib_Template($this->options['view_options']);
		}

		if(!empty($this->urlParams['dir']) && !empty($this->urlParams['photo'])){
			// A dir and a photo is selected
			$page = new Lib_Gallery_Photo($this->urlParams['dir'],$this->urlParams['photo']);
		}elseif(!empty($this->urlParams['dir'])){
			// only a dir is selected
			$page = new Lib_Gallery_Dir($this->urlParams['dir']);
		}else{
			// Nothing at all is selected
			$page = new Lib_Gallery_Albums();
		}
		
		if($page instanceof Lib_Gallery_Page_Interface){		
			$page->setOptions($this->options);
			$page->setUrlParams($this->urlParams);
			$page->setView($this->view);
			$page->init();
			
			if($return){
				return $page->fetch();
			}else{
				echo $page->fetch();
			}
		}else{
			throw new Exception(get_class($page).' is not an instance of Lib_Gallery_Page_Interface');
		}
	}	
	
}
?>
[/code]