Move gallery property page to an Ansel_View.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 14 Sep 2010 15:10:07 +0000 (11:10 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 14 Sep 2010 15:10:07 +0000 (11:10 -0400)
Also, start moving style information to be stored as a serialized array
within the gallery object. An empty style would mean to use the user
preference for default style. Gallery property page will implement
showing/editing style properties shortly.

ansel/gallery.php
ansel/lib/Gallery.php
ansel/lib/Storage.php
ansel/lib/View/Gallery.php
ansel/lib/View/GalleryProperties.php [new file with mode: 0644]
ansel/scripts/sql/ansel.sql
ansel/templates/common-header.inc
ansel/templates/gallery/gallery.inc [deleted file]
ansel/templates/gallery/properties.html.php [new file with mode: 0644]

index 6cc9a1c..8c151de 100644 (file)
@@ -6,6 +6,8 @@
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
  * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
  */
 
 require_once dirname(__FILE__) . '/lib/Application.php';
@@ -18,67 +20,16 @@ if (is_null($actionID)) {
     exit;
 }
 
-// Run through the action handlers.
 switch ($actionID) {
 case 'add':
-    // Set up the gallery attributes.
-    $gallery_name = '';
-    $gallery_desc = '';
-    $gallery_tags = '';
-    $gallery_thumbstyle = '';
-    $gallery_slug = '';
-    $gallery_age = 0;
-    $gallery_download = $prefs->getValue('default_download');
-    $gallery_parent = null;
-    $galleryId = null;
-    $gallery_mode = 'Normal';
-    $gallery_passwd = '';
-
-    Horde::addInlineScript(array(
-        '$("gallery_name").focus()'
-    ), 'dom');
-
-    $title = _("Adding A New Gallery");
-    break;
-
 case 'addchild':
-    // Get the parent and make sure that it exists and that we have
-    // permissions to add to it.
-    $parentId = Horde_Util::getFormData('gallery');
-    try {
-        $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($parentId);
-    } catch (Ansel_Exception $e) {
-        $notification->push($e->getMessage(), 'horde.error');
-        Horde::url('view.php?view=List', true)->redirect();
-        exit;
-    }
-
-    if (!$parent->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
-        $notification->push(sprintf(_("Access denied adding a gallery to \"%s\"."),
-                            $parent->get('name')), 'horde.error');
-        Horde::url('view.php?view=List', true)->redirect();
-        exit;
-    }
-
-    // Set up the gallery attributes.
-    $gallery_name = '';
-    $gallery_desc = '';
-    $gallery_tags = '';
-    $gallery_slug = '';
-    $gallery_age = 0;
-    $gallery_thumbstyle = $parent->get('style');
-    $gallery_download = $prefs->getValue('default_download');
-    $gallery_parent = $parentId;
-    $galleryId = null;
-    $gallery_mode = 'Normal';
-    $gallery_passwd = '';
-
-    Horde::addInlineScript(array(
-        '$("gallery_name").focus()'
-    ), 'dom');
-
-    $title = sprintf(_("Adding A Subgallery to %s"), $parent->get('name'));
-    break;
+case 'save':
+case 'modify':
+    $view = new Ansel_View_GalleryProperties(array('actionID' => $actionID,
+                                                   'url' => new Horde_Url(Horde_Util::getFormData('url')),
+                                                   'gallery' => Horde_Util::getFormData('gallery')));
+    $view->run();
+    exit;
 
 case 'downloadzip':
     $galleryId = Horde_Util::getFormData('gallery');
@@ -94,191 +45,6 @@ case 'downloadzip':
     Ansel::downloadImagesAsZip($gallery);
     exit;
 
-case 'modify':
-    $galleryId = Horde_Util::getFormData('gallery');
-
-    try {
-        $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($galleryId);
-         // Set up the gallery attributes.
-        $gallery_name = $gallery->get('name');
-        $gallery_desc = $gallery->get('desc');
-        $gallery_tags = implode(',', $gallery->getTags());
-        $gallery_thumbstyle = $gallery->get('style');
-        $gallery_slug = $gallery->get('slug');
-        $gallery_age = (int)$gallery->get('age');
-        $gallery_download = $gallery->get('download');
-        $title = sprintf(_("Modifying: %s"), $gallery_name);
-        $gallery_parent = $gallery->getParent();
-        if (!is_null($gallery_parent)) {
-            $gallery_parent = $gallery_parent->getId();
-        }
-        $gallery_mode = $gallery->get('view_mode');
-        $gallery_passwd = $gallery->get('passwd');
-    } catch (Ansel_Exception $e) {
-        $title = _("Unknown Gallery");
-    }
-
-    break;
-
-case 'save':
-    // Check general permissions.
-    if (!$registry->isAdmin() &&
-        ($injector->getInstance('Horde_Perms')->exists('ansel') &&
-         !$injector->getInstance('Horde_Perms')->hasPermission('ansel', $registry->getAuth(), Horde_Perms::EDIT))) {
-        $notification->push(_("Access denied editing galleries."), 'horde.error');
-        Horde::url('view.php?view=List', true)->redirect();
-        exit;
-    }
-
-    // Get the form values.
-    $galleryId = Horde_Util::getFormData('gallery');
-    $gallery_name = Horde_Util::getFormData('gallery_name');
-    $gallery_desc = Horde_Util::getFormData('gallery_desc');
-    $gallery_slug = Horde_Util::getFormData('gallery_slug');
-    $gallery_age = (int)Horde_Util::getFormData('gallery_age', 0);
-    $gallery_download = Horde_Util::getFormData('gallery_download');
-    $gallery_mode = Horde_Util::getFormData('view_mode', 'Normal');
-    $gallery_passwd = Horde_Util::getFormData('gallery_passwd');
-    $gallery_tags = Horde_Util::getFormData('gallery_tags');
-    $gallery_thumbstyle = Horde_Util::getFormData('gallery_style');
-    $gallery_parent = Horde_Util::getFormData('gallery_parent');
-    // Double check for an empty string instead of null
-    if (empty($gallery_parent)) {
-        $gallery_parent = null;
-    }
-    if ($galleryId &&
-        ($exists = ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->galleryExists($galleryId)) === true)) {
-
-        // Modifying an existing gallery.
-        $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($galleryId);
-        if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
-            $notification->push(sprintf(_("Access denied saving gallery \"%s\"."), $gallery->get('name')), 'horde.error');
-        } else {
-            // Don't allow the display name to be nulled out.
-            if ($gallery_name) {
-                $gallery->set('name', $gallery_name);
-            }
-
-            $gallery->set('desc', $gallery_desc);
-            $gallery->setTags(explode(',', $gallery_tags));
-            $gallery->set('style', $gallery_thumbstyle);
-            $gallery->set('slug', $gallery_slug);
-            $gallery->set('age', $gallery_age);
-            $gallery->set('download', $gallery_download);
-            $gallery->set('view_mode', $gallery_mode);
-            if ($registry->getAuth() &&
-                $gallery->get('owner') == $registry->getAuth()) {
-                $gallery->set('passwd', $gallery_passwd);
-            }
-
-            // Did the parent change?
-            $old_parent = $gallery->getParent();
-            if (!is_null($old_parent)) {
-                $old_parent_id = $old_parent->getId();
-            } else {
-                $old_parent_id = null;
-            }
-            if ($gallery_parent != $old_parent_id) {
-                if (!is_null($gallery_parent)) {
-                    $new_parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_parent);
-                } else {
-                    $new_parent = null;
-                }
-                try {
-                    $result = $gallery->setParent($new_parent);
-                } catch (Ansel_Exception $e) {
-                    $notification->push($e->getMessage(), 'horde.error');
-                    Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
-                    exit;
-                }
-            }
-            try {
-                $result = $gallery->save();
-                $notification->push(_("The gallery was saved."),'horde.success');
-            } catch (Ansel_Exception $e) {
-                $notification->push($e->getMessage(), 'horde.error');
-            }
-        }
-    } else {
-        // Is this a new subgallery?
-        if ($gallery_parent) {
-            try {
-                $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_parent);
-            } catch (Ansel_Exception $e) {
-                $notification->push($e->getMessage(), 'horde.error');
-                Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
-                exit;
-            }
-            if (!$parent->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
-                $notification->push(sprintf(
-                    _("You do not have permission to add children to %s."),
-                    $parent->get('name')), 'horde.error');
-
-                Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
-                exit;
-            }
-        }
-
-        // Require a display name.
-        if (!$gallery_name) {
-            $notification->push(
-                _("You must provide a display name for your new gallery."),
-                'horde.warning');
-            $actionId = 'add';
-            $title = _("Adding A New Gallery");
-            break;
-        }
-
-        // Create the new gallery.
-        $perm = (!empty($parent)) ? $parent->getPermission() : null;
-        $parent = (!empty($gallery_parent)) ? $gallery_parent : null;
-
-        try {
-            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->createGallery(
-                    array('name' => $gallery_name,
-                          'desc' => $gallery_desc,
-                          'tags' => explode(',', $gallery_tags),
-                          'style' => $gallery_thumbstyle,
-                          'slug' => $gallery_slug,
-                          'age' => $gallery_age,
-                          'download' => $gallery_download,
-                          'view_mode' => $gallery_mode,
-                          'passwd' => $gallery_passwd,
-                          ),
-                    $perm, $parent);
-
-            $galleryId = $gallery->getId();
-            $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
-            Horde::logMessage($msg, 'DEBUG');
-            $notification->push($msg, 'horde.success');
-        } catch (Ansel_Exception $e) {
-            $galleryId = null;
-            $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"),
-                             $gallery_name, $gallery->getMessage());
-            Horde::logMessage($error, 'ERR');
-            $notification->push($error, 'horde.error');
-        }
-
-    }
-
-    // Clear the OtherGalleries widget cache
-    if ($conf['ansel_cache']['usecache']) {
-        $injector->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
-    }
-
-    // Return to the last view.
-    $url = Horde_Util::getFormData('url');
-    if (empty($url) && empty($exists)) {
-        // Redirect to the images upload page for newly creted galleries
-        $url = Horde::url('img/upload.php')->add('gallery', $galleryId);
-    } elseif (empty($url)) {
-        $url = Horde::url('index.php', true);
-    } else {
-        $url = new Horde_Url($url);
-    }
-    $url->redirect();
-    exit;
-
 case 'delete':
 case 'empty':
     // Print the confirmation screen.
@@ -351,16 +117,3 @@ default:
     exit;
 }
 
-Horde::addScriptFile('stripe.js', 'horde');
-require ANSEL_TEMPLATES . '/common-header.inc';
-
-/* Attach the slug check action to the form */
-$injector->getInstance('Horde_Ajax_Imple')->getImple(array('ansel', 'GallerySlugCheck'), array(
-    'bindTo' => 'gallery_slug',
-    'slug' => $gallery_slug
-));
-Horde::addScriptFile('popup.js', 'horde');
-echo Horde::menu();
-$notification->notify(array('listeners' => 'status'));
-require ANSEL_TEMPLATES . '/gallery/gallery.inc';
-require $registry->get('templates', 'horde') . '/common-footer.inc';
index 5e4da3b..5454205 100644 (file)
@@ -721,11 +721,12 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
     public function getStyle()
     {
         if (empty($this->data['attribute_style'])) {
-            $style = $GLOBALS['prefs']->getValue('default_gallerystyle');
+            $style = Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle'));
         } else {
-            $style = $this->data['attribute_style'];
+            $style = unserialize($this->data['attribute_style']);
         }
-        return Ansel::getStyleDefinition($style);
+
+        return $style;
 
     }
 
index 6dd5c35..5787eda 100644 (file)
@@ -94,7 +94,7 @@ class Ansel_Storage
         $attributes['default_type'] = isset($attributes['default_type']) ? $attributes['default_type'] : 'auto';
         $attributes['default'] = isset($attributes['default']) ? (int)$attributes['default'] : 0;
         $attributes['default_prettythumb'] = isset($attributes['default_prettythumb']) ? $attributes['default_prettythumb'] : '';
-        $attributes['style'] = isset($attributes['style']) ? $attributes['style'] : $GLOBALS['prefs']->getValue('default_gallerystyle');
+        $attributes['style'] = isset($attributes['style']) ? $attributes['style'] : '';//$GLOBALS['prefs']->getValue('default_gallerystyle');
         $attributes['date_created'] = time();
         $attributes['last_modified'] = $attributes['date_created'];
         $attributes['images'] = isset($attributes['images']) ? (int)$attributes['images'] : 0;
index c49b0fa..ca45c44 100644 (file)
@@ -102,6 +102,7 @@ class Ansel_View_Gallery extends Ansel_View_Base
         } else {
             $renderer = (!empty($style['gallery_view'])) ? $style['gallery_view'] : 'Gallery';
         }
+
         /* Load the helper */
         $classname = 'Ansel_View_GalleryRenderer_' . basename($renderer);
         $this->_renderer = new $classname($this);
diff --git a/ansel/lib/View/GalleryProperties.php b/ansel/lib/View/GalleryProperties.php
new file mode 100644 (file)
index 0000000..6ed9ba6
--- /dev/null
@@ -0,0 +1,374 @@
+<?php
+/**
+ * Class to encapsulate the UI for adding/viewing/changing galleries.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+
+/**
+ * Description of GalleryProperties
+ *
+ * @author mrubinsk
+ */
+class Ansel_View_GalleryProperties
+{
+    /**
+     * View parameters
+     *
+     * @var array
+     */
+    protected $_params;
+
+    /**
+     * Hash of gallery properties.
+     *
+     * @var array
+     */
+    protected $_properties;
+
+    /**
+     * The view title
+     *
+     * @var string
+     */
+    protected $_title;
+
+    /**
+     * Const'r
+     *
+     * @param array $params  Parameters for the view
+     */
+    public function __construct($params = array())
+    {
+        $this->_params = $params;
+
+        /*Gallery properties */
+        $this->_properties = array(
+            'name' => '',
+            'desc' => '',
+            'tags' => '',
+            'style' => '',
+            'slug' => '',
+            'age' => 0,
+            'download' => $GLOBALS['prefs']->getValue('default_download'),
+            'parent' => null,
+            'id' => null,
+            'mode' => 'Normal',
+            'passwd' => '',
+            'owner' => ''
+        );
+    }
+
+    /**
+     * Runs the view
+     *
+     * @return void
+     */
+    public function run()
+    {
+        switch ($this->_params['actionID']) {
+        case 'add':
+            $this->_runNew();
+            $this->_output();
+            break;
+        case 'addchild':
+            $this->_runNewChild();
+            $this->_output();
+            break;
+        case 'modify':
+            $this->_runEdit();
+            $this->_output();
+            break;
+        case 'save':
+            $this->_runSave();
+            break;
+        }
+    }
+
+    /**
+     * Outputs the view to the browser.
+     *
+     * @return void
+     */
+    private function _output()
+    {
+
+        $view = new Horde_View(array('templatePath' => array(ANSEL_TEMPLATES . '/gallery',
+                                                             ANSEL_TEMPLATES . '/gallery/partial',
+                                                             ANSEL_TEMPLATES . '/gallery/layout')));
+        $view->addHelper('Text');
+        $view->properties = $this->_properties;
+        $view->title = $this->_title;
+        $view->action = $this->_params['actionID'];
+        $view->url = $this->_params['url'];
+
+        Horde::addInlineScript(array('$("gallery_name").focus()'), 'dom');
+        Horde::addScriptFile('stripe.js', 'horde');
+        Horde::addScriptFile('popup.js', 'horde');
+
+        /* Attach the slug check action to the form */
+        $GLOBALS['injector']->getInstance('Horde_Ajax_Imple')->getImple(array('ansel', 'GallerySlugCheck'), array(
+            'bindTo' => 'gallery_slug',
+            'slug' => $this->_properties['slug']
+        ));
+
+        require ANSEL_TEMPLATES . '/common-header.inc';
+        echo Horde::menu();
+        $GLOBALS['notification']->notify(array('listeners' => 'status'));
+        echo $view->render('properties');
+        require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc';
+    }
+
+    /**
+     * Set up for adding new galleries.
+     *
+     * @return void
+     */
+    private function _runNew()
+    {
+        $this->_title = _("Adding a New Gallery");
+        $this->_properties['owner'] = $GLOBALS['registry']->getAuth();
+    }
+
+    /**
+     * Set up for adding a new child gallery.
+     *
+     * @return void
+     */
+    private function _runNewChild()
+    {
+        // Get the parent and make sure that it exists and that we have
+        // permissions to add to it.
+        $parentId = $this->_params['gallery'];
+        try {
+            $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($parentId);
+        } catch (Ansel_Exception $e) {
+            $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
+            Horde::url('view.php?view=List', true)->redirect();
+            exit;
+        }
+
+        if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
+            $GLOBALS['notification']->push(sprintf(_("Access denied adding a gallery to \"%s\"."),
+                                $parent->get('name')), 'horde.error');
+            Horde::url('view.php?view=List', true)->redirect();
+            exit;
+        }
+
+        // Set up the gallery attributes.
+        $this->_properties['style'] = $parent->get('style');
+        $this->_properties['parent'] = $parentId;
+        $this->_title = sprintf(_("Adding A Subgallery to %s"), $parent->get('name'));
+    }
+
+    /**
+     * Handle setting up the form for editing an existing gallery
+     *
+     * @return void
+     * @throws InvalidArgumentException
+     */
+    private function _runEdit()
+    {
+        if (empty($this->_params['gallery'])) {
+            throw new InvalidArgumentException(_("Missing gallery parameter"));
+        }
+
+        try {
+            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_params['gallery']);
+            $parent = $gallery->getParent();
+            $this->_properties = array(
+                'name' => $gallery->get('name'),
+                'desc' => $gallery->get('desc'),
+                'tags' => implode(',', $gallery->getTags()),
+                'slug' => $gallery->get('slug'),
+                'age' => (int)$gallery->get('age'),
+                'download' => $gallery->get('download'),
+                'mode' => $gallery->get('view_mode'),
+                'passwd' => $gallery->get('passwd'),
+                'parent' => !is_null($parent) ? $parent->getId() : $parent,
+                'id' => $gallery->getId(),
+                'owner' => $gallery->get('owner')
+            );
+
+            //$gallery_thumbstyle = $gallery->get('style');
+            $this->_title = sprintf(_("Modifying: %s"), $this->_properties['name']);
+        } catch (Ansel_Exception $e) {
+            $title = _("Unknown Gallery");
+        }
+    }
+
+    /**
+     * Handles saving the gallery information from the form submission, and
+     * redirects back to previous view when complete.
+     *
+     * @return void
+     */
+    private function _runSave()
+    {
+        // Check general permissions.
+        if (!$GLOBALS['registry']->isAdmin() &&
+            ($GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') &&
+             !$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('ansel', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT))) {
+
+            $GLOBALS['notification']->push(_("Access denied editing galleries."), 'horde.error');
+            Horde::url('view.php?view=List', true)->redirect();
+            exit;
+        }
+
+        // Get the form values.
+        $galleryId = Horde_Util::getFormData('gallery');
+        $gallery_name = Horde_Util::getFormData('gallery_name');
+        $gallery_desc = Horde_Util::getFormData('gallery_desc');
+        $gallery_slug = Horde_Util::getFormData('gallery_slug');
+        $gallery_age = (int)Horde_Util::getFormData('gallery_age', 0);
+        $gallery_download = Horde_Util::getFormData('gallery_download');
+        $gallery_mode = Horde_Util::getFormData('view_mode', 'Normal');
+        $gallery_passwd = Horde_Util::getFormData('gallery_passwd');
+        $gallery_tags = Horde_Util::getFormData('gallery_tags');
+        $gallery_thumbstyle = Horde_Util::getFormData('gallery_style');
+        $gallery_parent = Horde_Util::getFormData('gallery_parent');
+
+        // Double check for an empty string instead of null
+        if (empty($gallery_parent)) {
+            $gallery_parent = null;
+        }
+        if ($galleryId &&
+            ($exists = ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->galleryExists($galleryId)) === true)) {
+
+            // Modifying an existing gallery.
+            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($galleryId);
+            if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
+                $GLOBALS['notification']->push(sprintf(_("Access denied saving gallery \"%s\"."), $gallery->get('name')), 'horde.error');
+            } else {
+                // Don't allow the display name to be nulled out.
+                if ($gallery_name) {
+                    $gallery->set('name', $gallery_name);
+                }
+                $gallery->set('desc', $gallery_desc);
+                $gallery->setTags(explode(',', $gallery_tags));
+                //$gallery->set('style', $style);
+                $gallery->set('slug', $gallery_slug);
+                $gallery->set('age', $gallery_age);
+                $gallery->set('download', $gallery_download);
+                $gallery->set('view_mode', $gallery_mode);
+                if ($GLOBALS['registry']->getAuth() &&
+                    $gallery->get('owner') == $GLOBALS['registry']->getAuth()) {
+                    $gallery->set('passwd', $gallery_passwd);
+                }
+
+                // Did the parent change?
+                $old_parent = $gallery->getParent();
+                if (!is_null($old_parent)) {
+                    $old_parent_id = $old_parent->getId();
+                } else {
+                    $old_parent_id = null;
+                }
+                if ($gallery_parent != $old_parent_id) {
+                    if (!is_null($gallery_parent)) {
+                        $new_parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_parent);
+                    } else {
+                        $new_parent = null;
+                    }
+                    try {
+                        $result = $gallery->setParent($new_parent);
+                    } catch (Ansel_Exception $e) {
+                        $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
+                        Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
+                        exit;
+                    }
+                }
+                try {
+                    $result = $gallery->save();
+                    $GLOBALS['notification']->push(_("The gallery was saved."),'horde.success');
+                } catch (Ansel_Exception $e) {
+                    $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
+                }
+            }
+        } else {
+            // Is this a new subgallery?
+            if ($gallery_parent) {
+                try {
+                    $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_parent);
+                } catch (Ansel_Exception $e) {
+                    $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
+                    Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
+                    exit;
+                }
+                if (!$parent->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
+                    $GLOBALS['notification']->push(sprintf(
+                        _("You do not have permission to add children to %s."),
+                        $parent->get('name')), 'horde.error');
+
+                    Horde::url(Ansel::getUrlFor('view', array('view' => 'List'), true))->redirect();
+                    exit;
+                }
+            }
+
+            // Require a display name.
+            if (!$gallery_name) {
+                $GLOBALS['notification']->push(
+                    _("You must provide a display name for your new gallery."),
+                    'horde.warning');
+                $actionId = 'add';
+                $title = _("Adding A New Gallery");
+                break;
+            }
+
+            // Create the new gallery.
+            $perm = (!empty($parent)) ? $parent->getPermission() : null;
+            $parent = (!empty($gallery_parent)) ? $gallery_parent : null;
+
+            try {
+                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->createGallery(
+                        array('name' => $gallery_name,
+                              'desc' => $gallery_desc,
+                              'tags' => explode(',', $gallery_tags),
+                              //'style' => $style,
+                              'slug' => $gallery_slug,
+                              'age' => $gallery_age,
+                              'download' => $gallery_download,
+                              'view_mode' => $gallery_mode,
+                              'passwd' => $gallery_passwd,
+                              ),
+                        $perm, $parent);
+
+                $galleryId = $gallery->getId();
+                $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
+                Horde::logMessage($msg, 'DEBUG');
+                $GLOBALS['notification']->push($msg, 'horde.success');
+            } catch (Ansel_Exception $e) {
+                $galleryId = null;
+                $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"),
+                                 $gallery_name, $gallery->getMessage());
+                Horde::logMessage($error, 'ERR');
+                $GLOBALS['notification']->push($error, 'horde.error');
+            }
+
+        }
+
+        // Clear the OtherGalleries widget cache
+        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
+        }
+
+        // Return to the last view.
+        $url = Horde_Util::getFormData('url');
+        if (empty($url) && empty($exists)) {
+            // Redirect to the images upload page for newly creted galleries
+            $url = Horde::url('img/upload.php')->add('gallery', $galleryId);
+        } elseif (empty($url)) {
+            $url = Horde::url('index.php', true);
+        } else {
+            $url = new Horde_Url($url);
+        }
+        $url->redirect();
+    }
+}
+
index 2d6f292..2c95432 100644 (file)
@@ -68,7 +68,7 @@ CREATE TABLE ansel_shares (
     attribute_default INT,
     attribute_default_type VARCHAR(6),
     attribute_default_prettythumb TEXT,
-    attribute_style VARCHAR(255),
+    attribute_style TEXT,
     attribute_category VARCHAR(255) DEFAULT '' NOT NULL,
     attribute_last_modified INT,
     attribute_date_created INT,
index 7140be4..6615acf 100644 (file)
@@ -12,7 +12,7 @@ if (isset($language)) {
 <head>
 <?php
 
-$page_title = $registry->get('name');
+$page_title = $GLOBALS['registry']->get('name');
 if (!empty($title)) {
     $page_title .= ' :: ' . $title;
 }
diff --git a/ansel/templates/gallery/gallery.inc b/ansel/templates/gallery/gallery.inc
deleted file mode 100644 (file)
index bf5ba0d..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-<form method="post" name="gallery" action="<?php echo Horde::selfUrl() ?>" >
-<?php Horde_Util::pformInput() ?>
-<input type="hidden" name="actionID" value="save" />
-<?php if ($actionID == 'addchild'): ?>
-<input type="hidden" name="parent" value="<?php echo (int)$parentId ?>" />
-<?php elseif ($actionID != 'add'): ?>
-<input type="hidden" name="gallery" value="<?php echo isset($galleryId) ? (int)$galleryId : '' ?>" />
-<?php endif; ?>
-<input type="hidden" name="url" value="<?php echo htmlspecialchars(Horde_Util::getFormData('url')) ?>" />
-
-<h1 class="header">
- <?php echo htmlspecialchars($title, ENT_COMPAT, $GLOBALS['registry']->getCharset()) ?>
-</h1>
-
-<table cellspacing="0" width="100%" class="striped headerbox">
-<tr>
- <td align="right" valign="top"><strong><?php echo _("Gallery Parent") ?></strong>&nbsp;</td>
- <td>
-  <select name="gallery_parent" id="gallery_parent">
-   <option value=""><?php echo _("Top Level Gallery") ?></option>
-   <?php echo Ansel::selectGalleries(array('selected' => $gallery_parent,
-                                           'perm' => Horde_Perms::EDIT,
-                                           'ignore' => $galleryId))?>
-  </select>
- </td>
-</tr>
-<?php
-if ($prefs->isLocked('default_gallerystyle')) {
-    echo '<input type="hidden" name="gallery_style" value="' . $prefs->getValue('default_gallerystyle') . '" />';
-} else {
-?>
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Style for this gallery") ?></strong>&nbsp;</td>
-  <td>
-   <?php echo Ansel::getStyleSelect('gallery_style', $gallery_thumbstyle) ?>
-  </td>
-</tr>
-<?php } ?>
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Display Mode") ?></strong></td>
-  <td>
-    <select name="view_mode">
-     <option value="Normal" <?php echo ((empty($gallery_mode) || $gallery_mode == 'Normal') ? 'selected="selected"' : '') ?>><?php echo _("Normal") ?></option>
-     <option value="Date" <?php echo ($gallery_mode == 'Date' ? 'selected="selected"' : '') ?>><?php echo _("Group By Date") ?></option>
-    </select>
-  </td>
-</tr>
-<tr>
-  <td align="right" valign="top"><?php echo Horde::img('required.png') ?><strong><?php echo _("Gallery Display Name") ?></strong>&nbsp;</td>
-  <td>
-    <input name="gallery_name" id="gallery_name" type="text" value="<?php echo htmlspecialchars($gallery_name) ?>" size="50" maxlength="100" />
-  </td>
-</tr>
-
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Gallery Description") ?></strong>&nbsp;</td>
-  <td>
-    <textarea name="gallery_desc" cols="50" rows="5"><?php echo htmlspecialchars($gallery_desc) ?></textarea>
-  </td>
-</tr>
-<tr>
-  <td align="right" valign="top"><strong id="slug_flag"><?php echo _("Gallery Slug") ?></strong>&nbsp;</td>
-  <td>
-   <input name="gallery_slug" id="gallery_slug" type="text" value="<?php echo htmlspecialchars($gallery_slug) ?>" size="50" /><br />
-   <?php if ($GLOBALS['conf']['urls']['pretty'] == 'rewrite') echo _("Slugs allows direct access to this gallery by visiting:") . ': ' . Horde::url('gallery/slugname', true) ?><br />
-   <?php echo _("Slug names may contain only letters, numbers, @, or _ (underscore).") ?>
-  </td>
- </tr>
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Gallery Tags") ?></strong>&nbsp;</td>
-  <td><input name="gallery_tags" type="text" value="<?php echo htmlspecialchars($gallery_tags) ?>" size="50" /><br />
-   <?php echo _("Separate tags with commas."); ?>
- </td>
-</tr>
-
-<?php if (!empty($conf['ages']['limits'])) { ?>
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Gallery Ages") ?></strong>&nbsp;</td>
-  <td><select name="gallery_age">
-   <option value="0" <?php echo (empty($gallery_age) ? 'selected="selected"' : '') ?>><?php echo _("Allow all ages") ?></option>
-<?php
-    foreach ($conf['ages']['limits'] as $age) {
-        echo '<option value="' . $age . '"'
-                . ($gallery_age == $age ? ' selected="selected"' : '' )
-                . '>' . sprintf(_("User must be over %d"), $age) . '</option>';
-    }
-?>
-</select>
- </td>
-</tr>
-<?php } ?>
-
-<?php
-if ($prefs->isLocked('default_download')) {
-    echo '<input type="hidden" name="default_download" value="' . $prefs->getValue('default_download') . '" />';
-} else {
-?>
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Who should be allowed to download original photos?") ?></strong>&nbsp;</td>
-  <td>
-    <select name="gallery_download">
-        <option value="all" <?php if ($gallery_download == 'all')  echo 'selected="selected"'; ?>><?php echo _("Anyone") ?></option>
-        <option value="authenticated" <?php if ($gallery_download == 'authenticated') echo 'selected="selected"'; ?>><?php echo _("Authenticated users") ?></option>
-        <option value="edit" <?php if ($gallery_download == 'edit') echo 'selected="selected"'; ?>><?php echo _("Users with edit permissions") ?></option>
-    </select>
-  </td>
-</tr>
-<?php } ?>
-<?php if ($GLOBALS['registry']->getAuth() && !empty($gallery) && $GLOBALS['registry']->getAuth() == $gallery->get('owner')): ?>
-<tr>
-  <td align="right" valign="top"><strong><?php echo _("Gallery Password") ?></strong>&nbsp;</td>
-  <td><input name="gallery_passwd" type="password" value="<?php echo htmlspecialchars($gallery_passwd) ?>" size="50" /></td>
-</tr>
-<?php endif; ?>
-<tr>
-  <td></td>
-  <td>
-   <input type="submit" id="gallery_submit" name="gallery_submit" class="button" value="<?php echo _("Save Gallery") ?>" />&nbsp;
-   <input type="reset" class="button" value="<?php echo _("Undo Changes") ?>"  />&nbsp;
-  </td>
-</tr>
-</table>
-</form>
diff --git a/ansel/templates/gallery/properties.html.php b/ansel/templates/gallery/properties.html.php
new file mode 100644 (file)
index 0000000..44f37c9
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+/**
+ * Main template for rendering gallery property page
+ * Expects the following properties to be set:
+ * <pre>
+ *   (string)action    The current actionID
+ *   (int)parent       The parent id
+ *   (int)id           The current gallery id, if not new.
+ *   (Horde_Url)url    The return url
+ *   (string)title     The form title
+ *   (string)mode      The gallery mode
+ *   (array)properties The gallery properties
+ *
+ *
+ * </pre>
+ */
+?>
+<form method="post" name="gallery" action="<?php echo Horde::selfUrl() ?>" >
+<?php Horde_Util::pformInput() ?>
+<input type="hidden" name="actionID" value="save" />
+<?php if ($this->action == 'addchild'): ?>
+  <input type="hidden" name="parent" value="<?php echo $this->properties['parent'] ?>" />
+<?php elseif ($this->action != 'add'): ?>
+  <input type="hidden" name="gallery" value="<?php echo isset($this->properties['id']) ? $this->properties['id'] : '' ?>" />
+<?php endif; ?>
+<input type="hidden" name="url" value="<?php echo $this->url->setRaw(false)->toString() ?>" />
+<h1 class="header">
+ <?php echo $this->h($this->title); ?>
+</h1>
+<table cellspacing="0" width="100%" class="striped headerbox">
+<tr>
+ <td align="right" valign="top"><strong><?php echo _("Gallery Parent") ?></strong>&nbsp;</td>
+ <td>
+  <select name="gallery_parent" id="gallery_parent">
+   <option value=""><?php echo _("Top Level Gallery") ?></option>
+   <?php echo Ansel::selectGalleries(array('selected' => $this->properties['parent'],
+                                           'perm' => Horde_Perms::EDIT,
+                                           'ignore' => $this->properties['id']))?>
+  </select>
+ </td>
+</tr>
+<?php if ($GLOBALS['prefs']->isLocked('default_gallerystyle')): ?>
+  <!--<input type="hidden" name="gallery_style" value="<?php //echo $GLOBALS['prefs']->getValue('default_gallerystyle') ?>" />';-->
+<?php else: ?>
+<tr>
+  <td align="right" valign="top"><strong><?php echo _("Style for this gallery") ?></strong>&nbsp;</td>
+  <td>
+   <?php //echo Ansel::getStyleSelect('gallery_style', $this->style) ?>
+  </td>
+</tr>
+<?php endif; ?>
+<tr>
+  <td align="right" valign="top"><strong><?php echo _("Display Mode") ?></strong></td>
+  <td>
+    <select name="view_mode">
+     <option value="Normal" <?php echo ((empty($this->properties['mode']) || $this->properties['mode'] == 'Normal') ? 'selected="selected"' : '') ?>><?php echo _("Normal") ?></option>
+     <option value="Date" <?php echo ($this->properties['mode'] == 'Date' ? 'selected="selected"' : '') ?>><?php echo _("Group By Date") ?></option>
+    </select>
+  </td>
+</tr>
+<tr>
+  <td align="right" valign="top"><?php echo Horde::img('required.png') ?><strong><?php echo _("Gallery Display Name") ?></strong>&nbsp;</td>
+  <td>
+    <input name="gallery_name" id="gallery_name" type="text" value="<?php echo $this->h($this->properties['name']) ?>" size="50" maxlength="100" />
+  </td>
+</tr>
+<tr>
+  <td align="right" valign="top"><strong><?php echo _("Gallery Description") ?></strong>&nbsp;</td>
+  <td>
+    <textarea name="gallery_desc" cols="50" rows="5"><?php echo $this->h($this->properties['desc']) ?></textarea>
+  </td>
+</tr>
+<tr>
+  <td align="right" valign="top"><strong id="slug_flag"><?php echo _("Gallery Slug") ?></strong>&nbsp;</td>
+  <td>
+   <input name="gallery_slug" id="gallery_slug" type="text" value="<?php echo $this->h($this->properties['slug']) ?>" size="50" /><br />
+   <?php if ($GLOBALS['conf']['urls']['pretty'] == 'rewrite') echo _("Slugs allows direct access to this gallery by visiting:") . ': ' . Horde::url('gallery/slugname', true) ?><br />
+   <?php echo _("Slug names may contain only letters, numbers, @, or _ (underscore).") ?>
+  </td>
+ </tr>
+<tr>
+  <td align="right" valign="top"><strong><?php echo _("Gallery Tags") ?></strong>&nbsp;</td>
+  <td><input name="gallery_tags" type="text" value="<?php echo $this->h($this->properties['tags']) ?>" size="50" /><br />
+   <?php echo _("Separate tags with commas."); ?>
+ </td>
+</tr>
+<?php if (!empty($conf['ages']['limits'])): ?>
+<tr>
+  <td align="right" valign="top"><strong><?php echo _("Gallery Ages") ?></strong>&nbsp;</td>
+  <td><select name="gallery_age">
+   <option value="0" <?php echo (empty($this->properties['age']) ? 'selected="selected"' : '') ?>><?php echo _("Allow all ages") ?></option>
+<?php
+    foreach ($GLOBALS['conf']['ages']['limits'] as $age) {
+        echo '<option value="' . $age . '"'
+                . ($this->properties['age'] == $age ? ' selected="selected"' : '' )
+                . '>' . sprintf(_("User must be over %d"), $age) . '</option>';
+    }
+?>
+</select>
+ </td>
+</tr>
+<?php endif; ?>
+<?php if ($GLOBALS['prefs']->isLocked('default_download')): ?>
+  <input type="hidden" name="default_download" value="<?php echo $GLOABLS['prefs']->getValue('default_download') ?>" />';
+<?php else: ?>
+  <tr>
+    <td align="right" valign="top"><strong><?php echo _("Who should be allowed to download original photos?") ?></strong>&nbsp;</td>
+    <td>
+      <select name="gallery_download">
+        <option value="all" <?php if ($this->properties['download'] == 'all')  echo 'selected="selected"'; ?>><?php echo _("Anyone") ?></option>
+        <option value="authenticated" <?php if ($this->properties['download'] == 'authenticated') echo 'selected="selected"'; ?>><?php echo _("Authenticated users") ?></option>
+        <option value="edit" <?php if ($this->properties['download'] == 'edit') echo 'selected="selected"'; ?>><?php echo _("Users with edit permissions") ?></option>
+      </select>
+    </td>
+  </tr>
+<?php endif; ?>
+<?php if ($GLOBALS['registry']->getAuth() && $GLOBALS['registry']->getAuth() == $this->properties['owner']): ?>
+  <tr>
+    <td align="right" valign="top"><strong><?php echo _("Gallery Password") ?></strong>&nbsp;</td>
+    <td><input name="gallery_passwd" type="password" value="<?php echo $this->h($this->properties['passwd']) ?>" size="50" /></td>
+  </tr>
+<?php endif; ?>
+<tr>
+  <td></td>
+  <td>
+   <input type="submit" id="gallery_submit" name="gallery_submit" class="button" value="<?php echo _("Save Gallery") ?>" />&nbsp;
+   <input type="reset" class="button" value="<?php echo _("Undo Changes") ?>"  />&nbsp;
+  </td>
+</tr>
+</table>
+</form>