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