how are you adding images to the gallery? are you storing the filenames in a db? if so, just add a field to the db to record upload time/date, and then write a query to display the images in time/date descending order.
/**
* Easy Peasy Image Gallery (EPIG)
*
* Copyright(c) 2005 Apostolos (Soumis) Dountsis
*
* @author Apostolos (Soumis) Dountsis
* @email
* @version 1.0.8
* @date 26-April-2005
*
* Revisions:
* 1.0.0 Initial release
* 1.0.2 Added PNG support
* 1.0.3 Sorting for the files is now added
* 1.0.4 Several code optimisations
* 1.0.5 Now 5 pages links are diplayed per line
* 1.0.6 Config file is now an external XML file. Allows user to upgrade EPIG
* and maintain the album settings
* 1.0.7 Bundled as a class. No global variables any more (array is used instead)
* 1.0.8 The popup window where the actual is being displayed is now resized to the
* dimensions of the image and the filebar and addressbar are now removed
* It uses javascript to control the popup window
*
*
* This file creates an image gallery with automatically generated thumbnails for
* all the images (gif, jpg and png) in the current directory.
* The images are sorted by file name. Simply copy this file and
* template to the directory where the pictures reside and you are done.
* EPIG requires PHP4 and GD.
* You can customise EPIG by changing the Configuration Settings to match your preference.
* If you want to customise it further, you can modify the template provided or create your own.
* Instructions on the custom template creation can be found below.
*
*
* Custom Template Instructions
* ----------------------------
* You are more than welcome to modify the template supplied by EPG. You can also create your
* own template by creating an html file and applying the EPIG markers on it.
* Do not forget to change the $template value if the filename is othen than "template.html".
* The EPIG markers are:
* {gallery} : Your thumbnails
* {next} : The link to the next page
* {back} : The link to the back page
* {pages} : A list with all your pages as links
* {title} : The title of your album (optional)
* {description} : A description for your album (optional)
* {author} : Your Name (optional)
*
*
* EPIG License
* ------------
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* TODO: <meta name="publisher" content="EPIG">
*
*/
define('VERSION', '1.0.8');
class epig
{
// Array that holds the user defined settings
var $settings = array();
// Current page on the album
var $current_page;
// The album photos
var $Images = array();
/**
* Default constructor
*
* @param void
* @return void
*/
function epig()
{
// Default Settings (to overide the values, modify the XML file and NOT this array)
$this->settings = array("epig_rows" => 2, // The number of thumbnail rows in each page
"epig_columns" => 2, // The number of thumbnail columns in each page
"thumbnail_width" => 100, // The width of each thumbnail
"thumbnail_height" => 50, // The height of each thumbnail
"thumbnail_quality" => 75, // The quality of each thumbnail. Applies only to JPEG files
"epig_author" => "", // User's name
"epig_email" => "", // User's e-mail address
"epig_title" => "FamilyAlbum", // The album title
"epig_description" => "Family Photos.", // Album description
"template_file" => "template.html", // Template file
"config_file" => "config.xml"); // Config file
/**
* Get contents from XML file and insert into an array
*
* @param string $file
* @return mixed
*/
function xml2php($file)
{
$arr_vals = array();
$xml_parser = xml_parser_create();
if (!($fp = fopen($file, "r")))
{
die("I am sorry but I cannot locate your configuration file with filename <b>$file</b>.");
}
function get_current_page()
{
return $_REQUEST['page'];
}
/**
* Load the XML config file and parse the EPIG elements
*
* @param string $file
* @return void
*/
function load_config($file)
{
$config = $this->xml2php($file);
foreach($config as $element)
{
// if(!empty($element['value']))
// {
switch($element['tag'])
{
case 'title': $this->settings['epig_title'] = $element['value'];
break;
case 'author': $this->settings['epig_author'] = $element['value'];
break;
case 'email': $this->settings['epig_email'] = $element['value'];
break;
case 'description': $this->settings['description'] = $element['value'];
break;
case 'title': $this->settings['epig_title'] = $element['value'];
break;
case 'template': $this->settings['template_file'] = $element['value'];
break;
case 'rows': $this->settings['epig_rows'] = $element['value'];
break;
case 'columns': $this->settings['epig_columns'] = $element['value'];
break;
case 'width': $this->settings['thumbnail_width'] = $element['value'];
break;
case 'height': $this->settings['thumbnail_height'] = $element['value'];
break;
case 'quality': $this->settings['thumbnail_quality'] = $element['value'];
break;
}
// }
}
}
/**
* Checks allowed image extensions
*
* @param string $file
* @return boolean
*/
function validate_image_extension($file)
{
switch(strtolower(substr($file, -4)))
{
case '.jpg': return true;
case '.gif': return true;
case '.png': return true;
default : return false;
}
}
/**
* Reads and sorts all images in the current directory
*
* @param void
* @return void
*/
function load_images()
{
if(empty($this->current_page))
{
$this->current_page = 1;
}
$html .= "<td align=\"center\">
<a href=\"#\" onClick=\"javascript:window.open('{$this->Images[$i]}','actualimage','toolbar=0,menubar=0,width=$image_width,height=$image_height,resizable=1,scrollbars=0,status=0');\" title=\"Click on the thumbnail to see the image in actual size\">
<img class=\"thumbnail\" border=\"0\" src=\"gallery.php?file={$this->Images[$i]}\">
</span>
</td>\n";
}
else
{
$html .= " \n";
}
$col_count++;
}
}
// Copyright footer
$html .= "</table> <div align=\"center\" style=\"font-size:small;color:blue;\"></div><br />
<div style=\"font-size:x-small\">Click on a thumbnail to see the image in actual size</div><br />\n";
return $html;
}
/**
* Displays the 'Next Page' link
*
* @param void
* @return string
*/
function build_next()
{
$html = "";
$pages = ceil(sizeof($this->Images) / ($this->settings['epig_rows'] * $this->settings['epig_columns']));
if($i % 5 == 0) // if the current page can be divided with 5 then line break
{
$html .= "<br />";
}
$i++;
}
return $html;
}
/**
* Loads and populates the template with the EPIG markers
*
* @param void
* @return string
*/
function populate_template()
{
$template_file = '';
// Check if the template exists in the filesystem.
if(!file_exists($this->settings['template_file']))
{
print("I am sorry but I cannot locate your template with filename <b>$this->settings['template_file']</b>.");
}
else
{
// Read the template file and load it into the appropriate attribute.
$template_file = implode("", file($this->settings['template_file']));
}
// Substitute the template markers {} with the contents of the attribute.
$template_file = str_replace('{gallery}', $this->build_gallery(), $template_file);
$template_file = str_replace('{next}', $this->build_next(), $template_file);
$template_file = str_replace('{back}', $this->build_back(), $template_file);
$template_file = str_replace('{pages}', $this->build_numbers(), $template_file);
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.