Welcome to Geeklog, Anonymous Sunday, December 22 2024 @ 08:32 pm EST

Geeklog Forums

Random Gallery Photo Display Block


Anonymous

Anonymous
It always shows me "no albums found" thing..i have 3 albums created and everything configured right..what could be the problem?? Here is the code im talking about: /** * This is the function that returns a random image from the Gallery * * NOTE: this does not like albums with no pictures in it! * */ function phpblock_gallery() { global $_CONF; // Location of the Gallery album directory $path_gallery_albums = $_CONF['path'] . 'screenshots/gallery'; // URL to the gallery $gallery_url = $_CONF['site_url'] . '/screenshots'; // URL to album directory $gallery_album_url = $_CONF['site_url'] . '/screenshots/gallery'; // Bail if we have a bad path if (!is_dir($path_gallery_albums)) return "invalid directory"; // Open album directory $fd = opendir($path_gallery_albums); $albums = array(); $index = 1; // Load all albums into an arrray. NOTE: this should be modified at // some point to ignore empty albums!!!!!! while (($f = @readdir($fd)) == TRUE) { if (is_dir($path_gallery_albums . $f) && !ereg('hidden',$f) && $f <> '.' && $f <> '..' && $f <> 'CVS' && ($f <> '.users')) { clearstatcache(); $albums[$index] = $f; $index++; } } closedir($fd); if (count($albums) == 0) return $retval .= "no albums found"; // Randomly select an album from the array mt_srand((double)microtime()*1000000); $indexr = (mt_rand(1, count($albums))); $rand_album = $albums[$indexr]; // Now get a random picture from this album $thepic = phpblock_random_files($path_gallery_albums . $rand_album); $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=' . $rand_album . '&id=' . $pic_prefix; $retval .= "\">"; $retval .= "<img border=0 src=\""; $retval .= $gallery_album_url . '/' . $rand_album . '/' . $thepic; $retval .= "\">"; $retval .= "</a> <br></div>\n"; return $retval; } /** * Given an album this will return a random Gallery thumbnail from that album * * @g string Path to gallery album to get a random image from * **/ function phpblock_random_files($g) { // Open directory $fd = opendir($g); $pics = array(); $index = 1; // Loop through directory inserting all thumbnails into an array. Do not add // .gif images because netpbm can't convert them. while (($f = @readdir($fd)) == TRUE) { if ($f <> '.' && $f <> '..' && $f <> 'CVS' && strpos($f,'thumb') && !strpos(strtolower($f),'.gif')) { clearstatcache(); $pics[$index] = $f; $index++; } } closedir($fd); if ($index > 2) { mt_srand((double)microtime()*1000000); $indexr = (mt_rand(1, count($pics))); } else { $indexr = 1; } // Return image name return $pics[$indexr]; }
 Quote

Status: offline

vinny

Site Admin
Admin
Registered: 06/24/02
Posts: 352
Location:Colorado, USA
If you used the 'standard' installation of gallery it should have created two sub-directories. 'gallery' and 'albums'. If this is the case, you're conf variables should probably read: $path_gallery_albums = $_CONF['path'] . 'screenshots/albums'; $gallery_url = $_CONF['site_url'] . '/screenshots/gallery'; $gallery_album_url = $_CONF['site_url'] . '/screenshots/albums'; If you post more details about your configuration we may be able to give more detailed help. Also, if you don't mind, the url of your site would be helpful also. -Vinny
 Quote

Anonymous

Anonymous
/screenshots/gallery is the path to the ablums..
 Quote

ken

Anonymous
I believe squatty was having the same problem. Does your cache file contain anything? His was being created by the program, but empty. Try defining the cache file /tmp or away from the album directory. That fixed it for him. Also, don't create file, let the program create it. Otherwise it'll think it has already done it and will wait a while until it expires (think it is once a day by default).
 Quote

Status: offline

efarmboy

Forum User
Moderator
Registered: 02/26/02
Posts: 147
Ken, this looks to be the original random photo block and not the New Gallery based API one that we have been having fun with. Blaine
 Quote

ken

Anonymous
Doh, I hadn't looked at the code. Smile
 Quote

All times are EST. The time is now 08:32 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content