Code Duplication    Length = 25-25 lines in 2 locations

main/lp/learnpath.class.php 2 locations

@@ 10261-10285 (lines=25) @@
10258
                                        $file_path = str_replace('\\', '/', $file_path);
10259
                                        $my_dep_file->setAttribute('href', 'document/'.$file_path);
10260
                                        $my_dep->setAttribute('xml:base', '');
10261
                                        if (strstr($file_path, $main_path) !== false) {
10262
                                            // The calculated real path is really inside the chamilo root path.
10263
                                            // Reduce file path to what's under the DocumentRoot.
10264
                                            $file_path = substr($file_path, strlen($root_path));
10265
                                            $zip_files_abs[] = $file_path;
10266
                                            $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
10267
                                            $my_dep_file->setAttribute('href', 'document/'.$file_path);
10268
                                            $my_dep->setAttribute('xml:base', '');
10269
                                        } elseif (empty($file_path)) {
10270
                                            /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
10271
                                            if (strpos($document_root,-1) == '/') {
10272
                                                $document_root = substr(0, -1, $document_root);
10273
                                            }*/
10274
                                            $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
10275
                                            $file_path = str_replace('//', '/', $file_path);
10276
                                            if (file_exists($file_path)) {
10277
                                                $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
10278
                                                $zip_files[] = $my_sub_dir.'/'.$file_path;
10279
                                                $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
10280
                                                $my_dep_file->setAttribute('href', 'document/'.$file_path);
10281
                                                $my_dep->setAttribute('xml:base', '');
10282
                                            }
10283
                                        }
10284
                                        break;
10285
                                    case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
10286
                                        $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
10287
                                        $current_dir = str_replace('\\', '/', $current_dir);
10288
                                        $file_path = realpath($doc_info[0]);
@@ 10293-10317 (lines=25) @@
10290
                                        $my_dep_file->setAttribute('href', $file_path);
10291
                                        $my_dep->setAttribute('xml:base', '');
10292
10293
                                        if (strstr($file_path, $main_path) !== false) {
10294
                                            // The calculated real path is really inside the chamilo root path.
10295
                                            // Reduce file path to what's under the DocumentRoot.
10296
                                            $file_path = substr($file_path, strlen($root_path));
10297
                                            //echo $file_path;echo '<br /><br />';
10298
                                            //error_log('Reduced path: '.$file_path, 0);
10299
                                            $zip_files_abs[] = $file_path;
10300
                                            $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
10301
                                            $my_dep_file->setAttribute('href', 'document/'.$file_path);
10302
                                            $my_dep->setAttribute('xml:base', '');
10303
                                        } elseif (empty($file_path)) {
10304
                                            /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
10305
                                            if (strpos($document_root,-1) == '/') {
10306
                                                $document_root = substr(0, -1, $document_root);
10307
                                            }*/
10308
                                            $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
10309
                                            $file_path = str_replace('//', '/', $file_path);
10310
                                            if (file_exists($file_path)) {
10311
                                                $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
10312
                                                $zip_files[] = $my_sub_dir.'/'.$file_path;
10313
                                                $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
10314
                                                $my_dep_file->setAttribute('href', 'document/'.$file_path);
10315
                                                $my_dep->setAttribute('xml:base', '');
10316
                                            }
10317
                                        }
10318
                                        break;
10319
                                    case 'rel': // Path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
10320
                                        if (substr($doc_info[0], 0, 2) == '..') {