[ansel] Tree view mods

Heath S. Hendrickson heath at outerspaceconsultants.com
Wed Feb 18 22:14:08 PST 2004


Attached is a single unified diff (via 'cvs diff -u' on the ansel root
directory) and two new files(that both go into templates/list/).

   ansel_tree_view.patches
   tree_gallery.inc
   tree_owner.inc

It's based on the tile listing with some heavy modifications to provide 
the full <UL> styled listing of all galleries either by owner or as a 
single list.  The two views are slightly different for now, but I'm 
thinking of modifying the owner view to not provide multiple preview 
slots, and just look like the gallery view with owner headings.  That's 
for another day, though.

I've tested it out on my system and it works fine, but I only have one
user with galleries (albeit sub-galleries as well).

Anyway, suggestions for modifications or changes are welcome, especially
if someone has a cleaner way of doing things than what I've done.  I
originally wanted to use the onMouseOver to change the preview and links
and then use onClick to go to the gallery, but Horde::link is hardcoded
to only write the window.status() in the onMouseOver event and I didn't
feel like messing with core Horde functionality.

Note that the CSS isn't the best (red text with white background for the
hover event), but that's easily modified in the html.php file.  I just
wanted something so I could make sure it was working.

heath

-------------- next part --------------
<script language="Javascript" type="text/javascript">
<!--

<?php echo $owner ?>_previews = new Array();
<?php echo $owner ?>_gallery_size = new Array();
<?php echo $owner ?>_gallery_id = new Array();
<?php echo $owner ?>_gallery_desc = new Array();
<?php echo $owner ?>_view_url = new Array();
<?php echo $owner ?>_slide_url = new Array();
<?php echo $owner ?>_zip_url = new Array();

<?php

$i = 0;
function createJS(&$parent, $cid)
{
    global $ansel_shares, $i, $owner;
    $gallery = &$ansel_shares->getGalleryById($cid);
    //$galleryId = $ansel_shares->_datatree->getName($cid);
    $galleryId = $gallery->getName();

    echo $owner . '_previews[' . $i . '] = \'' . addslashes(str_replace('&amp;', '&', Ansel::getImageUrl($gallery->getDefaultImage(), 'thumb'))) . "';\n";
    echo $owner . '_gallery_size[' . $i . '] = ' . $gallery->get('num-images') . ";\n";
    echo $owner . '_gallery_id[' . $i . '] = \'' . addslashes($galleryId) . "';\n";
    echo $owner . '_gallery_desc[' . $i . '] = \'' . addslashes($gallery->get('desc')) . "';\n";
    echo $owner . '_view_url[' . $i . '] = \'' . Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $galleryId)) . "';\n";
    echo $owner . '_slide_url[' . $i . '] = \'' . Horde::applicationUrl(Util::addParameter('slideshow.php', 'gallery', $galleryId)) . "';\n";
    $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
    echo $owner . '_zip_url[' . $i . '] = \'' . Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'downloadzip')) . "';\n";
    $i++;

    if (is_array($parent)) {
        array_walk($parent, 'createJS');
        return;
    }
}

foreach ($tree as $parentId => $children) {
    array_walk($children, 'createJS');
}
?>

function <?php echo $owner ?>_updateTile($id)
{
    size = <?php echo $owner ?>_gallery_size[$id];
    desc = <?php echo $owner ?>_gallery_desc[$id];
    preview = <?php echo $owner ?>_previews[$id];
    link = document.getElementById('<?php echo $owner; ?>_link');
    link.href = <?php echo $owner ?>_view_url[$id];

    html = desc + ' (';
    if (size == 1) {
        html += '<?php echo _("1 image") ?>';
    } else {
        html += size + ' <?php echo _("images") ?>';
    }
    html += ')';

    if (size > 0) {
        html += '<br /><br /><?php echo Horde::link(sprintf("javascript: %s_downloadzip(' + \$id + ')",$owner), false, -1) . Horde::img('mime/compressed.gif', _("Download all images in a .zip file"), '', $registry->getParam('graphics', 'horde')) . ' ' . _("Download") ?></a>';
        html += '<br /><?php echo Horde::link(sprintf("javascript:%s_slideshow(' + \$id + ')", $owner), false, -1) . Horde::img('slideshow.gif', _("Slide show")) . ' ' . _("Slide show") ?></a>';
    }

    spanObj = document.getElementById('<?php echo $owner; ?>_gallery_information');
    spanObj.innerHTML = html;

    document['<?php echo $owner ?>_preview'].src = preview;
}

function <?php echo $owner ?>_downloadzip($id)
{
    document.location = <?php echo $owner ?>_zip_url[$id];
}

function <?php echo $owner ?>_slideshow($id)
{
    document.location = <?php echo $owner ?>_slide_url[$id];
}

//-->
</script>

<table border="0" cellpadding="0" cellspacing="0" class="greybox" width="600">
 <tr>
  <td class="header" colspan="2">
   <?php echo $title ?>
  </td>
 </tr>
 <tr>
  <td class="preview"><?php echo Horde::link('" id="' . $owner . '_link"') . Horde::img('', _("Gallery Preview"), 'vspace="5" class="solidbox" name="' . $owner . '_preview"') ?></a></td>
  <td valign="top">
   <table border="0" cellpadding="3" cellspacing="0" width="100%">
    <tr>
     <td>

      <div id="tree">
       <form name="<?php echo $owner ?>_galleries" action="view.php" method="get">

<?php

$j = 0;
function list_print(&$parent, $key, $subcount)
{
    global $ansel_shares, $j;
    $gallery = &$ansel_shares->getGalleryById($key);
    //$galleryId = $ansel_shares->_datatree->getName($key);
    $galleryId = $gallery->getName();
    $viewurl = Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $galleryId));
    $slideurl = Horde::applicationUrl(Util::addParameter('slideshow.php', 'gallery', $galleryId));
    $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
    $zipurl = Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'downloadzip'));
    //$link = Horde::link($viewurl, sprintf(_("View %s"), $gallery->get('name')), '', '' , sprintf("%s_updateTile(); return true;",$gallery->get('owner')));
    $link = Horde::link('#', sprintf(_("View %s"), $gallery->get('name')), '', '' , sprintf("%s_updateTile(%s); return true;",$gallery->get('owner'),$j));
    $j++;

    if (is_array($parent) && $ansel_shares->_datatree->getNumberOfChildren($gallery) > 0) {
        echo "  <LI>" . $link . htmlspecialchars($gallery->get('name')) . "</a>";
        $subcount++;
        echo "    <UL>\n";
        array_walk($parent, 'list_print', $subcount);
        for (;$subcount > 0; $subcount--) {
            echo "    </UL>\n";
        }
        echo "  </LI>\n";
        return;
    } else {
        echo "  <LI>" . $link . htmlspecialchars($gallery->get('name')) . "</a></LI>\n";
    }
}
echo "<UL>\n";
foreach ($tree as $parentId => $children) {
    array_walk($children, 'list_print', 0);
}
echo "</UL>\n";

echo "</div>\n";

?>

        <br /><br />
        <span id="<?php echo $owner ?>_gallery_information"></span>
      </form>
      <script language="Javascript" type="text/javascript">
        <?php echo $owner ?>_updateTile(0);
      </script>
     </td>
    </tr>
   </table>
  </td>
 </tr>
</table>
<br />
-------------- next part --------------
Index: list.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/list.php,v
retrieving revision 1.31
diff -u -r1.31 list.php
--- list.php	7 Feb 2004 17:43:32 -0000	1.31
+++ list.php	19 Feb 2004 04:28:55 -0000
@@ -33,11 +33,20 @@
             $identity = &Identity::singleton('none', $owner);
             $name = $identity->getValue('fullname') == '' ? $owner : $identity->getValue('fullname');
             $title = _(sprintf("%s's Galleries", $name));
-            $title .= ' (' . count($galleries) . ')';
-
-            if ($prefs->getValue('listtype') != 'list') {
+            if ($prefs->getValue('listtype') == 'tree') {
+                $galleryCount = 0;
+                foreach ($galleries as $galleryId => $gallery) {
+                    $tree[$galleryId] = Ansel::getFullTree($galleryId);
+                    $galleryCount += $ansel_shares->_datatree->getNumberOfChildren($gallery);
+                }
+                $galleryCount += count($galleries);
+                $title .= ' (' . $galleryCount . ')';
+                require ANSEL_TEMPLATES . '/list/tree_owner.inc';
+            } elseif ($prefs->getValue('listtype') == 'tile') {
+                $title .= ' (' . count($galleries) . ')';
                 require ANSEL_TEMPLATES . '/list/tile_owner.inc';
             } else {
+                $title .= ' (' . count($galleries) . ')';
                 require ANSEL_TEMPLATES . '/list/header.inc';
                 require ANSEL_TEMPLATES . '/list/gallery_headers.inc';
                 foreach ($galleries as $galleryId => $gallery) {
@@ -64,7 +73,12 @@
     require ANSEL_TEMPLATES . '/common-header.inc';
     Ansel::menu();
     if (count($galleries) > 0) {
-        if ($prefs->getValue('listtype') != 'list') {
+        if ($prefs->getValue('listtype') == 'tree') {
+            foreach ($galleries as $galleryId => $gallery) {
+                $tree[$galleryId] = Ansel::getFullTree($galleryId);
+            }
+            require ANSEL_TEMPLATES . '/list/tree_gallery.inc';
+        } elseif ($prefs->getValue('listtype') == 'tile') {
             $template = ANSEL_TEMPLATES . '/list/tile_gallery.inc';
         } else {
             $template = ANSEL_TEMPLATES . '/list/gallery_summaries.inc';
@@ -72,12 +86,14 @@
             require ANSEL_TEMPLATES . '/list/gallery_headers.inc';
         }
 
-        foreach ($galleries as $galleryId => $gallery) {
-            $viewurl = Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $galleryId));
-            $slideurl = Horde::applicationUrl(Util::addParameter('slideshow.php', 'gallery', $galleryId));
-            $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
-            $zipurl = Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'downloadzip'));
-            require $template;
+        if ($prefs->getValue('listtype') != 'tree') {
+            foreach ($galleries as $galleryId => $gallery) {
+                $viewurl = Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $galleryId));
+                $slideurl = Horde::applicationUrl(Util::addParameter('slideshow.php', 'gallery', $galleryId));
+                $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
+                $zipurl = Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'downloadzip'));
+                require $template;
+            }
         }
 
         if ($prefs->getValue('listtype') == 'list') {
Index: config/html.php.dist
===================================================================
RCS file: /usr/local/horde/cvs/ansel/config/html.php.dist,v
retrieving revision 1.7
diff -u -r1.7 html.php.dist
--- config/html.php.dist	14 Nov 2003 19:31:52 -0000	1.7
+++ config/html.php.dist	19 Feb 2004 04:33:49 -0000
@@ -42,3 +42,12 @@
 $css['.preview']['text-align'] = 'center';
 $css['.preview']['border-right'] = '1px solid #999999';
 $css['.preview']['background-color'] = $css['.item0']['background-color'];
+
+$css['#tree ul']['list-style'] = 'none';
+$css['#tree ul']['margin-left'] = '0';
+$css['#tree ul']['padding-left'] = '1em';
+$css['#tree ul']['text-indent'] = '-1em';
+$css['#tree ul li']['list-style'] = 'none';
+$css['#tree ul li']['list-style-image'] = 'none';
+$css['#tree li a:hover']['color'] = 'red';
+$css['#tree li a:hover']['background-color'] = 'white';
Index: lib/Ansel.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/lib/Ansel.php,v
retrieving revision 1.48
diff -u -r1.48 Ansel.php
--- lib/Ansel.php	11 Feb 2004 22:17:10 -0000	1.48
+++ lib/Ansel.php	18 Feb 2004 16:56:23 -0000
@@ -26,6 +26,8 @@
      * @param string  $parent      (optional) The parent share to start searching at.
      * @param boolean $allLevels   (optional) Return all levels, or just the direct children
      *                             of $parent? Defaults to all levels.
+     * @param string  $sortby      (optional) The sorting key
+     * @param string  $sortdir     (optional) The sorting direction.
      *
      * @return array  Returns a list of matching, sorted galleries.
      */
@@ -40,9 +42,9 @@
 
         /* Sorting criteria for the gallery list. */
         $sort_functions = array(
-            ANSEL_SORT_NAME => 'ByName',
-            ANSEL_SORT_DESC => 'ByDesc',
-            ANSEL_SORT_OWNER => 'ByOwner',
+            ANSEL_SORT_NAME => 'ByName',        // 0
+            ANSEL_SORT_DESC => 'ByDesc',        // 1
+            ANSEL_SORT_OWNER => 'ByOwner',      // 2
         );
 
         $galleries = $ansel_shares->listShares(Auth::getAuth(), $perm, false, $parent, $allLevels);
@@ -63,6 +65,21 @@
     }
 
     /**
+     * Returns the full tree of the galleryId passed in.
+     *
+     * @param integer $pid  (optional) the starting gallery for the tree
+     *
+     * @return array  Returns a tree array of galleries.
+     */
+    function getFullTree($pid = '-1')
+    {
+        global $ansel_shares;
+
+        return $ansel_shares->_datatree->get(DATATREE_FORMAT_TREE, $pid);
+    }
+
+
+    /**
      * Retrieves the current user's gallery list from storage arranged by
      * the galleries' owner.
      *
@@ -89,6 +106,10 @@
 
         /* Return empty lists now. */
         if (!count($galleries)) {
+        }
+
+        /* Return empty lists now. */
+        if (!count($galleries)) {
             return $galleries;
         }
 
@@ -279,10 +300,6 @@
 
     /**
      * Comparison function for sorting galleries by owner.
-     *
-     * @param array $a  Gallery one.
-     * @param array $b  Gallery two.
-     *
      * @return integer  1 if gallery one is greater, -1 if gallery two is greater; 0 if they are equal.
      */
     function _sortByOwner($a, $b)
-------------- next part --------------
<script language="Javascript" type="text/javascript">
<!--

all_previews = new Array();
all_gallery_size = new Array();
all_gallery_id = new Array();
all_gallery_desc = new Array();
all_view_url = new Array();
all_slide_url = new Array();
all_zip_url = new Array();

<?php

$i = 0;
function createJS(&$parent, $cid)
{
    global $ansel_shares, $i;
    $gallery = &$ansel_shares->getGalleryById($cid);
    $galleryId = $gallery->getName();

    echo 'all_previews[' . $i . '] = \'' . addslashes(str_replace('&amp;', '&', Ansel::getImageUrl($gallery->getDefaultImage(), 'thumb'))) . "';\n";
    echo 'all_gallery_size[' . $i . '] = ' . $gallery->get('num-images') . ";\n";
    echo 'all_gallery_id[' . $i . '] = \'' . addslashes($galleryId) . "';\n";
    echo 'all_gallery_desc[' . $i . '] = \'' . addslashes($gallery->get('desc')) . "';\n";
    echo 'all_view_url[' . $i . '] = \'' . Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $galleryId)) . "';\n";
    echo 'all_slide_url[' . $i . '] = \'' . Horde::applicationUrl(Util::addParameter('slideshow.php', 'gallery', $galleryId)) . "';\n";
    $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
    echo 'all_zip_url[' . $i . '] = \'' . Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'downloadzip')) . "';\n";
    $i++;

    if (is_array($parent)) {
        array_walk($parent, 'createJS');
        return;
    }
}

foreach ($tree as $parentId => $children) {
    array_walk($children, 'createJS');
}
?>

function all_updateTile($id)
{
    size = all_gallery_size[$id];
    desc = all_gallery_desc[$id];
    preview = all_previews[$id];
    link = document.getElementById('all_link');
    link.href = all_view_url[$id];

    html = desc + ' (';
    if (size == 1) {
        html += '<?php echo _("1 image") ?>';
    } else {
        html += size + ' <?php echo _("images") ?>';
    }
    html += ')';

    if (size > 0) {
        html += '<br /><br /><?php echo Horde::link("javascript: all_downloadzip(' + \$id + ')", false, -1) . Horde::img('mime/compressed.gif', _("Download all images in a .zip file"), '', $registry->getParam('graphics', 'horde')) . ' ' . _("Download") ?></a>';
        html += '<br /><?php echo Horde::link("javascript:all_slideshow(' + \$id + ')", false, -1) . Horde::img('slideshow.gif', _("Slide show")) . ' ' . _("Slide show") ?></a>';
    }

    spanObj = document.getElementById('all_gallery_information');
    spanObj.innerHTML = html;

    document['all_preview'].src = preview;
}

function all_downloadzip($id)
{
    document.location = all_zip_url[$id];
}

function all_slideshow($id)
{
    document.location = all_slide_url[$id];
}

//-->
</script>

<table border="0" cellpadding="0" cellspacing="0" class="greybox" width="600">
 <tr>
  <td class="header" colspan="2">
   <?php echo $title ?>
  </td>
 </tr>
 <tr>
  <td class="preview"><?php echo Horde::link('" id="all_link') . Horde::img('', _("Gallery Preview"), 'vspace="5" class="solidbox" name="all_preview"') ?></a></td>
  <td valign="top">
   <table border="0" cellpadding="3" cellspacing="0" width="100%">
    <tr>
     <td>

      <div id="tree">
       <form name="all_galleries" action="view.php" method="get">

<?php

$j = 0;
function list_print(&$parent, $key, $subcount)
{
    global $ansel_shares, $j;
    $gallery = &$ansel_shares->getGalleryById($key);
    $galleryId = $gallery->getName();
    $viewurl = Horde::applicationUrl(Util::addParameter('view.php', 'gallery', $galleryId));
    $slideurl = Horde::applicationUrl(Util::addParameter('slideshow.php', 'gallery', $galleryId));
    $galleryurl = Util::addParameter('gallery.php', 'gallery', $galleryId);
    $zipurl = Horde::applicationUrl(Util::addParameter($galleryurl, 'actionID', 'downloadzip'));
    //$link = Horde::link($viewurl, sprintf(_("View %s"), $gallery->get('name')), '', '' , sprintf("%s_updateTile(); return true;",$gallery->get('owner')));
    $link = Horde::link('#', sprintf(_("View %s"), $gallery->get('name')), '', '' , sprintf("all_updateTile(%s); return true;",$j));
    $j++;

    if (is_array($parent) && $ansel_shares->_datatree->getNumberOfChildren($gallery) > 0) {
        echo "  <LI>" . $link . htmlspecialchars($gallery->get('name')) . "</a>";
        $subcount++;
        echo "    <UL>\n";
        array_walk($parent, 'list_print', $subcount);
        for (;$subcount > 0; $subcount--) {
            echo "    </UL>\n";
        }
        echo "  </LI>\n";
        return;
    } else {
        echo "  <LI>" . $link . htmlspecialchars($gallery->get('name')) . "</a></LI>\n";
    }
}
echo "<UL>\n";
foreach ($tree as $parentId => $children) {
    array_walk($children, 'list_print', 0);
}
echo "</UL>\n";

echo "</div>\n";

?>

        <br /><br />
        <span id="all_gallery_information"></span>
      </form>
      <script language="Javascript" type="text/javascript">
        all_updateTile(0);
      </script>
     </td>
    </tr>
   </table>
  </td>
 </tr>
</table>
<br />


More information about the ansel mailing list