*/
class CRM_Core_Config_Defaults {
- /**
- * Set the default values.
- * in an empty db, also called when setting component using GUI
- *
- * @param array $defaults
- * Associated array of form elements.
- * @param bool $formMode
- * this variable is set true for GUI
- * mode (eg: Global setting >> Components)
- *
- */
- public static function setValues(&$defaults, $formMode = FALSE) {
- }
-
- public static function getCustomCssUrl($k = NULL) {
- return Civi::settings()->getUrl('customCSSURL', 'absolute');
- }
-
- public static function getCustomFileUploadDir($k = NULL) {
- $settings = Civi::settings();
- $value = $settings->getPath('customFileUploadDir');
- if (empty($value)) {
- $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
- $value = $settings->filterPath($defaultFileStorage['path'] . "custom/");
- }
- $value = CRM_Utils_File::addTrailingSlash($value);
- CRM_Utils_File::createDir($value);
- CRM_Utils_File::restrictAccess($value);
- return $value;
- }
-
-
- public static function getCustomPhpPathDir($k = NULL) {
- return Civi::settings()->getPath('customPHPPathDir');
- }
-
- public static function getCustomTemplateDir($k = NULL) {
- return Civi::settings()->getPath('customTemplateDir');
- }
-
- public static function getExtensionsUrl($k = NULL) {
- return Civi::settings()->getUrl('extensionsURL', 'absolute');
- }
-
- public static function getExtensionsDir($k = NULL) {
- return Civi::settings()->getPath('extensionsDir');
- }
-
- public static function getImageUploadDir($k = NULL) {
- $settings = Civi::settings();
- $value = $settings->getPath('imageUploadDir');
- if (empty($value)) {
- $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
- $value = $settings->filterPath($defaultFileStorage['path'] . "persist/contribute/");
- }
- $value = CRM_Utils_File::addTrailingSlash($value);
- CRM_Utils_File::createDir($value);
- return $value;
- }
-
- public static function getImageUploadUrl($k = NULL) {
- $settings = Civi::settings();
- $imageUploadURL = $settings->getUrl('imageUploadURL', 'absolute');
- if (empty($imageUploadURL)) {
- $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
- $imageUploadURL = $settings->filterUrl($defaultFileStorage['url'] . 'persist/contribute/', 'absolute');
- }
- return $imageUploadURL;
- }
-
- public static function getUploadDir($k = NULL) {
- $settings = Civi::settings();
- $value = $settings->getPath('uploadDir');
- if (empty($value)) {
- $defaultFileStorage = CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
- $value = $settings->filterPath($defaultFileStorage['path'] . "upload/");
- }
- $value = CRM_Utils_File::addTrailingSlash($value);
- CRM_Utils_File::createDir($value);
- CRM_Utils_File::restrictAccess($value);
- return $value;
- }
-
- public static function getUserFrameworkResourceUrl($k = NULL) {
- $settings = Civi::settings();
- $url = $settings->getUrl('userFrameworkResourceURL', 'absolute');
- if (empty($url)) {
- $config = CRM_Core_Config::singleton();
- $civiSource = $config->userSystem->getCiviSourceStorage();
- $url = $settings->filterUrl($civiSource['url'], 'absolute');
- }
- return $url;
- }
-
- public static function getResourceBase($k = NULL) {
- $settings = Civi::settings();
- $url = $settings->getUrl('userFrameworkResourceURL', 'relative');
- if (empty($url)) {
- $config = CRM_Core_Config::singleton();
- $civiSource = $config->userSystem->getCiviSourceStorage();
- $url = $settings->filterUrl($civiSource['url'], 'relative');
- }
- return $url;
- }
-
public static function getDefaultCurrencySymbol($k = NULL) {
$config = CRM_Core_Config::singleton();
return $config->defaultCurrencySymbol(Civi::settings()->get('defaultCurrency'));
}
- public static function setPath($key, $value) {
- Civi::settings()->setPath($key, $value);
- }
-
- public static function setUrl($key, $value) {
- Civi::settings()->setPath($key, $value);
- }
-
- public static function revert($key) {
- Civi::settings()->revert($key);
- }
-
}
* @return array
*/
public static function getPropertyMap() {
+ // Each mapping: $propertyName => Array(0 => $type, 1 => $foreignName|NULL, ...).
+ // If $foreignName is omitted/null, then it's assumed to match the $propertyName.
+ // Other parameters may be specified, depending on the type.
return array(
- 'backtrace' => array('setting', 'backtrace'),
- 'countryLimit' => array('setting', 'countryLimit'),
- 'dashboardCacheTimeout' => array('setting', 'dashboardCacheTimeout'),
- 'dateInputFormat' => array('setting', 'dateInputFormat'),
- 'dateformatDatetime' => array('setting', 'dateformatDatetime'),
- 'dateformatFull' => array('setting', 'dateformatFull'),
- 'dateformatPartial' => array('setting', 'dateformatPartial'),
- 'dateformatTime' => array('setting', 'dateformatTime'),
- 'dateformatYear' => array('setting', 'dateformatYear'),
+ 'backtrace' => array('setting'),
+ 'countryLimit' => array('setting'),
+ 'dashboardCacheTimeout' => array('setting'),
+ 'dateInputFormat' => array('setting'),
+ 'dateformatDatetime' => array('setting'),
+ 'dateformatFull' => array('setting'),
+ 'dateformatPartial' => array('setting'),
+ 'dateformatTime' => array('setting'),
+ 'dateformatYear' => array('setting'),
'debug' => array('setting', 'debug_enabled'), // renamed.
- 'defaultContactCountry' => array('setting', 'defaultContactCountry'),
- 'defaultContactStateProvince' => array('setting', 'defaultContactStateProvince'),
- 'defaultCurrency' => array('setting', 'defaultCurrency'),
- 'defaultSearchProfileID' => array('setting', 'defaultSearchProfileID'),
- 'doNotAttachPDFReceipt' => array('setting', 'doNotAttachPDFReceipt'),
- 'empoweredBy' => array('setting', 'empoweredBy'),
+ 'defaultContactCountry' => array('setting'),
+ 'defaultContactStateProvince' => array('setting'),
+ 'defaultCurrency' => array('setting'),
+ 'defaultSearchProfileID' => array('setting'),
+ 'doNotAttachPDFReceipt' => array('setting'),
+ 'empoweredBy' => array('setting'),
'enableComponents' => array('setting', 'enable_components'), // renamed.
- 'enableSSL' => array('setting', 'enableSSL'),
- 'fatalErrorHandler' => array('setting', 'fatalErrorHandler'),
- 'fieldSeparator' => array('setting', 'fieldSeparator'),
- 'fiscalYearStart' => array('setting', 'fiscalYearStart'),
- 'geoAPIKey' => array('setting', 'geoAPIKey'),
- 'geoProvider' => array('setting', 'geoProvider'),
- 'includeAlphabeticalPager' => array('setting', 'includeAlphabeticalPager'),
- 'includeEmailInName' => array('setting', 'includeEmailInName'),
- 'includeNickNameInName' => array('setting', 'includeNickNameInName'),
- 'includeOrderByClause' => array('setting', 'includeOrderByClause'),
- 'includeWildCardInName' => array('setting', 'includeWildCardInName'),
- 'inheritLocale' => array('setting', 'inheritLocale'),
- 'languageLimit' => array('setting', 'languageLimit'),
- 'lcMessages' => array('setting', 'lcMessages'),
- 'legacyEncoding' => array('setting', 'legacyEncoding'),
- 'logging' => array('setting', 'logging'),
- 'mailThrottleTime' => array('setting', 'mailThrottleTime'),
- 'mailerBatchLimit' => array('setting', 'mailerBatchLimit'),
- 'mailerJobSize' => array('setting', 'mailerJobSize'),
- 'mailerJobsMax' => array('setting', 'mailerJobsMax'),
- 'mapAPIKey' => array('setting', 'mapAPIKey'),
- 'mapProvider' => array('setting', 'mapProvider'),
- 'maxFileSize' => array('setting', 'maxFileSize'),
+ 'enableSSL' => array('setting'),
+ 'fatalErrorHandler' => array('setting'),
+ 'fieldSeparator' => array('setting'),
+ 'fiscalYearStart' => array('setting'),
+ 'geoAPIKey' => array('setting'),
+ 'geoProvider' => array('setting'),
+ 'includeAlphabeticalPager' => array('setting'),
+ 'includeEmailInName' => array('setting'),
+ 'includeNickNameInName' => array('setting'),
+ 'includeOrderByClause' => array('setting'),
+ 'includeWildCardInName' => array('setting'),
+ 'inheritLocale' => array('setting'),
+ 'languageLimit' => array('setting'),
+ 'lcMessages' => array('setting'),
+ 'legacyEncoding' => array('setting'),
+ 'logging' => array('setting'),
+ 'mailThrottleTime' => array('setting'),
+ 'mailerBatchLimit' => array('setting'),
+ 'mailerJobSize' => array('setting'),
+ 'mailerJobsMax' => array('setting'),
+ 'mapAPIKey' => array('setting'),
+ 'mapProvider' => array('setting'),
+ 'maxFileSize' => array('setting'),
'maxAttachments' => array('setting', 'max_attachments'), // renamed.
- 'monetaryDecimalPoint' => array('setting', 'monetaryDecimalPoint'),
- 'monetaryThousandSeparator' => array('setting', 'monetaryThousandSeparator'),
- 'moneyformat' => array('setting', 'moneyformat'),
- 'moneyvalueformat' => array('setting', 'moneyvalueformat'),
- 'provinceLimit' => array('setting', 'provinceLimit'),
- 'recaptchaOptions' => array('setting', 'recaptchaOptions'),
- 'recaptchaPublicKey' => array('setting', 'recaptchaPublicKey'),
- 'recaptchaPrivateKey' => array('setting', 'recaptchaPrivateKey'),
- 'secondDegRelPermissions' => array('setting', 'secondDegRelPermissions'),
- 'smartGroupCacheTimeout' => array('setting', 'smartGroupCacheTimeout'),
- 'timeInputFormat' => array('setting', 'timeInputFormat'),
- 'userFrameworkLogging' => array('setting', 'userFrameworkLogging'),
- 'userFrameworkUsersTableName' => array('setting', 'userFrameworkUsersTableName'),
- 'verpSeparator' => array('setting', 'verpSeparator'),
- 'wkhtmltopdfPath' => array('setting', 'wkhtmltopdfPath'),
- 'wpBasePage' => array('setting', 'wpBasePage'),
- 'wpLoadPhp' => array('setting', 'wpLoadPhp'),
-
- 'doNotResetCache' => array('local', 'doNotResetCache'),
- 'inCiviCRM' => array('local', 'inCiviCRM'),
- 'userFrameworkFrontend' => array('local', 'userFrameworkFrontend'),
- 'initialized' => array('local', 'initialized'),
-
- 'dsn' => array('runtime', 'dsn'),
- 'userFramework' => array('runtime', 'userFramework'),
- 'userFrameworkBaseURL' => array('runtime', 'userFrameworkBaseURL'),
- 'userFrameworkClass' => array('runtime', 'userFrameworkClass'),
- 'userFrameworkDSN' => array('runtime', 'userFrameworkDSN'),
+ 'monetaryDecimalPoint' => array('setting'),
+ 'monetaryThousandSeparator' => array('setting'),
+ 'moneyformat' => array('setting'),
+ 'moneyvalueformat' => array('setting'),
+ 'provinceLimit' => array('setting'),
+ 'recaptchaOptions' => array('setting'),
+ 'recaptchaPublicKey' => array('setting'),
+ 'recaptchaPrivateKey' => array('setting'),
+ 'secondDegRelPermissions' => array('setting'),
+ 'smartGroupCacheTimeout' => array('setting'),
+ 'timeInputFormat' => array('setting'),
+ 'userFrameworkLogging' => array('setting'),
+ 'userFrameworkUsersTableName' => array('setting'),
+ 'verpSeparator' => array('setting'),
+ 'wkhtmltopdfPath' => array('setting'),
+ 'wpBasePage' => array('setting'),
+ 'wpLoadPhp' => array('setting'),
+
+ 'doNotResetCache' => array('local'),
+ 'inCiviCRM' => array('local'),
+ 'userFrameworkFrontend' => array('local'),
+ 'initialized' => array('local'),
+
+ 'dsn' => array('runtime'),
+ 'userFramework' => array('runtime'),
+ 'userFrameworkBaseURL' => array('runtime'),
+ 'userFrameworkClass' => array('runtime'),
+ 'userFrameworkDSN' => array('runtime'),
'useFrameworkRelativeBase' => array('runtime', 'useFrameworkRelativeBase'),
- 'userFrameworkURLVar' => array('runtime', 'userFrameworkURLVar'),
- 'userPermissionClass' => array('runtime', 'userPermissionClass'),
- 'userPermissionTemp' => array('runtime', 'userPermissionTemp'),
- 'userSystem' => array('runtime', 'userSystem'),
- 'userHookClass' => array('runtime', 'userHookClass'),
- 'cleanURL' => array('runtime', 'cleanURL'),
- 'configAndLogDir' => array('runtime', 'configAndLogDir'),
- 'templateCompileDir' => array('runtime', 'templateCompileDir'),
- 'templateDir' => array('runtime', 'templateDir'),
-
- 'customFileUploadDir' => array('callback', 'CRM_Core_Config_Defaults', 'getCustomFileUploadDir', 'setPath', 'revert'),
- 'customPHPPathDir' => array('callback', 'CRM_Core_Config_Defaults', 'getCustomPhpPathDir', 'setPath', 'revert'),
- 'customTemplateDir' => array('callback', 'CRM_Core_Config_Defaults', 'getCustomTemplateDir', 'setPath', 'revert'),
- 'extensionsDir' => array('callback', 'CRM_Core_Config_Defaults', 'getExtensionsDir', 'setPath', 'revert'),
- 'imageUploadDir' => array('callback', 'CRM_Core_Config_Defaults', 'getImageUploadDir', 'setPath', 'revert'),
- 'uploadDir' => array('callback', 'CRM_Core_Config_Defaults', 'getUploadDir', 'setPath'),
-
- 'customCSSURL' => array('callback', 'CRM_Core_Config_Defaults', 'getCustomCssUrl', 'setUrl', 'revert'),
- 'extensionsURL' => array('callback', 'CRM_Core_Config_Defaults', 'getExtensionsUrl', 'setUrl', 'revert'),
- 'imageUploadURL' => array('callback', 'CRM_Core_Config_Defaults', 'getImageUploadUrl', 'setUrl', 'revert'),
- 'resourceBase' => array('callback', 'CRM_Core_Config_Defaults', 'getResourceBase', 'setUrl', 'revert'),
- 'userFrameworkResourceURL' => array('callback', 'CRM_Core_Config_Defaults', 'getUserFrameworkResourceUrl', 'setUrl', 'revert'),
+ 'userFrameworkURLVar' => array('runtime'),
+ 'userPermissionClass' => array('runtime'),
+ 'userPermissionTemp' => array('runtime'),
+ 'userSystem' => array('runtime'),
+ 'userHookClass' => array('runtime'),
+ 'cleanURL' => array('runtime'),
+ 'configAndLogDir' => array('runtime'),
+ 'templateCompileDir' => array('runtime'),
+ 'templateDir' => array('runtime'),
+
+ 'customFileUploadDir' => array('setting-path', NULL, '[civicrm.files]/custom/', array('mkdir', 'restrict')),
+ 'customPHPPathDir' => array('setting-path'),
+ 'customTemplateDir' => array('setting-path'),
+ 'extensionsDir' => array('setting-path'),
+ 'imageUploadDir' => array('setting-path', NULL, '[civicrm.files]/persist/contribute/', array('mkdir')),
+ 'uploadDir' => array('setting-path', NULL, '[civicrm.files]/upload/', array('mkdir', 'restrict')),
+
+ 'customCSSURL' => array('setting-url-abs'),
+ 'extensionsURL' => array('setting-url-abs'),
+ 'imageUploadURL' => array('setting-url-abs', NULL, '[civicrm.files]/persist/contribute/'),
+ 'resourceBase' => array('setting-url-rel', 'userFrameworkResourceURL', '[civicrm]/.'),
+ 'userFrameworkResourceURL' => array('setting-url-abs', NULL, '[civicrm]/.'),
'geocodeMethod' => array('callback', 'CRM_Utils_Geocode', 'getProviderClass'),
'defaultCurrencySymbol' => array('callback', 'CRM_Core_Config_Defaults', 'getDefaultCurrencySymbol'),
- //'customFileUploadDir' => array('runtime', 'customFileUploadDir'),
- //'customPHPPathDir' => array('runtime', 'customPHPPathDir'),
- //'customTemplateDir' => array('runtime', 'customTemplateDir'),
- //'extensionsDir' => array('runtime', 'extensionsDir'),
- //'imageUploadDir' => array('runtime', 'imageUploadDir'),
- //'uploadDir' => array('runtime', 'uploadDir'),
- //
- //'customCSSURL' => array('runtime', 'customCSSURL'),
- //'extensionsURL' => array('runtime', 'extensionsURL'),
- //'imageUploadURL' => array('runtime', 'imageUploadURL'),
- //'resourceBase' => array('runtime', 'resourceBase'),
- //'userFrameworkResourceURL' => array('runtime', 'userFrameworkResourceURL'),
- //
- //'geocodeMethod' => array('runtime', 'geocodeMethod'),
- //'defaultCurrencySymbol' => array('runtime', 'defaultCurrencySymbol'),
);
}
if (!isset($this->map[$k])) {
throw new \CRM_Core_Exception("Cannot read unrecognized property CRM_Core_Config::\${$k}.");
}
- list ($type, $name) = $this->map[$k];
+
+ $type = $this->map[$k][0];
+ $name = isset($this->map[$k][1]) ? $this->map[$k][1] : $k;
switch ($type) {
case 'setting':
return $this->getSettings()->get($name);
case 'setting-path':
- return $this->getSettings()->getPath($name);
+ // Array(0 => $type, 1 => $setting, 2 => $default, 3 => $actions).
+ $value = $this->getSettings()->get($name);
+ if (empty($value) && isset($this->map[$k][2])) {
+ $value = $this->map[$k][2];
+ }
+ $value = Civi::paths()->getPath($value);
+ if ($value) {
+ $value = CRM_Utils_File::addTrailingSlash($value);
+ if (isset($this->map[$k][3]) && in_array('mkdir', $this->map[$k][3])) {
+ CRM_Utils_File::createDir($value);
+ }
+ if (isset($this->map[$k][3]) && in_array('restrict', $this->map[$k][3])) {
+ CRM_Utils_File::restrictAccess($value);
+ }
+ }
+ return $value;
+
+ case 'setting-url-abs':
+ // Array(0 => $type, 1 => $setting, 2 => $default).
+ $value = $this->getSettings()->get($name);
+ if (empty($value) && isset($this->map[$k][2])) {
+ $value = $this->map[$k][2];
+ }
+ return Civi::paths()->getUrl($value, 'absolute');
- case 'setting-url':
- return $this->getSettings()->getUrl($name, 'absolute');
+ case 'setting-url-rel':
+ // Array(0 => $type, 1 => $setting, 2 => $default).
+ $value = $this->getSettings()->get($name);
+ if (empty($value) && isset($this->map[$k][2])) {
+ $value = $this->map[$k][2];
+ }
+ return Civi::paths()->getUrl($value, 'relative');
case 'runtime':
return $this->getRuntime()->{$name};
$this->getSettings()->set($name, $v);
return;
- case 'setting-path':
- $this->getSettings()->setPath($name, $v);
- return;
-
- case 'setting-url':
- $this->getSettings()->setUrl($name, $v);
- return;
-
case 'runtime':
$this->getRuntime()->{$name} = $v;
return;
switch ($type) {
case 'setting':
case 'setting-path':
- case 'setting-url':
+ case 'setting-url-abs':
+ case 'setting-url-rel':
$this->getSettings()->revert($k);
return;
--- /dev/null
+<?php
+namespace Civi\Core;
+
+/**
+ * Class Paths
+ * @package Civi\Core
+ *
+ * This paths class translates path-expressions into local file paths and
+ * URLs. Path-expressions may take a few forms:
+ *
+ * - Paths and URLs may use a variable prefix. For example, '[civicrm.files]/upload'
+ * - Paths and URLS may be absolute.
+ * - Paths may be relative (base dir: [civicrm.files]).
+ * - URLs may be relative (base dir: [cms.root]).
+ */
+class Paths {
+
+ const DEFAULT_URL = 'cms.root';
+ const DEFAULT_PATH = 'civicrm.files';
+
+ /**
+ * @var array
+ * Array(string $name => array(url => $, path => $)).
+ */
+ private $containers = array();
+
+ protected $containerFactory = array();
+
+ public function __construct() {
+ $this
+ ->register('civicrm', function () {
+ return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
+ })
+ ->register('civicrm.root', function () {
+ return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
+ })
+ ->register('civicrm.files', function () {
+ return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
+ })
+ ->register('cms', function () {
+ return array(
+ 'path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(),
+ 'url' => \CRM_Utils_System::baseCMSURL(),
+ );
+ })
+ ->register('cms.root', function () {
+ return array(
+ 'path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(),
+ // Misleading: this *removes* the language part of the URL, producing a pristine base URL.
+ 'url' => \CRM_Utils_System::languageNegotiationURL(\CRM_Utils_System::baseCMSURL(), FALSE, TRUE),
+ );
+ });
+ }
+
+ /**
+ * Register a new URL/file path mapping.
+ *
+ * @param string $name
+ * The name of the container.
+ * @param callable $factory
+ * Function which returns an array with keys:
+ * - path: string.
+ * - url: string.
+ * @return $this
+ */
+ public function register($name, $factory) {
+ $this->containerFactory[$name] = $factory;
+ return $this;
+ }
+
+ protected function getContainerAttr($name, $attr) {
+ if (!isset($this->containers[$name])) {
+ $this->containers[$name] = call_user_func($this->containerFactory[$name]);
+ }
+ if (!isset($this->containers[$name][$attr])) {
+ throw new \RuntimeException("Cannot resolve path using \"$name.$attr\"");
+ }
+ return $this->containers[$name][$attr];
+ }
+
+ /**
+ * Determine the absolute path to a file, given that the file is most likely
+ * in a given particular container.
+ *
+ * @param string $value
+ * The file path (which is probably relative to $container).
+ * Use "." to reference to container root.
+ * Values may explicitly specify the a container, e.g. "[civicrm.files]/upload".
+ * @return mixed|string
+ */
+ public function getPath($value) {
+ $defaultContainer = self::DEFAULT_PATH;
+ if ($value && $value{0} == '[' && preg_match(';^\[([a-zA-Z0-9\._]+)\]/(.*);', $value, $matches)) {
+ $defaultContainer = $matches[1];
+ $value = $matches[2];
+ }
+ if (empty($value)) {
+ return FALSE;
+ }
+ if ($value === '.') {
+ $value = '';
+ }
+ return \CRM_Utils_File::absoluteDirectory($value, $this->getContainerAttr($defaultContainer, 'path'));
+ }
+
+ /**
+ * Determine the absolute URL to a file, given that the file is most likely
+ * in a given particular container.
+ *
+ * @param string $value
+ * The file path (which is probably relative to $container).
+ * Values may explicitly specify the a container, e.g. "[civicrm.files]/upload".
+ * @param string $preferFormat
+ * The preferred format ('absolute', 'relative').
+ * The result data may not meet the preference -- if the setting
+ * refers to an external domain, then the result will be
+ * absolute (regardless of preference).
+ * @param bool|NULL $ssl
+ * NULL to autodetect. TRUE to force to SSL.
+ * @return mixed|string
+ */
+ public function getUrl($value, $preferFormat = 'relative', $ssl = NULL) {
+ $defaultContainer = self::DEFAULT_URL;
+ if ($value && $value{0} == '[' && preg_match(';^\[([a-zA-Z0-9\._]+)\]/(.*);', $value, $matches)) {
+ $defaultContainer = $matches[1];
+ $value = $matches[2];
+ }
+
+ if (empty($value)) {
+ return FALSE;
+ }
+ if ($value === '.') {
+ $value = '';
+ }
+ if (substr($value, 0, 4) == 'http') {
+ return $value;
+ }
+
+ $value = $this->getContainerAttr($defaultContainer, 'url') . $value;
+
+ if ($preferFormat === 'relative') {
+ $parsed = parse_url($value);
+ if (isset($_SERVER['HTTP_HOST']) && isset($parsed['host']) && $_SERVER['HTTP_HOST'] == $parsed['host']) {
+ $value = $parsed['path'];
+ }
+ }
+
+ if ($ssl || ($ssl === NULL && \CRM_Utils_System::isSSL())) {
+ $value = str_replace('http://', 'https://', $value);
+ }
+
+ return $value;
+ }
+
+}