From 28e28c36cba970f652bd617d4ee0fc095bfb7aa7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 12 May 2020 23:52:53 -0700 Subject: [PATCH] Respect the defaultExternUrl setting ("standalone"/"router") --- CRM/Utils/System.php | 35 +++++++++++++++++++++++++++++++++++ Civi/Core/Container.php | 1 + 2 files changed, 36 insertions(+) diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 8713cf27fa..11e9eb1710 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -318,6 +318,41 @@ class CRM_Utils_System { return urldecode(CRM_Utils_Url::unparseUrl($event->url)); } + /** + * Perform any current conversions/migrations on the extern URL. + * + * @param \Civi\Core\Event\GenericHookEvent $e + * @see CRM_Utils_Hook::alterExternUrl + */ + public static function migrateExternUrl(\Civi\Core\Event\GenericHookEvent $e) { + + /** + * $mkRouteUri is a small adapter to return generated URL as a "UriInterface". + * @param string $path + * @param string $query + * @return \Psr\Http\Message\UriInterface + */ + $mkRouteUri = function ($path, $query) use ($e) { + $urlTxt = CRM_Utils_System::url($path, $query, $e->absolute, $e->fragment, FALSE); + if ($e->isSSL || ($e->isSSL === NULL && \CRM_Utils_System::isSSL())) { + $urlTxt = str_replace('http://', 'https://', $urlTxt); + } + return CRM_Utils_Url::parseUrl($urlTxt); + }; + + switch (Civi::settings()->get('defaultExternUrl') . ':' . $e->path) { + case 'router:extern/open': + $e->url = $mkRouteUri('civicrm/mailing/open', preg_replace('/(^|&)q=/', '\1qid=', $e->query)); + break; + + case 'router:extern/url': + $e->url = $mkRouteUri('civicrm/mailing/url', $e->query); + break; + + // Otherwise, keep the default. + } + } + /** * @deprecated * @see \CRM_Utils_System::currentPath diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 57ee309164..5e064cae44 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -354,6 +354,7 @@ class Container { $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Core_Resources', 'renderMenubarStylesheet']); $dispatcher->addListener('hook_civicrm_coreResourceList', ['\CRM_Utils_System', 'appendCoreResources']); $dispatcher->addListener('hook_civicrm_getAssetUrl', ['\CRM_Utils_System', 'alterAssetUrl']); + $dispatcher->addListener('hook_civicrm_alterExternUrl', ['\CRM_Utils_System', 'migrateExternUrl'], 1000); $dispatcher->addListener('civi.dao.postInsert', ['\CRM_Core_BAO_RecurringEntity', 'triggerInsert']); $dispatcher->addListener('civi.dao.postUpdate', ['\CRM_Core_BAO_RecurringEntity', 'triggerUpdate']); $dispatcher->addListener('civi.dao.postDelete', ['\CRM_Core_BAO_RecurringEntity', 'triggerDelete']); -- 2.25.1