Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
form
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 8
240
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 get_page_title
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_template_file
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 check_allow
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 get_return_message
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 bind
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 submit
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
30
 render
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
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
14namespace phpbb\message;
15
16/**
17* Abstract class form
18*/
19abstract class form
20{
21    /** @var \phpbb\auth\auth */
22    protected $auth;
23    /** @var \phpbb\config\config */
24    protected $config;
25    /** @var \phpbb\controller\helper */
26    protected $controller_helper;
27    /** @var \phpbb\db\driver\driver_interface */
28    protected $db;
29    /** @var \phpbb\message\message */
30    protected $message;
31    /** @var \phpbb\user */
32    protected $user;
33
34    /** @var string */
35    protected $phpbb_root_path;
36    /** @var string */
37    protected $phpEx;
38
39    /** @var array */
40    protected $errors = array();
41    /** @var bool */
42    protected $cc_sender;
43    /** @var string */
44    protected $body;
45
46    /**
47    * Construct
48    *
49    * @param \phpbb\auth\auth $auth
50    * @param \phpbb\config\config $config
51    * @param \phpbb\db\driver\driver_interface $db
52    * @param \phpbb\controller\helper $controller_helper
53    * @param \phpbb\user $user
54    * @param string $phpbb_root_path
55    * @param string $phpEx
56    */
57    public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $controller_helper, \phpbb\user $user, $phpbb_root_path, $phpEx)
58    {
59        $this->phpbb_root_path = $phpbb_root_path;
60        $this->phpEx = $phpEx;
61        $this->user = $user;
62        $this->auth = $auth;
63        $this->config = $config;
64        $this->controller_helper = $controller_helper;
65        $this->db = $db;
66
67        $this->message = new message($config['server_name']);
68        $this->message->set_sender_from_user($this->user);
69    }
70
71    /**
72    * Returns the title for the email form page
73    *
74    * @return string
75    */
76    public function get_page_title()
77    {
78        return $this->user->lang['SEND_EMAIL'];
79    }
80
81    /**
82    * Returns the file name of the form template
83    *
84    * @return string
85    */
86    public function get_template_file()
87    {
88        return 'memberlist_email.html';
89    }
90
91    /**
92    * Checks whether the user is allowed to use the form
93    *
94    * @return false|string    Error string if not allowed, false otherwise
95    */
96    public function check_allow()
97    {
98        if (!$this->config['email_enable'])
99        {
100            return 'EMAIL_DISABLED';
101        }
102
103        if (time() - $this->user->data['user_emailtime'] < $this->config['flood_interval'])
104        {
105            return 'FLOOD_EMAIL_LIMIT';
106        }
107
108        return false;
109    }
110
111    /**
112    * Get the return link after the message has been sent
113    *
114    * @return string
115    */
116    public function get_return_message()
117    {
118        return sprintf($this->user->lang['RETURN_INDEX'], '<a href="' . $this->controller_helper->route('phpbb_index_controller') . '">', '</a>');
119    }
120
121    /**
122    * Bind the values of the request to the form
123    *
124    * @param \phpbb\request\request_interface $request
125    * @return void
126    */
127    public function bind(\phpbb\request\request_interface $request)
128    {
129        $this->cc_sender = $request->is_set_post('cc_sender');
130        $this->body = $request->variable('message', '', true);
131    }
132
133    /**
134    * Submit form, generate the email and send it
135    *
136    * @param \phpbb\di\service_collection $messenger
137    * @return void
138    */
139    public function submit(\phpbb\di\service_collection $messenger)
140    {
141        if (!check_form_key('memberlist_email'))
142        {
143            $this->errors[] = $this->user->lang('FORM_INVALID');
144        }
145
146        if (!count($this->errors))
147        {
148            $sql = 'UPDATE ' . USERS_TABLE . '
149                SET user_emailtime = ' . time() . '
150                WHERE user_id = ' . $this->user->data['user_id'];
151            $this->db->sql_query($sql);
152
153            if ($this->cc_sender && $this->user->data['is_registered'])
154            {
155                $this->message->cc_sender();
156            }
157
158            $this->message->send($messenger, phpbb_get_board_contact($this->config, $this->phpEx));
159
160            meta_refresh(3, $this->controller_helper->route('phpbb_index_controller'));
161            trigger_error($this->user->lang['EMAIL_SENT'] . '<br /><br />' . $this->get_return_message());
162        }
163    }
164
165    /**
166    * Render the template of the form
167    *
168    * @param \phpbb\template\template $template
169    * @return void
170    */
171    public function render(\phpbb\template\template $template)
172    {
173        add_form_key('memberlist_email');
174
175        $template->assign_vars(array(
176            'ERROR_MESSAGE'        => (count($this->errors)) ? implode('<br />', $this->errors) : '',
177        ));
178    }
179}