This commit is contained in:
Markos Gogoulos
2026-03-04 13:09:19 +02:00
parent 814a7d3cee
commit 692b6b5f09
2 changed files with 31 additions and 35 deletions

View File

@@ -185,7 +185,7 @@ class text_filter extends \core_filters\text_filter {
* @return string Transformed HTML (or original if token cannot be extracted) * @return string Transformed HTML (or original if token cannot be extracted)
*/ */
private function transform_textlink($anchor_html) { private function transform_textlink($anchor_html) {
global $COURSE, $PAGE; global $COURSE;
// Extract href. // Extract href.
if (!preg_match('/href=["\']([^"\']+)["\']/', $anchor_html, $href_matches)) { if (!preg_match('/href=["\']([^"\']+)["\']/', $anchor_html, $href_matches)) {
@@ -205,36 +205,15 @@ class text_filter extends \core_filters\text_filter {
return $anchor_html; return $anchor_html;
} }
$launch_url = new moodle_url('/filter/mediacms/launch.php', [ $view_url = new moodle_url('/filter/mediacms/my_media.php', [
'token' => $token, 'token' => $token,
'courseid' => isset($COURSE->id) ? (int)$COURSE->id : 0, 'courseid' => isset($COURSE->id) ? (int)$COURSE->id : 0,
'show_media_page' => 'true',
]); ]);
if (!self::$textlink_js_added) {
self::$textlink_js_added = true;
$PAGE->requires->js_init_code(
'document.addEventListener("click",function(e){'
. 'var a=e.target.closest("a.mediacms-textlink-launch");if(!a)return;'
. 'e.preventDefault();'
. 'var f=document.createElement("iframe");'
. 'f.src=a.dataset.launchUrl;'
. 'f.style.cssText="width:100%;height:480px;border:none;display:block;";'
. 'f.allowFullscreen=true;'
. 'f.setAttribute("allow","autoplay *; fullscreen *; encrypted-media *;");'
. 'a.parentNode.replaceChild(f,a);'
. '});',
false
);
}
return html_writer::tag('a', $text_matches[1], [ return html_writer::tag('a', $text_matches[1], [
'href' => '#', 'href' => $view_url->out(false),
'class' => 'mediacms-textlink-launch', 'target' => '_blank',
'data-launch-url' => $launch_url->out(false), 'rel' => 'noopener noreferrer',
]); ]);
} }
/** @var bool Whether the inline-iframe JS has already been added to the page. */
private static $textlink_js_added = false;
} }

View File

@@ -9,28 +9,45 @@
require_once(__DIR__ . '/../../config.php'); require_once(__DIR__ . '/../../config.php');
global $SITE, $PAGE, $OUTPUT, $USER; global $SITE, $PAGE, $OUTPUT, $USER, $COURSE;
require_login(); require_login();
$context = context_system::instance(); $token = optional_param('token', '', PARAM_ALPHANUMEXT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$context = context_system::instance();
$PAGE->set_context($context); $PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/filter/mediacms/my_media.php'));
$PAGE->set_course($SITE); $PAGE->set_course($SITE);
$PAGE->set_pagelayout('mydashboard'); $PAGE->set_pagelayout('mydashboard');
$PAGE->set_title(get_string('mymedia', 'filter_mediacms'));
$PAGE->set_heading(get_string('mymedia', 'filter_mediacms')); if ($token) {
$PAGE->set_url(new moodle_url('/filter/mediacms/my_media.php', ['token' => $token]));
$PAGE->set_title('MediaCMS');
$PAGE->set_heading('MediaCMS');
$launch_params = [
'token' => $token,
'courseid' => $courseid ?: ($COURSE->id ?? 0),
'show_media_page' => 'true',
];
$src = (new moodle_url('/filter/mediacms/launch.php', $launch_params))->out(false);
} else {
$PAGE->set_url(new moodle_url('/filter/mediacms/my_media.php'));
$PAGE->set_title(get_string('mymedia', 'filter_mediacms'));
$PAGE->set_heading(get_string('mymedia', 'filter_mediacms'));
$src = (new moodle_url('/filter/mediacms/lti_launch.php'))->out(false);
}
echo $OUTPUT->header(); echo $OUTPUT->header();
$attr = [ echo html_writer::tag('iframe', '', [
'id' => 'contentframe', 'id' => 'contentframe',
'src' => (new moodle_url('/filter/mediacms/lti_launch.php'))->out(false), 'src' => $src,
'allowfullscreen' => 'true', 'allowfullscreen' => 'true',
'allow' => 'autoplay *; fullscreen *; encrypted-media *; camera *; microphone *;', 'allow' => 'autoplay *; fullscreen *; encrypted-media *; camera *; microphone *;',
'style' => 'border:none;display:block;width:100%;height:calc(100vh - 120px);', 'style' => 'border:none;display:block;width:100%;height:calc(100vh - 120px);',
]; ]);
echo html_writer::tag('iframe', '', $attr);
echo $OUTPUT->footer(); echo $OUTPUT->footer();