Commit | Line | Data |
---|---|---|
822a1063 | 1 | <?php |
ff95caa8 DM |
2 | |
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
6be7abc7 | 18 | /** |
ff95caa8 | 19 | * Displays help via AJAX call or in a new page |
6be7abc7 | 20 | * |
ff95caa8 DM |
21 | * Use {@link core_renderer::help_icon()} or {@link addHelpButton()} to display |
22 | * the help icon. | |
6be7abc7 | 23 | * |
ff95caa8 DM |
24 | * @copyright 2002 onwards Martin Dougiamas |
25 | * @package core | |
26 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
6be7abc7 | 27 | */ |
53a78cef PS |
28 | |
29 | define('NO_MOODLE_COOKIES', true); | |
30 | ||
ff95caa8 | 31 | require_once(dirname(__FILE__) . '/config.php'); |
6be7abc7 | 32 | |
ff95caa8 | 33 | $identifier = required_param('identifier', PARAM_STRINGID); |
aff24313 | 34 | $component = required_param('component', PARAM_COMPONENT); |
e4c3c7ea | 35 | $lang = required_param('lang', PARAM_LANG); // TODO: maybe split into separate scripts |
259c165d | 36 | $ajax = optional_param('ajax', 0, PARAM_BOOL); |
53a78cef PS |
37 | |
38 | if (!$lang) { | |
39 | $lang = 'en'; | |
40 | } | |
53a78cef | 41 | $SESSION->lang = $lang; // does not actually modify session because we do not use cookies here |
3a915b06 | 42 | |
259c165d | 43 | $sm = get_string_manager(); |
6be7abc7 | 44 | |
259c165d | 45 | $PAGE->set_url('/help.php'); |
5435c9dc | 46 | $PAGE->set_pagelayout('popup'); |
bf0f06b1 | 47 | $PAGE->set_context(context_system::instance()); |
259c165d PS |
48 | |
49 | if ($ajax) { | |
50 | @header('Content-Type: text/plain; charset=utf-8'); | |
53a78cef | 51 | } |
868ca14f | 52 | |
ed8eb15a | 53 | if (!$sm->string_exists($identifier.'_help', $component)) { |
238b8bc9 | 54 | // strings on disk-cache may be dirty - try to rebuild it and check again |
ed8eb15a DM |
55 | $sm->load_component_strings($component, current_language(), true); |
56 | } | |
57 | ||
238b8bc9 ARN |
58 | $data = new stdClass(); |
59 | ||
5435c9dc | 60 | if ($sm->string_exists($identifier.'_help', $component)) { |
a226a972 | 61 | $options = new stdClass(); |
5435c9dc MD |
62 | $options->trusted = false; |
63 | $options->noclean = false; | |
64 | $options->smiley = false; | |
65 | $options->filter = false; | |
66 | $options->para = true; | |
67 | $options->newlines = false; | |
367a75fa | 68 | $options->overflowdiv = !$ajax; |
5435c9dc | 69 | |
238b8bc9 | 70 | $data->heading = format_string(get_string($identifier, $component)); |
5435c9dc | 71 | // Should be simple wiki only MDL-21695 |
238b8bc9 | 72 | $data->text = format_text(get_string($identifier.'_help', $component), FORMAT_MARKDOWN, $options); |
5435c9dc | 73 | |
238b8bc9 ARN |
74 | $helplink = $identifier . '_link'; |
75 | if ($sm->string_exists($helplink, $component)) { // Link to further info in Moodle docs | |
76 | $link = get_string($helplink, $component); | |
5435c9dc | 77 | $linktext = get_string('morehelp'); |
5435c9dc | 78 | |
238b8bc9 ARN |
79 | $data->doclink = new stdClass(); |
80 | $url = new moodle_url(get_docs_url($link)); | |
81 | $data->doclink->link = $url->out(); | |
82 | $data->doclink->linktext = $linktext; | |
83 | $data->doclink->class = ($CFG->doctonewwindow) ? 'helplinkpopup' : ''; | |
84 | ||
85 | $completedoclink = html_writer::tag('div', $OUTPUT->doc_link($link, $linktext), array('class' => 'helpdoclink')); | |
86 | } | |
259c165d | 87 | } else { |
238b8bc9 ARN |
88 | $data->text = html_writer::tag('p', |
89 | html_writer::tag('strong', 'TODO') . ": missing help string [{$identifier}_help, {$component}]"); | |
259c165d PS |
90 | } |
91 | ||
238b8bc9 ARN |
92 | if ($ajax) { |
93 | echo json_encode($data); | |
94 | } else { | |
95 | echo $OUTPUT->header(); | |
96 | if (isset($data->heading)) { | |
97 | echo $OUTPUT->heading($data->heading, 1, 'helpheading'); | |
98 | } | |
99 | echo $data->text; | |
100 | if (isset($completedoclink)) { | |
101 | echo $completedoclink; | |
102 | } | |
259c165d PS |
103 | echo $OUTPUT->footer(); |
104 | } |