Merge pull request #6411 from colemanw/CRM-16444
[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
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.
11if (isset($_GET['qid'])) {
12 $queue_id = CRM_Utils_Array::value('qid', $_GET);
13}
14else {
15 $queue_id = CRM_Utils_Array::value('q', $_GET);
16}
17$url_id = CRM_Utils_Array::value('u', $_GET);
18
19if (!$url_id) {
20 echo "Missing input parameters\n";
21 exit();
22}
23
24require_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;
30unset($query_param['q'], $query_param['qid'], $query_param['u']);
31$query_string = http_build_query($query_param);
32
33if (strlen($query_string) > 0) {
34 // Parse the url to preserve the fragment.
35 $pieces = parse_url($url);
36
37 if (isset($pieces['fragment'])) {
29317797 38 $url = str_replace('#' . $pieces['fragment'], '', $url);
6a488035
TO
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
57CRM_Utils_System::redirect($url);