MDL-78895 mod_url: fix double encoded ampersands in URL.

Also restore the `$attributes` property (previously `$extra` prior
to 8d8af19a) to define URL opening behaviour, e.g. in popup or new
window.
This commit is contained in:
Paul Holden
2023-09-06 13:24:46 +01:00
parent 8ac8ea416a
commit 0ef9be6004
+8 -9
View File
@@ -250,7 +250,6 @@ EOF;
* @param object $url
* @param object $cm
* @param object $course
* @return does not return
*/
function url_print_workaround($url, $cm, $course) {
global $OUTPUT, $PAGE, $USER;
@@ -258,26 +257,26 @@ function url_print_workaround($url, $cm, $course) {
$PAGE->activityheader->set_description(url_get_intro($url, $cm, true));
url_print_header($url, $cm, $course);
$fullurl = url_get_full_url($url, $cm, $course);
$fullurl = new moodle_url(url_get_full_url($url, $cm, $course));
$display = url_get_final_display_type($url);
if ($display == RESOURCELIB_DISPLAY_POPUP) {
$jsfullurl = addslashes_js($fullurl);
$jsfullurl = addslashes_js($fullurl->out(false));
$options = empty($url->displayoptions) ? [] : (array) unserialize_array($url->displayoptions);
$width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
$height = empty($options['popupheight']) ? 450 : $options['popupheight'];
$wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
$extra = "onclick=\"window.open('$jsfullurl', '', '$wh'); return false;\"";
$attributes = ['onclick' => "window.open('$jsfullurl', '', '$wh'); return false;"];
} else if ($display == RESOURCELIB_DISPLAY_NEW) {
$extra = "onclick=\"this.target='_blank';\"";
$attributes = ['onclick' => "this.target='_blank';"];
} else {
$extra = '';
$attributes = [];
}
echo '<div class="urlworkaround">';
print_string('clicktoopen', 'url', html_writer::link($fullurl, format_string($cm->name)));
print_string('clicktoopen', 'url', html_writer::link($fullurl, format_string($cm->name), $attributes));
echo '</div>';
echo $OUTPUT->footer();
@@ -297,9 +296,9 @@ function url_display_embed($url, $cm, $course) {
$fullurl = url_get_full_url($url, $cm, $course);
$title = $url->name;
$link = html_writer::link($fullurl, format_string($cm->name));
$clicktoopen = get_string('clicktoopen', 'url', $link);
$moodleurl = new moodle_url($fullurl);
$link = html_writer::link($moodleurl, format_string($cm->name));
$clicktoopen = get_string('clicktoopen', 'url', $link);
$extension = resourcelib_get_extension($url->externalurl);