Exemple #1
0
/**
 * 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;
}
Exemple #2
0
/**
 * 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;
}