1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
<?php
class MyException extends Exception {
public function __construct($msg=NULL, $code=0)
{
parent::__construct($msg, $code);
}
}
class Gallery {
private $rw;
private $rh;
private $rtop;
private $w;
private $h;
private $pic;
private $nbpage;
public $nombre_pic;
public $page;
public $page_back;
public $page_next;
public $affiche_pic;
public $realpath;
public $webpath;
public $nombre_ppage;
public $name_gallery;
public $type;
public function __construct() {
}
public function data($rep,$type,$w,$h,$nbpp) {
if(is_dir($this->realpath.$rep)) {
$nbfiles=0;
$Dir=new RecursiveDirectoryIterator($this->realpath.$this->name_gallery);
foreach (new RecursiveIteratorIterator($Dir) as $filename=>$cur) {
if($cur->getFilename()!="index.html") {
$nbfiles++;
$this->pic[]=$cur->getFilename();
}
}
sort($this->pic);
$this->nombre_pic = count($this->pic);
$this->name_gallery = $rep; //repertoir des images
$this->type = $type; //type d'affichage
$this->w = $w; // largeur maxi de l'image
$this->h = $h; // hauteur maxi de l'image
$this->nombre_ppage = $nbpp; // nombre par page
if($this->w==0) { $this->w=300; }
elseif($this->w>1000) { $this->w=1000; } // test des dimention demander
if($this->h==0) { $this->h=300; }
elseif($this->h>1000) { $this->h=1000; }
}
else
{
throw new MyException('Erreur de repertoire');
}
}
// redimention d'image
public function RedimImage($img) {
if(GetImageSize("".$this->realpath."".$this->name_gallery."/".$img."")) {
$dst_w = $this->w;
$dst_h = $this->h;
$size = GetImageSize("".$this->realpath."".$this->name_gallery."/".$img.""); // taille reel de l'image
$src_w = $size[0];
$src_h = $size[1];
$test_h = round(($dst_w / $src_w) * $src_h);
$test_w = round(($dst_h / $src_h) * $src_w);
if(!$dst_h) { $dst_h = $test_h; }
elseif(!$dst_w) { $dst_w = $test_w; }
elseif($test_h>$dst_h) { $dst_w = $test_w; }
else { $dst_h = $test_h; }
if($dst_h > 1 && $dst_h < $this->h){ // centre l'image
$top = ceil(($this->h - $dst_h) / 2);
} else { $top = 0; }
$this->rtop = $top;
$this->rw = $dst_w;
$this->rh = $dst_h;
}
else
{
throw new MyException('Erreur de redimention');
}
}
public function ViewGallery($page=0) {
$this->page = $page; // recup de la page en cour
$this->nbpage = round($this->nombre_pic / $this->nombre_ppage); // nombre de page
if($this->page > $this->nbpage-1) { $this->page=0; } // si page en cour plus grand que le nombre de page on retourne au debut
if($this->page!=0) { $this->page_back = $this->page-1; } else { $this->page_back = 0; } // page retour
if($this->page+1 < $this->nbpage) { $this->page_next = $this->page+1; } else { $this->page_next = 0; } // page suivant
$varpic_debut = $this->page*$this->nombre_ppage;
$varpic_fin = ($this->page+1)*$this->nombre_ppage;
foreach ($this->pic as $key => $value) {
if($key>=$varpic_debut && $key<$varpic_fin) {
$this->RedimImage($value);
$args = array($value,
$this->rw,
$this->rh,
$this->rtop);
$this->affiche_pic[] = $args;
}
}
}
}
?>
<?php
// contenue de la page
try{
$gallery = new Gallery();
$gallery->realpath = "/home/website/public_html/files/images/";
$gallery->webpath = "../files/images/";
$gallery->data('MA_DIR_equipe2','1','300','300','10');
$gallery->ViewGallery($_GET['page']);
}
catch(MyException $e)
{
echo 'Oops un bug : ' .$e->getMessage() . ' à la ligne : ' . $e ->getLine();
}
?>
<table>
<td><a href="?op=test&page=<?= $gallery->page_back ?>"> back </a></td>
<td><?php for($i=0;$i<count($gallery->affiche_pic);$i++) { echo '<img src="'.$gallery->webpath.$gallery->name_gallery.'/'.$gallery->affiche_pic[$i][0].'" width="'.$gallery->affiche_pic[$i][1].'" height="'.$gallery->affiche_pic[$i][2].'" style="margin-bottom:'.$gallery->affiche_pic[$i][3].'px"/>'; } ?></td>
<td><a href="?op=test&page=<?= $gallery->page_next ?>"> next </a></td>
</tr>
</table> |
Partager