-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemaillog.php
90 lines (73 loc) · 1.98 KB
/
emaillog.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
<?php
defined('_JEXEC') or die;
/**
* Plg_system_emaillog plugin.
**/
class PlgSystemEmaillog extends JPlugin
{
protected $db;
protected $app;
protected $autoloadLanguage = true;
public function onSubmitContact(&$contact, &$data)
{
$logtype = $this->params->get('logtype', 'db');
switch ($logtype)
{
case 'file':
$this->writeLogFile($contact, $data);
break;
case 'both':
$this->writeLogFile($contact, $data);
$this->writeLogDB($contact, $data);
break;
default:
$this->writeLogDB($contact, $data);
break;
}
}
private function writeLogDB($contact, $data)
{
$comFields = json_encode($data['com_fields']);
$email = new stdClass;
$email->sent = JFactory::getDate()->toSql();
//check if fields should be logged
if ($this->params->get('log_contactid', 1))
{
$email->contact_id = (int) $contact->id;
}
if ($this->params->get('log_sender_name', 1))
{
$email->contact_name = $data['contact_name'];
}
if ($this->params->get('log_sender_email', 1))
{
$email->contact_email = $data['contact_email'];
}
if ($this->params->get('log_mail_subject', 0))
{
$email->contact_subject = $data['contact_subject'];
}
if ($this->params->get('log_message', 0))
{
$email->contact_message = $data['contact_message'];
}
if ($this->params->get('log_mail_fields', 0))
{
$email->com_fields = $comFields;
}
$this->db->insertObject('#__contact_email_log', $email, 'log_id');
}
private function writeLogFile($contact, $data)
{
//set message entry
$logEmail = array();
$logEmail['status'] = 'emailcontact';
$logEmail['comment'] = JText::sprintf('PLG_SYSTEM_EMAILLOG_FILELOG_TEXTENTRY', $contact->id, $data['contact_email'], $data['contact_subject']);
//set filename in joomla logs-directory
$options = array();
$options['text_file'] = 'email_log.php';
//save to log
JLog::addLogger($options, JLog::INFO);
JLog::add($logEmail['comment'], JLog::INFO, $logEmail['status']);
}
}