Improved Ingo menu rendering
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 May 2010 06:48:26 +0000 (00:48 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 May 2010 16:04:09 +0000 (10:04 -0600)
ingo/blacklist.php
ingo/filters.php
ingo/forward.php
ingo/lib/Ingo.php
ingo/rule.php
ingo/script.php
ingo/spam.php
ingo/templates/menu.inc [deleted file]
ingo/templates/menu/menu.html [new file with mode: 0644]
ingo/vacation.php
ingo/whitelist.php

index 367ba43..944331d 100644 (file)
@@ -102,6 +102,7 @@ Ingo::prepareMenu();
 Ingo::addNewFolderJs();
 $title = _("Blacklist Edit");
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 require INGO_TEMPLATES . '/blacklist/blacklist.inc';
 require $registry->get('templates', 'horde') . '/common-footer.inc';
index e104974..183a4e8 100644 (file)
@@ -143,7 +143,8 @@ Horde::addScriptFile('filters.js', 'ingo');
 Ingo::prepareMenu();
 $title = _("Filter Rules");
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 require INGO_TEMPLATES . '/filters/header.inc';
 
 /* Common URLs. */
index a1470b9..6080648 100644 (file)
@@ -95,6 +95,7 @@ $form->setTitle($form_title);
 $title = _("Forwards Edit");
 Ingo::prepareMenu();
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false)), $vars, 'forward.php', 'post');
 require $registry->get('templates', 'horde') . '/common-footer.inc';
index 7afb869..bfe3d5e 100644 (file)
@@ -23,11 +23,11 @@ class Ingo
     const USER_HEADER = '++USER_HEADER++';
 
     /**
-     * getMenu() cache.
+     * prepareMenu() cache.
      *
-     * @var string
+     * @var Horde_Template
      */
-    static private $_menuCache = null;
+    static private $_menuTemplate = null;
 
     /**
      * hasSharePermission() cache.
@@ -417,6 +417,8 @@ class Ingo
 
     /**
      * Build Ingo's list of menu items.
+     *
+     * @return Horde_Menu  A Horde_Menu object.
      */
     static public function getMenu()
     {
@@ -456,11 +458,46 @@ class Ingo
      */
     static public function prepareMenu()
     {
-        if (!self::$_menuCache) {
-            self::$_menuCache = self::getMenu()->render();
+        if (isset(self::$_menuTemplate)) {
+            return;
+        }
+
+        $t = $GLOBALS['injector']->createInstance('Horde_Template');
+        $t->set('forminput', Horde_Util::formInput());
+
+        if (!empty($GLOBALS['ingo_shares']) &&
+            (count($GLOBALS['all_rulesets']) > 1)) {
+            $options = array();
+            foreach (array_keys($GLOBALS['all_rulesets']) as $id) {
+                $options[] = array(
+                    'name' => htmlspecialchars($GLOBALS['all_rulesets'][$id]->get('name')),
+                    'selected' => ($_SESSION['ingo']['current_share'] == $id),
+                    'val' => htmlspecialchars($id)
+                );
+            }
+            $t->set('options', $options);
         }
 
-        return self::$_menuCache;
+        $t->set('menu_string', self::getMenu()->render());
+
+        self::$_menuTemplate = $t;
+    }
+
+    /**
+     * Outputs IMP's menu to the current output stream.
+     */
+    static public function menu()
+    {
+        self::prepareMenu();
+        echo self::$_menuTemplate->fetch(INGO_TEMPLATES . '/menu/menu.html');
+    }
+
+    /**
+     * Outputs IMP's status/notification bar.
+     */
+    static public function status()
+    {
+        $GLOBALS['notification']->notify(array('listeners' => array('status', 'audio')));
     }
 
     /**
index 166a5bf..96f409a 100644 (file)
@@ -197,7 +197,8 @@ Horde::addScriptFile('rule.js', 'ingo');
 Ingo::prepareMenu();
 Ingo::addNewFolderJs();
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 require INGO_TEMPLATES . '/rule/header.inc';
 
 /* Add new, blank condition. */
index e865eeb..77a3b5d 100644 (file)
@@ -52,7 +52,8 @@ case 'show_active':
 $title = _("Filter Script Display");
 Ingo::prepareMenu();
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 require INGO_TEMPLATES . '/script/header.inc';
 if (!empty($script)) {
     require INGO_TEMPLATES . '/script/activate.inc';
index f31dbe7..4b43559 100644 (file)
@@ -152,6 +152,7 @@ $title = _("Spam Filtering");
 Ingo::prepareMenu();
 Ingo::addNewFolderJs();
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 $form->renderActive($renderer, $vars, 'spam.php', 'post');
 require $registry->get('templates', 'horde') . '/common-footer.inc';
diff --git a/ingo/templates/menu.inc b/ingo/templates/menu.inc
deleted file mode 100644 (file)
index 71b6f2b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<form action="filters.php" method="post" name="rulesetsmenu">
-<?php echo Horde_Util::formInput() ?>
-<div id="menu">
-<?php if (!empty($ingo_shares) && count($all_rulesets) > 1): ?>
- <div style="float:right">
-<label for="ruleset" class="hidden"><?php echo _("Select ruleset to display:") ?></label>
-<select id="ruleset" name="ruleset" onchange="document.rulesetsmenu.submit(); return false;">
-  <option value=""><?php echo _("Select ruleset to display:") ?></option>
-<?php foreach (array_keys($all_rulesets) as $id): ?>
-  <option value="<?php echo htmlspecialchars($id) ?>"<?php echo ($_SESSION['ingo']['current_share'] == $id ? ' selected="selected"' : '') . '>' . htmlspecialchars($all_rulesets[$id]->get('name')) ?></option>
-<?php endforeach; ?>
-</select>
- </div>
-<?php endif; ?>
-
- <?php echo Ingo::prepareMenu() ?>
-</div>
-</form>
-
-<?php $GLOBALS['notification']->notify(array('listeners' => 'status')) ?>
diff --git a/ingo/templates/menu/menu.html b/ingo/templates/menu/menu.html
new file mode 100644 (file)
index 0000000..23d80ee
--- /dev/null
@@ -0,0 +1,17 @@
+<form action="filters.php" method="post" name="rulesetsmenu">
+ <tag:forminput />
+ <div id="menu">
+<if:options>
+  <div style="float:right">
+   <label for="ruleset" class="hidden"><gettext>Select ruleset to display:</gettext></label>
+   <select id="ruleset" name="ruleset" onchange="document.rulesetsmenu.submit(); return false;">
+    <option value=""><gettext>Select ruleset to display:</gettext></option>
+<loop:options>
+    <option value="<tag:options.val />"<if:options.selected> selected="selected"</if:options.selected>><tag:options.name /></option>
+</loop:options>
+   </select>
+  </div>
+</if:options>
+  <tag:menu_string />
+ </div>
+</form>
index 613c373..f6abdc0 100644 (file)
@@ -144,6 +144,7 @@ $form->setTitle($form_title);
 $title = _("Vacation Edit");
 Ingo::prepareMenu();
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false)), $vars, 'vacation.php', 'post');
 require $registry->get('templates', 'horde') . '/common-footer.inc';
index 8169f3e..dfec272 100644 (file)
@@ -55,6 +55,7 @@ $wl_rule = $filters->findRule(Ingo_Storage::ACTION_WHITELIST);
 $title = _("Whitelist Edit");
 Ingo::prepareMenu();
 require INGO_TEMPLATES . '/common-header.inc';
-require INGO_TEMPLATES . '/menu.inc';
+Ingo::menu();
+Ingo::status();
 require INGO_TEMPLATES . '/whitelist/whitelist.inc';
 require $registry->get('templates', 'horde') . '/common-footer.inc';