Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| topic_form | |
0.00% |
0 / 60 |
|
0.00% |
0 / 6 |
240 | |
0.00% |
0 / 1 |
| get_topic_row | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| check_allow | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
56 | |||
| bind | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| submit | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
| get_return_message | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| render | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\message; |
| 15 | |
| 16 | /** |
| 17 | * Class topic_form |
| 18 | * Form used to send topics as notification emails |
| 19 | */ |
| 20 | class topic_form extends form |
| 21 | { |
| 22 | /** @var int */ |
| 23 | protected $topic_id; |
| 24 | /** @var array */ |
| 25 | protected $topic_row; |
| 26 | /** @var string */ |
| 27 | protected $recipient_address; |
| 28 | /** @var string */ |
| 29 | protected $recipient_name; |
| 30 | /** @var string */ |
| 31 | protected $recipient_lang; |
| 32 | |
| 33 | /** |
| 34 | * Get the data of the topic |
| 35 | * |
| 36 | * @param int $topic_id |
| 37 | * @return false|array false if the topic does not exist, array otherwise |
| 38 | */ |
| 39 | protected function get_topic_row($topic_id) |
| 40 | { |
| 41 | $sql = 'SELECT forum_id, topic_title |
| 42 | FROM ' . TOPICS_TABLE . ' |
| 43 | WHERE topic_id = ' . (int) $topic_id; |
| 44 | $result = $this->db->sql_query($sql); |
| 45 | $row = $this->db->sql_fetchrow($result); |
| 46 | $this->db->sql_freeresult($result); |
| 47 | |
| 48 | return $row; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * {inheritDoc} |
| 53 | */ |
| 54 | public function check_allow() |
| 55 | { |
| 56 | $error = parent::check_allow(); |
| 57 | if ($error) |
| 58 | { |
| 59 | return $error; |
| 60 | } |
| 61 | |
| 62 | if (!$this->auth->acl_get('u_sendemail')) |
| 63 | { |
| 64 | return 'NO_EMAIL'; |
| 65 | } |
| 66 | |
| 67 | if (!$this->topic_row) |
| 68 | { |
| 69 | return 'NO_TOPIC'; |
| 70 | } |
| 71 | |
| 72 | if (!$this->auth->acl_get('f_read', $this->topic_row['forum_id'])) |
| 73 | { |
| 74 | if ($this->user->data['user_id'] != ANONYMOUS) |
| 75 | { |
| 76 | send_status_line(403, 'Forbidden'); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | send_status_line(401, 'Unauthorized'); |
| 81 | } |
| 82 | return 'SORRY_AUTH_READ'; |
| 83 | } |
| 84 | |
| 85 | if (!$this->auth->acl_get('f_email', $this->topic_row['forum_id'])) |
| 86 | { |
| 87 | return 'NO_EMAIL'; |
| 88 | } |
| 89 | |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * {inheritDoc} |
| 95 | */ |
| 96 | public function bind(\phpbb\request\request_interface $request) |
| 97 | { |
| 98 | parent::bind($request); |
| 99 | |
| 100 | $this->topic_id = $request->variable('t', 0); |
| 101 | $this->recipient_address = $request->variable('email', ''); |
| 102 | $this->recipient_name = $request->variable('name', '', true); |
| 103 | $this->recipient_lang = $request->variable('lang', $this->config['default_lang']); |
| 104 | |
| 105 | $this->topic_row = $this->get_topic_row($this->topic_id); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * {inheritDoc} |
| 110 | */ |
| 111 | public function submit(\phpbb\di\service_collection $messenger) |
| 112 | { |
| 113 | if (!$this->recipient_address || !preg_match('/^' . get_preg_expression('email') . '$/i', $this->recipient_address)) |
| 114 | { |
| 115 | $this->errors[] = $this->user->lang['EMPTY_ADDRESS_EMAIL']; |
| 116 | } |
| 117 | |
| 118 | if (!$this->recipient_name) |
| 119 | { |
| 120 | $this->errors[] = $this->user->lang['EMPTY_NAME_EMAIL']; |
| 121 | } |
| 122 | |
| 123 | $this->message->set_template('email_notify'); |
| 124 | $this->message->set_template_vars(array( |
| 125 | 'TOPIC_NAME' => html_entity_decode($this->topic_row['topic_title'], ENT_COMPAT), |
| 126 | 'U_TOPIC' => generate_board_url() . '/viewtopic.' . $this->phpEx . '?t=' . $this->topic_id, |
| 127 | )); |
| 128 | $this->message->set_body($this->body); |
| 129 | $this->message->add_recipient( |
| 130 | $this->recipient_name, |
| 131 | $this->recipient_address, |
| 132 | $this->recipient_lang |
| 133 | ); |
| 134 | |
| 135 | parent::submit($messenger); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * {inheritDoc} |
| 140 | */ |
| 141 | public function get_return_message() |
| 142 | { |
| 143 | return sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . append_sid($this->phpbb_root_path . 'viewtopic.' . $this->phpEx, 't=' . $this->topic_id) . '">', '</a>'); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * {inheritDoc} |
| 148 | */ |
| 149 | public function render(\phpbb\template\template $template) |
| 150 | { |
| 151 | parent::render($template); |
| 152 | |
| 153 | $this->user->add_lang('viewtopic'); |
| 154 | |
| 155 | $lang_options = phpbb_language_select($this->db, $this->recipient_lang); |
| 156 | |
| 157 | $template->assign_vars(array( |
| 158 | 'EMAIL' => $this->recipient_address, |
| 159 | 'NAME' => $this->recipient_name, |
| 160 | 'LANG_OPTIONS' => [ |
| 161 | 'id' => 'lang', |
| 162 | 'name' => 'lang', |
| 163 | 'options' => $lang_options, |
| 164 | ], |
| 165 | 'MESSAGE' => $this->body, |
| 166 | |
| 167 | 'L_EMAIL_BODY_EXPLAIN' => $this->user->lang['EMAIL_TOPIC_EXPLAIN'], |
| 168 | 'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=email&t=' . $this->topic_id)) |
| 169 | ); |
| 170 | } |
| 171 | } |