3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_BAO_TrackableURL
extends CRM_Mailing_DAO_TrackableURL
{
22 public function __construct() {
23 parent
::__construct();
27 * Given a url, mailing id and queue event id, find or construct a
28 * trackable url and redirect url.
31 * The target url to track.
32 * @param int $mailing_id
33 * The id of the mailing.
34 * @param int $queue_id
35 * The queue event id (contact clicking through).
38 * The redirect/tracking url
40 public static function getTrackerURL($url, $mailing_id, $queue_id) {
42 static $urlCache = [];
44 if (array_key_exists($mailing_id . $url, $urlCache)) {
45 return $urlCache[$mailing_id . $url] . "&qid=$queue_id";
48 // hack for basic CRM-1014 and CRM-1151 and CRM-3492 compliance:
49 // let's not replace possible image URLs and CiviMail ones
50 if (preg_match('/\.(png|jpg|jpeg|gif|css)[\'"]?$/i', $url)
51 or substr_count($url, 'civicrm/extern/')
52 or substr_count($url, 'civicrm/mailing/')
54 // let's not cache these, so they don't get &qid= appended to them
60 $config = CRM_Core_Config
::singleton();
62 $tracker = new CRM_Mailing_BAO_TrackableURL();
63 if (preg_match('/^href/i', $url)) {
64 $url = preg_replace('/^href[ ]*=[ ]*[\'"](.*?)[\'"]$/i', '$1', $url);
69 $tracker->mailing_id
= $mailing_id;
71 if (!$tracker->find(TRUE)) {
76 $redirect = $config->userFrameworkResourceURL
. "extern/url.php?u=$id";
77 $urlCache[$mailing_id . $url] = $redirect;
80 $returnUrl = "{$urlCache[$mailing_id . $url]}&qid={$queue_id}";
83 $returnUrl = "href='{$returnUrl}' rel='nofollow'";
94 * Url id of the given url and mail
96 public static function getTrackerURLId($url, $mailing_id) {
97 $tracker = new CRM_Mailing_BAO_TrackableURL();
99 $tracker->mailing_id
= $mailing_id;
100 if ($tracker->find(TRUE)) {