From a1bc3c2d528b63729ff26c7a8e29e70880d02afd Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 7 Apr 2016 14:32:36 +0200 Subject: [PATCH] FIx Paths see BT #11047 --- .../classes/CourseRestorer.class.php | 6 +- main/cron/notification.php | 9 +- main/document/create_document.php | 9 +- main/document/edit_draw.php | 49 +- main/exercice/export/exercise_import.php | 36 +- main/glossary/glossary_ajax_request.php | 7 +- main/inc/ajax/nanogong.ajax.php | 11 +- main/inc/global.inc.php | 8 +- main/inc/global_error_message.inc.php | 4 +- main/inc/lib/api.lib.php | 442 ++++++++++-------- main/inc/lib/course_home.lib.php | 15 +- main/inc/lib/glossary.lib.php | 3 +- main/inc/lib/online.inc.php | 14 +- main/inc/lib/pdf.lib.php | 3 +- main/inc/lib/system_announcements.lib.php | 15 +- main/inc/lib/template.lib.php | 17 +- main/inc/lib/usermanager.lib.php | 5 +- main/inc/lib/userportal.lib.php | 15 + main/install/install.lib.php | 4 +- main/newscorm/learnpath.class.php | 16 +- main/newscorm/lp_list.php | 2 +- main/newscorm/scorm_api.php | 2 +- main/wiki/wiki.inc.php | 4 +- src/Chamilo/UserBundle/Entity/User.php | 4 +- 24 files changed, 379 insertions(+), 321 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index db38a15123..0e84c66c80 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -2766,9 +2766,9 @@ class CourseRestorer } } - $destination = '../../courses/'.$this->course->destination_path.'/work/'; - $origin = '../../courses/'.$this->course->info['path'].'/work/'; - self::allow_create_all_directory($origin,$destination,false); + $destination = '../..'.api_get_path(REL_COURSE_PATH).$this->course->destination_path.'/work/'; + $origin = '../..'.api_get_path(REL_COURSE_PATH).$this->course->info['path'].'/work/'; + self::allow_create_all_directory($origin, $destination, false); } /** diff --git a/main/cron/notification.php b/main/cron/notification.php index 9f9ae16ff4..e263ad1e69 100755 --- a/main/cron/notification.php +++ b/main/cron/notification.php @@ -4,14 +4,13 @@ * @package chamilo.notification * @author Julio Montoya */ -/** - * Initialization - */ -if (PHP_SAPI!='cli') { + +if (PHP_SAPI != 'cli') { die('Run this script through the command line or comment this line in the code'); } -require_once '../inc/global.inc.php'; +require_once __DIR__.'/../inc/global.inc.php'; + /** * Notification sending */ diff --git a/main/document/create_document.php b/main/document/create_document.php index 7cc7d662a2..c0a021a9e4 100755 --- a/main/document/create_document.php +++ b/main/document/create_document.php @@ -445,7 +445,7 @@ if ($form->validate()) { $values = $form->exportValues(); $readonly = isset($values['readonly']) ? 1 : 0; $values['title'] = trim($values['title']); - + if (!empty($values['dirValue'])) { $dir = $values['dirValue']; } @@ -489,7 +489,8 @@ if ($form->validate()) { } if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) { - $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].'/courses/', $content); + //$content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].'/courses/', $content); + $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].api_get_path(REL_COURSE_PATH), $content); fputs($fp, $content); fclose($fp); @@ -617,9 +618,9 @@ if ($form->validate()) { $actionsLeft = ''. Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).''; } - + echo $toolbar = Display::toolbarAction('actions-documents', array(0 => $actionsLeft, 1 => '')); - + if ($is_certificate_mode) { $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id()); diff --git a/main/document/edit_draw.php b/main/document/edit_draw.php index 1955f7e83b..dd14c4f569 100755 --- a/main/document/edit_draw.php +++ b/main/document/edit_draw.php @@ -9,6 +9,7 @@ * @author Juan Carlos Ra�a Trabado * @since 25/september/2010 */ + require_once '../inc/global.inc.php'; $_SESSION['whereami'] = 'document/editdraw'; @@ -28,26 +29,25 @@ if (empty($document_data)) { $parent_id = DocumentManager::get_document_id(api_get_course_info(), $dir); $my_cur_dir_path = Security::remove_XSS($_GET['curdirpath']); } - -$dir= str_replace('\\', '/',$dir);//and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261) +//and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261) +$dir = str_replace('\\', '/', $dir); /* Constants & Variables */ $current_session_id=api_get_session_id(); $group_id = api_get_group_id(); //path for svg-edit save -$_SESSION['draw_dir']=Security::remove_XSS($dir); -if ($_SESSION['draw_dir']=='/'){ +$_SESSION['draw_dir'] = Security::remove_XSS($dir); +if ($_SESSION['draw_dir'] == '/') { $_SESSION['draw_dir'] = ''; } -$_SESSION['draw_file']=basename(Security::remove_XSS($file_path)); +$_SESSION['draw_file'] = basename(Security::remove_XSS($file_path)); $get_file = Security::remove_XSS($file_path); $file = basename($get_file); -$temp_file = explode(".",$file); -$filename=$temp_file[0]; -$nameTools = get_lang('EditDocument') . ': '.$filename; - -$courseDir = $_course['path'].'/document'; +$temp_file = explode(".", $file); +$filename = $temp_file[0]; +$nameTools = get_lang('EditDocument') . ': ' . $filename; +$courseDir = $_course['path'] . '/document'; $is_allowed_to_edit = api_is_allowed_to_edit(null, true); /* Other initialization code */ @@ -79,8 +79,10 @@ if (!is_dir($filepath)) { //groups //TODO:clean if (!empty($group_id)) { - $req_gid = '&gidReq='.$group_id; - $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?gidReq='.$group_id, 'name' => get_lang('GroupSpace')); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), + 'name' => get_lang('GroupSpace'), + ); $group_document = true; $noPHP_SELF = true; } @@ -88,15 +90,18 @@ if (!empty($group_id)) { $is_certificate_mode = DocumentManager::is_certificate_mode($dir); if (!$is_certificate_mode) - $interbreadcrumb[]= array("url" => "./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents')); + $interbreadcrumb[] = array( + "url" => "./document.php?curdirpath=".urlencode($my_cur_dir_path).'&'.api_get_cidreq(), + "name" => get_lang('Documents'), + ); else - $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook')); + $interbreadcrumb[] = array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook')); // Interbreadcrumb for the current directory root path if (empty($document_data['parents'])) { $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']); } else { - foreach($document_data['parents'] as $document_sub_data) { + foreach ($document_data['parents'] as $document_sub_data) { if ($document_data['title'] == $document_sub_data['title']) { continue; } @@ -115,8 +120,10 @@ Event::event_access_tool(TOOL_DOCUMENT); Display :: display_header($nameTools, 'Doc'); echo ''; if (api_browser_support('svg')) { @@ -125,13 +132,11 @@ if (api_browser_support('svg')) { $langsvgedit = api_get_language_isocode(); $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit; $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'svg-edit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en'; - - $svg_url= api_get_path(WEB_LIBRARY_PATH).'svg-edit/svg-editor.php?url=../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit; + //$svg_url= api_get_path(WEB_LIBRARY_PATH).'svg-edit/svg-editor.php?url=../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit; + $svg_url= api_get_path(WEB_LIBRARY_PATH).'svg-edit/svg-editor.php?url=../../../..'.api_get_path(REL_COURSE_PATH).$courseDir.$dir.$file.'&lang='.$langsvgedit; ?> - - '; echo ''; diff --git a/main/exercice/export/exercise_import.php b/main/exercice/export/exercise_import.php index a3ea4a5ab0..ca400f307d 100755 --- a/main/exercice/export/exercise_import.php +++ b/main/exercice/export/exercise_import.php @@ -1,14 +1,10 @@ - */ -/** - * Code - */ - require '../../inc/global.inc.php'; //SECURITY CHECK @@ -30,15 +26,9 @@ $tbl_rel_exercise_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION //Tool title $nameTools = get_lang('ImportExercise'); - -//bredcrump - $interbredcrump[] = array('url' => '../exercise.php', 'name' => get_lang('Exercises')); -//---------------------------------- // EXECUTE COMMAND -//---------------------------------- - $cmd = (isset($_REQUEST['cmd'])? $_REQUEST['cmd'] : 'show_import'); switch ($cmd) { @@ -75,33 +65,22 @@ switch ($cmd) { break; } -//---------------------------------- -// FIND INFORMATION -//---------------------------------- - -//empty! -//---------------------------------- // DISPLAY -//---------------------------------- - include api_get_path(INCLUDE_PATH) . '/header.inc.php'; -//display title - - // Tool introduction // TODO: These settings to be checked when it is possible. -Display::display_introduction_section(TOOL_QUIZ, array( +Display::display_introduction_section( + TOOL_QUIZ, + array( 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/', - 'CreateDocumentDir' => '../../../courses/'.api_get_course_path().'/document/', + 'CreateDocumentDir' => '../../..'.api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/' ) ); - -//Display Forms or dialog box(if needed) - +// Display Forms or dialog box(if needed) if (isset($dialogBox)) { echo Display::display_normal_message($dialogBox, false); } @@ -112,7 +91,4 @@ if (isset($display)) { echo $display; } -//footer display - include api_get_path(INCLUDE_PATH) . '/footer.inc.php'; -?> diff --git a/main/glossary/glossary_ajax_request.php b/main/glossary/glossary_ajax_request.php index 6fd92477e2..3c66bef06a 100644 --- a/main/glossary/glossary_ajax_request.php +++ b/main/glossary/glossary_ajax_request.php @@ -16,14 +16,13 @@ $charset = api_get_system_encoding(); //replace image path $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path(); -$path_image_search = '../../courses/'.api_get_course_path(); +$path_image_search = '../..'.api_get_path(REL_COURSE_PATH).api_get_course_path(); if (isset($_POST['glossary_id']) && $_POST['glossary_id'] == strval(intval($_POST['glossary_id'])) ) { - $glossary_id= Security::remove_XSS($_POST['glossary_id']); $glossary_description_by_id = GlossaryManager::get_glossary_term_by_glossary_id( - $glossary_id + $_POST['glossary_id'] ); $glossary_description_by_id = str_replace( $path_image_search, @@ -31,7 +30,7 @@ if (isset($_POST['glossary_id']) && $glossary_description_by_id ); echo api_xml_http_response_encode($glossary_description_by_id); -} elseif (isset($_POST['glossary_data']) && $_POST['glossary_data']=='true') { +} elseif (isset($_POST['glossary_data']) && $_POST['glossary_data'] == 'true') { //get_glossary_terms $glossary_data = GlossaryManager::get_glossary_terms(); $glossary_all_data = array(); diff --git a/main/inc/ajax/nanogong.ajax.php b/main/inc/ajax/nanogong.ajax.php index b7873efa06..ad44578157 100755 --- a/main/inc/ajax/nanogong.ajax.php +++ b/main/inc/ajax/nanogong.ajax.php @@ -1,17 +1,16 @@ get_param_value('user_id') == api_get_user_id() || api_is_allowed_to_edit()) { $file_path = $nano->load_filename_if_exists(); - //$file_path = '/var/www/rocio/courses/GREAT123/exercises/0/2/5/1/1-0-1-2-5-38.mp3'; if ($file_path) { $info = pathinfo($file_path); $user_info = api_get_user_info($nano->params['user_id']); $name = get_lang('Quiz').'-'.$user_info['firstname'].'-'.$user_info['lastname'].'.'.$info['extension']; $download = true; - if (isset($_REQUEST['download']) && $_REQUEST['download'] == 0) { + if (isset($_REQUEST['download']) && $_REQUEST['download'] == 0) { $download = false; } DocumentManager::file_send_for_download($file_path, $download); @@ -69,8 +67,7 @@ switch ($action) { echo $nano->return_form(); break; case 'save_file': - //User access same as upload.php - + // User access same as upload.php $return = $nano->upload_file($is_nano); if ($is_nano) { diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 17ace08608..a8b5d1ee86 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -43,11 +43,14 @@ if (file_exists($kernel->getConfigurationFile())) { $_configuration = array(); } +// Recalculate a system absolute path symlinks insensible. +$includePath = $_configuration['root_sys'].'main/inc/'; + //Redirects to the main/install/ page if (!$alreadyInstalled) { $global_error_code = 2; // The system has not been installed yet. - require $includePath.'/global_error_message.inc.php'; + require_once $includePath.'/global_error_message.inc.php'; die(); } @@ -58,7 +61,8 @@ if (!isset($GLOBALS['_configuration'])) { } // Include the main Chamilo platform library file. -require_once $includePath.'/lib/api.lib.php'; + +require_once $_configuration['root_sys'].'main/inc/lib/api.lib.php'; $passwordEncryption = api_get_configuration_value('password_encryption'); if ($passwordEncryption == 'bcrypt') { diff --git a/main/inc/global_error_message.inc.php b/main/inc/global_error_message.inc.php index 812d4d23b5..2c59a4a7de 100755 --- a/main/inc/global_error_message.inc.php +++ b/main/inc/global_error_message.inc.php @@ -78,9 +78,9 @@ if (is_int($global_error_code) && $global_error_code > 0) { $pos = $test_pos + 1; } $root_rel = substr($root_rel, 0, $pos); - } elseif (strpos($root_rel, '/courses/') !== false) { + } elseif (strpos($root_rel, api_get_path(REL_COURSE_PATH)) !== false) { $pos = 0; - while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), '/courses/')) !== false) { + while (($test_pos = strpos(substr($root_rel, $pos, strlen($root_rel)), api_get_path(REL_COURSE_PATH))) !== false) { $pos = $test_pos + 1; } $root_rel = substr($root_rel, 0, $pos); diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index c54296ec76..8fa1b39939 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -272,6 +272,22 @@ define('REPEATED_SLASHES_PURIFIER', '/\/{2,}/'); // $path = p define('VALID_WEB_PATH', '/https?:\/\/[^\/]*(\/.*)?/i'); // $is_valid_path = preg_match(VALID_WEB_PATH, $path); define('VALID_WEB_SERVER_BASE', '/https?:\/\/[^\/]*/i'); // $new_path = preg_replace(VALID_WEB_SERVER_BASE, $new_base, $path); + +// Constants for api_get_path() and api_get_path_type(), etc. - registered path types. +// basic (leaf elements) +define('REL_AJAX_PATH', 'REL_AJAX_PATH'); +define('REL_ARCHIVE_PATH', 'REL_ARCHIVE_PATH'); +define('REL_CODE_PATH', 'REL_CODE_PATH'); +define('REL_COURSE_PATH', 'REL_COURSE_PATH'); +define('REL_CSS_PATH', 'REL_CSS_PATH'); +define('REL_HOME_PATH', 'REL_HOME_PATH'); +define('REL_IMG_PATH', 'REL_IMG_PATH'); +define('REL_LANG_PATH', 'REL_LANG_PATH'); +define('REL_LIBRARY_PATH', 'REL_LIBRARY_PATH'); +define('REL_PLUGIN_PATH', 'REL_PLUGIN_PATH'); +define('REL_TEMPLATE_PATH', 'REL_TEMPLATE_PATH'); +define('REL_TEST_PATH', 'REL_TEST_PATH'); + // Constants for api_get_path() and api_get_path_type(), etc. - registered path types. define('WEB_PATH', 'WEB_PATH'); define('WEB_APP_PATH', 'WEB_APP_PATH'); @@ -285,8 +301,6 @@ define('WEB_SERVER_ROOT_PATH', 'WEB_SERVER_ROOT_PATH'); define('SYS_SERVER_ROOT_PATH', 'SYS_SERVER_ROOT_PATH'); define('WEB_COURSE_PATH', 'WEB_COURSE_PATH'); define('SYS_COURSE_PATH', 'SYS_COURSE_PATH'); -define('REL_COURSE_PATH', 'REL_COURSE_PATH'); -define('REL_CODE_PATH', 'REL_CODE_PATH'); define('REL_UPLOAD_PATH', 'REL_UPLOAD_PATH'); define('WEB_CODE_PATH', 'WEB_CODE_PATH'); define('SYS_CODE_PATH', 'SYS_CODE_PATH'); @@ -310,6 +324,9 @@ define('SYS_TEST_PATH', 'SYS_TEST_PATH'); define('WEB_TEMPLATE_PATH', 'WEB_TEMPLATE_PATH'); define('SYS_TEMPLATE_PATH', 'SYS_TEMPLATE_PATH'); define('SYS_PUBLIC_PATH', 'SYS_PUBLIC_PATH'); +define('SYS_HOME_PATH', 'SYS_HOME_PATH'); +define('WEB_HOME_PATH', 'WEB_HOME_PATH'); + define('WEB_FONTS_PATH', 'WEB_FONTS_PATH'); define('SYS_FONTS_PATH', 'SYS_FONTS_PATH'); @@ -674,96 +691,30 @@ require_once __DIR__.'/internationalization.lib.php'; * api_get_path(TO_WEB, $_SERVER['REQUEST_URI']) * api_get_path(TO_SYS, $_SERVER['PHP_SELF']) * api_get_path(TO_REL, __FILE__) - * ... - */ -function api_get_path($path_type, $path = null) -{ - static $paths = array( - WEB_PATH => '', - SYS_PATH => '', - REL_PATH => '', - WEB_SERVER_ROOT_PATH => '', - SYS_SERVER_ROOT_PATH => '', - WEB_COURSE_PATH => '', - SYS_COURSE_PATH => '', - REL_COURSE_PATH => '', - REL_CODE_PATH => '', - WEB_CODE_PATH => '', - SYS_CODE_PATH => '', - SYS_LANG_PATH => 'lang/', - WEB_IMG_PATH => 'img/', - WEB_CSS_PATH => 'web/css/', - SYS_CSS_PATH => 'app/Resources/public/css/', - SYS_PLUGIN_PATH => 'plugin/', - WEB_PLUGIN_PATH => 'plugin/', - SYS_ARCHIVE_PATH => 'app/cache/', - WEB_ARCHIVE_PATH => 'app/cache/', - SYS_APP_PATH => 'app/', - WEB_APP_PATH => 'app/', - SYS_UPLOAD_PATH => 'app/upload/', - REL_UPLOAD_PATH => 'app/upload/', - INCLUDE_PATH => 'inc/', - LIBRARY_PATH => 'inc/lib/', - CONFIGURATION_PATH => 'app/config/', - WEB_LIBRARY_PATH => 'inc/lib/', - WEB_LIBRARY_JS_PATH => 'inc/lib/javascript/', - WEB_AJAX_PATH => 'inc/ajax/', - SYS_TEST_PATH => 'tests/', - WEB_TEMPLATE_PATH => 'template/', - WEB_UPLOAD_PATH => 'app/upload/', - WEB_PUBLIC_PATH => 'web/', - SYS_TEMPLATE_PATH => 'template/', - SYS_PUBLIC_PATH => 'web/', - WEB_FONTS_PATH => 'fonts/', - SYS_FONTS_PATH => 'fonts/', - ); - static $resource_paths = array( - FLASH_PLAYER_AUDIO => 'inc/lib/mediaplayer/player.swf', - FLASH_PLAYER_VIDEO => 'inc/lib/mediaplayer/player.swf', - SCRIPT_SWFOBJECT => 'inc/lib/swfobject/swfobject.js', - SCRIPT_ASCIIMATHML => 'inc/lib/javascript/asciimath/ASCIIMathML.js', - DRAWING_ASCIISVG => 'inc/lib/javascript/asciimath/d.svg' - ); - - static $is_this_function_initialized; - static $server_base_web; // No trailing slash. - static $server_base_sys; // No trailing slash. - static $root_web; - static $root_sys; - static $root_rel; +* Vchamilo changes : allow using an alternate configuration +* to get vchamilo instance paths +*/ +function api_get_path($path_type, $path = null, $configuration = null) +{ + global $catcher; + global $paths; - // Always load root_web modifications for multiple url features + // get proper configuration data if exists global $_configuration; - //default $_configuration['root_web'] configuration - $root_web = $_configuration['root_web']; - - $code_folder = 'main/'; - $course_folder = 'courses/'; - - // Configuration data for already installed system. - $root_sys = $_configuration['root_sys']; - $load_new_config = false; - // To avoid that the api_get_access_url() function fails since global.inc.php also calls the main_api.lib.php - if ($path_type == WEB_PATH) { - if (isset($_configuration['access_url']) && $_configuration['access_url'] != 1) { - //we look into the DB the function api_get_access_url - $url_info = api_get_access_url($_configuration['access_url']); - $root_web = $url_info['active'] == 1 ? $url_info['url'] : $_configuration['root_web']; - $load_new_config = true; - } + if (is_null($configuration)) { + $configuration = $_configuration; } - if (!$is_this_function_initialized) { - global $_configuration; - - $root_rel = $_configuration['url_append']; - - // Support for the installation process. - // Developers might use the function api_get_path() directly or indirectly (this is difficult to be traced), at the moment when - // configuration has not been created yet. This is why this function should be upgraded to return correct results in this case. + $course_folder = 'courses/'; + $code_folder = 'main/'; + // Resolve master hostname. + if (!is_null($configuration) && array_key_exists('root_web', $configuration)) { + $root_web = $configuration['root_web']; + } else { + // Try guess it from server. if (defined('SYSTEM_INSTALLATION') && SYSTEM_INSTALLATION) { if (($pos = strpos(($requested_page_rel = api_get_self()), 'main/install')) !== false) { $root_rel = substr($requested_page_rel, 0, $pos); @@ -782,116 +733,223 @@ function api_get_path($path_type, $path = null) } $root_web = $server_protocol.'://'.$server_name.$root_rel; $root_sys = str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/'; - $code_folder = 'main/'; } // Here we give up, so we don't touch anything. } + } - // Dealing with trailing slashes. - $root_web = api_add_trailing_slash($root_web); - $root_sys = api_add_trailing_slash($root_sys); - $root_rel = api_add_trailing_slash($root_rel); - $code_folder = api_add_trailing_slash($code_folder); - $course_folder = api_add_trailing_slash($course_folder); + // define caches the path cache will know about effective root_web, from explicit configuration, + // or guess it from server information (install or early process time) + static $resourcePaths = null; + + if (empty($paths)) { + $paths = []; + } + + // Initialise cache with default values. + if (!array_key_exists($root_web, $paths)) { + $paths[$root_web] = array( + WEB_PATH => '', + SYS_PATH => '', + REL_PATH => '', + WEB_SERVER_ROOT_PATH => '', + SYS_SERVER_ROOT_PATH => '', + WEB_COURSE_PATH => '', + SYS_COURSE_PATH => '', + REL_COURSE_PATH => '', + WEB_CODE_PATH => 'main/', + SYS_CODE_PATH => 'main/', + REL_CODE_PATH => '/main/', + SYS_LANG_PATH => 'lang/', + REL_LANG_PATH => 'main/lang/', + WEB_IMG_PATH => 'img/', + REL_IMG_PATH => 'img/', + WEB_CSS_PATH => 'web/css/', + SYS_CSS_PATH => 'app/Resources/public/css/', + REL_CSS_PATH => 'css/', + SYS_PLUGIN_PATH => 'plugin/', + WEB_PLUGIN_PATH => 'plugin/', + REL_PLUGIN_PATH => 'plugin/', + SYS_ARCHIVE_PATH => 'app/cache/', + PLUGIN_PATH => 'plugin/', + WEB_ARCHIVE_PATH => 'app/cache/', + REL_ARCHIVE_PATH => 'app/cache/', + SYS_HOME_PATH => 'app/home/', + WEB_HOME_PATH => 'app/home/', + SYS_APP_PATH => 'app/', + WEB_APP_PATH => 'app/', + SYS_UPLOAD_PATH => 'app/upload/', + REL_UPLOAD_PATH => 'app/upload/', + REL_HOME_PATH => 'home/', + INCLUDE_PATH => 'inc/', + CONFIGURATION_PATH => 'app/config/', + LIBRARY_PATH => 'inc/lib/', + WEB_LIBRARY_PATH => 'inc/lib/', + WEB_LIBRARY_JS_PATH => 'inc/lib/javascript/', + REL_LIBRARY_PATH => 'inc/lib/', + REL_AJAX_PATH => 'inc/ajax/', + WEB_AJAX_PATH => 'inc/ajax/', + SYS_TEST_PATH => 'tests/', + REL_TEST_PATH => 'tests/', + WEB_TEMPLATE_PATH => 'template/', + SYS_TEMPLATE_PATH => 'template/', + REL_TEMPLATE_PATH => 'template/', + WEB_UPLOAD_PATH => 'app/upload/', + WEB_PUBLIC_PATH => 'web/', + SYS_PUBLIC_PATH => 'web/', + WEB_FONTS_PATH => 'fonts/', + SYS_FONTS_PATH => 'fonts/', + ); - // Web server base and system server base. - $server_base_web = preg_replace('@'.$root_rel.'$@', '', $root_web); // No trailing slash. - $server_base_sys = preg_replace('@'.$root_rel.'$@', '', $root_sys); // No trailing slash. + $resourcePaths[$root_web] = array( + FLASH_PLAYER_AUDIO => 'inc/lib/mediaplayer/player.swf', + FLASH_PLAYER_VIDEO => 'inc/lib/mediaplayer/player.swf', + SCRIPT_SWFOBJECT => 'inc/lib/swfobject/swfobject.js', + SCRIPT_ASCIIMATHML => 'inc/lib/javascript/asciimath/ASCIIMathML.js', + DRAWING_ASCIISVG => 'inc/lib/javascript/asciimath/d.svg', + ); + } - // Initialization of a table that contains common-purpose paths. - $paths[WEB_PATH] = $root_web; - $paths[SYS_PATH] = $root_sys; - $paths[REL_PATH] = $root_rel; - $paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/'; - $paths[SYS_SERVER_ROOT_PATH] = $server_base_sys.'/'; + static $isInitialized = []; - $paths[WEB_COURSE_PATH] = $root_web.$course_folder; + // Configuration data for all installed systems is unique. + if (empty($root_sys)) { + $root_sys = $configuration['root_sys']; + } - $paths[REL_COURSE_PATH] = $root_rel.$course_folder; - $paths[REL_CODE_PATH] = $root_rel.$code_folder; - $paths[WEB_CODE_PATH] = $root_web.$code_folder; - $paths[SYS_CODE_PATH] = $root_sys.$code_folder; - $paths[REL_UPLOAD_PATH] = $root_rel.$paths[SYS_UPLOAD_PATH]; + $loadNewConfig = false; - $paths[WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[WEB_CODE_PATH].'default_course_document/'; - $paths[REL_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[REL_PATH].'main/default_course_document/'; + // To avoid that the api_get_access_url() function fails since global.inc.php also calls the main_api.lib.php + if ($path_type == WEB_PATH) { + if (isset($configuration['access_url']) && $configuration['access_url'] != 1) { + //we look into the DB the function api_get_access_url + $url_info = api_get_access_url($configuration['access_url']); + $root_web = $url_info['active'] == 1 ? $url_info['url'] : $configuration['root_web']; + $loadNewConfig = true; + } + } + + if (isset($configuration['course_folder'])) { + $course_folder = $configuration['course_folder']; + } + + $configuration['code_append'] = isset($configuration['code_append']) ? $configuration['code_append'] : 'main'; + + if (preg_match('#https?://([^\.]+)#', $root_web, $matches)) { + $web_host = $matches[1]; + } else { + die('malformed root_web url'); + } + + // Web server base and system server base. + $root_rel = isset($configuration['url_append']) ? $configuration['url_append'] : ''; + $server_base_web = preg_replace('@'.$root_rel.'$@', '', $root_web); // No trailing slash. + $server_base_sys = preg_replace('@'.$root_rel.'$@', '', $root_sys); // No trailing slash. + + if (!array_key_exists($root_web, $isInitialized)) { + // process absolute global roots + //$root_rel = $configuration['url_append']; + if (!is_null($configuration)) { + $code_folder = $configuration['code_append']; + } else { + $code_folder = $paths[$root_web][REL_CODE_PATH]; + } + + // Support for the installation process. + // Developers might use the function api_get_path() directly or indirectly (this is difficult to be traced), at the moment when + // configuration has not been created yet. This is why this function should be upgraded to return correct results in this case. + + // Dealing with trailing slashes. + $slashed_root_web = api_add_trailing_slash($root_web); + $root_sys = api_add_trailing_slash($root_sys); + $root_rel = api_add_trailing_slash($root_rel); + $code_folder = api_add_trailing_slash($code_folder); + $course_folder = api_add_trailing_slash($course_folder); + + // Initialization of a table that contains common-purpose paths. + $paths[$root_web][WEB_PATH] = $slashed_root_web; + $paths[$root_web][SYS_PATH] = $root_sys; + $paths[$root_web][REL_PATH] = $root_rel; + $paths[$root_web][WEB_SERVER_ROOT_PATH] = $server_base_web.'/'; + $paths[$root_web][SYS_SERVER_ROOT_PATH] = $server_base_sys.'/'; + $paths[$root_web][WEB_COURSE_PATH] = $slashed_root_web.$course_folder; + + $paths[$root_web][REL_COURSE_PATH] = $root_rel.$course_folder; + $paths[$root_web][WEB_CODE_PATH] = $slashed_root_web.$code_folder; + $paths[$root_web][SYS_CODE_PATH] = $root_sys.$code_folder; + $paths[$root_web][REL_UPLOAD_PATH] = $root_rel.$paths[$root_web][SYS_UPLOAD_PATH]; + + $paths[$root_web][WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[$root_web][WEB_CODE_PATH].'default_course_document/'; + $paths[$root_web][REL_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[$root_web][REL_PATH].'main/default_course_document/'; // Now we can switch into api_get_path() "terminology". - $paths[SYS_LANG_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_LANG_PATH]; + $paths[$root_web][SYS_LANG_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_LANG_PATH]; + $paths[$root_web][SYS_PLUGIN_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_PLUGIN_PATH]; + $paths[$root_web][PLUGIN_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_PLUGIN_PATH]; + $paths[$root_web][SYS_ARCHIVE_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_ARCHIVE_PATH]; - $paths[SYS_APP_PATH] = $paths[SYS_PATH].$paths[SYS_APP_PATH]; - $paths[WEB_APP_PATH] = $paths[WEB_PATH].$paths[WEB_APP_PATH]; - $paths[SYS_UPLOAD_PATH] = $paths[SYS_PATH].$paths[SYS_UPLOAD_PATH]; + $paths[$root_web][SYS_APP_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][SYS_APP_PATH]; + $paths[$root_web][SYS_COURSE_PATH] = $paths[$root_web][SYS_APP_PATH].$course_folder; + $paths[$root_web][WEB_APP_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_APP_PATH]; + $paths[$root_web][SYS_UPLOAD_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][SYS_UPLOAD_PATH]; - $paths[SYS_PLUGIN_PATH] = $paths[SYS_PATH].$paths[SYS_PLUGIN_PATH]; - $paths[SYS_ARCHIVE_PATH] = $paths[SYS_PATH].$paths[SYS_ARCHIVE_PATH]; - $paths[SYS_TEST_PATH] = $paths[SYS_PATH].$paths[SYS_TEST_PATH]; - $paths[SYS_TEMPLATE_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_TEMPLATE_PATH]; - $paths[SYS_PUBLIC_PATH] = $paths[SYS_PATH].$paths[SYS_PUBLIC_PATH]; - $paths[SYS_CSS_PATH] = $paths[SYS_PATH].$paths[SYS_CSS_PATH]; - $paths[SYS_FONTS_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_FONTS_PATH]; - $paths[WEB_CSS_PATH] = $paths[WEB_PATH].$paths[WEB_CSS_PATH]; - $paths[WEB_IMG_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_IMG_PATH]; - $paths[WEB_LIBRARY_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_LIBRARY_PATH]; - $paths[WEB_LIBRARY_JS_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_LIBRARY_JS_PATH]; + // PATCH : Take VChamilo into account + /*global $VCHAMILO; + if (!empty($VCHAMILO) || !empty($configuration['virtual'])){ + $paths[$root_web][SYS_ARCHIVE_PATH] .= $web_host.'/'; + $paths[$root_web][SYS_HOME_PATH] .= $web_host.'/'; + }*/ - $paths[WEB_AJAX_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_AJAX_PATH]; - $paths[WEB_FONTS_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_FONTS_PATH]; + $paths[$root_web][SYS_TEST_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][SYS_TEST_PATH]; + $paths[$root_web][SYS_TEMPLATE_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][REL_TEMPLATE_PATH]; - $paths[WEB_PLUGIN_PATH] = $paths[WEB_PATH].$paths[WEB_PLUGIN_PATH]; - $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH].$paths[WEB_ARCHIVE_PATH]; + //$paths[$root_web][WEB_CSS_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][REL_CSS_PATH]; + //$paths[$root_web][WEB_IMG_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][REL_IMG_PATH]; + //$paths[$root_web][WEB_LIBRARY_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][REL_LIBRARY_PATH]; + //$paths[$root_web][WEB_AJAX_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][REL_AJAX_PATH]; - $paths[WEB_TEMPLATE_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_TEMPLATE_PATH]; - $paths[WEB_UPLOAD_PATH] = $paths[WEB_PATH].$paths[WEB_UPLOAD_PATH]; - $paths[WEB_PUBLIC_PATH] = $paths[WEB_PATH].$paths[WEB_PUBLIC_PATH]; + $paths[$root_web][WEB_PLUGIN_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_PLUGIN_PATH]; + $paths[$root_web][WEB_ARCHIVE_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_ARCHIVE_PATH]; - $paths[INCLUDE_PATH] = $paths[SYS_CODE_PATH].$paths[INCLUDE_PATH]; - $paths[LIBRARY_PATH] = $paths[SYS_CODE_PATH].$paths[LIBRARY_PATH]; - $paths[CONFIGURATION_PATH] = $paths[SYS_PATH].$paths[CONFIGURATION_PATH]; - $paths[SYS_COURSE_PATH] = $paths[SYS_APP_PATH].$course_folder; + $paths[$root_web][SYS_PUBLIC_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][SYS_PUBLIC_PATH]; + $paths[$root_web][SYS_CSS_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][SYS_CSS_PATH]; + $paths[$root_web][SYS_FONTS_PATH] = $paths[$root_web][SYS_CODE_PATH].$paths[$root_web][SYS_FONTS_PATH]; - $is_this_function_initialized = true; - } else { - if ($load_new_config) { - // Redefining variables to work well with the "multiple url" feature - - // All web paths need to be here - $web_paths = array( - WEB_PATH => '', - WEB_SERVER_ROOT_PATH => '', - WEB_COURSE_PATH => '', - WEB_CODE_PATH => '', - WEB_IMG_PATH => 'img/', - WEB_CSS_PATH => 'web/css/', - WEB_PLUGIN_PATH => 'plugin/', - WEB_ARCHIVE_PATH => 'archive/', - WEB_LIBRARY_PATH => 'inc/lib/', - WEB_AJAX_PATH => 'inc/ajax/' - ); + $paths[$root_web][WEB_CSS_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_CSS_PATH]; + $paths[$root_web][WEB_IMG_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_IMG_PATH]; + $paths[$root_web][WEB_LIBRARY_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_LIBRARY_PATH]; + $paths[$root_web][WEB_LIBRARY_JS_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_LIBRARY_JS_PATH]; - $root_web = api_add_trailing_slash($root_web); - // Web server base and system server base. - $server_base_web = preg_replace('@'.$root_rel.'$@', '', $root_web); // No trailing slash. + $paths[$root_web][WEB_AJAX_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_AJAX_PATH]; + $paths[$root_web][WEB_FONTS_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_FONTS_PATH]; - // Redefine root webs - $paths[WEB_PATH] = $root_web; - $paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/'; - $paths[WEB_COURSE_PATH] = $root_web.$course_folder; - $paths[WEB_CODE_PATH] = $root_web.$code_folder; - $paths[WEB_IMG_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_IMG_PATH]; + //$paths[$root_web][WEB_PLUGIN_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_PLUGIN_PATH]; + //$paths[$root_web][WEB_ARCHIVE_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_ARCHIVE_PATH]; - $paths[WEB_CSS_PATH] = $paths[WEB_PATH].$web_paths[WEB_CSS_PATH]; - $paths[WEB_PLUGIN_PATH] = $paths[WEB_PATH].$web_paths[WEB_PLUGIN_PATH]; - $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH].$web_paths[WEB_ARCHIVE_PATH]; - $paths[WEB_LIBRARY_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_LIBRARY_PATH]; - $paths[WEB_AJAX_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_AJAX_PATH]; - $paths[WEB_FONTS_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_FONTS_PATH]; - } + $paths[$root_web][WEB_TEMPLATE_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_TEMPLATE_PATH]; + $paths[$root_web][WEB_UPLOAD_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_UPLOAD_PATH]; + $paths[$root_web][WEB_PUBLIC_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_PUBLIC_PATH]; + + + /*// ADD : Take VChamilo into account + global $VCHAMILO; + if (!empty($VCHAMILO) || !empty($configuration['virtual'])) { + $paths[$root_web][WEB_ARCHIVE_PATH] .= $web_host.'/'; + $paths[$root_web][WEB_HOME_PATH] .= $web_host.'/'; + }*/ + + // /ADD + $paths[$root_web][WEB_TEMPLATE_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_TEMPLATE_PATH]; + $paths[$root_web][INCLUDE_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][INCLUDE_PATH]; + $paths[$root_web][LIBRARY_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][REL_CODE_PATH].$paths[$root_web][LIBRARY_PATH]; + $paths[$root_web][CONFIGURATION_PATH] = $paths[$root_web][SYS_PATH].$paths[$root_web][CONFIGURATION_PATH]; + $paths[$root_web][WEB_HOME_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_HOME_PATH]; + + $isInitialized[$root_web] = true; } // Shallow purification and validation of input parameters. - $path_type = trim($path_type); $path = trim($path); @@ -900,20 +958,21 @@ function api_get_path($path_type, $path = null) } // Retrieving a common-purpose path. - if (isset($paths[$path_type])) { - return $paths[$path_type]; + if (isset($paths[$root_web][$path_type])) { + if ($catcher) echo "common $path_type $root_web "; + return $paths[$root_web][$path_type]; } // Retrieving a specific resource path. - if (isset($resource_paths[$path])) { + if (isset($resourcePaths[$root_web][$path])) { switch ($path_type) { case TO_WEB: - return $paths[WEB_CODE_PATH].$resource_paths[$path]; + return $paths[$root_web][WEB_CODE_PATH].$resourcePaths[$root_web][$path]; case TO_SYS: - return $paths[SYS_CODE_PATH].$resource_paths[$path]; + return $paths[$root_web][SYS_CODE_PATH].$resourcePaths[$root_web][$path]; case TO_REL: - return $paths[REL_CODE_PATH].$resource_paths[$path]; + return $paths[$root_web][REL_CODE_PATH].$resourcePaths[$root_web][$path]; default: return null; } @@ -921,8 +980,11 @@ function api_get_path($path_type, $path = null) // Common-purpose paths as a second parameter - recognition. - if (isset($paths[$path])) { - $path = $paths[$path]; + if (isset($paths[$root_web][$path])) { + if ($catcher) { + echo "straight "; + } + $path = $paths[$root_web][$path]; } // Second purification. @@ -938,7 +1000,6 @@ function api_get_path($path_type, $path = null) // Detection of the input path type. Conversion to semi-absolute type ( /chamilo/main/inc/.... ). if (preg_match(VALID_WEB_PATH, $path)) { - // A special case: When a URL points to the document download script directly, without // mod-rewrite translation, we have to translate it into an "ordinary" web path. // For example: @@ -958,7 +1019,6 @@ function api_get_path($path_type, $path = null) } // Replacement of the present web server base with a slash '/'. $path = preg_replace(VALID_WEB_SERVER_BASE, '/', $path); - } elseif (strpos($path, $server_base_sys) === 0) { $path = preg_replace('@^'.$server_base_sys.'@', '', $path); } elseif (strpos($path, '/') === 0) { @@ -985,6 +1045,7 @@ function api_get_path($path_type, $path = null) return null; } + /** * Gets a modified version of the path for the CDN, if defined in * configuration.php @@ -6656,19 +6717,22 @@ function api_get_unique_id() { */ function api_get_home_path() { - $home = 'app/home/'; + // FIX : Start the routing determination from central path definition + $home = api_get_path(TO_SYS, SYS_HOME_PATH); if (api_get_multiple_access_url()) { $access_url_id = api_get_current_access_url_id(); - $url_info = api_get_access_url($access_url_id); - $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); - $clean_url = api_replace_dangerous_char($url); - $clean_url = str_replace('/', '-', $clean_url); - $clean_url .= '/'; - - $home = 'app/home/' . $clean_url; + $url_info = api_get_access_url($access_url_id); + $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); + $clean_url = replace_dangerous_char($url); + $clean_url = str_replace('/', '-', $clean_url); + $clean_url .= '/'; + if ($clean_url != 'localhost/') { + // means that the multiple URL was not well configured we don't rename the $home variable + return "{$home}{$clean_url}"; + } } - return $home; + // /FIX } /** diff --git a/main/inc/lib/course_home.lib.php b/main/inc/lib/course_home.lib.php index 8496c9bcbd..9a08fc8011 100755 --- a/main/inc/lib/course_home.lib.php +++ b/main/inc/lib/course_home.lib.php @@ -1094,15 +1094,14 @@ class CourseHome $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST); /* Link to the Course homepage */ - $navigation_items['home']['image'] = 'home.gif'; $navigation_items['home']['link'] = api_get_path(WEB_CODE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php'; $navigation_items['home']['name'] = get_lang('CourseHomepageLink'); - $sql_menu_query = "SELECT * FROM $course_tools_table - WHERE c_id = $course_id AND visibility='1' and admin='0' - ORDER BY id ASC"; - $sql_result = Database::query($sql_menu_query); + $sql = "SELECT * FROM $course_tools_table + WHERE c_id = $course_id AND visibility='1' and admin='0' + ORDER BY id ASC"; + $sql_result = Database::query($sql); while ($row = Database::fetch_array($sql_result)) { $navigation_items[$row['id']] = $row; if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) { @@ -1116,9 +1115,9 @@ class CourseHome - Course rights (roles & rights overview) */ if ($include_admin_tools) { - $course_settings_sql = "SELECT name,image FROM $course_tools_table - WHERE c_id = $course_id AND link='course_info/infocours.php'"; - $sql_result = Database::query($course_settings_sql); + $sql = "SELECT name, image FROM $course_tools_table + WHERE c_id = $course_id AND link='course_info/infocours.php'"; + $sql_result = Database::query($sql); $course_setting_info = Database::fetch_array($sql_result); $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info); if (api_get_session_id() == 0) { diff --git a/main/inc/lib/glossary.lib.php b/main/inc/lib/glossary.lib.php index 2ea1c75c1b..6aa6e6b884 100755 --- a/main/inc/lib/glossary.lib.php +++ b/main/inc/lib/glossary.lib.php @@ -37,6 +37,7 @@ class GlossaryManager * Get glossary term by glossary id * @author Isaac Flores * @param int $glossary_id + * * @return string The glossary description */ public static function get_glossary_term_by_glossary_id ($glossary_id) @@ -45,7 +46,7 @@ class GlossaryManager $course_id = api_get_course_int_id(); $sql = "SELECT description FROM $glossary_table WHERE c_id = $course_id AND glossary_id =".intval($glossary_id); - $rs=Database::query($sql); + $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { $row = Database::fetch_array($rs); diff --git a/main/inc/lib/online.inc.php b/main/inc/lib/online.inc.php index 6833bfc928..c233c0792c 100755 --- a/main/inc/lib/online.inc.php +++ b/main/inc/lib/online.inc.php @@ -10,6 +10,8 @@ * @package chamilo.whoisonline */ +use ChamiloSession as Session; + /** * Insert a login reference for the current user into the track_e_online stats table. * This table keeps trace of the last login. Nothing else matters (we don't keep traces of anything older) @@ -17,8 +19,6 @@ * @return void */ -use ChamiloSession as Session; - function LoginCheck($uid) { $_course = api_get_course_info(); @@ -154,7 +154,7 @@ function online_logout($user_id = null, $logout_redirect = false) session_regenerate_id(); Session::destroy(); if ($logout_redirect) { - header("Location: index.php"); + header("Location: ".api_get_path(WEB_PATH)."index.php"); return; } } @@ -397,11 +397,11 @@ function who_is_online_in_this_course($from, $number_of_items, $uid, $time_limit $time_limit = intval($time_limit); } - $online_time = time() - $time_limit*60; - $current_date = api_get_utc_datetime($online_time); + $online_time = time() - $time_limit * 60; + $current_date = api_get_utc_datetime($online_time); $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); - $course_code = Database::escape_string($course_code); - $courseInfo = api_get_course_info($course_code); + $course_code = Database::escape_string($course_code); + $courseInfo = api_get_course_info($course_code); $courseId = $courseInfo['real_id']; $from = intval($from); diff --git a/main/inc/lib/pdf.lib.php b/main/inc/lib/pdf.lib.php index 82f760885e..9dca5d2a2b 100755 --- a/main/inc/lib/pdf.lib.php +++ b/main/inc/lib/pdf.lib.php @@ -452,8 +452,7 @@ class PDF if (strpos($old_src, 'http') === false) { if (strpos($old_src, '/main/default_course_document') === false) { if (strpos($old_src, '/main/inc/lib/') === false) { - - $old_src_fixed = str_replace('/courses/'.$course_data['path'].'/document/', '', $old_src); + $old_src_fixed = str_replace(api_get_path(REL_COURSE_PATH).$course_data['path'].'/document/', '', $old_src); $old_src_fixed = str_replace('courses/'.$course_data['path'].'/document/', '', $old_src_fixed); $new_path = $document_path.$old_src_fixed; $document_html= str_replace($old_src, $new_path, $document_html); diff --git a/main/inc/lib/system_announcements.lib.php b/main/inc/lib/system_announcements.lib.php index 3399bb1454..a887073693 100755 --- a/main/inc/lib/system_announcements.lib.php +++ b/main/inc/lib/system_announcements.lib.php @@ -356,10 +356,13 @@ class SystemAnnouncementManager $end = api_get_utc_datetime($date_end); //Fixing urls that are sent by email - $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); - $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); + //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); + //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); + $content = str_replace('src=\"'.api_get_path(REL_HOME_PATH), 'src=\"'.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); + $content = str_replace('file='.api_get_path(REL_HOME_PATH), 'file='.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); - $lang = is_null($lang) ? '' : $lang; + + $lang = is_null($lang) ? '' : $lang; $current_access_url_id = 1; if (api_is_multiple_url_enabled()) { @@ -541,8 +544,10 @@ class SystemAnnouncementManager $end = api_get_utc_datetime($date_end); //Fixing urls that are sent by email - $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); - $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); + //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); + //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); + $content = str_replace('src=\"'.api_get_path(REL_HOME_PATH), 'src=\"'.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); + $content = str_replace('file='.api_get_path(REL_HOME_PATH), 'file='.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); $id = intval($id); diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 14b7638114..52a3d3db9f 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -155,7 +155,7 @@ class Template //Setting administrator variables $this->setAdministratorParams(); - + $this->setCSSEditor(); //header and footer are showed by default @@ -573,7 +573,7 @@ class Template if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/editor.css')) { $cssEditor = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/editor.css'; } - + $this->assign('cssEditor', $cssEditor); } /** @@ -585,7 +585,7 @@ class Template { global $disable_js_and_css_files; // Base CSS - + $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css'); if ($this->show_learnpath) { @@ -594,15 +594,15 @@ class Template $css[] = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/learnpath.css'; } } - + if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/editor.css')) { $css[] = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/editor.css'; }else{ $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'editor.css'); } - + $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/default.css'); - + $css_file_to_string = null; foreach ($css as $file) { $css_file_to_string .= api_get_css($file); @@ -856,8 +856,7 @@ class Template //If exist pick the current chamilo theme favicon if (is_file($favicoThemeUrl . 'favicon.ico')) { - $favico = ''; + $favico = ''; } if (api_is_multiple_url_enabled()) { @@ -1120,7 +1119,7 @@ class Template $tpl = $this->get_template('layout/show_footer.tpl'); $this->display($tpl); } - + /** * Show footer js template. */ diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 93b2294b63..9acc998d5a 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -333,8 +333,6 @@ class UserManager /** @var User $user */ $user = $userManager->createUser(); - $em = Database::getManager(); - /** @var User $user */ //$user = new User(); $user @@ -363,8 +361,6 @@ class UserManager $userManager->updateUser($user); $userId = $user->getId(); - error_log($userId); - if (!empty($userId)) { $return = $userId; $sql = "UPDATE $table_user SET user_id = $return WHERE id = $return"; @@ -1445,6 +1441,7 @@ class UserManager // In exceptional cases, on some portals, the intermediate base user // directory might not have been created. Make sure it is before // going further. + $rootPath = api_get_path(SYS_UPLOAD_PATH) . 'users/' . substr((string) $id, 0, 1); if (!is_dir($rootPath)) { $perm = api_get_permissions_for_new_directories(); diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index e28c698848..1adff25a60 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -26,6 +26,21 @@ class IndexManager $this->user_id = api_get_user_id(); $this->load_directories_preview = false; + // Load footer plugins systematically + /*$config = api_get_settings_params(array('subkey = ? ' => 'customfooter', ' AND category = ? ' => 'Plugins')); + if (!empty($config)) { + foreach ($config as $fooid => $configrecord) { + $canonic = preg_replace('/^customfooter_/', '', $configrecord['variable']); + $footerconfig->$canonic = $configrecord['selected_value']; + } + if (!empty($footerconfig->footer_left)) { + $this->tpl->assign('plugin_footer_left', $footerconfig->footer_left); + } + if (!empty($footerconfig->footer_right)) { + $this->tpl->assign('plugin_footer_right', $footerconfig->footer_right); + } + }*/ + if (api_get_setting('show_documents_preview') == 'true') { $this->load_directories_preview = true; } diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 56ec7d8ccb..6d9fc7ac90 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -363,7 +363,6 @@ function write_system_config_file($path) foreach ($config as $key => $value) { $content = str_replace($key, $value, $content); } - $fp = @ fopen($path, 'w'); if (!$fp) { @@ -2280,8 +2279,7 @@ function fixIds(EntityManager $em) if (isset($data['iid'])) { $newId = $data['iid']; } - $sql = "UPDATE c_item_property SET ref = $newId WHERE iid = $iid"; - error_log($sql); + $sql = "UPDATE c_item_property SET ref = $newId WHERE iid = $iid"; $connection->executeQuery($sql); } diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 352fbf8e72..7cfa2c68d2 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -6229,7 +6229,7 @@ class learnpath $file = $filepath . $row['path']; if ($fp = @ fopen($file, 'w')) { - $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content); + $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].api_get_path(REL_COURSE_PATH), $content); // Change the path of mp3 to absolute. // The first regexp deals with :// urls. @@ -8325,11 +8325,11 @@ class learnpath '; $audio_player .= ''; $audio_player .= ''; + var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF"); + s1.addParam("allowscriptaccess","always"); + s1.addParam("flashvars","file=../..'.api_get_path(REL_COURSE_PATH).$_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true"); + s1.write("container"); + '; } $url = api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id; @@ -9798,8 +9798,8 @@ class learnpath } $string = str_replace($old_new['orig'], $newDestination, $string); - //Add files inside the HTMLs - $new_path = str_replace('/courses/', '', $old_new['orig']); + // Add files inside the HTMLs + $new_path = str_replace(api_get_path(REL_COURSE_PATH), '', $old_new['orig']); $destinationFile = $archive_path.$temp_dir_short.'/'.$old_new['dest']; if (file_exists($sys_course_path.$new_path)) { copy($sys_course_path.$new_path, $destinationFile); diff --git a/main/newscorm/lp_list.php b/main/newscorm/lp_list.php index d0f8b56b16..b2f371e3da 100755 --- a/main/newscorm/lp_list.php +++ b/main/newscorm/lp_list.php @@ -57,7 +57,7 @@ $introductionSection = Display::return_introduction_section( TOOL_LEARNPATH, array( 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/', - 'CreateDocumentDir' => '../../courses/'.api_get_course_path().'/document/', + 'CreateDocumentDir' => '../..'.api_get_path(REL_COURSE_PATH).api_get_course_path().'/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/', ) ); diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index 535555c890..e7baf570f9 100755 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -2057,7 +2057,7 @@ function attach_glossary_into_scorm(type) { my_protocol = location.protocol; my_pathname=location.pathname; - work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/')); + work_path = my_pathname.substr(0,my_pathname.indexOf('')); var ajaxRequestUrl = ''; if (type == 'automatic') { diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index ea8bc3500c..de1d2d56d2 100755 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -1972,9 +1972,9 @@ class Wiki $wikiContents = str_replace('{CONTENT}', $wikiContents, $template); // replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents - if (api_strpos($wikiContents,'../../courses/') !== false) { + if (api_strpos($wikiContents,'../..'.api_get_path(REL_COURSE_PATH)) !== false) { $web_course_path = api_get_path(WEB_COURSE_PATH); - $wikiContents = str_replace('../../courses/',$web_course_path,$wikiContents); + $wikiContents = str_replace('../..'.api_get_path(REL_COURSE_PATH), $web_course_path, $wikiContents); } $i = 1; diff --git a/src/Chamilo/UserBundle/Entity/User.php b/src/Chamilo/UserBundle/Entity/User.php index e7b5d735fc..d3d6fb0348 100644 --- a/src/Chamilo/UserBundle/Entity/User.php +++ b/src/Chamilo/UserBundle/Entity/User.php @@ -2102,7 +2102,9 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser public function getPlainPassword() { - //return $this->plainPassword; + if (isset($this->plainPassword)) { + return $this->plainPassword; + } } /**