Completed
Push — next ( 5f2bc0...cef70f )
by Thomas
25s queued 12s
created

settings-dist-common.inc.php ➔ set_absolute_urls()   F

Complexity

Conditions 22
Paths > 20000

Size

Total Lines 114

Duplication

Lines 17
Ratio 14.91 %

Importance

Changes 0
Metric Value
cc 22
nc 458752
nop 4
dl 17
loc 114
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/***************************************************************************
3
 * for license information see LICENSE.md
4
 *
5
 *
6
 *  Settings shared by all configurations of lib1 and lib2.
7
 *  See also locale.inc.php, which is included in both lib1 and lib2.
8
 ***************************************************************************/
9
10
/* Database charset
11
 *   Frontend and PHP charsets are UTF-8.
12
 *   MySQL database default charset is 'utf8' (16 bit restricted Unicode).
13
 *   For MySQL or MariaDB >= 5.5, this can be changed to 'utf8mb4' (21 bit full Unicode).
14
 *   bin/dbsv-update.php will then migrate the tables' charset.
15
 */
16
$opt['charset']['iconv'] = 'UTF-8'; // 'ISO-8859-1'; // use iconv compatible charset-name
17
$opt['charset']['mysql'] = 'utf8'; // use mysql compatible charset-name
18
19
// handling of SQL and PHP errors
20
$opt['db']['error']['display'] = false;
21
$opt['db']['error']['mail'] = 'root'; // set '' to disable
22
23
// page title
24
$opt['page']['title'] = 'OPENCACHING';
25
$opt['page']['subtitle1'] = 'Geocaching with Opencaching';
26
$opt['page']['subtitle2'] = '';
27
$opt['page']['sitename'] = 'Opencaching.de';
28
$opt['page']['slogan'] = 'Opencaching.de - Geocaching in Deutschland, Österreich und der Schweiz';
29
30
// directory of rotator pictures and script, relative to head images dir
31
$opt['page']['headimagepath'] = '';
32
33
// sponsor link on e.g. print preview
34
$opt['page']['sponsor']['popup'] = '';
35
$opt['page']['sponsor']['bottom'] = 'Driven by the Opencaching community';
36
37
$opt['page']['showdonations'] = false; // Show donations button
38
$opt['page']['showsocialmedia'] = false;
39
40
/* maximum number of failed logins per hour before that IP address is blocked
41
 * (used to prevent brute-force-attacks)
42
 */
43
$opt['page']['max_logins_per_hour'] = 25;
44
45
// block troublemakers
46
$opt['page']['banned_user_agents'] = [];
47
48
/*
49
 * Main locale and style: The country and language with most content on this site.
50
 */
51
$opt['page']['main_country'] = 'DE';
52
$opt['page']['main_locale'] = 'DE';
53
54
/* Domain-dependend default settings;
55
 * can all be overwritten by corresponding $opt['domain'][<domain>['...'] settings.
56
 * Additionally, the cookie domain (different vor lib1 and lib2) can be overwritten.
57
 * See examples for overriding in settings-sample.inc.php.
58
 */
59
$opt['page']['meta']['keywords'] = 'Geocache, Cache, Schatzsuche, GPS, kostenlos, GPX, Koordinaten, Hobby, Natur'; // 5-10 keywords are recommended
60
// see http://forum.opencaching.de/index.php?topic=3065.0
61
// and http://forum.opencaching.de/index.php?topic=3065.0 regarding description
62
$opt['page']['meta']['description'] = 'Opencaching.de ist das freie Portal für Geocaching, ein Schatzsuche-Spiel. Mittels GPS-Koordinaten sind Behälter oder Objekte zu finden.';
63
$opt['page']['headoverlay'] = 'oc_head_alpha3_generic';
64
$opt['template']['default']['locale'] = 'DE';
65
$opt['template']['default']['article_locale'] = 'EN';
66
$opt['template']['default']['fallback_locale'] = 'EN';
67
$opt['template']['default']['style'] = 'ocstyle';
68
$opt['template']['default']['country'] = 'DE';
69
70
// smiley path
71
$opt['template']['smiley'] = 'resource2/tinymce/plugins/emotions/img/';
72
73
/* pregenerated waypoint list for new caches
74
 * - Waypoint prefix (OC, OP, OZ ... AA=local development)
75
 * - When pool contains less than min_count, generation process starts
76
 *   and fills up the pool until max_count is reached.
77
 */
78
$opt['logic']['waypoint_pool']['prefix'] = 'AA';
79
$opt['logic']['waypoint_pool']['min_count'] = 1000;
80
$opt['logic']['waypoint_pool']['max_count'] = 2000;
81
// chars used for waypoints. Remember to reinstall triggers and clear cache_waypoint_pool after changing
82
$opt['logic']['waypoint_pool']['valid_chars'] = '0123456789ABCDEF';
83
// fill_gaps = true: search for gaps between used waypoints and fill up these gaps
84
//                   (fill_gaps is slow and CPU intensive on database server. For
85
//                    productive servers you may want to generate some waypoints
86
//                    without fill_gaps first)
87
// fill_gaps = false: continue with the last waypoint
88
$opt['logic']['waypoint_pool']['fill_gaps'] = false;
89
90
/* number of finds needed to give one recommendation
91
 */
92
$opt['logic']['rating']['findsPerRating'] = 10;
93
94
/* admin functions
95
 */
96
// admin may use OC-team-comment log flag only when processing a cache report
97
// see also setting in lib/settings.inc.php!
98
$opt['logic']['admin']['team_comments_only_for_reports'] = true;
99
$opt['logic']['admin']['enable_listing_admins'] = false;
100
$opt['logic']['admin']['listingadmin_notification'] = ''; // Email address(es), comma separated
101
102
/*
103
 * html purifier
104
 */
105
$opt['html_purifier']['cache_path'] = __DIR__ . '/../var/cache2/html_purifier/';
106
107
/*
108
 * CMS links for external pages
109
 */
110
111
// explanation of common login errors
112
$opt['cms']['login'] = 'http://wiki.opencaching.de/index.php/Login_auf_Opencaching.de';
113
114
// explanation of nature protection areas
115
$opt['cms']['npa'] = 'articles.php?page=npa&wiki';
116
117
/* HTTPS settings
118
 *
119
 * mode:  HTTPS_DISABLED:  https requests will be redirected to http
120
 *        HTTPS_ENABLED:   all requests will stay within the same protocol
121
 *        HTTPS_ENFORCED:  http requests will be redirected to https
122
 *
123
 * is_default:   true:     links in exported data will point to https:
124
 *               false:    links in exported data will point to http:
125
 *
126
 * force_login:  true:     login forms submit to https:
127
 *               false     login forms submit to the current protocol
128
 */
129
if (!isset($opt['page']['https']['mode'])) {
130
    $opt['page']['https']['mode'] = HTTPS_DISABLED;
131
}
132
if (!isset($opt['page']['https']['is_default'])) {
133
    $opt['page']['https']['is_default'] = false;
134
}
135
if (!isset($opt['page']['https']['force_login'])) {
136
    $opt['page']['https']['force_login'] = false;
137
}
138
139
140
/* The following additional variables are generated:
141
 *
142
 * $opt['page']['absolute_url']           the base URL of the current request, http or https + current domain
143
 *   $absolute_server_URI                   ... the same, only in lib1
144
 * $opt['page']['absolute_http_url']      the http:// base URL of the current domain
145
 * $opt['page']['absolute_https_url']     the https:// base URL of the currenbt domain
146
 * $opt['page']['default_absolute_url']   the default-protocol base URL of the current domain (used in exported data)
147
 * $opt['page']['default_primary_url']    the default-protocol base URL of the primary domain of this site
148
 * $opt['page']['shortlink_url']          shortlink URL of the current protocol or false
149
 * $opt['page']['default_shortlink_url']  default-protocol shortlink URL or false
150
 * $opt['page']['default_primary_shortlink_url']  default-protocol shortlink URL of primary domain of this site, or false
151
 * $opt['page']['https']['active']        true if the current request is https, else false
152
 * $opt['page']['protocol']               the protocol of the current request, 'http' or 'https'
153
 *
154
 * These settings allow to run a consistently multi-protocol and multi-domain OC site.
155
 * All generated URls end on '/'.
156
 */
157
158
function set_absolute_urls(&$opt, $primary_site_url, $primary_shortlink_domain, $lib): void
159
{
160
    // $opt is passed as parameter because it is *local* in okapi_settings.php.
161
162
    global $absolute_server_URI, $rootpath;
163
164
    // 1. create settings for the primary domain, which was passed in $site_url
165
166
    $primary_domain = parse_url($primary_site_url, PHP_URL_HOST);
167
    if (isset($opt['domain'][$primary_domain]['url'])) {
168
        $primary_site_url = $opt['domain'][$primary_domain]['url'];
169
    }
170
    if (substr($primary_site_url, - 1, 1) != '/') {
171
        $primary_site_url .= '/';
172
    }
173
174
    if (isset($opt['domain'][$primary_domain]['https']['is_default'])) {
175
        $primary_httpsdefault = $opt['domain'][$primary_domain]['https']['is_default'];
176
    } else {
177
        $primary_httpsdefault = $opt['page']['https']['is_default'];
178
    }
179
    if ($primary_httpsdefault) {
180
        $opt['page']['default_primary_url'] = 'https' . strstr($primary_site_url, '://');
181
    } else {
182
        $opt['page']['default_primary_url'] = 'http' . strstr($primary_site_url, '://');
183
    }
184
185
    // 2. create settings for the current domain
186
187
    $current_domain = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $primary_domain;
188
    $opt['page']['domain'] = $current_domain;
189
190
    if (isset($opt['domain'][$current_domain]['url'])) {
191
        $current_site_url = $opt['domain'][$current_domain]['url'];
192
    } else {
193
        $current_site_url = 'x://' . $current_domain . parse_url($primary_site_url, PHP_URL_PATH);
194
    }
195
    if (substr($current_site_url, - 1, 1) != '/') {
196
        $current_site_url .= '/';
197
    }
198
199
    if (isset($opt['domain'][$current_domain]['https'])) {
200
        // This overwrites *all* https settings.
201
        $opt['page']['https'] = $opt['domain'][$current_domain]['https'];
202
    }
203
204
    $adr = strstr($current_site_url, '://');
205
    $opt['page']['absolute_http_url'] = 'http' . $adr;
206
    $opt['page']['absolute_https_url'] = 'https' . $adr;
207
    $opt['page']['https']['active'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off');
208
209 View Code Duplication
    if ($opt['page']['https']['active']) {
210
        $opt['page']['absolute_url'] = $opt['page']['absolute_https_url'];
211
        $opt['page']['protocol'] = 'https';
212
    } else {
213
        $opt['page']['absolute_url'] = $opt['page']['absolute_http_url'];
214
        $opt['page']['protocol'] = 'http';
215
    }
216
217
    if ($lib == 1) {
218
        $absolute_server_URI = $opt['page']['absolute_url'];
219
    }
220
221 View Code Duplication
    if ($opt['page']['https']['is_default']) {
222
        $opt['page']['default_absolute_url'] = $opt['page']['absolute_https_url'];
223
        $opt['page']['default_protocol'] = 'https';
224
    } else {
225
        $opt['page']['default_absolute_url'] = $opt['page']['absolute_http_url'];
226
        $opt['page']['default_protocol'] = 'http';
227
    }
228
229
    // 3. create shortlink URLs
230
231
    if (!$primary_shortlink_domain) {
232
        $opt['page']['shortlink_url'] = false;
233
        $opt['page']['default_shortlink_url'] = false;
234
        $opt['page']['default_primary_shortlink_url'] = false;
235
    } else {
236
        if ($primary_httpsdefault) {
237
            $opt['page']['default_primary_shortlink_url'] = 'https://' . $primary_shortlink_domain . '/';
238
        } else {
239
            $opt['page']['default_primary_shortlink_url'] = 'http://' . $primary_shortlink_domain . '/';
240
        }
241
242
        if (isset($opt['domain'][$current_domain]['shortlink_domain']) && $opt['domain'][$current_domain]['shortlink_domain']) {
243
            $opt['page']['shortlink_url'] = $opt['page']['protocol'] . '://' . $opt['domain'][$current_domain]['shortlink_domain'] . '/';
244
            $opt['page']['default_shortlink_url'] = $opt['page']['default_protocol'] . '://' . $opt['domain'][$current_domain]['shortlink_domain'] . '/';
245
        } else {
246
            if ($current_domain == $primary_domain) {
247
                $opt['page']['default_shortlink_url'] = $opt['page']['default_primary_shortlink_url'];
248
                $opt['page']['shortlink_url'] =
249
                    $opt['page']['protocol'] . strstr($opt['page']['default_shortlink_url'], '://');
250
            } else {
251
                $opt['page']['shortlink_url'] = false;
252
                $opt['page']['default_shortlink_url'] = false;
253
            }
254
        }
255
    }
256
257
    // 4. set location of uploaded images
258
259
    if (!isset($opt['logic']['pictures']['dir'])) {
260
        $opt['logic']['pictures']['dir'] = __DIR__ . '/../images/uploads';
261
    }  // Ocprop, OKAPI !
262 View Code Duplication
    if (!isset($opt['logic']['pictures']['url'])) {
263
        $opt['logic']['pictures']['url'] = $opt['page']['default_primary_url'] . 'images/uploads';
264
    }
265
    if (!isset($opt['logic']['pictures']['thumb_dir'])) {
266
        $opt['logic']['pictures']['thumb_dir'] = $opt['logic']['pictures']['dir'] . '/thumbs';
267
    }
268
    if (!isset($opt['logic']['pictures']['thumb_url'])) {
269
        $opt['logic']['pictures']['thumb_url'] = $opt['logic']['pictures']['url'] . '/thumbs';
270
    }
271
}
272
273
274
function set_common_domain_config(&$opt): void
275
{
276
    // $opt is passed as parameter because it is *local* in okapi_settings.php.
277
278
    $domain = $opt['page']['domain'];
279
280
    if (isset($opt['domain'][$domain])) {
281 View Code Duplication
        if (isset($opt['domain'][$domain]['locale'])) {
282
            $opt['template']['default']['locale'] = $opt['domain'][$domain]['locale'];
283
        }
284 View Code Duplication
        if (isset($opt['domain'][$domain]['fallback_locale'])) {
285
            $opt['template']['default']['fallback_locale'] = $opt['domain'][$domain]['fallback_locale'];
286
        }
287
288 View Code Duplication
        if (isset($opt['domain'][$domain]['country'])) {
289
            $opt['template']['default']['country'] = $opt['domain'][$domain]['country'];
290
        }
291
292
        if (isset($opt['domain'][$domain]['sitename'])) {
293
            $opt['page']['sitename'] = $opt['domain'][$domain]['sitename'];
294
        }
295
        if (isset($opt['domain'][$domain]['keywords'])) {
296
            $opt['page']['meta']['keywords'] = $opt['domain'][$domain]['keywords'];
297
        }
298 View Code Duplication
        if (isset($opt['domain'][$domain]['description'])) {
299
            $opt['page']['meta']['description'] = $opt['domain'][$domain]['description'];
300
        }
301
302
        if (isset($opt['domain'][$domain]['headoverlay'])) {
303
            $opt['page']['headoverlay'] = $opt['domain'][$domain]['headoverlay'];
304
        }
305
        if (isset($opt['domain'][$domain]['slogan'])) {
306
            $opt['page']['slogan'] = $opt['domain'][$domain]['slogan'];
307
        }
308
    }
309
}
310