From c08849570815d7c22fb94d0c28c92ab1a26f9809 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 6 May 2016 09:19:36 +0000 Subject: [PATCH] use new API for notifiations --- notifications/download.php | 14 ++++--- notifications/inc/class.notifications.inc.php | 35 +++++++++--------- .../inc/class.notifications_ajax.inc.php | 20 +++++----- .../inc/class.notifications_email.inc.php | 12 +++--- .../inc/class.notifications_iface.inc.php | 6 +-- .../class.notifications_jdesk_ajax.inc.php | 22 +++++------ .../inc/class.notifications_jpopup.inc.php | 13 ++++--- .../inc/class.notifications_popup.inc.php | 37 ++++++++++--------- .../inc/class.notifications_push.inc.php | 7 ++-- .../inc/class.notifications_winpopup.inc.php | 10 ++++- notifications/inc/hook_admin.inc.php | 4 +- notifications/inc/hook_after_navbar.inc.php | 11 ++++-- notifications/setup/etemplates.inc.php | 16 -------- notifications/setup/setup.inc.php | 11 ++---- notifications/setup/tables_update.inc.php | 4 ++ 15 files changed, 112 insertions(+), 110 deletions(-) delete mode 100644 notifications/setup/etemplates.inc.php diff --git a/notifications/download.php b/notifications/download.php index 5ef2c346fd..eaf907a144 100644 --- a/notifications/download.php +++ b/notifications/download.php @@ -10,6 +10,8 @@ * @version $Id$ */ +use EGroupware\Api; + $GLOBALS['egw_info'] = array( 'flags' => array( 'currentapp' => 'notifications', @@ -31,8 +33,8 @@ $ret=copy($document, $archive); error_log("copy('$document', '$archive' returned ".array2string($ret)); $document = 'zip://'.$archive.'#'.($config_file = 'lib/conf/egwnotifier.const.xml'); -$xml = file_get_contents($document); -//html::content_header('egwnotifier.const.xml', 'application/xml', bytes($xml)); echo $xml; exit; +$xml_in = file_get_contents($document); +//Api\Header\Content::type('egwnotifier.const.xml', 'application/xml', bytes($xml_in)); echo $xml_in; exit; function replace_callback($matches) { @@ -90,11 +92,11 @@ function replace_callback($matches) $htmlscflags = 16; // #define ENT_XML1 16 } - return '<'.$matches[1].'>'.htmlspecialchars($replacement, $htmlscflags, translation::charset()).''; + return '<'.$matches[1].'>'.htmlspecialchars($replacement, $htmlscflags, Api\Translation::charset()).''; } -$xml = preg_replace_callback('/<((egw_|MI_)[^>]+)>(.*)<\/[a-z0-9_-]+>/iU', 'replace_callback', $xml); -//html::content_header('egwnotifier.replace.xml', 'application/xml', bytes($xml)); echo $xml; exit; +$xml = preg_replace_callback('/<((egw_|MI_)[^>]+)>(.*)<\/[a-z0-9_-]+>/iU', 'replace_callback', $xml_in); +//Api\Header\Content::type('egwnotifier.const.xml', 'application/xml', bytes($xml)); echo $xml; exit; /* does NOT work, fails in addFromString :-( $zip = new ZipArchive; @@ -115,7 +117,7 @@ unset($zip); clearstatcache(); ob_end_clean(); -html::content_header('egroupware-notifier-'.$GLOBALS['egw_info']['user']['account_lid'].'.jar', 'application/x-java-archive', filesize($archive)); +Api\Header\Content::type('egroupware-notifier-'.$GLOBALS['egw_info']['user']['account_lid'].'.jar', 'application/x-java-archive', filesize($archive)); readfile($archive,'rb'); @unlink($archive); diff --git a/notifications/inc/class.notifications.inc.php b/notifications/inc/class.notifications.inc.php index ef675aa208..b2fc37a555 100644 --- a/notifications/inc/class.notifications.inc.php +++ b/notifications/inc/class.notifications.inc.php @@ -9,7 +9,7 @@ * @version $Id$ */ -if (!defined('SEP')) define('SEP','/'); +use EGroupware\Api; /** * Notifies users according to their preferences. @@ -179,13 +179,13 @@ final class notifications { * */ public function __construct() { - $this->config = (object) config::read(self::_appname); + $this->config = (object) Api\Config::read(self::_appname); } /** * Return notification errors * - * @param boolean $reset=false true: reset all errors + * @param boolean $reset =false true: reset all errors * @return array */ public static function errors($reset=false) @@ -480,9 +480,9 @@ final class notifications { $ids[] = $receiver->account_id; if ($GLOBALS['egw']->acl->get_specific_rights_for_account($ids,'run','notifications')) { // read the users notification chain - $prefs = new preferences($receiver->account_id); - $preferences = $prefs->read(); - $preferences = (object)$preferences[self::_appname]; + $prefs = new Api\Preferences($receiver->account_id); + $preferences_all = $prefs->read(); + $preferences = (object)$preferences_all[self::_appname]; if($preferences->notification_chain) { // fallback: admin disabled user-chosen chain if(!$notification_chain = $available_chains[$preferences->notification_chain]) { @@ -508,6 +508,7 @@ final class notifications { } foreach($notification_chain as $backend => $action) { + $notification_backend = null; try { // check if backend should be skipped if( in_array($backend, $this->skip_backends) ) { @@ -517,7 +518,7 @@ final class notifications { } $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.'/'. self::_appname.'/inc/class.'. $notification_backend. '.inc.php')) { throw new Exception('file for '.$notification_backend. ' does not exist'); } $obj = new $notification_backend( $this->sender, $receiver, $this->config, $preferences ); @@ -581,7 +582,7 @@ final class notifications { if(!empty($_message_plain)) { $messages['plain'] = $_message_plain; } else { - $messages['plain'] = translation::convertHTMLToText($_message_html, false, true); + $messages['plain'] = Api\Mail\Html::convertHTMLToText($_message_html, false, true); } if(!empty($_message_html)) { @@ -601,7 +602,7 @@ final class notifications { */ public static function plain2html($_plain) { - return html::activate_links(nl2br(html::htmlspecialchars($_plain, true))); + return Api\Html::activate_links(nl2br(Api\Html::htmlspecialchars($_plain, true))); } /** @@ -638,7 +639,9 @@ final class notifications { * @param string $_part * @return string chosen part of the address */ - private function get_addresspart($_address, $_part='email') { + private function get_addresspart($_address, $_part='email') + { + $parts = null; if(strpos($_address,'<') && preg_match('/^(.*)\S?\<(.*)\>/',$_address, $parts)) { // _address contains a fullname part $fullname = trim(trim($parts[1]),'\"'); $email = $parts[2]; @@ -649,11 +652,9 @@ final class notifications { switch($_part) { case 'fullname': return $fullname; - break; case 'email': default: return $email; - break; } return false; } @@ -668,9 +669,9 @@ final class notifications { * @return array containing notification chains, output like given in $_output */ public function get_available_chains($_output = 'routing') { - // determine enabled backends from config + // determine enabled backends from Api\Config $enabled_backends = array(); - foreach($this->backends as $id => $backend) { + foreach($this->backends as $backend) { switch($backend) { case 'email': case 'popup': @@ -689,7 +690,7 @@ final class notifications { foreach($this->notification_chains as $key => $chain) { $allow_chain = true; if(is_array($chain)) { - foreach($chain as $name => $action) { + foreach(array_keys($chain) as $name) { if(!$enabled_backends[$name]) { $allow_chain = false; // disable whole chain if one backend is disabled } @@ -728,7 +729,7 @@ final class notifications { // create descriptions for each chain key in each group foreach($chain_groups as $name => $arr_name) { ${$arr_name.$suffix} = array(); - foreach(${$arr_name} as $key => $value) { + foreach(array_keys(${$arr_name}) as $key) { if($arr_name == 'disabled_chains') { ${$arr_name.$suffix}[$key] = '('.lang('Disabled').') '.lang($this->chains_descriptions[$key]); } else { @@ -744,12 +745,10 @@ final class notifications { } } return $chains_final; - break; case 'routing': default: return array_merge($common_chains, $enabled_chains); - break; } return false; diff --git a/notifications/inc/class.notifications_ajax.inc.php b/notifications/inc/class.notifications_ajax.inc.php index 0bbcbdfd94..60ec50e3e6 100644 --- a/notifications/inc/class.notifications_ajax.inc.php +++ b/notifications/inc/class.notifications_ajax.inc.php @@ -10,6 +10,8 @@ * @version $Id$ */ +use EGroupware\Api; + /** * Ajax methods for notifications */ @@ -58,7 +60,7 @@ class notifications_ajax { /** * reference to global db object * - * @var egw_db + * @var Api\Db */ private $db; @@ -81,7 +83,7 @@ class notifications_ajax { /** * the xml response object * - * @var egw_json_response + * @var Api\Json\Response */ private $response; @@ -90,12 +92,12 @@ class notifications_ajax { * */ public function __construct() { - $this->response = egw_json_response::get(); + $this->response = Api\Json\Response::get(); $this->recipient = (object)$GLOBALS['egw']->accounts->read($GLOBALS['egw_info']['user']['account_id']); - $this->config = (object)config::read(self::_appname); + $this->config = (object)Api\Config::read(self::_appname); - $prefs = new preferences($this->recipient->account_id); + $prefs = new Api\Preferences($this->recipient->account_id); $this->preferences = $prefs->read(); $this->db = $GLOBALS['egw']->db; @@ -116,7 +118,7 @@ class notifications_ajax { // call a hook for notifications on new mail //if ($GLOBALS['egw_info']['user']['apps']['mail']) $this->check_mailbox(); - $GLOBALS['egw']->hooks->process('check_notify'); + Api\Hooks::process('check_notify'); // update currentusers if ($GLOBALS['egw_info']['user']['apps']['admin'] && @@ -170,11 +172,11 @@ class notifications_ajax { { $message = substr_replace($message, '', strpos($message, lang('Linked entries:'))); } - $message = preg_replace('#]*>#is','',$message); + $message2 = preg_replace('#]*>#is','',$message); - $message = 'data:text/html;charset=' . translation::charset() .';base64,'.base64_encode($message); + $message3 = 'data:text/html;charset=' . Api\Translation::charset() .';base64,'.base64_encode($message2); } - $this->response->apply('app.notifications.append',array($notification['notify_id'],$notification['notify_message'],$message)); + $this->response->apply('app.notifications.append',array($notification['notify_id'],$notification['notify_message'],$message3)); } switch($this->preferences[self::_appname]['egwpopup_verbosity']) { diff --git a/notifications/inc/class.notifications_email.inc.php b/notifications/inc/class.notifications_email.inc.php index af973b5d16..8be7dfe853 100644 --- a/notifications/inc/class.notifications_email.inc.php +++ b/notifications/inc/class.notifications_email.inc.php @@ -1,6 +1,6 @@ mail); } - $this->mail = new egw_mailer(); + $this->mail = new Api\Mailer(); } /** @@ -139,13 +141,13 @@ class notifications_email implements notifications_iface { if(is_null($_render_html)) { $_render_html = false; } if(is_null($_render_external)) { $_render_external = true; } $newline = $_render_html ? "
" : "\n"; - $hruler = $_render_html ? html::hr() : ''; + $hruler = $_render_html ? Api\Html::hr() : ''; $rendered_links = array(); foreach($_links as $link) { if($_render_external || ! $link->popup) { $link->view['no_popup'] = 1; } // do not expose sensitive data - $url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',html::link('/index.php', $link->view)); + $url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',Api\Html::link('/index.php', $link->view)); // complete missing protocol and domain part if needed if ($url{0} == '/' && $_render_external) { $url = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://'). diff --git a/notifications/inc/class.notifications_iface.inc.php b/notifications/inc/class.notifications_iface.inc.php index b65b5005ea..240cbdde1e 100644 --- a/notifications/inc/class.notifications_iface.inc.php +++ b/notifications/inc/class.notifications_iface.inc.php @@ -1,6 +1,6 @@ , Maik H�ttner */ +use EGroupware\Api; + /** * jdesk Json methods for notifications */ @@ -57,14 +59,14 @@ class notifications_jdesk_ajax { /** * reference to global db object * - * @var egw_db + * @var Api\Db */ private $db; /** * the xml response object * - * @var xajaxResponse + * @var Api\Json\Response */ private $response; @@ -74,17 +76,13 @@ class notifications_jdesk_ajax { */ public function __construct() { - if( class_exists('xajaxResponse') ) - { - $this->response = new xajaxResponse(); - } + $this->response = new Api\Json\Response(); $this->recipient = (object)$GLOBALS['egw']->accounts->read($GLOBALS['egw_info']['user']['account_id']); - $this->config = (object)config::read(self::_appname); + $this->config = (object)Api\Config::read(self::_appname); - $prefs = new preferences($this->recipient->account_id); - $preferences = $prefs->read(); + $prefs = new Api\Preferences($this->recipient->account_id); $this->preferences = $prefs->read(); $this->db = $GLOBALS['egw']->db; @@ -123,8 +121,6 @@ class notifications_jdesk_ajax { "message" => $message, "details" => $details)); */ - - return $this->response->getXML(); } /** @@ -150,7 +146,9 @@ class notifications_jdesk_ajax { * * @return boolean true or false */ - private function get_egwpopup($browserNotify = false) { + private function get_egwpopup($browserNotify = false) + { + unset($browserNotify); // not used $message = ''; diff --git a/notifications/inc/class.notifications_jpopup.inc.php b/notifications/inc/class.notifications_jpopup.inc.php index db2df018fc..d6d1ae6697 100755 --- a/notifications/inc/class.notifications_jpopup.inc.php +++ b/notifications/inc/class.notifications_jpopup.inc.php @@ -1,5 +1,4 @@ , Maik H�ttner */ +use EGroupware\Api; + class notifications_jpopup implements notifications_iface { @@ -59,7 +60,7 @@ class notifications_jpopup implements notifications_iface /** * holds db object of SQL database * - * @var egw_db + * @var Api\Db */ private $db; @@ -93,6 +94,8 @@ class notifications_jpopup implements notifications_iface */ public function send(array $_messages, $_subject=false, $_links=false, $_attachments=false) { + unset($_attachments); // not used + $jmessage = array(); // app-message @@ -119,7 +122,7 @@ class notifications_jpopup implements notifications_iface } $message = $this->render_infos($_subject) - .html::hr() + .Api\Html::hr() .$_messages['html']; $jmessage['msghtml'] = $message; @@ -133,7 +136,7 @@ class notifications_jpopup implements notifications_iface * renders additional infos from sender and subject * * @param string $_subject - * @return html rendered info as complete string + * @return string html rendered info as complete string */ private function render_infos($_subject = false) { $infos = array(); @@ -141,7 +144,7 @@ class notifications_jpopup implements notifications_iface $sender = $this->sender->account_fullname ? $this->sender->account_fullname : $this->sender_account_email; $infos[] = lang('Message from').': '.$sender; - if(!empty($_subject)) { $infos[] = html::bold($_subject); } + if(!empty($_subject)) { $infos[] = Api\Html::bold($_subject); } return implode($newline,$infos); } diff --git a/notifications/inc/class.notifications_popup.inc.php b/notifications/inc/class.notifications_popup.inc.php index b82c45a295..c785164553 100644 --- a/notifications/inc/class.notifications_popup.inc.php +++ b/notifications/inc/class.notifications_popup.inc.php @@ -10,6 +10,8 @@ * @version $Id$ */ +use EGroupware\Api; + /** * Instant user notification with egroupware popup. * @@ -67,7 +69,7 @@ class notifications_popup implements notifications_iface { /** * holds db object of SQL database * - * @var egw_db + * @var Api\Db */ private $db; @@ -98,15 +100,17 @@ class notifications_popup implements notifications_iface { * @param array $_links * @param array $_attachments */ - public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) { + public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) + { + unset($_attachments); // not used // Check access log to see if user is still logged in - if ( !egw_session::notifications_active($this->recipient->account_id) ) + if ( !Api\Session::notifications_active($this->recipient->account_id) ) { throw new Exception("User {$this->recipient->account_lid} isn't online. Can't send notification via popup"); } $message = $this->render_infos($_subject) - .html::hr() + .Api\Html::hr() .(isset($_messages['popup'])&&!empty($_messages['popup'])?$_messages['popup']:$_messages['html']) .$this->render_links($_links); @@ -133,7 +137,7 @@ class notifications_popup implements notifications_iface { * should be moved to the ajax class later - like mentioned in the Todo * * @param array $_links - * @return html rendered link(s) as complete string with jspopup or a new window + * @return string html rendered link(s) as complete string with jspopup or a new window */ private function render_links($_links = false) { if(!is_array($_links) || count($_links) == 0) { return false; } @@ -143,20 +147,19 @@ class notifications_popup implements notifications_iface { foreach($_links as $link) { if(!$link->popup) { $link->view['no_popup'] = 1; } - $url = html::link('/index.php', $link->view); // do not expose sensitive data - $url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$url); + $url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','', + Api\Html::link('/index.php', $link->view)); // extract application-icon from menuaction if($link->view['menuaction']) { $menuaction_arr = explode('.',$link->view['menuaction']); $application = $menuaction_arr[0]; - $image = $application ? html::image($application,'navbar',$link->text,'align="middle" style="width: 24px; margin-right: 0.5em;"') : ''; + $image = $application ? Api\Html::image($application,'navbar',$link->text,'align="middle" style="width: 24px; margin-right: 0.5em;"') : ''; } else { $image = ''; } if($link->popup && !$GLOBALS['egw_info']['user']['preferences']['notifications']['external_mailclient']) { - $dimensions = explode('x', $link->popup); $data = array( "data-app = '{$link->app}'", "data-id = '{$link->id}'", @@ -164,14 +167,14 @@ class notifications_popup implements notifications_iface { "data-popup = '{$link->popup}'" ); - $rendered_links[] = html::div($image.$link->text,implode(' ',$data),'link'); + $rendered_links[] = Api\Html::div($image.$link->text,implode(' ',$data),'link'); } else { - $rendered_links[] = html::div(''.$image.$link->text.'','','link'); + $rendered_links[] = Api\Html::div(''.$image.$link->text.'','','link'); } } if(count($rendered_links) > 0) { - return html::hr().html::bold(lang('Linked entries:')).$newline.implode($newline,$rendered_links); + return Api\Html::hr().Api\Html::bold(lang('Linked entries:')).$newline.implode($newline,$rendered_links); } } @@ -179,9 +182,9 @@ class notifications_popup implements notifications_iface { * returns javascript to open a popup window: window.open(...) * * @param string $link link or this.href - * @param string $target='_blank' name of target or this.target - * @param int $width=750 width of the window - * @param int $height=400 height of the window + * @param string $target ='_blank' name of target or this.target + * @param int $width =750 width of the window + * @param int $height =400 height of the window * @return string javascript (using single quotes) */ private function jspopup($link,$target='_blank',$width=750,$height=410) @@ -202,7 +205,7 @@ class notifications_popup implements notifications_iface { * renders additional infos from sender and subject * * @param string $_subject - * @return html rendered info as complete string + * @return string html rendered info as complete string */ private function render_infos($_subject = false) { $infos = array(); @@ -210,7 +213,7 @@ class notifications_popup implements notifications_iface { $sender = $this->sender->account_fullname ? $this->sender->account_fullname : $this->sender_account_email; $infos[] = lang('Message from').': '.$sender; - if(!empty($_subject)) { $infos[] = html::bold($_subject); } + if(!empty($_subject)) { $infos[] = Api\Html::bold($_subject); } return implode($newline,$infos); } diff --git a/notifications/inc/class.notifications_push.inc.php b/notifications/inc/class.notifications_push.inc.php index 8964001b67..283bdb70c8 100644 --- a/notifications/inc/class.notifications_push.inc.php +++ b/notifications/inc/class.notifications_push.inc.php @@ -10,9 +10,8 @@ * @version $Id$ */ -use EGroupware\Api\Json; - use EGroupware\Api; +use EGroupware\Api\Json; /** * Class to push via notification polling and other json requests from client-side @@ -34,7 +33,7 @@ class notifications_push implements Json\PushBackend /** * Reference to global DB object * - * @var egw_db + * @var Api\Db */ public static $db; @@ -113,7 +112,7 @@ class notifications_push implements Json\PushBackend { self::$db->delete(self::TABLE, array( 'notify_type' => self::TYPE, - 'notify_created < '.self::$db->from_unixtime(egw_session::heartbeat_limit()), + 'notify_created < '.self::$db->from_unixtime(Api\Session::heartbeat_limit()), ), __LINE__, __FILE__, self::APP); } diff --git a/notifications/inc/class.notifications_winpopup.inc.php b/notifications/inc/class.notifications_winpopup.inc.php index 45b83145ca..3958d03edb 100644 --- a/notifications/inc/class.notifications_winpopup.inc.php +++ b/notifications/inc/class.notifications_winpopup.inc.php @@ -10,6 +10,8 @@ * @version $Id$ */ +use EGroupware\Api; + /** * User notification via winpopup. */ @@ -100,9 +102,12 @@ class notifications_winpopup implements notifications_iface { * @param array $_links * @param array $_attachments */ - public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) { + public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) + { + unset($_links, $_attachments); // not used + $user_sessions = array(); - foreach (egw_session::session_list(0, 'asc', 'session_dla', true) as $session) { + foreach (Api\Session::session_list(0, 'asc', 'session_dla', true) as $session) { if ($session['session_lid'] == $this->recipient->account_lid. '@'. $GLOBALS['egw_info']['user']['domain']) { if($this->valid_ip($session['session_ip'])) { $user_sessions[] = $session['session_ip']; @@ -138,6 +143,7 @@ class notifications_winpopup implements notifications_iface { '/\[SENDER\]/' => $this->sender->account_fullname ? escapeshellarg($this->sender->account_fullname) : escapeshellarg($this->sender->account_email), ); $command = preg_replace(array_keys($placeholders), $placeholders, $this->netbios_command); + $output = $returncode = null; exec($command,$output,$returncode); if($returncode != 0) { throw new Exception("Failed sending notification message via winpopup. Error while executing the specified command."); diff --git a/notifications/inc/hook_admin.inc.php b/notifications/inc/hook_admin.inc.php index 752b053899..3306b47358 100644 --- a/notifications/inc/hook_admin.inc.php +++ b/notifications/inc/hook_admin.inc.php @@ -9,7 +9,9 @@ * @version $Id: hook_preferences.inc.php 22498 2006-09-25 10:20:46Z jaytraxx $ */ -$file = Array( 'Site Configuration' => egw::link('/index.php', array( +use EGroupware\Api\Egw; + +$file = Array( 'Site Configuration' => Egw::link('/index.php', array( 'menuaction' => 'admin.admin_config.index', 'appname' => $appname, 'ajax' => 'true', diff --git a/notifications/inc/hook_after_navbar.inc.php b/notifications/inc/hook_after_navbar.inc.php index e0d6805fb3..07e18665a8 100644 --- a/notifications/inc/hook_after_navbar.inc.php +++ b/notifications/inc/hook_after_navbar.inc.php @@ -1,6 +1,7 @@ * @version $Id$ */ + +use EGroupware\Api; if ($GLOBALS['egw_info']['user']['apps']['notifications']) { - $notification_config = config::read('notifications'); - translation::add_app('notifications'); + $notification_config = Api\Config::read('notifications'); + Api\Translation::add_app('notifications'); $popup_poll_interval = empty($notification_config['popup_poll_interval']) ? 60 : $notification_config['popup_poll_interval']; echo ''; echo '