Conditions | 22 |
Paths | > 20000 |
Total Lines | 114 |
Lines | 17 |
Ratio | 14.91 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | |||
310 |