Commit | Line | Data |
---|---|---|
bdf67e28 SL |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | namespace Civi\FlexMailer\Listener; | |
12 | ||
13 | use Civi\FlexMailer\Event\ComposeBatchEvent; | |
14 | ||
15 | class OpenTracker extends BaseListener { | |
16 | ||
17 | /** | |
18 | * Inject open-tracking codes. | |
19 | * | |
20 | * @param \Civi\FlexMailer\Event\ComposeBatchEvent $e | |
21 | */ | |
22 | public function onCompose(ComposeBatchEvent $e) { | |
23 | if (!$this->isActive() || !$e->getMailing()->open_tracking) { | |
24 | return; | |
25 | } | |
26 | ||
27 | $config = \CRM_Core_Config::singleton(); | |
28 | ||
29 | // TODO: After v5.21 goes EOL, remove the $isLegacy check. | |
30 | $isLegacy = version_compare(\CRM_Utils_System::version(), '5.23.alpha', '<'); | |
31 | ||
32 | foreach ($e->getTasks() as $task) { | |
33 | /** @var \Civi\FlexMailer\FlexMailerTask $task */ | |
34 | $mailParams = $task->getMailParams(); | |
35 | ||
36 | if (!empty($mailParams) && !empty($mailParams['html'])) { | |
37 | $openUrl = $isLegacy | |
38 | ? $config->userFrameworkResourceURL . "extern/open.php?q=" . $task->getEventQueueId() | |
39 | : \CRM_Utils_System::externUrl('extern/open', "q=" . $task->getEventQueueId()); | |
40 | ||
41 | $mailParams['html'] .= "\n" . '<img src="' . htmlentities($openUrl) . "\" width='1' height='1' alt='' border='0'>"; | |
42 | ||
43 | $task->setMailParams($mailParams); | |
44 | } | |
45 | } | |
46 | } | |
47 | ||
48 | } |