Code Duplication    Length = 37-39 lines in 3 locations

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

@@ 2277-2315 (lines=39) @@
2274
                                            //we didn't find any trace of current portal
2275
                                            $files_list[] = array($second_part, 'remote', 'url');
2276
                                        }
2277
                                    } elseif (strpos($second_part, '=') > 0) {
2278
                                        if (substr($second_part, 0, 1) === '/') {
2279
                                            //link starts with a /, making it absolute (relative to DocumentRoot)
2280
                                            $files_list[] = array($second_part, 'local', 'abs');
2281
                                            $in_files_list[] = self::get_resources_from_source_html($second_part, true, TOOL_DOCUMENT, $recursivity + 1);
2282
                                            if (count($in_files_list) > 0) {
2283
                                                $files_list = array_merge($files_list, $in_files_list);
2284
                                            }
2285
                                        } elseif (strstr($second_part, '..') === 0) {
2286
                                            //link is relative but going back in the hierarchy
2287
                                            $files_list[] = array($second_part, 'local', 'rel');
2288
                                            //$dir = api_get_path(SYS_CODE_PATH);//dirname($abs_path);
2289
                                            //$new_abs_path = realpath($dir.'/'.$second_part);
2290
                                            $dir = '';
2291
                                            if (!empty($abs_path)) {
2292
                                                $dir = dirname($abs_path) . '/';
2293
                                            }
2294
                                            $new_abs_path = realpath($dir . $second_part);
2295
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2296
                                            if (count($in_files_list) > 0) {
2297
                                                $files_list = array_merge($files_list, $in_files_list);
2298
                                            }
2299
                                        } else {
2300
                                            //no starting '/', making it relative to current document's path
2301
                                            if (substr($second_part, 0, 2) == './') {
2302
                                                $second_part = substr($second_part, 2);
2303
                                            }
2304
                                            $files_list[] = array($second_part, 'local', 'rel');
2305
                                            $dir = '';
2306
                                            if (!empty($abs_path)) {
2307
                                                $dir = dirname($abs_path) . '/';
2308
                                            }
2309
                                            $new_abs_path = realpath($dir . $second_part);
2310
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2311
                                            if (count($in_files_list) > 0) {
2312
                                                $files_list = array_merge($files_list, $in_files_list);
2313
                                            }
2314
                                        }
2315
                                    }
2316
                                    //leave that second part behind now
2317
                                    $source = substr($source, 0, strpos($source, '?'));
2318
                                    if (strpos($source, '://') > 0) {
@@ 2330-2366 (lines=37) @@
2327
                                            //we didn't find any trace of current portal
2328
                                            $files_list[] = array($source, 'remote', 'url');
2329
                                        }
2330
                                    } else {
2331
                                        //no protocol found, make link local
2332
                                        if (substr($source, 0, 1) === '/') {
2333
                                            //link starts with a /, making it absolute (relative to DocumentRoot)
2334
                                            $files_list[] = array($source, 'local', 'abs');
2335
                                            $in_files_list[] = self::get_resources_from_source_html($source, true, TOOL_DOCUMENT, $recursivity + 1);
2336
                                            if (count($in_files_list) > 0) {
2337
                                                $files_list = array_merge($files_list, $in_files_list);
2338
                                            }
2339
                                        } elseif (strstr($source, '..') === 0) { //link is relative but going back in the hierarchy
2340
                                            $files_list[] = array($source, 'local', 'rel');
2341
                                            $dir = '';
2342
                                            if (!empty($abs_path)) {
2343
                                                $dir = dirname($abs_path) . '/';
2344
                                            }
2345
                                            $new_abs_path = realpath($dir . $source);
2346
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2347
                                            if (count($in_files_list) > 0) {
2348
                                                $files_list = array_merge($files_list, $in_files_list);
2349
                                            }
2350
                                        } else {
2351
                                            //no starting '/', making it relative to current document's path
2352
                                            if (substr($source, 0, 2) == './') {
2353
                                                $source = substr($source, 2);
2354
                                            }
2355
                                            $files_list[] = array($source, 'local', 'rel');
2356
                                            $dir = '';
2357
                                            if (!empty($abs_path)) {
2358
                                                $dir = dirname($abs_path) . '/';
2359
                                            }
2360
                                            $new_abs_path = realpath($dir . $source);
2361
                                            $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2362
                                            if (count($in_files_list) > 0) {
2363
                                                $files_list = array_merge($files_list, $in_files_list);
2364
                                            }
2365
                                        }
2366
                                    }
2367
                                }
2368
                                //found some protocol there
2369
                                if (strpos($source, api_get_path(WEB_PATH)) !== false) {
@@ 2380-2417 (lines=38) @@
2377
                                    //we didn't find any trace of current portal
2378
                                    $files_list[] = array($source, 'remote', 'url');
2379
                                }
2380
                            } else {
2381
                                //no protocol found, make link local
2382
                                if (substr($source, 0, 1) === '/') {
2383
                                    //link starts with a /, making it absolute (relative to DocumentRoot)
2384
                                    $files_list[] = array($source, 'local', 'abs');
2385
                                    $in_files_list[] = self::get_resources_from_source_html($source, true, TOOL_DOCUMENT, $recursivity + 1);
2386
                                    if (count($in_files_list) > 0) {
2387
                                        $files_list = array_merge($files_list, $in_files_list);
2388
                                    }
2389
                                } elseif (strpos($source, '..') === 0) {
2390
                                    //link is relative but going back in the hierarchy
2391
                                    $files_list[] = array($source, 'local', 'rel');
2392
                                    $dir = '';
2393
                                    if (!empty($abs_path)) {
2394
                                        $dir = dirname($abs_path) . '/';
2395
                                    }
2396
                                    $new_abs_path = realpath($dir . $source);
2397
                                    $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2398
                                    if (count($in_files_list) > 0) {
2399
                                        $files_list = array_merge($files_list, $in_files_list);
2400
                                    }
2401
                                } else {
2402
                                    //no starting '/', making it relative to current document's path
2403
                                    if (substr($source, 0, 2) == './') {
2404
                                        $source = substr($source, 2);
2405
                                    }
2406
                                    $files_list[] = array($source, 'local', 'rel');
2407
                                    $dir = '';
2408
                                    if (!empty($abs_path)) {
2409
                                        $dir = dirname($abs_path) . '/';
2410
                                    }
2411
                                    $new_abs_path = realpath($dir . $source);
2412
                                    $in_files_list[] = self::get_resources_from_source_html($new_abs_path, true, TOOL_DOCUMENT, $recursivity + 1);
2413
                                    if (count($in_files_list) > 0) {
2414
                                        $files_list = array_merge($files_list, $in_files_list);
2415
                                    }
2416
                                }
2417
                            }
2418
                        }
2419
                    }
2420
                }