diff --git a/main/admin/settings.php b/main/admin/settings.php index 48cf3b0f12..44f160bf5c 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -212,9 +212,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', ' if ($pdf_export_watermark_path_result) { $message['confirmation'][] = get_lang('UplUploadSucceeded'); } else { - $message['warning'][] = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path( - SYS_CODE_PATH - ).'default_course_document/images'; + $message['warning'][] = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH).'/images'; } unset($update_values['pdf_export_watermark_path']); } diff --git a/main/document/document.php b/main/document/document.php index 7ad89a2f2b..fee0bc2654 100644 --- a/main/document/document.php +++ b/main/document/document.php @@ -29,9 +29,7 @@ /** * Code */ -// Language files that need to be included -$language_file = array('document', 'slideshow', 'gradebook', 'create_course'); -require_once '../inc/global.inc.php'; + $parent_id = null; $current_course_tool = TOOL_DOCUMENT; $this_section = SECTION_COURSES; @@ -349,7 +347,7 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isse $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery'; $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html); - $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document'; + $path_image_in_default_course = api_get_path(WEB_DEFAULT_COURSE_DOCUMENT_PATH); $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html); $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html); diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 1346c3356a..6de33cc28a 100644 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -87,7 +87,8 @@ $app['root_sys'] = isset($_configuration['root_sys']) ? $_configuration['root_sy $app['sys_root'] = $app['root_sys']; $app['sys_data_path'] = isset($_configuration['sys_data_path']) ? $_configuration['sys_data_path'] : $app['root_sys'].'data/'; $app['sys_config_path'] = isset($_configuration['sys_config_path']) ? $_configuration['sys_config_path'] : $app['root_sys'].'config/'; -$app['sys_temp_path'] = isset($_configuration['sys_temp_path']) ? $_configuration['sys_temp_path'] : $app['root_sys'].'temp/'; +$app['sys_course_path'] = isset($_configuration['sys_course_path']) ? $_configuration['sys_course_path'] : $app['sys_data_path'].'/courses/'; +$app['sys_temp_path'] = isset($_configuration['sys_temp_path']) ? $_configuration['sys_temp_path'] : $app['sys_data_path'].'temp/'; $app['sys_log_path'] = isset($_configuration['sys_log_path']) ? $_configuration['sys_log_path'] : $app['root_sys'].'logs/'; /** Loading config files (mail, auth, profile) */ @@ -492,17 +493,25 @@ $app->before( // Checking configuration file if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) { return new RedirectResponse(api_get_path(WEB_CODE_PATH).'install'); - $app->abort(500, "Configuration file was not found"); + $app->abort(500, "Configuration file was not found."); } // Check the PHP version. if (api_check_php_version() == false) { - $app->abort(500, "Incorrect PHP version"); + $app->abort(500, "Incorrect PHP version."); } // Checks temp folder permissions. if (!is_writable(api_get_path(SYS_ARCHIVE_PATH))) { - $app->abort(500, "temp folder must be writable"); + $app->abort(500, "temp folder must be writable."); + } + + if (!isset($app['configuration'])) { + $app->abort(500, '$configuration array must be set in the configuration.php file.'); + } + + if (!isset($app['configuration']['root_web'])) { + $app->abort(500, '$configuration[root_web] must be set in the configuration.php file.'); } /** @var Request $request */ diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index cd3c728ba0..19af759c9b 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -266,6 +266,9 @@ define('WEB_DATA_COURSE_PATH', 'WEB_DATA_COURSE_PATH'); define('WEB_DATA_PATH', 'WEB_DATA_PATH'); define('REL_DATA_PATH', 'REL_DATA_PATH'); +define('SYS_DEFAULT_COURSE_DOCUMENT_PATH', 'SYS_DEFAULT_COURSE_DOCUMENT_PATH'); +define('WEB_DEFAULT_COURSE_DOCUMENT_PATH', 'WEB_DEFAULT_COURSE_DOCUMENT_PATH'); + // Constants for requesting path conversion. define('TO_WEB', 'TO_WEB'); define('TO_SYS', 'TO_SYS'); @@ -523,31 +526,19 @@ function api_get_path($path_type, $path = null) { global $app; static $paths = array( - WEB_PATH => '', - SYS_PATH => '', SYS_DATA_PATH => 'data/', SYS_WEB_PATH => 'web/', SYS_CONFIG_PATH => 'config/', SYS_LOG_PATH => 'logs/', - REL_PATH => '', - WEB_SERVER_ROOT_PATH => '', - SYS_SERVER_ROOT_PATH => '', - WEB_COURSE_PATH => '', WEB_DATA_COURSE_PATH => 'courses/', WEB_DATA_PATH => '/', SYS_COURSE_PATH => 'data/', - REL_COURSE_PATH => '', - REL_CODE_PATH => '', - REL_DATA_PATH => '', - WEB_CODE_PATH => '', - SYS_CODE_PATH => '', SYS_CSS_PATH => 'css/', SYS_LANG_PATH => 'lang/', WEB_IMG_PATH => 'img/', WEB_CSS_PATH => 'css/', SYS_PLUGIN_PATH => 'plugin/', WEB_PLUGIN_PATH => 'plugin/', - SYS_ARCHIVE_PATH => 'temp/', WEB_ARCHIVE_PATH => 'temp/', INCLUDE_PATH => 'inc/', LIBRARY_PATH => 'inc/lib/', @@ -576,11 +567,11 @@ function api_get_path($path_type, $path = null) { static $code_folder; static $course_folder; - // Always load root_web modifications for multiple url features + // Always load root_web modifications for multiple url features. global $_configuration; - //default $_configuration['root_web'] configuration - $root_web = isset($_configuration['root_web']) ? $_configuration['root_web'] : null; + // Default $_configuration['root_web'] configuration + $root_web = $_configuration['root_web']; // Configuration data for already installed system. $root_sys = isset($_configuration['root_sys']) ? $_configuration['root_sys'] : $app['root_sys']; @@ -597,71 +588,39 @@ function api_get_path($path_type, $path = null) { } } + if (!$is_this_function_initialized) { - $root_rel = $_configuration['url_append']; + $root_rel = $_configuration['url_append']; $code_folder = 'main/'; //$course_folder = isset($_configuration['course_folder']) ? $_configuration['course_folder'] : null; $course_folder = "courses/"; - // 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. - - //if (defined('SYSTEM_INSTALLATION') && SYSTEM_INSTALLATION) - - if (empty($root_web)) { - - //$pos = strpos(($requested_page_rel = api_get_self()), 'index.php'); - $pos = strpos(($requested_page_rel = api_get_self()), 'web/index'); - $pos_install = strpos(($requested_page_rel = api_get_self()), 'main/install'); - - if ($pos_install) { - $pos = $pos_install; - } - //if (() !== false) { - $root_rel = substr($requested_page_rel, 0, $pos); - // See http://www.mediawiki.org/wiki/Manual:$wgServer - $server_protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http'; - $server_name = - isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] - : (isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME'] - : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] - : (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] - : 'localhost'))); - if (isset($_SERVER['SERVER_PORT']) && !strpos($server_name, ':') - && (($server_protocol == 'http' - && $_SERVER['SERVER_PORT'] != 80 ) || ($server_protocol == 'https' && $_SERVER['SERVER_PORT'] != 443 ))) { - $server_name .= ":" . $_SERVER['SERVER_PORT']; - } - $root_web = $server_protocol.'://'.$server_name.$root_rel; - $root_sys = str_replace('\\', '/', realpath(dirname(__FILE__).'/../../../')).'/'; - //} - // 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); // 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. - // Initialization of a table taht contains common-purpose paths. + // Initialization of a table that contains common-purpose paths. $paths[WEB_PATH] = $root_web; $paths[WEB_PUBLIC_PATH] = $root_web.'web/'; $paths[SYS_PATH] = $root_sys; - //update data path to get it from config file if defined - $paths[SYS_DATA_PATH] = $root_sys.'data/'; + // Update data path to get it from config file if defined + $paths[SYS_DATA_PATH] = $app['sys_data_path']; + $paths[SYS_LOG_PATH] = $app['sys_log_path']; + $paths[SYS_CONFIG_PATH] = $app['sys_config_path']; + $paths[SYS_COURSE_PATH] = $app['sys_course_path']; + + $paths[SYS_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[SYS_DATA_PATH].'default_course_document/'; + $paths[SYS_WEB_PATH] = $root_sys.'web/'; - $paths[SYS_LOG_PATH] = $root_sys.'logs/'; - $paths[SYS_CONFIG_PATH] = $root_sys.'config/'; $paths[REL_PATH] = $root_rel; $paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/'; @@ -671,7 +630,8 @@ function api_get_path($path_type, $path = null) { $paths[WEB_COURSE_PATH] = $root_web.$course_folder; $paths[WEB_DATA_COURSE_PATH] = $paths[WEB_DATA_PATH].$course_folder; - $paths[SYS_COURSE_PATH] = $paths[SYS_DATA_PATH].$course_folder; + $paths[WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[WEB_DATA_PATH].'default_course_document/'; + $paths[REL_COURSE_PATH] = $root_rel.$course_folder; $paths[REL_CODE_PATH] = $root_rel.$code_folder; $paths[WEB_CODE_PATH] = $root_web.$code_folder; @@ -682,7 +642,7 @@ function api_get_path($path_type, $path = null) { // Now we can switch into api_get_path() "terminology". $paths[SYS_LANG_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_LANG_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_ARCHIVE_PATH] = $app['sys_temp_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_CSS_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_CSS_PATH]; @@ -690,7 +650,7 @@ function api_get_path($path_type, $path = null) { $paths[WEB_CSS_PATH] = $paths[WEB_CODE_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_AJAX_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_AJAX_PATH]; + $paths[WEB_AJAX_PATH] = $paths[WEB_PUBLIC_PATH].'main/'.$paths[WEB_AJAX_PATH]; $paths[WEB_PLUGIN_PATH] = $paths[WEB_PATH].$paths[WEB_PLUGIN_PATH]; @@ -809,6 +769,7 @@ function api_get_path($path_type, $path = null) { $path = $matches[1].'courses/'.$sys_course_code.'/document/'.str_replace('//', '/', $matches[3].'/'.$matches[2]); } } + // Replacement of the present web server base with a slash '/'. $path = preg_replace(VALID_WEB_SERVER_BASE, '/', $path); @@ -816,7 +777,7 @@ function api_get_path($path_type, $path = null) { $path = preg_replace('@^'.$server_base_sys.'@', '', $path); } elseif (strpos($path, '/') === 0) { // Leading slash - we assume that this path is semi-absolute (REL), - // then path is left without furthes modifications. + // then path is left without further modifications. } else { return null; // Probably implementation of this case won't be needed. } @@ -6904,21 +6865,9 @@ function api_get_language_interface() $language_interface = api_get_setting('platformLanguage'); } } - return $language_interface; } -function api_get_default_course_document() -{ - return api_get_path(SYS_PATH).'app/data/default_course_document/'; -} - -function api_get_web_default_course_document() -{ - return api_get_path(WEB_PATH).'app/data/default_course_document/'; -} - - /** * Get user roles * @return array diff --git a/main/inc/lib/pdf.lib.php b/main/inc/lib/pdf.lib.php index c623ff5270..4410ceb5ce 100644 --- a/main/inc/lib/pdf.lib.php +++ b/main/inc/lib/pdf.lib.php @@ -381,9 +381,9 @@ class PDF $web_path = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/' . api_get_current_access_url_id() . '_pdf_watermark.png'; } } else { - $store_path = api_get_path(SYS_CODE_PATH) . 'default_course_document/images/' . api_get_current_access_url_id() . '_pdf_watermark.png'; // course path + $store_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH).'images/' . api_get_current_access_url_id() . '_pdf_watermark.png'; // course path if (file_exists($store_path)) - $web_path = api_get_path(WEB_CODE_PATH) . 'default_course_document/images/' . api_get_current_access_url_id() . '_pdf_watermark.png'; + $web_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH).'images/' . api_get_current_access_url_id() . '_pdf_watermark.png'; } return $web_path; } @@ -400,7 +400,7 @@ class PDF $course_info = api_get_course_info($course_code); $store_path = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/' . api_get_current_access_url_id() . '_pdf_watermark.png'; // course path } else { - $store_path = api_get_path(SYS_CODE_PATH) . 'default_course_document/' . api_get_current_access_url_id() . '_pdf_watermark.png'; // course path + $store_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH).'default_course_document/'.api_get_current_access_url_id().'_pdf_watermark.png'; // course path } if (file_exists($store_path)) { @unlink($store_path); @@ -423,8 +423,8 @@ class PDF $store_path = api_get_path(SYS_COURSE_PATH) . $course_info['path']; // course path $web_path = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/pdf_watermark.png'; } else { - $store_path = api_get_path(SYS_CODE_PATH) . 'default_course_document/images'; // course path - $web_path = api_get_path(WEB_CODE_PATH) . 'default_course_document/images/' . api_get_current_access_url_id() . '_pdf_watermark.png'; + $store_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH).'images'; // course path + $web_path = api_get_path(WEB_DEFAULT_COURSE_DOCUMENT_PATH).'images/' . api_get_current_access_url_id() . '_pdf_watermark.png'; } $course_image = $store_path . '/' . api_get_current_access_url_id() . '_pdf_watermark.png'; $extension = strtolower(substr(strrchr($filename, '.'), 1)); diff --git a/main/inc/routes.php b/main/inc/routes.php index 5fb72e9ad3..8b65ea18bd 100644 --- a/main/inc/routes.php +++ b/main/inc/routes.php @@ -520,6 +520,11 @@ $app->get('/data/default_platform_document/{file}', 'index.controller:getDefault ->assert('file', '.+') ->assert('type', '.+'); +/** Data default_platform_document files */ +$app->get('/data/default_course_document/{file}', 'index.controller:getDefaultCourseDocumentAction') + ->assert('file', '.+') + ->assert('type', '.+'); + /** User files */ $app->match('/data/upload/users/{file}', 'index.controller:getUserFile', 'GET|POST') ->assert('file', '.+'); diff --git a/src/ChamiloLMS/Controller/IndexController.php b/src/ChamiloLMS/Controller/IndexController.php index 46ea1988df..4a82a8c339 100644 --- a/src/ChamiloLMS/Controller/IndexController.php +++ b/src/ChamiloLMS/Controller/IndexController.php @@ -412,6 +412,22 @@ class IndexController extends CommonController } } + /** + * Gets a document from the data/default_platform_document/* folder + * @param Application $app + * @param string $file + * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void + */ + public function getDefaultCourseDocumentAction(Application $app, $file) + { + try { + $file = $app['chamilo.filesystem']->get('default_course_document/'.$file); + return $app->sendFile($file->getPathname()); + } catch (\InvalidArgumentException $e) { + return $app->abort(404, 'File not found'); + } + } + /** * @param Application $app * @param $groupId