Elgg  Version 1.11
Config.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
4 
14 class Config {
20  private $CONFIG;
21 
25  public function __construct() {
27  $this->CONFIG = $CONFIG;
28  }
29 
36  function getSiteUrl($site_guid = 0) {
37  if ($site_guid == 0) {
38 
39  return $this->CONFIG->wwwroot;
40  }
41 
42  $site = get_entity($site_guid);
43 
44  if (!$site instanceof \ElggSite) {
45  return false;
46  }
47  /* @var \ElggSite $site */
48 
49  return $site->url;
50  }
51 
57  function getPluginsPath() {
58 
59  return $this->CONFIG->pluginspath;
60  }
61 
67  function getDataPath() {
68 
69  return $this->CONFIG->dataroot;
70  }
71 
77  function getRootPath() {
78 
79  return $this->CONFIG->path;
80  }
81 
90  function get($name, $site_guid = 0) {
91 
92 
93  $name = trim($name);
94 
95  // do not return $CONFIG value if asking for non-current site
96  if (($site_guid === 0 || $site_guid === null || $site_guid == $this->CONFIG->site_guid) && isset($this->CONFIG->$name)) {
97  return $this->CONFIG->$name;
98  }
99 
100  if ($site_guid === null) {
101  // installation wide setting
102  $value = _elgg_services()->datalist->get($name);
103  } else {
104  if ($site_guid == 0) {
105  $site_guid = (int) $this->CONFIG->site_guid;
106  }
107 
108  // hit DB only if we're not sure if value isn't already loaded
109  if (!isset($this->CONFIG->site_config_loaded) || $site_guid != $this->CONFIG->site_guid) {
110  // site specific setting
111  $value = _elgg_services()->configTable->get($name, $site_guid);
112  } else {
113  $value = null;
114  }
115  }
116 
117  // @todo document why we don't cache false
118  if ($value === false) {
119  return null;
120  }
121 
122  if ($site_guid == $this->CONFIG->site_guid || $site_guid === null) {
123  $this->CONFIG->$name = $value;
124  }
125 
126  return $value;
127  }
128 
139  function set($name, $value) {
140 
141 
142  $name = trim($name);
143 
144  $this->CONFIG->$name = $value;
145  }
146 
156  function save($name, $value, $site_guid = 0) {
157 
158 
159  $name = trim($name);
160 
161  if (strlen($name) > 255) {
162  _elgg_services()->logger->error("The name length for configuration variables cannot be greater than 255");
163  return false;
164  }
165 
166  if ($site_guid === null) {
167  if (is_array($value) || is_object($value)) {
168  return false;
169  }
170  $result = _elgg_services()->datalist->set($name, $value);
171  } else {
172  if ($site_guid == 0) {
173  $site_guid = (int) $this->CONFIG->site_guid;
174  }
175  $result = _elgg_services()->configTable->set($name, $value, $site_guid);
176  }
177 
178  if ($site_guid === null || $site_guid == $this->CONFIG->site_guid) {
179  _elgg_services()->config->set($name, $value);
180  }
181 
182  return $result;
183  }
184 }
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$value
Definition: longtext.php:26
getRootPath()
Get the root directory path for this installation.
Definition: Config.php:77
getPluginsPath()
Get the plugin path for this installation.
Definition: Config.php:57
save($name, $value, $site_guid=0)
Save a configuration setting.
Definition: Config.php:156
Save menu items.
_elgg_services()
Definition: autoloader.php:14
global $CONFIG
elgg global
Pointer to the global context.
Definition: elgglib.js:12
getSiteUrl($site_guid=0)
Get the URL for the current (or specified) site.
Definition: Config.php:36
__construct()
Constructor.
Definition: Config.php:25
getDataPath()
Get the data directory path for this installation.
Definition: Config.php:67
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382