get("album") ) { if ( $album_item = ORM::factory("item") ->where("name", "=", $album_name) ->viewable() ->find() ) { $album_id = $album_item->id; } } $attempts=0; do { if ( $album_id ) { $item = item::random_query() ->where("type", "!=", "album") ->where("type", "!=", "movie") ->where("parent_id", "=", $album_id) ->find_all(1) ->current(); } else { $item = item::random_query() ->where("type", "!=", "album") ->where("type", "!=", "movie") ->find_all(1) ->current(); } } while ( !$item && $attempts++ < 5 ); $randimg = new View("randimg.html"); $randimg->item = $item; return $randimg; } }