]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - themes/Hawaiian/lib/random.php
extra_empty_lines
[SourceForge/phpwiki.git] / themes / Hawaiian / lib / random.php
1 <?php // $Id$
2 /**
3  */
4 class randomImage {
5     /**
6      * Usage:
7      *
8      * $imgSet = new randomImage($WikiTheme->file("images/pictures"));
9      * $imgFile = "pictures/" . $imgSet->filename;
10      */
11     function randomImage ($dirname) {
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         better_srand(); // Start with a good seed.
29         $this->filename = $this->imageList[array_rand($this->imageList)];
30         //trigger_error(sprintf(_("random image chosen: %s"),
31         //                      $this->filename),
32         //              E_USER_NOTICE); //debugging
33         return $this->filename;
34     }
35 };
36
37 class imageSet extends fileSet {
38     /**
39      * A file is considered an image when the suffix matches one from
40      * $InlineImages.
41      */
42     function _filenameSelector($filename) {
43         return preg_match("/(" . INLINE_IMAGES . ")$/i", $filename);
44     }
45 };
46
47 // Local Variables:
48 // mode: php
49 // tab-width: 8
50 // c-basic-offset: 4
51 // c-hanging-comment-ender-p: nil
52 // indent-tabs-mode: nil
53 // End:
54 ?>