This commit is contained in:
Markos Gogoulos
2026-05-07 14:08:18 +03:00
parent 56db5f3907
commit 630eb77173
7 changed files with 65 additions and 33 deletions
@@ -269,21 +269,7 @@ class text_filter extends \core_filters\text_filter {
$view_url = new moodle_url('/filter/mediacms/my_media.php', $view_params);
$launch_url = new moodle_url('/filter/mediacms/launch.php', $view_params);
// Hidden iframe fires the LTI launch silently on every page load.
// When the media owner (teacher) loads the page, EmbedMediaLTIView's
// auto-share logic runs, marking the media as shared — same as for
// regular embedded iframes. Visits by non-owners are harmless.
$hidden_iframe = html_writer::tag('iframe', '', [
'src' => $launch_url->out(false),
'style' => 'display:none;width:0;height:0;border:0;',
'title' => '',
'tabindex' => '-1',
'aria-hidden' => 'true',
]);
return $hidden_iframe . html_writer::tag('a', $text_matches[1], [
return html_writer::tag('a', $text_matches[1], [
'href' => $view_url->out(false),
'target' => '_blank',
'rel' => 'noopener noreferrer',
@@ -7,7 +7,7 @@ import Selectors from './selectors';
import { getLti, getData } from './options';
const PREFS_KEY = 'tiny_mediacms_embed_prefs';
const PREFS_FIELDS = ['showTitle', 'linkTitle', 'showUserAvatar', 'width', 'height'];
const PREFS_FIELDS = ['showTitle', 'linkTitle', 'showUserAvatar', 'width', 'height', 'textLinkOnly'];
export default class IframeEmbed {
editor = null;
@@ -210,6 +210,32 @@ export default class IframeEmbed {
return url.toString();
}
signalShare(values) {
const parsed = this.parseInput(values.url);
if (!parsed || parsed.isGeneric || !parsed.videoId) {
return;
}
const editorData = getData(this.editor);
const baseUrl = parsed.isLtiLaunch
? (editorData?.mediacmsBaseUrl || '')
: parsed.baseUrl;
if (!baseUrl) {
return;
}
const ltiConfig = getLti(this.editor);
const courseId = ltiConfig?.courseId || 0;
fetch(`${baseUrl}/api/v1/media/${parsed.videoId}/share`, {
method: 'POST',
credentials: 'include',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({courseid: courseId}),
}).catch(() => {});
}
savePrefs(values) {
try {
const prefs = {};
@@ -251,7 +277,7 @@ export default class IframeEmbed {
showTitle: getDefault('showTitle'),
linkTitle: getDefault('linkTitle'),
showUserAvatar: getDefault('showUserAvatar'),
textLinkOnly: data.textLinkOnly || false,
textLinkOnly: getDefault('textLinkOnly', false),
startAtEnabled: data.startAtEnabled || false,
startAt: data.startAt || '0:00',
width,
@@ -531,6 +557,7 @@ export default class IframeEmbed {
}
this.savePrefs(values);
this.signalShare(values);
const html = await this.generateIframeHtml(values);
if (html) {
if (this.isUpdating && this.selectedIframe) {