Aleksander Machniak
2013-06-14 461a30d771edd8bc6606f2c92dfde363514b93b1
commit | author | age
48e9c1 1 <?php
T 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  *
461a30 10  * Add it to the plugins list in config.inc.php to enable the user option
48e9c1 11  * The user option can be hidden and set globally by adding 'use_subscriptions'
654ac1 12  * to the 'dont_override' configure line:
48e9c1 13  * $rcmail_config['dont_override'] = array('use_subscriptions');
T 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 @package_version@
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('storage_folders', 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(
61be82 49                 'title' => html::label($field_id, rcube::Q($this->gettext('useimapsubscriptions'))),
48e9c1 50                 'content' => $checkbox->show($use_subscriptions?1:0),
T 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                     $storage = $rcmail->get_storage();
69                     $storage->clear_cache('mailboxes');
70             }
71         }
72         return $args;
73     }
74
75     function mailboxes_list($args)
76     {
3c5489 77         $rcmail = rcmail::get_instance();
48e9c1 78         if (!$rcmail->config->get('use_subscriptions', true)) {
3c5489 79             $args['folders'] = $rcmail->get_storage()->list_folders_direct();
48e9c1 80         }
T 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 }