Passed
Pull Request — master (#204)
by
unknown
23:41
created

midcom_config::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
/**
10
 * Core configuration defaults.
11
 *
12
 * As always, you must not change this file. Instead, you have two levels of customization,
13
 * merged in the order listed here:
14
 *
15
 * <b>Site-specific configuration:</b>
16
 *
17
 * MidCOM will include the file <i>midcom::get()->config->get('midcom_config_basedir') . /midcom.conf</i> which must be a regular
18
 * PHP file. You may populate the global array $midcom_config_site in this file. It should
19
 * list all options that apply to all installations (like the Cache backend selection
20
 * or the indexer host).
21
 *
22
 * Example:
23
 *
24
 * <code>
25
 * $GLOBALS['midcom_config_site']['cache_module_content_backend'] =
26
 *     ['directory' => 'content/', 'driver' => 'sqlite'];
27
 * </code>
28
 *
29
 * <b>Instance-specific configuration:</b>
30
 *
31
 * After including the site itself, MidCOM also merges the contents of the global array
32
 * $midcom_config_local, which may hold configuration data for the website itself.
33
 *
34
 * These settings must be set for all sites:
35
 * - midcom_root_topic_guid
36
 *
37
 * You will usually include these lines somewhere before actually including MidCOM.
38
 *
39
 * <code>
40
 * $GLOBALS['midcom_config_local']['midcom_root_topic_guid'] = '123456789...';
41
 * </code>
42
 *
43
 * <b>Configuration setting overview:</b>
44
 *
45
 * The following configuration options are available for the MidCOM core along
46
 * with their defaults, shown in alphabetical order:
47
 *
48
 * <b>Authentication configuration</b>
49
 *
50
 * - <b>boolean allow_sudo:</b> Set this to true (the default) to allow components to
51
 *   request super user privileges for certain operations. This is mainly used to allow
52
 *   anonymous access to the system without having to store a user account everywhere.
53
 * - <b>string auth_backend:</b> The authentication backend to use, the "simple"
54
 *   backend is used as a default.
55
 * - <b>boolean auth_check_client_ip:</b> Control whether to check the client IP address
56
 *   on each subsequent request when authentication a user. This is enabled by default
57
 *   as it will make session hijacking much harder. You should not turn it off unless
58
 *   you have very good reasons to do.
59
 * - <b>int auth_login_session_timeout:</b> The login session timeout to use, this
60
 *   defaults to 3600 seconds (1 hour). Use 0 to have the session stay active until manual logout
61
 * - <b>string auth_frontend:</b> The authentication frontend to use, the "form" frontend
62
 *   is used by default.
63
 * - <b>int auth_login_form_httpcode</b>: HTTP return code used in MidCOM login screens,
64
 *   either 403 (403 Forbidden) or 200 (200 OK), defaulting to 403.
65
 *
66
 * <b>Authentication Backend configuration: "simple"</b>
67
 *
68
 * - <b>auth_backend_simple_cookie_secure:</b> Set the "secure" flag on cookie, defaults to true, applies only when actually using SSL/TLS
69
 * - <b>auth_backend_simple_cookie_id:</b> The ID appended to the cookie prefix, separating
70
 *   auth cookies for different sites. Defaults to 1.
71
 *
72
 * <b>Cache configuration</b>
73
 *
74
 * - <b>array cache_autoload_queue:</b> The cache module loading queue during startup, you
75
 *   should normally have no need to change this (unless you want to add your own caching modules,
76
 *   in which case you have to ensure that the loading queue of MidCOM itself (as seen in this
77
 *   file) is not changed.
78
 * - <b>string cache_base_directory:</b> The directory where to place cache files for MidCOM.
79
 *      This defaults to /tmp/ (note the trailing slash) as this is writable everywhere.
80
 *
81
 * - <b>Array cache_module_content_backend:</b> The configuration of the content cache backend.
82
 *   Check the documentation of midcom_services_cache_backend of what options are available here.
83
 *   In general, you should use this only to change the backend driver.
84
 *   In all other cases you should leave this option untouched. The defaults are to store all
85
 *   cache databases into the 'content/' subdirectory of the cache base directory.
86
 * - <b>string cache_module_content_name:</b> The identifier, the content cache should use for
87
 *   naming the files/directories it creates. This defaults to a string constructed out of the
88
 *   host's name, port and prefix. You should only change this if you run multiple MidCOM
89
 *   sites on the same host.
90
 * - <b>boolean cache_module_content_uncached:</b> Set this to true if you want the site to run in an uncached
91
 *      mode. This is different from cache_disable in that the regular header preprocessing is
92
 *   done anyway, allowing for browser side caching. Essentially, the computing order is the
93
 *   same (no_cache for example is considered like usual), but the cache file is not stored.
94
 *   This defaults to false.
95
 * - <b>string cache_module_content_headers_strategy:</b> Valid values are<br/>
96
 *   'no-cache' activates no-cache mode that actively tries to circumvent all caching<br/>
97
 *   'revalidate' is the default which sets 'must-revalidate'. Expires defaults to the current time, so this behaves like 'no-cache' unless expires() is called<br/>
98
 *   'public' and 'private' enable caching with the cache-control header of the same name, default expiry timestamps are generated using the cache_module_content_default_lifetime
99
 * - <b>int cache_module_content_default_lifetime:</b> How many seconds from now to set the default Expires header to, defaults to 15 minutes. Also used as default expiry time for content-cache entries that have no expiry set.
100
 * - <b>string cache_module_content_headers_strategy_authenticated:</b> Defaults to 'private', this is equivalent to cache_module_content_headers_strategy but applies when we have authenticated user.
101
 * - <b>int cache_module_content_default_lifetime_authenticated:</b> defaults to 0, equivalent to cache_module_content_default_lifetime but applies to authenticated users (except this does not set content-cache expiry). These two options are added to combat braindead proxies.
102
 * - <b>string cache_module_content_caching_strategy:</b> Valid values are<br/>
103
 *   'user' the "classic" mode, per user content-cache, default<br/>
104
 *   'memberships' cache per group memberships (users that have same memberships share same cache), for many cases this should offer more performance and smaller cache but if you use per-user privileges or other user specific processing this will cause hard-to-debug issues<br/>
105
 *   'public' everything goes to single public cache, disabling logins altogether will likely be safer.
106
 * - <b>Array cache_module_nap_backend:</b> The configuration of the nap/metadata cache backend.
107
 *   Check the documentation of midcom_services_cache_backend of what options are available here.
108
 *   In general, you should use this only to change the backend driver.
109
 *   In all other cases you should leave this option untouched. The defaults are to store all
110
 *   cache databases into the 'nap/' subdirectory of the cache base directory.
111
 *   The databases are named after the root topic guid, which should be sufficient
112
 *   in all cases. If you really want to separate things here, use different directories for
113
 *   the backends.
114
 * - <b>string cache_module_memcache_backend:</b> The cache backend to use for the memcache caching
115
 *   module. The default is null, which disables the module entirely. This is the default. If you
116
 *   have both memcached and the memcached PHP extension installed, set this to 'memcached', to enable
117
 *   the cache.
118
 * - <b>Array cache_module_memcache_backend_config:</b> The backend configuration to use if a backend
119
 *   was specified. See the individual backend documentations for more information about the allowed
120
 *   option set. This defaults to an empty array.
121
 * - <b>Array cache_module_memcache_data_groups:</b> The data groups available for the memcache module.
122
 *   You should normally not have to touch this, see the memcache module documentation for details.
123
 *   This defaults to ['ACL', 'PARENT'].
124
 *
125
 * See also midcom_services_cache, the midcom_services_cache_backend class hierarchy and
126
 * the midcom_services_cache_module class hierarchy.
127
 *
128
 * <b>Indexer configuration</b>
129
 *
130
 * - <b>string indexer_index_name:</b> The default Index to use when indexing the website. This defaults to
131
 *   a string constructed out of the host's name, port and prefix. You should only change this if you run
132
 *   the same MidCOM site across multiple hosts.
133
 * - <b>string indexer_backend:</b> The default indexer backend to use. This defaults to the false,
134
 *   indicating that <i>no</i> indexing should be done. Right now, the SOLR backend is recommended.
135
 * - <b>indexer_reindex_allowed_ips:</b> Array of IPs that don't need to basic authenticate themselves
136
 *   to run MidCOM reindexing or cron.
137
 *
138
 * <b>Indexer backend configuration: SOLR module</b>
139
 *
140
 * - <b>string indexer_xmltcp_host:</b> The host name or IP address where the indexer daemon is running.
141
 *   This defaults to "tcp://127.0.0.1", which is the default bind address of the daemon.
142
 * - <b>int indexer_xmltcp_port:</b> The port to which to connect. This defaults to 8983, which is the
143
 *      default port of the daemon.
144
 *
145
 * <b>Logging configuration</b>
146
 *
147
 * - <b>string log_filename:</b> The filename to dump logging messages to, this
148
 *      defaults to /tmp/debug.log.
149
 * - <b>int log_level:</b> The logging level to use when starting up the logger, set to
150
 *   MIDCOM_LOG_ERROR by default. You cannot use the MIDCOM* constants when setting
151
 *   micdom_config_local, as they are not defined at that point. Use 0 for CRITICAL,
152
 *   1 for ERROR, 2 for WARNING, 3 for INFO and 4 for DEBUG level logging.
153
 * - <b>array error_actions:</b> Actions to run when a specific error code is produced. This can
154
 *   be used for saving logs about 404 errors from broken links, or sending an error 500 to
155
 *   webmaster for analysis.
156
 *
157
 *   Configuration example:
158
 *
159
 * <code>
160
 * $GLOBALS['midcom_config_local']['error_actions'] = array
161
 * (
162
 *     500 => array
163
 *     (
164
 *         'action' => 'email',
165
 *         'email' => '[email protected]',
166
 *     ),
167
 *     404 => array
168
 *     (
169
 *         'action' => 'log',
170
 *         'filename' => '/var/log/broken_links.log',
171
 *     ),
172
 * );
173
 * </code>
174
 *
175
 * <b>MidCOM Core configuration</b>
176
 *
177
 * - <b>GUID midcom_root_topic_guid:</b> This is the GUID of the topic we should handle.
178
 *   This must be set on a per-site basis, otherwise MidCOM won't start up.
179
 * - <b>string midcom_sgconfig_basedir:</b> The base snippetdir where the current
180
 *   sites' configuration is stored. This defaults to "/sitegroup-config" which will
181
 *   result in the original default shared sitegroup-wide configuration.
182
 * - <b>string midcom_site_url:</b> The fully qualified URL to the Website. A trailing
183
 *   slash is required. It defaults to '/'.
184
 *   If an absolute local URL is given to this value, the full URL of the current host
185
 *   is prefixed to its value, so that this configuration key can be used for Location
186
 *   headers. You must not use a relative URL. This key will be completed by the MidCOM
187
 *   Application constructor, before that, it might contain a URL which is not suitable
188
 *   for relocations.
189
 * - <b>string midcom_tempdir:</b> A temporary directory that can be used when components
190
 *   need to write out files. Defaults to '/tmp'.
191
 * - <b>mixed midcom_max_memory:</b> The maximum memory limit to use doing resource-intensive tasks
192
 *   like when reindexing the entire site, which can require quite some amount of memory, as the complete NAP
193
 *   cache has to be loaded and binary indexing can take some memory, too. Defaults to -1.
194
 *  - <b>mixed midcom_max_execution_time:</b> The maximum execution time for resource-intensive tasks
195
 *  - <b>array midcom_components:</b> Additional out-of-tree components as name => path pairs
196
 *
197
 * <b>RCS system</b>
198
 *
199
 *  <b>string midcom_services_rcs_bin_dir</b>: the prefix for the rcs utilities (default: /usr/bin)
200
 *  <b>string midcom_services_rcs_root </b>: the directory where the rcs files get placed. (default: must be set!)
201
 *  <b>boolean midcom_services_rcs_enable</b>:  if set, midcom will fail hard if the rcs service is not operational. (default: false)
202
 *
203
 * <b>Style Engine</b>
204
 *
205
 * - <b>Array styleengine_default_styles:</b> Use this array to set site-wide default
206
 *   styles to be used for the components. This is an array indexing component name to
207
 *   style path. Components not present in this array use the default style delivered
208
 *   with the component. Any style set directly on a topic or inherited to it will
209
 *   override these settings. This defaults to an empty Array.
210
 *
211
 * <b>Toolbars System</b>
212
 *
213
 * The CSS classes and IDs used by the toolbars service can be configured using these
214
 * options:
215
 *
216
 * - <b>string toolbars_host_style_class:</b> defaults to "midcom_toolbar host_toolbar"
217
 * - <b>string toolbars_host_style_id:</b> defaults to ""
218
 * - <b>string toolbars_node_style_class:</b> defaults to "midcom_toolbar node_toolbar"
219
 * - <b>string toolbars_node_style_id:</b> defaults to ""
220
 * - <b>string toolbars_view_style_class:</b> defaults to midcom_toolbar view_toolbar
221
 * - <b>string toolbars_view_style_id:</b> defaults to ""
222
 * - <b>string toolbars_object_style_class:</b> defaults to midcom_toolbar object_toolbar
223
 * - <b>string toolbars_simple_css_path:</b> this defaults to MIDCOM_STATIC_URL/midcom.services.toolbars/simple.css
224
 *   and is used to set the css for the toolbars used with onsite editing.
225
 * - <b>boolean toolbars_enable_centralized:</b> defaults to true, whether to enable the centralized,
226
 *   javascript-floating MidCOM toolbar that users can display with midcom::get()->toolbars->show();
227
 *
228
 * <b>Utility Programs</b>
229
 *
230
 * The various paths set here lead to the utility programs required by MidCOM, both
231
 * mandatory and optional applications are listed here. To indicate that a certain
232
 * application is unavailable, set it to null. The defaults assume that the files are within the
233
 * $PATH of the Apache user and should be sufficient in most cases. Package maintainers
234
 * are encouraged to make the paths explicit.
235
 *
236
 * - <b>string utility_imagemagick_base:</b> The base path of the ImageMagick executables,
237
 *   the tools <i>mogrify</i>, <i>identify</i> and <i>convert</i> are needed for almost
238
 *   all kinds of image operations in MidCOM and have to be present therefore. The path
239
 *   entered here requires a trailing slash.
240
 * - <b>string utility_jpegtran:</b> JPEGTran is used to do lossless rotation of JPEG
241
 *   images for automatic EXIF rotation in n.s.photos for example. If unavailable,
242
 *   there is an automatic fallback to imagemagick.
243
 * - <b>string utility_catdoc:</b> Transforms Word Documents into text for indexing.
244
 * - <b>string utility_pdftotext:</b> Transforms PDF Documents into text for indexing.
245
 * - <b>string utility_unrtf:</b> Transforms RTF Documents into text files for indexing.
246
 *
247
 * <b>Visibility settings (NAP and DBA)</b>
248
 *
249
 * - <b>boolean show_hidden_objects:</b> This flag indicates whether objects that are
250
 *   invisible either by explicit hiding or by their scheduling should be shown anyway.
251
 *   This defaults to true at this time
252
 * - <b>boolean show_unapproved_objects:</b> This flag indicates whether objects should be
253
 *   shown even if they are not approved. This defaults to true.
254
 *
255
 * @package midcom
256
 */
257
class midcom_config implements ArrayAccess
258
{
259
    private $_default_config = [
260
        // Authentication configuration
261
        'auth_type' => 'Legacy',
262
        'auth_backend' => 'simple',
263
        'auth_backend_simple_cookie_id' => 1,
264
        'auth_login_session_timeout' => 3600,
265
        'auth_login_session_update_interval' => 300,
266
        'auth_frontend' => 'form',
267
        'auth_check_client_ip' => true,
268
        'auth_allow_sudo' => true,
269
        'auth_login_form_httpcode' => 403,
270
        'auth_save_prev_login' => false,
271
        'auth_allow_trusted' => false,
272
        'person_class' => 'openpsa_person',
273
274
        // set secure flag on cookie (applies only when using SSL)
275
        'auth_backend_simple_cookie_secure' => true,
276
277
        // Cache configuration
278
        'cache_base_directory' => '/tmp/',
279
        'cache_autoload_queue' => ['content', 'nap', 'memcache'],
280
281
        // Content Cache
282
        'cache_module_content_name' => 'auto',
283
284
        //Memory Caching Daemon
285
        'cache_module_memcache_backend' => 'flatfile',
286
        'cache_module_memcache_backend_config' => [],
287
        'cache_module_memcache_data_groups' => ['ACL', 'PARENT', 'L10N', 'MISC'],
288
289
        // Defaults:
290
        'cache_module_content_backend' => ['driver' => 'flatfile'],
291
        'cache_module_content_uncached' => true,
292
        'cache_module_content_headers_strategy' => 'revalidate',
293
        'cache_module_content_headers_strategy_authenticated' => 'private',
294
        // Seconds, added to gmdate() for expiry timestamp (in case no other expiry is set),
295
        // also used as default expiry for content-cache entries that have no expiry set
296
        'cache_module_content_default_lifetime' => 900,
297
        // as above but concerns only authenticated state
298
        'cache_module_content_default_lifetime_authenticated' => 0,
299
        // Valid options are 'user' (default), 'memberships' and 'public'
300
        'cache_module_content_caching_strategy' => 'user',
301
302
        // NAP Cache
303
        'cache_module_nap_backend' => [] /* Auto-Detect */,
304
305
        // CRON Service configuration
306
        'cron_day_hours' => 0,
307
        'cron_day_minutes' => 0,
308
        'cron_hour_minutes' => 30,
309
310
        // I18n Subsystem configuration
311
        'i18n_available_languages' => null,
312
        'i18n_fallback_language' => 'en',
313
314
        // Indexer Configuration
315
        'indexer_backend' => false,
316
        'indexer_index_name' => 'auto',
317
        'indexer_reindex_allowed_ips' => ['127.0.0.1'],
318
319
        'indexer_config_options' => ['fl' => '*,score', 'rows' => 1000, 'defType' => 'dismax', 'qf' => 'content'],
320
321
        // XMLTCP indexer backend
322
        'indexer_xmltcp_host' => "127.0.0.1",
323
        'indexer_xmltcp_port' => 8983,
324
        'indexer_xmltcp_core' => null,
325
326
        // Logging Configuration
327
        'log_filename' => '/tmp/midcom.log',
328
        'log_level' => MIDCOM_LOG_ERROR,
329
        'error_actions' => [],
330
331
        // Core configuration
332
        'midcom_root_topic_guid' => '',
333
        'midcom_config_basedir' => '/etc/midgard/',
334
        'midcom_sgconfig_basedir' => '/sitegroup-config',
335
        'midcom_site_url' => '/',
336
        'midcom_site_title' => '',
337
        'midcom_tempdir' => '/tmp',
338
        'midcom_max_memory' => -1,
339
        'midcom_max_execution_time' => 0,
340
        'midcom_components' => [],
341
        'builtin_components' =>  [
342
            'lib/net/nehmer/comments',
343
            'lib/net/nehmer/blog',
344
            'lib/net/nehmer/static',
345
            'lib/net/nemein/rss',
346
            'lib/net/nemein/wiki',
347
            'lib/net/nemein/redirector',
348
            'lib/net/nemein/tag',
349
            'lib/org/openpsa/directmarketing',
350
            'lib/org/openpsa/calendar',
351
            'lib/org/openpsa/products',
352
            'lib/org/openpsa/core',
353
            'lib/org/openpsa/sales',
354
            'lib/org/openpsa/invoices',
355
            'lib/org/openpsa/mail',
356
            'lib/org/openpsa/expenses',
357
            'lib/org/openpsa/projects',
358
            'lib/org/openpsa/contacts',
359
            'lib/org/openpsa/user',
360
            'lib/org/openpsa/httplib',
361
            'lib/org/openpsa/mypage',
362
            'lib/org/openpsa/relatedto',
363
            'lib/org/openpsa/qbpager',
364
            'lib/org/openpsa/documents',
365
            'lib/org/openpsa/slideshow',
366
            'lib/org/openpsa/helpers',
367
            'lib/org/openpsa/notifications',
368
            'lib/org/openpsa/widgets',
369
            'lib/org/openpsa/reports',
370
            'lib/midcom/core/nullcomponent',
371
            'lib/midcom',
372
            'lib/midcom/admin/folder',
373
            'lib/midcom/admin/rcs',
374
            'lib/midcom/admin/help',
375
            'lib/midcom/helper/imagepopup',
376
            'lib/midcom/helper/reflector',
377
            'lib/midcom/helper/search',
378
            'lib/midcom/services/at',
379
            'lib/midgard/admin/user',
380
            'lib/midgard/admin/asgard',
381
            'lib/fi/protie/navigation',
382
            'src/midcom/datamanager',
383
            'src/midcom/grid',
384
        ],
385
386
        // Visibility settings (NAP)
387
        'show_hidden_objects' => true,
388
        'show_unapproved_objects' => true,
389
        // Style Engine defaults
390
        'styleengine_default_styles' => [],
391
392
        // Toolbars service
393
        'toolbars_host_style_class' => 'midcom_toolbar host_toolbar',
394
        'toolbars_host_style_id' => null,
395
        'toolbars_node_style_class' => 'midcom_toolbar node_toolbar',
396
        'toolbars_node_style_id' => null,
397
        'toolbars_view_style_class' => 'midcom_toolbar view_toolbar',
398
        'toolbars_view_style_id' => null,
399
        'toolbars_help_style_class' => 'midcom_toolbar help_toolbar',
400
        'toolbars_help_style_id' => null,
401
        'toolbars_simple_css_path' => null,
402
        'toolbars_enable_centralized' => true,
403
404
        // Public attachment caching directives
405
        'attachment_cache_enabled' => false,
406
        'attachment_cache_root' => '/var/lib/midgard/vhosts/example.net/80/midcom-static/blobs',
407
        'attachment_cache_url' => '/midcom-static/blobs',
408
409
        //X-sendfile support
410
        'attachment_xsendfile_enable' => false,
411
412
        // Utilities
413
        'utility_imagemagick_base' => '',
414
        'utility_jpegtran' => 'jpegtran',
415
        'utility_catdoc' => 'catdoc',
416
        'utility_pdftotext' => 'pdftotext',
417
        'utility_unrtf' => 'unrtf',
418
419
        'midcom_services_rcs_bin_dir' => '/usr/bin',
420
        'midcom_services_rcs_root' => '',
421
        'midcom_services_rcs_enable' => true,
422
423
        // Metadata system
424
425
        // Enables approval/scheduling controls (does not influence visibility checks using
426
        // show_unapproved_objects). Disabled by default. Unsafe to Link Prefetching!
427
        'metadata_approval' => false,
428
        'metadata_scheduling' => false,
429
        'metadata_lock_timeout' => 60,    // Time in minutes
430
        'staging2live_staging' => false,
431
432
        // Set the datamanager schema used by the Metadata Service
433
        'metadata_schema' => 'file:/midcom/config/metadata_default.inc',
434
435
        // Map MidCOM metadata properties to HTML meta tags
436
        'metadata_head_elements' => [
437
            'published'   => 'DC.date',
438
            'description'   => 'description',
439
        ],
440
441
        // Whether to gather and display Open Graph Protocol metadata for Midgard pages
442
        'metadata_opengraph' => false,
443
444
        // Component system
445
        // Show only these components when creating or editing
446
        'component_listing_allowed' => null,
447
        'component_listing_excluded' => null,
448
449
        // Page class (body class)
450
        // If this argument is set to true, sanitized name of the component is added to the page class string.
451
        'page_class_include_component' => true,
452
453
        // If this argument is set to true, All midcom_show_style calls wrap the style with HTML comments defining the style path
454
        'wrap_style_show_with_name' => false,
455
456
        // Related to JavaScript libraries
457
        'jquery_version' => '3.4.1.min',
458
        'jquery_ui_version' => '1.12.1',
459
        'jquery_ui_theme' => null,
460
        'jquery_load_from_google' => false,
461
462
        /**
463
         * Sessioning service, disabling the service will help with external caches.
464
         * The second option is to allow logged in users to benefit from the service
465
         */
466
        'sessioning_service_enable' => true,
467
        'sessioning_service_always_enable_for_users' => true,
468
469
        /**
470
         * Trash cleanup, purge deleted objects after X days
471
         */
472
        'cron_purge_deleted_after' => 25,
473
474
        /**
475
         * Theme support
476
         */
477
        'theme' => '',
478
    ];
479
480
    private $_merged_config = [];
481
482 5
    public function __construct()
483
    {
484 5
        $this->_complete_defaults();
485
486
        /* ----- MERGE THE CONFIGURATION ----- */
487 5
        if (!array_key_exists('midcom_config_site', $GLOBALS)) {
488
            $GLOBALS['midcom_config_site'] = [];
489
        }
490 5
        if (!array_key_exists('midcom_config_local', $GLOBALS)) {
491
            $GLOBALS['midcom_config_local'] = [];
492
        }
493 5
        $this->_merged_config = array_merge(
494 5
            $this->_default_config,
495 5
            $GLOBALS['midcom_config_site'],
496 5
            $GLOBALS['midcom_config_local']
497
        );
498 5
    }
499
500 5
    private function _complete_defaults()
501
    {
502 5
        if (class_exists('Memcached')) {
503 5
            $this->_default_config['cache_module_content_backend'] = ['driver' => 'memcached'];
504 5
            $this->_default_config['cache_module_memcache_backend'] = 'memcached';
505
        }
506 5
        if (isset($_SERVER['SERVER_ADDR'])) {
507
            $this->_default_config['indexer_reindex_allowed_ips'][] = $_SERVER['SERVER_ADDR'];
508
        }
509 5
        if (!empty($_SERVER['SERVER_NAME'])) {
510 5
            $this->_default_config['midcom_site_title'] = $_SERVER['SERVER_NAME'];
511
        }
512 5
    }
513
514 732
    public function get(string $key, $default = null)
515
    {
516 732
        if (!$this->offsetExists($key)) {
517 339
            return $default;
518
        }
519
520 732
        if (   $key === 'auth_type'
521 732
            && !in_array($this->_merged_config[$key], ['Plaintext', 'Legacy', 'SHA256'])) {
522
            throw new midcom_error('Unsupported authentication type');
523
        }
524
        // Check the midcom_config site prefix for absolute local urls
525 732
        if (   $key === 'midcom_site_url'
526 732
            && substr($this->_merged_config[$key], 0, 1) === '/') {
527
            $this->_merged_config[$key] = midcom::get()->get_page_prefix() . substr($this->_merged_config[$key], 1);
528
        }
529
530 732
        return $this->_merged_config[$key];
531
    }
532
533 8
    public function set(string $key, $value)
534
    {
535 8
        $this->_merged_config[$key] = $value;
536 8
    }
537
538 5
    public function offsetSet($offset, $value)
539
    {
540 5
        $this->set($offset, $value);
541 5
    }
542
543 732
    public function offsetExists($offset)
544
    {
545 732
        return isset($this->_merged_config[$offset]);
546
    }
547
548
    public function offsetUnset($offset)
549
    {
550
        unset($this->_merged_config[$offset]);
551
    }
552
553 82
    public function offsetGet($offset)
554
    {
555 82
        return $this->get($offset);
556
    }
557
}
558