Skip to content

Commit

Permalink
Merge pull request #13043 from christianwach/issue-wp-12
Browse files Browse the repository at this point in the history
Pass path through rawurlencode when not using CIVICRM_CLEANURL
  • Loading branch information
seamuslee001 authored Nov 1, 2018
2 parents a1d4f74 + df17aa2 commit 9080e65
Showing 1 changed file with 59 additions and 11 deletions.
70 changes: 59 additions & 11 deletions CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,28 @@ 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
// FIXME: Why bootstrap in url()? Generally want to define 1-2 strategic places to put bootstrap
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');
}
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 9080e65

Please sign in to comment.