mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -561,7 +561,7 @@ if (!$quiz_reordertool) {
|
|||
$randomform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'), $contexts);
|
||||
$randomform->set_data(array(
|
||||
'category' => $pagevars['cat'],
|
||||
'returnurl' => str_replace($CFG->wwwroot, '', $thispageurl->out(false)),
|
||||
'returnurl' => $thispageurl->out_as_local_url(false),
|
||||
'cmid' => $cm->id,
|
||||
));
|
||||
?>
|
||||
|
|
|
@ -453,7 +453,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
|
|||
|
||||
$pageopen = false;
|
||||
|
||||
$returnurl = str_replace($CFG->wwwroot, '', $pageurl->out(false));
|
||||
$returnurl = $pageurl->out_as_local_url(false);
|
||||
$questiontotalcount = count($order);
|
||||
|
||||
foreach ($order as $count => $qnum) {
|
||||
|
@ -731,7 +731,7 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts, $defaultc
|
|||
$returnurladdtoquiz = new moodle_url($pageurl, array('addonpage' => $page));
|
||||
|
||||
// Print a button linking to the choose question type page.
|
||||
$returnurladdtoquiz = str_replace($CFG->wwwroot, '', $returnurladdtoquiz->out(false));
|
||||
$returnurladdtoquiz = $returnurladdtoquiz->out_as_local_url(false);
|
||||
$newquestionparams = array('returnurl' => $returnurladdtoquiz,
|
||||
'cmid' => $quiz->cmid, 'appendqnumstring' => 'addquestion');
|
||||
create_new_question_button($defaultcategoryid, $newquestionparams,
|
||||
|
|
|
@ -829,7 +829,7 @@ function quiz_question_edit_button($cmid, $question, $returnurl, $contentafteric
|
|||
// Build the icon.
|
||||
if ($action) {
|
||||
if ($returnurl instanceof moodle_url) {
|
||||
$returnurl = str_replace($CFG->wwwroot, '', $returnurl->out(false));
|
||||
$returnurl = $returnurl->out_as_local_url(false);
|
||||
}
|
||||
$questionparams = array('returnurl' => $returnurl, 'cmid' => $cmid, 'id' => $question->id);
|
||||
$questionurl = new moodle_url("$CFG->wwwroot/question/question.php", $questionparams);
|
||||
|
|
|
@ -871,7 +871,7 @@ class question_bank_view {
|
|||
}
|
||||
|
||||
// Create the url of the new question page to forward to.
|
||||
$returnurl = str_replace($CFG->wwwroot, '', $pageurl->out(false));
|
||||
$returnurl = $pageurl->out_as_local_url(false);
|
||||
$this->editquestionurl = new moodle_url('/question/question.php',
|
||||
array('returnurl' => $returnurl));
|
||||
if ($cm !== null){
|
||||
|
|
|
@ -278,8 +278,7 @@ class core_question_renderer extends plugin_renderer_base {
|
|||
|
||||
$params = $options->editquestionparams;
|
||||
if ($params['returnurl'] instanceof moodle_url) {
|
||||
$params['returnurl'] = str_replace($CFG->wwwroot, '',
|
||||
$params['returnurl']->out(false));
|
||||
$params['returnurl'] = $params['returnurl']->out_as_local_url(false);
|
||||
}
|
||||
$params['id'] = $qa->get_question()->id;
|
||||
$editurl = new moodle_url('/question/question.php', $params);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue