Code Duplication    Length = 37-39 lines in 3 locations

main/inc/lib/document.lib.php 3 locations

@@ 2238-2276 (lines=39) @@
2235
                                            //we didn't find any trace of current portal
2236
                                            $files_list[] = array($second_part, 'remote', 'url');
2237
                                        }
2238
                                    } elseif (strpos($second_part, '=') > 0) {
2239
                                        if (substr($second_part, 0, 1) === '/') {
2240
                                            //link starts with a /, making it absolute (relative to DocumentRoot)
2241
                                            $files_list[] = array($second_part, 'local', 'abs');
2242
                                            $in_files_list[] = self::get_resources_from_source_html($second_part, true, TOOL_DOCUMENT, $recursivity + 1);
2243
                                            if (count($in_files_list) > 0) {
2244
                                                $files_list = array_merge($files_list, $in_files_list);
2245
                                            }
2246
                                        } elseif (strstr($second_part, '..') === 0) {
2247
                                            //link is relative but going back in the hierarchy
2248
                                            $files_list[] = array($second_part, 'local', 'rel');
2249
                                            //$dir = api_get_path(SYS_CODE_PATH);//dirname($abs_path);
2250
                                            //$new_abs_path = realpath($dir.'/'.$second_part);
2251
                                            $dir = '';
2252
                                            if (!empty($abs_path)) {
2253
                                                $dir = dirname($abs_path) . '/';
2254
                                            }
2255
                                            $new_abs_path = realpath($dir . $second_part);
2256
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2257
                                            if (count($in_files_list) > 0) {
2258
                                                $files_list = array_merge($files_list, $in_files_list);
2259
                                            }
2260
                                        } else {
2261
                                            //no starting '/', making it relative to current document's path
2262
                                            if (substr($second_part, 0, 2) == './') {
2263
                                                $second_part = substr($second_part, 2);
2264
                                            }
2265
                                            $files_list[] = array($second_part, 'local', 'rel');
2266
                                            $dir = '';
2267
                                            if (!empty($abs_path)) {
2268
                                                $dir = dirname($abs_path) . '/';
2269
                                            }
2270
                                            $new_abs_path = realpath($dir . $second_part);
2271
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2272
                                            if (count($in_files_list) > 0) {
2273
                                                $files_list = array_merge($files_list, $in_files_list);
2274
                                            }
2275
                                        }
2276
                                    }
2277
                                    //leave that second part behind now
2278
                                    $source = substr($source, 0, strpos($source, '?'));
2279
                                    if (strpos($source, '://') > 0) {
@@ 2291-2327 (lines=37) @@
2288
                                            //we didn't find any trace of current portal
2289
                                            $files_list[] = array($source, 'remote', 'url');
2290
                                        }
2291
                                    } else {
2292
                                        //no protocol found, make link local
2293
                                        if (substr($source, 0, 1) === '/') {
2294
                                            //link starts with a /, making it absolute (relative to DocumentRoot)
2295
                                            $files_list[] = array($source, 'local', 'abs');
2296
                                            $in_files_list[] = self::get_resources_from_source_html($source, true, TOOL_DOCUMENT, $recursivity + 1);
2297
                                            if (count($in_files_list) > 0) {
2298
                                                $files_list = array_merge($files_list, $in_files_list);
2299
                                            }
2300
                                        } elseif (strstr($source, '..') === 0) { //link is relative but going back in the hierarchy
2301
                                            $files_list[] = array($source, 'local', 'rel');
2302
                                            $dir = '';
2303
                                            if (!empty($abs_path)) {
2304
                                                $dir = dirname($abs_path) . '/';
2305
                                            }
2306
                                            $new_abs_path = realpath($dir . $source);
2307
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2308
                                            if (count($in_files_list) > 0) {
2309
                                                $files_list = array_merge($files_list, $in_files_list);
2310
                                            }
2311
                                        } else {
2312
                                            //no starting '/', making it relative to current document's path
2313
                                            if (substr($source, 0, 2) == './') {
2314
                                                $source = substr($source, 2);
2315
                                            }
2316
                                            $files_list[] = array($source, 'local', 'rel');
2317
                                            $dir = '';
2318
                                            if (!empty($abs_path)) {
2319
                                                $dir = dirname($abs_path) . '/';
2320
                                            }
2321
                                            $new_abs_path = realpath($dir . $source);
2322
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2323
                                            if (count($in_files_list) > 0) {
2324
                                                $files_list = array_merge($files_list, $in_files_list);
2325
                                            }
2326
                                        }
2327
                                    }
2328
                                }
2329
                                //found some protocol there
2330
                                if (strpos($source, api_get_path(WEB_PATH)) !== false) {
@@ 2341-2378 (lines=38) @@
2338
                                    //we didn't find any trace of current portal
2339
                                    $files_list[] = array($source, 'remote', 'url');
2340
                                }
2341
                            } else {
2342
                                //no protocol found, make link local
2343
                                if (substr($source, 0, 1) === '/') {
2344
                                    //link starts with a /, making it absolute (relative to DocumentRoot)
2345
                                    $files_list[] = array($source, 'local', 'abs');
2346
                                    $in_files_list[] = self::get_resources_from_source_html($source, true, TOOL_DOCUMENT, $recursivity + 1);
2347
                                    if (count($in_files_list) > 0) {
2348
                                        $files_list = array_merge($files_list, $in_files_list);
2349
                                    }
2350
                                } elseif (strpos($source, '..') === 0) {
2351
                                    //link is relative but going back in the hierarchy
2352
                                    $files_list[] = array($source, 'local', 'rel');
2353
                                    $dir = '';
2354
                                    if (!empty($abs_path)) {
2355
                                        $dir = dirname($abs_path) . '/';
2356
                                    }
2357
                                    $new_abs_path = realpath($dir . $source);
2358
                                    $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2359
                                    if (count($in_files_list) > 0) {
2360
                                        $files_list = array_merge($files_list, $in_files_list);
2361
                                    }
2362
                                } else {
2363
                                    //no starting '/', making it relative to current document's path
2364
                                    if (substr($source, 0, 2) == './') {
2365
                                        $source = substr($source, 2);
2366
                                    }
2367
                                    $files_list[] = array($source, 'local', 'rel');
2368
                                    $dir = '';
2369
                                    if (!empty($abs_path)) {
2370
                                        $dir = dirname($abs_path) . '/';
2371
                                    }
2372
                                    $new_abs_path = realpath($dir . $source);
2373
                                    $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2374
                                    if (count($in_files_list) > 0) {
2375
                                        $files_list = array_merge($files_list, $in_files_list);
2376
                                    }
2377
                                }
2378
                            }
2379
                        }
2380
                    }
2381
                }