--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+
+/**
+ * Redirects a user to the full url from a mailing url.
+ */
+class CRM_Mailing_Page_Url extends CRM_Core_Page {
+
+ /**
+ * Redirect the user to the specified url.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function run() {
+ $queue_id = CRM_Utils_Request::retrieveValue('qid', 'Integer');
+ $url_id = CRM_Utils_Request::retrieveValue('u', 'Integer', NULL, TRUE);
+ $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($queue_id, $url_id);
+
+ // CRM-7103
+ // Looking for additional query variables and append them when redirecting.
+ $query_param = $_GET;
+ unset($query_param['qid'], $query_param['u']);
+ $query_string = http_build_query($query_param);
+
+ if (strlen($query_string) > 0) {
+ // Parse the url to preserve the fragment.
+ $pieces = parse_url($url);
+
+ if (isset($pieces['fragment'])) {
+ $url = str_replace('#' . $pieces['fragment'], '', $url);
+ }
+
+ // Handle additional query string params.
+ if ($query_string) {
+ if (stristr($url, '?')) {
+ $url .= '&' . $query_string;
+ }
+ else {
+ $url .= '?' . $query_string;
+ }
+ }
+
+ // slap the fragment onto the end per URL spec
+ if (isset($pieces['fragment'])) {
+ $url .= '#' . $pieces['fragment'];
+ }
+ }
+ CRM_Utils_System::redirect($url);
+ }
+
+}
$this->assertRegExp(
";" .
// body_html
- "<p>You can go to <a href=['\"].*extern/url\.php\?u=\d+&\\;qid=\d+['\"] rel='nofollow'>Google</a>" .
+ "<p>You can go to <a href=['\"].*civicrm/mailing/url\.php\?u=\d+&\\;qid=\d+['\"] rel='nofollow'>Google</a>" .
" or <a href=\"http.*civicrm/mailing/optout.*\">opt out</a>.</p>\n" .
// Default footer
"Sample Footer for HTML formatted content" .
"\n" .
"Links:\n" .
"------\n" .
- "\\[1\\] .*extern/url\.php\?u=\d+&qid=\d+\n" .
+ "\\[1\\] http.*civicrm/mailing/url\.php\?u=\d+&qid=\d+\n" .
"\\[2\\] http.*civicrm/mailing/optout.*\n" .
"\n" .
// Default footer
// Tracking enabled
$cases[] = [
'<p><a href="http://example.net/">Foo</a></p>',
- ';<p><a href=[\'"].*extern/url\.php\?u=\d+.*[\'"]>Foo</a></p>;',
- ';\\[1\\] .*extern/url\.php\?u=\d+.*;',
+ ';<p><a href=[\'"].*civicrm/mailing/url\.php\?u=\d+.*[\'"]>Foo</a></p>;',
+ ';\\[1\\] .*civicrm/mailing/url\.php\?u=\d+.*;',
['url_tracking' => 1],
];
$cases[] = [
// but not in HTML emails.
"<p>Please go to: http://example.net/</p>",
";<p>Please go to: http://example\.net/</p>;",
- ';Please go to: .*extern/url.php\?u=\d+&qid=\d+;',
+ ';Please go to: .*civicrm/mailing.php\?u=\d+&qid=\d+;',
['url_tracking' => 1],
];
* Generate a fully-formatted mailing (with body_html content).
*
* @dataProvider urlTrackingExamples
+ * @throws \CRM_Core_Exception
*/
public function testUrlTracking($inputHtml, $htmlUrlRegex, $textUrlRegex, $params) {
$caseName = print_r(['inputHtml' => $inputHtml, 'params' => $params], 1);