1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ansel_Block_RandomPhoto extends Horde_Core_Block
14: {
15: 16:
17: public $updateable = true;
18:
19: 20:
21: public function __construct($app, $params = array())
22: {
23: parent::__construct($app, $params);
24:
25: $this->_name = _("Random photo");
26: }
27:
28: 29:
30: protected function _content()
31: {
32: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getRandomGallery();
33: if (!$gallery) {
34: return _("There are no photo galleries available.");
35: }
36: $imagelist = $gallery->listImages(rand(0, $gallery->countImages() - 1), 1);
37: if (empty($imagelist)) {
38: return '';
39: }
40: $imageId = $imagelist[0];
41: $viewurl = Ansel::getUrlFor('view', array('gallery' => $gallery->id,
42: 'slug' => $gallery->get('slug'),
43: 'image' => $imageId,
44: 'view' => 'Image'), true);
45:
46: if ($gallery->isOldEnough() && !$gallery->hasPasswd()) {
47: $img = '<img src="' . Ansel::getImageUrl($imageId, 'thumb', true, Ansel::getStyleDefinition('ansel_default')) . '" alt="[random photo]" />';
48: } else {
49: $img = Horde::img('thumb-error.png');
50: }
51:
52: return $viewurl->link(array('title' => _("View Photo"))) . $img . '</a>';
53: }
54:
55: }
56: