mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merge branch 'moodleurl_out_as_local_url' of git://git.luns.net.uk/moodle
This commit is contained in:
commit
d37d6e2a8e
7 changed files with 37 additions and 7 deletions
|
@ -127,6 +127,15 @@ class web_test extends UnitTestCase {
|
|||
$this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
|
||||
}
|
||||
|
||||
function test_out_as_local_url() {
|
||||
$url1 = new moodle_url('/lib/simpletest/testweblib.php');
|
||||
$this->assertEqual('/lib/simpletest/testweblib.php', $url1->out_as_local_url());
|
||||
|
||||
$url2 = new moodle_url('http://www.google.com/lib/simpletest/testweblib.php');
|
||||
$this->expectException('coding_exception');
|
||||
$url2->out_as_local_url();
|
||||
}
|
||||
|
||||
public function test_html_to_text_simple() {
|
||||
$this->assertEqual("\n\n_Hello_ WORLD!", html_to_text('<p><i>Hello</i> <b>world</b>!</p>'));
|
||||
}
|
||||
|
|
|
@ -717,6 +717,28 @@ class moodle_url {
|
|||
$urlbase = "$CFG->wwwroot/file.php";
|
||||
return self::make_file_url($urlbase, '/'.$courseid.'/'.$filepath, $forcedownload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns URL a relative path from $CFG->wwwroot
|
||||
*
|
||||
* Can be used for passing around urls with the wwwroot stripped
|
||||
*
|
||||
* @param boolean $escaped Use & as params separator instead of plain &
|
||||
* @param array $overrideparams params to add to the output url, these override existing ones with the same name.
|
||||
* @return string Resulting URL
|
||||
* @throws coding_exception if called on a non-local url
|
||||
*/
|
||||
public function out_as_local_url($escaped = true, array $overrideparams = null) {
|
||||
global $CFG;
|
||||
|
||||
$url = $this->out($escaped, $overrideparams);
|
||||
|
||||
if (strpos($url, $CFG->wwwroot) !== 0) {
|
||||
throw new coding_exception('out_as_local_url called on a non-local URL');
|
||||
}
|
||||
|
||||
return str_replace($CFG->wwwroot, '', $url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue