Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-07-14-22-39-05
[civicrm-core.git] / CRM / Core / Config / Defaults.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 */
43 class CRM_Core_Config_Defaults {
44 function setCoreVariables() {
45 global $civicrm_root;
46
47 // set of base directories relying on $civicrm_root
48 $this->smartyDir = $civicrm_root . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR;
49
50 $this->pluginsDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR;
51
52 $this->templateDir = array(
53 $civicrm_root . DIRECTORY_SEPARATOR .
54 'templates' . DIRECTORY_SEPARATOR,
55 );
56
57 $this->sqlDir = $civicrm_root . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR;
58
59 $this->importDataSourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'DataSource' . DIRECTORY_SEPARATOR;
60
61 $this->gettextResourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
62
63 // show tree widget
64 $this->groupTree = defined('CIVICRM_GROUPTREE') ? TRUE : FALSE;
65
66 // add UI revamp pages
67 //$this->revampPages = array( 'CRM/Admin/Form/Setting/Url.tpl', 'CRM/Admin/Form/Preferences/Address.tpl' );
68 $this->revampPages = array();
69
70 $size = trim(ini_get('upload_max_filesize'));
71 if ($size) {
72 $last = strtolower($size{strlen($size) - 1});
73 switch ($last) {
74 // The 'G' modifier is available since PHP 5.1.0
75
76 case 'g':
77 $size *= 1024;
78 case 'm':
79 $size *= 1024;
80 case 'k':
81 $size *= 1024;
82 }
83 $this->maxImportFileSize = $size;
84 }
85 }
86
87 /**
88 * Function to set the default values
89 *
90 * @param array $defaults associated array of form elements
91 * @param boolena $formMode this funtion is called to set default
92 * values in an empty db, also called when setting component using GUI
93 * this variable is set true for GUI
94 * mode (eg: Global setting >> Components)
95 *
96 * @access public
97 * @static
98 */
99 public static function setValues(&$defaults, $formMode = FALSE) {
100 $config = CRM_Core_Config::singleton();
101
102 $baseURL = $config->userFrameworkBaseURL;
103
104 // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH,
105 // which needs to be stripped before we start basing ResourceURL on it
106 if ($config->userSystem->is_drupal) {
107 global $language;
108 if (isset($language->prefix) and $language->prefix) {
109 if (substr($baseURL, -(strlen($language->prefix) + 1)) == $language->prefix . '/') {
110 $baseURL = substr($baseURL, 0, -(strlen($language->prefix) + 1));
111 }
112 }
113 }
114
115 $baseCMSURL = CRM_Utils_System::baseCMSURL();
116 if ($config->templateCompileDir) {
117 $path = CRM_Utils_File::baseFilePath($config->templateCompileDir);
118 }
119 if (!isset($defaults['enableSSL'])) {
120 $defaults['enableSSL'] = 0;
121 }
122 //set defaults if not set in db
123 if (!isset($defaults['userFrameworkResourceURL'])) {
124 if ($config->userFramework == 'Joomla') {
125 $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
126 }
127 elseif ($config->userFramework == 'WordPress') {
128 $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
129 }
130 else {
131 // Drupal setting
132 // check and see if we are installed in sites/all (for D5 and above)
133 // we dont use checkURL since drupal generates an error page and throws
134 // the system for a loop on lobo's macosx box
135 // or in modules
136 global $civicrm_root;
137 $cmsPath = $config->userSystem->cmsRootPath();
138 $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("$cmsPath/", '',
139 str_replace('\\', '/', $civicrm_root)
140 );
141
142 if (strpos($civicrm_root,
143 DIRECTORY_SEPARATOR . 'sites' .
144 DIRECTORY_SEPARATOR . 'all' .
145 DIRECTORY_SEPARATOR . 'modules'
146 ) === FALSE) {
147 $startPos = strpos($civicrm_root,
148 DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
149 );
150 $endPos = strpos($civicrm_root,
151 DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
152 );
153 if ($startPos && $endPos) {
154 // if component is in sites/SITENAME/modules
155 $siteName = substr($civicrm_root,
156 $startPos + 7,
157 $endPos - $startPos - 7
158 );
159
160 $civicrmDirName = trim(basename($civicrm_root));
161 $defaults['userFrameworkResourceURL'] = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
162 if (!isset($defaults['imageUploadURL'])) {
163 $defaults['imageUploadURL'] = $baseURL . "sites/$siteName/files/civicrm/persist/contribute/";
164 }
165 }
166 }
167 }
168 }
169
170 if (!isset($defaults['imageUploadURL'])) {
171 if ($config->userFramework == 'Joomla') {
172 // gross hack
173 // we need to remove the administrator/ from the end
174 $tempURL = str_replace("/administrator/", "/", $baseURL);
175 $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
176 }
177 elseif ($config->userFramework == 'WordPress') {
178 //for standalone no need of sites/defaults directory
179 $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/";
180 }
181 else {
182 $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
183 }
184 }
185
186 if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
187 $imgDir = $path . "persist/contribute/";
188
189 CRM_Utils_File::createDir($imgDir);
190 $defaults['imageUploadDir'] = $imgDir;
191 }
192
193 if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
194 $uploadDir = $path . "upload/";
195
196 CRM_Utils_File::createDir($uploadDir);
197 CRM_Utils_File::restrictAccess($uploadDir);
198 $defaults['uploadDir'] = $uploadDir;
199 }
200
201 if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
202 $customDir = $path . "custom/";
203
204 CRM_Utils_File::createDir($customDir);
205 $defaults['customFileUploadDir'] = $customDir;
206 }
207
208 /* FIXME: hack to bypass the step for generating defaults for components,
209 while running upgrade, to avoid any serious non-recoverable error
210 which might hinder the upgrade process. */
211
212
213 $args = array();
214 if (isset($_GET[$config->userFrameworkURLVar])) {
215 $args = explode('/', $_GET[$config->userFrameworkURLVar]);
216 }
217
218 if (isset($defaults['enableComponents'])) {
219 foreach ($defaults['enableComponents'] as $key => $name) {
220 $comp = $config->componentRegistry->get($name);
221 if ($comp) {
222 $co = $comp->getConfigObject();
223 $co->setDefaults($defaults);
224 }
225 }
226 }
227 }
228 }
229