New improved version
Now you need only one plugin, since it takes parameters:
dir -> image directory
types -> comma-separed list of valid extensions
exclude -> comma-separed list of excluded files
exclude_regexp -> comma-separed list of exclusion regexp
show_descr -> 'yes' shows the descriptions column, 'no' hides it
open_image -> 1: open image in a popup (javascript)
2: in a new window/tab (target=_blank)
3: in the self window/tab
table_class -> css class of the table
tb_td_class -> css class of the thumbnail cell
de_td_class -> css class of the description cell
If these parameters are not set, they default to values set in plugin code.
All params are optionals, default for "dir" is uploads/images/ (if not set in the code).
So paste the code into a new plugin, save it as "gallery" or whatever you want and call it in a content page
Code: Select all
{gallery_or_what dir="gallery/city" table_class="myclass"}
adding/changing/removing params as you want.
Code: Select all
/* PARAMETERS:
dir -> image directory
types -> comma-separed list of valid extensions
exclude -> comma-separed list of excluded files
exclude_regexp -> comma-separed list of exclusion regexp
show_descr -> 'yes' shows the descriptions column, 'no' hides it
open_image -> 1: open image in a popup (javascript)
2: in a new window/tab (target=_blank)
3: in the self window/tab
table_class -> css class of the table
tb_td_class -> css class of the thumbnail cell
de_td_class -> css class of the description cell
If these are not set default to values set below
*/
extract($params);
// ===== DEFAULT CONFIG =====
// === FILE ===
// = Image directory =
$cdir = "";
// = Valid extensions =
$ctypes = array('jpg', 'jpeg', 'gif', 'png');
// = Exclude files =
$cexclude = array('nottosee.jpg');
// = Exclude with regexp (PCRE) =
$cexclude_regexp = array('#^editor_#', '#^thumb_#');
// === APPEARENCE ===
// = Table class =
$ctable_class = 'gallery';
// = Thumbnail TD class =
$ctb_td_class = 'g_thumb';
// = Show descriptions =
$cshow_descr = 'yes';
// = Description TD class =
$cde_td_class = 'g_descr';
// === LINKS ===
// = Open images in: =
// 1 -> popup (javascript)
// 2 -> new window/tab (target=_blank)
// 3 -> self window/tab
$copen_image = 1;
// END CONFIG
if (!isset($dir)) $dir = &$cdir;
if (isset($types)) $types = explode(',', $types);
else $types = &$ctypes;
if (isset($exclude)) $exclude = explode(',', $exclude);
else $exclude = &$cexclude;
if (isset($exclude_regexp)) $exclude_regexp = explode(',', $exclude_regexp);
else $exclude_regexp = &$cexclude_regexp;
if (!isset($table_class)) $table_class = &$ctable_class;
if (!isset($tb_td_class)) $tb_td_class = &$ctb_td_class;
if (!isset($show_descr)) $show_descr = &$cshow_descr;
if (!isset($de_td_class)) $de_td_class = &$cde_td_class;
if (!isset($open_image) || !is_int($open_image) || $open_image < 1 || $open_image > 3)
$open_image = &$copen_image;
$filter = "#^(.+)\.(".implode($types,'|').")$#i";
$upath = "./uploads/images/{$dir}/";
$path = realpath("./uploads/images/{$dir}").'/';
if (empty($path)) return;
$d = dir($path);
echo "\n<table class=\"{$table_class}\">\n";
while ($f = $d->read()) {
if (filetype($path.$f) != 'file') continue;
if (in_array($f, $exclude)) continue;
if (!preg_match($filter, $f)) continue;
foreach ($exclude_regexp as $regexp)
if (preg_match($regexp, $f)) continue 2;
$size = @getimagesize($path.$f);
if (is_array($size)) $sizestr = ',width='.($size[0]+20).',height='.($size[1]+20);
else $sizestr = '';
switch ($open_image) {
case 1:
$url= "<a href=\"javascript:void(window.open('{$upath}{$f}','','resizable=no,".
"location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,".
"dependent=no{$sizestr}'))\" title=\"Full-size image\">";
break;
case 2:
$url = "<a href=\"{$upath}{$f}\" title=\"Full-size image\" target=\"_blank\">";
break;
case 3:
$url = "<a href=\"{$upath}{$f}\" title=\"Full-size image\">";
break;
}
echo "\t<tr>\n\t\t<td class=\"{$tb_td_class}\">\n\t\t\t".$url.
"<img src=\"{$upath}thumb_{$f}\" alt=\"\" /></a>\n\t\t</td>";
$pieces = explode('.', $f);
$pieces[count($pieces)-1] = 'txt';
$descf = implode('.', $pieces);
if (file_exists($path.$descf)) $descr = implode('', file($path.$descf));
else $descr = $f;
if ($show_descr == 'yes')
echo "\n\t\t<td class=\"{$de_td_class}\">\n\t\t\t\t{$descr}\n\t\t</td>";
echo "\n\t</tr>\n";
}
$d->close();
echo "</table>\n";
As usual, not very tested
Any suggestion? Please try it and say what do you think about it. Thanks very much
Fred
