mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 05:54:19 +02:00
MDL-21233 prepare_url obsoleted by new html_writer and changes in moodle_url
This commit is contained in:
parent
8afba50b84
commit
5509254c25
@ -903,7 +903,7 @@ class core_renderer extends renderer_base {
|
||||
|
||||
$this->prepare_event_handlers($link);
|
||||
|
||||
$attributes = array('href' => prepare_url($link->url),
|
||||
$attributes = array('href' => $link->url,
|
||||
'class' => $link->get_classes_string(),
|
||||
'title' => $link->title,
|
||||
'style' => $link->style,
|
||||
@ -1131,7 +1131,7 @@ class core_renderer extends renderer_base {
|
||||
|
||||
$formattributes = array(
|
||||
'method' => $form->method,
|
||||
'action' => prepare_url($form->url, true),
|
||||
'action' => $form->url->out_omit_querystring(),
|
||||
'id' => $form->id,
|
||||
'class' => $form->get_classes_string());
|
||||
|
||||
@ -1373,7 +1373,7 @@ class core_renderer extends renderer_base {
|
||||
$this->prepare_event_handlers($image);
|
||||
|
||||
$attributes = array('class' => $image->get_classes_string(),
|
||||
'src' => prepare_url($image->src),
|
||||
'src' => $image->src,
|
||||
'alt' => $image->alt,
|
||||
'style' => $image->style,
|
||||
'title' => $image->title,
|
||||
|
@ -88,25 +88,6 @@ class web_test extends UnitTestCase {
|
||||
$this->assertEqual(fix_non_standard_entities('£ä'), '£ä');
|
||||
}
|
||||
|
||||
function test_prepare_url() {
|
||||
global $CFG, $PAGE;
|
||||
$fullexternalurl = 'http://www.externalsite.com/somepage.php';
|
||||
$fullmoodleurl = $CFG->wwwroot . '/mod/forum/view.php?id=5';
|
||||
$relativeurl1 = 'edit.php';
|
||||
$relativeurl2 = '/edit.php';
|
||||
|
||||
$this->assertEqual($fullmoodleurl, prepare_url($fullmoodleurl));
|
||||
$this->assertEqual($fullexternalurl, prepare_url($fullexternalurl));
|
||||
$this->assertEqual("$CFG->wwwroot/admin/report/unittest/$relativeurl1", prepare_url($relativeurl1));
|
||||
$this->assertEqual("$CFG->wwwroot$relativeurl2", prepare_url($relativeurl2));
|
||||
|
||||
// Use moodle_url object
|
||||
$this->assertEqual($fullmoodleurl, prepare_url(new moodle_url('/mod/forum/view.php', array('id' => 5))));
|
||||
$this->assertEqual($fullexternalurl, prepare_url(new moodle_url($fullexternalurl)));
|
||||
$this->assertEqual("$CFG->wwwroot/admin/report/unittest/$relativeurl1", prepare_url(new moodle_url($relativeurl1)));
|
||||
$this->assertEqual("$CFG->wwwroot$relativeurl2", prepare_url(new moodle_url($relativeurl2)));
|
||||
}
|
||||
|
||||
function test_compare_url() {
|
||||
$url1 = new moodle_url('index.php', array('var1' => 1, 'var2' => 2));
|
||||
$url2 = new moodle_url('index2.php', array('var1' => 1, 'var2' => 2, 'var3' => 3));
|
||||
|
@ -607,46 +607,6 @@ class moodle_url {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an unknown $url type (string or moodle_url), returns a string URL.
|
||||
* A relative URL is handled with $PAGE->url but gives a debugging error.
|
||||
*
|
||||
* @param mixed $url The URL (moodle_url or string)
|
||||
* @param bool $stripformparams Whether or not to strip the query params from the URL
|
||||
* @return string the URL. &s are unescaped. You must use s(...) to output this to XHTML. ($OUTPUT normally does this automatically.)
|
||||
*/
|
||||
function prepare_url($url, $stripformparams=false) {
|
||||
global $CFG, $PAGE;
|
||||
|
||||
$output = $url;
|
||||
|
||||
if ($url instanceof moodle_url) {
|
||||
if ($stripformparams) {
|
||||
$output = $url->out_omit_querystring();
|
||||
} else {
|
||||
$output = $url->out(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle relative URLs
|
||||
if (substr($output, 0, 4) != 'http' && substr($output, 0, 1) != '/') {
|
||||
if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out_omit_querystring(), $matches)) {
|
||||
return $matches[1] . "/$output";
|
||||
} else if ($output == '') {
|
||||
return $PAGE->url->out(false) . '#';
|
||||
} else {
|
||||
throw new coding_exception('Unrecognied URL scheme. Please check the formatting of the URL passed to this function. Absolute URLs are the preferred scheme.');
|
||||
}
|
||||
}
|
||||
|
||||
// Add wwwroot only if the URL does not already start with http:// or https://
|
||||
if (!preg_match('|https?://|', $output) ) {
|
||||
$output = $CFG->wwwroot . $output;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there is data waiting to be processed from a form
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user