Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 09:51 pm EST

Geeklog Forums

Dead link


Anonymous

Anonymous
Tony, I was just reading the article on how to add PHP Block for displaying random Gallery photos. In a comment that you wrote, you referred to the following page: http://www.geeklog.net/samplecode/gallery_geeklog_random_pic.txt That page is no longer there so I was wondering where it may have gone. The thread that I was reading is: http://www.geeklog.net/article.php?story=20020205061244619
 Quote

Status: offline

Tony

Site Admin
Admin
Registered: 12/17/01
Posts: 405
Location:Urbandale, Iowa
This is fixed...left of shit from our site upgrade.
The reason people blame things on previous generations is that there's only one other choice.
 Quote

AlphaDominion

Anonymous
I'm glad somone posted this! Thanks! I just tried integrating the code and I found one typo that will cause a missing function error. Instead of making people figure it out on their own I figured that I would just repost the code here. I've also added the fix to avoid selecting an empty album. Put the following code in your lib-common.php file: (Sorry for the lack of formatting) /** * 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_html'] . 'albums/'; // URL to the gallery $gallery_url = $_CONF['site_url'] . '/gallery'; // URL to album directory $gallery_album_url = $_CONF['site_url'] . '/albums'; // 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) && $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 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

AlphaDominion

Anonymous
I wasn't able to figure out how to prevent images in hidden albums from being displayed. If anyone has the solution, then can you please post it. Thanks!
 Quote

Status: offline

efarmboy

Forum User
Moderator
Registered: 02/26/02
Posts: 147
You can add more album names to the if statement that is filtering out files when loading albums into the array. Example - Filtering out hobbies and my music files: while (($f = @readdir($fd)) == TRUE) { if (is_dir($path_gallery_albums . $f) && $f <> 'Hobbies' && $f <> 'music' && $f <> '.' && $f <> '..' && $f <> 'CVS' && ($f <> '.users')) { clearstatcache(); $albums[$index] = $f; $index++; Cheers, Blaine
 Quote

All times are EST. The time is now 09:51 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