Merge pull request #19280 from eileenmcnaughton/params
[civicrm-core.git] / extern / url.php
CommitLineData
6a488035
TO
1<?php
2require_once '../civicrm.config.php';
3require_once 'CRM/Core/Config.php';
4require_once 'CRM/Core/Error.php';
5require_once 'CRM/Utils/Array.php';
6
d523d24a 7CRM_Core_Config::singleton();
6a488035
TO
8
9// To keep backward compatibility for URLs generated
10// by CiviCRM < 1.7, we check for the q variable as well.
2cfe2cf4
CW
11$queue_id = $_GET['qid'] ?? $_GET['q'] ?? NULL;
12
9c1bc317 13$url_id = $_GET['u'] ?? NULL;
6a488035
TO
14
15if (!$url_id) {
16 echo "Missing input parameters\n";
17 exit();
18}
19
20require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php';
21$url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($queue_id, $url_id);
22
23// CRM-7103
24// Looking for additional query variables and append them when redirecting.
25$query_param = $_GET;
26unset($query_param['q'], $query_param['qid'], $query_param['u']);
27$query_string = http_build_query($query_param);
28
29if (strlen($query_string) > 0) {
30 // Parse the url to preserve the fragment.
31 $pieces = parse_url($url);
32
33 if (isset($pieces['fragment'])) {
29317797 34 $url = str_replace('#' . $pieces['fragment'], '', $url);
6a488035
TO
35 }
36
37 // Handle additional query string params.
38 if ($query_string) {
39 if (stristr($url, '?')) {
40 $url .= '&' . $query_string;
41 }
42 else {
43 $url .= '?' . $query_string;
44 }
45 }
46
47 // slap the fragment onto the end per URL spec
48 if (isset($pieces['fragment'])) {
49 $url .= '#' . $pieces['fragment'];
50 }
51}
52
07bb7edd
J
53// CRM-18320 - Fix encoded ampersands (see CRM_Utils_System::redirect)
54$url = str_replace('&amp;', '&', $url);
55
487e47ff
CW
56// CRM-17953 - The CMS is not bootstrapped so cannot use CRM_Utils_System::redirect
57header('Location: ' . $url);
58CRM_Utils_System::civiExit();