-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprivacycheckbox.php
96 lines (81 loc) · 2.15 KB
/
privacycheckbox.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
/**
* PrivacyCheckbox Plugin
*
* @copyright Copyright (C) 2018 - 2020 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;
use Joomla\CMS\Language\Text;
JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR);
/**
* PrivacyCheckbox Plugin
*
* @since 1.0.0
*/
class PlgFieldsPrivacyCheckbox extends FieldsPlugin
{
/**
* Transforms the field into a DOM XML element and appends it as a child on the given parent.
*
* @param stdClass $field The field.
* @param DOMElement $parent The field node parent.
* @param JForm $form The form.
*
* @return DOMElement
*
* @since 1.0.0
*/
public function onCustomFieldsPrepareDom($field, DOMElement $parent, $form)
{
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);
if (!$fieldNode)
{
return $fieldNode;
}
$fieldNode->setAttribute('validate', 'options');
$textValue = htmlspecialchars(Text::_($this->getTextValue($field)), ENT_COMPAT, 'UTF-8');
$option = new DOMElement('option');
$option->nodeValue = $textValue;
$element = $fieldNode->appendChild($option);
$element->setAttribute('value', 'privacycheckbox');
return $fieldNode;
}
/**
* Returns the text value from the given field.
*
* @param stdClass $field The field.
*
* @return string
*
* @since 1.0.0
*/
public function getTextValue($field)
{
// Fetch the options from the plugin
$params = clone $this->params;
$params->merge($field->fieldparams);
return strip_tags($params->get('textvalue', ''), '<a>');
}
/**
* Returns the email text value from the given field.
*
* @param stdClass $field The field.
*
* @return string
*
* @since 1.0.3
*/
public function getEmailTextValue($field)
{
// Fetch the options from the plugin
$params = clone $this->params;
$params->merge($field->fieldparams);
$emailTextValue = $params->get('emailtextvalue', '');
if (empty($emailTextValue))
{
return Text::_('PLG_FIELDS_PRIVACYCHECKBOX_CHECKBOX_CHECKED');
}
return $emailTextValue;
}
}