You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

subscriptions_option.php 3.4KB

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