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