Needs review
Project:
Brilliant Gallery
Version:
6.x-4.0
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Oct 2008 at 22:53 UTC
Updated:
31 Oct 2011 at 18:10 UTC
Just an idea how to display a random image out of any folders under the gallery root.
I hacked the brilliant_gallery.module starting at line 509:
if ( $thisfolder <> '' ) {
if ( $thisfolder == '?' ) {
$folders = array();
$dir = realpath(file_directory_path() . '/' . $galleryfolder);
$files = scandir($dir);
foreach ($files as $file) {
$currentfile = $dir . "/" . $file;
if (is_dir($currentfile)) {
if ($file != '.' && $file != '..') {
$folders[] = $file;
}
}
}
shuffle($folders);
$galleryfolder .= '/' . $folders[0];
}
else {
$galleryfolder .= '/' . $thisfolder;
}
}
This piece of code chooses a random directory if "?" is set as gallery folder.
Thus, with the following line of code you realise displaying a random image:
[bg|?|1|100|random|1||1|]
Maybe someone finds this useful and adds it to a future version.
Comments
Comment #1
drpchris commentedthanks - I was thinking of doing something like this. Works great.
Comment #2
doctrosx commentedIm no coder so I probably have no business messing with such things but I have been looking for something like this for a while. Can you please give me a bit more detailed instructions on this? I have tried several different things with the code above and keep getting syntax errors whenever I put in the BG line. Im sure its something simple. Here is the latest one I tried.. (Dont laugh :) )
Comment #3
charlieobrian commentedThis could be a very useful feature, choosing random images from random subdirectory.
I updated Satanclaus' code for current stable and dev version. In brilliant_gallery.module
was changed to
This way entering "?" as gallery name in a bg tag it will choose a random subdirectory.
Can you please check it and add to future release if you also find it useful...
Bence
Comment #4
charlieobrian commentedOne more idea:
The above code only scans the default brilliant gallery folder for subdirectories. If Picasa cached dirs are used, that folder should also be scanned for directories...
Comment #5
charlieobrian commentedIf someone is interested, the above code works also in 6.x-4.0 version. All you have to do open gallery_showtime.inc and at line 93 replace
with this:
and of course empty Drupal cache after the modification.