diff options
| author | Nils Adermann <naderman@naderman.de> | 2014-06-09 17:55:25 +0200 |
|---|---|---|
| committer | Nils Adermann <naderman@naderman.de> | 2014-06-09 17:55:25 +0200 |
| commit | b6232aa9b213fbf62f5ce351bc79220daf243cc6 (patch) | |
| tree | 0e169650c4b0bb9476b5f0f917bff6952b574e4d /phpBB/phpbb/message/user_form.php | |
| parent | 0c5af536f1de55b6ee30ab9f193b6ea7637ac5b1 (diff) | |
| parent | 92f43c5371f1f37bd6d77ade2fc5e2804b5cc49f (diff) | |
| download | forums-b6232aa9b213fbf62f5ce351bc79220daf243cc6.tar forums-b6232aa9b213fbf62f5ce351bc79220daf243cc6.tar.gz forums-b6232aa9b213fbf62f5ce351bc79220daf243cc6.tar.bz2 forums-b6232aa9b213fbf62f5ce351bc79220daf243cc6.tar.xz forums-b6232aa9b213fbf62f5ce351bc79220daf243cc6.zip | |
Merge remote-tracking branch 'github-nickvergessen/ticket/10073' into develop-ascraeus
* github-nickvergessen/ticket/10073: (36 commits)
[ticket/10073] Fix button descriptions
[ticket/10073] Do not check disable boxes by default
[ticket/10073] Store values with config_text in the ACP
[ticket/10073] Move config values to config_text
[ticket/10073] Fix request usage
[ticket/10073] Deduplicate template variable names
[ticket/10073] Get service from container
[ticket/10073] Fix more "Contact Us" strings
[ticket/10073] Move template code into the template
[ticket/10073] Make contact page available when board is disabled
[ticket/10073] Change name of the ACP module
[ticket/10073] Deduplicate posting buttons code in ACP
[ticket/10073] Use phpbb_validate_email to verify email address
[ticket/10073] Add tests for new validate_email()
[ticket/10073] Split email validation from email ban and taken checks
[ticket/10073] Deduplicate the if statement
[ticket/10073] Fallback to board_contact when contact page is disabled
[ticket/10073] Remove language string from rebase conflict
[ticket/10073] Add ACP module to add bbcode text for contact admin info
[ticket/10073] Add new configs to the schema
...
Diffstat (limited to 'phpBB/phpbb/message/user_form.php')
| -rw-r--r-- | phpBB/phpbb/message/user_form.php | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/phpBB/phpbb/message/user_form.php b/phpBB/phpbb/message/user_form.php new file mode 100644 index 0000000000..7aa4b94def --- /dev/null +++ b/phpBB/phpbb/message/user_form.php @@ -0,0 +1,134 @@ +<?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 +* Allows users to send emails to other users +* +* @package phpbb\message +*/ +class user_form extends form +{ + /** @var int */ + protected $recipient_id; + /** @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 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 . ')'; + $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(); + 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; + } + + /** + * {inheritDoc} + */ + 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); + } + + /** + * {inheritDoc} + */ + 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); + } + + /** + * {inheritDoc} + */ + 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), + + '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, + )); + } +} |
