1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Base
14: {
15: 16: 17: 18: 19:
20: public function html()
21: {
22:
23: $node = $this->_params['container'];
24: if (empty($node)) {
25: return '';
26: }
27:
28:
29: $gallery_slug = !empty($this->_params['gallery_slug']) ?
30: $this->_params['gallery_slug'] :
31: '';
32:
33: $gallery_id = !empty($this->_params['gallery_id'])
34: ? $this->_params['gallery_id'] :
35: null;
36:
37: $start = isset($this->_params['start']) ?
38: $this->_params['start'] :
39: 0;
40:
41: $count = isset($this->_params['count']) ?
42: $this->_params['count'] :
43: 0;
44:
45: $perpage = isset($this->_params['perpage']) ?
46: $this->_params['perpage'] :
47: 0;
48:
49: $thumbsize = !empty($this->_params['thumbsize']) ?
50: $this->_params['thumbsize'] :
51: 'mini';
52:
53: if ($thumbsize != 'mini' && $thumbsize != 'thumb' && $thumbsize != 'screen') {
54: $thumbsize = 'mini';
55: }
56: $thumbtype = !empty($this->_params['thumbtype']) ?
57: $this->_params['thumbtype'] :
58: 'squarethumb';
59:
60:
61: $images = (!empty($this->_params['images'])) ?
62: $this->_params['images'] :
63: array();
64: if (!empty($images)) {
65:
66:
67:
68: $images = explode(':', $images);
69: } elseif (!empty($this->_params['user'])) {
70:
71: $galleries = array();
72: $gs = $GLOBALS['injector']
73: ->getInstance('Ansel_Storage')
74: ->listGalleries(array('attributes' => $this->_params['user']));
75: foreach ($gs as $gallery) {
76: $galleries[] = $gallery->id;
77: }
78: $images = array();
79: $is = $GLOBALS['injector']
80: ->getInstance('Ansel_Storage')
81: ->getRecentImages($galleries, $count);
82: foreach ($is as $i) {
83: $images[] = $i->id;
84: }
85: } else {
86: try {
87: $this->gallery = $this->_getGallery($gallery_id, $gallery_slug);
88: } catch (Exception $e) {
89: Horde::logMessage($e, 'ERR');
90: exit;
91: }
92:
93:
94:
95: if (!$this->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ) ||
96: !$this->gallery->isOldEnough() ||
97: $this->gallery->hasPasswd()) {
98:
99: return '';
100: }
101: }
102:
103: if (empty($images)) {
104: $images =
105: $json = self::json($this->gallery,
106: array('full' => true,
107: 'from' => $start,
108: 'count' => $count,
109: 'image_view' => $thumbsize,
110: 'view_links' => true,
111: 'generator' => $thumbtype));
112: $json_full = self::json($this->gallery,
113: array('full' => true,
114: 'from' => $start,
115: 'count' => $count,
116: 'view_links' => true));
117: } else {
118: if ($thumbsize == 'thumb') {
119: $style = Ansel::getStyleDefinition('ansel_default');
120: $style->thumbstyle = $thumbtype;
121: } else {
122: $style = null;
123: }
124:
125: $json = $GLOBALS['injector']
126: ->getInstance('Ansel_Storage')
127: ->getImageJson($images, $style, true, $thumbsize, true);
128:
129: $json_full = $GLOBALS['injector']
130: ->getInstance('Ansel_Storage')
131: ->getImageJson($images, $style, true, 'screen', true);
132: }
133:
134: $horde_css = $GLOBALS['injector']->getInstance('Horde_Themes_Css');
135: $horde_css->addThemeStylesheet('embed.css');
136:
137:
138: $js_path = $GLOBALS['registry']->get('jsuri', 'horde');
139: $pturl = Horde::url($js_path . '/prototype.js', true);
140: $hjsurl = Horde::url($js_path . '/tooltips.js', true);
141: $ansel_js_path = $GLOBALS['registry']->get('jsuri', 'ansel');
142: $jsurl = Horde::url($ansel_js_path . '/embed.js', true);
143: $hideLinks = (bool)!empty($this->_params['hidelinks']);
144:
145:
146: if (!empty($this->_params['lightbox'])) {
147: $effectsurl = Horde::url($js_path . '/effects.js', true);
148: $lbjsurl = Horde::url($ansel_js_path . '/lightbox.js', true);
149: $horde_css->addThemeStylesheet('lightbox.css');
150: }
151:
152: Horde::startBuffer();
153: Horde::includeStylesheetFiles(array(
154: 'nobase' => true), true);
155: $css = Horde::endBuffer();
156:
157:
158: $html = <<<EOT
159: //<![CDATA[
160: // Old fashioned way to play nice with Safari 2 (Adding script inline with the
161: // DOM won't work). Need two seperate files output here since the incldued
162: // files don't seem to be parsed until after the entire page is loaded, so we
163: // can't include prototype on the same page it's needed.
164:
165: if (typeof anseljson == 'undefined') {
166: if (typeof Prototype == 'undefined') {
167: document.write('<script type="text/javascript" src="$pturl"></script>');
168: }
169: if (typeof Horde_ToolTips == 'undefined') {
170: document.write('<script type="text/javascript" src="$hjsurl"></script>');
171: }
172:
173: anselnodes = new Array();
174: anseljson = new Object();
175: document.write('$css');
176: document.write('<script type="text/javascript" src="$jsurl"></script>');
177: }
178: anselnodes[anselnodes.length] = '$node';
179: anseljson['$node'] = new Object();
180: anseljson['$node']['data'] = $json;
181: anseljson['$node']['perpage'] = $perpage;
182: anseljson['$node']['page'] = 0;
183: anseljson['$node']['hideLinks'] = '$hideLinks';
184: //]]>
185:
186: EOT;
187:
188: if (!empty($lbjsurl)) {
189: $loading_img = Horde_Themes::img('lightbox/loading.gif');
190: $close_img = Horde_Themes::img('lightbox/closelabel.gif');
191: $imageText = _("Photo");
192: $labelOf = _("of");
193: $html .= <<<EOT
194: if (typeof Effect == 'undefined') {
195: document.write('<script type="text/javascript" src="$effectsurl"></script>');
196: }
197:
198: /* Make sure we only include this stuff once */
199: if (typeof lbOptions == 'undefined') {
200:
201: document.write('<script type="text/javascript" src="$lbjsurl"></script>');
202:
203: lbOptions = {
204: fileLoadingImage: '$loading_img',
205: fileBottomNavCloseImage: '$close_img',
206: overlayOpacity: 0.8,
207: animate: true,
208: resizeSpeed: 7,
209: borderSize: 10,
210: labelImage: '$imageText',
211: labelOf: '$labelOf',
212: returnURL: '#',
213: startPage: 0
214: }
215: }
216: anseljson['$node']['lightbox'] = $json_full;
217: EOT;
218: }
219:
220: return $html;
221: }
222:
223: }
224: