AutoGalery
#1 Guest_TScafa_*
Posted 05 March 2005 - 01:09 PM
#2 Guest_TScafa_*
Posted 05 March 2005 - 03:37 PM
IMPORTANT
document must not be cacheable!!!
/*
Auto Galery Script
*/
$params = array(
'gallery' => 'Your Galery',
'error' => 'Fehlermeldung',
'php_error' => 'PHP >= 4.1 erforderlich.',
'gd_error' => 'GD-Bibliothek erforderlich. Siehe http://www.boutell.com/gd/.',
'jpg_error' => 'JPEG-Software erforderlich. Siehe ftp://ftp.uu.net/graphics/jpeg/.',
'mkdir_error' => 'Schreibrechte fehlen.',
'opendir_error' => 'Das Verzeichnis "%1" darf nicht beschrieben werden.',
'autogalerypath' => 'assets/images/'
);
/**
Private Functions
*/
/*
* @return String
* @param String $prm
* @desc Private Function for returning parsed strings from function _html()
*/
function _word ($prm) {
global $params;
return _html($params[$prm]);
}
/**
* @return String
* @param String $prm
* @desc Private Function for converting special chars to html conform entities
*/
function _html ($prmh) {
global $charset;
//return htmlentities($prmh, ENT_COMPAT, $charset); // with charset functionality
return htmlentities($prmh, ENT_COMPAT); // without charset functionality
}
/**
* @return String
* @param String $prm
* @param Variant $arg
* @desc Private Function for returning error messages while executing script
*/
function _error ($prm, $arg = '') {
global $params;
return _html(str_replace('%1', $arg, $params[$prm .'_error']));
}
/*
Public Functions
*/
/**
* @return void
* @param String $_galpath
* @param String $_thumbdir
* @param Bool $_included
* @param Bool $_inline
* @param String $_charset
* @param Integer $_thumbsize
* @param Integer $_maxpics
* @param Bool $_filenames
* @param Bool $_subdirs
* @param Bool $_title
* @param String $_bg
* @param String $_delim
* @param Integer $_fontsize
* @desc OpenSource Auto Galery Function Set (osAGFS)
* is a self-creating galeries script:
* Features:
* - osAGFS parses image Dirs recursively and
* - creates thumbnails via GD-Lib
* - trailing navigation within directories,
* - customizeable thumb size and
* - picture list,
* - auto-creating thumbnail directories,
* - includeable or standalone (if standalone => create new php-script)
* - simple error messages
* Requirements:
* PHP 4.1 above
* GD-Lib, JPEG
*/
function autogalery($__galpath = null)
{
global $params;
//global $_SERVER; // uncomment with charset functionality (uncomment _html)
//$_containerHAC = explode(",",$_SERVER["HTTP_ACCEPT_CHARSET"]); // for getting the initial charset of a requesting browser
//$_charset = $_containerHAC[0]; // uncomment for charset functionality
$_charset;
$_maxpics = 12;
$_thumbdir = "mini";
$_thumbsize = 120;
$_filenames = false;
$_subdirs = true;
$_title = $params["gallery"];
$_picdir = $__galpath;
$_included = true;
$_inline = true;
$_bg = "FFFFFF";
$_delim = "\\";
isset($_SERVER) || ($_error = _error('php'));
function_exists('imagecreate') || ($_error = _error('gd'));
function_exists('imagejpeg') || ($_error = _error('jpg'));
if (function_exists('ini_set')) {
@ini_set('memory_limit', -1);
}
$_jpg = '\.jpg$|\.jpeg$';
$_gif = '\.gif$';
$_png = '\.png$';
$_fontsize = 2;
if ($_included==false) {
// You may change the html-code for your own affords
$buffer = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n".
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n".
"<head>\n".
"<meta http-equiv=\"content-type\" content=\"text/html; charset=" . $__charset . "\" />\n".
"<style type=\"text/css\">\n".
"body { font-family: sans-serif }\n".
"hr { border-style: none; height: 1px; background-color: silver; color: silver }\n".
"p { margin: 0px; padding: 0px }\n".
"#pagenumbers { text-align: center; margin: 0px 1em 0px 1em }\n".
"img { margin: 10px; border: none }\n".
"a { text-decoration: none }\n";
if ($_filenames) {
$buffer .= "div a p { font-size: small }\n".
"a:hover p { text-decoration: underline }\n".
"div { width: " . ($_thumbsize + 20) . "px; text-align: center; float: left; margin: 1em }\n";
}
$buffer .= "</style>\n";
}
if (array_key_exists('dir', $_REQUEST) && $_subdirs==true)
$_dir = $_REQUEST['dir'];
else
$_dir = '';
if (!empty($_SERVER['PATH_TRANSLATED']))
$_d = dirname($_SERVER['PATH_TRANSLATED']);
elseif (!empty($_SERVER['SCRIPT_FILENAME']))
$_d = dirname($_SERVER['SCRIPT_FILENAME']);
else
$_d = getcwd();
$_delim = (substr($_d, 1, 1) == ':') ? '\\' : '/';
$_rp = function_exists('realpath');
if ($_rp)
$_root = realpath($_d . $_delim . $_picdir);
else
$_root = $_d . $_delim . $_picdir;
if ($_rp)
$_realdir = realpath($_root . $_dir);
else
$_realdir = $_root . $_dir;
if (substr($_realdir, 0, strlen($_root)) != $_root)
{
$_realdir = $_root;
$_dir = '';
}
$_dirname = substr($_realdir, strlen($_root));
$_dirnamehttp = $_picdir . $_dir;
if ($_delim == '\\') $_dirnamehttp = strtr($_dirnamehttp, '\\', '/');
if (substr($_dirnamehttp, 0, 2) == './')
$_dirnamehttp = substr($_dirnamehttp, 2);
if (empty($_dirnamehttp)) $_dirnamehttp = '.';
$_ti = ($_subdirs && !empty($_dirname)) ? ": $_dirname" : '';
if ($_included==false) {
if (isset($_error))
$buffer .= "<title>$_error</title>";
else
$buffer .= "<title>" . _word('gallery') . _html($_ti) . "</title>\n";
$buffer .= "</head>\n<body>\n";
}
if (($_d = @opendir($_realdir)) === false) $_error = _error('opendir', array($_realdir));
if (isset($_error))
$buffer .= "<p style=\"color: red\">$_error</p>\n";
else {
if ($_title)
$buffer .= "<h1>" . _word($params["gallery"]) . substr(_html($_ti),3) . "</h1>\n<hr />\n";
$_dirs = $_pics = array();
$_query = $_jpg;
if (function_exists('imagecreatefromgif'))
$_query .= "|$_gif";
if (function_exists('imagecreatefrompng'))
$_query .= "|$_png";
while (($_filename = readdir($_d)) !== false) {
if ($_filename == $_thumbdir || ($_filename == '..' && $_dirname == '') || ($_filename != '..' && substr($_filename, 0, 1) == '.'))
continue;
$_file = $_realdir . $_delim . $_filename;
if (is_dir($_file))
$_dirs[] = $_filename;
elseif (eregi($_query, $_file))
$_pics[] = $_filename;
}
closedir($_d);
sort($_dirs);
sort($_pics);
$_urlsuffix = '';
foreach ($_GET as $_v => $_r) {
if (!in_array($_v, array('dir', 'pic', 'offset')))
$_urlsuffix .= "&$_v=" . urlencode($_r);
}
if ($_included && $_inline && array_key_exists('pic', $_REQUEST)) {
$_pic = $_GET['pic'];
$buffer .= "<div id=\"picture\">\n";
$buffer .= "<img src=\"" . _html("$_dirnamehttp/{$_pics[$_pic]}") ."\" alt=\"" . _html(basename($_pics[$_pic])) . "\"";
//list($_width, $_height, $_type, $_attr) = @getimagesize($_pic);
if (!empty($_width))
$buffer .= " style=\"width: {$_width}px; height: {$_height}px\"";
$buffer .= " />\n";
$_url = ($_dirname == '') ? '?' : '?dir=' . urlencode($_dirname) . '&';
$buffer .= "<hr />\n";
if ($_pic > 0)
$buffer .= "<a href=\"" . _html($_url) . "pic=" . ($_pic - 1) . _html($_urlsuffix) . "\">[zurück]</a> ";
if ($_pic >= $_maxpics){
$_u = "{$_url}offset=" . (floor($_pic / $_maxpics) * $_maxpics) . $_urlsuffix;
}
else {
if (array_key_exists('dir', $_REQUEST)) {
$_u = substr($_url, 0, strlen($_url) - 1) . $_urlsuffix;
} else {
$_u = ereg_replace('^([^?]+).*$', '\1', $_SERVER['REQUEST_URI']);
if (!empty($_urlsuffix)) {
if (strstr($_u, '?') === false)
$_u .= '?' . substr($_urlsuffix, 1);
else
$_u .= $_urlsuffix;
}
}
}
$buffer .= "<a href=\"" . _html($_u) . "\">[Übersicht]</a>";
if ($_pic + 1 < sizeof($_pics)){
$buffer .= " <a href=\"" . _html($_url) . "pic=" . ($_pic + 1) . _html($_urlsuffix) . "\">[weiter]</a>";
}
$buffer .= "\n</div>\n";
} else {
if (sizeof($_dirs) > 0 && $_subdirs) {
$buffer .= "<ul id=\"directories\">\n";
foreach ($_dirs as $_filename){
if ($_rp){
$_target = substr(realpath($_realdir . $_delim . $_filename), strlen($_root));
} else {
$_target = substr($_realdir . $_delim . $_filename, strlen($_root));
}
if ($_delim == '\\'){
$_target = strtr($_target, '\\', '/');
}
if ($_target == '') {
$_url = ereg_replace('^([^?]+).*$', '\1', $_SERVER['REQUEST_URI']);
if (!empty($_urlsuffix)) {
if (strstr($_url, '?') === false)
$_url .= '?' . substr($_urlsuffix, 1);
else
$_url .= $_urlsuffix;
}
} else {
$_url = '?dir=' . urlencode($_target) . $_urlsuffix;
}
$buffer .= "<li><a href=\"" . _html($_url) . "\">" . _html($_filename) . "</a></li>\n";
}
$buffer .= "</ul>\n<hr />\n";
}
if (($_num = sizeof($_pics)) > 0) {
if (array_key_exists('offset', $_REQUEST)) {
$_offset = $_REQUEST['offset'];
} else {
$_offset = 0;
}
if ($_num > $_maxpics) {
$buffer .= "<p id=\"pagenumbers\">\n";
for ($_i = 0; $_i < $_num; $_i += $_maxpics) {
$_e = $_i + $_maxpics - 1;
if ($_e > $_num - 1)
$_e = $_num - 1;
if ($_i != $_e)
$_b = ($_i + 1) . '-' . ($_e + 1);
else
$_b = $_i + 1;
if ($_i == $_offset) {
$buffer .= "<b>$_b</b>";
} else {
$_url = ($_dirname == '') ? '?' : '?dir=' . urlencode($_dirname) . '&';
$buffer .= "<a href=\"{$_url}offset=$_i" . _html($_urlsuffix) . "\">$_b</a>";
}
if ($_e != $_num - 1)
$buffer .= " |";
$buffer .= "\n";
}
$buffer .= "</p>\n<hr />\n";
}
$buffer .= "<p id=\"pictures\">\n";
for ($_i = $_offset; $_i < $_offset + $_maxpics; $_i++) {
if ($_i >= $_num) break;
$_filename = $_pics[$_i];
$_file = $_realdir . $_delim . $_filename;
if (!is_readable($_file)) continue;
if (!is_dir($_realdir . $_delim . $_thumbdir)) {
$_u = umask(0);
if (!@mkdir($_realdir . $_delim . $_thumbdir, 0777)) {
$buffer .= "<p style=\"color: red; text-align: center\">" . _word('mkdir_error') . "</span>";
break;
}
umask($_u);
}
$_thumb = $_realdir . $_delim . $_thumbdir . $_delim . $_filename . '.thumb.jpg';
if (!is_file($_thumb)) {
if (eregi($_jpg, $_file))
$_original = @imagecreatefromjpeg($_file);
elseif (eregi($_gif, $_file))
$_original = @imagecreatefromgif($_file);
elseif (eregi($_png, $_file))
$_original = @imagecreatefrompng($_file);
else
continue;
if ($_original) {
if (function_exists('getimagesize'))
list($_width, $_height, $_type, $_attr) = @getimagesize($_file);
else
continue;
if ($_width >= $_height && $_width > $_thumbsize) {
$_smallwidth = $_thumbsize;
$_smallheight = floor($_height / ($_width / $_smallwidth));
$_ofx = 0; $_ofy = floor(($_thumbsize - $_smallheight) / 2);
} elseif ($_width <= $_height && $_height > $_thumbsize){
$_smallheight = $_thumbsize;
$_smallwidth = floor($_width / ($_height / $_smallheight));
$_ofx = floor(($_thumbsize - $_smallwidth) / 2); $_ofy = 0;
} else {
$_smallheight = $_height;
$_smallwidth = $_width;
$_ofx = floor(($_thumbsize - $_smallwidth) / 2);
$_ofy = floor(($_thumbsize - $_smallheight) / 2);
}
}
if (function_exists('imagecreatetruecolor'))
$_small = @imagecreatetruecolor($_thumbsize, $_thumbsize);
else
$_small = @imagecreate($_thumbsize, $_thumbsize);
sscanf($_bg, "%2x%2x%2x", $_red, $_green, $_blue);
$_b = @imagecolorallocate($_small, $_red, $_green, $_blue);
imagefill($_small, 0, 0, $_b);
if ($_original) {
if (function_exists('imagecopyresampled'))
@imagecopyresampled($_small, $_original, $_ofx, $_ofy, 0, 0, $_smallwidth, $_smallheight, $_width, $_height);
else
@imagecopyresized($_small, $_original, $_ofx, $_ofy, 0, 0, $_smallwidth, $_smallheight, $_width, $_height);
} else {
$_black = @imagecolorallocate($_small, 0, 0, 0);
$_fw = @imagefontwidth($_fontsize);
$_fh = @imagefontheight($_fontsize);
$_htw = ($_fw * strlen($_filename)) / 2;
$_hts = $_thumbsize / 2;
@imagestring($_small, $_fontsize, $_hts - $_htw, $_hts - ($_fh / 2), $_filename, $_black);
@imagerectangle($_small, $_hts - $_htw - $_fw - 1, $_hts - $_fh, $_hts + $_htw + $_fw - 1, $_hts + $_fh, $_black);
}
@imagejpeg($_small, $_thumb);
}
if ($_filenames)
$buffer .= "<div>";
if ($_included==true && $_inline) {
$buffer .= "<a href=\"?";
if (array_key_exists('dir', $_REQUEST))
$buffer .= "dir=" . urlencode($_REQUEST['dir']) . "&";
$buffer .= "pic=". $_i . _html($_urlsuffix);
} else {
$buffer .= "<a href=\"" . _html("$_dirnamehttp/$_filename");
}
$buffer .= "\"><img src=\"" . _html("$_dirnamehttp/$_thumbdir/$_filename.thumb.jpg");
$buffer .= "\" alt=\"" . _html($_filename) . "\" style=\"";
$buffer .= "width: {$_thumbsize}px; height: {$_thumbsize}px\" />";
if ($_filenames)
$buffer .= "<p>" . _html($_filename) . "</p>";
$buffer .= "</a>";
if ($_filenames)
$buffer .= "</div>\n";
else
$buffer .= "\n";
}
$buffer .= "</p>\n";
}
}
}
if (!$_included==false) {
$buffer .= "</body>\n</html>";
}
return $buffer;
}
$output = autogalery($params["autogalerypath"]);
return $output;
#3
Posted 05 March 2005 - 03:45 PM
I haven't taken much time to check the code... All I did was to try a couple different image directories, includinf my assets/images/...
#4
Posted 05 March 2005 - 03:54 PM
« Etomite Parse Error »
Etomite encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »
PHP error debug
Error: htmlentities(): charset `ANSI_X3.4-1968' not supported, assuming iso-8859-1
Error type/ Nr.: Warning - 2
File: /var/www/html/index.php(558) : eval()'d code
Line: 38
Parser timing
MySQL: 0.0208 s s (8 Requests)
PHP: 0.1757 s s
Total: 0.1964 s s
EDIT
Considering how there is no variable assignment to $charset, removing the variable corrects the problem...
Changed:
/**
* @return String
* @param String $prm
* @desc Private Function for converting special chars to html conform entities
*/
function _html ($prmh) {
global $charset;
return htmlentities($prmh, ENT_COMPAT, $charset);
}
To:
/**
* @return String
* @param String $prm
* @desc Private Function for converting special chars to html conform entities
*/
function _html ($prmh) {
return htmlentities($prmh, ENT_COMPAT);
}
#5 Guest_TScafa_*
Posted 06 March 2005 - 10:16 AM
global $_SERVER;
$_containerHAC = explode(",",$_SERVER["HTTP_ACCEPT_CHARSET"]); // for getting the initial charset of a requesting client browser
$_charset = $_containerHAC[0];
If you want to use charset functionality than place code above into function autogalery()
#6
Posted 14 June 2005 - 02:40 PM
ITS GREAT! Just what i needed!
Creates subdirectory's, reads all images, CREATES AUTOMATIC thumbs!, thumbsize is set as easy as ...
The only thing is the etomite linkback on the bottom, I have this showing on the main site and now its also showing on the gallery page, so its there twice.
I love Etomite, I do
Anybody to tell me how to remove it from te snippet?
Thanks!
#7
Posted 14 June 2005 - 02:56 PM
#8
Posted 14 June 2005 - 03:00 PM
Ravage, on Jun 14 2005, 05:40 PM, said:
...
Anybody to tell me how to remove it from te snippet?
Found it myself
Just replace:
if (!$_included==false) {
$buffer .= "</body>\n</html>";
}
with:if (!$_included==false) {
$buffer .= "\n</html>";
}
#9
Posted 14 June 2005 - 03:20 PM
#10
Posted 17 June 2005 - 12:22 PM
A link so that when you click on the thumbnail it opens the full view part, with the next and previous links to, in a new window.
I thought it would just be adjusting some link in the snippet code but I cant find it
Any help on this? Thanks.
#11
Posted 13 January 2007 - 03:50 PM
one small error (removed exclamation mark):
changed:
if (!$_included==false) {
$buffer .= "\n</html>";
} return $buffer;
into:
if ($_included==false) {
$buffer .= "\n</html>";
} return $buffer;
#12
Posted 09 June 2008 - 07:28 PM
#13
Posted 10 June 2008 - 09:31 AM
#14
Posted 10 June 2008 - 10:34 AM
coding or website building. I could not get the "target=_blank" to work. Thats why i came here to ask.
And why do i get the feeling i'm being talked to like i'm a 10 year old?
Edited by Excorio, 10 June 2008 - 11:06 AM.
#15
Posted 10 June 2008 - 11:11 AM
target='_blank'or
target="_blank"(ie the _blank bit must be in quotes, and the quotes should be the opposite form of quotes to those containing the string they are in)
Edited by mikef, 10 June 2008 - 11:12 AM.
#16
Posted 10 June 2008 - 11:37 AM
Quote
coding or website building. I could not get the "target=_blank" to work. Thats why i came here to ask.
And why do i get the feeling i'm being talked to like i'm a 10 year old?
Sorry if I caused any offence, it is never my intention. You can never guess how people will react to anything that is posted. My suggestion is that if you are really starting out, you have probably chosen a quite long and overly complex snippet (both with it's embedded spaghetti code output and embedded template) to start out with. If you have tried target="_blank" or target =\"_blank\" (if you escape the quotes) and it doesn't work, you must be either getting an error which you can't see because your template is covering the error message or something else wierd is going on that you will need to explain. I doubt that you would have added the target tags AND they don't work AND the snippet still works as expected.
Edited by Cris D., 10 June 2008 - 11:58 AM.
#17
Posted 10 June 2008 - 12:50 PM
If this it truly a PHP coding error you should either be able to see a PHP parser error or an HTML markup validation error if you check such things...
#18
Posted 10 June 2008 - 05:55 PM
Ralph, on Jun 10 2008, 01:50 PM, said:
#19
Posted 10 June 2008 - 07:04 PM
The template uses 1.0 Transitional.
I added target="_blank" to the line $buffer .= "<a href=\"{$_url}offset=$_i" . _html($_urlsuffix) . target="_blank" . "\">$_b</a>";
This results in an error Parse error: syntax error, unexpected '=' in C:\wamp\www\index.php(508) : eval()'d code on that line.
If i change this to target =\"_blank\" i get the same error...
Adding target="_blank" or target =\"_blank\" to the other lines with href in it, also result in the same parse errors.
I kow i didn't choose the easiest snippet but it does exactly what i need except for the new window thing:)
Edited by Excorio, 10 June 2008 - 07:09 PM.
#20
Posted 10 June 2008 - 08:03 PM
target="_blank"with
'target="_blank"'
Edited by mikef, 10 June 2008 - 08:04 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











