phpcs - Fix error, "CONST keyword must be lowercase; expected const but found CONST"
[civicrm-core.git] / CRM / Core / Config / Defaults.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
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 {
2ba175b6 44
6a488035
TO
45 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 $this->importDataSourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'DataSource' . DIRECTORY_SEPARATOR;
61
62 $this->gettextResourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
63
64 // show tree widget
65 $this->groupTree = defined('CIVICRM_GROUPTREE') ? TRUE : FALSE;
66
67 // add UI revamp pages
68 //$this->revampPages = array( 'CRM/Admin/Form/Setting/Url.tpl', 'CRM/Admin/Form/Preferences/Address.tpl' );
69 $this->revampPages = array();
70
6a488035 71 $size = trim(ini_get('upload_max_filesize'));
66dc6009 72 if ($size) {
73 $this->maxImportFileSize = self::formatUnitSize($size);
74 }
75 }
76
77 /**
100fef9d 78 * Format size
66dc6009 79 *
80 * @access public
81 * @static
82 */
83
84 public static function formatUnitSize($size, $checkForPostMax = FALSE) {
6a488035
TO
85 if ($size) {
86 $last = strtolower($size{strlen($size) - 1});
87 switch ($last) {
88 // The 'G' modifier is available since PHP 5.1.0
89
90 case 'g':
91 $size *= 1024;
92 case 'm':
93 $size *= 1024;
94 case 'k':
95 $size *= 1024;
96 }
66dc6009 97
98 if ($checkForPostMax) {
99 $config = CRM_Core_Config::singleton();
100 if($config->maxImportFileSize > $size) {
101 CRM_Core_Session::setStatus(ts("Note: Upload max filesize ('upload_max_filesize') should not exceed Post max size ('post_max_size') as defined in PHP.ini, please check with your system administrator."), ts("Warning"), "alert");
102 }
103 }
104 return $size;
6a488035
TO
105 }
106 }
107
108 /**
100fef9d 109 * Set the default values
6a488035 110 *
dd244018
EM
111 * @param array $defaults associated array of form elements
112 * @param bool|\boolena $formMode this funtion is called to set default
6a488035
TO
113 * values in an empty db, also called when setting component using GUI
114 * this variable is set true for GUI
115 * mode (eg: Global setting >> Components)
116 *
117 * @access public
118 * @static
119 */
120 public static function setValues(&$defaults, $formMode = FALSE) {
121 $config = CRM_Core_Config::singleton();
122
123 $baseURL = $config->userFrameworkBaseURL;
124
125 // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH,
126 // which needs to be stripped before we start basing ResourceURL on it
127 if ($config->userSystem->is_drupal) {
128 global $language;
129 if (isset($language->prefix) and $language->prefix) {
130 if (substr($baseURL, -(strlen($language->prefix) + 1)) == $language->prefix . '/') {
131 $baseURL = substr($baseURL, 0, -(strlen($language->prefix) + 1));
132 }
133 }
134 }
135
136 $baseCMSURL = CRM_Utils_System::baseCMSURL();
137 if ($config->templateCompileDir) {
138 $path = CRM_Utils_File::baseFilePath($config->templateCompileDir);
139 }
140 if (!isset($defaults['enableSSL'])) {
141 $defaults['enableSSL'] = 0;
142 }
143 //set defaults if not set in db
144 if (!isset($defaults['userFrameworkResourceURL'])) {
145 if ($config->userFramework == 'Joomla') {
146 $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
147 }
148 elseif ($config->userFramework == 'WordPress') {
149 $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
150 }
151 else {
152 // Drupal setting
153 // check and see if we are installed in sites/all (for D5 and above)
154 // we dont use checkURL since drupal generates an error page and throws
155 // the system for a loop on lobo's macosx box
156 // or in modules
157 global $civicrm_root;
158 $cmsPath = $config->userSystem->cmsRootPath();
159 $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("$cmsPath/", '',
160 str_replace('\\', '/', $civicrm_root)
161 );
162
163 if (strpos($civicrm_root,
164 DIRECTORY_SEPARATOR . 'sites' .
165 DIRECTORY_SEPARATOR . 'all' .
166 DIRECTORY_SEPARATOR . 'modules'
167 ) === FALSE) {
168 $startPos = strpos($civicrm_root,
169 DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
170 );
171 $endPos = strpos($civicrm_root,
172 DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
173 );
174 if ($startPos && $endPos) {
175 // if component is in sites/SITENAME/modules
176 $siteName = substr($civicrm_root,
177 $startPos + 7,
178 $endPos - $startPos - 7
179 );
180
181 $civicrmDirName = trim(basename($civicrm_root));
182 $defaults['userFrameworkResourceURL'] = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
183 if (!isset($defaults['imageUploadURL'])) {
184 $defaults['imageUploadURL'] = $baseURL . "sites/$siteName/files/civicrm/persist/contribute/";
185 }
186 }
187 }
188 }
189 }
190
191 if (!isset($defaults['imageUploadURL'])) {
192 if ($config->userFramework == 'Joomla') {
193 // gross hack
194 // we need to remove the administrator/ from the end
195 $tempURL = str_replace("/administrator/", "/", $baseURL);
196 $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
197 }
198 elseif ($config->userFramework == 'WordPress') {
199 //for standalone no need of sites/defaults directory
200 $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/";
201 }
202 else {
203 $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
204 }
205 }
206
207 if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
208 $imgDir = $path . "persist/contribute/";
209
210 CRM_Utils_File::createDir($imgDir);
211 $defaults['imageUploadDir'] = $imgDir;
212 }
213
214 if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
215 $uploadDir = $path . "upload/";
216
217 CRM_Utils_File::createDir($uploadDir);
218 CRM_Utils_File::restrictAccess($uploadDir);
219 $defaults['uploadDir'] = $uploadDir;
220 }
221
222 if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
223 $customDir = $path . "custom/";
224
225 CRM_Utils_File::createDir($customDir);
a738c74c 226 CRM_Utils_File::restrictAccess($customDir);
6a488035
TO
227 $defaults['customFileUploadDir'] = $customDir;
228 }
229
230 /* FIXME: hack to bypass the step for generating defaults for components,
231 while running upgrade, to avoid any serious non-recoverable error
232 which might hinder the upgrade process. */
233
234
235 $args = array();
236 if (isset($_GET[$config->userFrameworkURLVar])) {
237 $args = explode('/', $_GET[$config->userFrameworkURLVar]);
238 }
239
240 if (isset($defaults['enableComponents'])) {
241 foreach ($defaults['enableComponents'] as $key => $name) {
242 $comp = $config->componentRegistry->get($name);
243 if ($comp) {
244 $co = $comp->getConfigObject();
245 $co->setDefaults($defaults);
246 }
247 }
248 }
249 }
250}
251