From: eileen Date: Thu, 16 Apr 2020 04:06:51 +0000 (+1200) Subject: Implement 'extern/url.php' as a regular route X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6296d79469cbebde1e59c48f9467bd92a8a4f136;p=civicrm-core.git Implement 'extern/url.php' as a regular route --- diff --git a/CRM/Mailing/Page/Url.php b/CRM/Mailing/Page/Url.php new file mode 100644 index 0000000000..bd74484e02 --- /dev/null +++ b/CRM/Mailing/Page/Url.php @@ -0,0 +1,65 @@ + 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); + } + +} diff --git a/CRM/Mailing/xml/Menu/Mailing.xml b/CRM/Mailing/xml/Menu/Mailing.xml index 2df7db3622..7fea1938a4 100644 --- a/CRM/Mailing/xml/Menu/Mailing.xml +++ b/CRM/Mailing/xml/Menu/Mailing.xml @@ -202,4 +202,9 @@ CRM_Mailing_Page_AJAX::getContactMailings access CiviCRM + + civicrm/mailing/url + CRM_Mailing_Page_Url + *always allow* + diff --git a/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php b/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php index fa637eb0cd..c1a262b9ee 100644 --- a/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php +++ b/tests/phpunit/CRM/Mailing/BaseMailingSystemTest.php @@ -200,7 +200,7 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { $this->assertRegExp( ";" . // body_html - "

You can go to Google" . + "

You can go to Google" . " or opt out.

\n" . // Default footer "Sample Footer for HTML formatted content" . @@ -219,7 +219,7 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { "\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 @@ -280,8 +280,8 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { // Tracking enabled $cases[] = [ '

Foo

', - ';

Foo

;', - ';\\[1\\] .*extern/url\.php\?u=\d+.*;', + ';

Foo

;', + ';\\[1\\] .*civicrm/mailing/url\.php\?u=\d+.*;', ['url_tracking' => 1], ]; $cases[] = [ @@ -311,7 +311,7 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { // but not in HTML emails. "

Please go to: http://example.net/

", ";

Please go to: http://example\.net/

;", - ';Please go to: .*extern/url.php\?u=\d+&qid=\d+;', + ';Please go to: .*civicrm/mailing.php\?u=\d+&qid=\d+;', ['url_tracking' => 1], ]; @@ -322,6 +322,7 @@ abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase { * 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);