From fffb07fd91b42d64e71e16a13bcdde87114fad19 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 11 Apr 2014 18:09:25 +0200 Subject: [ticket/10073] Use namespaces and fix all class names PHPBB3-10073 --- phpBB/phpbb/message/user_form.php | 106 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 phpBB/phpbb/message/user_form.php (limited to 'phpBB/phpbb/message/user_form.php') diff --git a/phpBB/phpbb/message/user_form.php b/phpBB/phpbb/message/user_form.php new file mode 100644 index 0000000000..a76d553b7c --- /dev/null +++ b/phpBB/phpbb/message/user_form.php @@ -0,0 +1,106 @@ +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&u=' . $this->recipient_id), + + 'USERNAME' => $this->recipient_row['username'], + 'SUBJECT' => $this->subject, + 'MESSAGE' => $this->body, + )); + } +} -- cgit v1.2.1 From 67cf0a912c8ed24c7466163fa409e8154082e1df Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 13 Apr 2014 23:24:10 +0200 Subject: [ticket/10073] Add doc blocks to new classes PHPBB3-10073 --- phpBB/phpbb/message/user_form.php | 55 +++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/message/user_form.php') diff --git a/phpBB/phpbb/message/user_form.php b/phpBB/phpbb/message/user_form.php index a76d553b7c..5e98590c58 100644 --- a/phpBB/phpbb/message/user_form.php +++ b/phpBB/phpbb/message/user_form.php @@ -9,12 +9,43 @@ namespace phpbb\message; +/** +* Class user_form +* Allows users to send emails to other users +* +* @package phpbb\message +*/ class user_form extends form { + /** @var int */ protected $recipient_id; - protected $subject; + /** @var array */ protected $recipient_row; + /** @var string */ + protected $subject; + /** + * Get the data of the recipient + * + * @param int $user_id + * @return false|array false if the user does not exist, array otherwise + */ + 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; + } + + /** + * {inheritDoc} + */ public function check_allow() { $error = parent::check_allow(); @@ -47,19 +78,9 @@ class user_form extends form 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; - } - + /** + * {inheritDoc} + */ public function bind(\phpbb\request\request_interface $request) { parent::bind($request); @@ -70,6 +91,9 @@ class user_form extends form $this->recipient_row = $this->get_user_row($this->recipient_id); } + /** + * {inheritDoc} + */ public function submit(\messenger $messenger) { if (!$this->subject) @@ -90,6 +114,9 @@ class user_form extends form parent::submit($messenger); } + /** + * {inheritDoc} + */ public function render(\phpbb\template\template $template) { parent::render($template); -- cgit v1.2.1 From 84a02f5cef6cd2cc4b8fb5e9e083e848df8d2a48 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 13:28:38 +0200 Subject: [ticket/10073] Use get_username_string and correctly sprintf for languages PHPBB3-10073 --- phpBB/phpbb/message/user_form.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/message/user_form.php') diff --git a/phpBB/phpbb/message/user_form.php b/phpBB/phpbb/message/user_form.php index 5e98590c58..7aa4b94def 100644 --- a/phpBB/phpbb/message/user_form.php +++ b/phpBB/phpbb/message/user_form.php @@ -32,7 +32,7 @@ class user_form extends form */ protected function get_user_row($user_id) { - $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type + $sql = 'SELECT user_id, username, user_colour, 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 . ')'; @@ -125,7 +125,8 @@ class user_form extends form 'S_SEND_USER' => true, 'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=email&u=' . $this->recipient_id), - 'USERNAME' => $this->recipient_row['username'], + 'L_SEND_EMAIL_USER' => $this->user->lang('SEND_EMAIL_USER', $this->recipient_row['username']), + 'USERNAME_FULL' => get_username_string('full', $this->recipient_row['user_id'], $this->recipient_row['username'], $this->recipient_row['user_colour']), 'SUBJECT' => $this->subject, 'MESSAGE' => $this->body, )); -- cgit v1.2.1