WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: Argos on November 02, 2011, 01:27:06 PM

Title: Droplet: random image(s) from a media-dir with lightbox popup
Post by: Argos on November 02, 2011, 01:27:06 PM
I wanted to have a droplet that shows a certain number of random images from a media-dir, and showed large version in a lightbox on click. It seemed there is no such droplet yet, so created it myself by combing the droplet "RandomOrderImages" and the module "MiniGallery". It's a crude solution and could be made much better, but it works fine nevertheless.

You have to install the MiniGallery module (https://forum.WebsiteBaker.org/index.php/topic,22174.0.html) and set the settings. Do not upload images.

Then create a new droplet and call it for example "RandomImagesLightbo x", and add this code:

Code: [Select]
$folder=opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$dir.'/.');
$names = array();
while ($file = readdir($folder))  {
$ext=strtolower(substr($file,-4));
if ($ext==".jpg"||$ext==".gif"||$ext==".png"){
$names[count($names)] = $file;
}
}
closedir($folder);
reset(shuffle($names));
array_unshift($names," ");
if(isset($width)){$width=' width="'.$width.'"';}else{$width="";}
if(isset($height)){$height=' height="'.$height.'"';}else{$height="";}
$count=1;
while(($image=next($names))and(($count<=$num)or(!isset($num)))){
$name=substr($image,0,-4);
if($link=="y"){$images=$images.'<a rel="gallery" class="fancybox" href="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/'.$image.'" target=_blank>';}
if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/'.$dir.'/thumbs/'.$image.'.thumb.jpg')){
$images=$images.'<img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/thumbs/'.$image.'.thumb.jpg" alt="'.$name.'" '.$width.$height.' border=0"/>';
}else{
$images=$images.' <img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/'.$image.'" alt="'.$name.'" '.$width.$height.' ">';
}
if($link=="y"){$images=$images.'</a>';}
$count++;
}
return $images;

If you compare this to the original RandomOrderImages droplet, you see that I only add the class and rel from the MiniGallery module to the link tag.

Now the original image pops up in a lightbox when clicked  :-D

Use this call:
 
[[RandomOrderImages?dir=some_media_folder_here&num=3&link=y]]

Change the mediafolder and the number of images you want to show.
Title: Re: Droplet: random image(s) from a media-dir with lightbox popup
Post by: svsanchez on August 18, 2012, 03:40:46 AM
Hello Argos, I installed your droplet and although it shows the images, it shows them at their full size instead of a little thumb. Also, when clicked, it will open the image on a new window. What do I have to change to make it work correctly?
Title: Re: Droplet: random image(s) from a media-dir with lightbox popup
Post by: Argos on August 18, 2012, 10:07:16 AM
My droplet just combines the random image droplet with the Minigallery module. It seems the Minigallery doesn't work with you. So I suggest you try to get this module to work first, and then try my droplet. So install the Minigallery and add images, and see if it works. I suspect it won't work and there is something wrong. Check out http://minigallery.allwww.nl/ for info.