diff --git a/mod/url/locallib.php b/mod/url/locallib.php
index 0346579375..be3244830e 100644
--- a/mod/url/locallib.php
+++ b/mod/url/locallib.php
@@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die;
require_once("$CFG->libdir/filelib.php");
require_once("$CFG->libdir/resourcelib.php");
require_once("$CFG->dirroot/mod/url/lib.php");
+require_once("$CFG->dirroot/lib/classes/local/url_unfurl.php");
/**
* This methods does weak url validation, we are looking for major problems only,
@@ -267,20 +292,133 @@ function url_print_workaround($url, $cm, $course) {
$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;\"";
-
+ $onclick = "window.open('$jsfullurl', '', '$wh'); return false;";
} else if ($display == RESOURCELIB_DISPLAY_NEW) {
- $extra = "onclick=\"this.target='_blank';\"";
-
+ $onclick = "this.target='_blank';";
} else {
- $extra = '';
+ $onclick = '';
}
- echo '
';
- print_string('clicktoopen', 'url', "
$fullurl");
- echo '
';
+ $unfurl_store = unfurl_store::get_instance();
+ $unfurled = $unfurl_store->get_unfurl($fullurl);
+
+ $output = '';
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'urlworkaround'
+ )
+ );
+ $title = $unfurled->title ?? $url->name;
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'header',
+ )
+ );
+ $output .= html_writer::tag(
+ 'h3',
+ $url->name,
+ array(
+ 'id' => 'url-workaround-og-title',
+ )
+ );
+ $output .= html_writer::end_tag('div');
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'description',
+ )
+ );
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'image-text-container',
+ )
+ );
+ if (!empty($unfurled->image)) {
+ $output .= html_writer::tag(
+ 'img',
+ '',
+ array(
+ 'width' => 200,
+ 'src' => $unfurled->image,
+ 'alt' => get_string('socialmediametatag:imagealt', 'url').$title,
+ 'onerror' => "arguments[0].currentTarget.style.display='none'",
+ )
+ );
+ } else {
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'icon-container',
+ )
+ );
+ $output .= html_writer::tag(
+ 'img',
+ '',
+ array(
+ 'class' => 'icon',
+ 'src' => $OUTPUT->image_url('i/course-link', 'theme')
+ )
+ );
+ $output .= html_writer::tag(
+ 'span',
+ get_string('linkedurl', 'url'),
+ );
+ $output .= html_writer::end_tag('div');
+ }
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'description-container',
+ )
+ );
+ if (!empty($unfurled->title)) {
+ $output .= html_writer::tag(
+ 'h3',
+ $unfurled->title
+ );
+ }
+ if (!empty($unfurled->description)) {
+ $output .= html_writer::tag(
+ 'p',
+ $unfurled->description
+ );
+ } else {
+ $output .= html_writer::tag(
+ 'p',
+ $url->intro
+ );
+ }
+ $output .= html_writer::end_tag('div');
+ $output .= html_writer::end_tag('div');
+ $output .= html_writer::start_tag(
+ 'div',
+ array(
+ 'class' => 'button-container',
+ )
+ );
+ $output .= html_writer::start_tag(
+ 'a',
+ array(
+ 'target' => '_blank',
+ 'rel' => 'noopener noreferrer',
+ 'class' => 'link',
+ 'href' => $fullurl,
+ 'onclick' => $onclick,
+ )
+ );
+ $output .= get_string('launch', 'url');
+ $output .= html_writer::end_tag('a');
+ $output .= html_writer::end_tag('div');
+ $output .= html_writer::end_tag('div');
+ $output .= html_writer::end_tag('div');
+
+ $output .= $OUTPUT->footer();
+
+ echo $output;
- echo $OUTPUT->footer();
die;
}