*/
function get_docs_url($path) {
global $CFG;
- //derive branch from the first three letters of version.php's $release with the period taken out.($CFG->release isn't populated yet during upgrade)
- include($CFG->dirroot.'/version.php');
- preg_match('/^(.)\.(.)/', $release, $matches);
- $branch = $matches[1].$matches[2];
++ // Check that $CFG->release has been set up, during installation it won't be.
++ if (empty($CFG->release)) {
++ // It's not there yet so look at version.php
++ include($CFG->dirroot.'/version.php');
++ } else {
++ // We can use $CFG->release and avoid having to include version.php
++ $release = $CFG->release;
++ }
++ // Attempt to match the branch from the release
++ if (preg_match('/^(.)\.(.)/', $release, $matches)) {
++ // We should ALWAYS get here
++ $branch = $matches[1].$matches[2];
++ } else {
++ // We should never get here but in case we do lets set $branch to .
++ // the smart one's will know that this is the current directory
++ // and the smarter ones will know that there is some smart matching
++ // that will ensure people end up at the latest version of the docs.
++ $branch = '.';
++ }
if (!empty($CFG->docroot)) {
- return $CFG->docroot . '/' . current_language() . '/' . $path;
+ return $CFG->docroot . '/' . $branch . '/' . current_language() . '/' . $path;
} else {
- return 'http://docs.moodle.org/en/'.$path;
+ return 'http://docs.moodle.org/'. $branch . '/en/' . $path;
}
}