diff options
| -rw-r--r-- | helpers/randimg.php | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/helpers/randimg.php b/helpers/randimg.php index af56564..ba15f66 100644 --- a/helpers/randimg.php +++ b/helpers/randimg.php @@ -19,9 +19,33 @@ class randimg_Core { static function randimg_link() { + // Accept an "album" query parameter to allow the random image to be + // limited to a specific album name. + $album_id = null; + if ( $album_name = Input::instance()->get("album") ) { + if ( $album_item = ORM::factory("item") + ->where("name", "=", $album_name) + ->viewable() + ->find() ) + { + $album_id = $album_item->id; + } + } + $attempts=0; do { - $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); + if ( $album_id ) { + $item = item::random_query() + ->where("type", "!=", "album") + ->where("parent_id", "=", $album_id) + ->find_all(1) + ->current(); + } else { + $item = item::random_query() + ->where("type", "!=", "album") + ->find_all(1) + ->current(); + } } while ( !$item && $attempts++ < 5 ); $randimg = new View("randimg.html"); |
