diff options
| author | Nils Adermann <naderman@naderman.de> | 2011-06-05 09:40:43 +0200 | 
|---|---|---|
| committer | Joas Schilling <nickvergessen@gmx.de> | 2014-05-29 02:14:27 +0200 | 
| commit | d52f34f5ec5d006ec7e610e1c72266df21e70ac7 (patch) | |
| tree | 31a105436f12a23a13e4af995a19ff43e8d02191 /phpBB/includes/message/topic_form.php | |
| parent | 624c0e4ef6b638adb325e72158ac3a7e5f66b0bf (diff) | |
| download | forums-d52f34f5ec5d006ec7e610e1c72266df21e70ac7.tar forums-d52f34f5ec5d006ec7e610e1c72266df21e70ac7.tar.gz forums-d52f34f5ec5d006ec7e610e1c72266df21e70ac7.tar.bz2 forums-d52f34f5ec5d006ec7e610e1c72266df21e70ac7.tar.xz forums-d52f34f5ec5d006ec7e610e1c72266df21e70ac7.zip  | |
[ticket/10073] Add a contact administrators page and refactor email forms.
The message to be displayed on top of the email form cannot be configured yet.
PHPBB3-10073
Diffstat (limited to 'phpBB/includes/message/topic_form.php')
| -rw-r--r-- | phpBB/includes/message/topic_form.php | 150 | 
1 files changed, 150 insertions, 0 deletions
diff --git a/phpBB/includes/message/topic_form.php b/phpBB/includes/message/topic_form.php new file mode 100644 index 0000000000..0dbfdb0ca2 --- /dev/null +++ b/phpBB/includes/message/topic_form.php @@ -0,0 +1,150 @@ +<?php +/** +* +* @package message +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ +	exit; +} + +class phpbb_message_topic_form extends phpbb_message_form +{ +	protected $topic_id; + +	protected $topic_row; +	protected $recipient_address; +	protected $recipient_name; +	protected $recipient_lang; + +	protected function get_topic_row($topic_id) +	{ +		$sql = 'SELECT forum_id, topic_title +			FROM ' . TOPICS_TABLE . ' +			WHERE topic_id = ' . (int) $topic_id; +		$result = $this->db->sql_query($sql); +		$row = $this->db->sql_fetchrow($result); +		$this->db->sql_freeresult($result); + +		return $row; +	} + +	public function check_allow() +	{ +		$error = parent::check_allow(); +		if ($error) +		{ +			return $error; +		} + +		if (!$this->auth->acl_get('u_sendemail')) +		{ +			return 'NO_EMAIL'; +		} + +		if (!$this->topic_row) +		{ +			return 'NO_TOPIC'; +		} + +		/** +		* @todo remove else case when global topics have forum id +		*/ +		if ($this->topic_row['forum_id']) +		{ +			if (!$this->auth->acl_get('f_read', $this->topic_row['forum_id'])) +			{ +				return 'SORRY_AUTH_READ'; +			} + +			if (!$this->auth->acl_get('f_email', $this->topic_row['forum_id'])) +			{ +				return 'NO_EMAIL'; +			} +		} +		else +		{ +			// If global announcement, we need to check if the user is able to at least read and email in one forum... +			if (!$this->auth->acl_getf_global('f_read')) +			{ +				return 'SORRY_AUTH_READ'; +			} + +			if (!$this->auth->acl_getf_global('f_email')) +			{ +				return 'NO_EMAIL'; +			} +		} + +		return false; +	} + +	public function bind($request) +	{ +		parent::bind($request); + +		$this->topic_id = $request->variable('t', 0); +		$this->recipient_address = $request->variable('email', ''); +		$this->recipient_name = $request->variable('name', '', true); +		$this->recipient_lang = $request->variable('lang', $this->config['default_lang']); + +		$this->topic_row = $this->get_topic_row($this->topic_id); +	} + +	public function submit(messenger $messenger) +	{ +		if (!$this->recipient_address || !preg_match('/^' . get_preg_expression('email') . '$/i', $this->recipient_address)) +		{ +			$this->errors[] = $this->user->lang['EMPTY_ADDRESS_EMAIL']; +		} + +		if (!$this->recipient_name) +		{ +			$this->errors[] = $this->user->lang['EMPTY_NAME_EMAIL']; +		} + + +		$this->message->set_template('email_notify'); +		$this->message->set_template_vars(array( +			'TOPIC_NAME'	=> htmlspecialchars_decode($this->topic_row['topic_title']), +			'U_TOPIC'		=> generate_board_url() . '/viewtopic.' . $this->phpEx . '?f=' . $this->topic_row['forum_id'] . '&t=' . $this->topic_id, +		)); + +		$this->message->add_recipient( +			$this->recipient_name, +			$this->recipient_address, +			$this->recipient_lang, +			NOTIFY_EMAIL +		); +		$this->message->set_sender_notify_type(NOTIFY_EMAIL); + +		parent::submit($messenger); +	} + +	protected function get_return_message() +	{ +		return sprintf($this->user->lang['RETURN_TOPIC'],  '<a href="' . append_sid($this->phpbb_root_path . 'viewtopic.' . $this->phpEx, 'f=' . $this->topic_row['forum_id'] . '&t=' . $this->topic_id) . '">', '</a>'); +	} + +	public function render($template) +	{ +		parent::render($template); + +		$template->assign_vars(array( +			'EMAIL'				=> $this->recipient_address, +			'NAME'				=> $this->recipient_name, +			'S_LANG_OPTIONS'	=> language_select($this->recipient_lang), +			'MESSAGE'			=> $this->body, + +			'L_EMAIL_BODY_EXPLAIN'	=> $this->user->lang['EMAIL_TOPIC_EXPLAIN'], +			'S_POST_ACTION'			=> append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=email&t=' . $this->topic_id)) +		); +	} +}  | 
