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 $config = 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 if (isset($_GET['qid'])) {
12 $queue_id = CRM_Utils_Array
::value('qid', $_GET);
15 $queue_id = CRM_Utils_Array
::value('q', $_GET);
17 $url_id = CRM_Utils_Array
::value('u', $_GET);
20 echo "Missing input parameters\n";
24 require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php';
25 $url = CRM_Mailing_Event_BAO_TrackableURLOpen
::track($queue_id, $url_id);
28 // Looking for additional query variables and append them when redirecting.
30 unset($query_param['q'], $query_param['qid'], $query_param['u']);
31 $query_string = http_build_query($query_param);
33 if (strlen($query_string) > 0) {
34 // Parse the url to preserve the fragment.
35 $pieces = parse_url($url);
37 if (isset($pieces['fragment'])) {
38 $url = str_replace('#' . $pieces['fragment'], '', $url);
41 // Handle additional query string params.
43 if (stristr($url, '?')) {
44 $url .= '&' . $query_string;
47 $url .= '?' . $query_string;
51 // slap the fragment onto the end per URL spec
52 if (isset($pieces['fragment'])) {
53 $url .= '#' . $pieces['fragment'];
57 CRM_Utils_System
::redirect($url);