From: Kevin Cristiano Date: Sat, 22 Apr 2017 21:21:10 +0000 (-0400) Subject: CRM16421 CRM 17633: Changes to support WP in it's own directory. Allow for civicrn... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f553d1eac3d3bd329fd85d0a2abf7b3acf2a7023;p=civicrm-core.git CRM16421 CRM 17633: Changes to support WP in it's own directory. Allow for civicrn.settings.extra.php for WP. Create template for civicrm.settings.extra.php. Update install/civicrm.php for all needed params for different common install scenarios. Fix linting issues in civicrm.php. CRM 16421 CRM 17633 - update CRM_Utils_System_WordPress to allow for common install configurations CRM-16421 - Convert constants to `$civicrm_paths` Following up on the discussion from [#10513](https://github.com/civicrm/civicrm-core/pull/10513), this converts the proposed constants `CIVICRM_UF_WP_BASEURL` and `CIVICRM_UF_ADMINURL` to variables in the `Paths` system. A few benefits: * Reduces code duplication between `civicrm.php` and `WordPress.php`. * Can construct sub-paths with prettier notation (`Civi::paths()->getUrl('[wp.frontend]/foo.txt')`) * Has options to output relative or absolute URLs * Can expand on `Paths` to provide more inspection/validation Notes: * `CIVICRM_UF_WP_BASEURL` => `wp.frontend.base` * `CIVICRM_UF_ADMINURL` => `wp.backend.base` ---------------------------------------- * CRM-16421: Work to get CiviCRM for WordPress in WordPress' official Repository https://issues.civicrm.org/jira/browse/CRM-16421 CRM-16421 - Assimilate `civicrm.settings.extra.php` into `civicrm.settings.php` ---------------------------------------- * CRM-16421: Work to get CiviCRM for WordPress in WordPress' official Repository https://issues.civicrm.org/jira/browse/CRM-16421 CRM-17633 merge current master changes to civicrm.settings.php.template --- diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index bfab40510f..579f647d28 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -266,6 +266,12 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } /** + * 27-09-2016 + * CRM-16421 CRM-17633 WIP Changes to support WP in it's own directory + * https://wiki.civicrm.org/confluence/display/CRM/WordPress+installed+in+its+own+directory+issues + * For now leave hard coded wp-admin references. + * TODO: remove wp-admin references and replace with admin_url() in the future. Look at best way to get path to admin_url + * * @param $absolute * @param $frontend * @param $forceBackend @@ -274,22 +280,12 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { */ private function getBaseUrl($absolute, $frontend, $forceBackend) { $config = CRM_Core_Config::singleton(); - - $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; - if ((is_admin() && !$frontend) || $forceBackend) { - $base .= 'wp-admin/admin.php'; - return $base; + return Civi::paths()->getUrl('[wp.backend]/.', $absolute ? 'absolute' : 'relative'); } - elseif (defined('CIVICRM_UF_WP_BASEPAGE')) { - $base .= CIVICRM_UF_WP_BASEPAGE; - return $base; - } - elseif (isset($config->wpBasePage)) { - $base .= $config->wpBasePage; - return $base; + else { + return Civi::paths()->getUrl('[wp.frontend]/.', $absolute ? 'absolute' : 'relative'); } - return $base; } /** diff --git a/Civi/Core/Paths.php b/Civi/Core/Paths.php index 13efe656f7..fc2f670693 100644 --- a/Civi/Core/Paths.php +++ b/Civi/Core/Paths.php @@ -30,6 +30,7 @@ class Paths { * Class constructor. */ public function __construct() { + $paths = $this; $this ->register('civicrm.root', function () { return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage(); @@ -55,6 +56,24 @@ class Paths { ->register('civicrm.files', function () { return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage(); }) + ->register('wp.frontend.base', function () { + return array('url' => CIVICRM_UF_BASEURL); + }) + ->register('wp.frontend', function () use ($paths) { + $config = \CRM_Core_Config::singleton(); + $suffix = defined('CIVICRM_UF_WP_BASEPAGE') ? CIVICRM_UF_WP_BASEPAGE : $config->wpBasePage; + return array( + 'url' => $paths->getVariable('wp.frontend.base', 'url') . $suffix, + ); + }) + ->register('wp.backend.base', function () { + return array('url' => CIVICRM_UF_BASEURL . 'wp-admin/'); + }) + ->register('wp.backend', function () use ($paths) { + return array( + 'url' => $paths->getVariable('wp.backend.base', 'url') . 'admin.php', + ); + }) ->register('cms', function () { return array( 'path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), diff --git a/install/civicrm.php b/install/civicrm.php index 50e4271081..591079d3cd 100644 --- a/install/civicrm.php +++ b/install/civicrm.php @@ -84,8 +84,7 @@ function civicrm_main(&$config) { if ($installType == 'drupal') { $siteDir = isset($config['site_dir']) ? $config['site_dir'] : getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']); - civicrm_setup($cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . - $siteDir . DIRECTORY_SEPARATOR . 'files' + civicrm_setup($cmsPath . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . $siteDir . DIRECTORY_SEPARATOR . 'files' ); } elseif ($installType == 'backdrop') { @@ -139,7 +138,6 @@ function civicrm_main(&$config) { civicrm_write_file($configFile, $string ); - } /** @@ -217,6 +215,9 @@ function civicrm_config(&$config) { global $compileDir; global $tplPath, $installType; + // Ex: $extraSettings[] = '$civicrm_settings["domain"]["foo"] = "bar";'; + $extraSettings = array(); + $params = array( 'crmRoot' => $crmPath, 'templateCompileDir' => $compileDir, @@ -274,6 +275,18 @@ function civicrm_config(&$config) { // CRM-12386 $params['crmRoot'] = addslashes($params['crmRoot']); + //CRM-16421 + + $extraSettings[] = sprintf('$civicrm_paths[\'wp.frontend.base\'][\'url\'] = %s;', var_export(home_url() . '/', 1)); + $extraSettings[] = sprintf('$civicrm_paths[\'wp.backend.base\'][\'url\'] = %s;', var_export(admin_url(), 1)); + $extraSettings[] = sprintf('$civicrm_setting[\'URL Preferences\'][\'userFrameworkResourceURL\'] = %s;', var_export(plugin_dir_url(CIVICRM_PLUGIN_FILE) . 'civicrm', 1)); + } + + if ($extraSettings) { + $params['extraSettings'] = "Additional settings generated by installer:\n" . implode("\n", $extraSettings); + } + else { + $params['extraSettings'] = ""; } $params['siteKey'] = md5(rand() . mt_rand() . rand() . uniqid('', TRUE) . $params['baseURL']); diff --git a/templates/CRM/common/civicrm.settings.php.template b/templates/CRM/common/civicrm.settings.php.template index b580e27638..507b96b133 100644 --- a/templates/CRM/common/civicrm.settings.php.template +++ b/templates/CRM/common/civicrm.settings.php.template @@ -28,7 +28,7 @@ /** * CiviCRM Configuration File. */ -global $civicrm_setting; +global $civicrm_root, $civicrm_setting, $civicrm_paths; /** * Content Management System (CMS) Host: @@ -76,6 +76,8 @@ if (!defined('CIVICRM_UF_DSN') && CIVICRM_UF !== 'UnitTests') { define( 'CIVICRM_UF_DSN' , 'mysql://%%CMSdbUser%%:%%CMSdbPass%%@%%CMSdbHost%%/%%CMSdbName%%?new_link=true'); } +// %%extraSettings%% + /** * CiviCRM Database Settings *