From c49c35ca0fdd4d3972748a8846c0c71f50c80b16 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Sat, 28 Sep 2013 06:03:20 -0400
Subject: [PATCH] Generate settings tabs with a template object 'settingstabs' and let plugins register themselves there using the 'settings_actions' hook

---
 program/steps/settings/func.inc |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index f117017..af278e5 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -1246,9 +1246,66 @@
             $name_utf8, $display_name, $protected, $class_name);
 }
 
+/**
+ * Render the list of settings sections (AKA tabs)
+ */
+function rcmail_settings_tabs($attrib)
+{
+    global $RCMAIL, $OUTPUT;
+
+    // add default attributes
+    $attrib += array('tagname' => 'span', 'idprefix' => 'settingstab', 'selclass' => 'selected');
+
+    $default_actions = array(
+        array('command' => 'preferences', 'type' => 'link', 'label' => 'preferences', 'title' => 'editpreferences'),
+        array('command' => 'folders',     'type' => 'link', 'label' => 'folders',     'title' => 'managefolders'),
+        array('command' => 'identities',  'type' => 'link', 'label' => 'identities',  'title' => 'manageidentities'),
+    );
+
+    // get all identites from DB and define list of cols to be displayed
+    $plugin = $RCMAIL->plugins->exec_hook('settings_actions', array(
+        'actions' => $default_actions,
+        'attrib' => $attrib,
+    ));
+
+    $attrib = $plugin['attrib'];
+    $tagname = $attrib['tagname'];
+    $tabs = array();
+
+    foreach ($plugin['actions'] as $k => $action) {
+        if (!$action['command'] && !$action['href'] && $action['action']) {
+            $action['href'] = $RCMAIL->url(array('_action' => $action['action']));
+        }
+
+        $button = $OUTPUT->button($action);
+        $attr = $attrib;
+
+        $cmd = $action['action'] ? $action['action'] : $action['command'];
+        $id = $action['id'] ? $action['id'] : $cmd;
+        if (!empty($id)) {
+            $attr['id'] = preg_replace('/[^a-z0-9]/i', '', $attrib['idprefix'] . $id);
+        }
+        $classnames = array($attrib['class']);
+        if (!empty($action['class'])) {
+            $classnames[] = $action['class'];
+        }
+        else if (!empty($cmd)) {
+            $classnames[] = $cmd;
+        }
+        if ($RCMAIL->action == $cmd) {
+            $classnames[] = $attrib['selclass'];
+        }
+        $attr['class'] = join(' ', $classnames);
+        $tabs[] = html::tag($tagname, $attr, $button, html::$common_attrib);
+    }
+
+    return join('', $tabs);
+}
+
 
 // register UI objects
 $OUTPUT->add_handlers(array(
+    'settingstabs' => 'rcmail_settings_tabs',
     'prefsframe' => 'rcmail_preferences_frame',
     'sectionslist' => 'rcmail_sections_list',
     'identitieslist' => 'rcmail_identities_list',

--
Gitblit v1.9.1