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 144 145 146
|
<?php
class viewgallery {
public $id;
public $name_gallery;
public $type;
public $w;
public $h;
public $rw;
public $rh;
public $rtop;
public $relpatch;
public $webpatch;
public $nombre_pic;
public $nombre_ppage;
public $page;
public $verif;
public $name;
public $pic;
public $nbpage;
public $page_back;
public $page_next;
public $affiche_pic;
public function __construct($id) {
$this->id = $id;
}
// recherche des infos dans la sql
private function get_sql() {
global $db;
$sql = "SELECT * FROM `".TABLE_GALLERY."` WHERE `id`='".$this->id."' limit 1";
$args = $db->query_first($sql);
$this->name_gallery = $args['name_gallery']; //repertoir des images
$this->type = $args['type']; //type d'affichage
$this->w = $args['w']; // largeur maxi de l'image
$this->h = $args['h']; // hauteur maxi de l'image
$this->nombre_ppage = $args['var']; // 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; }
}
// verifie si le repertoir est bien present
public function verif_dir() {
if(is_dir("".$this->relpatch."".$this->name_gallery."")) { $this->verif = true; }
else { $this->verif = false; }
}
// recup des image du repertoire
public function get_array_pic() {
$dh = opendir("".$this->relpatch."".$this->name_gallery."");
while (false !== ($filename = readdir($dh))) { $files[] = $filename; }
closedir($dh);
sort($files);
for ($i=0;$i<=count($files);$i++)
{
if ($files[$i] != "." && $files[$i] != ".." && $files[$i]!="index.html" && $files[$i]!=null) {
$this->pic[] = $files[$i];
}
}
$this->nombre_pic = count($this->pic); // combien d'image dans le rep
$this->name = ucfirst(str_replace("_","",str_replace("MA_DIR_","",$this->name_gallery))); // nétoie le nom du rep
}
// redimention d'image
public function dim_image($img) {
$dst_w = $this->w;
$dst_h = $this->h;
$size = GetImageSize("".$this->relpatch."".$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;
}
public function view($page=0) {
$this->get_sql();
$this->verif_dir();
if($this->verif==true) {
$this->get_array_pic(); // recup des images du repertoire
$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->dim_image($value);
// image a afficher
$this->affiche_pic[] = '<img src="'.$this->webpatch.''.$this->name_gallery.'/'.$value.'" width="'.$this->rw.'" height="'.$this->rh.'" style="margin-bottom:'.$this->rtop.'px"/>'."\n";
}
}
}
else
{
echo "Erreur: Répertoire galerie non valide.";
}
}
}
?>
<?php
// contenue de la page
$gallery = new viewgallery('14');
$gallery->relpatch = "/le/chemin/complet/du/rep/files/images/";
$gallery->webpatch = "../files/images/";
$gallery->view($_GET['page']);
?>
<table>
<tr>
<td colspan="3">Galerie : <?= $gallery->name ?></td>
<tr>
<td><a href="?op=test&page=<?= $gallery->page_back ?>"> back </a></td>
<td><?php if($gallery->verif==true) { foreach ($gallery->affiche_pic as $img) { echo $img; } } ?></td>
<td><a href="?op=test&page=<?= $gallery->page_next ?>"> next </a></td>
</tr>
</table> |
Partager