|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Escopecz\MauticFormSubmit\Mautic; |
|
4
|
|
|
|
|
5
|
|
|
use Escopecz\MauticFormSubmit\Cookie as StandardCookie; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Helper class to get cookie properties specific to Mautic |
|
9
|
|
|
*/ |
|
10
|
|
|
class Cookie extends StandardCookie |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Holds Mautic session ID defined by PHP |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
const MAUTIC_DEVICE_ID = 'mautic_device_id'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Holds Mautic session ID defined by PHP |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
const MAUTIC_SESSION_ID = 'mautic_session_id'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Holds Mautic session ID defined by JS |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
const MTC_SID = 'mtc_sid'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Holds Mautic Contact ID defined by JS |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
18 |
|
const MTC_ID = 'mtc_id'; |
|
39
|
|
|
|
|
40
|
18 |
|
/** |
|
41
|
12 |
|
* Get Mautic Contact ID from Cookie |
|
42
|
10 |
|
* |
|
43
|
|
|
* @return int|null |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getContactId() |
|
46
|
10 |
|
{ |
|
47
|
|
|
if ($mtcId = $this->getInt(self::MTC_ID)) { |
|
48
|
|
|
return $mtcId; |
|
49
|
|
|
} elseif ($mauticSessionId = $this->getSessionId()) { |
|
50
|
|
|
return $this->getInt($mauticSessionId); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
12 |
|
* Set Mautic Contact ID cookies |
|
58
|
|
|
* Note: Call setMauticSessionId prior to this |
|
59
|
12 |
|
* |
|
60
|
|
|
* @param int $contactId |
|
61
|
12 |
|
* |
|
62
|
2 |
|
* @return Cookie |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setContactId($contactId) |
|
65
|
12 |
|
{ |
|
66
|
|
|
$this->set(self::MTC_ID, $contactId); |
|
67
|
|
|
|
|
68
|
|
|
if ($sessionId = $this->getSessionId()) { |
|
69
|
|
|
$this->set($sessionId, $contactId); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
6 |
|
} |
|
74
|
|
|
|
|
75
|
6 |
|
/** |
|
76
|
|
|
* Unet Mautic Contact ID cookies |
|
77
|
6 |
|
* |
|
78
|
|
|
* @return Cookie |
|
79
|
|
|
*/ |
|
80
|
|
|
public function unsetContactId() |
|
81
|
6 |
|
{ |
|
82
|
|
|
$this->clear(self::MTC_ID); |
|
83
|
|
|
|
|
84
|
|
|
if ($sessionId = $this->getSessionId()) { |
|
85
|
|
|
$this->clear($sessionId); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
24 |
|
} |
|
90
|
|
|
|
|
91
|
24 |
|
/** |
|
92
|
8 |
|
* Returns Mautic session ID if it exists in the cookie |
|
93
|
|
|
* |
|
94
|
|
|
* @return string|null |
|
95
|
24 |
|
*/ |
|
96
|
4 |
|
public function getSessionId() |
|
97
|
|
|
{ |
|
98
|
|
|
if ($mauticSessionId = $this->get(self::MAUTIC_SESSION_ID)) { |
|
99
|
24 |
|
return $mauticSessionId; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if ($mauticSessionId = $this->get(self::MTC_SID)) { |
|
103
|
|
|
return $mauticSessionId; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return null; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
6 |
|
/** |
|
110
|
|
|
* Set Mautic Session ID cookies |
|
111
|
6 |
|
* |
|
112
|
6 |
|
* @param string $sessionId |
|
113
|
|
|
* |
|
114
|
6 |
|
* @return Cookie |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setSessionId($sessionId) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->set(self::MAUTIC_SESSION_ID, $sessionId); |
|
119
|
|
|
$this->set(self::MTC_SID, $sessionId); |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
6 |
|
} |
|
123
|
|
|
|
|
124
|
6 |
|
/** |
|
125
|
6 |
|
* Set Mautic Device ID cookies |
|
126
|
|
|
* |
|
127
|
6 |
|
* @param string $deviceId |
|
128
|
|
|
* |
|
129
|
|
|
* @return Cookie |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setDeviceId($deviceId) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->set(self::MAUTIC_DEVICE_ID, $deviceId); |
|
134
|
|
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Unset Mautic Session ID cookies |
|
140
|
|
|
* |
|
141
|
|
|
* @return Cookie |
|
142
|
|
|
*/ |
|
143
|
|
|
public function unsetSessionId() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->clear(self::MAUTIC_SESSION_ID); |
|
146
|
|
|
$this->clear(self::MTC_SID); |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|