/** * This function returns the value of a parameter from the configuration file * * WARNING - this function relies heavily on global variables $updateFromConfigFile * and $configFile, and also changes these globals. This can be rewritten. * * @param string $param the parameter of which the value is returned * @param string If we want to give the path rather than take it from POST * @return string the value of the parameter * @author Olivier Brouckaert * @author Reworked by Ivan Tcholakov, 2010 */ function get_config_param($param, $updatePath = '') { global $configFile, $updateFromConfigFile; // Look if we already have the queried parameter. if (is_array($configFile) && isset($configFile[$param])) { return $configFile[$param]; } if (empty($updatePath) && !empty($_POST['updatePath'])) { $updatePath = $_POST['updatePath']; } if (empty($updatePath)) { $updatePath = api_get_path(SYS_PATH); } $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath))); $updateFromInstalledVersionFile = ''; if (empty($updateFromConfigFile)) { // If update from previous install was requested, // try to recover config file from Chamilo 1.9.x if (file_exists($updatePath . 'main/inc/conf/configuration.php')) { $updateFromConfigFile = 'main/inc/conf/configuration.php'; } else { // Give up recovering. //error_log('Chamilo Notice: Could not find previous config file at '.$updatePath.'main/inc/conf/configuration.php nor at '.$updatePath.'claroline/inc/conf/claro_main.conf.php in get_config_param(). Will start new config (in '.__FILE__.', line '.__LINE__.')', 0); return null; } } if (file_exists($updatePath . $updateFromConfigFile) && !is_dir($updatePath . $updateFromConfigFile)) { require $updatePath . $updateFromConfigFile; $config = new Zend\Config\Config($_configuration); return $config->get($param); } error_log('Config array could not be found in get_config_param()', 0); return null; /*if (file_exists($updatePath.$updateFromConfigFile)) { return $val; } else { error_log('Config array could not be found in get_config_param()', 0); return null; }*/ }
/** * Returns a path to a certain resource within the Chamilo area, specifyed through a parameter. * Also, this function provides conversion between path types, in this case the input path points inside the Chamilo area too. * * See $_configuration['course_folder'] in the configuration.php to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters. * @param string $type The requested path type (a defined constant), see the examples. * @param string $path (optional) A path which type is to be converted. Also, it may be a defined constant for a path. * This parameter has meaning when $type parameter has one of the following values: TO_WEB, TO_SYS, TO_REL. Otherwise it is ignored. * @return string The requested path or the converted path. * * A terminology note: * The defined constants used by this function contain the abbreviations WEB, REL, SYS with the following meaning for types: * WEB - an absolute URL (we often call it web-path), * example: http://www.mychamilo.org/chamilo/courses/COURSE01/document/lesson01.html; * * REL - represents a semi-absolute URL - a web-path, which is relative to the root web-path of the server, without server's base, * example: /chamilo/courses/COURSE01/document/lesson01.html; * * SYS - represents an absolute path inside the scope of server's file system, * /var/www/chamilo/courses/COURSE01/document/lesson01.html or * C:/Inetpub/wwwroot/chamilo/courses/COURSE01/document/lesson01.html. * * In some abstract sense we can consider these three path types as absolute. * * Notes about the current behaviour model: * 1. Windows back-slashes are converted to slashes in the result. * 2. A semi-absolute web-path is detected by its leading slash. On Linux systems, absolute system paths start with * a slash too, so an additional check about presence of leading system server base is implemented. For example, the function is * able to distinguish type difference between /var/www/chamilo/courses/ (SYS) and /chamilo/courses/ (REL). * 3. The function api_get_path() returns only these three types of paths, which in some sense are absolute. The function has * no a mechanism for processing relative web/system paths, such as: lesson01.html, ./lesson01.html, ../css/my_styles.css. * It has not been identified as needed yet. * 4. Also, resolving the meta-symbols "." and ".." within paths has not been implemented, it is to be identified as needed. * * Example: * Assume that your server root is /var/www/ , * Chamilo is installed in a sub folder chamilo/ and the URL of your campus is http://www.mychamilo.org * The other configuration parameters have not been changed. * * This is how we can get most used paths, for common purpose: * api_get_path(REL_PATH) /chamilo/ * api_get_path(REL_COURSE_PATH) /chamilo/courses/ * api_get_path(REL_CODE_PATH) /chamilo/main/ * api_get_path(REL_UPLOAD_PATH) /chamilo/app/upload/ * api_get_path(SYS_SERVER_ROOT_PATH) /var/www/ - This is the physical folder where the system Chamilo has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT']. * api_get_path(SYS_PATH) /var/www/chamilo/ * api_get_path(SYS_APP_PATH) /var/www/chamilo/app/ * api_get_path(SYS_UPLOAD_PATH) /var/www/chamilo/app/upload/ * api_get_path(SYS_ARCHIVE_PATH) /var/www/chamilo/app/cache * api_get_path(SYS_COURSE_PATH) /var/www/chamilo/app/courses/ * api_get_path(SYS_CSS_PATH) /var/www/chamilo/app/Resources/public/css * api_get_path(SYS_CODE_PATH) /var/www/chamilo/main/ * api_get_path(INCLUDE_PATH) /var/www/chamilo/main/inc/ * api_get_path(LIBRARY_PATH) /var/www/chamilo/main/inc/lib/ * api_get_path(CONFIGURATION_PATH) /var/www/chamilo/main/inc/conf/ * api_get_path(SYS_LANG_PATH) /var/www/chamilo/main/lang/ * api_get_path(SYS_PLUGIN_PATH) /var/www/chamilo/plugin/ * api_get_path(SYS_TEST_PATH) /var/www/chamilo/tests/ * api_get_path(SYS_TEMPLATE_PATH) /var/www/chamilo/main/template/ * api_get_path(SYS_PUBLIC_PATH) /var/www/chamilo/web/ * * api_get_path(WEB_SERVER_ROOT_PATH) http://www.mychamilo.org/ * api_get_path(WEB_PATH) http://www.mychamilo.org/chamilo/ * api_get_path(WEB_COURSE_PATH) http://www.mychamilo.org/chamilo/courses/ * api_get_path(WEB_CODE_PATH) http://www.mychamilo.org/chamilo/main/ * api_get_path(WEB_PLUGIN_PATH) http://www.mychamilo.org/chamilo/plugin/ * api_get_path(WEB_ARCHIVE_PATH) http://www.mychamilo.org/chamilo/app/cache/ * api_get_path(WEB_IMG_PATH) http://www.mychamilo.org/chamilo/web/bundles/chamilocore/img/ * api_get_path(SYS_IMG_PATH) /var/www/chamilo/web/bundles/chamilocore/img/ * api_get_path(WEB_CSS_PATH) http://www.mychamilo.org/chamilo/web/css/ * api_get_path(WEB_LIBRARY_PATH) http://www.mychamilo.org/chamilo/main/inc/lib/ * api_get_path(WEB_LIBRARY_JS_PATH) http://www.mychamilo.org/chamilo/web/bundles/chamilocore/js * api_get_path(WEB_TEMPLATE_PATH) http://www.mychamilo.org/chamilo/main/template/ * api_get_path(WEB_UPLOAD_PATH) http://www.mychamilo.org/chamilo/app/upload/ * api_get_path(WEB_PUBLIC_PATH) http://www.mychamilo.org/chamilo/web/ * * This is how we retrieve paths of "registered" resource files (scripts, players, etc.): * api_get_path(TO_WEB, FLASH_PLAYER_AUDIO) http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf * api_get_path(TO_WEB, FLASH_PLAYER_VIDEO) http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf * api_get_path(TO_SYS, SCRIPT_SWFOBJECT) /var/www/chamilo/main/inc/lib/swfobject/swfobject.js * api_get_path(TO_REL, SCRIPT_ASCIIMATHML) /chamilo/main/inc/lib/asciimath/ASCIIMathML.js * ... * * We can convert arbitrary paths, that are not registered (no defined constant). * For guaranteed result, these paths should point inside the system Chamilo. * Some random examples: * 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 => 'web/bundles/chamilocore/img/', SYS_IMG_PATH => 'web/bundles/chamilocore/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 => 'web/bundles/chamilocore/js/', 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_rel; $root_web = Container::getUrlGenerator()->generate('home', [], \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL); $rootDir = Container::getRootDir(); // Configuration data for already installed system. $root_sys = $rootDir; $code_folder = 'main/'; $course_folder = 'courses/'; // Configuration data for already installed system. $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_this_function_initialized) { $root_rel = Container::getUrlAppend(); // 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 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 . '/'; $paths[WEB_COURSE_PATH] = $root_web . $course_folder; $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]; $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/'; // Now we can switch into api_get_path() "terminology". $paths[SYS_LANG_PATH] = $paths[SYS_CODE_PATH] . $paths[SYS_LANG_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[SYS_PLUGIN_PATH] = $paths[SYS_PATH] . $paths[SYS_PLUGIN_PATH]; $paths[SYS_ARCHIVE_PATH] = Container::getTempDir(); $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]; $bundleWebPath = Container::getAsset()->getUrl('bundles/chamilocore/'); $paths[WEB_IMG_PATH] = $bundleWebPath . 'img/'; $paths[SYS_IMG_PATH] = $paths[SYS_PATH] . $paths[SYS_IMG_PATH]; $paths[WEB_LIBRARY_PATH] = $paths[WEB_CODE_PATH] . $paths[WEB_LIBRARY_PATH]; $paths[WEB_LIBRARY_JS_PATH] = $bundleWebPath . 'js/'; $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[WEB_PLUGIN_PATH] = $paths[WEB_PATH] . $paths[WEB_PLUGIN_PATH]; $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH] . $paths[WEB_ARCHIVE_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[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] = Container::getCourseDir(); $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/'); $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. // 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[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]; } } // Shallow purification and validation of input parameters. $path_type = trim($path_type); $path = trim($path); if (empty($path_type)) { return null; } // Retrieving a common-purpose path. if (isset($paths[$path_type])) { return $paths[$path_type]; } // Retrieving a specific resource path. if (isset($resource_paths[$path])) { switch ($path_type) { case TO_WEB: return $paths[WEB_CODE_PATH] . $resource_paths[$path]; case TO_SYS: return $paths[SYS_CODE_PATH] . $resource_paths[$path]; case TO_REL: return $paths[REL_CODE_PATH] . $resource_paths[$path]; default: return null; } } // Common-purpose paths as a second parameter - recognition. if (isset($paths[$path])) { $path = $paths[$path]; } // Second purification. // Replacing Windows back slashes. $path = str_replace('\\', '/', $path); // Query strings sometimes mighth wrongly appear in non-URLs. // Let us check remove them from all types of paths. if (($pos = strpos($path, '?')) !== false) { $path = substr($path, 0, $pos); } // Detection of the input path type. Conversion to semi-absolute type ( /chamilo/main/inc/.... ). $courseCode = api_get_course_id(); 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: // http://localhost/chamilo/main/document/download.php?doc_url=/image.png&cDir=/ // becomes // http://localhost/chamilo/courses/TEST/document/image.png // TEST is a course directory name, so called "system course code". if (strpos($path, 'download.php') !== false) { // Fast detection first. $path = urldecode($path); if (preg_match('/(.*)main\\/document\\/download.php\\?doc_url=\\/(.*)&cDir=\\/(.*)?/', $path, $matches)) { $sys_course_code = isset($courseCode) ? $courseCode : '{SYS_COURSE_CODE}'; // No, then use a fake code, it may be processed later. $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); } elseif (strpos($path, $server_base_sys) === 0) { $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. } else { return null; // Probably implementation of this case won't be needed. } // Path now is semi-absolute. It is convenient at this moment repeated slashes to be removed. $path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path); // Path conversion to the requested type. switch ($path_type) { case TO_WEB: return $server_base_web . $path; case TO_SYS: return $server_base_sys . $path; case TO_REL: return $path; } return null; }
/** * Write the main system config file * @param string $path Path to the config file */ function write_system_config_file($path) { global $dbHostForm; global $dbUsernameForm; global $dbPassForm; global $singleDbForm; global $dbPrefixForm; global $dbNameForm; global $urlForm; global $pathForm; global $urlAppendPath; global $languageForm; global $encryptPassForm; global $installType; global $updatePath; global $session_lifetime; global $new_version; global $new_version_stable; $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm))); $content = file_get_contents(dirname(__FILE__) . '/' . SYSTEM_CONFIG_FILENAME); $config['{DATE_GENERATED}'] = date('r'); $config['{DATABASE_HOST}'] = $dbHostForm; $config['{DATABASE_USER}'] = $dbUsernameForm; $config['{DATABASE_PASSWORD}'] = $dbPassForm; $config['SINGLE_DATABASE'] = true_false($singleDbForm); $config['{COURSE_TABLE_PREFIX}'] = $singleDbForm ? 'crs_' : ''; $config['{DATABASE_GLUE}'] = $singleDbForm ? '_' : '`.`'; $config['{DATABASE_PREFIX}'] = ''; $config['{DATABASE_MAIN}'] = $dbNameForm; $config['{ROOT_WEB}'] = $urlForm; $config['{ROOT_SYS}'] = $root_sys; $config['{URL_APPEND_PATH}'] = $urlAppendPath; $config['{PLATFORM_LANGUAGE}'] = $languageForm; $config['{SECURITY_KEY}'] = md5(uniqid(rand() . time())); $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm; $config['SESSION_LIFETIME'] = $session_lifetime; $config['{NEW_VERSION}'] = $new_version; $config['NEW_VERSION_STABLE'] = true_false($new_version_stable); foreach ($config as $key => $value) { $content = str_replace($key, $value, $content); } $fp = @fopen($path, 'w'); if (!$fp) { echo '<strong> <font color="red">Your script doesn\'t have write access to the config directory</font></strong> <br /> <em>(' . str_replace('\\', '/', realpath($path)) . ')</em><br /><br /> You probably do not have write access on Chamilo root directory, i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br /> Your problems can be related on two possible causes:<br /> <ul> <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li> <li>PHP is running in <a href="http://www.php.net/manual/en/features.safe-mode.php" target="_blank">Safe-Mode</a>. If possible, try to switch it off.</li> </ul> <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br /> Please go back to step 5. <p><input type="submit" name="step5" value="< Back" /></p> </td></tr></table></form></body></html>'; exit; } fwrite($fp, $content); fclose($fp); }
}*/ $badUpdatePath = false; $emptyUpdatePath = true; $proposedUpdatePath = ''; if (!empty($_POST['updatePath'])) { $proposedUpdatePath = $_POST['updatePath']; } if (@$_POST['step2_install'] || @$_POST['step2_update_8'] || @$_POST['step2_update_6']) { if (@$_POST['step2_install']) { $installType = 'new'; $_POST['step2'] = 1; } else { $installType = 'update'; if (@$_POST['step2_update_8']) { $emptyUpdatePath = false; $proposedUpdatePath = api_add_trailing_slash(empty($_POST['updatePath']) ? api_get_path(SYS_PATH) : $_POST['updatePath']); if (file_exists($proposedUpdatePath)) { if (in_array($my_old_version, $update_from_version_8)) { $_POST['step2'] = 1; } else { $badUpdatePath = true; } } else { $badUpdatePath = true; } } } } elseif (@$_POST['step1']) { $_POST['updatePath'] = ''; $installType = ''; $updateFromConfigFile = '';
* Notice : This script has to be included by index.php * * @package chamilo.install */ /* This page is called only during a NEW chamilo installation */ /* This page can only be access through including from the install script. */ /** * Init checks */ if (!defined('SYSTEM_INSTALLATION')) { echo 'You are not allowed here!'; exit; } $urlForm = api_add_trailing_slash($urlForm); switch ($encryptPassForm) { case 'md5' : $passToStore = md5($passForm); break; case 'sha1' : $passToStore = sha1($passForm); break; case 'none' : $passToStore = $passForm; break; } $dbPrefixForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbPrefixForm);
/** * Returns a path to a certain resource within the Chamilo area, specifyed through a parameter. * Also, this function provides conversion between path types, in this case the input path points inside the Chamilo area too. * * See $_configuration['course_folder'] in the configuration.php to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters. * @param string $type The requested path type (a defined constant), see the examples. * @param string $path (optional) A path which type is to be converted. Also, it may be a defined constant for a path. * This parameter has meaning when $type parameter has one of the following values: TO_WEB, TO_SYS, TO_REL. Otherwise it is ignored. * @return string The requested path or the converted path. * * A terminology note: * The defined constants used by this function contain the abbreviations WEB, REL, SYS with the following meaning for types: * WEB - an absolute URL (we often call it web-path), * example: http://www.mychamilo.org/chamilo/courses/COURSE01/document/lesson01.html; * * REL - represents a semi-absolute URL - a web-path, which is relative to the root web-path of the server, without server's base, * example: /chamilo/courses/COURSE01/document/lesson01.html; * * SYS - represents an absolute path inside the scope of server's file system, * /var/www/chamilo/courses/COURSE01/document/lesson01.html or * C:/Inetpub/wwwroot/chamilo/courses/COURSE01/document/lesson01.html. * * In some abstract sense we can consider these three path types as absolute. * * Notes about the current behaviour model: * 1. Windows back-slashes are converted to slashes in the result. * 2. A semi-absolute web-path is detected by its leading slash. On Linux systems, absolute system paths start with * a slash too, so an additional check about presense of leading system server base is implemented. For example, the function is * able to distinguish type difference between /var/www/chamilo/courses/ (SYS) and /chamilo/courses/ (REL). * 3. The function api_get_path() returns only these three types of paths, which in some sense are absolute. The function has * no a mechanism for processing relative web/system paths, such as: lesson01.html, ./lesson01.html, ../css/my_styles.css. * It has not been identified as needed yet. * 4. Also, resolving the meta-symbols "." and ".." withiin paths has not been implemented, it is to be identified as needed. * * Example: * Assume that your server root is /var/www/ , Chamilo is installed in a subfolder chamilo/ and the URL of your campus is http://www.mychamilo.org * The other configuration paramaters have not been changed. * * This is how we can retireve mosth used paths, for common purpose: * api_get_path(REL_PATH) /chamilo/ * api_get_path(REL_COURSE_PATH) /chamilo/courses/ * api_get_path(REL_CODE_PATH) /chamilo/main/ * api_get_path(SYS_SERVER_ROOT_PATH) /var/www/ - This is the physical folder where the system Chamilo has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT']. * api_get_path(SYS_PATH) /var/www/chamilo/ * * api_get_path(SYS_ARCHIVE_PATH) /var/www/chamilo/temp/ * api_get_path(SYS_LOG_PATH) /var/www/chamilo/logs/ * api_get_path(SYS_DATA_PATH) /var/www/chamilo/data/ * api_get_path(SYS_CONFIG_PATH) /var/www/chamilo/config/ * api_get_path(SYS_WEB_PATH) /var/www/chamilo/web/ * * api_get_path(SYS_COURSE_PATH) /var/www/chamilo/data/courses/ * api_get_path(SYS_CODE_PATH) /var/www/chamilo/main/ * api_get_path(SYS_CSS_PATH) /var/www/chamilo/main/css * api_get_path(INCLUDE_PATH) /var/www/chamilo/main/inc/ * api_get_path(LIBRARY_PATH) /var/www/chamilo/main/inc/lib/ * api_get_path(SYS_LIBRARY_JS_PATH) /var/www/chamilo/web/Chamilo/js * api_get_path(CONFIGURATION_PATH) /var/www/chamilo/main/inc/conf/ * api_get_path(SYS_LANG_PATH) /var/www/chamilo/main/lang/ * api_get_path(SYS_PLUGIN_PATH) /var/www/chamilo/plugin/ * api_get_path(SYS_TEST_PATH) /var/www/chamilo/tests/ * api_get_path(SYS_TEMPLATE_PATH) /var/www/chamilo/main/template/ * * api_get_path(WEB_SERVER_ROOT_PATH) http://www.mychamilo.org/ * * api_get_path(WEB_PUBLIC_PATH) http://www.mychamilo.org/chamilo/web/ * api_get_path(WEB_PATH) http://www.mychamilo.org/chamilo/ * api_get_path(WEB_COURSE_PATH) http://www.mychamilo.org/chamilo/courses/ * api_get_path(WEB_CODE_PATH) http://www.mychamilo.org/chamilo/main/ * api_get_path(WEB_PLUGIN_PATH) http://www.mychamilo.org/chamilo/plugin/ * api_get_path(WEB_ARCHIVE_PATH) http://www.mychamilo.org/chamilo/archive/ * api_get_path(WEB_IMG_PATH) http://www.mychamilo.org/chamilo/web/chamilo/img/ * api_get_path(SYS_IMG_PATH) /var/www/chamilo/web/bundles/chamilocore/img/ * * api_get_path(WEB_CSS_PATH) http://www.mychamilo.org/chamilo/main/css/ * api_get_path(WEB_LIBRARY_PATH) http://www.mychamilo.org/chamilo/main/inc/lib/ * api_get_path(WEB_LIBRARY_JS_PATH) http://www.mychamilo.org/chamilo/web/Chamilo/javascript * api_get_path(WEB_TEMPLATE_PATH) http://www.mychamilo.org/chamilo/main/template/ * * * We can convert arbitrary paths, that are not registered (no defined constant). * For guaranteed result, these paths should point inside the system Chamilo. * Some random examples: * 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) { $paths = array(SYS_DATA_PATH => 'data/', SYS_WEB_PATH => 'web/', SYS_CONFIG_PATH => 'config/', SYS_LOG_PATH => 'logs/', WEB_DATA_COURSE_PATH => 'courses/', WEB_DATA_PATH => '/', SYS_COURSE_PATH => 'data/', SYS_CSS_PATH => 'bundles/chamilocore/css/', SYS_LANG_PATH => 'lang/', WEB_IMG_PATH => 'bundles/chamilocore/img/', SYS_IMG_PATH => 'web/bundles/chamilocore/img/', WEB_CSS_PATH => 'bundles/chamilocore/css/', SYS_PLUGIN_PATH => 'plugin/', WEB_PLUGIN_PATH => 'plugin/', WEB_ARCHIVE_PATH => 'temp/', INCLUDE_PATH => 'inc/', LIBRARY_PATH => 'inc/lib/', SYS_LIBRARY_JS_PATH => 'bundles/chamilocore/js/', CONFIGURATION_PATH => 'inc/conf/', WEB_LIBRARY_PATH => 'inc/lib/', WEB_LIBRARY_JS_PATH => 'bundles/chamilocore/js/', WEB_AJAX_PATH => 'inc/ajax/', SYS_TEST_PATH => 'tests/', WEB_TEMPLATE_PATH => 'template/', SYS_TEMPLATE_PATH => 'template/'); $root_web = Container::getUrlGenerator()->generate('home'); $rootDir = Container::getRootDir(); // Configuration data for already installed system. $root_sys = $rootDir; $code_folder = 'main/'; //$course_folder = isset($_configuration['course_folder']) ? $_configuration['course_folder'] : null; $course_folder = "courses/"; // 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); $root_rel = null; // Initialization of a table that contains common-purpose paths. $paths[WEB_PATH] = $root_web; $webPathNoDev = str_replace('app_dev.php/', '', $paths[WEB_PATH]); $paths[WEB_PUBLIC_PATH] = $root_web; $paths[SYS_PATH] = $root_sys; // Update data path to get it from config file if defined $paths[SYS_DATA_PATH] = Container::getDataDir(); $paths[SYS_LOG_PATH] = Container::getLogDir(); $paths[SYS_CONFIG_PATH] = Container::getConfigDir(); $paths[SYS_COURSE_PATH] = Container::getCourseDir(); $paths[SYS_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[SYS_DATA_PATH] . 'default_course_document/'; $paths[SYS_WEB_PATH] = $root_sys . 'web/'; $paths[REL_PATH] = $root_rel; $paths[WEB_DATA_PATH] = $paths[WEB_PUBLIC_PATH] . 'data/'; $paths[WEB_COURSE_PATH] = $root_web . $course_folder; $paths[WEB_DATA_COURSE_PATH] = $paths[WEB_DATA_PATH] . $course_folder; $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[REL_DATA_PATH] = $root_rel . 'data/'; $paths[WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[WEB_DATA_PATH] . 'default_course_document/'; $paths[REL_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[REL_DATA_PATH] . 'default_course_document/'; $paths[SYS_CODE_PATH] = $root_sys . $code_folder; // 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] = Container::getTempDir(); $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_PATH] . $paths[SYS_CSS_PATH]; $paths[WEB_CSS_PATH] = $paths[WEB_PATH] . $paths[WEB_CSS_PATH]; $paths[WEB_IMG_PATH] = $paths[WEB_PATH] . $paths[WEB_IMG_PATH]; $paths[SYS_IMG_PATH] = $paths[SYS_PATH] . $paths[SYS_IMG_PATH]; $paths[WEB_LIBRARY_PATH] = $paths[WEB_CODE_PATH] . $paths[WEB_LIBRARY_PATH]; $paths[WEB_LIBRARY_JS_PATH] = $webPathNoDev . $paths[WEB_LIBRARY_JS_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]; $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH] . $paths[WEB_ARCHIVE_PATH]; $paths[WEB_TEMPLATE_PATH] = $paths[WEB_CODE_PATH] . $paths[WEB_TEMPLATE_PATH]; $paths[INCLUDE_PATH] = $paths[SYS_CODE_PATH] . $paths[INCLUDE_PATH]; $paths[LIBRARY_PATH] = $paths[SYS_CODE_PATH] . $paths[LIBRARY_PATH]; $paths[SYS_LIBRARY_JS_PATH] = $paths[SYS_PATH] . $paths[SYS_LIBRARY_JS_PATH]; $paths[CONFIGURATION_PATH] = $paths[SYS_CODE_PATH] . $paths[CONFIGURATION_PATH]; // Path conversion to the requested type. if (empty($path_type)) { return null; } if (isset($paths[$path_type])) { return $paths[$path_type]; } return null; }
/** * This function returns the value of a parameter from the configuration file * * WARNING - this function relies heavily on global variables $updateFromConfigFile * and $configFile, and also changes these globals. This can be rewritten. * * @param string $param the parameter of which the value is returned * @param string If we want to give the path rather than take it from POST * @return string the value of the parameter * @author Olivier Brouckaert * @author Reworked by Ivan Tcholakov, 2010 */ function get_config_param($param, $updatePath = '') { global $configFile, $updateFromConfigFile; // Look if we already have the queried parameter. if (is_array($configFile) && isset($configFile[$param])) { return $configFile[$param]; } if (empty($updatePath) && !empty($_POST['updatePath'])) { $updatePath = $_POST['updatePath']; } if (empty($updatePath)) { $updatePath = api_get_path(SYS_PATH); } $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath))); $updateFromInstalledVersionFile = ''; if (empty($updateFromConfigFile)) { // If update from previous install was requested, // try to recover old config file from dokeos 1.8.x. if (file_exists($updatePath.'main/inc/conf/configuration.php')) { $updateFromConfigFile = 'main/inc/conf/configuration.php'; } elseif (file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php')) { $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php'; } else { // Give up recovering. //error_log('Chamilo Notice: Could not find previous config file at '.$updatePath.'main/inc/conf/configuration.php nor at '.$updatePath.'claroline/inc/conf/claro_main.conf.php in get_config_param(). Will start new config (in '.__FILE__.', line '.__LINE__.')', 0); return null; } } if (file_exists($updatePath.$updateFromConfigFile) && !is_dir($updatePath.$updateFromConfigFile)) { // The parameter was not found among the global variables, so look into the old configuration file. // Make sure the installedVersion file is read first so it is overwritten // by the config file if the config file contains the version (from 1.8.4). $config_data_2 = array(); if (file_exists($updatePath.$updateFromInstalledVersionFile)) { $config_data_2 = file_to_array($updatePath.$updateFromInstalledVersionFile); } $configFile = array(); $config_data = file_to_array($updatePath.$updateFromConfigFile); $config_data = array_merge($config_data, $config_data_2); $val = ''; // Parse the configuration file, statement by statement (line by line, actually). foreach ($config_data as $php_statement) { if (strpos($php_statement, '=') !== false) { // Variable assignment statement have been detected (probably). // It is expected to be as follows: // $variable = 'some_value'; // A comment that is not mandatory. // Split the statement into its left and right sides. $php_statement = explode('=', $php_statement); $variable = trim($php_statement[0]); $value = $php_statement[1]; if (substr($variable, 0, 1) == '$') { // We have for sure a php variable assignment detected. // On the left side: Retrieve the pure variable's name $variable = trim(str_replace('$', '', $variable)); // On the right side: Remove the comment, if it exists. list($value) = explode(' //', $value); // Remove extra whitespace, if any. Remove the trailing semicolon (;). $value = substr(trim($value), 0, -1); // Remove surroundig quotes, restore escaped quotes. $value = str_replace('\"', '"', preg_replace('/^"|"$/', '', $value)); $value = str_replace('\'', '"', preg_replace('/^\'|\'$/', '', $value)); if (strtolower($value) == 'true') { // A boolean true value have been recognized. $value = 1; } elseif (strtolower($value) == 'false') { // A boolean false value have been recognized. $value = 0; } else { // Probably we have a string value, but also we have to check // possible string concatenations that may include string values // and other configuration variables. I this case we have to // get the calculated result of the concatenation. $implode_string = ' '; if (!strstr($value, '." ".') && strstr($value, '.$')) { // Yes, there is concatenation, insert a special separator string. $value = str_replace('.$', '." ".$', $value); $implode_string = ''; } // Split the concatenated values, if they are more than one. $sub_strings = explode('." ".', $value); // Seek for variables and retrieve their values. foreach ($sub_strings as $key => & $sub_string) { if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $sub_string)) { // A variable has been detected, read it by recursive call. $sub_string = get_config_param(str_replace('$', '', $sub_string)); } } // Concatenate everything into the final, the calculated string value. $value = implode($implode_string, $sub_strings); } // Cache the result value. $configFile[$variable] = $value; $a = explode("'", $variable); $key_tmp = isset($a[1]) ? $a[1] : null; if ($key_tmp == $param) { $val = $value; } } } } } if($param == 'dbGlu' && empty($val)){ return '`.`'; } //Special treatment for dokeos_version parameter due to Dokeos 1.8.3 have the dokeos_version in the main/inc/installedVersion.inc.php file if ($param == 'dokeos_version') { //dokeos_version from configuration.php if empty $dokeos_version = $val; if (empty($dokeos_version)) { //checking the dokeos_version value exists in main/inc/installedVersion.inc.php if (file_exists($updatePath.'main/inc/installedVersion.inc.php')) { $updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php'; require ($updateFromInstalledVersionFile); //there are only 2 variables here: $stable & $dokeos_version $stable = false; } } return $dokeos_version; } else { if (file_exists($updatePath.$updateFromConfigFile)) { return $val; } else { error_log('Config array could not be found in get_config_param()', 0); return null; } } }
$proposedUpdatePath = api_add_trailing_slash(empty($_POST['updatePath']) ? api_get_path(SYS_PATH) : $_POST['updatePath']); if (file_exists($proposedUpdatePath)) { if (in_array($my_old_version, $update_from_version_8)) { $_POST['step2'] = 1; } else { $badUpdatePath = true; } } else { $badUpdatePath = true; } } else { //step2_update_6, presumably if (empty($_POST['updatePath'])) { $_POST['step1'] = 1; } else { $emptyUpdatePath = false; $_POST['updatePath'] = api_add_trailing_slash($_POST['updatePath']); if (file_exists($_POST['updatePath'])) { //1.6.x $my_old_version = get_config_param('clarolineVersion', $_POST['updatePath']); if (in_array($my_old_version, $update_from_version_6)) { $_POST['step2'] = 1; $proposedUpdatePath = $_POST['updatePath']; } else { $badUpdatePath = true; } } else { $badUpdatePath = true; } } } }
/** * This method returns detected configuration data about editor's MimeTeX plugin. * @return array */ private function &get_mimetex_plugin_configuration() { static $config; if (!isset($config)) { $config = array(); if (is_array($this->Config['LoadPlugin']) && in_array('mimetex', $this->Config['LoadPlugin'])) { $server_base = api_get_path(WEB_SERVER_ROOT_PATH); $server_base_parts = explode('/', $server_base); $url_relative = 'cgi-bin/mimetex' . (IS_WINDOWS_OS ? '.exe' : '.cgi'); if (!isset($this->Config['MimetexExecutableInstalled'])) { $this->Config['MimetexExecutableDetectionMethod'] = 'detect'; } if ($this->Config['MimetexExecutableInstalled'] == 'detect') { $detection_method = isset($this->Config['MimetexExecutableDetectionMethod']) ? $this->Config['MimetexExecutableDetectionMethod'] : 'bootstrap_ip'; $detection_timeout = isset($this->Config['MimetexExecutableDetectionTimeout']) ? $this->Config['MimetexExecutableDetectionTimeout'] : 0.05; switch ($detection_method) { case 'bootstrap_ip': $detection_url = $server_base_parts[0] . '//127.0.0.1/'; break; case 'localhost': $detection_url = $server_base_parts[0] . '//localhost/'; break; case 'ip': $detection_url = $server_base_parts[0] . '//' . $_SERVER['SERVER_ADDR'] . '/'; break; default: $detection_url = $server_base_parts[0] . '//' . $_SERVER['SERVER_NAME'] . '/'; } $detection_url .= $url_relative . '?' . rand(); $config['IsMimetexInstalled'] = self::url_exists($detection_url, $detection_timeout); } else { $config['IsMimetexInstalled'] = $this->Config['MimetexExecutableInstalled']; } $config['MimetexUrl'] = api_add_trailing_slash($server_base) . $url_relative; } // Cleaning detection related settings, we don't need them anymore. unset($this->Config['MimetexExecutableInstalled']); unset($this->Config['MimetexExecutableDetectionMethod']); unset($this->Config['MimetexExecutableDetectionTimeout']); } return $config; }
/** * Returns a path to a certain resource within the Chamilo area, specifyed through a parameter. * Also, this function provides conversion between path types, in this case the input path points inside the Chamilo area too. * * See $_configuration['course_folder'] in the configuration.php to alter the WEB_COURSE_PATH and SYS_COURSE_PATH parameters. * @param string $type The requested path type (a defined constant), see the examples. * @param string $path (optional) A path which type is to be converted. Also, it may be a defined constant for a path. * This parameter has meaning when $type parameter has one of the following values: TO_WEB, TO_SYS, TO_REL. Otherwise it is ignored. * @return string The requested path or the converted path. * * A terminology note: * The defined constants used by this function contain the abbreviations WEB, REL, SYS with the following meaning for types: * WEB - an absolute URL (we often call it web-path), * example: http://www.mychamilo.org/chamilo/courses/COURSE01/document/lesson01.html; * * REL - represents a semi-absolute URL - a web-path, which is relative to the root web-path of the server, without server's base, * example: /chamilo/courses/COURSE01/document/lesson01.html; * * SYS - represents an absolute path inside the scope of server's file system, * /var/www/chamilo/courses/COURSE01/document/lesson01.html or * C:/Inetpub/wwwroot/chamilo/courses/COURSE01/document/lesson01.html. * * In some abstract sense we can consider these three path types as absolute. * * Notes about the current behaviour model: * 1. Windows back-slashes are converted to slashes in the result. * 2. A semi-absolute web-path is detected by its leading slash. On Linux systems, absolute system paths start with * a slash too, so an additional check about presence of leading system server base is implemented. For example, the function is * able to distinguish type difference between /var/www/chamilo/courses/ (SYS) and /chamilo/courses/ (REL). * 3. The function api_get_path() returns only these three types of paths, which in some sense are absolute. The function has * no a mechanism for processing relative web/system paths, such as: lesson01.html, ./lesson01.html, ../css/my_styles.css. * It has not been identified as needed yet. * 4. Also, resolving the meta-symbols "." and ".." within paths has not been implemented, it is to be identified as needed. * * Example: * Assume that your server root is /var/www/ , * Chamilo is installed in a sub folder chamilo/ and the URL of your campus is http://www.mychamilo.org * The other configuration parameters have not been changed. * * This is how we can get most used paths, for common purpose: * api_get_path(REL_PATH) /chamilo/ * api_get_path(REL_COURSE_PATH) /chamilo/courses/ * api_get_path(REL_CODE_PATH) /chamilo/main/ * api_get_path(REL_UPLOAD_PATH) /chamilo/app/upload/ * api_get_path(SYS_SERVER_ROOT_PATH) /var/www/ - This is the physical folder where the system Chamilo has been placed. It is not always equal to $_SERVER['DOCUMENT_ROOT']. * api_get_path(SYS_PATH) /var/www/chamilo/ * api_get_path(SYS_APP_PATH) /var/www/chamilo/app/ * api_get_path(SYS_UPLOAD_PATH) /var/www/chamilo/app/upload/ * api_get_path(SYS_ARCHIVE_PATH) /var/www/chamilo/app/cache * api_get_path(SYS_COURSE_PATH) /var/www/chamilo/app/courses/ * api_get_path(SYS_CSS_PATH) /var/www/chamilo/app/Resources/public/css * api_get_path(SYS_CODE_PATH) /var/www/chamilo/main/ * api_get_path(INCLUDE_PATH) /var/www/chamilo/main/inc/ * api_get_path(LIBRARY_PATH) /var/www/chamilo/main/inc/lib/ * api_get_path(CONFIGURATION_PATH) /var/www/chamilo/main/inc/conf/ * api_get_path(SYS_LANG_PATH) /var/www/chamilo/main/lang/ * api_get_path(SYS_PLUGIN_PATH) /var/www/chamilo/plugin/ * api_get_path(SYS_TEST_PATH) /var/www/chamilo/tests/ * api_get_path(SYS_TEMPLATE_PATH) /var/www/chamilo/main/template/ * api_get_path(SYS_PUBLIC_PATH) /var/www/chamilo/web/ * * api_get_path(WEB_SERVER_ROOT_PATH) http://www.mychamilo.org/ * api_get_path(WEB_PATH) http://www.mychamilo.org/chamilo/ * api_get_path(WEB_COURSE_PATH) http://www.mychamilo.org/chamilo/courses/ * api_get_path(WEB_CODE_PATH) http://www.mychamilo.org/chamilo/main/ * api_get_path(WEB_PLUGIN_PATH) http://www.mychamilo.org/chamilo/plugin/ * api_get_path(WEB_ARCHIVE_PATH) http://www.mychamilo.org/chamilo/app/cache/ * api_get_path(WEB_IMG_PATH) http://www.mychamilo.org/chamilo/main/img/ * api_get_path(WEB_CSS_PATH) http://www.mychamilo.org/chamilo/web/css/ * api_get_path(WEB_LIBRARY_PATH) http://www.mychamilo.org/chamilo/main/inc/lib/ * api_get_path(WEB_LIBRARY_JS_PATH) http://www.mychamilo.org/chamilo/web/Chamilo/javascript * api_get_path(WEB_TEMPLATE_PATH) http://www.mychamilo.org/chamilo/main/template/ * api_get_path(WEB_UPLOAD_PATH) http://www.mychamilo.org/chamilo/app/upload/ * api_get_path(WEB_PUBLIC_PATH) http://www.mychamilo.org/chamilo/web/ * * This is how we retrieve paths of "registered" resource files (scripts, players, etc.): * api_get_path(TO_WEB, FLASH_PLAYER_AUDIO) http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf * api_get_path(TO_WEB, FLASH_PLAYER_VIDEO) http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf * api_get_path(TO_SYS, SCRIPT_SWFOBJECT) /var/www/chamilo/main/inc/lib/swfobject/swfobject.js * api_get_path(TO_REL, SCRIPT_ASCIIMATHML) /chamilo/main/inc/lib/asciimath/ASCIIMathML.js * ... * * We can convert arbitrary paths, that are not registered (no defined constant). * For guaranteed result, these paths should point inside the system Chamilo. * Some random examples: * 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; // Always load root_web modifications for multiple url features 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_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. 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); // 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(__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); // 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 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 . '/'; $paths[WEB_COURSE_PATH] = $root_web . $course_folder; $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]; $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/'; // Now we can switch into api_get_path() "terminology". $paths[SYS_LANG_PATH] = $paths[SYS_CODE_PATH] . $paths[SYS_LANG_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[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]; $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[WEB_PLUGIN_PATH] = $paths[WEB_PATH] . $paths[WEB_PLUGIN_PATH]; $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH] . $paths[WEB_ARCHIVE_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[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; $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 => 'css/', WEB_PLUGIN_PATH => 'plugin/', WEB_ARCHIVE_PATH => 'archive/', WEB_LIBRARY_PATH => 'inc/lib/', WEB_AJAX_PATH => 'inc/ajax/'); $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. // 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[WEB_CSS_PATH] = $paths[WEB_CODE_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]; } } // Shallow purification and validation of input parameters. $path_type = trim($path_type); $path = trim($path); if (empty($path_type)) { return null; } // Retrieving a common-purpose path. if (isset($paths[$path_type])) { return $paths[$path_type]; } // Retrieving a specific resource path. if (isset($resource_paths[$path])) { switch ($path_type) { case TO_WEB: return $paths[WEB_CODE_PATH] . $resource_paths[$path]; case TO_SYS: return $paths[SYS_CODE_PATH] . $resource_paths[$path]; case TO_REL: return $paths[REL_CODE_PATH] . $resource_paths[$path]; default: return null; } } // Common-purpose paths as a second parameter - recognition. if (isset($paths[$path])) { $path = $paths[$path]; } // Second purification. // Replacing Windows back slashes. $path = str_replace('\\', '/', $path); // Query strings sometimes mighth wrongly appear in non-URLs. // Let us check remove them from all types of paths. if (($pos = strpos($path, '?')) !== false) { $path = substr($path, 0, $pos); } // 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: // http://localhost/chamilo/main/document/download.php?doc_url=/image.png&cDir=/ // becomes // http://localhost/chamilo/courses/TEST/document/image.png // TEST is a course directory name, so called "system course code". if (strpos($path, 'download.php') !== false) { // Fast detection first. $path = urldecode($path); if (preg_match('/(.*)main\\/document\\/download.php\\?doc_url=\\/(.*)&cDir=\\/(.*)?/', $path, $matches)) { $sys_course_code = isset($_SESSION['_course']['sysCode']) ? $_SESSION['_course']['sysCode'] : '{SYS_COURSE_CODE}'; // No, then use a fake code, it may be processed later. $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); } elseif (strpos($path, $server_base_sys) === 0) { $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. } else { return null; // Probably implementation of this case won't be needed. } // Path now is semi-absolute. It is convenient at this moment repeated slashes to be removed. $path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path); // Path conversion to the requested type. switch ($path_type) { case TO_WEB: return $server_base_web . $path; case TO_SYS: return $server_base_sys . $path; case TO_REL: return $path; } return null; }