2 require_once '../civicrm.config.php';
3 require_once 'CRM/Core/Config.php';
4 require_once 'CRM/Core/Error.php';
5 require_once 'CRM/Utils/Array.php';
7 CRM_Core_Config
::singleton();
9 // To keep backward compatibility for URLs generated
10 // by CiviCRM < 1.7, we check for the q variable as well.
11 $queue_id = $_GET['qid'] ??
$_GET['q'] ??
NULL;
13 $url_id = $_GET['u'] ??
NULL;
16 echo "Missing input parameters\n";
20 require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php';
21 $url = CRM_Mailing_Event_BAO_TrackableURLOpen
::track($queue_id, $url_id);
24 // Looking for additional query variables and append them when redirecting.
26 unset($query_param['q'], $query_param['qid'], $query_param['u']);
27 $query_string = http_build_query($query_param);
29 if (strlen($query_string) > 0) {
30 // Parse the url to preserve the fragment.
31 $pieces = parse_url($url);
33 if (isset($pieces['fragment'])) {
34 $url = str_replace('#' . $pieces['fragment'], '', $url);
37 // Handle additional query string params.
39 if (stristr($url, '?')) {
40 $url .= '&' . $query_string;
43 $url .= '?' . $query_string;
47 // slap the fragment onto the end per URL spec
48 if (isset($pieces['fragment'])) {
49 $url .= '#' . $pieces['fragment'];
53 // CRM-18320 - Fix encoded ampersands (see CRM_Utils_System::redirect)
54 $url = str_replace('&', '&', $url);
56 // CRM-17953 - The CMS is not bootstrapped so cannot use CRM_Utils_System::redirect
57 header('Location: ' . $url);
58 CRM_Utils_System
::civiExit();