@@ -1163,7 +1163,14 @@ public function renderSingle($buffer=false) {
11631163 foreach ($ videos as $ video ) {
11641164 $ media_file = $ video ->media ?? null ;
11651165 echo ('<li typeof="oer:SupportingMaterial" class="tsugi-lessons-module-video"> ' );
1166- if ( is_string ($ media_file ) && is_string ($ media_base ) && is_string ($ media_folder ) &&
1166+ $ kaltura_url = $ this ->kalturaEmbedUrl ($ video );
1167+ if ( $ kaltura_url ) {
1168+ if ( $ nostyle ) {
1169+ self ::nostyleUrl ($ video ->title , $ kaltura_url );
1170+ } else {
1171+ $ this ->renderKalturaOverlay ($ video ->title , $ kaltura_url , false );
1172+ }
1173+ } else if ( is_string ($ media_file ) && is_string ($ media_base ) && is_string ($ media_folder ) &&
11671174 file_exists ($ media_folder . '/ ' . $ media_file ) ) {
11681175 $ media_path = $ media_base . '/ ' . $ media_file ;
11691176?>
@@ -2431,11 +2438,26 @@ public function footer($buffer=false)
24312438// http://bxslider.com/examples/video
24322439?>
24332440<script>
2441+ function tsugiOpenKalturaOverlay(id) {
2442+ var el = document.getElementById(id);
2443+ var iframe = document.getElementById(id + '-iframe');
2444+ if (iframe) {
2445+ var src = iframe.getAttribute('data-src');
2446+ if (src) iframe.src = src;
2447+ }
2448+ if (el) el.style.display = 'block';
2449+ }
2450+ function tsugiCloseKalturaOverlay(id) {
2451+ var el = document.getElementById(id);
2452+ var iframe = document.getElementById(id + '-iframe');
2453+ if (iframe) iframe.src = '';
2454+ if (el) el.style.display = 'none';
2455+ }
24342456$(document).ready(function() {
24352457 $('.w3schools-overlay').on('click', function(event) {
24362458 if ( event.target.id == event.currentTarget.id ) {
24372459 // Stop our embedded YouTube Players
2438- labnolStopPlayers();
2460+ if (typeof labnolStopPlayers === 'function') labnolStopPlayers();
24392461 // https://stackoverflow.com/questions/4071872/html5-video-force-abort-of-buffering
24402462 // https://stackoverflow.com/a/34058996
24412463 $('.w3schools-overlay audio, video').each(function (i,e) {
@@ -2447,6 +2469,10 @@ public function footer($buffer=false)
24472469 this.currentTime = playtime;
24482470
24492471 });
2472+ // Stop Kaltura (and any other) iframes in this overlay
2473+ $(event.currentTarget).find('iframe').each(function() {
2474+ this.src = '';
2475+ });
24502476 event.target.style.display = 'none';
24512477 } else {
24522478 event.stopPropagation();
@@ -2717,6 +2743,51 @@ private function renderItemText($item) {
27172743 echo ("< {$ tag }{$ class }> " .$ text ."</ {$ tag }> \n" );
27182744 }
27192745
2746+ /**
2747+ * Build a Kaltura embed URL from lessons.json kaltura_id + kaltura_embed extension.
2748+ * The extension template must include a literal {id} placeholder.
2749+ *
2750+ * @return string|null Absolute embed URL, or null if unavailable
2751+ */
2752+ private function kalturaEmbedUrl ($ item ) {
2753+ global $ CFG ;
2754+ $ kaltura_id = isset ($ item ->kaltura_id ) ? $ item ->kaltura_id : null ;
2755+ $ template = $ CFG ->getExtension ('kaltura_embed ' , null );
2756+ if ( !is_string ($ kaltura_id ) || $ kaltura_id === '' ) {
2757+ return null ;
2758+ }
2759+ if ( !is_string ($ template ) || $ template === '' || strpos ($ template , '{id} ' ) === false ) {
2760+ return null ;
2761+ }
2762+ return str_replace ('{id} ' , $ kaltura_id , $ template );
2763+ }
2764+
2765+ /**
2766+ * Canvas-style Kaltura modal: title bar link (open in new window) + iframe embed.
2767+ */
2768+ private function renderKalturaOverlay ($ title , $ embed_url , $ with_icon =true ) {
2769+ static $ kaltura_no = 0 ;
2770+ $ kaltura_no = $ kaltura_no + 1 ;
2771+ $ navid = 'kaltura- ' .md5 ($ kaltura_no .$ embed_url );
2772+ $ safe_title = htmlspecialchars ($ title , ENT_QUOTES , 'UTF-8 ' );
2773+ $ safe_url = htmlspecialchars ($ embed_url , ENT_QUOTES , 'UTF-8 ' );
2774+ $ open_lbl = htmlspecialchars (__ ('Open in a new window ' ), ENT_QUOTES , 'UTF-8 ' );
2775+ ?>
2776+ <div id="<?= $ navid ?> " class="w3schools-overlay" role="dialog" aria-modal="true" aria-label="Video: <?= $ safe_title ?> ">
2777+ <div class="w3schools-overlay-content tsugi-kaltura-overlay-content">
2778+ <div class="tsugi-kaltura-titlebar">
2779+ <a href="<?= $ safe_url ?> " target="_blank" rel="noopener noreferrer" class="tsugi-kaltura-title-link"><?= htmlentities ($ title ) ?> </a>
2780+ <a href="<?= $ safe_url ?> " target="_blank" rel="noopener noreferrer" class="tsugi-kaltura-open-new" title="<?= $ open_lbl ?> "><?= $ open_lbl ?> </a>
2781+ <button type="button" class="tsugi-overlay-close tsugi-kaltura-close" aria-label="Close" onclick="tsugiCloseKalturaOverlay('<?= $ navid ?> ');">×</button>
2782+ </div>
2783+ <iframe data-src="<?= $ safe_url ?> " src="" id="<?= $ navid ?> -iframe" title="<?= $ safe_title ?> " class="tsugi-kaltura-iframe" allowfullscreen allow="autoplay *; fullscreen *; encrypted-media *; picture-in-picture *"></iframe>
2784+ <div class="clear" style="clear:both;"></div>
2785+ </div>
2786+ </div>
2787+ <button type="button" class="tsugi-video-play-btn" onclick="tsugiOpenKalturaOverlay('<?= $ navid ?> ');"><?php if ( $ with_icon ) { self ::renderItemIcon ('video ' ); } ?> <?= htmlentities ($ title ) ?> </button>
2788+ <?php
2789+ }
2790+
27202791 /**
27212792 * Render a single video item
27222793 */
@@ -2726,10 +2797,17 @@ private function renderItemVideo($item, $nostyle=false) {
27262797 $ media_folder = $ CFG ->getExtension ('media_folder ' , null );
27272798 $ media_base = $ CFG ->getExtension ('media_base ' , null );
27282799 $ media_file = isset ($ item ->media ) ? $ item ->media : null ;
2800+ $ kaltura_url = $ this ->kalturaEmbedUrl ($ item );
27292801
27302802 echo ('<li typeof="oer:SupportingMaterial" class="tsugi-lessons-module-video"> ' );
27312803
2732- if ( is_string ($ media_file ) && is_string ($ media_base ) && is_string ($ media_folder ) &&
2804+ if ( $ kaltura_url ) {
2805+ if ( $ nostyle ) {
2806+ self ::nostyleUrl ($ item ->title , $ kaltura_url );
2807+ } else {
2808+ $ this ->renderKalturaOverlay ($ item ->title , $ kaltura_url , true );
2809+ }
2810+ } else if ( is_string ($ media_file ) && is_string ($ media_base ) && is_string ($ media_folder ) &&
27332811 file_exists ($ media_folder . '/ ' . $ media_file ) ) {
27342812 $ media_path = $ media_base . '/ ' . $ media_file ;
27352813 echo ('<a href=" ' .$ media_path .'" target="_blank" rel="noopener noreferrer" style="display: inline-flex; align-items: center;"> ' );
0 commit comments