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