diff options
| author | Nathan Kinkade <nkinkade@nkinka.de> | 2011-01-09 17:37:23 +0000 |
|---|---|---|
| committer | Nathan Kinkade <nkinkade@nkinka.de> | 2011-01-09 17:37:23 +0000 |
| commit | 37e82a433cd09995988bc52e5cc23f35860fcd69 (patch) | |
| tree | 7ed02c364b0b0bdce4e0eda296a202d32cfd99b2 /helpers | |
| parent | 2cdc3b76dc51d4d7a7675117974ce3c6b004cb63 (diff) | |
Overhaul of module, with a good many changes suggested by danneh3826 on the gallery forum.
Diffstat (limited to 'helpers')
| -rw-r--r-- | helpers/randimg.php | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/helpers/randimg.php b/helpers/randimg.php index 91bf5cb..af56564 100644 --- a/helpers/randimg.php +++ b/helpers/randimg.php @@ -19,23 +19,14 @@ class randimg_Core { static function randimg_link() { - $db = Database::instance(); - $table_prefix = $db->table_prefix; - $query = " - SELECT i1.name, i1.title, i1.description, i1.relative_path_cache, i1.relative_url_cache, i1.slug AS imgslug, i2.slug - FROM {$table_prefix}items i1 JOIN {$table_prefix}items i2 - ON i1.parent_id = i2.id - WHERE i1.type != 'album' AND i1.relative_path_cache IS NOT NULL - ORDER BY RAND() - LIMIT 1; - "; - $result = $db->query($query)->current(); - - $randimg = new View("randimg.html"); - $randimg->imgpath = $result->relative_path_cache; - $randimg->linkpath = $result->relative_url_cache; - $randimg->img_title = $result->title; + $attempts=0; + do { + $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); + } while ( !$item && $attempts++ < 5 ); + $randimg = new View("randimg.html"); + $randimg->item = $item; + return $randimg; } |
