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.

html5_notifier.php 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * html5_notifier
  4. * Shows a desktop notification every time a new (recent) mail comes in
  5. *
  6. * @version 0.5.0 - 19.12.2013
  7. * @author Tilman Stremlau <tilman@stremlau.net>
  8. * @website stremlau.net/html5_notifier
  9. * @licence GNU GPL
  10. *
  11. **/
  12. class html5_notifier extends rcube_plugin
  13. {
  14. public $task = '?(?!login|logout).*';
  15. function init()
  16. {
  17. $RCMAIL = rcmail::get_instance();
  18. if(file_exists("./plugins/html5_notifier/config/config.inc.php"))
  19. {
  20. $this->load_config('config/config.inc.php');
  21. }
  22. $this->add_hook('preferences_list', array($this, 'prefs_list'));
  23. $this->add_hook('preferences_save', array($this, 'prefs_save'));
  24. if ($RCMAIL->config->get('html5_notifier_duration').'' != '0')
  25. {
  26. $this->add_hook('new_messages', array($this, 'show_notification'));
  27. }
  28. $this->include_script("html5_notifier.js");
  29. if ($RCMAIL->action != 'check-recent')
  30. {
  31. $this->add_texts('localization', array('notification_title', 'ok_notifications', 'no_notifications', 'check_ok', 'check_fail', 'check_fail_blocked')); //PR�ZESIEREN
  32. }
  33. }
  34. function show_notification($args)
  35. {
  36. $RCMAIL = rcmail::get_instance();
  37. //$search = $RCMAIL->config->get('html5_notifier_only_new', false) ?'NEW' : 'RECENT';
  38. $deleted = $RCMAIL->config->get('skip_deleted') ? 'UNDELETED ' : '';
  39. $search = $deleted . 'UNSEEN UID ' . $args['diff']['new'];
  40. $RCMAIL->storage->set_folder($args['mailbox']);
  41. $RCMAIL->storage->search($args['mailbox'], $search, null);
  42. $msgs = (array) $RCMAIL->storage->list_messages($args['mailbox']);
  43. $excluded_directories = preg_split("/(,|;| )+/", $RCMAIL->config->get('html5_notifier_excluded_directories'));
  44. foreach ($msgs as $msg) {
  45. $from = $msg->get('from');
  46. $mbox = '';
  47. switch ($RCMAIL->config->get('html5_notifier_smbox')) {
  48. case 1: $mbox = array_pop(explode('.', str_replace('INBOX.', '', $args['mailbox']))); break;
  49. case 2: $mbox = str_replace('.', '/', str_replace('INBOX.', '', $args['mailbox'])); break;
  50. }
  51. $subject = ((!empty($mbox)) ? rcube_charset::convert($mbox, 'UTF7-IMAP') . ': ' : '') . $msg->get('subject');
  52. if(strtolower($_SESSION['username']) == strtolower($RCMAIL->user->data['username']) && !in_array($mbox, $excluded_directories))
  53. {
  54. $RCMAIL->output->command("plugin.showNotification", array(
  55. 'duration' => $RCMAIL->config->get('html5_notifier_duration'),
  56. 'opentype' => $RCMAIL->config->get('html5_notifier_popuptype'),
  57. 'subject' => $subject,
  58. 'from' => $from,
  59. 'uid' => $msg->uid.'&_mbox='.$args['mailbox'],
  60. ));
  61. }
  62. }
  63. $RCMAIL->storage->search($args['mailbox'], "ALL", null);
  64. }
  65. function prefs_list($args)
  66. {
  67. if($args['section'] == 'mailbox')
  68. {
  69. $RCMAIL = rcmail::get_instance();
  70. $field_id = 'rcmfd_html5_notifier';
  71. $select_duration = new html_select(array('name' => '_html5_notifier_duration', 'id' => $field_id));
  72. $select_duration->add($this->gettext('off'), '0');
  73. $times = array('3', '5', '8', '10', '12', '15', '20', '25', '30');
  74. foreach ($times as $time)
  75. $select_duration->add($time.' '.$this->gettext('seconds'), $time);
  76. $select_duration->add($this->gettext('durable'), '-1');
  77. $select_smbox = new html_select(array('name' => '_html5_notifier_smbox', 'id' => $field_id));
  78. $select_smbox->add($this->gettext('no_mailbox'), '0');
  79. $select_smbox->add($this->gettext('short_mailbox'), '1');
  80. $select_smbox->add($this->gettext('full_mailbox'), '2');
  81. $content = $select_duration->show($RCMAIL->config->get('html5_notifier_duration').'');
  82. $content .= $select_smbox->show($RCMAIL->config->get('html5_notifier_smbox').'');
  83. $content .= html::a(array('href' => '#', 'id' => 'rcmfd_html5_notifier_browser_conf', 'onclick' => 'rcmail_browser_notifications(); return false;'), $this->gettext('conf_browser')).' ';
  84. $content .= html::a(array('href' => '#', 'onclick' => 'rcmail_browser_notifications_test(); return false;'), $this->gettext('test_browser'));
  85. $args['blocks']['new_message']['options']['html5_notifier'] = array(
  86. 'title' => html::label($field_id, rcube::Q($this->gettext('shownotifies'))),
  87. 'content' => $content,
  88. );
  89. $check_only_new = new html_checkbox(array('name' => '_html5_notifier_only_new', 'id' => $field_id . '_only_new', 'value' => 1));
  90. $content = $check_only_new->show($RCMAIL->config->get('html5_notifier_only_new', false));
  91. $args['blocks']['new_message']['options']['html5_notifier_only_new'] = array(
  92. 'title' => html::label($field_id, rcube::Q($this->gettext('onlynew'))),
  93. 'content' => $content,
  94. );
  95. $input_excluded = new html_inputfield(array('name' => '_html5_notifier_excluded_directories', 'id' => $field_id . '_excluded'));
  96. $args['blocks']['new_message']['options']['html5_notifier_excluded_directories'] = array(
  97. 'title' => html::label($field_id, rcube::Q($this->gettext('excluded_directories'))),
  98. 'content' => $input_excluded->show($RCMAIL->config->get('html5_notifier_excluded_directories').''),
  99. );
  100. $select_type = new html_select(array('name' => '_html5_notifier_popuptype', 'id' => $field_id . '_popuptype'));
  101. $select_type->add($this->gettext('new_tab'), '0');
  102. $select_type->add($this->gettext('new_window'), '1');
  103. $args['blocks']['new_message']['options']['html5_notifier_popuptype'] = array(
  104. 'title' => html::label($field_id, rcube::Q($this->gettext('notifier_popuptype'))),
  105. 'content' => $select_type->show($RCMAIL->config->get('html5_notifier_popuptype').'')
  106. );
  107. $RCMAIL->output->add_script("$(document).ready(function(){ rcmail_browser_notifications_colorate(); });");
  108. }
  109. return $args;
  110. }
  111. function prefs_save($args)
  112. {
  113. if($args['section'] == 'mailbox')
  114. {
  115. $args['prefs']['html5_notifier_only_new'] = !empty($_POST['_html5_notifier_only_new']);
  116. $args['prefs']['html5_notifier_duration'] = rcube_utils::get_input_value('_html5_notifier_duration', rcube_utils::INPUT_POST);
  117. $args['prefs']['html5_notifier_smbox'] = rcube_utils::get_input_value('_html5_notifier_smbox', rcube_utils::INPUT_POST);
  118. $args['prefs']['html5_notifier_excluded_directories'] = rcube_utils::get_input_value('_html5_notifier_excluded_directories', rcube_utils::INPUT_POST);
  119. $args['prefs']['html5_notifier_popuptype'] = rcube_utils::get_input_value('_html5_notifier_popuptype', rcube_utils::INPUT_POST);
  120. return $args;
  121. }
  122. }
  123. }
  124. ?>