1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/10073] Use namespaces and fix all class names

PHPBB3-10073
This commit is contained in:
Joas Schilling
2014-04-11 18:09:25 +02:00
parent 6c287e57fc
commit fffb07fd91
8 changed files with 116 additions and 78 deletions

View File

@@ -0,0 +1,112 @@
<?php
/**
*
* @package message
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\message;
class admin_form extends form
{
protected $subject;
protected $sender_name;
protected $sender_address;
public function check_allow()
{
$error = parent::check_allow();
if ($error)
{
return $error;
}
if (!$this->config['contact_admin_form_enable']) /** TODO: && !$this->config['contact_admin_info']) */
{
return 'NO_CONTACT_PAGE';
}
return false;
}
public function bind(\phpbb\request\request_interface $request)
{
parent::bind($request);
$this->subject = $request->variable('subject', '', true);
$this->sender_address = $request->variable('email', '');
$this->sender_name = $request->variable('name', '', true);
}
public function submit(\messenger $messenger)
{
if (!$this->subject)
{
$this->errors[] = $this->user->lang['EMPTY_SUBJECT_EMAIL'];
}
if (!$this->body)
{
$this->errors[] = $this->user->lang['EMPTY_MESSAGE_EMAIL'];
}
if ($this->user->data['is_registered'])
{
$this->message->set_sender_from_user($this->user);
$this->sender_name = $this->user->data['username'];
$this->sender_address = $this->user->data['user_email'];
}
else
{
if (!$this->sender_name)
{
$this->errors[] = $this->user->lang['EMPTY_SENDER_NAME'];
}
if (!$this->sender_address || !preg_match('/^' . get_preg_expression('email') . '$/i', $this->sender_address))
{
$this->errors[] = $this->user->lang['EMPTY_SENDER_EMAIL'];
}
$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_template('contact_admin');
$this->message->set_subject($this->subject);
$this->message->set_body($this->body);
$this->message->add_recipient(
$this->user->lang['ADMINISTRATOR'],
$this->config['board_contact'],
$this->config['default_lang'],
NOTIFY_EMAIL
);
$this->message->set_template_vars(array(
'FROM_EMAIL_ADDRESS' => $this->sender_address,
'FROM_IP_ADDRESS' => $this->user->ip,
'S_IS_REGISTERED' => $this->user->data['is_registered'],
'U_FROM_PROFILE' => generate_board_url() . '/memberlist.' . $this->phpEx . '?mode=viewprofile&u=' . $this->user->data['user_id'],
));
parent::submit($messenger);
}
public function render(\phpbb\template\template $template)
{
$template->assign_vars(array(
'S_CONTACT_ADMIN' => true,
'S_CONTACT_FORM' => $this->config['contact_admin_form_enable'],
'S_IS_REGISTERED' => $this->user->data['is_registered'],
'CONTACT_INFO' => '', /** TODO: $this->config['contact_admin_info'] */
'MESSAGE' => $this->body,
'SUBJECT' => $this->subject,
'NAME' => $this->sender_name,
'EMAIL' => $this->sender_address,
));
parent::render($template);
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
*
* @package message
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\message;
abstract class form
{
/** @var \phpbb\auth\auth */
protected $auth;
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\user */
protected $user;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $phpEx;
protected $errors;
protected $message;
protected $cc_sender;
protected $body;
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $phpEx)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
$this->user = $user;
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->errors = array();
$this->message = new \phpbb\message\message($config['server_name']);
$this->message->set_sender_from_user($this->user);
}
/**
* Returns the title for the email form page
*/
public function get_page_title()
{
$this->user->lang['SEND_EMAIL'];
}
public function get_template_file()
{
return 'memberlist_email.html';
}
public function check_allow()
{
if (!$this->config['email_enable'])
{
return 'EMAIL_DISABLED';
}
if (time() - $this->user->data['user_emailtime'] < $this->config['flood_interval'])
{
return 'FLOOD_EMAIL_LIMIT';
}
return false;
}
public function get_return_message()
{
return sprintf($this->user->lang['RETURN_INDEX'], '<a href="' . append_sid($this->phpbb_root_path . 'index.' . $this->phpEx) . '">', '</a>');
}
public function bind(\phpbb\request\request_interface $request)
{
$this->cc_sender = $request->is_set_post('cc_sender');
$this->body = $request->variable('message', '', true);
}
public function submit(\messenger $messenger)
{
if (!check_form_key('memberlist_email'))
{
$this->errors[] = 'FORM_INVALID';
}
if (!sizeof($this->errors))
{
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_emailtime = ' . time() . '
WHERE user_id = ' . $this->user->data['user_id'];
$this->db->sql_query($sql);
if ($this->cc_sender)
{
$this->message->cc_sender();
}
$this->message->send($messenger, $this->phpEx);
meta_refresh(3, append_sid($this->phpbb_root_path . 'index.' . $this->phpEx));
trigger_error($this->user->lang['EMAIL_SENT'] . '<br /><br />' . $this->get_return_message());
}
}
public function render(\phpbb\template\template $template)
{
add_form_key('memberlist_email');
$template->assign_vars(array(
'ERROR_MESSAGE' => (sizeof($this->errors)) ? implode('<br />', $this->errors) : '',
));
}
}

View File

@@ -0,0 +1,183 @@
<?php
/**
*
* @package message
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\message;
class message
{
protected $server_name;
protected $subject = '';
protected $body = '';
protected $template = '';
protected $template_vars = array();
protected $sender_ip = '';
protected $sender_name = '';
protected $sender_address = '';
protected $sender_lang = '';
protected $sender_id = '';
protected $sender_username = '';
protected $sender_jabber = '';
protected $sender_notify_type = NOTIFY_EMAIL;
protected $recipients;
public function __construct($server_name)
{
$this->server_name = $server_name;
}
public function set_subject($subject)
{
$this->subject = $subject;
}
public function set_body($body)
{
$this->body = $body;
}
public function set_template($template)
{
$this->template = $template;
}
public function set_template_vars($template_vars)
{
$this->template_vars = $template_vars;
}
public function add_recipient_from_user_row(array $user)
{
$this->add_recipient(
$user['username'],
$user['user_email'],
$user['user_lang'],
$user['username'],
$user['user_jabber'],
$user['user_notify_type']
);
}
public function add_recipient($recipient_name, $recipient_address, $recipient_lang, $recipient_notify_type = NOTIFY_EMAIL, $recipient_username = '', $recipient_jabber = '')
{
$this->recipients[] = array(
'name' => $recipient_name,
'address' => $recipient_address,
'lang' => $recipient_lang,
'username' => $recipient_username,
'jabber' => $recipient_jabber,
'notify_type' => $recipient_notify_type,
'to_name' => $recipient_name,
);
}
public function set_sender_from_user($user)
{
$this->set_sender(
$user->ip,
$user->data['username'],
$user->data['user_email'],
$user->lang_name,
$user->data['user_id'],
$user->data['username'],
$user->data['user_jabber']
);
$this->set_sender_notify_type($user->data['user_notify_type']);
}
public function set_sender($sender_ip, $sender_name, $sender_address, $sender_lang = '', $sender_id = 0, $sender_username = '', $sender_jabber = '')
{
$this->sender_ip = $sender_ip;
$this->sender_name = $sender_name;
$this->sender_address = $sender_address;
$this->sender_lang = $sender_lang;
$this->sender_id = $sender_id;
$this->sender_username = $sender_username;
$this->sender_jabber = $sender_jabber;
}
public function set_sender_notify_type($sender_notify_type)
{
$this->sender_notify_type = $sender_notify_type;
}
/**
* Ok, now the same email if CC specified, but without exposing the users email address
*
* @return null
*/
public function cc_sender()
{
if (!sizeof($this->recipients))
{
trigger_error('No email recipients specified');
}
if (!$this->sender_address)
{
trigger_error('No email sender specified');
}
$this->recipients[] = array(
'lang' => $this->sender_lang,
'address' => $this->sender_address,
'name' => $this->sender_name,
'username' => $this->sender_username,
'jabber' => $this->sender_jabber,
'notify_type' => $this->sender_notify_type,
'to_name' => $this->recipients[0]['to_name'],
);
}
public function send(\messenger $messenger, $phpEx)
{
if (!sizeof($this->recipients))
{
return;
}
foreach ($this->recipients as $recipient)
{
$messenger->template($this->template, $recipient['lang']);
$messenger->replyto($this->sender_address);
$messenger->to($recipient['address'], $recipient['name']);
$messenger->im($recipient['jabber'], $recipient['username']);
$messenger->headers('X-AntiAbuse: Board servername - ' . $this->server_name);
$messenger->headers('X-AntiAbuse: User IP - ' . $this->sender_ip);
if ($this->sender_id)
{
$messenger->headers('X-AntiAbuse: User_id - ' . $this->sender_id);
}
if ($this->sender_username)
{
$messenger->headers('X-AntiAbuse: Username - ' . $this->sender_username);
}
$messenger->subject(htmlspecialchars_decode($this->subject));
$messenger->assign_vars(array(
'BOARD_CONTACT' => generate_board_url() . '/memberlist.' . $phpEx . '?mode=contactadmin',
'TO_USERNAME' => htmlspecialchars_decode($recipient['to_name']),
'FROM_USERNAME' => htmlspecialchars_decode($this->sender_name),
'MESSAGE' => htmlspecialchars_decode($this->body))
);
if (sizeof($this->template_vars))
{
$messenger->assign_vars($this->template_vars);
}
$messenger->send($recipient['notify_type']);
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
*
* @package message
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\message;
class topic_form extends form
{
protected $topic_id;
protected $topic_row;
protected $recipient_address;
protected $recipient_name;
protected $recipient_lang;
protected function get_topic_row($topic_id)
{
$sql = 'SELECT forum_id, topic_title
FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . (int) $topic_id;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return $row;
}
public function check_allow()
{
$error = parent::check_allow();
if ($error)
{
return $error;
}
if (!$this->auth->acl_get('u_sendemail'))
{
return 'NO_EMAIL';
}
if (!$this->topic_row)
{
return 'NO_TOPIC';
}
/**
* @todo remove else case when global topics have forum id
*/
if ($this->topic_row['forum_id'])
{
if (!$this->auth->acl_get('f_read', $this->topic_row['forum_id']))
{
return 'SORRY_AUTH_READ';
}
if (!$this->auth->acl_get('f_email', $this->topic_row['forum_id']))
{
return 'NO_EMAIL';
}
}
else
{
// If global announcement, we need to check if the user is able to at least read and email in one forum...
if (!$this->auth->acl_getf_global('f_read'))
{
return 'SORRY_AUTH_READ';
}
if (!$this->auth->acl_getf_global('f_email'))
{
return 'NO_EMAIL';
}
}
return false;
}
public function bind(\phpbb\request\request_interface $request)
{
parent::bind($request);
$this->topic_id = $request->variable('t', 0);
$this->recipient_address = $request->variable('email', '');
$this->recipient_name = $request->variable('name', '', true);
$this->recipient_lang = $request->variable('lang', $this->config['default_lang']);
$this->topic_row = $this->get_topic_row($this->topic_id);
}
public function submit(\messenger $messenger)
{
if (!$this->recipient_address || !preg_match('/^' . get_preg_expression('email') . '$/i', $this->recipient_address))
{
$this->errors[] = $this->user->lang['EMPTY_ADDRESS_EMAIL'];
}
if (!$this->recipient_name)
{
$this->errors[] = $this->user->lang['EMPTY_NAME_EMAIL'];
}
$this->message->set_template('email_notify');
$this->message->set_template_vars(array(
'TOPIC_NAME' => htmlspecialchars_decode($this->topic_row['topic_title']),
'U_TOPIC' => generate_board_url() . '/viewtopic.' . $this->phpEx . '?f=' . $this->topic_row['forum_id'] . '&t=' . $this->topic_id,
));
$this->message->add_recipient(
$this->recipient_name,
$this->recipient_address,
$this->recipient_lang,
NOTIFY_EMAIL
);
$this->message->set_sender_notify_type(NOTIFY_EMAIL);
parent::submit($messenger);
}
public function get_return_message()
{
return sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . append_sid($this->phpbb_root_path . 'viewtopic.' . $this->phpEx, 'f=' . $this->topic_row['forum_id'] . '&amp;t=' . $this->topic_id) . '">', '</a>');
}
public function render(\phpbb\template\template $template)
{
parent::render($template);
$template->assign_vars(array(
'EMAIL' => $this->recipient_address,
'NAME' => $this->recipient_name,
'S_LANG_OPTIONS' => language_select($this->recipient_lang),
'MESSAGE' => $this->body,
'L_EMAIL_BODY_EXPLAIN' => $this->user->lang['EMAIL_TOPIC_EXPLAIN'],
'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=email&amp;t=' . $this->topic_id))
);
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
*
* @package message
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\message;
class user_form extends form
{
protected $recipient_id;
protected $subject;
protected $recipient_row;
public function check_allow()
{
$error = parent::check_allow();
if ($error)
{
return $error;
}
if (!$this->auth->acl_get('u_sendemail'))
{
return 'NO_EMAIL';
}
if ($this->recipient_id == ANONYMOUS || !$this->config['board_email_form'])
{
return 'NO_EMAIL';
}
if (!$this->recipient_row)
{
return 'NO_USER';
}
// Can we send email to this user?
if (!$this->recipient_row['user_allow_viewemail'] && !$this->auth->acl_get('a_user'))
{
return 'NO_EMAIL';
}
return false;
}
protected function get_user_row($user_id)
{
$sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
FROM ' . USERS_TABLE . '
WHERE user_id = ' . ((int) $user_id) . '
AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return $row;
}
public function bind(\phpbb\request\request_interface $request)
{
parent::bind($request);
$this->recipient_id = $request->variable('u', 0);
$this->subject = $request->variable('subject', '', true);
$this->recipient_row = $this->get_user_row($this->recipient_id);
}
public function submit(\messenger $messenger)
{
if (!$this->subject)
{
$this->errors[] = $this->user->lang['EMPTY_SUBJECT_EMAIL'];
}
if (!$this->body)
{
$this->errors[] = $this->user->lang['EMPTY_MESSAGE_EMAIL'];
}
$this->message->set_template('profile_send_email');
$this->message->set_subject($this->subject);
$this->message->set_body($this->body);
$this->message->add_recipient_from_user_row($this->recipient_row);
parent::submit($messenger);
}
public function render(\phpbb\template\template $template)
{
parent::render($template);
$template->assign_vars(array(
'S_SEND_USER' => true,
'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=email&amp;u=' . $this->recipient_id),
'USERNAME' => $this->recipient_row['username'],
'SUBJECT' => $this->subject,
'MESSAGE' => $this->body,
));
}
}