This commit is contained in:
Markos Gogoulos
2026-02-12 12:42:26 +02:00
parent 209cede39c
commit 364d22dd8e
4 changed files with 125 additions and 14 deletions

View File

@@ -80,7 +80,7 @@ class text_filter extends \core_filters\text_filter {
* Callback for [mediacms:TOKEN]
*/
public function callback_tag($matches) {
return $this->generate_iframe($matches[1]);
return $this->generate_iframe($matches[1], []);
}
/**
@@ -99,25 +99,51 @@ class text_filter extends \core_filters\text_filter {
// We'll check this in the main filter method instead
$token = $matches[3];
return $this->generate_iframe($token);
// Extract additional embed parameters from the URL
$embed_params = [];
$full_url = $matches[1];
$parsed_url = parse_url($full_url);
if (isset($parsed_url['query'])) {
parse_str($parsed_url['query'], $query_params);
// Extract embed-related parameters
$supported_params = ['showTitle', 'showRelated', 'showUserAvatar', 'linkTitle', 't'];
foreach ($supported_params as $param) {
if (isset($query_params[$param])) {
$embed_params[$param] = $query_params[$param];
}
}
}
return $this->generate_iframe($token, $embed_params);
}
/**
* Generate the Iframe pointing to launch.php
*/
private function generate_iframe($token) {
private function generate_iframe($token, $embed_params = []) {
global $CFG, $COURSE;
$width = get_config('filter_mediacms', 'iframewidth') ?: 960;
$height = get_config('filter_mediacms', 'iframeheight') ?: 540;
$courseid = $COURSE->id ?? 0;
$launchurl = new moodle_url('/filter/mediacms/launch.php', [
// Build launch URL parameters
$launch_params = [
'token' => $token,
'courseid' => $courseid,
'width' => $width,
'height' => $height
]);
];
// Add embed parameters if provided
foreach ($embed_params as $key => $value) {
$launch_params[$key] = $value;
}
$launchurl = new moodle_url('/filter/mediacms/launch.php', $launch_params);
$iframe = html_writer::tag('iframe', '', [
'src' => $launchurl->out(false),

View File

@@ -77,6 +77,13 @@ $courseid = optional_param('courseid', 0, PARAM_INT);
$height = optional_param('height', 0, PARAM_INT);
$width = optional_param('width', 0, PARAM_INT);
// Extract embed parameters
$showTitle = optional_param('showTitle', '', PARAM_TEXT);
$showRelated = optional_param('showRelated', '', PARAM_TEXT);
$showUserAvatar = optional_param('showUserAvatar', '', PARAM_TEXT);
$linkTitle = optional_param('linkTitle', '', PARAM_TEXT);
$startTime = optional_param('t', '', PARAM_TEXT);
// Get configuration
$mediacmsurl = get_config('filter_mediacms', 'mediacmsurl');
$ltitoolid = get_config('filter_mediacms', 'ltitoolid');
@@ -128,16 +135,54 @@ $cm = get_coursemodule_from_id('lti', $dummy_cmid, 0, false, MUST_EXIST);
$instance = $DB->get_record('lti', ['id' => $cm->instance], '*', MUST_EXIST);
// Override with our media token for THIS launch only (doesn't save to DB)
$instance->instructorcustomparameters = "media_friendly_token=" . $mediatoken;
$custom_params = ["media_friendly_token=" . $mediatoken];
// Add embed parameters if provided
if (!empty($showTitle)) {
$custom_params[] = "embed_show_title=" . $showTitle;
}
if (!empty($showRelated)) {
$custom_params[] = "embed_show_related=" . $showRelated;
}
if (!empty($showUserAvatar)) {
$custom_params[] = "embed_show_user_avatar=" . $showUserAvatar;
}
if (!empty($linkTitle)) {
$custom_params[] = "embed_link_title=" . $linkTitle;
}
if (!empty($startTime)) {
$custom_params[] = "embed_start_time=" . $startTime;
}
$instance->instructorcustomparameters = implode("\n", $custom_params);
$instance->name = 'MediaCMS Video: ' . $mediatoken;
// Set up page
$PAGE->set_url(new moodle_url('/filter/mediacms/launch.php', [
$page_params = [
'token' => $mediatoken,
'courseid' => $courseid,
'width' => $width,
'height' => $height
]));
];
// Add embed parameters to page URL if provided
if (!empty($showTitle)) {
$page_params['showTitle'] = $showTitle;
}
if (!empty($showRelated)) {
$page_params['showRelated'] = $showRelated;
}
if (!empty($showUserAvatar)) {
$page_params['showUserAvatar'] = $showUserAvatar;
}
if (!empty($linkTitle)) {
$page_params['linkTitle'] = $linkTitle;
}
if (!empty($startTime)) {
$page_params['t'] = $startTime;
}
$PAGE->set_url(new moodle_url('/filter/mediacms/launch.php', $page_params));
$PAGE->set_context($context);
$PAGE->set_pagelayout('embedded');
$PAGE->set_title('MediaCMS');

View File

@@ -33,7 +33,8 @@ import {getButtonImage} from 'editor_tiny/utils';
const isIframe = (node) => node.nodeName.toLowerCase() === 'iframe' ||
(node.classList && node.classList.contains('tiny-iframe-responsive')) ||
(node.classList && node.classList.contains('tiny-mediacms-iframe-wrapper'));
(node.classList && node.classList.contains('tiny-mediacms-iframe-wrapper')) ||
(node.nodeName.toLowerCase() === 'a' && node.getAttribute('data-mediacms-textlink') === 'true');
/**
* Wrap iframes with overlay containers that allow hover detection.
@@ -227,8 +228,14 @@ const registerIframeCommand = (editor, iframeButtonText, iframeButtonImage) => {
tooltip: iframeButtonText,
onAction: handleIframeAction,
onSetup: api => {
const selector = [
'iframe:not([data-mce-object]):not([data-mce-placeholder])',
'.tiny-iframe-responsive',
'.tiny-mediacms-iframe-wrapper',
'a[data-mediacms-textlink="true"]'
].join(',');
return editor.selection.selectorChangedWithUnbind(
'iframe:not([data-mce-object]):not([data-mce-placeholder]),.tiny-iframe-responsive,.tiny-mediacms-iframe-wrapper',
selector,
api.setActive
).unbind;
}

View File

@@ -281,13 +281,18 @@ export default class IframeEmbed {
}
/**
* Get the currently selected iframe in the editor.
* Get the currently selected iframe or text link in the editor.
*
* @returns {HTMLElement|null} The iframe element or null
* @returns {HTMLElement|null} The iframe element, text link, or null
*/
getSelectedIframe() {
const node = this.editor.selection.getNode();
// Check if it's a text-only link
if (node.nodeName.toLowerCase() === 'a' && node.getAttribute('data-mediacms-textlink') === 'true') {
return node;
}
if (node.nodeName.toLowerCase() === 'iframe') {
return node;
}
@@ -306,19 +311,47 @@ export default class IframeEmbed {
return wrapper.querySelector('iframe');
}
// Check if we're inside a text-only link
const textLink = node.closest('a[data-mediacms-textlink="true"]');
if (textLink) {
return textLink;
}
return null;
}
/**
* Get current iframe data for editing.
* Get current iframe or text link data for editing.
*
* @returns {Object|null} Current iframe data or null
* @returns {Object|null} Current iframe/link data or null
*/
getCurrentIframeData() {
if (!this.selectedIframe) {
return null;
}
// Check if it's a text-only link
if (this.selectedIframe.nodeName.toLowerCase() === 'a' &&
this.selectedIframe.getAttribute('data-mediacms-textlink') === 'true') {
const href = this.selectedIframe.getAttribute('href');
const parsed = this.parseInput(href);
return {
url: href,
width: 560,
height: 315,
showTitle: parsed?.showTitle ?? true,
linkTitle: parsed?.linkTitle ?? true,
showRelated: parsed?.showRelated ?? true,
showUserAvatar: parsed?.showUserAvatar ?? true,
responsive: true,
textLinkOnly: true,
startAtEnabled: parsed?.startAt !== null,
startAt: parsed?.startAt || '0:00',
};
}
// Handle iframe
const src = this.selectedIframe.getAttribute('src');
const parsed = this.parseInput(src);