This repository has been archived by the owner on Oct 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
emailadditionalfields.php
80 lines (70 loc) · 1.74 KB
/
emailadditionalfields.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
<?php defined('_JEXEC') or die;
/**
* File emailadditionalfields.php
* Created 8/1/14 2:29 PM
* Author Matt Thomas | [email protected] | http://betweenbrain.com
* Support https://github.com/betweenbrain/
* Copyright Copyright (C) 2014 betweenbrain llc. All Rights Reserved.
* License GNU GPL v2 or later
*/
/**
* Leverages the mystical onSubmitContact Joomla! plugin event to email additional field data added by plugins.
*
* @package Joomla.Plugin
* @subpackage Contact
* @version 1.0
*/
class plgContactEmailadditionalfields extends JPlugin
{
/**
* @param $contact
* @param array $data The associated data for the form.
*
* @return boolean
*
* @since 1.0
*/
public function onSubmitContact(&$contact, &$data)
{
$data['contact_message'] .= "\n";
foreach ($data as $field => $value)
{
if (!in_array($field, array('contact_name', 'contact_email', 'contact_subject', 'contact_message')))
{
if (is_array($value))
{
foreach ($value as $label => $input)
{
$data['contact_message'] .= "\n" . $this->getLabel($label) . ': ' . $input;
}
}
if (!is_array($value))
{
$data['contact_message'] .= "\n" . $this->getLabel($field) . ': ' . $value;
}
}
}
return $data;
}
/**
* Checks if the JText translation of a dynamically generated constant has a value
*
* @param $label
*
* @return string
*
* @since 1.1.0
*/
private function getLabel($label)
{
$constant = 'PLG_CONTACT_EMAILADDITIONALFIELDS_' . strtoupper($label);
if (JText::_($constant) != $constant)
{
return JText::_('PLG_CONTACT_EMAILADDITIONALFIELDS_' . strtoupper($label));
}
if (JText::_($constant) == $constant)
{
return ucfirst($label);
}
}
}