

[[simplegallery? &pathToImg=`fruit` &galleryName=`verger`]]
* @package Thumbnail and Watermark Class
* @author Emilio Rodriguez <[email protected]>
* @version 1.48 <2005/07/18>
* @copyright GNU General Public License (GPL)
<?php
/*
Snippet name: simplegallery
Short Desc: builds gallery from a folder
Version: beta1
Thank's to : Heliotrope and doze
Date: October 16, 2006
MODx version: 0.9.5
*/
class simplegallery {
/* Declaring private variables */
var $pathToImgFolder;
var $imgtype;
var $galleryName;
var $imglist;
/* Constructor class */
function simplegallery() {
global $modx, $_lang;
$this->imglist = array();
}
/* List of images */
function getImagesList() {
global $modx, $_lang;
if (is_dir($this->pathToImgFolder)) {
if ($this->imglist = glob($this->pathToImgFolder.$this->imgtype,GLOB_BRACE)) {
return $this->imglist;
} else die ($_lang['cannot_open_dir'].$this->pathToImgFolder.$this->imgtype);
} else die ($_lang['path_not_directory'].$this->pathToImgFolder);
}
}
?><?php
/*
Snippet name: simplegallery
Short Desc: builds gallery from a folder
Version: beta1
Thank's to : Heliotrope and doze
Date: October 16, 2006
MODx version: 0.9.5
*/
global $modx;
$output='<div id="images">';
/* General setting */
$baseImgPath = $modx->config['base_path'].'assets/images/';
$imgtype = '/*{jpg,jpeg,gif,png}';
$simplegallery_version = "beta 0.1";
$quality = '75';
$max_thumb_size ='240';
/* Get Language */
$language = (isset($language))? $language : "english";
/* Include files */
$files['language'] = $snipPath."lang/$language.inc.php";
$files['functions'] = $snipPath."class/simplegallery.class.php";
foreach ($files as $filename => $filevalue) {
if (file_exists($filevalue) && $filename != "language") {
include_once($filevalue);
} elseif(file_exists($filevalue) && $filename == "language") {
include($filevalue);
$GLOBALS['_lang'] = $_lang;
} elseif($filename == "language") {
$output="Language file does not exist Please check: ".$filevalue;
return $output;
} else {
$output=$_lang['error'].__LINE__.") ".$filevalue." ".$_lang['file_does_not_exist'];
return $output;
}
}
/* Begin the traitement */
$gal = null;
if (class_exists('simplegallery')){
$gal = new simplegallery();
} else {
$output=$_lang['error'].__LINE__.") ".$filevalue." ".$_lang['invalid_class'];
return $output;
}
/* Parameters */
$gal->galleryName = isset($galleryName) ? $galleryName : $_lang['gallery'];
$gal->pathToImgFolder = isset($pathToImg) ? $baseImgPath.$pathToImg : '';
$gal->imgtype = $imgtype;
$gal->getImagesList();
foreach($gal->imglist as $image){
$imagefull = preg_replace('`'.$gal->pathToImgFolder.'/(.+)`','$1',$image);
$imagename = preg_replace('`(.+)\..*`', '$1', $imagefull);
//verification thumb et creation
$thumburl = $gal->pathToImgFolder.'/.thumb_'.$imagefull;
if (!file_exists($thumburl)) {
include_once($snipPath.'class/Thumbnail.class.php');
$thumb=new Thumbnail($image);
$thumb->quality=$quality;
$thumb->size_auto($max_thumb_size);
$thumb->process();
$thumb->save($thumburl);
}
$imginfo = getimagesize($thumburl);
$sizeiptc = getimagesize ($image, &$info);
$iptc = iptcparse($info["APP13"]);
$iptccaption = $iptc["2#120"][0];
$iptcheadline = $iptc["2#105"][0];
$output .= '<a href="assets/images/'.$pathToImg.'/'.$imagefull.'" rel="lightboxmirmande" title="'.$iptccaption.'"><img src="assets/images/'.$pathToImg.'/.thumb_'.$imagefull.'" alt="'.$iptccaption.'" '.$imginfo[3].' />';
}
$output .= '</div>';
return $output;
?><ul id="gallerie"> <li><a href="<img src="img/img_01.jpg" alt="Grande" />"><img src="img/img_01.jpg" alt="Petite" /><br /><span>Légende 1</span></a></li> <li><a href="<img src="img/img_01.jpg" alt="Grande" />"><img src="img/img_02.jpg" alt="Petite" /><br /><span>Légende 2</span></a></li> <li><a href="<img src="img/img_01.jpg" alt="Grande" />"><img src="img/img_03.jpg" alt="Petite" /><br /><span>Légende 3</span></a></li> </ul>