3 rcs_id('$Id: random.php,v 1.1 2002-01-18 20:08:30 carstenklapp Exp $');
10 function RandomImage ($dirname) {
11 if (empty($dirname)) {
12 trigger_error(sprintf(_("%s is empty."), 'dirname'),
14 return ""; // early return
17 $this->readAvailableImages($dirname);
18 //echo "count is " . count($this->imageList) ."<br>\n";//tempdebugcode
20 if (empty($this->imageList)) {
21 trigger_error(sprintf(_("%s is empty."), 'imageList'),
23 return ""; // early return
25 $this->_srand(); // Start with a good seed.
27 $random_num = mt_rand(0,count($this->imageList)-1);
28 //echo "random_num is " . $random_num;
30 //FIXME: Help! This is where it all craps out.
31 trigger_error("The random image class doesn't quite work yet. Help!", E_USER_NOTICE);
33 $imgname = $this->imageList[$random_num];
35 return "$dirname/" . $imgname;
40 * Prepare a random seed.
42 * How random do you want it? See
43 * http://download.php.net/manual/en/function.srand.php
44 * mt_srand ((double) microtime() * 1000000 / pi())
46 function _srand($seed = '') {
47 static $wascalled = FALSE;
49 $seed = $seed === '' ? (double) microtime() * 1000000 : $seed;
57 * Build an array in $this->imageList of image files from
58 * $dirname. Files are considered images when it's suffix matches
59 * one from $InlineImages.
61 * (This is a variation of function LoadDir in lib/loadsave.php)
62 * See also http://www.php.net/manual/en/function.readdir.php
64 function readAvailableImages($dirname) {
65 @ $handle = opendir($dir = $dirname);
67 trigger_error(sprintf(_("Unable to open directory '%s' for reading"),
68 $dir), E_USER_NOTICE);
69 return; // early return
71 $this->imageList = array();
72 while ($fn = readdir($handle)) {
74 if ($fn[0] == '.' || filetype("$dir/$fn") != 'file')
77 if (preg_match("/($InlineImages)$/i", $fn)) {
78 array_push($this->imageList, "$fn");
79 //echo $fn."<br>\n"; //debug
87 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 // (c-file-style: "gnu")
93 // c-hanging-comment-ender-p: nil
94 // indent-tabs-mode: nil