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