| 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 | 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 | $queue_id = $_GET['qid'] ?? $_GET['q'] ?? NULL; |
| 12 | |
| 13 | $url_id = $_GET['u'] ?? NULL; |
| 14 | |
| 15 | if (!$url_id) { |
| 16 | echo "Missing input parameters\n"; |
| 17 | exit(); |
| 18 | } |
| 19 | |
| 20 | require_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; |
| 26 | unset($query_param['q'], $query_param['qid'], $query_param['u']); |
| 27 | $query_string = http_build_query($query_param); |
| 28 | |
| 29 | if (strlen($query_string) > 0) { |
| 30 | // Parse the url to preserve the fragment. |
| 31 | $pieces = parse_url($url); |
| 32 | |
| 33 | if (isset($pieces['fragment'])) { |
| 34 | $url = str_replace('#' . $pieces['fragment'], '', $url); |
| 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 | |
| 53 | // CRM-18320 - Fix encoded ampersands (see CRM_Utils_System::redirect) |
| 54 | $url = str_replace('&', '&', $url); |
| 55 | |
| 56 | // CRM-17953 - The CMS is not bootstrapped so cannot use CRM_Utils_System::redirect |
| 57 | header('Location: ' . $url); |
| 58 | CRM_Utils_System::civiExit(); |