From df17aa2122c80199d295277f9055e4cef46bb3c7 Mon Sep 17 00:00:00 2001 From: Christian Wach Date: Wed, 31 Oct 2018 14:51:34 +0000 Subject: [PATCH] Pass path through rawurlencode when not using CIVICRM_CLEANURL --- CRM/Utils/System/WordPress.php | 70 ++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index f2df6c84761c..493e174f7950 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -208,6 +208,7 @@ public function url( $fragment = isset($fragment) ? ('#' . $fragment) : ''; $path = CRM_Utils_String::stripPathChars($path); + $basepage = FALSE; //this means wp function we are trying to use is not available, //so load bootStrap @@ -215,16 +216,20 @@ public function url( if (!function_exists('get_option')) { $this->loadBootStrap(); } + if ($config->userFrameworkFrontend) { + global $post; if (get_option('permalink_structure') != '') { - global $post; $script = get_permalink($post->ID); } - + if ($config->wpBasePage == $post->post_name) { + $basepage = TRUE; + } // when shortcode is included in page // also make sure we have valid query object + // FIXME: $wpPageParam has no effect and is only set on the *basepage* global $wp_query; - if (method_exists($wp_query, 'get')) { + if (get_option('permalink_structure') == '' && method_exists($wp_query, 'get')) { if (get_query_var('page_id')) { $wpPageParam = "page_id=" . get_query_var('page_id'); } @@ -251,18 +256,61 @@ public function url( } $queryParts = array(); - if (isset($path)) { - $queryParts[] = 'page=CiviCRM'; - $queryParts[] = "q={$path}"; + + // CRM_Core_Payment::getReturnSuccessUrl() passes $query as an array + if (isset($query) && is_array($query)) { + $query = implode($separator, $query); } - if ($wpPageParam) { - $queryParts[] = $wpPageParam; + + if ( + // not using clean URLs + !$config->cleanURL + // requesting an admin URL + || ((is_admin() && !$frontend) || $forceBackend) + // is shortcode + || (!$basepage && $script != '') + ) { + + // pre-existing logic + if (isset($path)) { + $queryParts[] = 'page=CiviCRM'; + // Encode all but the *path* placeholder + if ($path !== '*path*') { + $path = rawurlencode($path); + } + $queryParts[] = "q={$path}"; + } + if ($wpPageParam) { + $queryParts[] = $wpPageParam; + } + if (isset($query)) { + $queryParts[] = $query; + } + + $final = $base . '?' . implode($separator, $queryParts) . $fragment; + } - if (isset($query)) { - $queryParts[] = $query; + else { + + // clean URLs + if (isset($path)) { + $base = trailingslashit($base) . str_replace('civicrm/', '', $path) . '/'; + } + if (isset($query)) { + $query = ltrim($query, '=?&'); + $queryParts[] = $query; + } + + if (!empty($queryParts)) { + $final = $base . '?' . implode($separator, $queryParts) . $fragment; + } + else { + $final = $base . $fragment; + } + } - return $base . '?' . implode($separator, $queryParts) . $fragment; + return $final; } /**