[ansel] TODO item completed...!

Heath S. Hendrickson heath at outerspaceconsultants.com
Wed Feb 11 21:52:01 PST 2004


I finally got a few minutes to code up some changes to Ansel and managed 
to complete one of the TODO's and modified something else that was 
bugging me...

The following patches provide the following functionality:

1) Added a "Custom Watermark" option to the Edit Image page that uses a 
pop-up to let you define a custom watermark.  The default value is the 
defined one in the users preferences (if it exists).  What I'm hoping is 
that this can easily be extended to make changes to the way an image is 
watermarked (font, size, color, etc.)... but I'll leave that up to 
someone else for now.
2) modified the behaviour of the Set Caption option on the Edit Image 
page.  It now uses a pop-up that automatically refreshes the main page 
when the form is submitted...  I wanted this so that the user could see 
the picture while typing the caption.

I think I followed the coding standards and all that jazz, so it should 
be a clean commit.

I introduced two new files:
templates/image/watermark.inc
templates/image/caption.inc

and changed:
File: image.php         Status: Locally Modified
File: edit_image.inc    Status: Locally Modified
File: preview_image.inc Status: Locally Modified
File: navbar-image.inc  Status: Locally Modified


heath
-------------- next part --------------
Index: templates/image/preview_image.inc
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/image/preview_image.inc,v
retrieving revision 1.9
diff -u -r1.9 preview_image.inc
--- templates/image/preview_image.inc	20 Jan 2004 18:13:47 -0000	1.9
+++ templates/image/preview_image.inc	12 Feb 2004 05:37:01 -0000
@@ -8,6 +8,9 @@
 $base_url = Util::addParameter('image.php', 'gallery', $gallery_id);
 $base_url = Util::addParameter($base_url, 'image', $image_id);
 $base_url = Util::addParameter($base_url, 'page', $page);
+if (isset($watermark)) {
+    $base_url = Util::addParameter($base_url, 'watermark', $watermark);
+}
 
 $edit_url = Util::addParameter($base_url, 'actionID', 'editimage');
 $save_url = Util::addParameter($base_url, 'actionID', $action);
-------------- next part --------------
Index: templates/image/edit_image.inc
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/image/edit_image.inc,v
retrieving revision 1.18
diff -u -r1.18 edit_image.inc
--- templates/image/edit_image.inc	9 Feb 2004 21:27:07 -0000	1.18
+++ templates/image/edit_image.inc	12 Feb 2004 05:03:13 -0000
@@ -35,6 +35,8 @@
         echo Menu::createItem(Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'previewgrayscale')), _("Grayscale"), 'image/grayscale.gif', $registry->getParam('graphics', 'horde'), null, null, 'control', 'widget');
     }
     if (Ansel::isAvailable('watermark')) {
+        Horde::addScriptFile('open_share_edit_win.js', 'horde');
+        echo Menu::createItem('javascript:open_share_edit_win(\'' . Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'setwatermark'), 'share', $gallery->getName()) . '\');', _("Custom Watermark"), 'text.png', null, null, null, 'control', 'widget');
         echo Menu::createItem(Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'previewwatermark')), _("Watermark"), 'text.png', null, null, null, 'control', 'widget');
     }
 }
-------------- next part --------------
Index: image.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/image.php,v
retrieving revision 1.59
diff -u -r1.59 image.php
--- image.php	25 Jan 2004 04:32:32 -0000	1.59
+++ image.php	12 Feb 2004 05:32:58 -0000
@@ -40,10 +40,32 @@
 
 }
 
+class WatermarkForm extends Horde_Form {
+
+    var $_useFormToken = false;
+
+    function WatermarkForm(&$vars, $title)
+    {
+        global $gallery;
+
+        parent::Horde_Form($vars, $title);
+
+        $this->setButtons(_("Save"));
+        $this->addHidden('', 'actionID', 'text', false);
+        $this->addHidden('', 'gallery', 'text', false);
+        $this->addHidden('', 'image', 'text', false);
+        $this->addHidden('', 'page', 'text', false);
+
+        $this->addVariable(_("Custom Watermark"), 'watermark', 'text', false, false, null);
+    }
+
+}
+
 /* Redirect to the image list if no action has been requested. */
 $actionID = Util::getFormData('actionID');
 $gallery_id = Util::getFormData('gallery');
 $image_id = Util::getFormData('image');
+$watermark = Util::getFormData('watermark');
 
 $page = Util::getFormData('page');
 if (!isset($page)) {
@@ -75,13 +97,13 @@
     break;
 
 case 'modify':
-    $title = _("Edit Image");
+    $title = _("Edit Image Data");
 
     $image = &$ansel_shares->getImageById($image_id);
     if ($image) {
         /* Set up the form object. */
         $vars = &Horde_Form::getDefaultVars();
-        $vars->setVar('actionID', 'save');
+        $vars->setVar('actionID', 'saveclose');
         $form = &Horde_Form::singleton('ImageForm', $vars, sprintf(_("Edit %s"), $image->get('filename')));
         $renderer = &new Horde_Form_Renderer();
 
@@ -92,8 +114,13 @@
         $vars->setVar('image_desc', $image->get('description'));
         $vars->setVar('file', $image->get('filename'));
     }
+    require ANSEL_TEMPLATES . '/common-header.inc';
+    require ANSEL_TEMPLATES . '/image/caption.inc';
+    require $registry->getParam('templates', 'horde') . '/common-footer.inc';
+    exit;
     break;
 
+case 'saveclose':
 case 'save':
     $title = _("Save Image");
 
@@ -211,12 +238,16 @@
             }
         }
 
-        /* Return to the gallery view. */
-        $imageurl = Util::addParameter('view.php', 'gallery', $gallery_id);
-        $imageurl = Util::addParameter($imageurl, 'image', $image_id);
-        $imageurl = Util::addParameter($imageurl, 'actionID', 'view');
-        $imageurl = Util::addParameter($imageurl, 'page', $page);
-        header('Location: ' . Horde::applicationUrl($imageurl, true));
+        if ($actionID == 'save') {
+            /* Return to the gallery view. */
+            $imageurl = Util::addParameter('view.php', 'gallery', $gallery_id);
+            $imageurl = Util::addParameter($imageurl, 'image', $image_id);
+            $imageurl = Util::addParameter($imageurl, 'actionID', 'view');
+            $imageurl = Util::addParameter($imageurl, 'page', $page);
+            header('Location: ' . Horde::applicationUrl($imageurl, true));
+        } else {
+            Util::closeWindowJS(' window.opener.location.href = window.opener.location.href;');
+        }
         exit;
     }
     break;
@@ -229,6 +260,7 @@
     require ANSEL_TEMPLATES . '/image/exif.inc';
     require $registry->getParam('templates', 'horde') . '/common-footer.inc';
     exit;
+    break;
 
 case 'editimage':
     if (!$gallery->hasPermission(Auth::getAuth(), PERMS_EDIT)) {
@@ -289,7 +321,10 @@
             break;
 
         case 'watermark':
-            $image->watermark($prefs->getValue('watermark'));
+            if (!isset($watermark)) {
+                $watermark = $prefs->getValue('watermark');
+            }
+            $image->watermark($watermark);
             break;
         }
 
@@ -304,6 +339,38 @@
     exit;
     break;
 
+case 'setwatermark':
+    $title = _("Set Custom Watermark");
+    $image = &$ansel_shares->getImageById($image_id);
+    if ($image) {
+        /* Set up the form object. */
+        $vars = &Horde_Form::getDefaultVars();
+        $vars->setVar('actionID', 'previewcustomwatermark');
+        $form = &Horde_Form::singleton('WatermarkForm', $vars, _("Custom Watermark"));
+        $renderer = &new Horde_Form_Renderer();
+
+        $gallery = &$ansel_shares->getGallery($image->get('gallery'));
+
+        /* Set up the gallery attributes. */
+        $vars->setVar('watermark', $prefs->getValue('watermark'));
+    }
+    require ANSEL_TEMPLATES . '/common-header.inc';
+    require ANSEL_TEMPLATES . '/image/watermark.inc';
+    require $registry->getParam('templates', 'horde') . '/common-footer.inc';
+    exit;
+    break;
+
+case 'previewcustomwatermark':
+    $imageurl = Util::addParameter('image.php', 'gallery', $gallery_id);
+    $imageurl = Util::addParameter($imageurl, 'image', $image_id);
+    $imageurl = Util::addParameter($imageurl, 'page', $page);
+    $imageurl = Util::addParameter($imageurl, 'watermark', $watermark);
+    $url =  Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'previewwatermark'));
+    $url = str_replace( '&', '&', $url);
+    Util::closeWindowJS('window.opener.location.href = "' . $url . '";');
+    exit;
+    break;
+
 case 'previewgrayscale':
 case 'previewwatermark':
 case 'previewflip':
@@ -366,7 +433,10 @@
 
 case 'imagewatermark':
     $image = &$ansel_shares->getImageById($image_id);
-    $image->watermark($prefs->getValue('watermark'));
+    if (!isset($watermark)) {
+        $watermark = $prefs->getValue('watermark');
+    }
+    $image->watermark($watermark);
     $image->display();
     exit;
     break;
-------------- next part --------------
Index: templates/view/navbar-image.inc
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/view/navbar-image.inc,v
retrieving revision 1.19
diff -u -r1.19 navbar-image.inc
--- templates/view/navbar-image.inc	27 Jan 2004 01:48:03 -0000	1.19
+++ templates/view/navbar-image.inc	12 Feb 2004 02:38:40 -0000
@@ -18,7 +18,8 @@
 <tr class="control">
   <td align="left">
     <?php if ($gallery->hasPermission(Auth::getAuth(), PERMS_EDIT)): ?>
-        <?php echo Horde::link(Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'modify')), _("Set Caption"), 'widget') . _("Set Caption") ?></a>
+        <?php echo Horde::link('', _("Set Caption"), 'widget', '', 'open_share_edit_win(\'' . str_replace('&amp;', '&', Util::addParameter(Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'modify')), 'share', $gallery->getName())) . '\'); return false;') . _("Set Caption") ?></a>
+        <?php //echo Horde::link(Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'modify')), _("Set Caption"), 'widget') . _("Set Caption") ?><!--</a>-->
       | <?php echo Horde::link(Horde::applicationUrl(Util::addParameter($imageurl, 'actionID', 'editimage')), _("Edit"), 'widget') . _("Edit") ?></a>
       <?php if (Ansel::isAvailable('crop')): ?>
       | <?php echo Horde::link(Horde::applicationUrl($cropurl), _("Crop"), 'widget') . _("Crop") ?></a>


More information about the ansel mailing list