Commit | Line | Data |
---|---|---|
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 | */ | |
43 | class CRM_Core_Config_Defaults { | |
2ba175b6 | 44 | |
00be9182 | 45 | public function setCoreVariables() { |
6a488035 TO |
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 | * |
66dc6009 | 80 | * @static |
81 | */ | |
82 | ||
83 | public static function formatUnitSize($size, $checkForPostMax = FALSE) { | |
6a488035 TO |
84 | if ($size) { |
85 | $last = strtolower($size{strlen($size) - 1}); | |
86 | switch ($last) { | |
87 | // The 'G' modifier is available since PHP 5.1.0 | |
88 | ||
89 | case 'g': | |
90 | $size *= 1024; | |
91 | case 'm': | |
92 | $size *= 1024; | |
93 | case 'k': | |
94 | $size *= 1024; | |
95 | } | |
66dc6009 | 96 | |
97 | if ($checkForPostMax) { | |
fc19e2ac | 98 | $maxImportFileSize = self::formatUnitSize(ini_get('upload_max_filesize')); |
12e4bf47 | 99 | $postMaxSize = self::formatUnitSize(ini_get('post_max_size')); |
100 | if ($maxImportFileSize > $postMaxSize && $postMaxSize == $size) { | |
66dc6009 | 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 | } | |
12e4bf47 | 103 | //respect php.ini upload_max_filesize |
104 | if ($size > $maxImportFileSize) { | |
105 | $size = $maxImportFileSize; | |
106 | CRM_Core_Session::setStatus(ts("Note: Please verify your configuration for Maximum File Size (in MB) <a href='%1'>Administrator >> System Settings >> Misc</a>. It should support 'upload_max_size' as defined in PHP.ini.Please check with your system administrator.", array(1 => CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1'))), ts("Warning"), "alert"); | |
107 | } | |
66dc6009 | 108 | } |
109 | return $size; | |
6a488035 TO |
110 | } |
111 | } | |
112 | ||
113 | /** | |
100fef9d | 114 | * Set the default values |
6a488035 | 115 | * |
6a0b768e TO |
116 | * @param array $defaults |
117 | * Associated array of form elements. | |
dd244018 | 118 | * @param bool|\boolena $formMode this funtion is called to set default |
6a488035 TO |
119 | * values in an empty db, also called when setting component using GUI |
120 | * this variable is set true for GUI | |
121 | * mode (eg: Global setting >> Components) | |
122 | * | |
6a488035 TO |
123 | * @static |
124 | */ | |
125 | public static function setValues(&$defaults, $formMode = FALSE) { | |
126 | $config = CRM_Core_Config::singleton(); | |
127 | ||
128 | $baseURL = $config->userFrameworkBaseURL; | |
129 | ||
130 | // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH, | |
131 | // which needs to be stripped before we start basing ResourceURL on it | |
132 | if ($config->userSystem->is_drupal) { | |
133 | global $language; | |
134 | if (isset($language->prefix) and $language->prefix) { | |
135 | if (substr($baseURL, -(strlen($language->prefix) + 1)) == $language->prefix . '/') { | |
136 | $baseURL = substr($baseURL, 0, -(strlen($language->prefix) + 1)); | |
137 | } | |
138 | } | |
139 | } | |
140 | ||
141 | $baseCMSURL = CRM_Utils_System::baseCMSURL(); | |
142 | if ($config->templateCompileDir) { | |
143 | $path = CRM_Utils_File::baseFilePath($config->templateCompileDir); | |
144 | } | |
145 | if (!isset($defaults['enableSSL'])) { | |
146 | $defaults['enableSSL'] = 0; | |
147 | } | |
148 | //set defaults if not set in db | |
149 | if (!isset($defaults['userFrameworkResourceURL'])) { | |
150 | if ($config->userFramework == 'Joomla') { | |
151 | $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/"; | |
152 | } | |
153 | elseif ($config->userFramework == 'WordPress') { | |
154 | $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/"; | |
155 | } | |
156 | else { | |
157 | // Drupal setting | |
158 | // check and see if we are installed in sites/all (for D5 and above) | |
159 | // we dont use checkURL since drupal generates an error page and throws | |
160 | // the system for a loop on lobo's macosx box | |
161 | // or in modules | |
162 | global $civicrm_root; | |
163 | $cmsPath = $config->userSystem->cmsRootPath(); | |
164 | $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("$cmsPath/", '', | |
165 | str_replace('\\', '/', $civicrm_root) | |
166 | ); | |
167 | ||
168 | if (strpos($civicrm_root, | |
169 | DIRECTORY_SEPARATOR . 'sites' . | |
170 | DIRECTORY_SEPARATOR . 'all' . | |
171 | DIRECTORY_SEPARATOR . 'modules' | |
172 | ) === FALSE) { | |
173 | $startPos = strpos($civicrm_root, | |
174 | DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR | |
175 | ); | |
176 | $endPos = strpos($civicrm_root, | |
177 | DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR | |
178 | ); | |
179 | if ($startPos && $endPos) { | |
180 | // if component is in sites/SITENAME/modules | |
181 | $siteName = substr($civicrm_root, | |
182 | $startPos + 7, | |
183 | $endPos - $startPos - 7 | |
184 | ); | |
185 | ||
186 | $civicrmDirName = trim(basename($civicrm_root)); | |
187 | $defaults['userFrameworkResourceURL'] = $baseURL . "sites/$siteName/modules/$civicrmDirName/"; | |
188 | if (!isset($defaults['imageUploadURL'])) { | |
189 | $defaults['imageUploadURL'] = $baseURL . "sites/$siteName/files/civicrm/persist/contribute/"; | |
190 | } | |
191 | } | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
196 | if (!isset($defaults['imageUploadURL'])) { | |
197 | if ($config->userFramework == 'Joomla') { | |
198 | // gross hack | |
199 | // we need to remove the administrator/ from the end | |
200 | $tempURL = str_replace("/administrator/", "/", $baseURL); | |
201 | $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/"; | |
202 | } | |
203 | elseif ($config->userFramework == 'WordPress') { | |
204 | //for standalone no need of sites/defaults directory | |
205 | $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/"; | |
206 | } | |
207 | else { | |
208 | $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/"; | |
209 | } | |
210 | } | |
211 | ||
212 | if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) { | |
213 | $imgDir = $path . "persist/contribute/"; | |
214 | ||
215 | CRM_Utils_File::createDir($imgDir); | |
216 | $defaults['imageUploadDir'] = $imgDir; | |
217 | } | |
218 | ||
219 | if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) { | |
220 | $uploadDir = $path . "upload/"; | |
221 | ||
222 | CRM_Utils_File::createDir($uploadDir); | |
223 | CRM_Utils_File::restrictAccess($uploadDir); | |
224 | $defaults['uploadDir'] = $uploadDir; | |
225 | } | |
226 | ||
227 | if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) { | |
228 | $customDir = $path . "custom/"; | |
229 | ||
230 | CRM_Utils_File::createDir($customDir); | |
a738c74c | 231 | CRM_Utils_File::restrictAccess($customDir); |
6a488035 TO |
232 | $defaults['customFileUploadDir'] = $customDir; |
233 | } | |
234 | ||
235 | /* FIXME: hack to bypass the step for generating defaults for components, | |
236 | while running upgrade, to avoid any serious non-recoverable error | |
237 | which might hinder the upgrade process. */ | |
238 | ||
6a488035 TO |
239 | $args = array(); |
240 | if (isset($_GET[$config->userFrameworkURLVar])) { | |
241 | $args = explode('/', $_GET[$config->userFrameworkURLVar]); | |
242 | } | |
243 | ||
244 | if (isset($defaults['enableComponents'])) { | |
245 | foreach ($defaults['enableComponents'] as $key => $name) { | |
246 | $comp = $config->componentRegistry->get($name); | |
247 | if ($comp) { | |
248 | $co = $comp->getConfigObject(); | |
249 | $co->setDefaults($defaults); | |
250 | } | |
251 | } | |
252 | } | |
253 | } | |
254 | } |