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