-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts_sendgrid_event_webhook_notifier.php
78 lines (66 loc) · 1.95 KB
/
mod.ts_sendgrid_event_webhook_notifier.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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExpressionEngine - by EllisLab
*
* @package ExpressionEngine
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc.
* @license http://expressionengine.com/user_guide/license.html
* @link http://expressionengine.com
* @since Version 2.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* TS SendGrid Event Webhook Notifier Module Front End File
*
* @package ExpressionEngine
* @subpackage Addons
* @category Module
* @author Michael Pasqualone
* @link https://www.mpasqualone.com
*/
class Ts_sendgrid_event_webhook_notifier {
public $return_data;
/**
* Constructor
*/
public function __construct()
{
$this->EE =& get_instance();
}
// ----------------------------------------------------------------
public function event_webhook()
{
/* Get raw POST'ed JSON data */
$data = json_decode( file_get_contents('php://input') );
/* Debugging */
/* $fh = fopen('/mnt/san-cbr/internal/dev/frameworks/expressionengine2/totalserve.net.au/system/expressionengine/third_party/ts_sendgrid_event_webhook_notifier/events.log', 'a+');
if ( $fh )
{
fwrite($fh, print_r($data, true));
fclose($fh);
} */
foreach($data as $event)
{
$data = array(
'email' => $event->email,
'timestamp' => $event->timestamp,
'smtp-id' => $event->{'smtp-id'},
'event' => $event->event,
'subject' => $event->subject
);
// If it's an open, event
switch ($event->event)
{
case 'open':
$data['ipv4'] = ip2long ( $event->ip );
$data['useragent'] = $event->useragent;
break;
}
ee()->db->insert('ts_sendgrid_events', $data);
}
}
}
/* End of file mod.ts_sendgrid_event_webhook_notifier.php */
/* Location: /system/expressionengine/third_party/ts_sendgrid_event_webhook_notifier/mod.ts_sendgrid_event_webhook_notifier.php */