All pastes #147271 Raw Edit

blazer1

public php v1 · immutable
#147271 ·published 2006-08-24 08:24 UTC
rendered paste body
<?php	//this function accepts a directory name and returns	//a listing of all sub directories	function return_directory_list($target_dir)	{		$dir_list = array();		$i = 0;		$handle = opendir($target_dir);		while ($target_dir != '' && $file = readdir($handle))		{			if ($file != "." && $file != ".." && is_dir($target_dir."/".$file))			{				$dir_list[$i] = $file;				$i++;			}		}		closedir($handle);		return $dir_list;	}	//this function rearranges the directory name into a presentable	//form, of format: dd/mm/yyyy name	function directory_name($dir_name)	{		$presentable_link = explode("_", $dir_name);		$return_link = $presentable_link[0]."/".$presentable_link[1]."/".$presentable_link[2].":&nbsp;&nbsp;".$presentable_link[3];		return $return_link;	}	//this function returns a html row-by-row menu of sub-albums	//reading from the relative directory: 'gallery'	function return_sub_albums()	{		$album_names = return_directory_list('gallery');		$return_menu_table = "<link href='gallery.css' rel='stylesheet' type='text/css'>";		$return_menu_table .= "<div='submenu'>\r";		$return_menu_table .= "<table width = '100%'>\r";		if (is_array($album_names))		{			foreach ($album_names as $album_name)			{				$return_menu_table .= "<tr><td>";				$return_menu_table .= "<a href='thumbs.php?index=0&dir=".urlencode($album_name)."'>".directory_name($album_name)."</a>";				$return_menu_table .= "</td></tr>\r";			}		}		$return_menu_table .= "</table>\r";		$return_menu_table .= "<div='submenu'>\r";		$return_menu_table .= "</link>";		return $return_menu_table;	}	//this function returns an array of valid image filenames within the supplied	//relative directory	function return_image_filenames($dir_name)	{		$file_list = array();		$i = 0;		$ext = '';		if (is_dir($dir_name))		{			$handle = opendir($dir_name);			while ($dir_name != '' && $file = readdir($handle))			{				$ext = strrchr( $file, '.' );				if (!is_dir($dir_name."/".$file) && $ext == '.jpg' || $ext == '.gif')				{					$file_list[$i] = $file;					$i++;				}			}			closedir($handle);		}		sort($file_list);		return $file_list;	}	//this function returns all the start indexes (also previous)	function return_factors($total, $multiple)	{		$factors = array();		$curr_factor = 0;		array_push($factors, 0);		while ($curr_factor < $total)		{			$curr_factor += $multiple;			if ($curr_factor <= $total)				array_push($factors, $curr_factor);		}		return $factors;	}	function return_previous($start_index, $max_thumbs, $num_images, $gallery)	{		$start_indexes = return_factors ($num_images, $max_thumbs);		$prev_index = $start_indexes[array_search($start_index, $start_indexes)-1];		if (is_integer($prev_index))			$return_prev = "<a href='thumbs.php?index=".$prev_index."&dir=".urlencode($gallery)."'>Prev</a>&nbsp;&nbsp;&nbsp;&nbsp;";		return $return_prev;	}	function return_next($start_index, $max_thumbs, $num_images, $gallery)	{		$start_indexes = return_factors ($num_images, $max_thumbs);		$next_index = $start_indexes[array_search($start_index, $start_indexes)+1];		if (is_integer($next_index))			$return_next = "<a href='thumbs.php?index=".$next_index."&dir=".urlencode($gallery)."'>Next</a>";		return $return_next;	}	//at the moment this function is replica of return_thumbnails_table in structure	//but it returns a css defined list which takes care of thumb wrapping	function return_thumbnails($max_thumbs=20, $start_index=-1, $gallery='')	{		$image_files = return_image_filenames('gallery/'.$gallery);		if (sizeof($image_files) != 0 && $start_index >= 0 && is_numeric($start_index))		{			$thumbs_table = "<link href='gallery.css' rel='stylesheet' type='text/css'>";			$thumbs_table .= "<div class = 'thumbs'>\r";			$thumbs_table .= "<div class = 'row'>\r";			$thumbs_table .= "<span class='left'>".return_previous($start_index, $max_thumbs, sizeof($image_files), $gallery)."</span>";			$thumbs_table .= "<span class='right'>".return_next($start_index, $max_thumbs, sizeof($image_files), $gallery)."</span>";			$thumbs_table .= "</div>\r";			$index_counter = $start_index;			$thumb_counter = 0;			$thumbs_table .= "<ul>\r";			while ($index_counter <= sizeof($image_files)-1)			{				$thumbs_table .= "<li><a href = 'enlarge.php?dir=".urlencode($gallery)."&index=".$index_counter."'>								<img src='gallery/".$gallery."/".$image_files[$index_counter]."'></a></li>\r";				$index_counter++;				$thumb_counter++;				if ($thumb_counter == $max_thumbs)				{					break;//out of while loop				}			}			$thumbs_table .= "</ul>\r";			$thumbs_table .= "</span>";			$thumbs_table .= "</div>\r";		}		else		{			$thumbs_table = return_sub_albums();		}		return $thumbs_table;	}	function return_thumbnails_table($columns=4, $max_thumbs=20, $start_index=-1, $gallery='')	{		$image_files = return_image_filenames('gallery/'.$gallery);		if (sizeof($image_files) != 0 && $start_index >= 0 && is_numeric($start_index))		{			$thumbs_table = "<table cellpadding = '1' cellspacing = '1' width='100%'>\r";			$col_count = 1;			$index_counter = $start_index;			$thumb_counter = 0;			while ($index_counter < sizeof($image_files))			{				if ($col_count == 1)					$thumbs_table .= "<tr>\r\r";				$thumbs_table .= "<td><a href = 'enlarge.php?dir=".urlencode($gallery)."&index=".$index_counter."'>								<img width = '100' height = '100' src='gallery/".$gallery."/".$image_files[$index_counter]."'></a></td>\r";				$col_count++;				$index_counter++;				$thumb_counter++;				if ($col_count == ($columns + 1))				{					$thumbs_table .= "</tr>\r\r";					$col_count = 1;				}				if ($thumb_counter == $max_thumbs)				{					break;//out of while loop				}			}			if ($col_count <= $columns && $col_count > 1)				$thumbs_table .= "</tr>\r\r";			$thumbs_table .= "</table>\r";			echo return_previous($start_index, $max_thumbs, sizeof($image_files), $gallery);			echo return_next($start_index, $max_thumbs, sizeof($image_files), $gallery);		}		else		{			$thumbs_table = return_sub_albums();		}		return $thumbs_table;	}	//this function returns the "previous" link for the enlarged picture slide	function return_prev_link($index='-1', $gallery)	{		if ($index < 0 || !is_numeric($index))		{			$return_prev_link = "";//nothing		}		else		{			$return_prev_link = "<a href='enlarge.php?dir=".urlencode($gallery)."&index=".($index)."'>prev</a>";		}		return $return_prev_link;	}	//this function returns the "next" link for the enlarged picture slide	function return_next_link($index='', $gallery, $max_index)	{		if (!is_numeric($index) || $index == $max_index)		{			$return_next_link = "";//nothing		}		else		{			$return_next_link = "<a href='enlarge.php?dir=".urlencode($gallery)."&index=".($index)."'>next</a>";		}		return $return_next_link;	}	//this function returns the enlarged version of the selected thumbnail with appropriate prev/next links	function return_enlarge_picture($index = '', $gallery='')	{		$image_files = return_image_filenames('gallery/'.$gallery);		if (sizeof($image_files) != 0 && $index <= sizeof($image_files) && $gallery != '' && is_numeric($index) && $index >= 0)		{			$return_enlarge_table = "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\r";			$return_enlarge_table .= "<tr>\r";			$return_enlarge_table .= "<td width='20%'></td>";			$return_enlarge_table .= "<td width='60%'>";			$return_enlarge_table .= "<p align='center'><img src='gallery/".$gallery."/".$image_files[$index]."'></p></td>";			$return_enlarge_table .= "<td width='20%'></td>";			$return_enlarge_table .= "</tr>";			$return_enlarge_table .= "<tr>";			$return_enlarge_table .= "<td width='20%'><p align='right'>".return_prev_link($index-1, $gallery)."</p></td>";			$return_enlarge_table .= "<td width='60%'></td>";			$return_enlarge_table .= "<td width='20%'><p align='left'>".return_next_link($index+1, $gallery, sizeof($image_files))."</p></td>";			$return_enlarge_table .= "";			$return_enlarge_table .= "</tr>";			$return_enlarge_table .= " </table>";		}		else		{			$return_enlarge_table = return_sub_albums();		}		return $return_enlarge_table;	}?>