26d652a7093a356cf225bfc5ae5096c31210b42e
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class is a temporary place to store default setting values
38 * before they will be distributed in proper places (component configurations
39 * and core configuration). The name is intentionally stupid so that it will be fixed
43 class CRM_Core_Config_Defaults
{
45 public function setCoreVariables() {
48 // set of base directories relying on $civicrm_root
49 $this->smartyDir
= $civicrm_root . DIRECTORY_SEPARATOR
. 'packages' . DIRECTORY_SEPARATOR
. 'Smarty' . DIRECTORY_SEPARATOR
;
51 $this->pluginsDir
= $civicrm_root . DIRECTORY_SEPARATOR
. 'CRM' . DIRECTORY_SEPARATOR
. 'Core' . DIRECTORY_SEPARATOR
. 'Smarty' . DIRECTORY_SEPARATOR
. 'plugins' . DIRECTORY_SEPARATOR
;
53 $this->templateDir
= array(
54 $civicrm_root . DIRECTORY_SEPARATOR
.
55 'templates' . DIRECTORY_SEPARATOR
,
58 $this->sqlDir
= $civicrm_root . DIRECTORY_SEPARATOR
. 'sql' . DIRECTORY_SEPARATOR
;
62 * Set the default values.
63 * in an empty db, also called when setting component using GUI
65 * @param array $defaults
66 * Associated array of form elements.
67 * @param bool $formMode
68 * this variable is set true for GUI
69 * mode (eg: Global setting >> Components)
72 public static function setValues(&$defaults, $formMode = FALSE) {
73 $config = CRM_Core_Config
::singleton();
75 $baseURL = $config->userFrameworkBaseURL
;
77 // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH,
78 // which needs to be stripped before we start basing ResourceURL on it
79 if ($config->userSystem
->is_drupal
) {
81 if (isset($language->prefix
) and $language->prefix
) {
82 if (substr($baseURL, -(strlen($language->prefix
) +
1)) == $language->prefix
. '/') {
83 $baseURL = substr($baseURL, 0, -(strlen($language->prefix
) +
1));
88 $baseCMSURL = CRM_Utils_System
::baseCMSURL();
89 if ($config->templateCompileDir
) {
90 $path = CRM_Utils_File
::baseFilePath($config->templateCompileDir
);
92 if (!isset($defaults['enableSSL'])) {
93 $defaults['enableSSL'] = 0;
95 //set defaults if not set in db
96 if (!isset($defaults['userFrameworkResourceURL'])) {
97 if ($config->userFramework
== 'Joomla') {
98 $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
100 elseif ($config->userFramework
== 'WordPress') {
101 $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
105 // check and see if we are installed in sites/all (for D5 and above)
106 // we dont use checkURL since drupal generates an error page and throws
107 // the system for a loop on lobo's macosx box
109 global $civicrm_root;
110 $cmsPath = $config->userSystem
->cmsRootPath();
111 $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("$cmsPath/", '',
112 str_replace('\\', '/', $civicrm_root)
115 if (strpos($civicrm_root,
116 DIRECTORY_SEPARATOR
. 'sites' .
117 DIRECTORY_SEPARATOR
. 'all' .
118 DIRECTORY_SEPARATOR
. 'modules'
121 $startPos = strpos($civicrm_root,
122 DIRECTORY_SEPARATOR
. 'sites' . DIRECTORY_SEPARATOR
124 $endPos = strpos($civicrm_root,
125 DIRECTORY_SEPARATOR
. 'modules' . DIRECTORY_SEPARATOR
127 if ($startPos && $endPos) {
128 // if component is in sites/SITENAME/modules
129 $siteName = substr($civicrm_root,
131 $endPos - $startPos - 7
134 $civicrmDirName = trim(basename($civicrm_root));
135 $defaults['userFrameworkResourceURL'] = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
136 if (!isset($defaults['imageUploadURL'])) {
137 $defaults['imageUploadURL'] = $baseURL . "sites/$siteName/files/civicrm/persist/contribute/";
144 if (!isset($defaults['imageUploadURL'])) {
145 if ($config->userFramework
== 'Joomla') {
147 // we need to remove the administrator/ from the end
148 $tempURL = str_replace("/administrator/", "/", $baseURL);
149 $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
151 elseif ($config->userFramework
== 'WordPress') {
152 //for standalone no need of sites/defaults directory
153 $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/";
156 $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
160 if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir
)) {
161 $imgDir = $path . "persist/contribute/";
163 CRM_Utils_File
::createDir($imgDir);
164 $defaults['imageUploadDir'] = $imgDir;
167 if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir
)) {
168 $uploadDir = $path . "upload/";
170 CRM_Utils_File
::createDir($uploadDir);
171 CRM_Utils_File
::restrictAccess($uploadDir);
172 $defaults['uploadDir'] = $uploadDir;
175 if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir
)) {
176 $customDir = $path . "custom/";
178 CRM_Utils_File
::createDir($customDir);
179 CRM_Utils_File
::restrictAccess($customDir);
180 $defaults['customFileUploadDir'] = $customDir;
183 // FIXME: hack to bypass the step for generating defaults for components,
184 // while running upgrade, to avoid any serious non-recoverable error
185 // which might hinder the upgrade process.
187 if (isset($_GET[$config->userFrameworkURLVar
])) {
188 $args = explode('/', $_GET[$config->userFrameworkURLVar
]);
191 if (isset($defaults['enableComponents'])) {
192 foreach ($defaults['enableComponents'] as $key => $name) {
193 $comp = $config->componentRegistry
->get($name);
195 $co = $comp->getConfigObject();
196 $co->setDefaults($defaults);