From: Christian Wach Date: Thu, 15 Nov 2018 12:05:54 +0000 (+0000) Subject: Retrieve tab key from form attributes even when action is urlencoded X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b90552b70b6ba710dc4abc2aef4b018c9546fec5;p=civicrm-core.git Retrieve tab key from form attributes even when action is urlencoded --- diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index cdd2ba2f3d..65173bec6f 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -391,7 +391,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { switch ($className) { case 'Contribute': $attributes = $this->getVar('_attributes'); - $subPage = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); + $subPage = CRM_Utils_Request::retrieveComponent($attributes); if ($subPage == 'friend') { $nextPage = 'custom'; } diff --git a/CRM/Contribute/Form/ContributionPage/TabHeader.php b/CRM/Contribute/Form/ContributionPage/TabHeader.php index cd8611c404..172eeb3c8d 100644 --- a/CRM/Contribute/Form/ContributionPage/TabHeader.php +++ b/CRM/Contribute/Form/ContributionPage/TabHeader.php @@ -142,7 +142,7 @@ class CRM_Contribute_Form_ContributionPage_TabHeader { switch ($className) { case 'Contribute': $attributes = $form->getVar('_attributes'); - $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); + $class = CRM_Utils_Request::retrieveComponent($attributes); break; case 'MembershipBlock': diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index d3173546fa..5e58066d39 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -357,7 +357,7 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { switch ($className) { case 'Event': $attributes = $this->getVar('_attributes'); - $subPage = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); + $subPage = CRM_Utils_Request::retrieveComponent($attributes); break; case 'EventInfo': diff --git a/CRM/Event/Form/ManageEvent/TabHeader.php b/CRM/Event/Form/ManageEvent/TabHeader.php index e4a19a77e4..c2bb54fa14 100644 --- a/CRM/Event/Form/ManageEvent/TabHeader.php +++ b/CRM/Event/Form/ManageEvent/TabHeader.php @@ -168,7 +168,7 @@ WHERE e.id = %1 switch ($className) { case 'Event': $attributes = $form->getVar('_attributes'); - $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); + $class = CRM_Utils_Request::retrieveComponent($attributes); break; case 'EventInfo': diff --git a/CRM/Utils/Request.php b/CRM/Utils/Request.php index 9f0c5bc3eb..e6e0fdf122 100644 --- a/CRM/Utils/Request.php +++ b/CRM/Utils/Request.php @@ -221,4 +221,35 @@ class CRM_Utils_Request { return CRM_Utils_Request::retrieve((string) $name, (string) $type, $null, (bool) $isRequired, $defaultValue, $method, TRUE); } + /** + * Retrieve the component from the action attribute of a form. + * + * Contribution Page forms and Event Management forms detect the value of a + * component (and therefore the desired tab key) by reaching into the "action" + * attribute of a form and reading the final item of the path. In WordPress, + * however, the URL may be urlencoded, and so the URL may need to be decoded + * before parsing it. + * + * @see https://lab.civicrm.org/dev/wordpress/issues/12#note_10699 + * + * @param array $attributes + * The form attributes array. + * + * @return string $value + * The desired value. + */ + public static function retrieveComponent($attributes) { + $url = CRM_Utils_Array::value('action', $attributes); + // Whilst the following is a fallible universal test for urlencoded URLs, + // thankfully the "action" URL has a limited and predictable form and + // therefore this comparison is sufficient for our purposes. + if (rawurlencode(rawurldecode($url)) !== $url) { + $value = strtolower(basename(rawurldecode($url))); + } + else { + $value = strtolower(basename($url)); + } + return $value; + } + }