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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * @version @package_version@
  22. * @author Ziba Scott
  23. * @license GNU GPLv3+
  24. */
  25. class subscriptions_option extends rcube_plugin
  26. {
  27. public $task = 'mail|settings';
  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('preferences_list', array($this, 'settings_blocks'));
  34. $this->add_hook('preferences_save', array($this, 'save_prefs'));
  35. }
  36. $this->add_hook('storage_folders', array($this, 'mailboxes_list'));
  37. $this->add_hook('folders_list', array($this, 'folders_list'));
  38. }
  39. function settings_blocks($args)
  40. {
  41. if ($args['section'] == 'server') {
  42. $use_subscriptions = rcmail::get_instance()->config->get('use_subscriptions');
  43. $field_id = 'rcmfd_use_subscriptions';
  44. $checkbox = new html_checkbox(array('name' => '_use_subscriptions', 'id' => $field_id, 'value' => 1));
  45. $args['blocks']['main']['options']['use_subscriptions'] = array(
  46. 'title' => html::label($field_id, rcube::Q($this->gettext('useimapsubscriptions'))),
  47. 'content' => $checkbox->show($use_subscriptions?1:0),
  48. );
  49. }
  50. return $args;
  51. }
  52. function save_prefs($args)
  53. {
  54. if ($args['section'] == 'server') {
  55. $rcmail = rcmail::get_instance();
  56. $use_subscriptions = $rcmail->config->get('use_subscriptions');
  57. $args['prefs']['use_subscriptions'] = isset($_POST['_use_subscriptions']);
  58. // if the use_subscriptions preference changes, flush the folder cache
  59. if (($use_subscriptions && !isset($_POST['_use_subscriptions'])) ||
  60. (!$use_subscriptions && isset($_POST['_use_subscriptions']))) {
  61. $storage = $rcmail->get_storage();
  62. $storage->clear_cache('mailboxes');
  63. }
  64. }
  65. return $args;
  66. }
  67. function mailboxes_list($args)
  68. {
  69. $rcmail = rcmail::get_instance();
  70. if (!$rcmail->config->get('use_subscriptions', true)) {
  71. $args['folders'] = $rcmail->get_storage()->list_folders_direct();
  72. }
  73. return $args;
  74. }
  75. function folders_list($args)
  76. {
  77. $rcmail = rcmail::get_instance();
  78. if (!$rcmail->config->get('use_subscriptions', true)) {
  79. foreach ($args['list'] as $idx => $data) {
  80. $args['list'][$idx]['content'] = preg_replace('/<input [^>]+>/', '', $data['content']);
  81. }
  82. }
  83. return $args;
  84. }
  85. }