[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

@ -238,6 +238,36 @@ services:
- %core.php_ext% - %core.php_ext%
- %tables.log% - %tables.log%
message.form.admin:
class: phpbb\message\admin_form
arguments:
- @auth
- @config
- @dbal.conn
- @user
- %core.root_path%
- %core.php_ext%
message.form.topic:
class: phpbb\message\topic_form
arguments:
- @auth
- @config
- @dbal.conn
- @user
- %core.root_path%
- %core.php_ext%
message.form.user:
class: phpbb\message\user_form
arguments:
- @auth
- @config
- @dbal.conn
- @user
- %core.root_path%
- %core.php_ext%
notification_manager: notification_manager:
class: phpbb\notification\manager class: phpbb\notification\manager
arguments: arguments:

View file

@ -755,20 +755,21 @@ switch ($mode)
if ($user_id) if ($user_id)
{ {
$form = new phpbb_message_user_form($phpbb_root_path, $phpEx, $user, $auth, $config, $db); $form_name = 'user';
} }
else if ($topic_id) else if ($topic_id)
{ {
$form = new phpbb_message_topic_form($phpbb_root_path, $phpEx, $user, $auth, $config, $db); $form_name = 'topic';
} }
else if ($mode === 'contactadmin') else if ($mode === 'contactadmin')
{ {
$form = new phpbb_message_admin_form($phpbb_root_path, $phpEx, $user, $auth, $config, $db); $form_name = 'admin';
} }
else else
{ {
trigger_error('NO_EMAIL'); trigger_error('NO_EMAIL');
} }
$form = $phpbb_container->get('message.form.' . $form_name);
$form->bind($request); $form->bind($request);
$error = $form->check_allow(); $error = $form->check_allow();
@ -777,7 +778,7 @@ switch ($mode)
trigger_error($error); trigger_error($error);
} }
if (isset($_POST['submit'])) if ($request->is_set_post('submit'))
{ {
$messenger = new messenger(false); $messenger = new messenger(false);
$form->submit($messenger); $form->submit($messenger);

View file

@ -0,0 +1,25 @@
<?php
/**
*
* @package migration
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\db\migration\data\v310;
class contact_admin_form extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return isset($this->config['contact_admin_form_enable']);
}
public function update_data()
{
return array(
array('config.add', array('contact_admin_form_enable', 1)),
);
}
}

View file

@ -1,21 +1,15 @@
<?php <?php
/** /**
* *
* @package email * @package message
* @copyright (c) 2011 phpBB Group * @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
/** namespace phpbb\message;
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_message_admin_form extends phpbb_message_form class admin_form extends form
{ {
protected $subject; protected $subject;
protected $sender_name; protected $sender_name;
@ -37,7 +31,7 @@ class phpbb_message_admin_form extends phpbb_message_form
return false; return false;
} }
public function bind($request) public function bind(\phpbb\request\request_interface $request)
{ {
parent::bind($request); parent::bind($request);
@ -46,7 +40,7 @@ class phpbb_message_admin_form extends phpbb_message_form
$this->sender_name = $request->variable('name', '', true); $this->sender_name = $request->variable('name', '', true);
} }
public function submit(messenger $messenger) public function submit(\messenger $messenger)
{ {
if (!$this->subject) if (!$this->subject)
{ {
@ -99,7 +93,7 @@ class phpbb_message_admin_form extends phpbb_message_form
parent::submit($messenger); parent::submit($messenger);
} }
public function render($template) public function render(\phpbb\template\template $template)
{ {
$template->assign_vars(array( $template->assign_vars(array(
'S_CONTACT_ADMIN' => true, 'S_CONTACT_ADMIN' => true,

View file

@ -2,33 +2,35 @@
/** /**
* *
* @package message * @package message
* @copyright (c) 2011 phpBB Group * @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
/** namespace phpbb\message;
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
abstract class phpbb_message_form abstract class form
{ {
protected $phpbb_root_path; /** @var \phpbb\auth\auth */
protected $phpEx;
protected $user;
protected $auth; protected $auth;
/** @var \phpbb\config\config */
protected $config; protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db; protected $db;
/** @var \phpbb\user */
protected $user;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $phpEx;
protected $errors; protected $errors;
protected $message; protected $message;
protected $cc_sender; protected $cc_sender;
protected $body; protected $body;
public function __construct($phpbb_root_path, $phpEx, $user, $auth, $config, $db) 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->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx; $this->phpEx = $phpEx;
@ -39,7 +41,7 @@ abstract class phpbb_message_form
$this->errors = array(); $this->errors = array();
$this->message = new phpbb_message($config['server_name']); $this->message = new \phpbb\message\message($config['server_name']);
$this->message->set_sender_from_user($this->user); $this->message->set_sender_from_user($this->user);
} }
@ -76,13 +78,13 @@ abstract class phpbb_message_form
return sprintf($this->user->lang['RETURN_INDEX'], '<a href="' . append_sid($this->phpbb_root_path . 'index.' . $this->phpEx) . '">', '</a>'); return sprintf($this->user->lang['RETURN_INDEX'], '<a href="' . append_sid($this->phpbb_root_path . 'index.' . $this->phpEx) . '">', '</a>');
} }
public function bind(phpbb_request_interface $request) public function bind(\phpbb\request\request_interface $request)
{ {
$this->cc_sender = $request->is_set_post('cc_sender'); $this->cc_sender = $request->is_set_post('cc_sender');
$this->body = $request->variable('message', '', true); $this->body = $request->variable('message', '', true);
} }
public function submit(messenger $messenger) public function submit(\messenger $messenger)
{ {
if (!check_form_key('memberlist_email')) if (!check_form_key('memberlist_email'))
{ {
@ -94,21 +96,21 @@ abstract class phpbb_message_form
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_emailtime = ' . time() . ' SET user_emailtime = ' . time() . '
WHERE user_id = ' . $this->user->data['user_id']; WHERE user_id = ' . $this->user->data['user_id'];
$result = $this->db->sql_query($sql); $this->db->sql_query($sql);
if ($this->cc_sender) if ($this->cc_sender)
{ {
$this->message->cc_sender(); $this->message->cc_sender();
} }
$this->message->send($messenger); $this->message->send($messenger, $this->phpEx);
meta_refresh(3, append_sid($this->phpbb_root_path . 'index.' . $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()); trigger_error($this->user->lang['EMAIL_SENT'] . '<br /><br />' . $this->get_return_message());
} }
} }
public function render($template) public function render(\phpbb\template\template $template)
{ {
add_form_key('memberlist_email'); add_form_key('memberlist_email');

View file

@ -2,20 +2,14 @@
/** /**
* *
* @package message * @package message
* @copyright (c) 2011 phpBB Group * @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
/** namespace phpbb\message;
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_message class message
{ {
protected $server_name; protected $server_name;
@ -116,8 +110,11 @@ class phpbb_message
$this->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 * Ok, now the same email if CC specified, but without exposing the users email address
*
* @return null
*/
public function cc_sender() public function cc_sender()
{ {
if (!sizeof($this->recipients)) if (!sizeof($this->recipients))
@ -140,7 +137,7 @@ class phpbb_message
); );
} }
public function send(messenger $messenger) public function send(\messenger $messenger, $phpEx)
{ {
if (!sizeof($this->recipients)) if (!sizeof($this->recipients))
{ {

View file

@ -2,20 +2,14 @@
/** /**
* *
* @package message * @package message
* @copyright (c) 2011 phpBB Group * @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
/** namespace phpbb\message;
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_message_topic_form extends phpbb_message_form class topic_form extends form
{ {
protected $topic_id; protected $topic_id;
@ -86,7 +80,7 @@ class phpbb_message_topic_form extends phpbb_message_form
return false; return false;
} }
public function bind($request) public function bind(\phpbb\request\request_interface $request)
{ {
parent::bind($request); parent::bind($request);
@ -98,7 +92,7 @@ class phpbb_message_topic_form extends phpbb_message_form
$this->topic_row = $this->get_topic_row($this->topic_id); $this->topic_row = $this->get_topic_row($this->topic_id);
} }
public function submit(messenger $messenger) public function submit(\messenger $messenger)
{ {
if (!$this->recipient_address || !preg_match('/^' . get_preg_expression('email') . '$/i', $this->recipient_address)) if (!$this->recipient_address || !preg_match('/^' . get_preg_expression('email') . '$/i', $this->recipient_address))
{ {
@ -128,12 +122,12 @@ class phpbb_message_topic_form extends phpbb_message_form
parent::submit($messenger); parent::submit($messenger);
} }
protected function get_return_message() 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>'); 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($template) public function render(\phpbb\template\template $template)
{ {
parent::render($template); parent::render($template);

View file

@ -2,23 +2,18 @@
/** /**
* *
* @package message * @package message
* @copyright (c) 2011 phpBB Group * @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
/** namespace phpbb\message;
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_message_user_form extends phpbb_message_form class user_form extends form
{ {
protected $recipient_id; protected $recipient_id;
protected $subject; protected $subject;
protected $recipient_row;
public function check_allow() public function check_allow()
{ {
@ -65,7 +60,7 @@ class phpbb_message_user_form extends phpbb_message_form
return $row; return $row;
} }
public function bind($request) public function bind(\phpbb\request\request_interface $request)
{ {
parent::bind($request); parent::bind($request);
@ -75,7 +70,7 @@ class phpbb_message_user_form extends phpbb_message_form
$this->recipient_row = $this->get_user_row($this->recipient_id); $this->recipient_row = $this->get_user_row($this->recipient_id);
} }
public function submit(messenger $messenger) public function submit(\messenger $messenger)
{ {
if (!$this->subject) if (!$this->subject)
{ {
@ -95,7 +90,7 @@ class phpbb_message_user_form extends phpbb_message_form
parent::submit($messenger); parent::submit($messenger);
} }
public function render($template) public function render(\phpbb\template\template $template)
{ {
parent::render($template); parent::render($template);