]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - themes/Hawaiian/lib/random.php
Connect the rest of PhpWiki to the IniConfig system. Also the keyword regular expres...
[SourceForge/phpwiki.git] / themes / Hawaiian / lib / random.php
1 <?php rcs_id('$Id: random.php,v 1.10 2004-04-19 23:13:04 zorloc Exp $');
2 /**
3  */
4 class randomImage {
5     /**
6      * Usage:
7      *
8      * $imgSet = new randomImage($Theme->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
38 class imageSet extends fileSet {
39     /**
40      * A file is considered an image when the suffix matches one from
41      * $InlineImages.
42      */
43     function _filenameSelector($filename) {
44         return preg_match("/(" . INLINE_IMAGES . ")$/i", $filename);
45     }
46 };
47
48
49 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 // (c-file-style: "gnu")
51 // Local Variables:
52 // mode: php
53 // tab-width: 8
54 // c-basic-offset: 4
55 // c-hanging-comment-ender-p: nil
56 // indent-tabs-mode: nil
57 // End:   
58 ?>