Elgg  Version 1.11
configuration.php
Go to the documentation of this file.
1 <?php
28 function elgg_get_site_url($site_guid = 0) {
29  return _elgg_services()->config->getSiteUrl($site_guid);
30 }
31 
39  return _elgg_services()->config->getPluginsPath();
40 }
41 
48 function elgg_get_data_path() {
49  return _elgg_services()->config->getDataPath();
50 }
51 
58 function elgg_get_root_path() {
59  return _elgg_services()->config->getRootPath();
60 }
61 
71 function elgg_get_config($name, $site_guid = 0) {
72  return _elgg_services()->config->get($name, $site_guid);
73 }
74 
87  return _elgg_services()->config->set($name, $value);
88 }
89 
100 function elgg_save_config($name, $value, $site_guid = 0) {
101  return _elgg_services()->config->save($name, $value, $site_guid);
102 }
103 
117 function datalist_get($name) {
118  return _elgg_services()->datalist->get($name);
119 }
120 
139  return _elgg_services()->datalist->set($name, $value);
140 }
141 
169 function run_function_once($functionname, $timelastupdatedcheck = 0) {
170  return _elgg_services()->datalist->runFunctionOnce($functionname, $timelastupdatedcheck);
171 }
172 
187 function unset_config($name, $site_guid = 0) {
188  return _elgg_services()->configTable->remove($name, $site_guid);
189 }
190 
215 function set_config($name, $value, $site_guid = 0) {
216  return _elgg_services()->configTable->set($name, $value, $site_guid);
217 }
218 
235 function get_config($name, $site_guid = 0) {
236  return _elgg_services()->configTable->get($name, $site_guid);
237 }
238 
251  global $CONFIG;
252 
253  $CONFIG->site_guid = (int) datalist_get('default_site');
254  $CONFIG->site_id = $CONFIG->site_guid;
255  $CONFIG->site = _elgg_services()->entityTable->get($CONFIG->site_guid, 'site');
256  if (!$CONFIG->site) {
257  throw new \InstallationException("Unable to handle this request. This site is not configured or the database is down.");
258  }
259 
260  $CONFIG->wwwroot = $CONFIG->site->url;
261  $CONFIG->sitename = $CONFIG->site->name;
262  $CONFIG->sitedescription = $CONFIG->site->description;
263  $CONFIG->siteemail = $CONFIG->site->email;
264  $CONFIG->url = $CONFIG->wwwroot;
265 
266  _elgg_services()->configTable->loadAll();
267 
268  // gives hint to elgg_get_config function how to approach missing values
269  $CONFIG->site_config_loaded = true;
270 
271  if (!empty($CONFIG->debug)) {
272  _elgg_services()->logger->setLevel($CONFIG->debug);
273  _elgg_services()->logger->setDisplay(true);
274  }
275 }
276 
287  global $CONFIG;
288 
289  $install_root = str_replace("\\", "/", dirname(dirname(dirname(__FILE__))));
290  $defaults = array(
291  'path' => "$install_root/",
292  'view_path' => "$install_root/views/",
293  'plugins_path' => "$install_root/mod/",
294  'language' => 'en',
295 
296  // compatibility with old names for plugins not using elgg_get_config()
297  'viewpath' => "$install_root/views/",
298  'pluginspath' => "$install_root/mod/",
299  );
300 
301  foreach ($defaults as $name => $value) {
302  if (empty($CONFIG->$name)) {
303  $CONFIG->$name = $value;
304  }
305  }
306 
307  // set cookie values for session and remember me
308  if (!isset($CONFIG->cookies)) {
309  $CONFIG->cookies = array();
310  }
311  if (!isset($CONFIG->cookies['session'])) {
312  $CONFIG->cookies['session'] = array();
313  }
314  $session_defaults = session_get_cookie_params();
315  $session_defaults['name'] = 'Elgg';
316  $CONFIG->cookies['session'] = array_merge($session_defaults, $CONFIG->cookies['session']);
317  if (!isset($CONFIG->cookies['remember_me'])) {
318  $CONFIG->cookies['remember_me'] = array();
319  }
320  $session_defaults['name'] = 'elggperm';
321  $session_defaults['expire'] = strtotime("+30 days");
322  $CONFIG->cookies['remember_me'] = array_merge($session_defaults, $CONFIG->cookies['remember_me']);
323 
324  if (!is_memcache_available()) {
325  _elgg_services()->datalist->loadAll();
326  }
327 
328  // allow sites to set dataroot and simplecache_enabled in settings.php
329  if (isset($CONFIG->dataroot)) {
330  $CONFIG->dataroot = sanitise_filepath($CONFIG->dataroot);
331  $CONFIG->dataroot_in_settings = true;
332  } else {
333  $dataroot = datalist_get('dataroot');
334  if (!empty($dataroot)) {
335  $CONFIG->dataroot = $dataroot;
336  }
337  $CONFIG->dataroot_in_settings = false;
338  }
339  if (isset($CONFIG->simplecache_enabled)) {
340  $CONFIG->simplecache_enabled_in_settings = true;
341  } else {
342  $simplecache_enabled = datalist_get('simplecache_enabled');
343  if ($simplecache_enabled !== false) {
344  $CONFIG->simplecache_enabled = $simplecache_enabled;
345  } else {
346  $CONFIG->simplecache_enabled = 1;
347  }
348  $CONFIG->simplecache_enabled_in_settings = false;
349  }
350 
351  $system_cache_enabled = datalist_get('system_cache_enabled');
352  if ($system_cache_enabled !== false) {
353  $CONFIG->system_cache_enabled = $system_cache_enabled;
354  } else {
355  $CONFIG->system_cache_enabled = 1;
356  }
357 
358  // needs to be set before system, init for links in html head
359  $CONFIG->lastcache = (int)datalist_get("simplecache_lastupdate");
360 
361  $CONFIG->i18n_loaded_from_cache = false;
362 
363  // this must be synced with the enum for the entities table
364  $CONFIG->entity_types = array('group', 'object', 'site', 'user');
365 }
366 
370 function _elgg_config_test($hook, $type, $tests) {
371  global $CONFIG;
372  $tests[] = "{$CONFIG->path}engine/tests/ElggCoreConfigTest.php";
373  return $tests;
374 }
375 
376 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
377  $hooks->registerHandler('unit_test', 'system', '_elgg_config_test');
378 };
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$defaults
unset_config($name, $site_guid=0)
Removes a config setting.
elgg_save_config($name, $value, $site_guid=0)
Save a configuration setting.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
Definition: elgglib.php:368
get_config($name, $site_guid=0)
Gets a configuration value.
$value
Definition: longtext.php:26
_elgg_config_test($hook, $type, $tests)
private
_elgg_load_site_config()
Loads configuration related to this site.
datalist_get($name)
Get the value of a datalist element.
elgg_set_config($name, $value)
Set an Elgg configuration value.
_elgg_services()
Definition: autoloader.php:14
global $CONFIG
datalist_set($name, $value)
Set the value for a datalist element.
elgg_get_root_path()
Get the root directory path for this installation.
$dataroot
elgg global
Pointer to the global context.
Definition: elgglib.js:12
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
$type
Definition: add.php:8
run_function_once($functionname, $timelastupdatedcheck=0)
Run a function one time per installation.
elgg_get_plugins_path()
Get the plugin path for this installation.
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
elgg_get_data_path()
Get the data directory path for this installation.
_elgg_load_application_config()
Loads configuration related to Elgg as an application.
set_config($name, $value, $site_guid=0)
Add or update a config setting.