diff --git a/phpBB/includes/acp/acp_email.php b/phpBB/includes/acp/acp_email.php index 9d8657a294..446067c2a8 100644 --- a/phpBB/includes/acp/acp_email.php +++ b/phpBB/includes/acp/acp_email.php @@ -11,6 +11,8 @@ * */ +use phpbb\messenger\method\messenger_interface; + /** * @ignore */ @@ -156,9 +158,9 @@ class acp_email foreach ($rows as $row) { - if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) || - ($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) || - ($row['user_notify_type'] == NOTIFY_BOTH && ($row['user_email'] || $row['user_jabber']))) + if (($row['user_notify_type'] == messenger_interface::NOTIFY_EMAIL && $row['user_email']) || + ($row['user_notify_type'] == messenger_interface::NOTIFY_IM && $row['user_jabber']) || + ($row['user_notify_type'] == messenger_interface::NOTIFY_BOTH && ($row['user_email'] || $row['user_jabber']))) { if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type) { @@ -228,14 +230,14 @@ class acp_email foreach ($messenger_collection_iterator as $messenger_method) { $notify_method = $messenger_method->get_id(); - if ($notify_method == $used_method || $used_method == NOTIFY_BOTH) + if ($notify_method == $used_method || $used_method == messenger_interface::NOTIFY_BOTH) { $messenger_method->set_use_queue($use_queue); $messenger_method->template($email_template, $used_lang); $messenger_method->subject(html_entity_decode($subject, ENT_COMPAT)); $messenger_method->assign_vars($template_data); - if ($notify_method == NOTIFY_EMAIL) + if ($notify_method == messenger_interface::NOTIFY_EMAIL) { for ($j = 0, $list_size = count($email_list[$i]); $j < $list_size; $j++) { @@ -243,7 +245,6 @@ class acp_email if (count($email_list[$i]) == 1) { $messenger_method->to($email_row['email'], $email_row['name']); - } else { @@ -254,7 +255,7 @@ class acp_email $messenger_method->anti_abuse_headers($config, $user); $messenger_method->set_mail_priority($priority); } - else if ($notify_method == NOTIFY_IM) + else if ($notify_method == messenger_interface::NOTIFY_IM) { for ($j = 0, $list_size = count($email_list[$i]); $j < $list_size; $j++) { diff --git a/phpBB/includes/acp/acp_inactive.php b/phpBB/includes/acp/acp_inactive.php index fa9ad8fa52..ec74d59169 100644 --- a/phpBB/includes/acp/acp_inactive.php +++ b/phpBB/includes/acp/acp_inactive.php @@ -207,7 +207,7 @@ class acp_inactive { foreach ($messenger_collection_iterator as $messenger_method) { - if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == NOTIFY_BOTH) + if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == $messenger_method::NOTIFY_BOTH) { $messenger_method->template('user_remind_inactive', $row['user_lang']); $messenger_method->set_addresses($row); diff --git a/phpBB/includes/acp/acp_jabber.php b/phpBB/includes/acp/acp_jabber.php index 07f5dadbff..c952275daa 100644 --- a/phpBB/includes/acp/acp_jabber.php +++ b/phpBB/includes/acp/acp_jabber.php @@ -30,15 +30,10 @@ class acp_jabber function main($id, $mode) { global $db, $user, $template, $phpbb_log, $request; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_container, $phpbb_root_path, $phpEx; $user->add_lang('acp/board'); - if (!class_exists('jabber')) - { - include($phpbb_root_path . 'includes/functions_jabber.' . $phpEx); - } - $submit = (isset($_POST['submit'])) ? true : false; if ($mode != 'settings') @@ -73,11 +68,11 @@ class acp_jabber $message = $user->lang['JAB_SETTINGS_CHANGED']; $log = 'JAB_SETTINGS_CHANGED'; - // Is this feature enabled? Then try to establish a connection - if ($jab_enable) - { - $jabber = new jabber($jab_host, $jab_port, $jab_username, $jab_password, $jab_use_ssl, $jab_verify_peer, $jab_verify_peer_name, $jab_allow_self_signed); + $jabber = $phpbb_container->get('messenger.method.jabber'); + // Is this feature enabled? Then try to establish a connection + if ($jabber->is_enabled()) + { if (!$jabber->connect()) { trigger_error($user->lang['ERR_JAB_CONNECT'] . '

' . $jabber->get_log() . adm_back_link($this->u_action), E_USER_WARNING); @@ -97,12 +92,12 @@ class acp_jabber // We update the user table to be sure all users that have IM as notify type are set to both as notify type // We set this to both because users still have their jabber address entered and may want to receive jabber notifications again once it is re-enabled. $sql_ary = array( - 'user_notify_type' => NOTIFY_BOTH, + 'user_notify_type' => $jabber::NOTIFY_BOTH, ); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_notify_type = ' . NOTIFY_IM; + WHERE user_notify_type = ' . $jabber::NOTIFY_IM; $db->sql_query($sql); } @@ -137,7 +132,7 @@ class acp_jabber 'JAB_VERIFY_PEER' => $jab_verify_peer, 'JAB_VERIFY_PEER_NAME' => $jab_verify_peer_name, 'JAB_ALLOW_SELF_SIGNED' => $jab_allow_self_signed, - 'S_CAN_USE_SSL' => jabber::can_use_ssl(), + 'S_CAN_USE_SSL' => $jabber::can_use_ssl(), 'S_GTALK_NOTE' => (!@function_exists('dns_get_record')) ? true : false, )); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index d88d050387..a954ec09f0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -16,6 +16,7 @@ */ use phpbb\controller\helper; +use phpbb\messenger\method\messenger_interface; if (!defined('IN_PHPBB')) { @@ -1792,9 +1793,9 @@ class acp_users 'MASS_EMAIL' => $data['massemail'], 'ALLOW_PM' => $data['allowpm'], 'HIDE_ONLINE' => $data['hideonline'], - 'NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, - 'NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false, - 'NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, + 'NOTIFY_EMAIL' => ($data['notifymethod'] == messenger_interface::NOTIFY_EMAIL) ? true : false, + 'NOTIFY_IM' => ($data['notifymethod'] == messenger_interface::NOTIFY_IM) ? true : false, + 'NOTIFY_BOTH' => ($data['notifymethod'] == messenger_interface::NOTIFY_BOTH) ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 825a328d39..e9890d27e1 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -120,8 +120,11 @@ define('POST_ANNOUNCE', 2); define('POST_GLOBAL', 3); // Notify methods +/** @deprecated 4.0.0-a1 Replaced by \phpbb\messenger\method\messenger_interface::NOTIFY_EMAIL, to be removed in 5.0.0-a1 */ define('NOTIFY_EMAIL', 0); +/** @deprecated 4.0.0-a1 Replaced by \phpbb\messenger\method\messenger_interface::NOTIFY_IM, to be removed in 5.0.0-a1 */ define('NOTIFY_IM', 1); +/** @deprecated 4.0.0-a1 Replaced by \phpbb\messenger\method\messenger_interface::NOTIFY_BOTH, to be removed in 5.0.0-a1 */ define('NOTIFY_BOTH', 2); // Notify status diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index bb1b63f177..7441b74413 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -11,6 +11,8 @@ * */ +use phpbb\messenger\method\messenger_interface; + /** * @ignore */ @@ -244,7 +246,7 @@ function user_add($user_row, $cp_data = false, $notifications_data = null) 'user_notify' => 0, 'user_notify_pm' => 1, - 'user_notify_type' => NOTIFY_EMAIL, + 'user_notify_type' => messenger_interface::NOTIFY_EMAIL, 'user_allow_pm' => 1, 'user_allow_viewonline' => 1, 'user_allow_viewemail' => 1, diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index dcb2801fff..c9dd3e553e 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -135,7 +135,7 @@ class ucp_activate $messenger_collection_iterator = $messenger->getIterator(); foreach ($messenger_collection_iterator as $messenger_method) { - if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == NOTIFY_BOTH) + if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == $messenger_method::NOTIFY_BOTH) { $messenger_method->set_use_queue(false); $messenger_method->template('admin_welcome_activated', $user_row['user_lang']); diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 8c682cebc0..d08a81b854 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -11,6 +11,8 @@ * */ +use phpbb\messenger\method\messenger_interface; + /** * @ignore */ @@ -52,10 +54,10 @@ class ucp_prefs 'allowpm' => $request->variable('allowpm', (bool) $user->data['user_allow_pm']), ); - if ($data['notifymethod'] == NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml'))) + if ($data['notifymethod'] == messenger_interface::NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml'))) { // Jabber isnt enabled, or no jabber field filled in. Update the users table to be sure its correct. - $data['notifymethod'] = NOTIFY_BOTH; + $data['notifymethod'] = messenger_interface::NOTIFY_BOTH; } /** @@ -182,9 +184,9 @@ class ucp_prefs $template->assign_vars([ 'ERROR' => (count($error)) ? implode('
', $error) : '', - 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, - 'S_NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false, - 'S_NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, + 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == messenger_interface::NOTIFY_EMAIL) ? true : false, + 'S_NOTIFY_IM' => ($data['notifymethod'] == messenger_interface::NOTIFY_IM) ? true : false, + 'S_NOTIFY_BOTH' => ($data['notifymethod'] == messenger_interface::NOTIFY_BOTH) ? true : false, 'S_VIEW_EMAIL' => $data['viewemail'], 'S_MASS_EMAIL' => $data['massemail'], 'S_ALLOW_PM' => $data['allowpm'], diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 0b34598e14..52b007a1fe 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -11,6 +11,8 @@ * */ +use phpbb\messenger\method\messenger_interface; + /** * @ignore */ @@ -363,11 +365,11 @@ class ucp_profile { $data['notify'] = $user->data['user_notify_type']; - if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))) + if ($data['notify'] == messenger_interface::NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))) { // User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled) // Disable notify by Jabber now for this user. - $data['notify'] = NOTIFY_EMAIL; + $data['notify'] = messenger_interface::NOTIFY_EMAIL; } $sql_ary = array( diff --git a/phpBB/includes/ucp/ucp_resend.php b/phpBB/includes/ucp/ucp_resend.php index 278c086a8b..4c9c1a86c6 100644 --- a/phpBB/includes/ucp/ucp_resend.php +++ b/phpBB/includes/ucp/ucp_resend.php @@ -139,7 +139,7 @@ class ucp_resend foreach ($messenger_collection_iterator as $messenger_method) { $messenger_method->set_use_queue(false); - if ($messenger_method->get_id() == $row['user_notify_type'] || $row['user_notify_type'] == NOTIFY_BOTH) + if ($messenger_method->get_id() == $row['user_notify_type'] || $row['user_notify_type'] == $messenger_method::NOTIFY_BOTH) { $messenger_method->template('admin_activate', $row['user_lang']); $messenger_method->set_addresses($row); diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index 864e6f3b6e..8750c24dcc 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -11,6 +11,8 @@ * */ +use phpbb\messenger\method\messenger_interface; + /** * NOTE to potential convertor authors. Please use this file to get * familiar with the structure since we added some bare explanations here. @@ -936,7 +938,7 @@ if (!$get_info) array('user_emailtime', 'users.user_emailtime', 'null_to_zero'), array('user_notify', 'users.user_notify', 'intval'), array('user_notify_pm', 'users.user_notify_pm', 'intval'), - array('user_notify_type', NOTIFY_EMAIL, ''), + array('user_notify_type', $messenger_method::NOTIFY_EMAIL, ''), array('user_allow_pm', 'users.user_allow_pm', 'intval'), array('user_allow_viewonline', 'users.user_allow_viewonline', 'intval'), array('user_allow_viewemail', 'users.user_viewemail', 'intval'), diff --git a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php index 7c03eef347..7f58076a8d 100644 --- a/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php +++ b/phpBB/phpbb/db/migration/data/v310/notification_options_reconvert.php @@ -13,6 +13,8 @@ namespace phpbb\db\migration\data\v310; +use phpbb\messenger\method\messenger_interface; + class notification_options_reconvert extends \phpbb\db\migration\migration { public static function depends_on() @@ -67,12 +69,12 @@ class notification_options_reconvert extends \phpbb\db\migration\migration // In-board notification $notification_methods[] = ''; - if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) + if ($row['user_notify_type'] == messenger_interface::NOTIFY_EMAIL || $row['user_notify_type'] == messenger_interface::NOTIFY_BOTH) { $notification_methods[] = 'email'; } - if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) + if ($row['user_notify_type'] == messenger_interface::NOTIFY_IM || $row['user_notify_type'] == messenger_interface::NOTIFY_BOTH) { $notification_methods[] = 'jabber'; } diff --git a/phpBB/phpbb/message/admin_form.php b/phpBB/phpbb/message/admin_form.php index 2c3305dc03..72beaa38a6 100644 --- a/phpBB/phpbb/message/admin_form.php +++ b/phpBB/phpbb/message/admin_form.php @@ -13,6 +13,8 @@ namespace phpbb\message; +use phpbb\messenger\method\messenger_interface; + /** * Class admin_form * Displays a message to the user and allows him to send an email @@ -155,7 +157,7 @@ class admin_form extends form } $this->message->set_sender($this->user->ip, $this->sender_name, $this->sender_address, $this->user->lang_name); - $this->message->set_sender_notify_type(NOTIFY_EMAIL); + $this->message->set_sender_notify_type(messenger_interface::NOTIFY_EMAIL); } $this->message->set_template('contact_admin'); @@ -165,7 +167,7 @@ class admin_form extends form $this->user->lang['ADMINISTRATOR'], $this->config['board_contact'], $this->config['default_lang'], - NOTIFY_EMAIL + messenger_interface::NOTIFY_EMAIL ); $this->message->set_template_vars(array( diff --git a/phpBB/phpbb/message/message.php b/phpBB/phpbb/message/message.php index 34295d1a02..90b8a1ff5f 100644 --- a/phpBB/phpbb/message/message.php +++ b/phpBB/phpbb/message/message.php @@ -13,6 +13,8 @@ namespace phpbb\message; +use phpbb\messenger\method\messenger_interface; + /** * Class message * Holds all information for an email and sends it in the end @@ -46,7 +48,7 @@ class message /** @var string */ protected $sender_jabber = ''; /** @var int */ - protected $sender_notify_type = NOTIFY_EMAIL; + protected $sender_notify_type = messenger_interface::NOTIFY_EMAIL; /** @var array */ protected $recipients; @@ -134,7 +136,7 @@ class message * @param string $recipient_jabber * @return void */ - public function add_recipient($recipient_name, $recipient_address, $recipient_lang, $recipient_notify_type = NOTIFY_EMAIL, $recipient_username = '', $recipient_jabber = '') + public function add_recipient($recipient_name, $recipient_address, $recipient_lang, $recipient_notify_type = messenger_interface::NOTIFY_EMAIL, $recipient_username = '', $recipient_jabber = '') { $this->recipients[] = array( 'name' => $recipient_name, @@ -250,7 +252,7 @@ class message foreach ($messenger_collection_iterator as $messenger_method) { $messenger_method->set_use_queue(false); - if ($messenger_method->get_id() == $recipient['notify_type'] || $recipient['notify_type'] == NOTIFY_BOTH) + if ($messenger_method->get_id() == $recipient['notify_type'] || $recipient['notify_type'] == $messenger_method::NOTIFY_BOTH) { $messenger_method->template($this->template, $recipient['lang']); $messenger_method->set_addresses($recipient); diff --git a/phpBB/phpbb/message/topic_form.php b/phpBB/phpbb/message/topic_form.php index facde9a462..dd73a67ab2 100644 --- a/phpBB/phpbb/message/topic_form.php +++ b/phpBB/phpbb/message/topic_form.php @@ -13,6 +13,8 @@ namespace phpbb\message; +use phpbb\messenger\method\messenger_interface; + /** * Class topic_form * Form used to send topics as notification emails @@ -130,9 +132,9 @@ class topic_form extends form $this->recipient_name, $this->recipient_address, $this->recipient_lang, - NOTIFY_EMAIL + messenger_interface::NOTIFY_EMAIL ); - $this->message->set_sender_notify_type(NOTIFY_EMAIL); + $this->message->set_sender_notify_type(messenger_interface::NOTIFY_EMAIL); parent::submit($messenger); } diff --git a/phpBB/phpbb/messenger/method/email.php b/phpBB/phpbb/messenger/method/email.php index a8927c23e3..1bad23760c 100644 --- a/phpBB/phpbb/messenger/method/email.php +++ b/phpBB/phpbb/messenger/method/email.php @@ -75,7 +75,7 @@ class email extends base */ public function get_id(): int { - return NOTIFY_EMAIL; + return self::NOTIFY_EMAIL; } /** diff --git a/phpBB/phpbb/messenger/method/jabber.php b/phpBB/phpbb/messenger/method/jabber.php index b4fab79574..a4a2c07f61 100644 --- a/phpBB/phpbb/messenger/method/jabber.php +++ b/phpBB/phpbb/messenger/method/jabber.php @@ -115,7 +115,7 @@ class jabber extends base */ public function get_id(): int { - return NOTIFY_IM; + return self::NOTIFY_IM; } /** diff --git a/phpBB/phpbb/messenger/method/messenger_interface.php b/phpBB/phpbb/messenger/method/messenger_interface.php index 980cd06a22..b733f3d3d4 100644 --- a/phpBB/phpbb/messenger/method/messenger_interface.php +++ b/phpBB/phpbb/messenger/method/messenger_interface.php @@ -18,6 +18,15 @@ namespace phpbb\messenger\method; */ interface messenger_interface { + /** @var int Email notify method used */ + public const NOTIFY_EMAIL = 0; + + /** @var int Instant messaging (Jabber) notify method used */ + public const NOTIFY_IM = 1; + + /** @var int Both notify methods used */ + public const NOTIFY_BOTH = 2; + /** * Get messenger method id * diff --git a/phpBB/phpbb/notification/method/email.php b/phpBB/phpbb/notification/method/email.php index 2c612367cc..8a2fff1bb9 100644 --- a/phpBB/phpbb/notification/method/email.php +++ b/phpBB/phpbb/notification/method/email.php @@ -19,6 +19,7 @@ use phpbb\user_loader; use phpbb\config\config; use phpbb\db\driver\driver_interface; use phpbb\di\service_collection; +use phpbb\messenger\method\messenger_interface; /** * Email notification method class @@ -135,7 +136,7 @@ class email extends \phpbb\notification\method\messenger_base $insert_buffer->flush(); - $this->notify_using_messenger(NOTIFY_EMAIL); + $this->notify_using_messenger(messenger_interface::NOTIFY_EMAIL); } /** diff --git a/phpBB/phpbb/notification/method/jabber.php b/phpBB/phpbb/notification/method/jabber.php index 4a0e52fc62..e3482f98be 100644 --- a/phpBB/phpbb/notification/method/jabber.php +++ b/phpBB/phpbb/notification/method/jabber.php @@ -18,6 +18,7 @@ use phpbb\user; use phpbb\user_loader; use phpbb\config\config; use phpbb\di\service_collection; +use phpbb\messenger\method\messenger_interface; /** * Jabber notification method class @@ -98,6 +99,6 @@ class jabber extends \phpbb\notification\method\messenger_base return; } - $this->notify_using_messenger(NOTIFY_IM, 'short/'); + $this->notify_using_messenger(messenger_interface::NOTIFY_IM, 'short/'); } } diff --git a/phpBB/phpbb/notification/method/messenger_base.php b/phpBB/phpbb/notification/method/messenger_base.php index 4aaf01c133..ca93f4c8a2 100644 --- a/phpBB/phpbb/notification/method/messenger_base.php +++ b/phpBB/phpbb/notification/method/messenger_base.php @@ -67,7 +67,7 @@ abstract class messenger_base extends \phpbb\notification\method\base /** * Notify using phpBB messenger * - * @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM) + * @param int $notify_method Notify method for messenger (e.g. \phpbb\messenger\method\messenger_interface::NOTIFY_IM) * @param string $template_dir_prefix Base directory to prepend to the email template name * * @return void @@ -115,7 +115,7 @@ abstract class messenger_base extends \phpbb\notification\method\base $messenger_collection_iterator = $this->messenger->getIterator(); foreach ($messenger_collection_iterator as $messenger_method) { - if ($messenger_method->get_id() == $notify_method || $notify_method == NOTIFY_BOTH) + if ($messenger_method->get_id() == $notify_method || $notify_method == $messenger_method::NOTIFY_BOTH) { $messenger_method->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix); $messenger_method->set_addresses($user);