mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/17135] Refactor messenger code to services [ci skip]
PHPBB3-17135
This commit is contained in:
parent
5be1f5d5c9
commit
1f952ca6d8
6 changed files with 99 additions and 57 deletions
|
@ -458,30 +458,26 @@ class ucp_register
|
||||||
|
|
||||||
if ($config['email_enable'])
|
if ($config['email_enable'])
|
||||||
{
|
{
|
||||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||||
|
$email = $this->messenger->offsetGet('messenger.method.email');
|
||||||
$messenger = new messenger(false);
|
$email->set_use_queue(false);
|
||||||
|
$email->template($email_template, $data['lang']);
|
||||||
$messenger->template($email_template, $data['lang']);
|
$email->to($data['email'], $data['username']);
|
||||||
|
$email->anti_abuse_headers($config, $user);
|
||||||
$messenger->to($data['email'], $data['username']);
|
$email->assign_vars([
|
||||||
|
|
||||||
$messenger->anti_abuse_headers($config, $user);
|
|
||||||
|
|
||||||
$messenger->assign_vars(array(
|
|
||||||
'WELCOME_MSG' => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
|
'WELCOME_MSG' => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
|
||||||
'USERNAME' => html_entity_decode($data['username'], ENT_COMPAT),
|
'USERNAME' => html_entity_decode($data['username'], ENT_COMPAT),
|
||||||
'PASSWORD' => html_entity_decode($data['new_password'], ENT_COMPAT),
|
'PASSWORD' => html_entity_decode($data['new_password'], ENT_COMPAT),
|
||||||
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
|
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey",
|
||||||
);
|
]);
|
||||||
|
|
||||||
if ($coppa)
|
if ($coppa)
|
||||||
{
|
{
|
||||||
$messenger->assign_vars(array(
|
$email->assign_vars([
|
||||||
'FAX_INFO' => $config['coppa_fax'],
|
'FAX_INFO' => $config['coppa_fax'],
|
||||||
'MAIL_INFO' => $config['coppa_mail'],
|
'MAIL_INFO' => $config['coppa_mail'],
|
||||||
'EMAIL_ADDRESS' => $data['email'])
|
'EMAIL_ADDRESS' => $data['email'],
|
||||||
);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -510,7 +506,7 @@ class ucp_register
|
||||||
);
|
);
|
||||||
extract($phpbb_dispatcher->trigger_event('core.ucp_register_welcome_email_before', compact($vars)));
|
extract($phpbb_dispatcher->trigger_event('core.ucp_register_welcome_email_before', compact($vars)));
|
||||||
|
|
||||||
$messenger->send(NOTIFY_EMAIL);
|
$email->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
|
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ucp_resend
|
||||||
function main($id, $mode)
|
function main($id, $mode)
|
||||||
{
|
{
|
||||||
global $config, $phpbb_root_path, $phpEx;
|
global $config, $phpbb_root_path, $phpEx;
|
||||||
global $db, $user, $auth, $template, $request;
|
global $db, $user, $auth, $template, $request, $phpbb_container;
|
||||||
|
|
||||||
$username = $request->variable('username', '', true);
|
$username = $request->variable('username', '', true);
|
||||||
$email = strtolower($request->variable('email', ''));
|
$email = strtolower($request->variable('email', ''));
|
||||||
|
@ -94,32 +94,33 @@ class ucp_resend
|
||||||
|
|
||||||
$coppa = ($row['group_name'] == 'REGISTERED_COPPA' && $row['group_type'] == GROUP_SPECIAL) ? true : false;
|
$coppa = ($row['group_name'] == 'REGISTERED_COPPA' && $row['group_type'] == GROUP_SPECIAL) ? true : false;
|
||||||
|
|
||||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||||
$messenger = new messenger(false);
|
$email = $messenger->offsetGet('messenger.method.email');
|
||||||
|
$email->set_use_queue(false);
|
||||||
|
|
||||||
if ($config['require_activation'] == USER_ACTIVATION_SELF || $coppa)
|
if ($config['require_activation'] == USER_ACTIVATION_SELF || $coppa)
|
||||||
{
|
{
|
||||||
$messenger->template(($coppa) ? 'coppa_resend_inactive' : 'user_resend_inactive', $user_row['user_lang']);
|
$email->template(($coppa) ? 'coppa_resend_inactive' : 'user_resend_inactive', $user_row['user_lang']);
|
||||||
$messenger->set_addresses($user_row);
|
$email->set_addresses($user_row);
|
||||||
|
|
||||||
$messenger->anti_abuse_headers($config, $user);
|
$email->anti_abuse_headers($config, $user);
|
||||||
|
|
||||||
$messenger->assign_vars(array(
|
$email->assign_vars([
|
||||||
'WELCOME_MSG' => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
|
'WELCOME_MSG' => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
|
||||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
||||||
'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}")
|
'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
|
||||||
);
|
]);
|
||||||
|
|
||||||
if ($coppa)
|
if ($coppa)
|
||||||
{
|
{
|
||||||
$messenger->assign_vars(array(
|
$email->assign_vars([
|
||||||
'FAX_INFO' => $config['coppa_fax'],
|
'FAX_INFO' => $config['coppa_fax'],
|
||||||
'MAIL_INFO' => $config['coppa_mail'],
|
'MAIL_INFO' => $config['coppa_mail'],
|
||||||
'EMAIL_ADDRESS' => $user_row['user_email'])
|
'EMAIL_ADDRESS' => $user_row['user_email'],
|
||||||
);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$messenger->send(NOTIFY_EMAIL);
|
$email->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
|
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
|
||||||
|
@ -132,20 +133,31 @@ class ucp_resend
|
||||||
WHERE ' . $db->sql_in_set('user_id', $admin_ary[0]['a_user']);
|
WHERE ' . $db->sql_in_set('user_id', $admin_ary[0]['a_user']);
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
$messenger_collection_iterator = $messenger->getIterator();
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$messenger->template('admin_activate', $row['user_lang']);
|
while ($messenger_collection_iterator->valid())
|
||||||
$messenger->set_addresses($row);
|
{
|
||||||
|
$messenger_method = $messenger_collection_iterator->current();
|
||||||
|
$messenger_method->set_use_queue(false);
|
||||||
|
if ($messenger_method->get_id() == $row['user_notify_type'] || $row['user_notify_type'] == NOTIFY_BOTH)
|
||||||
|
{
|
||||||
|
$messenger_method->template('admin_activate', $row['user_lang']);
|
||||||
|
$messenger_method->set_addresses($row);
|
||||||
|
$messenger_method->anti_abuse_headers($config, $user);
|
||||||
|
$messenger_method->assign_vars([
|
||||||
|
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
||||||
|
'U_USER_DETAILS' => generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$user_row['user_id']}",
|
||||||
|
'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
|
||||||
|
]);
|
||||||
|
|
||||||
$messenger->anti_abuse_headers($config, $user);
|
$messenger_method->send();
|
||||||
|
|
||||||
$messenger->assign_vars(array(
|
// Save the queue in the messenger method class (has to be called or these messages could be lost)
|
||||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
$messenger_method->save_queue();
|
||||||
'U_USER_DETAILS' => generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$user_row['user_id']}",
|
}
|
||||||
'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}")
|
$messenger_collection_iterator->next();
|
||||||
);
|
}
|
||||||
|
|
||||||
$messenger->send($row['user_notify_type']);
|
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ class message
|
||||||
'user_email' => $recipient_address,
|
'user_email' => $recipient_address,
|
||||||
'lang' => $recipient_lang,
|
'lang' => $recipient_lang,
|
||||||
'username' => $recipient_username,
|
'username' => $recipient_username,
|
||||||
'user_jabber' => $recipient_jabber,
|
'user_jabber' => $recipient_jabber,
|
||||||
'notify_type' => $recipient_notify_type,
|
'notify_type' => $recipient_notify_type,
|
||||||
'to_name' => $recipient_name,
|
'to_name' => $recipient_name,
|
||||||
);
|
);
|
||||||
|
@ -245,7 +245,7 @@ class message
|
||||||
|
|
||||||
foreach ($this->recipients as $recipient)
|
foreach ($this->recipients as $recipient)
|
||||||
{
|
{
|
||||||
$messenger_collection_iterator = $this->messenger->getIterator();
|
$messenger_collection_iterator = $messenger->getIterator();
|
||||||
while ($messenger_collection_iterator->valid())
|
while ($messenger_collection_iterator->valid())
|
||||||
{
|
{
|
||||||
$messenger_method = $messenger_collection_iterator->current();
|
$messenger_method = $messenger_collection_iterator->current();
|
||||||
|
@ -256,15 +256,15 @@ class message
|
||||||
$messenger_method->set_addresses($recipient);
|
$messenger_method->set_addresses($recipient);
|
||||||
$messenger_method->replyto($this->sender_address);
|
$messenger_method->replyto($this->sender_address);
|
||||||
|
|
||||||
$messenger_method->headers('X-AntiAbuse', 'Board servername - ' . $this->server_name);
|
$messenger_method->header('X-AntiAbuse', 'Board servername - ' . $this->server_name);
|
||||||
$messenger_method->headers('X-AntiAbuse', 'User IP - ' . $this->sender_ip);
|
$messenger_method->header('X-AntiAbuse', 'User IP - ' . $this->sender_ip);
|
||||||
if ($this->sender_id)
|
if ($this->sender_id)
|
||||||
{
|
{
|
||||||
$messenger_method->headers('X-AntiAbuse', 'User_id - ' . $this->sender_id);
|
$messenger_method->header('X-AntiAbuse', 'User_id - ' . $this->sender_id);
|
||||||
}
|
}
|
||||||
if ($this->sender_username)
|
if ($this->sender_username)
|
||||||
{
|
{
|
||||||
$messenger_method->headers('X-AntiAbuse', 'Username - ' . $this->sender_username);
|
$messenger_method->header('X-AntiAbuse', 'Username - ' . $this->sender_username);
|
||||||
}
|
}
|
||||||
|
|
||||||
$messenger_method->subject(html_entity_decode($this->subject, ENT_COMPAT));
|
$messenger_method->subject(html_entity_decode($this->subject, ENT_COMPAT));
|
||||||
|
|
|
@ -25,14 +25,11 @@ use phpbb\user;
|
||||||
/**
|
/**
|
||||||
* Messenger base class
|
* Messenger base class
|
||||||
*/
|
*/
|
||||||
class base
|
abstract class base
|
||||||
{
|
{
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $additional_headers = [];
|
protected $additional_headers = [];
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
protected $addresses = [];
|
|
||||||
|
|
||||||
/** @var config */
|
/** @var config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
@ -90,6 +87,15 @@ class base
|
||||||
$this->set_use_queue();
|
$this->set_use_queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get messenger method id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
abstract public function get_id()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the use of messenger queue flag
|
* Sets the use of messenger queue flag
|
||||||
*
|
*
|
||||||
|
@ -105,10 +111,12 @@ class base
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function reset()
|
abstract public function reset()
|
||||||
{
|
{
|
||||||
$this->addresses = [];
|
$this->subject = $this->additional_headers = [];
|
||||||
$this->msg = '';
|
$this->msg = '';
|
||||||
|
$this->use_queue = true;
|
||||||
|
unset($this->template);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +125,7 @@ class base
|
||||||
* @param array $user User row
|
* @param array $user User row
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function set_addresses($user)
|
abstract public function set_addresses($user)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +172,14 @@ class base
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send out messages
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
abstract protected function send()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set email template to use
|
* Set email template to use
|
||||||
*
|
*
|
||||||
|
@ -295,7 +311,7 @@ class base
|
||||||
'SITENAME' => html_entity_decode($this->config['sitename'], ENT_COMPAT),
|
'SITENAME' => html_entity_decode($this->config['sitename'], ENT_COMPAT),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$subject = $this->email->getSubject();
|
$subject = $this->subject;
|
||||||
$template = $this->template;
|
$template = $this->template;
|
||||||
/**
|
/**
|
||||||
* Event to modify the template before parsing
|
* Event to modify the template before parsing
|
||||||
|
@ -304,7 +320,7 @@ class base
|
||||||
* @var string subject The message subject
|
* @var string subject The message subject
|
||||||
* @var \phpbb\template\template template The (readonly) template object
|
* @var \phpbb\template\template template The (readonly) template object
|
||||||
* @since 3.2.4-RC1
|
* @since 3.2.4-RC1
|
||||||
* @changed 4.0.0-a1 Added vars: email. Removed vars: method, break.
|
* @changed 4.0.0-a1 Removed vars: method, break.
|
||||||
*/
|
*/
|
||||||
$vars = ['subject', 'template'];
|
$vars = ['subject', 'template'];
|
||||||
extract($this->dispatcher->trigger_event('core.modify_notification_template', compact($vars)));
|
extract($this->dispatcher->trigger_event('core.modify_notification_template', compact($vars)));
|
||||||
|
@ -378,7 +394,7 @@ class base
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save message data to the messemger file queue
|
* Save message data to the messenger file queue
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function save_queue()
|
public function save_queue()
|
||||||
|
|
|
@ -106,12 +106,14 @@ class email extends base
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function reset()
|
||||||
{
|
{
|
||||||
$this->email = new Email();
|
$this->email = new Email();
|
||||||
$this->headers = $this->email->getHeaders();
|
$this->headers = $this->email->getHeaders();
|
||||||
$this->msg = $this->replyto = $this->from = '';
|
$this->msg = $this->replyto = $this->from = '';
|
||||||
$this->mail_priority = Email::PRIORITY_NORMAL;
|
$this->mail_priority = Email::PRIORITY_NORMAL;
|
||||||
|
|
||||||
|
parent::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -567,6 +569,7 @@ class email extends base
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
$this->reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -393,6 +393,19 @@ class jabber extends base
|
||||||
$this->to[$pos]['name'] = trim($realname);
|
$this->to[$pos]['name'] = trim($realname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inits/resets the data to default
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function reset()
|
||||||
|
{
|
||||||
|
$this->msg = '';
|
||||||
|
$this->to = [];
|
||||||
|
|
||||||
|
parent::reset();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the use of messenger queue flag
|
* Sets the use of messenger queue flag
|
||||||
*
|
*
|
||||||
|
@ -455,6 +468,8 @@ class jabber extends base
|
||||||
}
|
}
|
||||||
unset($addresses);
|
unset($addresses);
|
||||||
|
|
||||||
|
$this->reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue