mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-10 18:54:08 +02:00
[ticket/17135] Fix code review issues
PHPBB-17135
This commit is contained in:
@@ -61,12 +61,12 @@ abstract class base
|
||||
/** @var path_helper */
|
||||
protected $path_helper;
|
||||
|
||||
/** @var string */
|
||||
protected $root_path;
|
||||
|
||||
/** @var request */
|
||||
protected $request;
|
||||
|
||||
/** @var string */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string */
|
||||
protected $subject = '';
|
||||
|
||||
@@ -94,95 +94,98 @@ abstract class base
|
||||
* @param assets_bag $assets_bag
|
||||
* @param config $config
|
||||
* @param dispatcher $dispatcher
|
||||
* @param manager $ext_manager
|
||||
* @param language $language
|
||||
* @param log_interface $log
|
||||
* @param request $request
|
||||
* @param user $user
|
||||
* @param queue $queue
|
||||
* @param path_helper $path_helper
|
||||
* @param manager $ext_manager
|
||||
* @param request $request
|
||||
* @param service_collection $twig_extensions_collection
|
||||
* @param lexer $twig_lexer
|
||||
* @param string $template_cache_path
|
||||
* @param user $user
|
||||
* @param string $phpbb_root_path
|
||||
* @param string $template_cache_path
|
||||
*/
|
||||
function __construct(
|
||||
public function __construct(
|
||||
assets_bag $assets_bag,
|
||||
config $config,
|
||||
dispatcher $dispatcher,
|
||||
manager $ext_manager,
|
||||
language $language,
|
||||
log_interface $log,
|
||||
request $request,
|
||||
user $user,
|
||||
queue $queue,
|
||||
path_helper $path_helper,
|
||||
manager $ext_manager,
|
||||
request $request,
|
||||
service_collection $twig_extensions_collection,
|
||||
lexer $twig_lexer,
|
||||
$template_cache_path,
|
||||
$phpbb_root_path
|
||||
user $user,
|
||||
$phpbb_root_path,
|
||||
$template_cache_path
|
||||
)
|
||||
{
|
||||
$this->assets_bag = $assets_bag;
|
||||
$this->config = $config;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->ext_manager = $ext_manager;
|
||||
$this->language = $language;
|
||||
$this->log = $log;
|
||||
$this->request = $request;
|
||||
$this->user = $user;
|
||||
$this->queue = $queue;
|
||||
$this->path_helper = $path_helper;
|
||||
$this->ext_manager = $ext_manager;
|
||||
$this->request = $request;
|
||||
$this->twig_extensions_collection = $twig_extensions_collection;
|
||||
$this->twig_lexer = $twig_lexer;
|
||||
$this->template_cache_path = $template_cache_path;
|
||||
$this->user = $user;
|
||||
$this->root_path = $phpbb_root_path;
|
||||
$this->template_cache_path = $template_cache_path;
|
||||
|
||||
$this->set_use_queue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get messenger method id
|
||||
* @return mixed
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
abstract public function get_id();
|
||||
abstract public function get_id(): int;
|
||||
|
||||
/**
|
||||
* Check if the messenger method is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function is_enabled();
|
||||
abstract public function is_enabled(): bool;
|
||||
|
||||
/**
|
||||
* Sets the use of messenger queue flag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_use_queue($use_queue = true)
|
||||
public function set_use_queue(bool $use_queue = true): void
|
||||
{
|
||||
$this->use_queue = $use_queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all the data (address, template file, etc etc) to default
|
||||
* Initializes all the data (address, template file, etc) or resets to default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function reset();
|
||||
abstract public function init(): void;
|
||||
|
||||
/**
|
||||
* Set addresses for to/im as available
|
||||
*
|
||||
* @param array $user User row
|
||||
* @param array $user_row User row
|
||||
* @return void
|
||||
*/
|
||||
abstract public function set_addresses($user);
|
||||
abstract public function set_addresses(array $user_row): void;
|
||||
|
||||
/**
|
||||
* Get messenger method fie queue object name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_queue_object_name();
|
||||
abstract public function get_queue_object_name(): string;
|
||||
|
||||
/**
|
||||
* Set up subject for mail
|
||||
@@ -190,7 +193,7 @@ abstract class base
|
||||
* @param string $subject Email subject
|
||||
* @return void
|
||||
*/
|
||||
public function subject($subject = '')
|
||||
public function subject(string $subject = ''): void
|
||||
{
|
||||
$this->subject = $subject;
|
||||
}
|
||||
@@ -202,9 +205,7 @@ abstract class base
|
||||
* @param user $user User object
|
||||
* @return void
|
||||
*/
|
||||
public function anti_abuse_headers($config, $user)
|
||||
{
|
||||
}
|
||||
abstract public function anti_abuse_headers(config $config, user $user): void;
|
||||
|
||||
/**
|
||||
* Set up extra headers
|
||||
@@ -213,9 +214,7 @@ abstract class base
|
||||
* @param string $header_value Email header body
|
||||
* @return void
|
||||
*/
|
||||
public function header($header_name, $header_value)
|
||||
{
|
||||
}
|
||||
abstract public function header(string $header_name, string $header_value): void;
|
||||
|
||||
/**
|
||||
* Set the reply to address
|
||||
@@ -223,15 +222,14 @@ abstract class base
|
||||
* @param string $address Email "Reply to" address
|
||||
* @return void
|
||||
*/
|
||||
public function replyto($address)
|
||||
{
|
||||
}
|
||||
abstract public function reply_to($address): void;
|
||||
|
||||
/**
|
||||
* Send out messages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function send();
|
||||
abstract protected function send(): bool;
|
||||
|
||||
/**
|
||||
* Send messages from the queue
|
||||
@@ -239,7 +237,7 @@ abstract class base
|
||||
* @param array $queue_data Queue data array
|
||||
* @return void
|
||||
*/
|
||||
abstract public function process_queue(&$queue_data);
|
||||
abstract public function process_queue(array &$queue_data): void;
|
||||
|
||||
/**
|
||||
* Set email template to use
|
||||
@@ -251,17 +249,12 @@ abstract class base
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function template($template_file, $template_lang = '', $template_path = '', $template_dir_prefix = '')
|
||||
public function template(string $template_file, string $template_lang = '', string $template_path = '', string $template_dir_prefix = ''): bool
|
||||
{
|
||||
$template_dir_prefix = (!$template_dir_prefix || $template_dir_prefix[0] === '/') ? $template_dir_prefix : '/' . $template_dir_prefix;
|
||||
|
||||
$this->setup_template();
|
||||
|
||||
if (!trim($template_file))
|
||||
{
|
||||
trigger_error('No template file for emailing set.', E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (!trim($template_lang))
|
||||
{
|
||||
// fall back to board default language if the user's language is
|
||||
@@ -338,7 +331,7 @@ abstract class base
|
||||
* @param array $vars Array of VAR => VALUE to assign to email template
|
||||
* @return void
|
||||
*/
|
||||
public function assign_vars($vars)
|
||||
public function assign_vars(array $vars): void
|
||||
{
|
||||
$this->setup_template();
|
||||
$this->template->assign_vars($vars);
|
||||
@@ -351,7 +344,7 @@ abstract class base
|
||||
* @param array $vars Array of VAR => VALUE to assign to email template block
|
||||
* @return void
|
||||
*/
|
||||
public function assign_block_vars($blockname, $vars)
|
||||
public function assign_block_vars(string $blockname, array $vars): void
|
||||
{
|
||||
$this->setup_template();
|
||||
|
||||
@@ -363,7 +356,7 @@ abstract class base
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepare_message()
|
||||
public function prepare_message(): void
|
||||
{
|
||||
// We add some standard variables we always use, no need to specify them always
|
||||
$this->assign_vars([
|
||||
@@ -440,7 +433,7 @@ abstract class base
|
||||
* @param string $msg Error message text
|
||||
* @return void
|
||||
*/
|
||||
public function error($msg)
|
||||
public function error(string $msg): void
|
||||
{
|
||||
// Session doesn't exist, create it
|
||||
if (!isset($this->user->session_id) || $this->user->session_id === '')
|
||||
@@ -458,7 +451,7 @@ abstract class base
|
||||
* Save message data to the messenger file queue
|
||||
* @return void
|
||||
*/
|
||||
public function save_queue()
|
||||
public function save_queue(): void
|
||||
{
|
||||
if ($this->use_queue && !empty($this->queue))
|
||||
{
|
||||
@@ -469,9 +462,10 @@ abstract class base
|
||||
|
||||
/**
|
||||
* Setup template engine
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setup_template()
|
||||
protected function setup_template(): void
|
||||
{
|
||||
if (isset($this->template) && $this->template instanceof \phpbb\template\template)
|
||||
{
|
||||
@@ -510,7 +504,7 @@ abstract class base
|
||||
* @param string|array $paths Email template paths
|
||||
* @return void
|
||||
*/
|
||||
protected function set_template_paths($path_name, $paths)
|
||||
protected function set_template_paths(string|array $path_name, string|array $paths): void
|
||||
{
|
||||
$this->setup_template();
|
||||
$this->template->set_custom_style($path_name, $paths);
|
||||
|
@@ -16,7 +16,7 @@ namespace phpbb\messenger\method;
|
||||
use Symfony\Component\Mailer\Transport;
|
||||
use Symfony\Component\Mailer\Mailer;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Mime\Email as symfony_email;
|
||||
use Symfony\Component\Mime\Header\DateHeader;
|
||||
use Symfony\Component\Mime\Header\Headers;
|
||||
use Symfony\Component\Mime\Header\IdentificationHeader;
|
||||
@@ -28,7 +28,7 @@ use Symfony\Component\Mime\Header\UnstructuredHeader;
|
||||
/**
|
||||
* Messenger class
|
||||
*/
|
||||
class phpbb_email extends base
|
||||
class email extends base
|
||||
{
|
||||
/** @var array */
|
||||
private const PRIORITY_MAP = [
|
||||
@@ -39,21 +39,6 @@ class phpbb_email extends base
|
||||
Email::PRIORITY_LOWEST => 'Lowest',
|
||||
];
|
||||
|
||||
/** @var array */
|
||||
private const HEADER_CLASS_MAP = [
|
||||
'date' => DateHeader::class,
|
||||
'from' => MailboxListHeader::class,
|
||||
'sender' => MailboxHeader::class,
|
||||
'reply-to' => MailboxListHeader::class,
|
||||
'to' => MailboxListHeader::class,
|
||||
'cc' => MailboxListHeader::class,
|
||||
'bcc' => MailboxListHeader::class,
|
||||
'message-id' => IdentificationHeader::class,
|
||||
'in-reply-to' => UnstructuredHeader::class,
|
||||
'references' => UnstructuredHeader::class,
|
||||
'return-path' => PathHeader::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@@ -86,7 +71,7 @@ class phpbb_email extends base
|
||||
protected $queue;
|
||||
|
||||
/** @var Address */
|
||||
protected $replyto;
|
||||
protected $reply_to;
|
||||
|
||||
/** @var \Symfony\Component\Mailer\Transport\AbstractTransport */
|
||||
protected $transport;
|
||||
@@ -94,7 +79,7 @@ class phpbb_email extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_id()
|
||||
public function get_id(): int
|
||||
{
|
||||
return NOTIFY_EMAIL;
|
||||
}
|
||||
@@ -102,7 +87,7 @@ class phpbb_email extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_queue_object_name()
|
||||
public function get_queue_object_name(): string
|
||||
{
|
||||
return 'email';
|
||||
}
|
||||
@@ -110,7 +95,7 @@ class phpbb_email extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function is_enabled()
|
||||
public function is_enabled(): bool
|
||||
{
|
||||
return (bool) $this->config['email_enable'];
|
||||
}
|
||||
@@ -118,16 +103,16 @@ class phpbb_email extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reset()
|
||||
public function init(): void
|
||||
{
|
||||
$this->email = new Email();
|
||||
$this->email = new symfony_email();
|
||||
$this->headers = $this->email->getHeaders();
|
||||
$this->subject = $this->msg = '';
|
||||
$this->mail_priority = Email::PRIORITY_NORMAL;
|
||||
|
||||
$this->additional_headers = [];
|
||||
$this->use_queue = true;
|
||||
unset($this->template, $this->replyto, $this->from);
|
||||
unset($this->template, $this->reply_to, $this->from);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +120,7 @@ class phpbb_email extends base
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_use_queue($use_queue = true)
|
||||
public function set_use_queue(bool $use_queue = true): void
|
||||
{
|
||||
$this->use_queue = !$this->config['email_package_size'] ? false : $use_queue;
|
||||
}
|
||||
@@ -143,11 +128,11 @@ class phpbb_email extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set_addresses($user)
|
||||
public function set_addresses(array $user_row): void
|
||||
{
|
||||
if (isset($user['user_email']) && $user['user_email'])
|
||||
if (isset($user_row['user_email']) && $user_row['user_email'])
|
||||
{
|
||||
$this->to($user['user_email'], $user['username'] ?: '');
|
||||
$this->to($user_row['user_email'], $user_row['username'] ?: '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +143,7 @@ class phpbb_email extends base
|
||||
* @param string $realname Email "To" recipient name
|
||||
* @return void
|
||||
*/
|
||||
public function to($address, $realname = '')
|
||||
public function to(string $address, string $realname = ''): void
|
||||
{
|
||||
if (!$address = trim($address))
|
||||
{
|
||||
@@ -179,7 +164,7 @@ class phpbb_email extends base
|
||||
* @param string $realname Email carbon copy recipient name
|
||||
* @return void
|
||||
*/
|
||||
public function cc($address, $realname = '')
|
||||
public function cc(string $address, string $realname = ''): void
|
||||
{
|
||||
if (!$address = trim($address))
|
||||
{
|
||||
@@ -197,7 +182,7 @@ class phpbb_email extends base
|
||||
* @param string $realname Email black carbon copy recipient name
|
||||
* @return void
|
||||
*/
|
||||
public function bcc($address, $realname = '')
|
||||
public function bcc(string $address, string $realname = ''): void
|
||||
{
|
||||
if (!$address = trim($address))
|
||||
{
|
||||
@@ -212,23 +197,35 @@ class phpbb_email extends base
|
||||
* Set the reply to address
|
||||
*
|
||||
* @param string $address Email "Reply to" address
|
||||
* @param string $realname Email "Reply to" recipient name
|
||||
* @return void
|
||||
*/
|
||||
public function replyto($address)
|
||||
public function reply_to(string $address, string $realname = ''): void
|
||||
{
|
||||
$this->replyto = new Address(trim($address));
|
||||
$this->email->getReplyTo() ? $this->email->addReplyTo($this->replyto) : $this->email->replyTo($this->replyto);
|
||||
if (!$address = trim($address))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reply_to = new Address($address, trim($realname));
|
||||
$this->email->getReplyTo() ? $this->email->addReplyTo($this->reply_to) : $this->email->replyTo($this->reply_to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the from address
|
||||
*
|
||||
* @param string $address Email "from" address
|
||||
* @param string $realname Email "from" recipient name
|
||||
* @return void
|
||||
*/
|
||||
public function from($address)
|
||||
public function from(string $address, string $realname = ''): void
|
||||
{
|
||||
$this->from = new Address(trim($address));
|
||||
if (!$address = trim($address))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->from = new Address($address, trim($realname));
|
||||
$this->email->getFrom() ? $this->email->addFrom($this->from) : $this->email->from($this->from);
|
||||
}
|
||||
|
||||
@@ -238,32 +235,12 @@ class phpbb_email extends base
|
||||
* @param string $subject Email subject
|
||||
* @return void
|
||||
*/
|
||||
public function subject($subject = '')
|
||||
public function subject(string $subject = ''): void
|
||||
{
|
||||
parent::subject(trim($subject));
|
||||
$this->email->subject($this->subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up extra mail headers
|
||||
*
|
||||
* @param string $header_name Email header name
|
||||
* @param string $header_value Email header body
|
||||
* @return void
|
||||
*/
|
||||
public function header($header_name, $header_value)
|
||||
{
|
||||
$header_name = $header_name;
|
||||
$header_value = $header_value;
|
||||
|
||||
// addMailboxListHeader() requires value to be array
|
||||
if ($this->get_header_method($header_name) == 'addMailboxListHeader')
|
||||
{
|
||||
$header_value = [$header_value];
|
||||
}
|
||||
$this->headers->addHeader($header_name, $header_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds X-AntiAbuse headers
|
||||
*
|
||||
@@ -271,12 +248,12 @@ class phpbb_email extends base
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
*/
|
||||
public function anti_abuse_headers($config, $user)
|
||||
public function anti_abuse_headers(\phpbb\config\config $config, \phpbb\user $user): void
|
||||
{
|
||||
$this->header('X-AntiAbuse', 'Board servername - ' . $config['server_name']);
|
||||
$this->header('X-AntiAbuse', 'User_id - ' . $user->data['user_id']);
|
||||
$this->header('X-AntiAbuse', 'Username - ' . $user->data['username']);
|
||||
$this->header('X-AntiAbuse', 'User IP - ' . $user->ip);
|
||||
$this->headers->addHeader('X-AntiAbuse', 'Board servername - ' . $config['server_name']);
|
||||
$this->headers->addHeader('X-AntiAbuse', 'User_id - ' . $user->data['user_id']);
|
||||
$this->headers->addHeader('X-AntiAbuse', 'Username - ' . $user->data['username']);
|
||||
$this->headers->addHeader('X-AntiAbuse', 'User IP - ' . $user->ip);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,79 +269,63 @@ class phpbb_email extends base
|
||||
* @param int $priority Email priority level
|
||||
* @return void
|
||||
*/
|
||||
public function set_mail_priority($priority = Email::PRIORITY_NORMAL)
|
||||
public function set_mail_priority(int $priority = Email::PRIORITY_NORMAL): void
|
||||
{
|
||||
$this->email->priority($priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect proper Header class method to add header
|
||||
*
|
||||
* @param string $name Email header name
|
||||
* @return string
|
||||
*/
|
||||
protected function get_header_method(string $name)
|
||||
{
|
||||
$parts = explode('\\', self::HEADER_CLASS_MAP[strtolower($name)] ?? UnstructuredHeader::class);
|
||||
$method = 'add'.ucfirst(array_pop($parts));
|
||||
if ('addUnstructuredHeader' === $method)
|
||||
{
|
||||
$method = 'addTextHeader';
|
||||
}
|
||||
else if ('addIdentificationHeader' === $method)
|
||||
{
|
||||
$method = 'addIdHeader';
|
||||
}
|
||||
|
||||
return $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email headers
|
||||
*
|
||||
* @return bool
|
||||
* @return void
|
||||
*/
|
||||
protected function build_header()
|
||||
protected function build_headers(): void
|
||||
{
|
||||
$headers = [];
|
||||
|
||||
$board_contact = $this->config['board_contact'];
|
||||
$board_contact = trim($this->config['board_contact']);
|
||||
$contact_name = html_entity_decode($this->config['board_contact_name'], ENT_COMPAT);
|
||||
|
||||
if (empty($this->email->getReplyTo()))
|
||||
{
|
||||
$this->replyto($board_contact);
|
||||
$headers['Reply-To'] = $this->replyto;
|
||||
$this->reply_to($board_contact, $contact_name);
|
||||
}
|
||||
|
||||
if (empty($this->email->getFrom()))
|
||||
{
|
||||
$this->from($board_contact);
|
||||
$headers['From'] = $this->from;
|
||||
$this->from($board_contact, $contact_name);
|
||||
}
|
||||
|
||||
$headers['Return-Path'] = new Address($this->config['board_email']);
|
||||
$headers['Sender'] = new Address($this->config['board_email']);
|
||||
$headers['X-Priority'] = sprintf('%d (%s)', $this->mail_priority, self::PRIORITY_MAP[$this->mail_priority]);
|
||||
$headers['X-MSMail-Priority'] = self::PRIORITY_MAP[$this->mail_priority];
|
||||
$headers['X-Mailer'] = 'phpBB3';
|
||||
$headers['X-MimeOLE'] = 'phpBB3';
|
||||
$headers['X-phpBB-Origin'] = 'phpbb://' . str_replace(['http://', 'https://'], ['', ''], generate_board_url());
|
||||
$this->email->priority($this->mail_priority);
|
||||
|
||||
$phpbb_headers = [
|
||||
'Return-Path' => new Address($this->config['board_email']),
|
||||
'Sender' => new Address($this->config['board_email']),
|
||||
'X-MSMail-Priority' => self::PRIORITY_MAP[$this->mail_priority],
|
||||
'X-Mailer' => 'phpBB3',
|
||||
'X-MimeOLE' => 'phpBB3',
|
||||
'X-phpBB-Origin' => 'phpbb://' . str_replace(['http://', 'https://'], ['', ''], generate_board_url()),
|
||||
];
|
||||
|
||||
// Add additional headers
|
||||
$phpbb_headers = array_merge($phpbb_headers, $this->additional_headers);
|
||||
|
||||
foreach ($phpbb_headers as $header => $value)
|
||||
{
|
||||
$this->headers->addHeader($header, $value);
|
||||
}
|
||||
|
||||
$headers = $this->headers;
|
||||
/**
|
||||
* Event to modify email header entries
|
||||
*
|
||||
* @event core.modify_email_headers
|
||||
* @var array headers Array containing email header entries
|
||||
* @var Headers headers Array containing email header entries
|
||||
* @since 3.1.11-RC1
|
||||
* @changed 4.0.0-a1 'headers' var type changed from array to \Symfony\Component\Mime\Header\Headers
|
||||
*/
|
||||
$vars = ['headers'];
|
||||
extract($this->dispatcher->trigger_event('core.modify_email_headers', compact($vars)));
|
||||
|
||||
foreach ($headers as $header => $value)
|
||||
{
|
||||
$this->header($header, $value);
|
||||
}
|
||||
|
||||
return true;
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,7 +334,7 @@ class phpbb_email extends base
|
||||
* @param string $dsn Symfony Mailer transport DSN
|
||||
* @return void
|
||||
*/
|
||||
public function set_dsn($dsn = '')
|
||||
public function set_dsn(string $dsn = ''): void
|
||||
{
|
||||
if (!empty($dsn))
|
||||
{
|
||||
@@ -406,7 +367,7 @@ class phpbb_email extends base
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_dsn()
|
||||
public function get_dsn(): string
|
||||
{
|
||||
return $this->dsn;
|
||||
}
|
||||
@@ -416,7 +377,7 @@ class phpbb_email extends base
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_transport()
|
||||
public function set_transport(): void
|
||||
{
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
@@ -440,7 +401,7 @@ class phpbb_email extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process_queue(&$queue_data)
|
||||
public function process_queue(array &$queue_data): void
|
||||
{
|
||||
$queue_object_name = $this->get_queue_object_name();
|
||||
$messages_count = count($queue_data[$queue_object_name]['data']);
|
||||
@@ -504,23 +465,18 @@ class phpbb_email extends base
|
||||
*
|
||||
* @return \Symfony\Component\Mailer\Transport\TransportInterface Symfony Mailer transport object
|
||||
*/
|
||||
public function get_transport()
|
||||
public function get_transport(): \Symfony\Component\Mailer\Transport\TransportInterface
|
||||
{
|
||||
return $this->transport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send out emails
|
||||
*
|
||||
* @return bool
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function send()
|
||||
public function send(): bool
|
||||
{
|
||||
$this->prepare_message();
|
||||
|
||||
$contact_name = html_entity_decode($this->config['board_contact_name'], ENT_COMPAT);
|
||||
$board_contact = trim($this->config['board_contact']);
|
||||
|
||||
$this->email->subject($this->subject);
|
||||
$this->email->text($this->msg);
|
||||
|
||||
@@ -543,23 +499,9 @@ class phpbb_email extends base
|
||||
'email',
|
||||
];
|
||||
extract($this->dispatcher->trigger_event('core.notification_message_email', compact($vars)));
|
||||
$this->email = $email;
|
||||
|
||||
if (empty($this->email->getReplyto()))
|
||||
{
|
||||
$this->replyto($board_contact);
|
||||
}
|
||||
|
||||
if (empty($this->email->getFrom()))
|
||||
{
|
||||
$this->from($board_contact);
|
||||
}
|
||||
|
||||
// Build headers
|
||||
foreach ($this->additional_headers as $header_name => $header_value)
|
||||
{
|
||||
$this->header($header_name, $header_value);
|
||||
}
|
||||
$this->build_header();
|
||||
$this->build_headers();
|
||||
|
||||
// Send message ...
|
||||
if (!$this->use_queue)
|
@@ -22,9 +22,9 @@ namespace phpbb\messenger\method;
|
||||
* @author Florian Schmitz (floele)
|
||||
*
|
||||
* Slightly modified by Acyd Burn (2006)
|
||||
* Refactored to a service (2023)
|
||||
* Refactored to a service (2024)
|
||||
*/
|
||||
class phpbb_jabber extends base
|
||||
class jabber extends base
|
||||
{
|
||||
/** @var string */
|
||||
protected $connect_server;
|
||||
@@ -96,7 +96,7 @@ class phpbb_jabber extends base
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
$this->username($this->config['jab_username'])
|
||||
->password($this->config['jab_password'])
|
||||
@@ -113,7 +113,7 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_id()
|
||||
public function get_id(): int
|
||||
{
|
||||
return NOTIFY_IM;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_queue_object_name()
|
||||
public function get_queue_object_name(): string
|
||||
{
|
||||
return 'jabber';
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function is_enabled()
|
||||
public function is_enabled(): bool
|
||||
{
|
||||
return
|
||||
!empty($this->config['jab_enable']) &&
|
||||
@@ -143,9 +143,9 @@ class phpbb_jabber extends base
|
||||
* See http://php.net/manual/en/context.ssl.php
|
||||
*
|
||||
* @param array $options SSL context options array
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function stream_options($options = [])
|
||||
public function stream_options(array $options = []): self
|
||||
{
|
||||
if ($this->use_ssl)
|
||||
{
|
||||
@@ -160,9 +160,9 @@ class phpbb_jabber extends base
|
||||
* Set password to connect to server
|
||||
*
|
||||
* @param string $password Password to connect to server
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function password($password = '')
|
||||
public function password(string $password = ''): self
|
||||
{
|
||||
$this->password = html_entity_decode($password, ENT_COMPAT);
|
||||
|
||||
@@ -173,9 +173,9 @@ class phpbb_jabber extends base
|
||||
* Set use of ssl to connect to server
|
||||
*
|
||||
* @param bool $use_ssl Flag indicating use of ssl to connect to server
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function ssl($use_ssl = false)
|
||||
public function ssl(bool $use_ssl = false): self
|
||||
{
|
||||
$this->use_ssl = $use_ssl && self::can_use_ssl();
|
||||
|
||||
@@ -187,9 +187,9 @@ class phpbb_jabber extends base
|
||||
* use_ssl flag should be set first
|
||||
*
|
||||
* @param int $port Port to connect to server
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function port($port = 5222)
|
||||
public function port(int $port = 5222): self
|
||||
{
|
||||
$this->port = ($port) ? $port : 5222;
|
||||
|
||||
@@ -206,9 +206,9 @@ class phpbb_jabber extends base
|
||||
* Set username to connect to server
|
||||
*
|
||||
* @param string $username Username to connect to server
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function username($username = '')
|
||||
public function username(string $username = ''): self
|
||||
{
|
||||
if (strpos($username, '@') === false)
|
||||
{
|
||||
@@ -228,9 +228,9 @@ class phpbb_jabber extends base
|
||||
* Username should be set first
|
||||
*
|
||||
* @param string $server Server to connect
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function server($server = '')
|
||||
public function server(string $server = ''): self
|
||||
{
|
||||
$this->connect_server = ($server) ? $server : 'localhost';
|
||||
$this->server = $this->jid[1] ?? $this->connect_server;
|
||||
@@ -239,17 +239,21 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Able to use the SSL functionality?
|
||||
* Check if it's possible to use the SSL functionality
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_use_ssl()
|
||||
public static function can_use_ssl(): bool
|
||||
{
|
||||
return @extension_loaded('openssl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Able to use TLS?
|
||||
* Check if it's possible to use TLS functionality
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_use_tls()
|
||||
public static function can_use_tls(): bool
|
||||
{
|
||||
if (!@extension_loaded('openssl') || !function_exists('stream_socket_enable_crypto') || !function_exists('stream_get_meta_data') || !function_exists('stream_set_blocking') || !function_exists('stream_get_wrappers'))
|
||||
{
|
||||
@@ -272,19 +276,22 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resource which is used. No validation is done here, only escaping.
|
||||
* Sets the resource which is used. No validation is done here, only escaping
|
||||
*
|
||||
* @param string $name
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function set_resource($name)
|
||||
public function set_resource(string $name): void
|
||||
{
|
||||
$this->resource = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect
|
||||
* Connect to the server
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connect()
|
||||
public function connect(): bool
|
||||
{
|
||||
/* if (!$this->check_jid($this->username . '@' . $this->server))
|
||||
{
|
||||
@@ -311,9 +318,11 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect
|
||||
* Disconnect from the server
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): bool
|
||||
{
|
||||
if ($this->connected())
|
||||
{
|
||||
@@ -341,9 +350,11 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Connected?
|
||||
* Check if it's still connected to the server
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected()
|
||||
public function connected(): bool
|
||||
{
|
||||
return is_resource($this->connection) && !feof($this->connection);
|
||||
}
|
||||
@@ -354,7 +365,7 @@ class phpbb_jabber extends base
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
public function login()
|
||||
public function login(): bool|void
|
||||
{
|
||||
if (empty($this->features))
|
||||
{
|
||||
@@ -368,11 +379,11 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set_addresses($user)
|
||||
public function set_addresses(array $user_row): void
|
||||
{
|
||||
if (isset($user['user_jabber']) && $user['user_jabber'])
|
||||
if (isset($user_row['user_jabber']) && $user_row['user_jabber'])
|
||||
{
|
||||
$this->to($user['user_jabber'], (isset($user['username']) ? $user['username'] : ''));
|
||||
$this->to($user_row['user_jabber'], (isset($user_row['username']) ? $user_row['username'] : ''));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +394,7 @@ class phpbb_jabber extends base
|
||||
* @param string $realname Jabber "To" recipient name
|
||||
* @return void
|
||||
*/
|
||||
public function to($address, $realname = '')
|
||||
public function to(string $address, string $realname = ''): void
|
||||
{
|
||||
// IM-Addresses could be empty
|
||||
if (!trim($address))
|
||||
@@ -399,7 +410,7 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reset()
|
||||
public function init(): void
|
||||
{
|
||||
$this->subject = $this->msg = '';
|
||||
$this->additional_headers = $this->to = [];
|
||||
@@ -408,11 +419,9 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the use of messenger queue flag
|
||||
*
|
||||
* @return void
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set_use_queue($use_queue = true)
|
||||
public function set_use_queue(bool $use_queue = true): void
|
||||
{
|
||||
$this->use_queue = !$this->config['jab_package_size'] ? false : $use_queue;
|
||||
}
|
||||
@@ -420,7 +429,7 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process_queue(&$queue_data)
|
||||
public function process_queue(array &$queue_data): void
|
||||
{
|
||||
$queue_object_name = $this->get_queue_object_name();
|
||||
$messages_count = count($queue_data[$queue_object_name]['data']);
|
||||
@@ -473,9 +482,9 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Send jabber message out
|
||||
*/
|
||||
public function send()
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function send(): void
|
||||
{
|
||||
$this->prepare_message();
|
||||
|
||||
@@ -537,10 +546,9 @@ class phpbb_jabber extends base
|
||||
* Send data to the Jabber server
|
||||
*
|
||||
* @param string $xml
|
||||
*
|
||||
* @return int|bool
|
||||
*/
|
||||
public function send_xml($xml)
|
||||
public function send_xml(string $xml): int|bool
|
||||
{
|
||||
if ($this->connected())
|
||||
{
|
||||
@@ -555,14 +563,14 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenSocket
|
||||
* Open socket
|
||||
*
|
||||
* @param string $server host to connect to
|
||||
* @param int $port port number
|
||||
* @param string $server Host to connect to
|
||||
* @param int $port Port number
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function open_socket($server, $port)
|
||||
public function open_socket(string $server, int $port): bool
|
||||
{
|
||||
if (@function_exists('dns_get_record'))
|
||||
{
|
||||
@@ -590,9 +598,11 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* Return log
|
||||
* Get connection log
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_log()
|
||||
public function get_log(): string
|
||||
{
|
||||
if ($this->enable_logging && count($this->log_array))
|
||||
{
|
||||
@@ -604,8 +614,11 @@ class phpbb_jabber extends base
|
||||
|
||||
/**
|
||||
* Add information to log
|
||||
*
|
||||
* @param string $string Log entry
|
||||
* @return void
|
||||
*/
|
||||
protected function add_to_log($string)
|
||||
protected function add_to_log(string $string): void
|
||||
{
|
||||
if ($this->enable_logging)
|
||||
{
|
||||
@@ -617,9 +630,11 @@ class phpbb_jabber extends base
|
||||
* Listens to the connection until it gets data or the timeout is reached.
|
||||
* Thus, it should only be called if data is expected to be received.
|
||||
*
|
||||
* @return mixed either false for timeout or an array with the received data
|
||||
* @param int $timeout Connection timeout
|
||||
* @param bool $wait Flag indicating if it should wait for the responce until timeout
|
||||
* @return bool|array Either false for timeout or an array with the received data
|
||||
*/
|
||||
public function listen($timeout = 10, $wait = false)
|
||||
public function listen(int $timeout = 10, bool $wait = false): bool|array
|
||||
{
|
||||
if (!$this->connected())
|
||||
{
|
||||
@@ -653,7 +668,7 @@ class phpbb_jabber extends base
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
public function register()
|
||||
public function register(): bool|void
|
||||
{
|
||||
if (!isset($this->session['id']) || isset($this->session['jid']))
|
||||
{
|
||||
@@ -668,13 +683,12 @@ class phpbb_jabber extends base
|
||||
/**
|
||||
* Sets account presence. No additional info required (default is "online" status)
|
||||
*
|
||||
* @param string $message online, offline...
|
||||
* @param string $type dnd, away, chat, xa or nothing
|
||||
* @param bool $unavailable set this to true if you want to become unavailable
|
||||
*
|
||||
* @param string $message Account status (online, offline)
|
||||
* @param string $type Status type (dnd, away, chat, xa or nothing)
|
||||
* @param bool $unavailable Set to true to make unavailable status
|
||||
* @return int|bool
|
||||
*/
|
||||
function send_presence($message = '', $type = '', $unavailable = false)
|
||||
function send_presence(string $message = '', string $type = '', bool $unavailable = false): int|bool
|
||||
{
|
||||
if (!isset($this->session['jid']))
|
||||
{
|
||||
@@ -697,10 +711,9 @@ class phpbb_jabber extends base
|
||||
* This handles all the different XML elements
|
||||
*
|
||||
* @param array $xml
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
function response($xml)
|
||||
function response(array $xml): bool|void
|
||||
{
|
||||
if (!is_array($xml) || !count($xml))
|
||||
{
|
||||
@@ -1019,7 +1032,7 @@ class phpbb_jabber extends base
|
||||
*
|
||||
* @return int|bool
|
||||
*/
|
||||
public function send_message($to, $text, $subject = '', $type = 'normal')
|
||||
public function send_message(string $to, string $text, string $subject = '', string $type = 'normal'): int|bool
|
||||
{
|
||||
if (!isset($this->session['jid']))
|
||||
{
|
||||
@@ -1042,10 +1055,9 @@ class phpbb_jabber extends base
|
||||
* Encrypts a password as in RFC 2831
|
||||
*
|
||||
* @param array $data Needs data from the client-server connection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encrypt_password($data)
|
||||
public function encrypt_password(array $data): string
|
||||
{
|
||||
// let's me think about <challenge> again...
|
||||
foreach (array('realm', 'cnonce', 'digest-uri') as $key)
|
||||
@@ -1074,12 +1086,12 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* parse_data like a="b",c="d",... or like a="a, b", c, d="e", f=g,...
|
||||
* @param string $data
|
||||
* Parse data string like a="b",c="d",... or like a="a, b", c, d="e", f=g,...
|
||||
*
|
||||
* @param string $data
|
||||
* @return array a => b ...
|
||||
*/
|
||||
public function parse_data($data)
|
||||
public function parse_data(string $data): array
|
||||
{
|
||||
$data = explode(',', $data);
|
||||
$pairs = array();
|
||||
@@ -1106,13 +1118,12 @@ class phpbb_jabber extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* opposite of jabber::parse_data()
|
||||
*
|
||||
* @param array $data
|
||||
* The opposite of jabber::parse_data()
|
||||
*
|
||||
* @param array $data Data array
|
||||
* @return string
|
||||
*/
|
||||
public function implode_data($data)
|
||||
public function implode_data(arary $data): string
|
||||
{
|
||||
$return = array();
|
||||
foreach ($data as $key => $value)
|
||||
@@ -1126,8 +1137,13 @@ class phpbb_jabber extends base
|
||||
* xmlize()
|
||||
* @author Hans Anderson
|
||||
* @copyright Hans Anderson / http://www.hansanderson.com/php/xml/
|
||||
*
|
||||
* @param string $data Data string
|
||||
* @param string|int|bool $skip_white New XML parser option value
|
||||
* @param string $encoding Encoding value
|
||||
* @return string
|
||||
*/
|
||||
function xmlize($data, $skip_white = 1, $encoding = 'UTF-8')
|
||||
function xmlize(string $data, string|int|bool $skip_white = 1, string $encoding = 'UTF-8'): array
|
||||
{
|
||||
$data = trim($data);
|
||||
|
||||
@@ -1162,8 +1178,12 @@ class phpbb_jabber extends base
|
||||
* _xml_depth()
|
||||
* @author Hans Anderson
|
||||
* @copyright Hans Anderson / http://www.hansanderson.com/php/xml/
|
||||
*
|
||||
* @param array $vals XML data array
|
||||
* @param int $i XML tags depth level
|
||||
* @return array
|
||||
*/
|
||||
function _xml_depth($vals, &$i)
|
||||
function _xml_depth(array $vals, int &$i): array
|
||||
{
|
||||
$children = array();
|
||||
|
Reference in New Issue
Block a user