MDL-36674 Administration: out_as_local_url will check for both http and https url's

out_as_local_url will first check if url passed in wwwroot, if it's not then it will check
if loginhttps is enabled and url is httpswwwroot
This commit is contained in:
Rajesh Taneja 2012-11-19 11:52:15 +08:00
parent ca48fe5f97
commit 72b181ba59
2 changed files with 49 additions and 3 deletions

View file

@ -747,12 +747,18 @@ class moodle_url {
global $CFG;
$url = $this->out($escaped, $overrideparams);
$httpswwwroot = str_replace("http://", "https://", $CFG->wwwroot);
if (strpos($url, $CFG->wwwroot) !== 0) {
// $url should be equal to wwwroot or httpswwwroot. If not then throw exception.
if (($url === $CFG->wwwroot) || (strpos($url, $CFG->wwwroot.'/') === 0)) {
$localurl = substr($url, strlen($CFG->wwwroot));
return !empty($localurl) ? $localurl : '';
} else if (($url === $httpswwwroot) || (strpos($url, $httpswwwroot.'/') === 0)) {
$localurl = substr($url, strlen($httpswwwroot));
return !empty($localurl) ? $localurl : '';
} else {
throw new coding_exception('out_as_local_url called on a non-local URL');
}
return str_replace($CFG->wwwroot, '', $url);
}
/**