| 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 | |
|---|
| 28 | function init() |
|---|
| 29 | { |
|---|
| 30 | $this->add_texts('localization/', false); |
|---|
| 31 | $dont_override = rcmail::get_instance()->config->get('dont_override', array()); |
|---|
| 32 | if (!in_array('use_subscriptions', $dont_override)){ |
|---|
| 33 | $this->add_hook('user_preferences', array($this, 'settings_table')); |
|---|
| 34 | $this->add_hook('save_preferences', array($this, 'save_prefs')); |
|---|
| 35 | } |
|---|
| 36 | $this->add_hook('list_mailboxes', array($this, 'list_mailboxes')); |
|---|
| 37 | $this->add_hook('manage_folders', array($this, 'manage_folders')); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | function settings_table($args) |
|---|
| 41 | { |
|---|
| 42 | if ($args['section'] == 'server') { |
|---|
| 43 | $use_subscriptions = rcmail::get_instance()->config->get('use_subscriptions'); |
|---|
| 44 | $field_id = 'rcmfd_use_subscriptions'; |
|---|
| 45 | $use_subscriptions = new html_checkbox(array('name' => '_use_subscriptions', 'id' => $field_id, 'value' => 1)); |
|---|
| 46 | |
|---|
| 47 | $args['table']->add('title', html::label($field_id, Q($this->gettext('useimapsubscriptions')))); |
|---|
| 48 | $args['table']->add(null, $use_subscriptions->show($use_subscriptions?1:0)); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | return $args; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | function save_prefs($args){ |
|---|
| 55 | $rcmail = rcmail::get_instance(); |
|---|
| 56 | $use_subscriptions = $rcmail->config->get('use_subscriptions'); |
|---|
| 57 | |
|---|
| 58 | $args['prefs']['use_subscriptions'] = isset($_POST['_use_subscriptions']) ? true : false; |
|---|
| 59 | // if the use_subscriptions preference changes, flush the folder cache |
|---|
| 60 | if (($use_subscriptions && !isset($_POST['_use_subscriptions'])) || |
|---|
| 61 | (!$use_subscriptions && isset($_POST['_use_subscriptions']))) { |
|---|
| 62 | $rcmail->imap_init(true); |
|---|
| 63 | $rcmail->imap->clear_cache('mailboxes'); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | return $args; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | function list_mailboxes($args){ |
|---|
| 70 | $rcmail = rcmail::get_instance(); |
|---|
| 71 | if (!$rcmail->config->get('use_subscriptions', true)) { |
|---|
| 72 | $args['folders'] = iil_C_ListMailboxes($rcmail->imap->conn, $rcmail->imap->_mod_mailbox($args['root']), $args['filter']); |
|---|
| 73 | } |
|---|
| 74 | return $args; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | function manage_folders($args){ |
|---|
| 78 | $rcmail = rcmail::get_instance(); |
|---|
| 79 | if (!$rcmail->config->get('use_subscriptions', true)) { |
|---|
| 80 | $args['table']->remove_column('subscribed'); |
|---|
| 81 | } |
|---|
| 82 | return $args; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|