This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
TextClickTracker.php
47 lines (43 loc) · 1.67 KB
/
TextClickTracker.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
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer\ClickTracker;
class TextClickTracker implements ClickTrackerInterface {
public function filterContent($msg, $mailing_id, $queue_id) {
return self::replaceTextUrls($msg,
function ($url) use ($mailing_id, $queue_id) {
if (strpos($url, '{') !== FALSE) {
return $url;
}
return \CRM_Mailing_BAO_TrackableURL::getTrackerURL($url, $mailing_id,
$queue_id);
}
);
}
/**
* Find any URLs and replace them.
*
* @param string $text
* @param callable $replace
* Function(string $oldUrl) => string $newUrl.
* @return mixed
* String, text.
*/
public static function replaceTextUrls($text, $replace) {
$callback = function ($matches) use ($replace) {
// ex: $matches[0] == 'http://foo.com'
return $replace($matches[0]);
};
// Find any HTTP(S) URLs in the text.
// return preg_replace_callback('/\b(?:(?:https?):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $callback, $tex
return preg_replace_callback('/\b(?:(?:https?):\/\/)[-A-Z0-9+&@#\/%=~_|$?!:,.{}\[\];]*[A-Z0-9+&@#\/%=~_|${}\[\];]/i',
$callback, $text);
}
}