Repository navigation
Expand file tree
/
Copy pathlib.php
More file actions
102 lines (84 loc) · 3.54 KB
/
Copy pathlib.php
File metadata and controls
102 lines (84 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library functions for Cloudflare Stream plugin
*
* @package local_cloudflarestream
* @copyright 2025 Your Name
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
function local_cloudflarestream_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
global $DB;
if (!get_config('local_cloudflarestream', 'enabled')) {
return false;
}
$fs = get_file_storage();
$itemid = array_shift($args);
$filename = array_pop($args);
$filepath = $args ? '/' . implode('/', $args) . '/' : '/';
$file = $fs->get_file($context->id, 'local_cloudflarestream', $filearea, $itemid, $filepath, $filename);
if (!$file || $file->is_directory()) {
return false;
}
$streamvideo = \local_cloudflarestream\video_manager::get_stream_video_by_fileid($file->get_id());
if ($streamvideo && $streamvideo->status === 'ready') {
$playerurl = \local_cloudflarestream\video_manager::get_player_url($streamvideo->streamid);
if ($playerurl) {
redirect($playerurl);
die();
}
}
send_stored_file($file, null, 0, $forcedownload, $options);
}
function local_cloudflarestream_before_standard_html_head() {
global $PAGE;
if (!get_config('local_cloudflarestream', 'enabled')) {
return '';
}
if ($PAGE->pagelayout === 'embedded' || $PAGE->pagelayout === 'popup') {
return '';
}
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$(document).ready(function() {
// Find all video elements and check if they have Stream versions
$('video').each(function() {
var video = $(this);
var src = video.attr('src') || video.find('source').attr('src');
if (src && src.indexOf('pluginfile.php') > -1) {
// This is a Moodle file, check if we have a Stream version
$.ajax({
url: M.cfg.wwwroot + '/local/cloudflarestream/ajax.php',
data: {
action: 'check_stream_video',
url: src,
sesskey: M.cfg.sesskey
},
success: function(response) {
if (response.success && response.embed_code) {
// Replace video with Stream player
video.replaceWith(response.embed_code);
}
}
});
}
});
});
});
");
return '';
}