mailto.php
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Mailto model class.
*
* @since 3.8.9
*/
class MailtoModelMailto extends JModelForm
{
/**
* Method to get the mailto form.
*
* The base form is loaded from XML and then an event is fired
* for users plugins to extend the form with extra fields.
*
* @param array $data An optional array of data for the form to interrogate.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return JForm A JForm object on success, false on failure
*
* @since 3.8.9
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_mailto.mailto', 'mailto', array('load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return array The default data is an empty array.
*
* @since 3.8.9
*/
protected function loadFormData()
{
$user = JFactory::getUser();
$app = JFactory::getApplication();
$data = $app->getUserState('mailto.mailto.form.data', array());
$data['link'] = urldecode($app->input->get('link', '', 'BASE64'));
if ($data['link'] == '')
{
JError::raiseError(403, JText::_('COM_MAILTO_LINK_IS_MISSING'));
return false;
}
// Load with previous data, if it exists
$data['sender'] = $app->input->post->getString('sender', '');
$data['subject'] = $app->input->post->getString('subject', '');
$data['emailfrom'] = JStringPunycode::emailToPunycode($app->input->post->getString('emailfrom', ''));
$data['emailto'] = JStringPunycode::emailToPunycode($app->input->post->getString('emailto', ''));
if (!$user->guest)
{
$data['sender'] = $user->name;
$data['emailfrom'] = $user->email;
}
$app->setUserState('mailto.mailto.form.data', $data);
$this->preprocessData('com_mailto.mailto', $data);
return $data;
}
/**
* Get the request data
*
* @return array The requested data
*
* @since 3.8.9
*/
public function getData()
{
$input = JFactory::getApplication()->input;
$data['emailto'] = $input->get('emailto', '', 'string');
$data['sender'] = $input->get('sender', '', 'string');
$data['emailfrom'] = $input->get('emailfrom', '', 'string');
$data['subject'] = $input->get('subject', '', 'string');
$data['consentbox'] = $input->get('consentbox', '', 'string');
return $data;
}
}