Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 44 additions & 36 deletions html5_notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,30 @@ function show_notification($args)
$RCMAIL = rcmail::get_instance();

//$search = $RCMAIL->config->get('html5_notifier_only_new', false) ?'NEW' : 'RECENT';
$deleted = $RCMAIL->config->get('skip_deleted') ? 'UNDELETED ' : '';
$search = $deleted . 'UNSEEN UID ' . $args['diff']['new'];

$RCMAIL->storage->set_folder($args['mailbox']);
$RCMAIL->storage->search($args['mailbox'], $search, null);
$msgs = (array) $RCMAIL->storage->list_messages($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)) ? rcube_charset::convert($mbox, 'UTF7-IMAP') . ': ' : '') . $msg->get('subject');
$deleted = $RCMAIL->config->get('skip_deleted') ? 'UNDELETED ' : '';
$search = $deleted . 'UNSEEN UID ' . $args['diff']['new'];

$RCMAIL->storage->set_folder($args['mailbox']);
$RCMAIL->storage->search($args['mailbox'], $search, null);
$msgs = (array) $RCMAIL->storage->list_messages($args['mailbox']);
$excluded_directories = array();
if (!empty($RCMAIL->config->get('html5_notifier_excluded_directories'))) {
$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 = explode('.', str_replace('INBOX.', '', $args['mailbox']));
$mbox = array_pop($mbox);
break;
case 2:
$mbox = str_replace('.', '/', str_replace('INBOX.', '', $args['mailbox']));
break;
}
$subject = ((!empty($mbox)) ? rcube_charset::convert($mbox, 'UTF7-IMAP') . ': ' : '') . $msg->get('subject');

if(strtolower($_SESSION['username']) == strtolower($RCMAIL->user->data['username']) && !in_array($args['mailbox'], $excluded_directories))
{
Expand All @@ -72,7 +80,7 @@ function show_notification($args)
));
}
}
$RCMAIL->storage->search($args['mailbox'], "ALL", null);
$RCMAIL->storage->search($args['mailbox'], "ALL", null);
}

function prefs_list($args)
Expand All @@ -82,21 +90,21 @@ function prefs_list($args)
$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 = 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');
$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 .= $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(
Expand All @@ -111,19 +119,19 @@ function prefs_list($args)
'content' => $content,
);

$input_excluded = new html_inputfield(array('name' => '_html5_notifier_excluded_directories', 'id' => $field_id . '_excluded'));
$args['blocks']['new_message']['options']['html5_notifier_excluded_directories'] = array(
$input_excluded = new html_inputfield(array('name' => '_html5_notifier_excluded_directories', 'id' => $field_id . '_excluded'));
$args['blocks']['new_message']['options']['html5_notifier_excluded_directories'] = array(
'title' => html::label($field_id, rcube::Q($this->gettext('excluded_directories'))),
'content' => $input_excluded->show($RCMAIL->config->get('html5_notifier_excluded_directories').''),
);

$select_type = new html_select(array('name' => '_html5_notifier_popuptype', 'id' => $field_id . '_popuptype'));
$select_type->add($this->gettext('new_tab'), '0');
$select_type->add($this->gettext('new_window'), '1');
$args['blocks']['new_message']['options']['html5_notifier_popuptype'] = array(
'title' => html::label($field_id, rcube::Q($this->gettext('notifier_popuptype'))),
'content' => $select_type->show($RCMAIL->config->get('html5_notifier_popuptype').'')
);
$select_type = new html_select(array('name' => '_html5_notifier_popuptype', 'id' => $field_id . '_popuptype'));
$select_type->add($this->gettext('new_tab'), '0');
$select_type->add($this->gettext('new_window'), '1');
$args['blocks']['new_message']['options']['html5_notifier_popuptype'] = array(
'title' => html::label($field_id, rcube::Q($this->gettext('notifier_popuptype'))),
'content' => $select_type->show($RCMAIL->config->get('html5_notifier_popuptype').'')
);

$RCMAIL->output->add_script("$(document).ready(function(){ rcmail_browser_notifications_colorate(); });");
}
Expand All @@ -136,10 +144,10 @@ function prefs_save($args)
{
$args['prefs']['html5_notifier_only_new'] = !empty($_POST['_html5_notifier_only_new']);
$args['prefs']['html5_notifier_duration'] = rcube_utils::get_input_value('_html5_notifier_duration', rcube_utils::INPUT_POST);
$args['prefs']['html5_notifier_smbox'] = rcube_utils::get_input_value('_html5_notifier_smbox', rcube_utils::INPUT_POST);
$args['prefs']['html5_notifier_excluded_directories'] = rcube_utils::get_input_value('_html5_notifier_excluded_directories', rcube_utils::INPUT_POST);
$args['prefs']['html5_notifier_popuptype'] = rcube_utils::get_input_value('_html5_notifier_popuptype', rcube_utils::INPUT_POST);
return $args;
$args['prefs']['html5_notifier_smbox'] = rcube_utils::get_input_value('_html5_notifier_smbox', rcube_utils::INPUT_POST);
$args['prefs']['html5_notifier_excluded_directories'] = rcube_utils::get_input_value('_html5_notifier_excluded_directories', rcube_utils::INPUT_POST);
$args['prefs']['html5_notifier_popuptype'] = rcube_utils::get_input_value('_html5_notifier_popuptype', rcube_utils::INPUT_POST);
return $args;
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions localization/pt_PT.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
$labels = array();
$labels['shownotifies'] = 'Notificações no Ambiente de trabalho';
$labels['onlynew'] = 'Mostrar apenas novas mensagens';
$labels['conf_browser'] = 'Configurar o navegador';
$labels['test_browser'] = 'Testar';
$labels['excluded_directories'] = 'Pastas excluídas das notificações';
$labels['check_ok'] = 'As definições do seu navegador estão corretas.';
$labels['check_fail'] = 'Não foi possível mostrar a notificação, clique em "Configurar o navegador"!';
$labels['check_fail_blocked'] = 'O seu navegador bloqueou a notificação, ative a permissão nas definições do navegador!';
$labels['no_notifications'] = 'O seu navegador não suporta Notificações no Ambiente de trabalho!';
$labels['ok_notifications'] = 'A página já obteve permissão. As Notificações no Ambiente de trabalho devem funcionar.';
$labels['notification_title'] = 'Novo e-mail de [from]';

$labels['seconds'] = 'segundos';
$labels['off'] = 'desativado';
$labels['durable'] = 'permanente';

$labels['no_mailbox'] = 'não mostrar caixa de correio';
$labels['short_mailbox'] = 'mostrar caixa de correio curta';
$labels['full_mailbox'] = 'mostrar caixa de correio completa';

$labels['notifier_popuptype'] = 'Como abrir mensagens ao clicar na notificação';
$labels['new_tab'] = 'Numa nova aba';
$labels['new_window'] = 'Numa nova janela';
?>