<?php
/***************************************************************************
____ _ _ ____ _ _ _ _ _ _
| _ \| | | | _ \| |_ ___ ___ | |___| || | | | | |
| |_) | |_| | |_) | __/ _ \ / _ \| / __| || |_| | | |
| __/| _ | __/| || (_) | (_) | \__ \__ _| |_| |
|_| |_| |_|_| \__\___/ \___/|_|___/ |_| \___/
mgallery.php - A mini gallery :o)
-------------------
begin : Mon Aug 26 2002
copyright : (C) 2002 PHPtools4U.com - Mathieu LESNIAK
email : support@phptools4u.com
***************************************************************************/
/***************************************************************************
*
* 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.
*
***************************************************************************/
$directory = '../../images';
$thumb_dir = '../../images';
$comm_dir = 'comms';
$nb_col = 2;
$nb_row = 1;
$font = '<FONT face="Verdana, Arial, Helvetica" size="2">';
function mgallery() {
Global $directory, $thumb_dir, $comm_dir, $nb_col, $nb_row, $font;
Global $HTTP_GET_VARS, $DOCUMENT_ROOT, $PHP_SELF, $HTTP_HOST;
$output = '';
$nb_img_page = $nb_row * $nb_col;
$entries = array();
$current_page = isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : 1;
$d = dir($thumb_dir);
while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..' && !is_dir($DOCUMENT_ROOT.$directory.'/'.$entry)) {
$entries[] = $entry;
}
}
$d->close();
$nb_total = count($entries);
$rep_used = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/')).'/';
### Fct Js par Laurent
$output = '<script LANGUAGE="JavaScript">'."\n";
$output .= ' function extrait(chemin, addHeight) {'."\n";
$output .= ' i1 = new Image;
i1.src = chemin;
html = \'<HTML><HEAD><TITLE>Extrait</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="http://'.$HTTP_HOST.$rep_used.'\'+chemin+\'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+32)"></CENTER></BODY></HTML>\';
popupImage = window.open(\'\',\'_blank\',\'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1\');
popupImage.document.open();
popupImage.document.write(html);
popupImage.document.close()
};'."\n";
$output .= '</SCRIPT>'."\n";
$output .= nav_par_page($nb_total, $nb_img_page, 5, $current_page, $PHP_SELF, $font);
$output .= '<TABLE border="0" width="100%">'."\n";
for ($i = 0; $i < $nb_img_page; $i++) {
if ( !($i % $nb_col) ) {
$count = 0;
$output .= '<TR>'."\n";
}
if ( isset($entries[($i + ($nb_img_page * ($current_page-1)))])) {
$name = $entries[($i + ($nb_img_page * ($current_page-1)))];
$comm_name = substr($name, 0, strrpos($name, '.')).'.txt';
if (is_file($comm_dir.'/'.$comm_name)) {
$comm = '<BR>'.$font.implode('<BR>', file($comm_dir.'/'.$comm_name)).'</FONT>';
}
else {
$comm = '';
}
$output .= '<TD valign="top" align="center" width="'.round(100 / $nb_col).'%"><A href="javascript:extrait(\''.$directory.'/'.$entries[($i + ($nb_img_page * ($current_page-1)))].'\',0);"><IMG src="'.$thumb_dir.'/'.$entries[($i + ($nb_img_page * ($current_page-1)))].'" border="0"></A>'.$comm.'</TD>'."\n";
}
else {
break;
}
$count++;
if (($i+1)%$nb_col == 0) {
$output .= '</TR>'."\n";
}
}
for ($i = $count; $i < $nb_col; $i++) {
$output .= '<TD> </TD>';
if (($i+1) == $nb_col) {
$output .= '</TR>';
}
}
$output .= '</TABLE>'."\n";
$output .= nav_par_page($nb_total, $nb_img_page, 5, $current_page, $PHP_SELF, $font);
return $output;
}
function nav_par_page($total, $nb_par_page, $nb_entree_nav, $page_en_cours, $lien, $font) {
if ($total == 0 || $total == '') {
return '';
}
$lien = (eregi('\?', $lien)) ? $lien : $lien.'?';
$lien = (eregi('&', $lien)) ? $lien : $lien.'&';
### Nb de pages total
$nb_pages = ceil($total / $nb_par_page);
### Check des paramètres
$page_en_cours = ($page_en_cours > $nb_pages) ? $nb_pages : $page_en_cours;
$page_en_cours = ($page_en_cours < 1 || $page_en_cours == '') ? 1 : $page_en_cours;
$index_b_nav = ceil($page_en_cours / $nb_entree_nav);
$debut = ($page_en_cours - 1) * $nb_par_page;
### marge sup de la barre de nav
$marge_sup = ($index_b_nav * $nb_entree_nav);
### marge inf de la barre de nav
$marge_inf = ($index_b_nav - 1) * $nb_entree_nav + 1;
$marge_sup = ($marge_sup > $nb_pages) ? $nb_pages : $marge_sup;
$i = $marge_inf;
$nav_bar = '<TABLE width="100%">'."\n";
$nav_bar .= '<TR>'."\n";
$nav_bar .= ' <TD width="50%">'."\n";
$nav_bar .= $font.'Page : ';
if ($index_b_nav > 1) {
$nav_bar .= '<A href="'.$lien.'page=1"><<</A> ';
}
if ($i > 1) {
$nav_bar .= '<A href="'.$lien.'page='.($i-1).'"><</A> ';
}
while ($i <= $marge_sup) {
if ($i == $page_en_cours) {
$nav_bar .= '<B>'.$i.'</B> ';
}
else {
$nav_bar .= '<A href="'.$lien.'page='.$i.'"">'.$i.'</A> ';
}
$i++;
}
if ($i < $nb_pages) {
$nav_bar .= '<A href="'.$lien.'page='.($i).'">></A> ';
}
if ($index_b_nav < ceil($nb_pages / $nb_entree_nav)) {
$nav_bar .= '<A href="'.$lien.'page='.$nb_pages.'">>></A>';
}
$nav_bar .= '</FONT></TD><TD width="50%" align="right">'.$font;
$suivant = $page_en_cours + 1;
$precedent = $page_en_cours - 1;
if ($precedent > 0) {
$nav_bar .= '< <A HREF="'.$lien.'page='.($page_en_cours - 1).'">Page précédente</A>';
}
if (($precedent > 0) && ($suivant <= $nb_pages)) {
$nav_bar .= " ";
}
if ($suivant <= $nb_pages) {
$nav_bar .= '<A HREF="'.$lien.'page='.($page_en_cours + 1).'">Page suivante</A> >';
}
$nav_bar .= '</FONT></TD></TR></TABLE>';
return $nav_bar;
}
echo mgallery();
?>