t("Random image")); } static function get($block_id, $theme) { $block = ""; switch ($block_id) { case "random_image": // The random_query approach is flawed and doesn't always return a // result when there actually is one. Retry a *few* times. // @todo Consider another fallback if further optimizations are necessary. $attempts = 0; do { $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); } while (!$item && $attempts++ < 3); if ($item && $item->loaded()) { $block = new Block(); $block->css_id = "g-image-block"; $block->title = t("Random image"); $block->content = new View("image_block_block.html"); $block->content->item = $item; } break; } return $block; } }