t("Random image")); } static function get($block_id, $theme) { $block = ""; switch ($block_id) { case "random_image": $block = new Block(); $block->css_id = "g-image-block"; $block->title = t("Random image"); $block->content = new View("image_block_block.html"); $random = ((float)mt_rand()) / (float)mt_getrandmax(); $items = ORM::factory("item") ->viewable() ->where("type !=", "album") ->where("rand_key < ", $random) ->orderby(array("rand_key" => "DESC")) ->find_all(1); if ($items->count() == 0) { // Try once more. If this fails, just ditch the block altogether $items = ORM::factory("item") ->viewable() ->where("type !=", "album") ->where("rand_key >= ", $random) ->orderby(array("rand_key" => "DESC")) ->find_all(1); } if ($items->count() > 0) { $block->content->item = $items->current(); } else { $block = ""; } break; } return $block; } }