7 use Elgg\Traits\Loggable;
138 private array $values = [];
140 private array $initial_values = [];
142 private bool $cookies_configured =
false;
144 private array $cookies = [];
149 protected array $locked_values = [
161 protected array $deprecated = [];
166 protected array $config_defaults = [
167 'admin_validation_notification' =>
false,
168 'allow_phpinfo' =>
false,
169 'authentication_failures_lifetime' => 600,
170 'authentication_failures_limit' => 5,
171 'auto_disable_plugins' =>
true,
172 'batch_run_time_in_secs' => 4,
173 'boot_cache_ttl' => 3600,
174 'can_change_username' =>
false,
175 'class_loader_verify_file_existence' =>
true,
176 'comment_box_collapses' =>
true,
177 'comments_group_only' =>
true,
178 'comments_latest_first' =>
true,
179 'comments_max_depth' => 0,
180 'comments_per_page' => 25,
181 'db_enable_query_logging' =>
false,
182 'db_query_cache_limit' => 50,
183 'default_limit' => 10,
184 'elgg_maintenance_mode' =>
false,
185 'email_html_part' =>
true,
186 'email_html_part_images' =>
'no',
187 'email_subject_limit' => 998,
188 'enable_delayed_email' =>
true,
189 'friendly_time_number_of_days' => 30,
191 'topbar' => [
'w' => 16,
'h' => 16,
'square' =>
true,
'upscale' =>
true],
192 'tiny' => [
'w' => 25,
'h' => 25,
'square' =>
true,
'upscale' =>
true],
193 'small' => [
'w' => 40,
'h' => 40,
'square' =>
true,
'upscale' =>
true],
194 'medium' => [
'w' => 100,
'h' => 100,
'square' =>
true,
'upscale' =>
true],
195 'large' => [
'w' => 200,
'h' => 200,
'square' =>
true,
'upscale' =>
true],
196 'master' => [
'w' => 10240,
'h' => 10240,
'square' =>
false,
'upscale' =>
false,
'crop' =>
false],
199 'language_detect_from_browser' =>
true,
201 'mentions_display_format' =>
'display_name',
202 'message_delay' => 6,
203 'min_password_length' => 6,
205 'notifications_max_runtime' => 45,
206 'notifications_queue_delay' => 0,
207 'pagination_behaviour' =>
'ajax-replace',
208 'require_admin_validation' =>
false,
209 'security_email_require_confirmation' =>
true,
210 'security_email_require_password' =>
true,
211 'security_notify_admins' =>
true,
212 'security_notify_user_password' =>
true,
213 'security_protect_upgrade' =>
true,
214 'session_bound_entity_icons' =>
false,
215 'simplecache_enabled' =>
false,
216 'subresource_integrity_enabled' =>
false,
217 'system_cache_enabled' =>
false,
218 'testing_mode' =>
false,
219 'trash_enabled' =>
true,
220 'trash_retention' => 30,
221 'user_joined_river' =>
false,
222 'webp_enabled' =>
true,
223 'who_can_change_language' =>
'everyone',
229 protected array $path_properties = [
241 const ENTITY_TYPES = [
'group',
'object',
'site',
'user'];
248 const SENSITIVE_PROPERTIES = [
264 $this->saveInitialValues($values);
266 $this->values = array_merge($this->config_defaults, $values);
269 $this->getCookieConfig();
282 unset($values[
$name]);
285 $this->initial_values = $values;
295 public static function factory(
string $settings_path =
''): static {
296 $settings_path = self::resolvePath($settings_path);
298 return self::fromFile($settings_path);
314 if (!is_readable(
$path)) {
320 if (isset($GLOBALS[
'CONFIG'])) {
322 $global = $GLOBALS[
'CONFIG'];
323 unset($GLOBALS[
'CONFIG']);
328 Includer::requireFile(
$path);
330 if (empty($GLOBALS[
'CONFIG']->
dataroot)) {
331 throw new ConfigurationException(__METHOD__ .
': Reading configs failed: The Elgg settings file is missing $CONFIG->dataroot.');
334 if (empty($GLOBALS[
'CONFIG']->
wwwroot)) {
335 throw new ConfigurationException(__METHOD__ .
': Reading configs failed: The Elgg settings file is missing $CONFIG->wwwroot.');
338 $config =
new self(get_object_vars($GLOBALS[
'CONFIG']));
340 if ($global !==
null) {
342 $GLOBALS[
'CONFIG'] = $global;
344 unset($GLOBALS[
'CONFIG']);
347 if (
$config->{
'X-Sendfile-Type'}) {
349 unset(
$config->{
'X-Sendfile-Type'});
352 if (
$config->{
'X-Accel-Mapping'}) {
354 unset(
$config->{
'X-Accel-Mapping'});
367 public static function resolvePath(
string $settings_path =
''): string {
368 if (empty($settings_path)) {
369 $settings_path = Paths::settingsFile(Paths::SETTINGS_PHP);
372 return Paths::sanitize($settings_path,
false);
390 if ($this->cookies_configured) {
391 return $this->cookies;
395 if ($this->hasInitialValue(
'cookies')) {
396 $cookies = $this->getInitialValue(
'cookies');
400 if (!isset($cookies[
'session'])) {
401 $cookies[
'session'] = [];
404 $session_defaults = session_get_cookie_params();
405 $session_defaults[
'name'] =
'Elgg';
406 $cookies[
'session'] = array_merge($session_defaults, $cookies[
'session']);
409 if (!isset($cookies[
'remember_me'])) {
410 $cookies[
'remember_me'] = [];
413 $session_defaults[
'name'] =
'elggperm';
414 $session_defaults[
'expire'] = strtotime(
'+30 days');
415 $cookies[
'remember_me'] = array_merge($session_defaults, $cookies[
'remember_me']);
417 $this->cookies = $cookies;
418 $this->cookies_configured =
true;
434 if (array_key_exists(
$name, $this->deprecated)) {
438 if (!isset($this->values[
$name])) {
443 if (in_array(
$name, $this->path_properties)) {
468 return $this->initial_values[
$name] ??
null;
490 $testing = $this->values[
'testing_mode'] ?? false;
491 return !$testing && in_array(
$name, $this->locked_values) && $this->hasValue(
$name);
504 if ($this->wasWarnedLocked(
$name)) {
508 if (in_array(
$name, $this->path_properties)) {
532 if ($this->wasWarnedLocked(
$name)) {
536 unset($this->values[
$name]);
548 if ($this->wasWarnedLocked(
$name)) {
552 if (strlen(
$name) > 255) {
553 $this->getLogger()->error(
'The name length for configuration variables cannot be greater than 255');
559 return $this->
remove(
$name);
576 public function remove(
string $name):
bool {
577 if ($this->wasWarnedLocked(
$name)) {
583 unset($this->values[
$name]);
599 $this->getLogger()->warning(
"The property {$name} is read-only.");
if(! $user||! $user->canDelete()) $name
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
foreach( $paths as $path)
hasValue(string $name)
Test if we have a set value.
isLocked(string $name)
Is this value locked?
static fromFile($path)
Build a config from a file.
__construct(array $values=[])
Constructor.
getCookieConfig()
Set up and return the cookie configuration array resolved from settings.
save(string $name, $value)
Save a configuration setting to the database.
hasInitialValue(string $name)
Was a value available at construction time? (From settings.php)
getInitialValue(string $name)
Get a value set at construction time.
static factory(string $settings_path='')
Build a config from default settings locations.
saveInitialValues(array $values)
Stores the inital values.
static resolvePath(string $settings_path='')
Resolve settings path.
wasWarnedLocked(string $name)
Log a read-only warning if the name is read-only.
__set(string $name, $value)
Set an Elgg configuration value.
__isset(string $name)
Handle isset()
__unset(string $name)
Handle unset()
getValues()
Get all values.
__get(string $name)
Get an Elgg configuration value if it's been set or loaded during the boot process.
A generic parent class for Configuration exceptions.
Find Elgg and project paths.
$config
Advanced site settings, debugging section.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
_elgg_services()
Get the global service provider.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
$CONFIG wwwroot
The installation root URL of the site.
if(!isset($CONFIG)) $CONFIG dataroot
The full file path for Elgg data storage.