Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Moodle Component Library
19
 *
20
 * Serves the Hugo docs html pages.
21
 *
22
 * @package    tool_componentlibrary
23
 * @copyright  2021 Bas Brands <bas@moodle.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
require_once(__DIR__ . '/../../../config.php');
28
require_once($CFG->dirroot . '/lib/filelib.php');
29
 
30
require_login();
31
require_capability('moodle/site:configview', context_system::instance());
32
 
33
if (empty($relativepath)) {
34
    $relativepath = get_file_argument();
35
}
36
 
37
$args = explode('/', ltrim($relativepath, '/'));
38
 
39
$docs = clean_param($args[0], PARAM_TEXT);
40
$folder = clean_param($args[1], PARAM_TEXT);
41
$section = clean_param($args[2], PARAM_TEXT);
42
 
43
$docsdir = '/' . $CFG->admin . '/tool/componentlibrary/docs/';
44
$cssfile = '/' . $CFG->admin . '/tool/componentlibrary/hugo/dist/css/docs.css';
45
$docspage = '';
46
 
47
$validroots = [
48
    'bootstrap',
49
    'library',
50
    'moodle',
51
];
52
 
53
if (in_array($docs, $validroots)) {
54
    $docspage = implode(
55
        '/',
56
        [
57
            $CFG->dirroot,
58
            $docsdir,
59
            $docs,
60
            $folder,
61
            $section,
62
            'index.html',
63
 
64
        ]
65
    );
66
}
67
 
68
$thispageurl = new moodle_url('/admin/tool/componentlibrary/docspage.php');
69
 
70
$PAGE->set_pagelayout('base');
71
$PAGE->set_url($thispageurl);
72
$PAGE->set_context(context_system::instance());
73
$title = get_string('pluginname', 'tool_componentlibrary');
74
$PAGE->set_heading($title);
75
$PAGE->set_title($title);
76
$PAGE->requires->css($cssfile);
77
$jsonfile = new moodle_url('/admin/tool/componentlibrary/hugo/site/data/my-index.json');
78
$PAGE->requires->js_call_amd('tool_componentlibrary/loader', 'init', ['jsonfile' => $jsonfile->out()]);
79
$PAGE->set_secondary_navigation(false);
80
 
81
if (get_config('core', 'allowthemechangeonurl')) {
82
    $themes = core_component::get_plugin_list('theme');
83
    $themes = array_keys($themes);
84
    $menuthemes = [];
85
    foreach ($themes as $themename) {
86
        $actionurl = new moodle_url($thispageurl . $relativepath, ['theme' => $themename]);
87
        $menuthemes[] = new action_menu_link_secondary($actionurl, null, $themename);
88
    }
89
    $thememenu = new action_menu($menuthemes);
90
    $thememenu->set_menu_trigger($PAGE->theme->name, 'nav-link');
91
    $thememenu->set_owner_selector('change-moodle-theme');
92
    $PAGE->set_headingmenu($OUTPUT->render($thememenu));
93
}
94
 
95
if (!file_exists($docspage)) {
96
    $firstpage = new moodle_url('/admin/tool/componentlibrary/docspage.php/library/getting-started/');
97
    redirect($firstpage);
98
}
99
 
100
echo $OUTPUT->header();
101
if (!file_exists($CFG->dirroot . $docsdir)) {
102
    echo $OUTPUT->render_from_template('tool_componentlibrary/rundocs', (object) []);
103
    exit(0);
104
}
105
// Load the content after the footer that contains the JS for this page.
106
$page = file_get_contents($docspage);
107
$jsdocurl = new moodle_url('/admin/tool/componentlibrary/jsdocspage.php');
108
$page = str_replace('http://JSDOC', $jsdocurl, $page);
109
$page = str_replace('http://MOODLEROOT', $thispageurl, $page);
110
$page = str_replace('MOODLEIMAGEDIR', new moodle_url('/admin/tool/componentlibrary/content/static'), $page);
111
$filtered = str_replace('MOODLEROOT', $thispageurl, $page);
112
$rooturl = new moodle_url('/');
113
$filtered = str_replace('MOODLESITE', $rooturl->out(), $page);
114
echo $filtered;
115
 
116
echo $OUTPUT->footer();