CRM_Utils_API_ReloadOptionTest - Fix typo
[civicrm-core.git] / extern / url.php
1 <?php
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';
6
7 $config = CRM_Core_Config::singleton();
8
9 // To keep backward compatibility for URLs generated
10 // by CiviCRM < 1.7, we check for the q variable as well.
11 if (isset($_GET['qid'])) {
12 $queue_id = CRM_Utils_Array::value('qid', $_GET);
13 }
14 else {
15 $queue_id = CRM_Utils_Array::value('q', $_GET);
16 }
17 $url_id = CRM_Utils_Array::value('u', $_GET);
18
19 if (!$url_id) {
20 echo "Missing input parameters\n";
21 exit();
22 }
23
24 require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php';
25 $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($queue_id, $url_id);
26
27 // CRM-7103
28 // Looking for additional query variables and append them when redirecting.
29 $query_param = $_GET;
30 unset($query_param['q'], $query_param['qid'], $query_param['u']);
31 $query_string = http_build_query($query_param);
32
33 if (strlen($query_string) > 0) {
34 // Parse the url to preserve the fragment.
35 $pieces = parse_url($url);
36
37 if (isset($pieces['fragment'])) {
38 $url = str_replace('#' . $pieces['fragment'], '', $url);
39 }
40
41 // Handle additional query string params.
42 if ($query_string) {
43 if (stristr($url, '?')) {
44 $url .= '&' . $query_string;
45 }
46 else {
47 $url .= '?' . $query_string;
48 }
49 }
50
51 // slap the fragment onto the end per URL spec
52 if (isset($pieces['fragment'])) {
53 $url .= '#' . $pieces['fragment'];
54 }
55 }
56
57 CRM_Utils_System::redirect($url);