Location: PHPKode > projects > Exhibitae > exhibitae-1.1-ffd/Exhibitae/archive.php
<?php
/*	This file is part of Exhibitae.

    Exhibitae 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.

    Exhibitae 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/>.
*/

require('includes/include.php');

// Get the albums
$array_images = array();
$albums = new directory_class;
$albums->i = 0;
$albums->path = $ini['c_dir_gallery'];
if ($albums->scan('directories') === false) { header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }
if ($albums->sort_elements() === false) { header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }
$albums->array_directory[] = '.';

$_GET['image'] = stripslashes($_GET['image']);

// Image page
if (!empty($_GET['image']))
{
	$_GET['image'] = ereg_replace('^'.$ini['l_title_miscalaneous'], '.', $_GET['image']);

	// Make sure the image name is not empty
	if (empty($_GET['image']))
	{ $_SESSION['error'] = $ini['l_error_no_image']; error_log(time().'>'.__FILE__.'>'.__LINE__.'>'.$_SESSION['error'].'>'.$_GET['image'].'|', 3, $ini['c_file_log']); header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }

	// Get the images of all albums
	while ($albums->i<count($albums->array_directory))
	{
		$album_path = $albums->array_directory[$albums->i];

		$images = new directory_class;
		$images->path = $albums->path.'/'.$album_path;
		if ($images->scan('images') === false) { header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }
		if ($images->sort_elements() === false) { header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }
		$images->array_directory = array_add_value($images->array_directory, $album_path.'/');

		$array_images = array_merge($array_images, $images->array_directory);
		$albums->i++;
	}

	// Make sure the image exists
	$current_image_id = array_search($_GET['image'], $array_images);
	if ($current_image_id === false)
	{ $_SESSION['error'] = $ini['l_error_no_image']; error_log(time().'>'.__FILE__.'>'.__LINE__.'>'.$_SESSION['error'].'>'.$_GET['image'].'|', 3, $ini['c_file_log']); header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }

	// Set the navigation for surrounding images
	$first_image = ereg_replace('^\./', $ini['l_title_miscalaneous'].'/', $array_images[0]);
	$previous_image = ereg_replace('^\./', $ini['l_title_miscalaneous'].'/', $array_images[($current_image_id-1)]);
	$this_image = ereg_replace('^\./', $ini['l_title_miscalaneous'].'/', $_GET['image']);
	$next_image = ereg_replace('^\./', $ini['l_title_miscalaneous'].'/', $array_images[($current_image_id+1)]);
	$last_image = ereg_replace('^\./', $ini['l_title_miscalaneous'].'/', $array_images[(count($array_images)-1)]);
	$current_image_page = ceil(($current_image_id+1)/$ini['c_ammount_images_per_page']);
	
	// Image display size calculation
	$resize = false;
	$width_resize = false;
	$height_resize = false;
	$width = $ini['c_image_width_maximum'];
	$height = $ini['c_image_height_maximum'];
	$properties = image_get_properties($ini['c_dir_gallery'].'/'.$_GET['album'].'/'.$_GET['image']);

	$resize_rate_width = $properties[0]/$width;
	$resize_rate_height = $properties[1]/$height;
	if ($resize_rate_width>$resize_rate_height && $resize_rate_width>1)
	{
		$height = ($width*$properties[1])/$properties[0];
		$resize = true;
		$height_resize = true;
	}
	elseif ($resize_rate_height>$resize_rate_width && $resize_rate_height>1)
	{
		$width = ($height*$properties[0])/$properties[1];
		$resize = true;
		$width_resize = true;
	}
	
	// Replace by reduction if the dimensions are correct, to reduce bandwidth
	$semithumbnail = false;
	if ($resize && is_file($ini['c_dir_gallery'].'/'.$_GET['album'].'/'.image_remove_extension($_GET['image']).'-'.$ini['c_image_semithumbnail_mode'].'.'.image_get_extension($_GET['image'])))
	{
		$properties_semithumbnail = image_get_properties($ini['c_dir_gallery'].'/'.$_GET['album'].'/'.image_remove_extension($_GET['image']).'-'.$ini['c_image_semithumbnail_mode'].'.'.image_get_extension($_GET['image']));
		if ($properties_semithumbnail[0]==$width && $properties_semithumbnail[1]==$height)
		{
			$resize = false;
			$semithumbnail = true;
		}
		elseif ($properties_semithumbnail[0]>$width && $properties_semithumbnail[1]>$height && $properties_semithumbnail[0]<$properties[0] && $properties_semithumbnail[1]<$properties[1] && ($properties[0]/$properties_semithumbnail[0])==($properties[1]/$properties_semithumbnail[1]))
		{ $semithumbnail = true; }
	}
	
	// No one pixel column should appear left or right of the image
	if (($ini['c_image_width_maximum']%2)!=($width%2))
	{ $width--; }
	
	// Get the image's title and description
	if (is_file($ini['c_dir_gallery'].'/'.$_GET['image'].'.conf'))
	{
		if (is_file($ini['c_dir_gallery'].'/'.ereg_replace("/.*", "", $_GET['image']).'.conf'))
		{
			$ini_db = parse_ini_file($ini['c_dir_gallery'].'/'.ereg_replace("/.*", "", $_GET['image']).'.conf');
			$album_title = $ini_db['title'];
		}
		else
		{ $album_title = ereg_replace("/.*", "", $_GET['image']); }
		
		$ini_db = parse_ini_file($ini['c_dir_gallery'].'/'.$_GET['image'].'.conf');
		$image_title = ereg_replace('^\.', $ini['l_title_miscalaneous'], $album_title).' - '.$ini_db['title'];
		$image_title_navigation = $ini_db['title'];
		db_config_add_view($ini['c_dir_gallery'].'/'.$_GET['image'].'.conf');
	}
	else
	{
		$image_title = eregi_replace("/", " - ", image_remove_extension(ereg_replace('^\./', $ini['l_title_miscalaneous'].'/', $_GET['image'])));
		$image_title_navigation = ereg_replace(".*/", "", image_remove_extension($_GET['image']));
		$ini_db['description'] = '';
		db_config_create($ini['c_dir_gallery'].'/'.$_GET['image'].'.conf', $image_title_navigation, '', 1);
	}
	
	// Load the top
	if ($ini['c_lightbox_image'])
	{ $lightbox = 1; }
	$title = $image_title;
	$navigation_top = array(
		array('title' => $image_title_navigation, 'link' => RELATIVE_DIR.$mod_rewrite_links['archive_to_image'].$_GET['image']),
		array('title' => $ini['l_title_archive'], 'link' => RELATIVE_DIR.$mod_rewrite_links['archive']),
		array('title' => $ini['l_title_index'], 'link' => RELATIVE_DIR.$mod_rewrite_links['index'])
	);
	if ($this_image!=$first_image)
	{
		$first = RELATIVE_DIR.$mod_rewrite_links['archive_to_image'].$first_image;
		$previous = RELATIVE_DIR.$mod_rewrite_links['archive_to_image'].$previous_image;
	}
	if ($this_image!=$last_image)
	{
		$next = RELATIVE_DIR.$mod_rewrite_links['archive_to_image'].$next_image;
		$last = RELATIVE_DIR.$mod_rewrite_links['archive_to_image'].$last_image;
	}
	$navigation_bottom = array('first' => $first, 'previous' => $previous, 'up' => RELATIVE_DIR.$mod_rewrite_links['archive_to_page'].$current_image_page, 'next' => $next, 'last' => $last);
	require('includes/top.php');
	
	// Get the right parameters for the image
	if ($ini['c_lightbox_image'])
	{
		if (is_file($ini['c_dir_gallery'].'/'.image_remove_extension($_GET['image']).'-'.$ini['c_image_semithumbnail_mode'].'.'.image_get_extension($_GET['image'])))
		{ $a = RELATIVE_DIR.$ini['c_dir_gallery'].'/'.image_remove_extension(image_remove_size($_GET['image'])).'-'.$ini['c_image_semithumbnail_mode'].'.'.image_get_extension($_GET['image']); }
		else
		{ $a = RELATIVE_DIR.$ini['c_dir_gallery'].'/'.image_remove_size($_GET['image']); }
		$resize = 1;
	}
	else
	{ $a = RELATIVE_DIR.$ini['c_dir_gallery'].'/'.image_remove_size($_GET['image']); }
	
	// If reduction has the correct dimension, this can reduce bandwidth
	if ($semithumbnail)
	{ $src = $_GET['album'].'/'.image_remove_extension($_GET['image']).'-'.$ini['c_image_semithumbnail_mode'].'.'.image_get_extension($_GET['image']); }

	// Load the page
	$smarty->assign('image', array('link' => $a, 'image' => RELATIVE_DIR.$ini['c_dir_gallery'].'/'.$_GET['image'], 'title' => $title, 'description' => $ini_db['description'], 'width' => $width, 'height' => $height, 'resize' => $resize));
	$smarty->display('image.tpl');
}
// Images page
else
{
	// Make sure the page number is correct
	if (!isset($_GET['page']))
	{ $_GET['page'] = 1; }

	$page = $_GET['page']-1;
	if ($page<0)
	{ header("Location: ".RELATIVE_DIR.$mod_rewrite_links['archive_to_page']."1"); exit; }
	
	// Get the images of all albums
	while ($albums->i<count($albums->array_directory))
	{
		$album_path = $albums->array_directory[$albums->i];

		$images = new directory_class;
		$images->i = 0;
		$images->path = $albums->path.'/'.$album_path;
		if ($images->scan('images') === false) { header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }
		if ($images->sort_elements() === false) { header("Location: ".RELATIVE_DIR.$mod_rewrite_links['error']); exit; }
		$images->array_directory = array_replace_by_thumbnail($images->array_directory);
		$images->array_directory = array_add_value($images->array_directory, $album_path.'/');

		$array_images = array_merge($array_images, $images->array_directory);
		$albums->i++;
	}

	// Make sure the page number is not bigger than the last page
	$last_page = (ceil(count($array_images)/$ini['c_ammount_images_per_page'])-1);
	if ($page>$last_page && $page!=0)
	{ header("Location: ".RELATIVE_DIR.$mod_rewrite_links['archive_to_page'].($last_page+1)); exit; }

	// Make an error with all the image's parameters
	$output = array_echo_images(array_slice($array_images, ($page*$ini['c_ammount_images_per_page']), $ini['c_ammount_images_per_page']), $mod_rewrite_links['archive_to_image']);

	// Load the page
	$space = 1;
	$width = $output[1];
	if ($ini['c_lightbox_imagelist'])
	{ $lightbox = 1; }
	$title = $ini['l_title_archive'];
	$header = $ini['c_header_archive'];
	$navigation_top = array(
		array('title' => $ini['l_title_archive'], 'link' => RELATIVE_DIR.$mod_rewrite_links['archive']),
		array('title' => $ini['l_title_index'], 'link' => RELATIVE_DIR.$mod_rewrite_links['index'])
	);
	if ($page)
	{
		$first = RELATIVE_DIR.$mod_rewrite_links['archive_to_page'].'1';
		$previous = RELATIVE_DIR.$mod_rewrite_links['archive_to_page'].$page;
	}
	if ($page!=$last_page)
	{
		$next = RELATIVE_DIR.$mod_rewrite_links['archive_to_page'].($page+2);
		$last = RELATIVE_DIR.$mod_rewrite_links['archive_to_page'].($last_page+1);
	}
	$navigation_bottom = array('first' => $first, 'previous' => $previous, 'up' => RELATIVE_DIR.$mod_rewrite_links['index'], 'next' => $next, 'last' => $last);
	require('includes/top.php');

	$smarty->assign('imagelist', $output[0]);
	$smarty->display('imagelist.tpl');
}

require('includes/bottom.php');
?>
Return current item: Exhibitae