mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-25 17:33:49 +01:00
improve notification by allowing to set up specific popup notification messages and subjects; this is used for calendar notification to give worthwile information in popup and meet expectations for ical/rfc type notification
This commit is contained in:
parent
8009d3ccf6
commit
0a076525b8
@ -841,7 +841,7 @@ class calendar_boupdate extends calendar_bo
|
||||
}
|
||||
|
||||
list($subject,$body) = explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
|
||||
|
||||
$popup = '';
|
||||
switch($part_prefs['calendar']['update_format'])
|
||||
{
|
||||
case 'ical':
|
||||
@ -860,13 +860,14 @@ class calendar_boupdate extends calendar_bo
|
||||
'encoding' => '8bit',
|
||||
'type' => 'text/calendar; method='.$method,
|
||||
);
|
||||
$popup = $body;
|
||||
$popupsubject = $subject;
|
||||
// format iCal uses now like Exchange event-title as subject and description as body
|
||||
$subject = $event['title'];
|
||||
$body = $event['description'];
|
||||
break;
|
||||
|
||||
case 'extended':
|
||||
$body .= "\n\n".lang('Event Details follow').":\n";
|
||||
$popup .= "\n\n".lang('Event Details follow').":\n";
|
||||
foreach($event_arr as $key => $val)
|
||||
{
|
||||
if(!empty($details[$key]))
|
||||
@ -877,11 +878,16 @@ class calendar_boupdate extends calendar_bo
|
||||
case 'link':
|
||||
break;
|
||||
default:
|
||||
$body .= sprintf("%-20s %s\n",$val['field'].':',$details[$key]);
|
||||
$popup .= sprintf("%-20s %s\n",$val['field'].':',$details[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($part_prefs['calendar']['update_format']=='extended')
|
||||
{
|
||||
$body = $body.$popup;
|
||||
unset($popup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// send via notification_app
|
||||
@ -891,8 +897,10 @@ class calendar_boupdate extends calendar_bo
|
||||
$notification = new notifications();
|
||||
$notification->set_receivers(array($userid));
|
||||
$notification->set_message($body);
|
||||
if (isset($popup)&&!empty($popup)) $notification->set_popupmessage($popup);
|
||||
$notification->set_sender($senderid);
|
||||
$notification->set_subject($subject);
|
||||
if (isset($popupsubject)&&!empty($popupsubject)) $notification->set_popupsubject($popupsubject);
|
||||
$notification->set_links(array($details['link_arr']));
|
||||
if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
|
||||
$notification->send();
|
||||
|
@ -120,6 +120,12 @@ final class notifications {
|
||||
*/
|
||||
private $subject = '';
|
||||
|
||||
/**
|
||||
* holds notification subject for popup
|
||||
* @var string
|
||||
*/
|
||||
private $popupsubject = '';
|
||||
|
||||
/**
|
||||
* holds notification message in plaintext
|
||||
* @var string
|
||||
@ -132,6 +138,12 @@ final class notifications {
|
||||
*/
|
||||
private $message_html = '';
|
||||
|
||||
/**
|
||||
* holds notification message for popup
|
||||
* @var string
|
||||
*/
|
||||
private $message_popup = '';
|
||||
|
||||
/**
|
||||
* array with objects of links
|
||||
* @var array
|
||||
@ -239,6 +251,16 @@ final class notifications {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets notification subject for popup
|
||||
*
|
||||
* @param string $_subject
|
||||
*/
|
||||
public function set_popupsubject($_subject) {
|
||||
$this->popupsubject = $_subject;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets notification message
|
||||
* @abstract $_message accepts plaintext or html
|
||||
@ -258,6 +280,21 @@ final class notifications {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets specific popup notification message
|
||||
* @abstract $_message accepts plaintext or html
|
||||
* NOTE: There is no XSS prevention in notifications framework!
|
||||
* You have to filter userinputs yourselve (e.g. htmlspechialchars() )
|
||||
*
|
||||
* @param string $_message
|
||||
*/
|
||||
public function set_popupmessage($_message) {
|
||||
//popup requires html
|
||||
if(strlen($_message) == strlen(strip_tags($_message))) $_message=nl2br($_message);
|
||||
$this->message_popup = $_message;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the notification links
|
||||
*
|
||||
@ -354,7 +391,7 @@ final class notifications {
|
||||
if (!is_array($this->receivers) || count($this->receivers) == 0) {
|
||||
throw new Exception('Error: cannot send notifications. No receivers supplied');
|
||||
}
|
||||
if(!$messages = $this->create_messages($this->message_plain, $this->message_html)) {
|
||||
if(!$messages = $this->create_messages($this->message_plain, $this->message_html, $this->message_popup)) {
|
||||
throw new Exception('Error: cannot send notifications. No valid messages supplied');
|
||||
}
|
||||
|
||||
@ -428,8 +465,9 @@ final class notifications {
|
||||
unset ( $obj );
|
||||
throw new Exception($notification_backend. ' is no implementation of notifications_iface');
|
||||
}
|
||||
|
||||
$obj->send($this->prepend_message($messages, $prepend_message), $this->subject, $this->links, $this->attachments);
|
||||
$lsubject = $this->subject;
|
||||
if ($backend=='popup' && isset($this->popupsubject) && !empty($this->popupsubject)) $lsubject = $this->popupsubject;
|
||||
$obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $this->links, $this->attachments);
|
||||
}
|
||||
catch (Exception $exception) {
|
||||
$backend_errors[] = $notification_backend.' failed: '.$exception->getMessage();
|
||||
@ -459,14 +497,15 @@ final class notifications {
|
||||
}
|
||||
|
||||
/**
|
||||
* creates an array with the message as plaintext and html
|
||||
* creates an array with the message as plaintext and html, and optional a html popup message
|
||||
*
|
||||
* @param string $_message_plain
|
||||
* @param string $_message_html
|
||||
* @return plain and html message in one array, $messages['plain'] and $messages['html']
|
||||
* @param string $_message_popup
|
||||
* @return plain and html message in one array, $messages['plain'] and $messages['html'] and, if exists $messages['popup']
|
||||
*/
|
||||
private function create_messages($_message_plain = '', $_message_html = '') {
|
||||
if(empty($_message_plain) && empty($_message_html)) { return false; } // no message set
|
||||
private function create_messages($_message_plain = '', $_message_html = '', $_message_popup = '') {
|
||||
if(empty($_message_plain) && empty($_message_html) && empty($_message_popup)) { return false; } // no message set
|
||||
$messages = array();
|
||||
|
||||
// create the messages
|
||||
@ -481,7 +520,7 @@ final class notifications {
|
||||
} else {
|
||||
$messages['html'] = nl2br($_message_plain);
|
||||
}
|
||||
|
||||
if (!empty($_message_popup)) $messages['popup']=$_message_popup;
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class notifications_popup implements notifications_iface {
|
||||
|
||||
$message = $this->render_infos($_subject)
|
||||
.html::hr()
|
||||
.$_messages['html']
|
||||
.(isset($_messages['popup'])&&!empty($_messages['popup'])?$_messages['popup']:$_messages['html'])
|
||||
.$this->render_links($_links);
|
||||
|
||||
$this->save( $message );
|
||||
|
Loading…
Reference in New Issue
Block a user