1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Ansel_Api extends Horde_Registry_Api
16: {
17: 18: 19: 20: 21: 22: 23: 24: 25:
26: public function browse($path = '', array $properties = array())
27: {
28:
29: if (!$properties) {
30: $properties = array('name', 'icon', 'browseable');
31: }
32:
33: if (substr($path, 0, 5) == 'ansel') {
34: $path = substr($path, 5);
35: }
36: $path = trim($path, '/');
37: $parts = explode('/', $path);
38:
39: $storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
40: if (empty($path)) {
41: $owners = array();
42: $galleries = $storage->listGalleries(array('all_levels' => false));
43: foreach ($galleries as $gallery) {
44: $owners[$gallery->get('owner') ? $gallery->get('owner') : '-system-'] = true;
45: }
46:
47: $results = array();
48: foreach (array_keys($owners) as $owner) {
49: if (in_array('name', $properties)) {
50: $results['ansel/' . $owner]['name'] = $owner;
51: }
52: if (in_array('icon', $properties)) {
53: $results['ansel/' . $owner]['icon'] = Horde_Themes::img('user.png');
54: }
55: if (in_array('browseable', $properties)) {
56: $results['ansel/' . $owner]['browseable'] = true;
57: }
58: if (in_array('contenttype', $properties)) {
59: $results['ansel/' . $owner]['contenttype'] =
60: 'httpd/unix-directory';
61: }
62: if (in_array('contentlength', $properties)) {
63: $results['ansel/' . $owner]['contentlength'] = 0;
64: }
65: if (in_array('modified', $properties)) {
66: $results['ansel/' . $owner]['modified'] = time();
67: }
68: if (in_array('created', $properties)) {
69: $results['ansel/' . $owner]['created'] = 0;
70: }
71: }
72: return $results;
73: } else {
74: if (count($parts) == 1) {
75:
76: $galleries = $storage->listGalleries(
77: array('attributes' => $parts[0],
78: 'all_levels' => false));
79: $images = array();
80: } elseif ($this->galleryExists(null, end($parts))) {
81:
82:
83: $gallery_id = end($parts);
84: $galleries = $storage->listGalleries(
85: array('parent' => $gallery_id,
86: 'all_levels' => false,
87: 'perm' => Horde_Perms::SHOW));
88: $images = $this->listImages(
89: $gallery_id,
90: array('perms' => Horde_Perms::SHOW,
91: 'view' => 'mini'));
92:
93: } elseif (count($parts) > 2 &&
94: $this->galleryExists(null, $parts[count($parts) - 2]) &&
95: ($image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(end($parts)))) {
96:
97: return array(
98: 'data' => $image->raw(),
99: 'mimetype' => $image->type,
100: 'mtime' => $image->uploaded);
101: } else {
102: throw new Horde_Exception_NotFound(_("File not found."));
103: }
104:
105: $results = array();
106: foreach ($galleries as $gallery) {
107: $retpath = 'ansel/' . implode('/', $parts) . '/' . $gallery->id;
108: if (in_array('name', $properties)) {
109: $results[$retpath]['name'] = $gallery->get('name');
110: }
111: if (in_array('displayname', $properties)) {
112: $results[$retpath]['displayname'] = rawurlencode($gallery->get('name'));
113: }
114: if (in_array('icon', $properties)) {
115: $results[$retpath]['icon'] = Horde_Themes::img('ansel.png');
116: }
117: if (in_array('browseable', $properties)) {
118: $results[$retpath]['browseable'] = $gallery->hasPermission(
119: $GLOBALS['registry']->getAuth(), Horde_Perms::READ);
120: }
121: if (in_array('contenttype', $properties)) {
122: $results[$retpath]['contenttype'] = 'httpd/unix-directory';
123: }
124: if (in_array('contentlength', $properties)) {
125: $results[$retpath]['contentlength'] = 0;
126: }
127: if (in_array('modified', $properties)) {
128: $results[$retpath]['modified'] = time();
129: }
130: if (in_array('created', $properties)) {
131: $results[$retpath]['created'] = 0;
132: }
133: }
134:
135: foreach ($images as $imageId => $image) {
136: $retpath = 'ansel/' . implode('/', $parts) . '/' . $imageId;
137: if (in_array('name', $properties)) {
138: $results[$retpath]['name'] = $image['name'];
139: }
140: if (in_array('displayname', $properties)) {
141: $results[$retpath]['displayname'] = rawurlencode($image['name']);
142: }
143: if (in_array('icon', $properties)) {
144: $results[$retpath]['icon'] = Horde::url($image['url'], true);
145: }
146: if (in_array('browseable', $properties)) {
147: $results[$retpath]['browseable'] = false;
148: }
149: if (in_array('contenttype', $properties)) {
150: $results[$retpath]['contenttype'] = $image['type'];
151: }
152: if (in_array('contentlength', $properties)) {
153: $results[$retpath]['contentlength'] = 0;
154: }
155: if (in_array('modified', $properties)) {
156: $results[$retpath]['modified'] = $image['uploaded'];
157: }
158: if (in_array('created', $properties)) {
159: $results[$retpath]['created'] = $image['uploaded'];
160: }
161: }
162: return $results;
163:
164: }
165:
166: throw Horde_Exception_NotFound(_("File not found."), 404);
167: }
168:
169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179:
180: public function put($path, $content, $content_type)
181: {
182: if (substr($path, 0, 5) == 'ansel') {
183: $path = substr($path, 9);
184: }
185: $path = trim($path, '/');
186: $parts = explode('/', $path);
187:
188: if (count($parts) < 3) {
189: throw new Horde_Exception_NotFound("Gallery does not exist");
190: }
191: $image_name = array_pop($parts);
192: $gallery_id = end($parts);
193: if (!$GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($gallery_id)) {
194: throw new Horde_Exception_NotFound("Gallery does not exist");
195: }
196: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
197: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
198: throw new Horde_Exception_PermissionDenied(_("Access denied adding photos to \"%s\"."));
199: }
200:
201: return $gallery->addImage(array(
202: 'image_type' => $content_type,
203: 'image_filename' => $image_name,
204: 'image_caption' => '',
205: 'data' => $content));
206: }
207:
208: 209: 210: 211: 212: 213: 214:
215: public function ($image_id)
216: {
217: if (!$GLOBALS['conf']['comments']['allow']) {
218: return false;
219: }
220:
221: try {
222: if (!($image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id))) {
223: return false;
224: }
225: } catch (Ansel_Exception $e) {
226: return false;
227: }
228:
229: return $image->filename;
230: }
231:
232: 233: 234: 235: 236:
237: public function ()
238: {
239: if (($GLOBALS['conf']['comments']['allow'] == 'all' ||
240: ($GLOBALS['conf']['comments']['allow'] == 'authenticated' &&
241: $GLOBALS['registry']->getAuth()))) {
242: return true;
243: } else {
244: return false;
245: }
246: }
247:
248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259:
260: protected function _getImageData($data, $encoding = 'none', $compression = 'none', $upload = true)
261: {
262: switch ($encoding) {
263: case 'base64':
264: $data = $upload ? base64_decode($data) : base64_encode($data);
265: break;
266:
267: case 'binhex':
268: $data = $upload ? pack('H*', $data) : unpack('H*', $data);
269: }
270:
271: switch ($compression) {
272: case 'gzip':
273: if (Horde_Util::loadExtension('zlib')) {
274: return $upload ? gzuncompress($data) : gzcompress($data);
275: }
276: break;
277:
278: case 'lzf':
279: if (Horde_Util::loadExtension('lzf')) {
280: return $upload ? lzf_decompress($data) : lzf_compress($data);
281: }
282: break;
283:
284: default:
285: return $data;
286: }
287: }
288:
289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314:
315: public function saveImage($gallery_id, array $image, array $params = array())
316: {
317:
318: if (!empty($params['scope'])) {
319: $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
320: }
321:
322:
323: if (isset($image['filename']) &&
324: isset($image['description']) &&
325: isset($image['data']) &&
326: isset($image['type'])) {
327: Horde::logMessage(sprintf("Receiving image %s in saveImage() with a raw filesize of %i", $image['filename'], strlen($image['data'])), 'DEBUG');
328: $image_data = array(
329: 'image_filename' => $image['filename'],
330: 'image_caption' => $image['description'],
331: 'image_type' => $image['type'],
332: 'data' => $this->_getImageData($image['data'], (empty($params['encoding']) ? 'none' : $params['encoding']), (empty($params['compression']) ? 'none' : $params['compression']), true));
333: }
334:
335:
336: if (empty($image_data) && getimagesize($image['file']) === false) {
337: throw new InvalidArgumentException(_("The file you uploaded does not appear to be a valid photo."));
338: }
339: if (empty($params['slug']) && empty($gallery_id)) {
340: throw new InvalidArgumentException(_("A gallery to add this photo to is required."));
341: }
342: if (!empty($params['slug'])) {
343: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleryBySlug($params['slug']);
344: } elseif ($GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($gallery_id)) {
345: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
346: }
347:
348:
349: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
350: throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name')));
351: }
352:
353:
354: if (!empty($params['gallery_data'])) {
355: foreach ($params['gallery_data'] as $key => $value) {
356: $gallery->set($key, $value);
357: }
358: $gallery->save();
359: }
360:
361: if (empty($image_data)) {
362: $image_data = array(
363: 'image_filename' => $image['name'],
364: 'image_caption' => $image['name'],
365: 'image_type' => $image['name']['type'],
366: 'data' => file_get_contents($image['file']),
367: );
368: }
369:
370: if (isset($image['tags']) && is_array($image['tags']) && count($image['tags'])) {
371: $image_data['tags'] = $image['tags'];
372: }
373: $image_id = $gallery->addImage($image_data, !empty($params['default']));
374:
375:
376: if (empty($params['skiphook'])) {
377: $this->postBatchUpload($image_id);
378: }
379:
380: return array(
381: 'image_id' => (int)$image_id,
382: 'gallery_id' => (int)$gallery->id,
383: 'gallery_slug' => $gallery->get('slug'),
384: 'image_count' => (int)$gallery->countImages());
385: }
386:
387: 388: 389: 390: 391: 392: 393:
394: public function postBatchUpload(array $image_ids)
395: {
396: try {
397: Horde::callHook('postupload', array($image_ids), 'ansel');
398: } catch (Horde_Exception_HookNotSet $e) {}
399: }
400:
401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412:
413: public function removeImage($gallery_id, $image_id, array $params = array())
414: {
415:
416: if (!$GLOBALS['injector']->getInstance('Horde_Perms')->getPermissions('ansel', $GLOBALS['registry']->getAuth())) {
417: throw new Horde_Exception_PermissionDenied(_("Access denied deleting galleries."));
418: }
419:
420:
421: if (!empty($params['scope'])) {
422: $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
423: }
424:
425: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
426: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
427: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
428: throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name')));
429: }
430:
431: $gallery->removeImage($image);
432: }
433:
434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450:
451: public function createGallery($attributes, array $params = array())
452: {
453: if (!($GLOBALS['registry']->isAdmin() ||
454: (!$GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') && $GLOBALS['registry']->getAuth()) ||
455: $GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('ansel', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT))) {
456:
457: throw new Horde_Exception_PermissionDenied(_("Access denied creating new galleries."));
458: }
459:
460:
461: if (!empty($params['scope'])) {
462: $GLOBALS['injector']->getInstance('Ansel_Config')
463: ->set('scope', $params['scope']);
464: }
465:
466:
467: if (!empty($params['perm'])) {
468:
469:
470: $permobj = new Horde_Perms_Permission('');
471: $permobj->data = $perm;
472: } else {
473: $permobj = null;
474: }
475:
476:
477: $gallery = $GLOBALS['injector']
478: ->getInstance('Ansel_Storage')
479: ->createGallery(
480: $attributes,
481: $permobj,
482: (!empty($params['parent']) ? $params['parent'] : null));
483:
484: return $gallery->id;
485: }
486:
487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498:
499: public function removeGallery($gallery_id, array $params = array())
500: {
501:
502: if (!$GLOBALS['injector']->getInstance('Horde_Perms')->getPermissions('ansel', $GLOBALS['registry']->getAuth())) {
503: throw new Horde_Exception_PermissionDenied(_("Access denied deleting galleries."));
504: }
505:
506:
507: if (!empty($params['scope'])) {
508: $GLOBALS['injector']->getInstance('Ansel_Config')
509: ->set('scope', $params['scope']);
510: }
511:
512:
513: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
514: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
515: throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied deleting gallery \"%s\"."), $gallery->get('name')));
516: } else {
517: $GLOBALS['injector']
518: ->getInstance('Ansel_Storage')
519: ->removeGallery($gallery);
520: }
521: }
522:
523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535:
536: public function count($gallery_id = null, array $params = array())
537: {
538: if (!empty($params['scope'])) {
539: $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
540: }
541:
542: try {
543: if (!empty($params['slug'])) {
544: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleryBySlug($params['slug']);
545: } else {
546: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
547: }
548: return (int)$gallery->countImages();
549: } catch (Ansel_Exception $e) {
550: return 0;
551: }
552: }
553:
554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566:
567: public function getGalleryKeyImage($gallery_id, array $params = array())
568: {
569: if (!empty($params['scope'])) {
570: $GLOBALS['injector']->getInstance('Ansel_Config')
571: ->set('scope', $params['scope']);
572: }
573:
574: if (!empty($params['slug'])) {
575: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')
576: ->getGalleryBySlug($params['slug']);
577: } else {
578: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')
579: ->getGallery($gallery_id);
580: }
581:
582: $style = empty($params['style']) ?
583: Ansel::getStyleDefinition('ansel_default') :
584: Ansel::getStyleDefinition($params['style']);
585:
586: return $gallery->getKeyImage($style);
587: }
588:
589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602:
603: public function getImageUrl($image_id, array $params = array())
604: {
605: if (!empty($params['scope'])) {
606: $GLOBALS['injector']->getInstance('Ansel_Config')
607: ->set('scope', $params['scope']);
608: }
609:
610: $style = empty($params['style']) ?
611: Ansel::getStyleDefinition('ansel_default') :
612: Ansel::getStyleDefinition($params['style']);
613:
614: return (string)Ansel::getImageUrl(
615: $image_id,
616: empty($params['view']) ? 'screen': $params['view'],
617: empty($params['full']) ? false : $params['full'],
618: $style);
619: }
620:
621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639:
640: public function getImageContent($image_id, array $params = array())
641: {
642: if (!empty($params['scope'])) {
643: $GLOBALS['injector']->getInstance('Ansel_Config')
644: ->set('scope', $params['scope']);
645: }
646:
647:
648: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')
649: ->getImage($image_id);
650: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')
651: ->getGallery($image->gallery);
652:
653:
654: if ($gallery->hasPasswd() || !$gallery->isOldEnough()) {
655: throw new Horde_Exception_PermissionDenied(
656: _("Locked galleries are not viewable via the api."));
657: }
658:
659: if ($view == 'full') {
660:
661: if (!$gallery->canDownload()) {
662: throw new Horde_Exception_PermissionDenied(
663: sprintf(_("Access denied downloading full sized photos from \"%s\"."), $gallery->get('name')));
664: }
665:
666:
667: try {
668: $data = $GLOBALS['injector']
669: ->getInstance('Horde_Core_Factory_Vfs')
670: ->create('images')
671: ->read($image->getVFSPath('full'), $image->getVFSName('full'));
672: } catch (Horde_Vfs_Exception $e) {
673: Horde::logMessage($e->getMessage(), 'ERR');
674: throw new Ansel_Exception($e->getMessage());
675: }
676: } else {
677: if (!empty($params['style'])) {
678: $params['style'] = Ansel::getStyleDefinition($style);
679: } else {
680: $params['style'] = null;
681: }
682: $image->load($view, $params['style']);
683: $data = $image->_image->raw();
684: }
685:
686: return $this->_getImageData($data, $encoding, $compression, false);
687: }
688:
689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710:
711: public function listGalleries(array $params = array())
712: {
713:
714: if (!empty($params['scope'])) {
715: $GLOBALS['injector']->getInstance('Ansel_Config')
716: ->set('scope', $params['scope']);
717: }
718: $galleries = $GLOBALS['injector']
719: ->getInstance('Ansel_Storage')
720: ->listGalleries($params);
721: $return = array();
722: foreach ($galleries as $gallery) {
723: $return[] = array_merge(
724: $gallery->toArray(),
725: array('crumbs' => $gallery->getGalleryCrumbData()));
726: }
727:
728: return $return;
729: }
730:
731: 732: 733: 734: 735: 736: 737: 738: 739:
740: public function getGalleries(array $ids, $app = null, array $slugs = array())
741: {
742: if (!is_null($app)) {
743: $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
744: }
745:
746: if (count($slugs)) {
747: $results = $GLOBALS['injector']->getInstance('Ansel_Storage')
748: ->getGalleriesBySlugs($slugs);
749: } else {
750: $results = $GLOBALS['injector']->getInstance('Ansel_Storage')
751: ->getGalleries($ids);
752: }
753:
754:
755:
756: $galleries = array();
757: foreach ($results as $gallery) {
758: $galleries[$gallery->id] = array_merge(
759: $gallery->toArray(),
760: array('crumbs' => $gallery->getGalleryCrumbData()));
761: }
762:
763: return $galleries;
764: }
765:
766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783:
784: public function selectGalleries(array $params = array())
785: {
786: if (!empty($params['scope'])) {
787: $GLOBALS['injector']->getInstance('Ansel_Config')
788: ->set('scope', $params['scope']);
789: unset($params['scope']);
790: }
791:
792: return Ansel::selectGalleries($params);
793: }
794:
795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823:
824: public function listImages($gallery_id, array $params = array())
825: {
826: $params = new Horde_Support_Array($params);
827: if ($params->app) {
828: $GLOBALS['injector']->getInstance('Ansel_Config')
829: ->set('scope', $params->app);
830: }
831: $storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
832: if ($params->slug) {
833: $gallery = $storage->getGalleryBySlug($params->slug);
834: } else {
835: $gallery = $storage->getGallery($gallery_id);
836: }
837: $images = $gallery->listImages($params->get('from', 0), $params->get('limit', 0));
838: if ($params->style) {
839: $params->style = Ansel::getStyleDefinition($params->style);
840: } else {
841: $params->style = $gallery->getStyle();
842: }
843:
844: $counter = 0;
845: $imagelist = array();
846: foreach ($images as $id) {
847: $image = $storage->getImage($id);
848: $imagelist[$id]['name'] = $image->filename;
849: $imagelist[$id]['caption'] = $image->caption;
850: $imagelist[$id]['type'] = $image->type;
851: $imagelist[$id]['uploaded'] = $image->uploaded;
852: $imagelist[$id]['original_date'] = $image->originalDate;
853: $imagelist[$id]['url'] = Ansel::getImageUrl(
854: $id, $params->get('view', 'thumb'), $params->get('full', false), $params->style);
855: if ($params->app && $GLOBALS['conf']['vfs']['src'] != 'direct') {
856: $imagelist[$id]['url']->add('app', $params->app);
857: }
858: $imagelist[$id]['url'] = $imagelist[$id]['url']->toString();
859: }
860:
861: return $imagelist;
862: }
863:
864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881:
882: public function getRecentImages(array $params = array())
883: {
884: $params = new Horde_Support_Array($params);
885:
886: if ($params->app) {
887: $GLOBALS['injector']->getInstance('Ansel_Config')
888: ->set('scope', $params->app);
889: }
890: $images = $GLOBALS['injector']->getInstance('Ansel_Storage')
891: ->getRecentImages(
892: $params->get('galleries', array()),
893: $params->get('limit', 10),
894: $params->get('slugs', array()));
895: $imagelist = array();
896: if ($params->style) {
897: $params->style = Ansel::getStyleDefinition($params->style);
898: }
899: foreach ($images as $image) {
900: $id = $image->id;
901: $imagelist[$id]['id'] = $id;
902: $imagelist[$id]['name'] = $image->filename;
903: $imagelist[$id]['url'] = Ansel::getImageUrl(
904: $id,
905: $params->get('view', 'screen'),
906: $params->get('full', false),
907: $params->style);
908: $imagelist[$id]['caption'] = $image->caption;
909: $imagelist[$id]['filename'] = $image->filename;
910: $imagelist[$id]['gallery'] = $image->gallery;
911: $imagelist[$id]['uploaded'] = $image->uploaded;
912: $imagelist[$id]['original_date'] = $image->originalDate;
913:
914: if ($params->app && $GLOBALS['conf']['vfs']['src'] != 'direct') {
915: $imagelist[$id]['url']->add('app', $params->app);
916: }
917: }
918: return $imagelist;
919:
920: }
921:
922: 923: 924: 925: 926: 927: 928: 929: 930: 931: 932: 933: 934: 935: 936: 937: 938:
939: public function countGalleries(array $params = array())
940: {
941: if (!empty($params['app'])) {
942: $GLOBALS['injector']->getInstance('Ansel_Config')
943: ->set('scope', $params['app']);
944: unset($params['app']);
945: }
946:
947: return $GLOBALS['injector']->getInstance('Ansel_Storage')
948: ->countGalleries(
949: $GLOBALS['registry']->getAuth(),
950: $params);
951: }
952:
953: 954: 955: 956: 957: 958: 959: 960: 961:
962: public function listTagInfo($tags = null, $user = null)
963: {
964: return $GLOBALS['injector']->getInstance('Ansel_Tagger')->getTagInfo($tags, 500, null, $user);
965: }
966:
967: 968: 969: 970: 971: 972: 973: 974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985: 986: 987: 988: 989:
990: public function searchTags($names, $max = 10, $from = 0,
991: $resource_type = '', $user = null, $raw = false,
992: $app = 'ansel')
993: {
994: $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
995: $results = $GLOBALS['injector']
996: ->getInstance('Ansel_Tagger')
997: ->search(
998: $names,
999: array('type' => $resource_type, 'user' => $user));
1000:
1001:
1002: if ($raw) {
1003: return $results;
1004: }
1005:
1006: $return = array();
1007: if (!empty($results['images'])) {
1008: foreach ($results['images'] as $image_id) {
1009: $image = $GLOBALS['injector']
1010: ->getInstance('Ansel_Storage')
1011: ->getImage($image_id);
1012: $g = $GLOBALS['injector']
1013: ->getInstance('Ansel_Storage')
1014: ->getGallery($image->gallery);
1015: $view_url = Ansel::getUrlFor('view',
1016: array('gallery' => $image->gallery,
1017: 'image' => $image_id,
1018: 'view' => 'Image'),
1019: true);
1020: $gurl = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $image->gallery));
1021: $return[] = array(
1022: 'title' => $image->filename,
1023: 'desc'=> $image->caption . ' '. _("from") . ' ' . $gurl->link() . $g->get('name') . '</a>',
1024: 'view_url' => $view_url,
1025: 'app' => $app,
1026: 'icon' => Ansel::getImageUrl($image_id, 'mini'));
1027: }
1028: }
1029:
1030: if (!empty($results['galleries'])) {
1031: foreach ($results['galleries'] as $gallery) {
1032: $gal = $GLOBALS['injector']
1033: ->getInstance('Ansel_Storage')
1034: ->getGallery($gallery);
1035: $view_url = Horde::url('view.php')
1036: ->add(
1037: array('gallery' => $gallery,
1038: 'view' => 'Gallery'));
1039: $gurl = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery));
1040: $return[] = array(
1041: 'desc' => $gurl->link() . $gal->get('name') . '</a>',
1042: 'view_url' => $view_url,
1043: 'app' => $app,
1044: 'icon' => Ansel::getImageUrl($gal->getKeyImage(), 'mini'));
1045: }
1046: }
1047:
1048: return $return;
1049: }
1050:
1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059:
1060: public function galleryExists($gallery_id, $slug = '', $app = null)
1061: {
1062: if (!is_null($app)) {
1063: $GLOBALS['injector']->getInstance('Ansel_Config')
1064: ->set('scope', $app);
1065: }
1066:
1067: return $GLOBALS['injector']->getInstance('Ansel_Storage')
1068: ->galleryExists($gallery_id, $slug);
1069: }
1070:
1071: 1072: 1073: 1074: 1075:
1076: public function getGalleryStyles()
1077: {
1078: return $GLOBALS['injector']->getInstance('Ansel_Styles');
1079: }
1080:
1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092:
1093: public function renderView($params = array(), $app = null, $view = 'Gallery')
1094: {
1095: if (!is_null($app)) {
1096: $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
1097: }
1098: $classname = 'Ansel_View_' . basename($view);
1099: $params['api'] = true;
1100: $params['view'] = $view;
1101: $trail = array();
1102: $return = array();
1103: try {
1104: $view = new $classname($params);
1105: } catch (Horde_Exception $e) {
1106: $return['html'] = $e->getMessage();
1107: $return['crumbs'] = array();
1108: return $return;
1109: }
1110: $return['html'] = $view->html();
1111: if ($params['view'] == 'Gallery' || $params['view'] == 'Image') {
1112: $trail = $view->getGalleryCrumbData();
1113: }
1114: $return['crumbs'] = $trail;
1115:
1116: return $return;
1117: }
1118:
1119: }
1120: