This repository has been archived by the owner on Nov 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsentbox.php
96 lines (86 loc) · 2.08 KB
/
consentbox.php
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
<?php
/**
* ConsentBox Plugin
*
* @copyright Copyright (C) 2018 Tobias Zulauf All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
*/
defined('_JEXEC') or die;
/**
* A consent box plugin
*
* @since 1.0
*/
class PlgContentConsentBox extends JPlugin
{
/**
* @var JApplicationSite $app
*/
protected $app;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 1.0
*/
protected $autoloadLanguage = true;
/**
* Constructor
*
* @param object &$subject The object to observe
* @param array $config An array that holds the plugin configuration
*
* @since 1.0
*/
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
// Get the application if not done by JPlugin. This will happen with Joomla 2.5.
if (!$this->app)
{
$this->app = JFactory::getApplication();
}
JFormHelper::addFieldPath(__DIR__ . '/field');
}
/**
* Adds additional fields to the user editing form
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 1.0
*/
public function onContentPrepareForm($form, $data)
{
if ($this->app->isAdmin() || $form->getName() !== 'com_contact.contact')
{
return true;
}
// Add the registration fields to the form.
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('consentbox');
return true;
}
/**
* onSubmitContact
*
* @param object $contact contact
* @param array &$data Data from the form
*
* @return void
*
* @since 1.0
*/
public function onSubmitContact(&$contact, &$data)
{
if ($this->params->get('consent_message', 0) == 1)
{
$data['contact_message'] .= "\r\n\r\n";
$data['contact_message'] .= '--------';
$data['contact_message'] .= "\r\n\r\n";
$data['contact_message'] .= JText::_('PLG_CONTENT_CONSENTBOX_CONSENT_MESSAGE_TEXT');
}
}
}