Subject: Random Gallery Picture Block

Posted on: 14/08/02 01:22pm
By: vinny

I was dissatisfied with the random image block not producing really random images (images in smaller albums would come up more frequently). Also the poor handling of empty albums and the desire to have a list of excluded albums prompted me to rework the Random Image Block for Gallery/Geeklog. I found the original block while surfing, so I'm afraid I don't know who to ascribe the original work to. Also, this seems to run a bit slower (and bigger in memory) than the original as it builds an array with the name of every picture in Gallery. Without further ado, here it is: /** * This is the function that returns a random image from the Gallery */ function phpblock_gallery() { global $_CONF; // Location of the Gallery album directory $path_gallery_albums = $_CONF['path_html'] . 'albums/'; // URL to the gallery $gallery_url = $_CONF['site_url'] . '/gallery'; // URL to album directory $gallery_album_url = $_CONF['site_url'] . '/albums'; // Albums we want excluded $ignore_albums = array('album01', 'album02', 'album03'); // Bail if we have a bad path if (!is_dir($path_gallery_albums)) return "invalid directory"; // Open album directory $fd = opendir($path_gallery_albums); // Load all pictures into an array. We do this but itering over the // albums available, then selecting all the thumnails from them. $pics = array(); while (($f = @readdir($fd)) == TRUE) { if (is_dir($path_gallery_albums . $f) && !ereg('hidden',$f) && $f <> '.' && $f <> '..' && $f <> 'CVS' && ($f <> '.users') && !in_array($f, $ignore_albums)) { $dir = opendir($path_gallery_albums . $f); $fcount = 0; while (($g = @readdir($dir)) == TRUE) { if ($g <> '.' && $g <> '..' && $g <> 'CVS' && strpos($g,'thumb') && !strpos(strtolower($g),'.gif')) { clearstatcache(); $pics[] = $f . '/' . $g; } } closedir($dir); } } closedir($fd); if (count($pics) == 0) return $retval .= "no pictures found"; // Randomly select a picture from the array mt_srand((double)microtime()*1000000); $indexr = (mt_rand(1, count($pics))); $thepic = $pics[$indexr]; // Now get a random picture from this album, album name, and pic prefix $slashpos = strpos($thepic, '/'); $album = substr($thepic, 0, $slashpos); $thepic = substr($thepic, $slashpos - strlen($thepic) + 1); $pos = strpos($thepic, '.'); $pic_prefix = substr($thepic, 0, $pos); // build HTML output and return it $retval .= "<div align=center> <a href=\""; $retval .= $gallery_url . '/view_photo.php?set_albumName=' . $album . '&id=' . $pic_prefix; $retval .= "\">"; $retval .= "<img border=0 src=\""; $retval .= $gallery_album_url . '/' . $album . '/' . $thepic; $retval .= "\">"; $retval .= "</a> <br></div>\n"; $retval .= "<div align=center> <a href=\""; $retval .= $gallery_url . "\">More Pictures</a>"; $retval .= "<br></div>\n"; return $retval; }

Random Gallery Picture Block

Posted on: 14/08/02 02:18pm
By: Dirk

As with all longer pieces of code, it's probably best to make this available for download somewhere ... bye, Dirk

Random Gallery Picture Block

Posted on: 29/08/02 08:42pm
By: Anonymous

i dont know why but it shows me no albums found even thought i have 3 albums created...help!?

Random Gallery Picture Block

Posted on: 05/02/03 02:39pm
By: Anonymous

I get no pictures found. Any idea?

Random Gallery Picture Block

Posted on: 01/04/03 02:43am
By: Anonymous

i also ge the same "invalid directory" cant seem to find the problem..

Random Gallery Picture Block

Posted on: 01/04/03 02:54am
By: Anonymous

this is what i have set // Location of the Gallery album directory $path_gallery_albums = $_CONF['path_html'] . '/gallery/albums/steven/'; // URL to the gallery $gallery_url = $_CONF['site_url'] . '/gallery'; // URL to album directory $gallery_album_url = $_CONF['site_url'] . '/albums/steven'; My gallery is not relative to my geeklog URL geeklog is here. /home/mi6/fragtheworld.net/public_html/index.php /home/mi6/fragtheworld.net/config.php /home/mi6/fragtheworld.net/gallery/ /home/mi6/fragtheworld.net/gallery/albums/steven/ so the ['path_html'] . '/gallery/albums/steven/'; wont work cuz the link is actualy /public_html/gallery/albums/steven when it should be only /gallery/albums/steven/ not sure how to fix that with out moving my gallery ? any one? hehe thanks for the help M|6 please reply to my post via ( wongxx@mi6warez.zzn.com ) my main mail server is down and i cant get my lost password... so i wont be able to see if there a reply unless i check everyday...and well we all have work to do =p anyhow i will try my best cya and thanks for the help im sure i will get.

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=20751