[imp] Folder-view frameset for IMP

Matthew Hodgson matthew at mxtelecom.com
Tue Jan 13 08:24:28 PST 2004


Hi all,

I just installed IMP for my workplace - seems to work very nicely indeed.  I 
had one immediate request from users however - the desire for the option to 
have the IMAP folder list visible down the left hand side of the page at all 
times.

As far as my cursory Googling could attest, this isn't a feature of current 
IMP 3.2.2 - and i couldn't see any customised examples where people have done 
this; perhaps due to trepidation about using frames (ick).  However, in my 
opinion this is practically the only instance where it's legitimate to use 
frames, and so I've knocked up a very rough and ready patch to provide the 
option of such a layout - the results of which look a bit like:

http://buccaneer.mxtelecom.com/~matthew/images/impshot.gif

The code isn't perfect at all - folders.php should presumably replace the 
frameset when it loads (and then switch back to frame view when exiting the 
page); the actual URL redirection via frameset.php should probably be 
arbritated by Horde::link or an IMP:: version thereof rather than being 
kludged into redirect.php.  Finally, a logo for the top-left is hardcoded into 
folders.php rather than being in a trivial template of its own, which violates 
the model/view abstraction.  Putting javascript to maintain the title of the 
frameset window in menu/menu.inc is a nasty hack.  It also hasn't been 
rigorously tested (yet).

But, it seems to work for my purposes - so I enclose the patch here (against 
IMP 3.2.2) in the spirit of open source software in case anyone else wants to 
give it a whirl/extend/critique it, etc.

cheers,

M.

-- 
Matthew Hodgson <matthew at mxtelecom.com>
http://www.mxtelecom.com
-------------- next part --------------
diff -urP imp-3.2.2/config/prefs.php.dist imp/config/prefs.php.dist
--- imp-3.2.2/config/prefs.php.dist	2002-10-29 21:04:33.000000000 +0000
+++ imp/config/prefs.php.dist	2004-01-13 15:38:10.000000000 +0000
@@ -85,7 +85,7 @@
     'label' => _("Display Options"),
     'desc' => _("Change display options such as how many messages you see on each page and how messages are sorted."),
     'members' => array('sortby', 'sortdir', 'max_msgs', 'num_words',
-                       'nav_expanded', 'show_legend',
+                       'nav_expanded', 'use_folder_frame', 'show_legend',
                        'highlight_text', 'dim_signature')
 );
 
@@ -570,6 +570,16 @@
     'type' => 'implicit'
 );
 
+// display folder tree in lhs frame
+// a value of 0 =no, 1 = yes
+$_prefs['use_folder_frame'] = array(
+    'value' => 1,
+    'locked' => false,
+    'shared' => false,
+    'type' => 'checkbox',
+    'desc' => _("Always display folder list (in a frame)")
+);
+
 // show mailbox legend?
 // a value of 0 =no, 1 = yes
 $_prefs['show_legend'] = array(
diff -urP imp-3.2.2/folders.php imp/folders.php
--- imp-3.2.2/folders.php	2003-08-06 19:02:46.000000000 +0100
+++ imp/folders.php	2004-01-13 15:12:29.000000000 +0000
@@ -62,7 +62,7 @@
 /* Utility function to return a url for the various folder images */
 function folderImage($name, $alt, $width, $height) {
     return Horde::img('folders/' . $name,
-                      '" hspace="0" border="0" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"');
+                      '" hspace="0" border="0" align="absmiddle" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"');
 }
 
 /* Decide whether or not to show all the unsubscribed folders */
@@ -274,7 +274,7 @@
 $subToggleText = $showAll ? _("Hide Unsubscribed") : _("Show Unsubscribed");
 
 /* Set the URL to refresh the page to in the META tag */
-$refresh_url = Horde::applicationUrl('folders.php', true);
+$refresh_url = Horde::applicationUrl('folders.php'.(Horde::getFormData('in_frame') == 'yes' ? '?in_frame=yes' : ''), true);
 
 if ($conf['compress_pages']) {
     ob_start('ob_gzhandler');
@@ -283,9 +283,15 @@
 $title = _("Folder Navigator");
 $js_onLoad = null;
 require IMP_TEMPLATES . '/common-header.inc';
-require IMP_BASE . '/menu.php';
-require IMP_BASE . '/status.php';
-echo $quota_html;
+
+if (Horde::getFormData('in_frame') != 'yes') {
+	require IMP_BASE . '/menu.php';
+	require IMP_BASE . '/status.php';
+	echo $quota_html;
+}
+else {
+	echo '<center><img src="/images/imp_logo.gif" width="180" height="43" alt="Horde IMP"></center><br />';
+}
 
 /* Default to the very top of the hierarchy */
 if (!isset($pattern)) {
@@ -299,7 +305,13 @@
 
 require IMP_TEMPLATES . '/folders/javascript.inc';
 require IMP_TEMPLATES . '/folders/head.inc';
-require IMP_TEMPLATES . '/folders/actions.inc';
+
+if (Horde::getFormData('in_frame') != 'yes') {
+	require IMP_TEMPLATES . '/folders/actions.inc';
+}
+else {
+	require IMP_TEMPLATES . '/folders/actions_frame.inc';
+}
 
 /* Always poll the INBOX for new mail */
 $nm = $imaptree->updateMessageInfo();
@@ -347,7 +359,8 @@
 
     if (!($mailbox['attributes'] & LATT_NOSELECT)) {
         $name = Horde::link(Horde::applicationUrl('mailbox.php?newmail_popup=no&mailbox=' . urlencode($mailbox['value'])),
-                _("View messages in ") . IMP::displayFolder($mailbox['value'])) .
+                _("View messages in ") . IMP::displayFolder($mailbox['value']), '',
+		($prefs->getValue('use_folder_frame') == 1 ? 'imp_rhs' : '' )) .
                 $mailbox['label'] . '</a>';
 
         if ($mailbox['value'] == 'INBOX') {
@@ -372,11 +385,11 @@
 
         if ($imaptree->isOpen($mailbox)) {
             $dir = Horde::link(Horde::applicationUrl('folders.php?actionID=' . COLLAPSE_FOLDER . "&folder=" .
-                   urlencode($imaptree->server . $mailbox['value'])), _("Collapse Folder")) .
+                   urlencode($imaptree->server . $mailbox['value']) . (Horde::getFormData('in_frame') == 'yes' ? '&in_frame=yes' : '' )), _("Collapse Folder")) .
                    folderImage('expanded.gif', _("Collapse Folder"), 18, 18) . "</a>$dir2";
         } else {
             $dir = Horde::link(Horde::applicationUrl('folders.php?actionID=' . EXPAND_FOLDER . "&folder=" .
-                   urlencode($imaptree->server . $mailbox['value'])), _("Expand Folder")) .
+                   urlencode($imaptree->server . $mailbox['value']) . (Horde::getFormData('in_frame') == 'yes' ? '&in_frame=yes' : '' )), _("Expand Folder")) .
                    folderImage('collapsed.gif', _("Expand Folder"), 18, 18) . "</a>$dir2";
         }
     } else {
@@ -434,11 +447,17 @@
 /* Put the tree back into the session object for caching */
 $imp['imaptree'] = $imaptree->pickle();
 
-require IMP_TEMPLATES . '/folders/actions.inc';
+if (Horde::getFormData('in_frame') != 'yes') {
+        require IMP_TEMPLATES . '/folders/actions.inc';
+}
+else {
+        require IMP_TEMPLATES . '/folders/actions_frame.inc';
+}
 require IMP_TEMPLATES . '/folders/foot.inc';
 
 /* Check to see if user wants new mail notification */
 if ($prefs->getValue('nav_popup') && 
+    (Horde::getFormData('in_frame') != 'yes') &&
     (Horde::getFormData('newmail_popup') != 'no')) {
     $alert = '';
     $count = 0;
diff -urP imp-3.2.2/frameset.php imp/frameset.php
--- imp-3.2.2/frameset.php	1970-01-01 01:00:00.000000000 +0100
+++ imp/frameset.php	2004-01-13 14:38:44.000000000 +0000
@@ -0,0 +1,42 @@
+<?php
+/*
+ * $Horde: imp/frameset.php,v Exp $
+ *
+ * Copyright 2002-2003 Brent J. Nordquist <bjn at horde.org>
+ * Copyright 1999-2003 Charles J. Hagenbuch <chuck at horde.org>
+ * Copyright 1999-2003 Jon Parise <jon at horde.org>
+ * Copyright 2004      Matthew J. Hodgson <matthew at mxtelecom.com>
+ *
+ * See the enclosed file COPYING for license information (LGPL).  If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ */
+
+/* Set character encoding. */
+header('Content-type: text/html; charset=utf-8');
+header('Vary: Accept-Language');
+
+define('IMP_BASE', dirname(__FILE__));
+require_once IMP_BASE . '/lib/base.php';
+
+$imp_lhs = Horde::applicationUrl('folders.php?in_frame=yes', true);
+$imp_rhs = Horde::getFormData('url');
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>IMP</title>
+<script language="JavaScript">
+<!--
+if (window != window.top)
+  top.location.href = location.href;
+// -->
+</script>
+</head>
+
+<frameset cols="210, *" border="0" id="imp_fs">
+	<frame src="<?php echo $imp_lhs ?>" name="imp_lhs" />
+	<frame src="<?php echo $imp_rhs ?>" name="imp_rhs" />
+</frameset>
+</html>
diff -urP imp-3.2.2/lib/IMP.php imp/lib/IMP.php
--- imp-3.2.2/lib/IMP.php	2003-08-21 02:54:07.000000000 +0100
+++ imp/lib/IMP.php	2004-01-13 15:32:58.000000000 +0000
@@ -1173,6 +1173,31 @@
     }
 
     /**
+     * Turns the URL into a frameset which contains said URL on the rhs
+     * and folder view in the left hand side, if appropriate. - currently
+     * only used by redirect.php (which in turn is only used when logging in)
+     * 
+     * Decisions to not framesetify particular pages (e.g. folders.php perhaps)
+     * should go here.
+     */
+    function makeFrameset($desturl)
+    {
+        global $prefs;
+
+        if ($prefs->getValue('use_folder_frame') == 1) {
+            $url = 'frameset.php';
+            $url = IMP::addParameter($url, 'url='. urlencode($desturl));
+	    $url = Horde::applicationUrl($url, true);
+        }
+        else {
+            $url = $desturl;
+        }
+
+        return $url;
+    }
+
+
+    /**
      * Perform filtering on the current mailbox.
      *
      * @access public
diff -urP imp-3.2.2/redirect.php imp/redirect.php
--- imp-3.2.2/redirect.php	2003-06-14 16:13:38.000000000 +0100
+++ imp/redirect.php	2004-01-13 13:39:36.000000000 +0000
@@ -61,7 +61,7 @@
             $actionID = null;
         }
 
-        header('Location: ' . _getInitialUrl($actionID));
+        header('Location: ' . IMP::makeFrameset(_getInitialUrl($actionID)));
         exit;
     } else {
         /* Disable the old session. */
@@ -109,7 +109,7 @@
         } else {
             $url = _getInitialUrl($actionID);
         }
-        header('Location: ' . $url);
+        header('Location: ' . IMP::makeFrameset($url));
         exit;
     } else {
         header('Location: ' . Horde::applicationUrl(IMP::logoutUrl('login.php', $reason), true));
diff -urP imp-3.2.2/templates/folders/actions.inc imp/templates/folders/actions.inc
--- imp-3.2.2/templates/folders/actions.inc	2002-07-16 16:45:52.000000000 +0100
+++ imp/templates/folders/actions.inc	2004-01-13 10:59:07.000000000 +0000
@@ -29,5 +29,4 @@
        <?php echo _("Collapse All") ?></a>
     </td>
     <td width="1%" align="center"><b>#</b></td>
-    <td width="1%" align="center"><?php echo Horde::img('unseen.gif', 'alt="' . _("Unseen Messages") . '" height="16" width="16"') ?></td>
 </tr>
diff -urP imp-3.2.2/templates/folders/actions_frame.inc imp/templates/folders/actions_frame.inc
--- imp-3.2.2/templates/folders/actions_frame.inc	1970-01-01 01:00:00.000000000 +0100
+++ imp/templates/folders/actions_frame.inc	2004-01-13 10:59:01.000000000 +0000
@@ -0,0 +1,13 @@
+<tr class="item">
+    <td colspan="2" align="left">
+       <?php if ($prefs->getValue('subscribe')): ?>
+       <?php echo Horde::link('javascript:submitAction(' . TOGGLE_SUBSCRIBED_VIEW . ')', $subToggleText, 'widget') ?>
+       <?php echo $subToggleText ?></a>&nbsp;|
+       <?php endif; ?>
+       <?php echo Horde::link('javascript:submitAction(' . EXPAND_ALL_FOLDERS . ')', _("Expand All Folders"), 'widget') ?>
+       <?php echo _("Expand All") ?></a>&nbsp;|
+       <?php echo Horde::link('javascript:submitAction(' . COLLAPSE_ALL_FOLDERS . ')', _("Collapse All Folders"), 'widget') ?>
+       <?php echo _("Collapse All") ?></a>
+    </td>
+    <td width="1%" align="center"><b>#</b></td>
+</tr>
diff -urP imp-3.2.2/templates/folders/foot.inc imp/templates/folders/foot.inc
--- imp-3.2.2/templates/folders/foot.inc	2002-03-10 02:52:11.000000000 +0000
+++ imp/templates/folders/foot.inc	2004-01-13 10:54:15.000000000 +0000
@@ -5,6 +5,9 @@
 <input type="hidden" name="old_names" value="" />
 <input type="hidden" name="view_subscribed" value="" />
 <input type="hidden" name="refresh_time" value="" />
+<?php if (Horde::getFormData('in_frame') == 'yes') {?>
+<input type="hidden" name="in_frame" value="yes" />
+<?php } ?>
 </form>
 
 <script language="JavaScript" type="text/javascript">
diff -urP imp-3.2.2/templates/folders/row.inc imp/templates/folders/row.inc
--- imp-3.2.2/templates/folders/row.inc	2002-07-16 16:45:53.000000000 +0100
+++ imp/templates/folders/row.inc	2004-01-13 12:31:40.000000000 +0000
@@ -1,10 +1,10 @@
 <tr class="<?php echo $navclass ?>">
     <td class="<?php echo $navclass ?>">
-        <input class="<?php echo $navclass ?>" type="checkbox" name="folder_list[]" value="<?php echo htmlspecialchars($mailbox['value']) ?>" />
+        <?php if (Horde::getFormData('in_frame') != 'yes') { ?><input class="<?php echo $navclass ?>" type="checkbox" name="folder_list[]" value="<?php echo htmlspecialchars($mailbox['value']) ?>" /><?php } ?>
         <?php echo Horde::img('folders/spacer.gif', 'alt="" height="1" width="' . $indent_level * 18 . '"') ?>
-        <?php echo $dir . '&nbsp;&nbsp;' . $name ?>
+        <?php echo $dir . '&nbsp;&nbsp;' . $name;
+	      if ($new>0) { echo ' ('.$new.')'; } ?>
     </td>
     <td>&nbsp;</td>
     <td align="center"><?php echo $msgs ?></td>
-    <td align="center"><?php echo $new ?></td>
 </tr>
diff -urP imp-3.2.2/templates/menu/menu.inc imp/templates/menu/menu.inc
--- imp-3.2.2/templates/menu/menu.inc	2003-02-21 12:42:25.000000000 +0000
+++ imp/templates/menu/menu.inc	2004-01-13 14:25:22.000000000 +0000
@@ -1,5 +1,14 @@
 <link rel="search" href="<?php echo Horde::applicationUrl('search.php') ?>" />
 
+<?php if ($prefs->getValue('use_folder_frame')) { ?>
+<script language="JavaScript" type="text/javascript">
+<!--
+	window.top.document.title = document.title;
+// -->
+</script>
+<?php } ?>
+
+
 <?php if ($conf['user']['allow_folders'] && isset($menu_folders)): ?>
 <form action="<?php echo Horde::applicationUrl("mailbox.php") ?>" method="get" name="menu">
 <input type="hidden" name="newmail_popup" value="no" />
@@ -51,9 +60,9 @@
 
 /* Logout */
 if ($registry->getMethod('auth/logout') == 'imp' && !$imp['direct_access']) {
-    Menu::printItem(Horde::url($registry->getParam('webroot', 'horde') . '/login.php?reason=logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'));
+    Menu::printItem(Horde::url($registry->getParam('webroot', 'horde') . '/login.php?reason=logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'), $prefs->getValue('use_folder_frame') == 1 ? '_parent' : '');
 } else {
-    Menu::printItem(Horde::applicationUrl('login.php?reason=logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'));
+    Menu::printItem(Horde::applicationUrl('login.php?reason=logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'), $prefs->getValue('use_folder_frame') == 1 ? '_parent' : '');
 }
 
 ?>


More information about the imp mailing list