[Svn] r2326 - in branches/devel-api: plugins plugins/subscriptions_option plugins/subscriptions_option/localization program/include program/steps/settings

trac at roundcube.net trac at roundcube.net
Tue Mar 3 20:29:26 CET 2009


Author: ziba
Date: 2009-03-03 13:29:26 -0600 (Tue, 03 Mar 2009)
New Revision: 2326

Added:
   branches/devel-api/plugins/subscriptions_option/
   branches/devel-api/plugins/subscriptions_option/localization/
   branches/devel-api/plugins/subscriptions_option/localization/en_US.inc
   branches/devel-api/plugins/subscriptions_option/subscriptions_option.php
Modified:
   branches/devel-api/program/include/html.php
   branches/devel-api/program/include/rcube_imap.php
   branches/devel-api/program/steps/settings/func.inc
   branches/devel-api/program/steps/settings/manage_folders.inc
   branches/devel-api/program/steps/settings/save_prefs.inc
Log:
New Plugin: Use Imap Subscriptions Option - by default roundcube only lists subscribed folders, this introduces an option to ignore subscriptions
New Plugin Hook: list_mailboxes - allows a plugin to provide the list of mailboxes instead of roundcube core
New Plugin Hook: manage_folders - allows a plugin to modify the main table on the manage folders screen
New Plugin Hook: user_preferences_server_settings - allows a plugin to modify the user preferences server settings table
New Plugin Hook: save_preferences - allows a plugin to inject data into the array of preferences about to be saved
Change to html class: added a remove_column method to give plugins a greater ability to modify the interface


Added: branches/devel-api/plugins/subscriptions_option/localization/en_US.inc
===================================================================
--- branches/devel-api/plugins/subscriptions_option/localization/en_US.inc	                        (rev 0)
+++ branches/devel-api/plugins/subscriptions_option/localization/en_US.inc	2009-03-03 19:29:26 UTC (rev 2326)
@@ -0,0 +1,6 @@
+<?php
+
+$labels = array();
+$labels['useimapsubscriptions']  = 'Use IMAP Subscriptions';
+
+?>

Added: branches/devel-api/plugins/subscriptions_option/subscriptions_option.php
===================================================================
--- branches/devel-api/plugins/subscriptions_option/subscriptions_option.php	                        (rev 0)
+++ branches/devel-api/plugins/subscriptions_option/subscriptions_option.php	2009-03-03 19:29:26 UTC (rev 2326)
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * Subscription Options
+ *
+ * A plugin which can enable or disable the use of imap subscriptions.
+ * It includes a toggle on the settings page under "Server Settings".
+ * The preference can also be locked
+ *
+ * Add it to the plugins list in config/main.inc.php to enable the user option
+ * The user option can be hidden and set globally by adding 'use_subscriptions'
+ * to the the 'dont_override' configure line:
+ * $rcmail_config['dont_override'] = array('use_subscriptions');
+ * and then set the global preference"
+ * $rcmail_config['use_subscriptions'] = true; // or false
+ *
+ * Roundcube caches folder lists.  When a user changes this option or visits
+ * their folder list, this cache is refreshed.  If the option is on the
+ * 'dont_override' list and the global option has changed, don't expect
+ * to see the change until the folder list cache is refreshed.
+ *
+ * @version 1.0
+ * @author Ziba Scott
+ */
+class subscriptions_option extends rcube_plugin
+{
+
+    function init()
+    {
+        $this->add_texts('localization/', false);
+        $config = rcmail::get_instance()->config->all();
+        if (!in_array('use_subscriptions',$config['dont_override'])){
+            $this->add_hook('user_preferences_server_settings', array($this, 'settings_table'));
+            $this->add_hook('save_preferences', array($this, 'save_prefs'));
+        }
+        $this->add_hook('list_mailboxes', array($this, 'list_mailboxes'));
+        $this->add_hook('manage_folders', array($this, 'manage_folders'));
+    }
+
+    function settings_table($args)
+    {
+        $config = rcmail::get_instance()->config->all();
+        $field_id = 'rcmfd_use_subscriptions';
+        $use_subscriptions = new html_checkbox(array('name' => '_use_subscriptions', 'id' => $field_id, 'value' => 1));
+
+        $args['table']->add('title', html::label($field_id, Q($this->gettext('useimapsubscriptions'))));
+        $args['table']->add(null, $use_subscriptions->show($config['use_subscriptions']?1:0));
+
+        return $args;
+    }
+
+    function save_prefs($args){
+        $rcmail = rcmail::get_instance();
+        $config = $rcmail->config->all();
+
+        $args['a_user_prefs']['use_subscriptions'] = isset($_POST['_use_subscriptions']) ? TRUE : FALSE;
+        // if the use_subscriptions preference changes, flush the folder cache
+        if (($config['use_subscriptions'] && !isset($_POST['_use_subscriptions'])) ||
+            (!$config['use_subscriptions'] && isset($_POST['_use_subscriptions']))) {
+                $rcmail->imap_init(true);
+                $rcmail->imap->clear_cache('mailboxes');
+            }
+
+        return $args;
+    }
+
+    function list_mailboxes($args){
+        $rcmail = rcmail::get_instance();
+        if ($rcmail->config->get('use_subscriptions', TRUE) == FALSE) {
+            $args['a_folders'] = iil_C_ListMailboxes($rcmail->imap->conn, $rcmail->imap->_mod_mailbox($args['root']), $args['filter']);
+        }
+        return $args;
+    }
+
+    function manage_folders($args){
+        $rcmail =rcmail::get_instance();
+        if ($rcmail->config->get('use_subscriptions', TRUE) == FALSE) {
+            $args['table']->remove_column('subscribed');
+        }
+        return $args;
+    }
+}

Modified: branches/devel-api/program/include/html.php
===================================================================
--- branches/devel-api/program/include/html.php	2009-03-03 12:49:03 UTC (rev 2325)
+++ branches/devel-api/program/include/html.php	2009-03-03 19:29:26 UTC (rev 2326)
@@ -599,6 +599,34 @@
         $this->header[] = $cell;
     }
 
+     /**
+     * Remove a column from a table
+     * Useful for plugins making alterations
+     * 
+     * @param string $class 
+     */
+    public function remove_column($class)
+    {
+        // Remove the header
+        foreach($this->header as $index=>$header){
+            if($header->attrib['class'] == $class){
+                unset($this->header[$index]);
+                break;
+            }
+        }
+
+        // Remove cells from rows
+        foreach($this->rows as $i=>$row){
+            foreach($row->cells as $j=>$cell){
+                if($cell->attrib['class'] == $class){
+                    unset($this->rows[$i]->cells[$j]);
+                    break;
+                }
+            }
+        }
+    }
+
+
     /**
      * Jump to next row
      *

Modified: branches/devel-api/program/include/rcube_imap.php
===================================================================
--- branches/devel-api/program/include/rcube_imap.php	2009-03-03 12:49:03 UTC (rev 2325)
+++ branches/devel-api/program/include/rcube_imap.php	2009-03-03 19:29:26 UTC (rev 2326)
@@ -426,8 +426,16 @@
     if (is_array($a_mboxes))
       return $a_mboxes;
 
-    // retrieve list of folders from IMAP server
-    $a_folders = iil_C_ListSubscribed($this->conn, $this->_mod_mailbox($root), $filter);
+    // Give plugins a chance to provide a list of mailboxes
+    $data = rcmail::get_instance()->plugins->exec_hook('list_mailboxes',array('root'=>$root,'filter'=>$filter));
+    if(isset($data['a_folders'])){
+        $a_folders = $data['a_folders'];
+    }
+    else{
+        // retrieve list of folders from IMAP server
+        $a_folders = iil_C_ListSubscribed($this->conn, $this->_mod_mailbox($root), $filter);
+    }
+
     
     if (!is_array($a_folders) || !sizeof($a_folders))
       $a_folders = array();

Modified: branches/devel-api/program/steps/settings/func.inc
===================================================================
--- branches/devel-api/program/steps/settings/func.inc	2009-03-03 12:49:03 UTC (rev 2325)
+++ branches/devel-api/program/steps/settings/func.inc	2009-03-03 19:29:26 UTC (rev 2326)
@@ -381,6 +381,8 @@
       $table->add(null, $input_expunge->show($config['logout_expunge']?1:0));
     }
 
+    rcmail::get_instance()->plugins->exec_hook('user_preferences_server_settings', array('table'=>$table));
+
     if ($table->size())
       $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('serversettings'))) . $table->show($attrib));
     break;

Modified: branches/devel-api/program/steps/settings/manage_folders.inc
===================================================================
--- branches/devel-api/program/steps/settings/manage_folders.inc	2009-03-03 12:49:03 UTC (rev 2325)
+++ branches/devel-api/program/steps/settings/manage_folders.inc	2009-03-03 19:29:26 UTC (rev 2326)
@@ -261,6 +261,7 @@
     $a_js_folders['rcmrow'.$idx] = array($folder_utf8, $display_folder, $protected || $folder['virtual']);
   }
 
+  rcmail::get_instance()->plugins->exec_hook('manage_folders', array('table'=>$table));
 
   $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']);
   $OUTPUT->set_env('subscriptionrows', $a_js_folders);

Modified: branches/devel-api/program/steps/settings/save_prefs.inc
===================================================================
--- branches/devel-api/program/steps/settings/save_prefs.inc	2009-03-03 12:49:03 UTC (rev 2325)
+++ branches/devel-api/program/steps/settings/save_prefs.inc	2009-03-03 19:29:26 UTC (rev 2326)
@@ -48,6 +48,9 @@
   'trash_mbox' => get_input_value('_trash_mbox', RCUBE_INPUT_POST),
   );
 
+$data  =  rcmail::get_instance()->plugins->exec_hook('save_preferences', array('a_user_prefs'=>$a_user_prefs));
+$a_user_prefs = $data['a_user_prefs'];
+
 // don't override these parameters
 foreach ((array)$CONFIG['dont_override'] as $p)
   $a_user_prefs[$p] = $CONFIG[$p];

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list