mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
"removed deprecated ereg, to get ride of the warning"
This commit is contained in:
parent
d22a9aa537
commit
bb0ab3d0ff
@ -10,17 +10,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(EGW_INCLUDE_ROOT.'/phpgwapi/inc/class.config.inc.php');
|
require_once(EGW_INCLUDE_ROOT.'/phpgwapi/inc/class.config.inc.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies users according to their preferences.
|
* Notifies users according to their preferences.
|
||||||
*
|
*
|
||||||
* @abstract NOTE: This is for instant notifications. If you need time dependend notifications use the
|
* @abstract NOTE: This is for instant notifications. If you need time dependend notifications use the
|
||||||
* asyncservices wrapper!
|
* asyncservices wrapper!
|
||||||
*
|
*
|
||||||
* This class takes care about the notification-routing. It chooses one or more backends for each
|
* This class takes care about the notification-routing. It chooses one or more backends for each
|
||||||
* given recipient depending on its prefs or falls back to self::_fallback
|
* given recipient depending on its prefs or falls back to self::_fallback
|
||||||
*
|
*
|
||||||
* The classes doing the notifications are called notifications_<backend> and should only be
|
* The classes doing the notifications are called notifications_<backend> and should only be
|
||||||
* called from this class. The backend's job is to deliver ONE message to ONE recipient.
|
* called from this class. The backend's job is to deliver ONE message to ONE recipient.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -30,30 +30,30 @@ final class notifications {
|
|||||||
* Appname
|
* Appname
|
||||||
*/
|
*/
|
||||||
const _appname = 'notifications';
|
const _appname = 'notifications';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* backend to use for fallback reasons
|
* backend to use for fallback reasons
|
||||||
*/
|
*/
|
||||||
const _fallback = 'email_only';
|
const _fallback = 'email_only';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered backends
|
* registered backends
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $backends = array('popup', 'winpopup', 'email', 'sms');
|
private $backends = array('popup', 'winpopup', 'email', 'sms');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* backends to skip even if the user has chosen it
|
* backends to skip even if the user has chosen it
|
||||||
* this could be set by the calling application
|
* this could be set by the calling application
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $skip_backends = array();
|
private $skip_backends = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pre-defined notificaton chains
|
* pre-defined notificaton chains
|
||||||
* @abstract
|
* @abstract
|
||||||
* arrays with name => chain pairs
|
* arrays with name => chain pairs
|
||||||
* the chain itself consists of an array with framework => action pairs
|
* the chain itself consists of an array with framework => action pairs
|
||||||
* where action defines what to do after the framework has been executed:
|
* where action defines what to do after the framework has been executed:
|
||||||
* stop: stop executing notifications
|
* stop: stop executing notifications
|
||||||
* fail: do not stop if framework fails, otherwise stop
|
* fail: do not stop if framework fails, otherwise stop
|
||||||
@ -77,7 +77,7 @@ final class notifications {
|
|||||||
'sms_only' => array('sms' => 'stop'),
|
'sms_only' => array('sms' => 'stop'),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* human readable descriptions for the notification chains
|
* human readable descriptions for the notification chains
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -96,56 +96,56 @@ final class notifications {
|
|||||||
'winpopup_and_email' => 'Windows-Popup and E-Mail',
|
'winpopup_and_email' => 'Windows-Popup and E-Mail',
|
||||||
'sms_only' => 'SMS only',
|
'sms_only' => 'SMS only',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array with objects of receivers
|
* array with objects of receivers
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $receivers = array();
|
private $receivers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* object of sender
|
* object of sender
|
||||||
* @var object
|
* @var object
|
||||||
*/
|
*/
|
||||||
private $sender;
|
private $sender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds notification subject
|
* holds notification subject
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $subject = '';
|
private $subject = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds notification message in plaintext
|
* holds notification message in plaintext
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $message_plain = '';
|
private $message_plain = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds notification message in html
|
* holds notification message in html
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $message_html = '';
|
private $message_html = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array with objects of links
|
* array with objects of links
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $links = array();
|
private $links = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array with objects of attachments
|
* array with objects of attachments
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $attachments = array();
|
private $attachments = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds config object (sitewide configuration of app)
|
* holds config object (sitewide configuration of app)
|
||||||
*
|
*
|
||||||
* @var object
|
* @var object
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor of notifications
|
* constructor of notifications
|
||||||
*
|
*
|
||||||
@ -153,7 +153,7 @@ final class notifications {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->config = (object) config::read(self::_appname);
|
$this->config = (object) config::read(self::_appname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set sender for the current notification
|
* Set sender for the current notification
|
||||||
*
|
*
|
||||||
@ -174,14 +174,14 @@ final class notifications {
|
|||||||
if(is_string($_sender) && strpos($_sender,'@')) {
|
if(is_string($_sender) && strpos($_sender,'@')) {
|
||||||
$this->sender = (object) array (
|
$this->sender = (object) array (
|
||||||
'account_email' => $this->get_addresspart($_sender,'email'),
|
'account_email' => $this->get_addresspart($_sender,'email'),
|
||||||
'account_fullname' => $this->get_addresspart($_sender,'fullname'),
|
'account_fullname' => $this->get_addresspart($_sender,'fullname'),
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set receivers for the current notification
|
* Set receivers for the current notification
|
||||||
*
|
*
|
||||||
@ -195,7 +195,7 @@ final class notifications {
|
|||||||
$this->add_receiver($receiver);
|
$this->add_receiver($receiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add single receiver for the current notification
|
* Add single receiver for the current notification
|
||||||
*
|
*
|
||||||
@ -216,32 +216,32 @@ final class notifications {
|
|||||||
if(is_string($_receiver) && strpos($_receiver,'@')) {
|
if(is_string($_receiver) && strpos($_receiver,'@')) {
|
||||||
$this->receivers[] = (object) array (
|
$this->receivers[] = (object) array (
|
||||||
'account_email' => $this->get_addresspart($_receiver,'email'),
|
'account_email' => $this->get_addresspart($_receiver,'email'),
|
||||||
'account_fullname' => $this->get_addresspart($_receiver,'fullname'),
|
'account_fullname' => $this->get_addresspart($_receiver,'fullname'),
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets notification subject
|
* sets notification subject
|
||||||
*
|
*
|
||||||
* @param string $_subject
|
* @param string $_subject
|
||||||
*/
|
*/
|
||||||
public function set_subject($_subject) {
|
public function set_subject($_subject) {
|
||||||
$this->subject = $_subject;
|
$this->subject = $_subject;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets notification message
|
* sets notification message
|
||||||
* @abstract $_message accepts plaintext or html
|
* @abstract $_message accepts plaintext or html
|
||||||
* NOTE: There is no XSS prevention in notifications framework!
|
* NOTE: There is no XSS prevention in notifications framework!
|
||||||
* You have to filter userinputs yourselve (e.g. htmlspechialchars() )
|
* You have to filter userinputs yourselve (e.g. htmlspechialchars() )
|
||||||
* If you want to set plain AND html messages, just call this function
|
* If you want to set plain AND html messages, just call this function
|
||||||
* two times, it autodetects the type of your input
|
* two times, it autodetects the type of your input
|
||||||
*
|
*
|
||||||
* @param string $_message
|
* @param string $_message
|
||||||
*/
|
*/
|
||||||
public function set_message($_message) {
|
public function set_message($_message) {
|
||||||
@ -252,10 +252,10 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the notification links
|
* sets the notification links
|
||||||
*
|
*
|
||||||
* @param array $_links link array (like defined in $this->add_link)
|
* @param array $_links link array (like defined in $this->add_link)
|
||||||
*/
|
*/
|
||||||
public function set_links(array $_links) {
|
public function set_links(array $_links) {
|
||||||
@ -267,7 +267,7 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a notification link
|
* adds a notification link
|
||||||
*
|
*
|
||||||
@ -283,10 +283,10 @@ final class notifications {
|
|||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the notification attachments
|
* sets the notification attachments
|
||||||
*
|
*
|
||||||
* @param array $_attachments attachment array (like defined in $this->add_attachment)
|
* @param array $_attachments attachment array (like defined in $this->add_attachment)
|
||||||
*/
|
*/
|
||||||
public function set_attachments(array $_attachments) {
|
public function set_attachments(array $_attachments) {
|
||||||
@ -302,12 +302,12 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a notification attachment
|
* adds a notification attachment
|
||||||
* This method can be used to attach ascii or binary data,
|
* This method can be used to attach ascii or binary data,
|
||||||
* such as a BLOB record from a database.
|
* such as a BLOB record from a database.
|
||||||
*
|
*
|
||||||
* @param string $_string Attachment data.
|
* @param string $_string Attachment data.
|
||||||
* @param string $_filename Name of the attachment.
|
* @param string $_filename Name of the attachment.
|
||||||
* @param string $_encoding File encoding (see $Encoding).
|
* @param string $_encoding File encoding (see $Encoding).
|
||||||
@ -322,7 +322,7 @@ final class notifications {
|
|||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets backends that should be skipped even if the user
|
* Sets backends that should be skipped even if the user
|
||||||
* defined them in its chain
|
* defined them in its chain
|
||||||
@ -333,7 +333,7 @@ final class notifications {
|
|||||||
public function set_skip_backends(array $_skip_backends) {
|
public function set_skip_backends(array $_skip_backends) {
|
||||||
$this->skip_backends = $_skip_backends;
|
$this->skip_backends = $_skip_backends;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sends notifications
|
* sends notifications
|
||||||
*/
|
*/
|
||||||
@ -347,9 +347,9 @@ final class notifications {
|
|||||||
if(!$messages = $this->create_messages($this->message_plain, $this->message_html)) {
|
if(!$messages = $this->create_messages($this->message_plain, $this->message_html)) {
|
||||||
throw new Exception('Error: cannot send notifications. No valid messages supplied');
|
throw new Exception('Error: cannot send notifications. No valid messages supplied');
|
||||||
}
|
}
|
||||||
|
|
||||||
$available_chains = $this->get_available_chains('routing');
|
$available_chains = $this->get_available_chains('routing');
|
||||||
|
|
||||||
foreach ($this->receivers as $receiver) {
|
foreach ($this->receivers as $receiver) {
|
||||||
$user_notified = false;
|
$user_notified = false;
|
||||||
$prepend_message = '';
|
$prepend_message = '';
|
||||||
@ -386,7 +386,7 @@ final class notifications {
|
|||||||
$receiver->handle = $receiver->account_email;
|
$receiver->handle = $receiver->account_email;
|
||||||
$notification_chain = $available_chains[self::_fallback]; // fallback: non-system user
|
$notification_chain = $available_chains[self::_fallback]; // fallback: non-system user
|
||||||
}
|
}
|
||||||
|
|
||||||
if($notification_chain == 'disable') {
|
if($notification_chain == 'disable') {
|
||||||
continue; //user disabled notifications
|
continue; //user disabled notifications
|
||||||
}
|
}
|
||||||
@ -399,7 +399,7 @@ final class notifications {
|
|||||||
$backend_errors[] = $backend.' will be skipped (as defined by calling application)';
|
$backend_errors[] = $backend.' will be skipped (as defined by calling application)';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification_backend = self::_appname.'_'.$backend;
|
$notification_backend = self::_appname.'_'.$backend;
|
||||||
if(!file_exists(EGW_INCLUDE_ROOT. SEP. self::_appname. SEP. 'inc'. SEP. 'class.'. $notification_backend. '.inc.php')) {
|
if(!file_exists(EGW_INCLUDE_ROOT. SEP. self::_appname. SEP. 'inc'. SEP. 'class.'. $notification_backend. '.inc.php')) {
|
||||||
throw new Exception('file for '.$notification_backend. ' does not exist');
|
throw new Exception('file for '.$notification_backend. ' does not exist');
|
||||||
@ -409,7 +409,7 @@ final class notifications {
|
|||||||
unset ( $obj );
|
unset ( $obj );
|
||||||
throw new Exception($notification_backend. ' is no implementation of notifications_iface');
|
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);
|
$obj->send($this->prepend_message($messages, $prepend_message), $this->subject, $this->links, $this->attachments);
|
||||||
}
|
}
|
||||||
catch (Exception $exception) {
|
catch (Exception $exception) {
|
||||||
@ -422,7 +422,7 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
// backend sucseeded
|
// backend sucseeded
|
||||||
$user_notified = true;
|
$user_notified = true;
|
||||||
if($action == 'stop' || $action == 'fail') { break; } // stop running through chain
|
if($action == 'stop' || $action == 'fail') { break; } // stop running through chain
|
||||||
}
|
}
|
||||||
// check if the user has been notified at all
|
// check if the user has been notified at all
|
||||||
/*if(!$user_notified) {
|
/*if(!$user_notified) {
|
||||||
@ -438,7 +438,7 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates an array with the message as plaintext and html
|
* creates an array with the message as plaintext and html
|
||||||
*
|
*
|
||||||
@ -449,23 +449,23 @@ final class notifications {
|
|||||||
private function create_messages($_message_plain = '', $_message_html = '') {
|
private function create_messages($_message_plain = '', $_message_html = '') {
|
||||||
if(empty($_message_plain) && empty($_message_html)) { return false; } // no message set
|
if(empty($_message_plain) && empty($_message_html)) { return false; } // no message set
|
||||||
$messages = array();
|
$messages = array();
|
||||||
|
|
||||||
// create the messages
|
// create the messages
|
||||||
if(!empty($_message_plain)) {
|
if(!empty($_message_plain)) {
|
||||||
$messages['plain'] = $_message_plain;
|
$messages['plain'] = $_message_plain;
|
||||||
} else {
|
} else {
|
||||||
$messages['plain'] = strip_tags($_message_html);
|
$messages['plain'] = strip_tags($_message_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($_message_html)) {
|
if(!empty($_message_html)) {
|
||||||
$messages['html'] = $_message_html;
|
$messages['html'] = $_message_html;
|
||||||
} else {
|
} else {
|
||||||
$messages['html'] = nl2br($_message_plain);
|
$messages['html'] = nl2br($_message_plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepends another message to the messages array
|
* prepends another message to the messages array
|
||||||
*
|
*
|
||||||
@ -489,10 +489,10 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $_messages;
|
return $_messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns specified part from a given mailaddress
|
* returns specified part from a given mailaddress
|
||||||
*
|
*
|
||||||
@ -501,8 +501,7 @@ final class notifications {
|
|||||||
* @return string chosen part of the address
|
* @return string chosen part of the address
|
||||||
*/
|
*/
|
||||||
private function get_addresspart($_address, $_part='email') {
|
private function get_addresspart($_address, $_part='email') {
|
||||||
if(strpos($_address,'<')) { // _address contains a fullname part
|
if(strpos($_address,'<') && preg_match('/^(.*)\S?\<(.*)\>/',$_address, $parts)) { // _address contains a fullname part
|
||||||
ereg('^(.*)[:space:]{0,1}<(.*)>',$_address, $parts);
|
|
||||||
$fullname = trim(trim($parts[1]),'\"');
|
$fullname = trim(trim($parts[1]),'\"');
|
||||||
$email = $parts[2];
|
$email = $parts[2];
|
||||||
} else {
|
} else {
|
||||||
@ -512,7 +511,7 @@ final class notifications {
|
|||||||
switch($_part) {
|
switch($_part) {
|
||||||
case 'fullname':
|
case 'fullname':
|
||||||
return $fullname;
|
return $fullname;
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case 'email':
|
||||||
default:
|
default:
|
||||||
return $email;
|
return $email;
|
||||||
@ -520,7 +519,7 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns notification chains based on admin prefs
|
* returns notification chains based on admin prefs
|
||||||
* @abstract the available chains can be retrieved in two different output formats:
|
* @abstract the available chains can be retrieved in two different output formats:
|
||||||
@ -544,7 +543,7 @@ final class notifications {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$enabled_chains = array();
|
$enabled_chains = array();
|
||||||
$disabled_chains = array();
|
$disabled_chains = array();
|
||||||
foreach($this->notification_chains as $key => $chain) {
|
foreach($this->notification_chains as $key => $chain) {
|
||||||
@ -562,7 +561,7 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// common chain
|
// common chain
|
||||||
$common_chains = array();
|
$common_chains = array();
|
||||||
$common_chains['disable'] = 'disable';
|
$common_chains['disable'] = 'disable';
|
||||||
@ -572,12 +571,12 @@ final class notifications {
|
|||||||
$backend_count = 1;
|
$backend_count = 1;
|
||||||
foreach($enabled_backends as $backend => $enabled) {
|
foreach($enabled_backends as $backend => $enabled) {
|
||||||
if($enabled) {
|
if($enabled) {
|
||||||
$chain_all[$backend] = count($enabled_backends) == $backend_count ? 'stop' : 'continue';
|
$chain_all[$backend] = count($enabled_backends) == $backend_count ? 'stop' : 'continue';
|
||||||
}
|
}
|
||||||
$backend_count++;
|
$backend_count++;
|
||||||
}
|
}
|
||||||
$common_chains['all'] = $chain_all;
|
$common_chains['all'] = $chain_all;
|
||||||
|
|
||||||
switch($_output) {
|
switch($_output) {
|
||||||
case 'human':
|
case 'human':
|
||||||
$chain_groups = array(
|
$chain_groups = array(
|
||||||
@ -606,13 +605,13 @@ final class notifications {
|
|||||||
}
|
}
|
||||||
return $chains_final;
|
return $chains_final;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'routing':
|
case 'routing':
|
||||||
default:
|
default:
|
||||||
return array_merge($common_chains, $enabled_chains);
|
return array_merge($common_chains, $enabled_chains);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user