[ansel] Patches for gallery image reordering

Heath S. Hendrickson heath at outerspaceconsultants.com
Sun Mar 21 23:39:52 PST 2004


Attached are patches and new files to add gallery reording to Ansel.

New Files:
    reorder.php
    templates/view/reorderHeader.inc

Modified File:
    templates/view/gallery.inc

I implemented the gallery display ordering via the gallery.inc file.  It 
would have been major surgery to change the DataTree driver, and this 
works well enough.  It's easy to remove once the DataTree driver has 
been updated and tested.

I also made it so that if an explicit order wasn't set for a gallery, 
that it still functions as it has, meaning that there is no update to 
the database necessary...

Thanks,
h

-------------- next part --------------
<?php
/**
 * $Horde: ansel/view.php,v 1.43 2004/03/20 02:19:51 chuck Exp $
 *
 * Copyright 2001-2004 Chuck Hagenbuch <chuck at 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.
 */

@define('ANSEL_BASE', dirname(__FILE__));
require_once ANSEL_BASE . '/lib/base.php';
require_once HORDE_LIBS . 'Horde/Text.php';
require_once HORDE_LIBS . 'Horde/Form.php';
require_once HORDE_LIBS . 'Horde/Form/Renderer.php';


class ReorderForm extends Horde_Form {
                                                                                
    var $_useFormToken = false;
                                                                                
    function ReorderForm(&$vars, $title)
    {
        global $gallery, $prefs;
                                                                                
        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);
    }
}


/* If we aren't provided with a gallery, redirect to the gallery list. */
$galleryId = Util::getFormData('gallery');
$actionID = Util::getFormData('actionID');

if (!isset($galleryId)) {
    header('Location: ' . Horde::applicationUrl('list.php', true));
    exit;
}

$gallery = &$ansel_shares->getShare($galleryId);
if (is_a($gallery, 'PEAR_Error') || !$gallery->hasPermission(Auth::getAuth(), PERMS_READ)) {
    $notification->push(_("You do not have permission to view this gallery."), 'horde.error');
    header('Location: ' . Horde::applicationUrl('list.php', true));
    exit;
}

require_once HORDE_LIBS . 'Horde/Variables.php';

$viewurl = Util::addParameter('view.php', 'gallery', $galleryId);
$vars = &Variables::getDefaultVariables();

$title = $gallery->get('name');
require ANSEL_TEMPLATES . '/common-header.inc';

Ansel::menu();

/* See if we have any parents to go up to. */
$parents = array();
$p = $gallery;
while (is_a($p = $p->getParent(), 'DataTreeObject_Gallery')) {
    $parents[] = Horde::link(Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $p->getName())), $p->get('name'), 'smallheader') . $p->get('name') . '</a>';
}

if (count($parents)) {
    $parents = array_reverse($parents);
    require ANSEL_TEMPLATES . '/view/parents.inc';
}

require ANSEL_TEMPLATES . '/view/reorderHeader.inc';

$imagelist = $gallery->listImages();
$numimages = $gallery->get('num-images');

switch ($actionID) {
case 'setOrder';
    foreach ($imagelist as $id => $name ) {
        $image = &$ansel_shares->getImage($name);
        $neworder = Util::getFormData($id . '_order');
        $image->data['order'] = $neworder;
        $image->update();
    }
    $notification->push(_("Gallery reordered."), 'horde.success');
    break;

case 'getOrder':
default:
    $vars->set('actionID', 'setOrder');
    $form = &Horde_Form::singleton('ReorderForm', $vars, _("Reorder"));

    Horde::addScriptFile('popup.js', 'horde');

    if ($numimages) {
        $num = 0;
        foreach ($imagelist as $id => $name) {
            $num++;
            $image = &$ansel_shares->getImage($name);
            $thumb_url = Ansel::getImageUrl($id, 'thumb');
            $link = Horde::link('', _("Thumbnail"), 'widget', '', 'popup(\'' . $thumb_url . '\',' . $conf['thumbnail']['width'] . ', ' . $conf['thumbnail']['height'] .'); return false;') . $image->get('filename') . '</a>';
                                                                                
            $description = $image->get('description');
            if (!empty($description)) {
                $link = $link . '<br/>' . $description;
            }
            $o = &$form->addVariable($link, $id . '_order', 'text', true, false, null, array('[:digit]', '3', '3'));
            $im_num = $image->get('order') ? $image->get('order') : $num;
            $o->setDefault($im_num);
        }

        $renderer = &new Horde_Form_Renderer();

        $form->renderActive($renderer, $vars, 'reorder.php', 'post', 'multipart/form-data');
    } else {
        echo '<i>' . _("There are no images in this gallery.") . '</i>';
    }

    //require ANSEL_TEMPLATES . '/view/reorder.inc';
    break;

}

require $registry->getParam('templates', 'horde') . '/common-footer.inc';
-------------- next part --------------
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
  <td class="header">
    <b><?php echo $title; ?></b>
  </td>
  <td align="right" class="header"><span class="smallheader">
  </span></td>
</tr>
                                                                                
<?php if ($gallery->get('desc')): ?>
<tr>
  <td class="control" width="100%" colspan="2">
    <?php echo nl2br(Text::linkUrls(Text::htmlSpaces($gallery->get('desc')), false, 'fixed')) ?>
  </td>
</tr>
<?php endif; ?>
</table>
-------------- next part --------------
Index: templates/view/gallery.inc
===================================================================
RCS file: /usr/local/horde/cvs/ansel/templates/view/gallery.inc,v
retrieving revision 1.36
diff -u -r1.36 gallery.inc
--- templates/view/gallery.inc	11 Mar 2004 07:07:58 -0000	1.36
+++ templates/view/gallery.inc	22 Mar 2004 07:28:15 -0000
@@ -4,6 +4,7 @@
 $captionurl = Util::addParameter('captions.php', 'gallery', $galleryId);
 $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
 $viewurl = Util::addParameter('view.php', 'gallery', $galleryId);
+$reorderurl = Util::addParameter('reorder.php', 'gallery', $galleryId);
 
 $numimages = $gallery->get('num-images');
 
@@ -38,6 +39,7 @@
       | <?php echo Horde::link(Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'addchild')), _("Add Subgallery"), 'smallheader') . _("Subgallery") ?></a>
       | <?php echo Horde::link(Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'modify')), _("Modify Gallery"), 'smallheader') . _("Modify") ?></a>
       | <?php echo Horde::link(Horde::applicationUrl($captionurl), _("Caption Editor"), 'smallheader') . _("Captions") ?></a>
+      | <?php echo Horde::link(Horde::applicationUrl(Util::addParameter($reorderurl, 'actionId' , 'getOrder')), _("Reorder Gallery"), 'smallheader') . _("Reorder") ?></a>
     <?php endif; ?>
     <?php if ($gallery->get('owner') == Auth::getAuth()): ?>
       | <?php echo Horde::link('', _("Set Permissions"), 'smallheader', '', 'open_share_edit_win(\'' . str_replace('&amp;', '&', Util::addParameter(Horde::applicationUrl('perms.php'), 'share', $gallery->getName())) . '\'); return false;') . _("Permissions") ?></a>
@@ -76,6 +78,25 @@
     echo '<table align="center" border="0"><tr>';
 
     foreach ($imagelist as $id => $name) {
+        $image =  &$ansel_shares->getImage($name);
+        if($image->get('order')) {
+            $imagetmp[$image->get('order')] = array( $id => $name);
+        } else {
+            $imagetmp[] = array( $id => $name);
+        }
+    }
+    ksort($imagetmp);
+    reset($imagetmp);
+    $imagelist2 = array();
+    foreach ($imagetmp as $order => $data) {
+        $imagelist2[key($data)] = $data[key($data)];
+    }
+    $imagelist = $imagelist2;
+    unset($imagetmp);
+    unset($imagelist2);
+    unset($image);
+
+    foreach ($imagelist as $id => $name) {
         if ($total++ < $min || $total > $max) {
             continue;
         }
@@ -154,4 +175,4 @@
     </td>
   </tr>
 </table>
-<br />
\ No newline at end of file
+<br />


More information about the ansel mailing list