Repository navigation
Expand file tree
/
Copy pathscript.php
More file actions
42 lines (39 loc) · 1.64 KB
/
Copy pathscript.php
File metadata and controls
42 lines (39 loc) · 1.64 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
<?php
// This file is part of Moodle - https://moodle.org/
/**
* Native script entry point for Script Manager.
*
* @package local_scriptmanager
* @copyright 2026 Andreas Giesen <andreas@108design.com>
* @license 108design source-available software license; see LICENSE.md
*/
// This file is part of a 108design source-available software product.
//
// Copyright (C) 2026 Andreas Giesen <andreas@108design.com>.
//
// Use and modification are permitted only under the Software License included
// with this distribution. See LICENSE.md for the full terms.
define('NO_MOODLE_COOKIES', true);
require_once(__DIR__ . '/../../config.php');
if (!\local_scriptmanager\local\authority::active()) {
http_response_code(404);
exit;
}
$scriptid = required_param('id', PARAM_INT);
$versionid = required_param('version', PARAM_INT);
$sql = 'SELECT v.*, s.identifier FROM {local_scriptmanager_scriptver} v
JOIN {local_scriptmanager_script} s ON s.id = v.scriptid
WHERE v.id = :versionid AND v.scriptid = :scriptid AND s.enabled = 1';
$version = $DB->get_record_sql($sql, ['versionid' => $versionid, 'scriptid' => $scriptid]);
if (!$version) {
http_response_code(404);
exit;
}
header('Content-Type: application/javascript; charset=utf-8');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: public, max-age=31536000, immutable');
$identifier = json_encode($version->identifier, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
echo "require(['local_scriptmanager/script_runtime'],function(runtime){'use strict';runtime.register({id:" .
$identifier . ",run:function(context){\n";
echo $version->code;
echo "\n}});});";