1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ansel_View_Gallery extends Ansel_View_Ansel
14: {
15: 16: 17: 18: 19:
20: protected $_renderer;
21:
22: 23: 24: 25: 26:
27: public function __construct($params = array())
28: {
29: parent::__construct($params);
30:
31: if (!empty($params['gallery_slug'])) {
32: $this->gallery = $this->_getGallery(null, $params['gallery_slug']);
33: } elseif (!empty($params['gallery_id'])) {
34: $this->gallery = $this->_getGallery($params['gallery_id']);
35: } else {
36: $this->gallery = $this->_getGallery();
37: }
38:
39:
40: if (!$this->gallery->isOldEnough()) {
41: if (!empty($params['api'])) {
42: throw new Horde_Exception('Locked galleries are not viewable via the api.');
43: }
44: $date = Ansel::getDateParameter(
45: array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0,
46: 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0,
47: 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0));
48:
49: $galleryurl = Ansel::getUrlFor('view', array_merge(
50: array('gallery' => $this->gallery->id,
51: 'slug' => empty($params['slug']) ? '' : $params['slug'],
52: 'page' => empty($params['page']) ? 0 : $params['page'],
53: 'view' => 'Gallery'),
54: $date),
55: true);
56:
57: $params = array('gallery' => $this->gallery->id, 'url' => $galleryurl);
58: Horde::url('disclamer.php')->add($params)->setRaw(true)->redirect();
59: exit;
60: }
61:
62: if ($this->gallery->hasPasswd()) {
63: if (!empty($params['api'])) {
64: throw new Ansel_Exception(_("Locked galleries are not viewable via the api."));
65: }
66: $date = Ansel::getDateParameter(
67: array('year' => isset($this->_params['year']) ? $this->_params['year'] : 0,
68: 'month' => isset($this->_params['month']) ? $this->_params['month'] : 0,
69: 'day' => isset($this->_params['day']) ? $this->_params['day'] : 0));
70:
71: $galleryurl = Ansel::getUrlFor('view', array_merge(
72: array('gallery' => $this->gallery->id,
73: 'slug' => empty($params['slug']) ? '' : $params['slug'],
74: 'page' => empty($params['page']) ? 0 : $params['page'],
75: 'view' => 'Gallery'),
76: $date),
77: true);
78:
79: $params = array('gallery' => $this->gallery->id, 'url' => $galleryurl);
80: Horde::url('protect.php')->add($params)->setRaw(true)->redirect();
81: exit;
82: }
83:
84: if (!$this->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
85: throw new Horde_Exception('Access denied viewing this gallery.');
86: }
87:
88:
89: $this->resource = $this->gallery;
90:
91:
92: if (!empty($this->_params['style'])) {
93: $style = Ansel::getStyleDefinition($this->_params['style']);
94: } else {
95: $style = $this->gallery->getStyle();
96: }
97: if (!empty($this->_params['gallery_view'])) {
98: $renderer = $this->_params['gallery_view'];
99: } else {
100: $renderer = (!empty($style->gallery_view)) ? $style->gallery_view : 'Gallery';
101: }
102:
103:
104: $classname = 'Ansel_View_GalleryRenderer_' . basename($renderer);
105: $this->_renderer = new $classname($this);
106: $this->_renderer->init();
107: }
108:
109: public function getGalleryCrumbData()
110: {
111: return $this->gallery->getGalleryCrumbData();
112: }
113:
114: 115: 116: 117: 118:
119: public function getTitle()
120: {
121: return $this->gallery->get('name');
122: }
123:
124: 125: 126: 127: 128: 129:
130: public function html()
131: {
132: return $this->_renderer->html();
133: }
134:
135: public function viewType()
136: {
137: return 'Gallery';
138: }
139: }
140: