Ian province abbreviation patch - issue 724
[civicrm-core.git] / CRM / Core / Config / Defaults.php
... / ...
CommitLineData
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35
36/**
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
40 * ASAP.
41 *
42 */
43class CRM_Core_Config_Defaults {
44
45 public function setCoreVariables() {
46 global $civicrm_root;
47
48 // set of base directories relying on $civicrm_root
49 $this->smartyDir = $civicrm_root . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR;
50
51 $this->pluginsDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR;
52
53 $this->templateDir = array(
54 $civicrm_root . DIRECTORY_SEPARATOR .
55 'templates' . DIRECTORY_SEPARATOR,
56 );
57
58 $this->sqlDir = $civicrm_root . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR;
59 }
60
61 /**
62 * Set the default values.
63 * in an empty db, also called when setting component using GUI
64 *
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)
70 *
71 */
72 public static function setValues(&$defaults, $formMode = FALSE) {
73 $config = CRM_Core_Config::singleton();
74
75 $baseURL = $config->userFrameworkBaseURL;
76
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) {
80 global $language;
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));
84 }
85 }
86 }
87
88 $baseCMSURL = CRM_Utils_System::baseCMSURL();
89 if ($config->templateCompileDir) {
90 $path = CRM_Utils_File::baseFilePath($config->templateCompileDir);
91 }
92 if (!isset($defaults['enableSSL'])) {
93 $defaults['enableSSL'] = 0;
94 }
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/";
99 }
100 elseif ($config->userFramework == 'WordPress') {
101 $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
102 }
103 else {
104 // Drupal setting
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
108 // or in modules
109 global $civicrm_root;
110 $cmsPath = $config->userSystem->cmsRootPath();
111 $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("$cmsPath/", '',
112 str_replace('\\', '/', $civicrm_root)
113 );
114
115 if (strpos($civicrm_root,
116 DIRECTORY_SEPARATOR . 'sites' .
117 DIRECTORY_SEPARATOR . 'all' .
118 DIRECTORY_SEPARATOR . 'modules'
119 ) === FALSE
120 ) {
121 $startPos = strpos($civicrm_root,
122 DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
123 );
124 $endPos = strpos($civicrm_root,
125 DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
126 );
127 if ($startPos && $endPos) {
128 // if component is in sites/SITENAME/modules
129 $siteName = substr($civicrm_root,
130 $startPos + 7,
131 $endPos - $startPos - 7
132 );
133
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/";
138 }
139 }
140 }
141 }
142 }
143
144 if (!isset($defaults['imageUploadURL'])) {
145 if ($config->userFramework == 'Joomla') {
146 // gross hack
147 // we need to remove the administrator/ from the end
148 $tempURL = str_replace("/administrator/", "/", $baseURL);
149 $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
150 }
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/";
154 }
155 else {
156 $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
157 }
158 }
159
160 if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
161 $imgDir = $path . "persist/contribute/";
162
163 CRM_Utils_File::createDir($imgDir);
164 $defaults['imageUploadDir'] = $imgDir;
165 }
166
167 if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
168 $uploadDir = $path . "upload/";
169
170 CRM_Utils_File::createDir($uploadDir);
171 CRM_Utils_File::restrictAccess($uploadDir);
172 $defaults['uploadDir'] = $uploadDir;
173 }
174
175 if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
176 $customDir = $path . "custom/";
177
178 CRM_Utils_File::createDir($customDir);
179 CRM_Utils_File::restrictAccess($customDir);
180 $defaults['customFileUploadDir'] = $customDir;
181 }
182
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.
186 $args = array();
187 if (isset($_GET[$config->userFrameworkURLVar])) {
188 $args = explode('/', $_GET[$config->userFrameworkURLVar]);
189 }
190
191 if (isset($defaults['enableComponents'])) {
192 foreach ($defaults['enableComponents'] as $key => $name) {
193 $comp = $config->componentRegistry->get($name);
194 if ($comp) {
195 $co = $comp->getConfigObject();
196 $co->setDefaults($defaults);
197 }
198 }
199 }
200 }
201
202}