1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Ansel_GalleryMode_Normal extends Ansel_GalleryMode_Base
15: {
16: 17: 18: 19: 20:
21: protected $_features = array('subgalleries', 'stacks', 'sort_images',
22: 'image_captions', 'faces', 'slideshow',
23: 'zipdownload', 'upload');
24:
25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: public function getGalleryChildren($perm = Horde_Perms::SHOW, $from = 0, $to = 0)
36: {
37: $galleries = array();
38: $num_galleries = 0;
39: if ($this->hasSubGalleries()) {
40: $storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
41:
42: $numimages = $this->countImages();
43: $num_galleries = $storage->countGalleries(
44: $GLOBALS['registry']->getAuth(),
45: array('parent' => $this->_gallery, 'all_levels' => false));
46:
47:
48: if ($num_galleries > $from) {
49: $galleries = $storage->listGalleries(
50: array('parent' => $this->_gallery->id,
51: 'all_levels' => false,
52: 'from' => $from,
53: 'count' => $to));
54: }
55: }
56:
57:
58: if (($to - count($galleries) > 0) || ($from == 0 && $to == 0) &&
59: $this->_gallery->get('images')) {
60:
61: try {
62: $images = $this->getImages(max(0, $from - $num_galleries), $to - count($galleries));
63: } catch (Ansel_Exception $e) {
64: Horde::logMessage($e->getMessage(), 'ERR');
65: $images = array();
66: }
67: } else {
68: $images = array();
69: }
70:
71: return array_merge($galleries, $images);
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function getGalleryCrumbData()
81: {
82: $trail = array();
83: $text = htmlspecialchars($this->_gallery->get('name'));
84: $navdata = array('view' => 'Gallery',
85: 'gallery' => $this->_gallery->id,
86: 'slug' => $this->_gallery->get('slug'));
87: $trail[] = array('title' => $text, 'navdata' => $navdata);
88: $parent_list = array_reverse($this->_gallery->getParents());
89: foreach ($parent_list as $p) {
90: $text = htmlspecialchars($p->get('name'));
91: $navdata = array('view' => 'Gallery',
92: 'gallery' => $p->id,
93: 'slug' => $p->get('slug'));
94: $trail[] = array('title' => $text, 'navdata' => $navdata);
95: }
96:
97: return $trail;
98: }
99:
100: 101: 102: 103: 104: 105: 106: 107:
108: public function countGalleryChildren($perm = Horde_Perms::SHOW, $galleries_only = false)
109: {
110: if (!$galleries_only && !$this->hasSubGalleries()) {
111: return $this->_gallery->get('images');
112: }
113:
114: $gCnt = $GLOBALS['injector']->getInstance('Ansel_Storage')
115: ->countGalleries(
116: $GLOBALS['registry']->getAuth(),
117: array('perm' => $perm,
118: 'parent' => $this->_gallery,
119: 'all_levels' => false));
120:
121: if (!$galleries_only) {
122: $iCnt = $this->countImages(false);
123: } else {
124: $iCnt = 0;
125: }
126:
127: return $gCnt + $iCnt;
128: }
129:
130: 131: 132: 133: 134: 135: 136: 137:
138: public function listImages($from = 0, $count = 0)
139: {
140: return $GLOBALS['injector']
141: ->getInstance('Ansel_Storage')
142: ->listImages(array(
143: 'gallery_id' => $this->_gallery->id,
144: 'offset' => $from,
145: 'limit' => $count));
146: }
147:
148: 149: 150: 151: 152: 153: 154: 155: 156: 157:
158: public function moveImagesTo($images, $gallery)
159: {
160: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
161: throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
162: } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
163: throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
164: }
165:
166:
167: $ids = array();
168: foreach ($images as $imageId) {
169: $ids[] = (int)$imageId;
170: if ($imageId == $this->_gallery->get('default')) {
171: $this->_gallery->set('default', null, true);
172: }
173: }
174:
175: $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id);
176: $this->_gallery->updateImageCount(count($ids), false);
177: $gallery->updateImageCount(count($ids), true);
178:
179:
180: if ($GLOBALS['conf']['ansel_cache']['usecache']) {
181: $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
182: $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
183: }
184:
185: return count($ids);
186: }
187:
188: 189: 190: 191: 192: 193: 194: 195: 196:
197: public function removeImage($image, $isStack)
198: {
199:
200: if (!($image instanceof Ansel_Image)) {
201: $image = $this->_gallery->getImage($image);
202: } else {
203:
204: if (abs($image->gallery) != $this->_gallery->id) {
205: throw new Horde_Exception_NotFound(_("Image not found in gallery."));
206: }
207: }
208:
209:
210: if ($this->_gallery->get('default') == $image->id) {
211: $this->_gallery->set('default', null);
212: $this->_gallery->set('default_type', 'auto');
213: }
214:
215:
216: $image->deleteCache();
217:
218:
219: try {
220: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile($image->getVFSPath('full'), $image->getVFSName('full'));
221: } catch (Horde_Vfs_Exception $e) {}
222:
223:
224: $GLOBALS['injector']->getInstance('Ansel_Storage')->removeImage($image->id);
225: if (!$isStack) {
226: $this->_gallery->updateImageCount(1, false);
227: }
228:
229:
230: if (!$isStack) {
231: $this->_gallery->set('last_modified', time());
232: }
233:
234:
235: $this->_gallery->save();
236:
237:
238: $image->setTags(array());
239:
240:
241: if ($image->facesCount) {
242: Ansel_Faces::delete($image);
243: }
244:
245:
246: if (($GLOBALS['conf']['comments']['allow'] == 'all' || ($GLOBALS['conf']['comments']['allow'] == 'authenticated' && $GLOBALS['registry']->getAuth())) &&
247: $GLOBALS['registry']->hasMethod('forums/deleteForum')) {
248:
249: try {
250: $result = $GLOBALS['registry']->forums->deleteForum('ansel', $image->id);
251: } catch (Horde_Exception $e) {
252: Horde::logMessage($e, 'ERR');
253: return false;
254: }
255: }
256:
257: return true;
258: }
259:
260: 261: 262: 263: 264: 265: 266: 267:
268: public function getImages($from = 0, $count = 0)
269: {
270: $images = $GLOBALS['injector']->getInstance('Ansel_Storage')
271: ->getImages(array('gallery_id' => $this->_gallery->id,
272: 'count' => $count,
273: 'from' => $from));
274:
275: return array_values($images);
276: }
277:
278: 279: 280: 281: 282:
283: public function hasSubGalleries()
284: {
285: return $this->_gallery->get('has_subgalleries') == 1;
286: }
287:
288: 289: 290: 291: 292: 293: 294: 295: 296:
297: public function countImages($subgalleries = false)
298: {
299: if ($subgalleries && $this->hasSubGalleries()) {
300: $count = $this->countImages(false);
301: $galleries = $GLOBALS['injector']
302: ->getInstance('Ansel_Storage')
303: ->listGalleries(array('parent' => $this->_gallery->id));
304:
305: foreach ($galleries as $galleryId => $gallery) {
306: $count += $gallery->countImages();
307: }
308:
309: return $count;
310: }
311:
312: return $this->_gallery->get('images');
313: }
314: }
315: