| 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 @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( |
|---|
| 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 | $storage = $rcmail->get_storage(); |
|---|
| 69 | $storage->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 | $storage = $rcmail->get_storage(); |
|---|
| 80 | if ($storage->check_connection()) { |
|---|
| 81 | $args['folders'] = $storage->conn->listMailboxes($args['root'], $args['name']); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | return $args; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | function folders_list($args) |
|---|
| 88 | { |
|---|
| 89 | $rcmail = rcmail::get_instance(); |
|---|
| 90 | if (!$rcmail->config->get('use_subscriptions', true)) { |
|---|
| 91 | $args['table']->remove_column('subscribed'); |
|---|
| 92 | } |
|---|
| 93 | return $args; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|