]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - themes/Hawaiian/lib/random.php
Reformat code
[SourceForge/phpwiki.git] / themes / Hawaiian / lib / random.php
1 <?php
2 class randomImage
3 {
4     /**
5      * Usage:
6      *
7      * $imgSet = new randomImage($WikiTheme->file("images/pictures"));
8      * $imgFile = "pictures/" . $imgSet->filename;
9      */
10     function randomImage($dirname)
11     {
12
13         $this->filename = ""; // Pick up your filename here.
14
15         $_imageSet = new imageSet($dirname);
16         $this->imageList = $_imageSet->getFiles();
17         unset($_imageSet);
18
19         if (empty($this->imageList)) {
20             trigger_error(sprintf(_("%s is empty."), $dirname),
21                 E_USER_NOTICE);
22         } else {
23             $dummy = $this->pickRandom();
24         }
25     }
26
27     function pickRandom()
28     {
29         better_srand(); // Start with a good seed.
30         $this->filename = $this->imageList[array_rand($this->imageList)];
31         //trigger_error(sprintf(_("random image chosen: %s"),
32         //                      $this->filename),
33         //              E_USER_NOTICE); //debugging
34         return $this->filename;
35     }
36 }
37
38 ;
39
40 class imageSet extends fileSet
41 {
42     /**
43      * A file is considered an image when the suffix matches one from
44      * $InlineImages.
45      */
46     function _filenameSelector($filename)
47     {
48         return preg_match("/(" . INLINE_IMAGES . ")$/i", $filename);
49     }
50 }
51
52 ;
53
54 // Local Variables:
55 // mode: php
56 // tab-width: 8
57 // c-basic-offset: 4
58 // c-hanging-comment-ender-p: nil
59 // indent-tabs-mode: nil
60 // End: