Commit f21fa430 authored by kcristiano's avatar kcristiano Committed by GitHub

Merge pull request #144 from christianwach/cleaner-urls

Cleaner front-end URLs
parents 3dca8470 9ecb1f41
This diff is collapsed.
......@@ -529,19 +529,34 @@ class CiviCRM_For_WordPress_Basepage {
*/
public function basepage_canonical_url( $canonical ) {
/*
* It would be better to specify which params are okay to accept as the
* canonical URLs, but this will work for the time being.
*/
if ( empty( $_GET['page'] )
|| empty( $_GET['q'] )
|| 'CiviCRM' !== $_GET['page'] ) {
return $canonical;
// Access Civi config object
$config = CRM_Core_Config::singleton();
// Retain old logic when not using clean URLs
if (!$config->cleanURL) {
/*
* It would be better to specify which params are okay to accept as the
* canonical URLs, but this will work for the time being.
*/
if ( empty( $_GET['page'] )
|| empty( $_GET['q'] )
|| 'CiviCRM' !== $_GET['page'] ) {
return $canonical;
}
$path = $_GET['q'];
unset( $_GET['q'] );
unset( $_GET['page'] );
$query = http_build_query( $_GET );
}
else {
$argdata = $this->civi->get_request_args();
$path = $argdata['argString'];
$query = http_build_query( $_GET );
}
$path = $_GET['q'];
unset( $_GET['q'] );
unset( $_GET['page'] );
$query = http_build_query( $_GET );
// We should, however, build the URL the way that CiviCRM expects it to be
// (rather than through some other funny base page).
......
......@@ -321,6 +321,7 @@ class CiviCRM_For_WordPress_Shortcodes {
// invoke() requires environment variables to be set
foreach ( $args as $key => $value ) {
if ( $value !== NULL ) {
set_query_var($key, $value);
$_REQUEST[$key] = $_GET[$key] = $value;
}
}
......@@ -406,18 +407,37 @@ class CiviCRM_For_WordPress_Shortcodes {
// $absolute, $frontend, $forceBackend
$base_url = $this->civi->get_base_url(TRUE, FALSE, FALSE);
// Construct query parts
// Init query parts
$queryParts = array();
$queryParts[] = 'page=CiviCRM';
if (isset($args['q'])) {
$queryParts[] = 'q=' . $args['q'];
}
if (isset($query)) {
$queryParts[] = $query;
// When not using clean URLs
if (!$config->cleanURL) {
// Construct query parts
$queryParts[] = 'page=CiviCRM';
if (isset($args['q'])) {
$queryParts[] = 'q=' . $args['q'];
}
if (isset($query)) {
$queryParts[] = $query;
}
// Construct link
$link = trailingslashit( $base_url ) . '?' . implode('&', $queryParts);
}
else {
// Construct link
$link = trailingslashit( $base_url ) . '?' . implode('&', $queryParts);
// Clean URLs
if (isset($args['q'])) {
$base_url = trailingslashit( $base_url ) . str_replace('civicrm/', '', $args['q']) . '/';
}
if (isset($query)) {
$queryParts[] = $query;
}
$link = $base_url . '?' . implode('&', $queryParts);
}
// Add a class for styling purposes
$class = ' civicrm-shortcode-multiple';
......@@ -706,7 +726,6 @@ class CiviCRM_For_WordPress_Shortcodes {
case 'info':
$args['q'] = 'civicrm/event/info';
$_REQUEST['page'] = $_GET['page'] = 'CiviCRM';
break;
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment