1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Ansel_View_GalleryProperties
15: {
16: 17: 18: 19: 20:
21: protected $_params;
22:
23: 24: 25: 26: 27:
28: protected $_properties;
29:
30: 31: 32: 33: 34:
35: protected $_title;
36:
37: 38: 39: 40: 41:
42: public function __construct($params = array())
43: {
44: $this->_params = $params;
45: }
46:
47: 48: 49: 50: 51:
52: public function run()
53: {
54: switch ($this->_params['actionID']) {
55: case 'add':
56: $this->_runNew();
57: $this->_output();
58: break;
59: case 'addchild':
60: $this->_runNewChild();
61: $this->_output();
62: break;
63: case 'modify':
64: $this->_runEdit();
65: $this->_output();
66: break;
67: case 'save':
68: $this->_runSave();
69: break;
70: }
71: }
72:
73: private function _loadDefaults()
74: {
75:
76: $this->_properties = array(
77: 'name' => '',
78: 'desc' => '',
79: 'tags' => '',
80: 'style' => Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle')),
81: 'slug' => '',
82: 'age' => 0,
83: 'download' => $GLOBALS['prefs']->getValue('default_download'),
84: 'parent' => null,
85: 'id' => null,
86: 'mode' => 'Normal',
87: 'passwd' => '',
88: 'owner' => ''
89: );
90: }
91:
92: 93: 94: 95: 96:
97: private function _output()
98: {
99: $view = new Horde_View(array('templatePath' => array(ANSEL_TEMPLATES . '/gallery',
100: ANSEL_TEMPLATES . '/gallery/partial',
101: ANSEL_TEMPLATES . '/gallery/layout')));
102: $view->addHelper('Text');
103: $view->properties = $this->_properties;
104: $view->title = $this->_title;
105: $view->action = $this->_params['actionID'];
106: $view->url = $this->_params['url'];
107: $view->availableThumbs = $this->_thumbStyles();
108: $view->galleryViews = $this->_galleryViewStyles();
109: $view->locked = array('download' => $GLOBALS['prefs']->isLocked('default_download'));
110: $view->isOwner = $GLOBALS['registry']->getAuth() &&
111: $GLOBALS['registry']->getAuth() == $this->_properties['owner'];
112:
113: $view->havePretty = $GLOBALS['conf']['image']['prettythumbs'];
114: $view->ages = $GLOBALS['conf']['ages']['limits'];
115:
116: $js = array('$("gallery_name").focus()');
117: if ($GLOBALS['conf']['image']['type'] != 'png') {
118: $js[] = 'function checkStyleSelection()
119: {
120: var s, bg = $F("background_color");
121: $A($("thumbnail_style").options).each(function(o) {
122: if (o.value == "Thumb" && o.selected == "1") {
123: s = true;
124: }
125: });
126: if (bg == "none" && !s) {
127: alert("' . _("Your server does not support thumbnails with transparent backgrounds. Either select a background color or use the 'Basic Thumbnail' type. Please contact your server administrator for more information.") . '");
128: $A($("thumbnail_style").options).each(function(o) {
129: if (o.value == "Thumb") {
130: o.selected = "1";
131: }
132: })
133: }
134: }';
135: $js[] = '$("background_color").observe("change", checkStyleSelection); $("thumbnail_style").observe("change", checkStyleSelection);';
136: }
137: Horde::addInlineScript($js, 'dom');
138: Horde::addScriptFile('stripe.js', 'horde');
139: Horde::addScriptFile('popup.js', 'horde');
140:
141:
142: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('ansel', 'GallerySlugCheck'), array(
143: 'bindTo' => 'gallery_slug',
144: 'slug' => $this->_properties['slug']
145: ));
146:
147: require $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc';
148: echo Horde::menu();
149: $GLOBALS['notification']->notify(array('listeners' => 'status'));
150: echo $view->render('properties');
151: require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc';
152: }
153:
154: 155: 156: 157: 158:
159: private function _runNew()
160: {
161: $this->_loadDefaults();
162: $this->_title = _("Adding a New Gallery");
163: $this->_properties['owner'] = $GLOBALS['registry']->getAuth();
164: }
165:
166: 167: 168: 169: 170:
171: private function _runNewChild()
172: {
173: $this->_loadDefaults();
174:
175:
176:
177: $parentId = $this->_params['gallery'];
178: try {
179: $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($parentId);
180: } catch (Ansel_Exception $e) {
181: $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
182: Horde::url('view.php?view=List', true)->redirect();
183: exit;
184: }
185:
186: if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
187: $GLOBALS['notification']->push(sprintf(_("Access denied adding a gallery to \"%s\"."),
188: $parent->get('name')), 'horde.error');
189: Horde::url('view.php?view=List', true)->redirect();
190: exit;
191: }
192:
193:
194: $this->_properties['style'] = $parent->get('style');
195: $this->_properties['parent'] = $parentId;
196: $this->_title = sprintf(_("Adding A Subgallery to %s"), $parent->get('name'));
197: }
198:
199: 200: 201: 202: 203: 204:
205: private function _runEdit()
206: {
207: if (empty($this->_params['gallery'])) {
208: throw new InvalidArgumentException(_("Missing gallery parameter"));
209: }
210:
211: try {
212: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->_params['gallery']);
213: $parent = $gallery->getParent();
214: $this->_properties = array(
215: 'name' => $gallery->get('name'),
216: 'desc' => $gallery->get('desc'),
217: 'tags' => implode(',', $gallery->getTags()),
218: 'slug' => $gallery->get('slug'),
219: 'age' => (int)$gallery->get('age'),
220: 'download' => $gallery->get('download'),
221: 'mode' => $gallery->get('view_mode'),
222: 'passwd' => $gallery->get('passwd'),
223: 'parent' => !is_null($parent) ? $parent->id : $parent,
224: 'id' => $gallery->id,
225: 'owner' => $gallery->get('owner'),
226: 'style' => $gallery->getStyle()
227: );
228: $this->_title = sprintf(_("Modifying: %s"), $this->_properties['name']);
229: } catch (Ansel_Exception $e) {
230: $title = _("Unknown Gallery");
231: }
232: }
233:
234: 235: 236: 237: 238: 239:
240: private function _runSave()
241: {
242:
243: if (!$GLOBALS['registry']->isAdmin() &&
244: ($GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') &&
245: !$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('ansel', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT))) {
246:
247: $GLOBALS['notification']->push(_("Access denied editing galleries."), 'horde.error');
248: Horde::url('view.php?view=List', true)->redirect();
249: exit;
250: }
251:
252:
253: $galleryId = Horde_Util::getFormData('gallery');
254: $gallery_name = Horde_Util::getFormData('gallery_name');
255: $gallery_desc = Horde_Util::getFormData('gallery_desc');
256: $gallery_slug = Horde_Util::getFormData('gallery_slug');
257: $gallery_age = (int)Horde_Util::getFormData('gallery_age', 0);
258: $gallery_download = Horde_Util::getFormData('gallery_download');
259: $gallery_mode = Horde_Util::getFormData('view_mode', 'Normal');
260: $gallery_passwd = Horde_Util::getFormData('gallery_passwd');
261: $gallery_tags = Horde_Util::getFormData('gallery_tags');
262: $gallery_thumbstyle = Horde_Util::getFormData('gallery_style');
263: $gallery_parent = Horde_Util::getFormData('gallery_parent');
264:
265:
266: $style = new Ansel_Style(array(
267: 'thumbstyle' => Horde_Util::getFormData('thumbnail_style'),
268: 'background' => Horde_Util::getFormData('background_color'),
269: 'gallery_view' => Horde_Util::getFormData('gallery_view'),
270:
271: 'widgets' => array(
272: 'Tags' => array('view' => 'gallery'),
273: 'OtherGalleries' => array(),
274: 'Geotag' => array(),
275: 'Links' => array(),
276: 'GalleryFaces' => array(),
277: 'OwnerFaces' => array())
278: ));
279:
280:
281: if (empty($gallery_parent)) {
282: $gallery_parent = null;
283: }
284:
285: if ($galleryId &&
286: ($exists = ($GLOBALS['injector']->getInstance('Ansel_Storage')->galleryExists($galleryId)) === true)) {
287:
288:
289: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($galleryId);
290: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
291: $GLOBALS['notification']->push(sprintf(_("Access denied saving gallery \"%s\"."), $gallery->get('name')), 'horde.error');
292: } else {
293:
294: if ($gallery_name) {
295: $gallery->set('name', $gallery_name);
296: }
297: $gallery->set('desc', $gallery_desc);
298: $gallery->setTags(!empty($gallery_tags) ? explode(',', $gallery_tags) : array());
299: $gallery->set('style', $style);
300: $gallery->set('slug', $gallery_slug);
301: $gallery->set('age', $gallery_age);
302: $gallery->set('download', $gallery_download);
303: $gallery->set('view_mode', $gallery_mode);
304: if ($GLOBALS['registry']->getAuth() &&
305: $gallery->get('owner') == $GLOBALS['registry']->getAuth()) {
306: $gallery->set('passwd', $gallery_passwd);
307: }
308:
309:
310: $old_parent = $gallery->getParent();
311: if (!is_null($old_parent)) {
312: $old_parent_id = $old_parent->id;
313: } else {
314: $old_parent_id = null;
315: }
316: if ($gallery_parent != $old_parent_id) {
317: if (!is_null($gallery_parent)) {
318: $new_parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_parent);
319: } else {
320: $new_parent = null;
321: }
322: try {
323: $result = $gallery->setParent($new_parent);
324: } catch (Ansel_Exception $e) {
325: $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
326: Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
327: exit;
328: }
329: }
330: try {
331: $result = $gallery->save();
332: $GLOBALS['notification']->push(_("The gallery was saved."),'horde.success');
333: } catch (Ansel_Exception $e) {
334: $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
335: }
336: }
337: } else {
338:
339: if ($gallery_parent) {
340: try {
341: $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_parent);
342: } catch (Ansel_Exception $e) {
343: $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
344: Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
345: exit;
346: }
347: if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
348: $GLOBALS['notification']->push(sprintf(
349: _("You do not have permission to add children to %s."),
350: $parent->get('name')), 'horde.error');
351:
352: Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
353: exit;
354: }
355: }
356:
357:
358: if (!$gallery_name) {
359: $GLOBALS['notification']->push(
360: _("You must provide a display name for your new gallery."),
361: 'horde.warning');
362: $actionId = 'add';
363: $title = _("Adding A New Gallery");
364: }
365:
366:
367: $perm = (!empty($parent)) ? $parent->getPermission() : null;
368:
369: try {
370: $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->createGallery(
371: array('name' => $gallery_name,
372: 'desc' => $gallery_desc,
373: 'tags' => explode(',', $gallery_tags),
374: 'style' => $style,
375: 'slug' => $gallery_slug,
376: 'age' => $gallery_age,
377: 'download' => $gallery_download,
378: 'view_mode' => $gallery_mode,
379: 'passwd' => $gallery_passwd,
380: ),
381: $perm, $gallery_parent);
382:
383: $galleryId = $gallery->id;
384: $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
385: Horde::logMessage($msg, 'DEBUG');
386: $GLOBALS['notification']->push($msg, 'horde.success');
387: } catch (Ansel_Exception $e) {
388: $galleryId = null;
389: $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"),
390: $gallery_name, $e->getMessage());
391: Horde::logMessage($error, 'ERR');
392: $GLOBALS['notification']->push($error, 'horde.error');
393: Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
394: exit;
395: }
396: }
397:
398:
399: if ($style->thumbstyle != 'Thumb') {
400: $GLOBALS['injector']->
401: getInstance('Ansel_Storage')
402: ->ensureHash($gallery->getStyle()->getHash('thumb'));
403: }
404:
405:
406: if ($GLOBALS['conf']['ansel_cache']['usecache']) {
407: $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
408: }
409:
410:
411: $url = Horde_Util::getFormData('url');
412: if (empty($url) && empty($exists)) {
413:
414: $url = Horde::url('img/upload.php')->add('gallery', $galleryId);
415: } elseif (empty($url)) {
416: $url = Horde::url('index.php', true);
417: } else {
418: $url = new Horde_Url($url);
419: }
420: $url->redirect();
421: }
422:
423: 424: 425: 426: 427:
428: protected function _thumbStyles()
429: {
430:
431: $dir = ANSEL_BASE . '/lib/ImageGenerator';
432: $files = scandir($dir);
433: $thumbs = array();
434: foreach ($files as $file) {
435: if (substr($file, -9) == 'Thumb.php') {
436: try {
437: $generator = Ansel_ImageGenerator::factory(
438: substr($file, 0, -4),
439: array('style' => Ansel::getStyleDefinition('ansel_default')));
440: $thumbs[substr($file, 0, -4)] = $generator->title;
441: } catch (Ansel_Exception $e) {}
442: }
443: }
444:
445: return $thumbs;
446: }
447:
448: 449: 450: 451: 452:
453: protected function _galleryViewStyles()
454: {
455:
456: $dir = ANSEL_BASE . '/lib/View/GalleryRenderer';
457: $files = scandir($dir);
458: $views = array();
459: foreach ($files as $file) {
460: if ($file != 'Base.php' && strpos($file, '.') !== 0) {
461: $class = 'Ansel_View_GalleryRenderer_' . substr($file, 0, -4);
462: $view = new $class(null);
463: $views[substr($file, 0, -4)] = $view->title;
464: }
465: }
466:
467: return $views;
468: }
469: }
470:
471: