]> git.donarmstrong.com Git - roundcube.git/blob - plugins/subscriptions_option/subscriptions_option.php
d9c5ce7db8b8b498bc8e99e6615b1d30cade7408
[roundcube.git] / plugins / subscriptions_option / subscriptions_option.php
1 <?php
2
3 /**
4  * Subscription Options
5  *
6  * A plugin which can enable or disable the use of imap subscriptions.
7  * It includes a toggle on the settings page under "Server Settings".
8  * The preference can also be locked
9  *
10  * Add it to the plugins list in config/main.inc.php to enable the user option
11  * The user option can be hidden and set globally by adding 'use_subscriptions'
12  * to the the 'dont_override' configure line:
13  * $rcmail_config['dont_override'] = array('use_subscriptions');
14  * and then set the global preference
15  * $rcmail_config['use_subscriptions'] = true; // or false
16  *
17  * Roundcube caches folder lists.  When a user changes this option or visits
18  * their folder list, this cache is refreshed.  If the option is on the
19  * 'dont_override' list and the global option has changed, don't expect
20  * to see the change until the folder list cache is refreshed.
21  *
22  * @version 1.0
23  * @author Ziba Scott
24  */
25 class subscriptions_option extends rcube_plugin
26 {
27     public $task = 'mail|settings';
28     
29     function init()
30     {
31         $this->add_texts('localization/', false);
32         $dont_override = rcmail::get_instance()->config->get('dont_override', array());
33         if (!in_array('use_subscriptions', $dont_override)) {
34             $this->add_hook('preferences_list', array($this, 'settings_blocks'));
35             $this->add_hook('preferences_save', array($this, 'save_prefs'));
36         }
37         $this->add_hook('mailboxes_list', array($this, 'mailboxes_list'));
38         $this->add_hook('folders_list', array($this, 'folders_list'));
39     }
40
41     function settings_blocks($args)
42     {
43         if ($args['section'] == 'server') {
44             $use_subscriptions = rcmail::get_instance()->config->get('use_subscriptions');
45             $field_id = 'rcmfd_use_subscriptions';
46             $checkbox = new html_checkbox(array('name' => '_use_subscriptions', 'id' => $field_id, 'value' => 1));
47
48             $args['blocks']['main']['options']['use_subscriptions'] = array(
49                 'title' => html::label($field_id, Q($this->gettext('useimapsubscriptions'))),
50                 'content' => $checkbox->show($use_subscriptions?1:0),
51             );
52         }
53
54         return $args;
55     }
56
57     function save_prefs($args)
58     {
59         if ($args['section'] == 'server') {
60             $rcmail = rcmail::get_instance();
61             $use_subscriptions = $rcmail->config->get('use_subscriptions');
62
63             $args['prefs']['use_subscriptions'] = isset($_POST['_use_subscriptions']) ? true : false;
64
65             // if the use_subscriptions preference changes, flush the folder cache
66             if (($use_subscriptions && !isset($_POST['_use_subscriptions'])) ||
67                 (!$use_subscriptions && isset($_POST['_use_subscriptions']))) {
68                     $rcmail->imap_connect();
69                     $rcmail->imap->clear_cache('mailboxes');
70             }
71         }
72         return $args;
73     }
74
75     function mailboxes_list($args)
76     {
77         $rcmail = rcmail::get_instance();
78         if (!$rcmail->config->get('use_subscriptions', true)) {
79             $args['folders'] = $rcmail->imap->conn->listMailboxes($rcmail->imap->mod_mailbox($args['root']), $args['filter']);
80         }
81         return $args;
82     }
83
84     function folders_list($args)
85     {
86         $rcmail = rcmail::get_instance();
87         if (!$rcmail->config->get('use_subscriptions', true)) {
88             $args['table']->remove_column('subscribed');
89         }
90         return $args;
91     }
92 }