7 use Elgg\Traits\Loggable;
145 private array $values = [];
147 private array $initial_values = [];
149 private bool $cookies_configured =
false;
151 private array $cookies = [];
156 protected array $locked_values = [
168 protected array $deprecated = [];
173 protected array $config_defaults = [
174 'admin_validation_notification' =>
false,
175 'allow_phpinfo' =>
false,
176 'authentication_failures_lifetime' => 600,
177 'authentication_failures_limit' => 5,
178 'auto_disable_plugins' =>
true,
179 'batch_run_time_in_secs' => 4,
180 'boot_cache_ttl' => 3600,
181 'can_change_username' =>
false,
182 'class_loader_verify_file_existence' =>
true,
183 'comment_box_collapses' =>
true,
184 'comments_group_only' =>
true,
185 'comments_latest_first' =>
true,
186 'comments_max_depth' => 0,
187 'comments_per_page' => 25,
188 'db_enable_query_logging' =>
false,
189 'db_query_cache_limit' => 50,
190 'default_limit' => 10,
191 'elgg_maintenance_mode' =>
false,
192 'email_html_part' =>
true,
193 'email_html_part_images' =>
'no',
194 'email_subject_limit' => 998,
195 'enable_delayed_email' =>
true,
196 'friendly_time_number_of_days' => 30,
198 'topbar' => [
'w' => 16,
'h' => 16,
'square' =>
true,
'upscale' =>
true],
199 'tiny' => [
'w' => 25,
'h' => 25,
'square' =>
true,
'upscale' =>
true],
200 'small' => [
'w' => 40,
'h' => 40,
'square' =>
true,
'upscale' =>
true],
201 'medium' => [
'w' => 100,
'h' => 100,
'square' =>
true,
'upscale' =>
true],
202 'large' => [
'w' => 200,
'h' => 200,
'square' =>
true,
'upscale' =>
true],
203 'master' => [
'w' => 10240,
'h' => 10240,
'square' =>
false,
'upscale' =>
false,
'crop' =>
false],
206 'language_detect_from_browser' =>
true,
208 'mentions_display_format' =>
'display_name',
209 'message_delay' => 6,
210 'min_password_length' => 6,
212 'notifications_max_runtime' => 45,
213 'notifications_queue_delay' => 0,
214 'pagination_behaviour' =>
'ajax-replace',
215 'require_admin_validation' =>
false,
216 'security_email_require_confirmation' =>
true,
217 'security_email_require_password' =>
true,
218 'security_notify_admins' =>
true,
219 'security_notify_user_password' =>
true,
220 'security_protect_upgrade' =>
true,
221 'session_bound_entity_icons' =>
false,
222 'simplecache_enabled' =>
false,
223 'subresource_integrity_enabled' =>
false,
224 'system_cache_enabled' =>
false,
225 'testing_mode' =>
false,
226 'trash_enabled' =>
true,
227 'trash_retention' => 30,
228 'user_joined_river' =>
false,
229 'webp_enabled' =>
true,
230 'who_can_change_language' =>
'everyone',
236 protected array $path_properties = [
248 const ENTITY_TYPES = [
'group',
'object',
'site',
'user'];
255 const SENSITIVE_PROPERTIES = [
271 $this->saveInitialValues($values);
273 $this->values = array_merge($this->config_defaults, $values);
276 $this->getCookieConfig();
289 unset($values[
$name]);
292 $this->initial_values = $values;
302 public static function factory(
string $settings_path =
''): static {
303 $settings_path = self::resolvePath($settings_path);
305 return self::fromFile($settings_path);
321 if (!is_readable(
$path)) {
327 if (isset($GLOBALS[
'CONFIG'])) {
329 $global = $GLOBALS[
'CONFIG'];
330 unset($GLOBALS[
'CONFIG']);
335 Includer::requireFile(
$path);
337 if (empty($GLOBALS[
'CONFIG']->
dataroot)) {
338 throw new ConfigurationException(__METHOD__ .
': Reading configs failed: The Elgg settings file is missing $CONFIG->dataroot.');
341 if (empty($GLOBALS[
'CONFIG']->
wwwroot)) {
342 throw new ConfigurationException(__METHOD__ .
': Reading configs failed: The Elgg settings file is missing $CONFIG->wwwroot.');
345 $config =
new self(get_object_vars($GLOBALS[
'CONFIG']));
347 if ($global !==
null) {
349 $GLOBALS[
'CONFIG'] = $global;
351 unset($GLOBALS[
'CONFIG']);
354 if (
$config->{
'X-Sendfile-Type'}) {
356 unset(
$config->{
'X-Sendfile-Type'});
359 if (
$config->{
'X-Accel-Mapping'}) {
361 unset(
$config->{
'X-Accel-Mapping'});
374 public static function resolvePath(
string $settings_path =
''): string {
375 if (empty($settings_path)) {
376 $settings_path = Paths::settingsFile(Paths::SETTINGS_PHP);
379 return Paths::sanitize($settings_path,
false);
397 if ($this->cookies_configured) {
398 return $this->cookies;
402 if ($this->hasInitialValue(
'cookies')) {
403 $cookies = $this->getInitialValue(
'cookies');
407 if (!isset($cookies[
'session'])) {
408 $cookies[
'session'] = [];
411 $session_defaults = session_get_cookie_params();
412 $session_defaults[
'name'] =
'Elgg';
413 $cookies[
'session'] = array_merge($session_defaults, $cookies[
'session']);
416 if (!isset($cookies[
'remember_me'])) {
417 $cookies[
'remember_me'] = [];
420 $session_defaults[
'name'] =
'elggperm';
421 $session_defaults[
'expire'] = strtotime(
'+30 days');
422 $cookies[
'remember_me'] = array_merge($session_defaults, $cookies[
'remember_me']);
424 $this->cookies = $cookies;
425 $this->cookies_configured =
true;
441 if (array_key_exists(
$name, $this->deprecated)) {
445 if (!isset($this->values[
$name])) {
450 if (in_array(
$name, $this->path_properties)) {
475 return $this->initial_values[
$name] ??
null;
497 $testing = $this->values[
'testing_mode'] ?? false;
498 return !$testing && in_array(
$name, $this->locked_values) && $this->hasValue(
$name);
511 if ($this->wasWarnedLocked(
$name)) {
515 if (in_array(
$name, $this->path_properties)) {
539 if ($this->wasWarnedLocked(
$name)) {
543 unset($this->values[
$name]);
555 if ($this->wasWarnedLocked(
$name)) {
559 if (strlen(
$name) > 255) {
560 $this->getLogger()->error(
'The name length for configuration variables cannot be greater than 255');
566 return $this->
remove(
$name);
583 public function remove(
string $name):
bool {
584 if ($this->wasWarnedLocked(
$name)) {
590 unset($this->values[
$name]);
606 $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.