3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Displays help via AJAX call or in a new page
21 * Use {@link core_renderer::help_icon()} or {@link addHelpButton()} to display
24 * @copyright 2002 onwards Martin Dougiamas
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 define('NO_MOODLE_COOKIES', true);
31 require_once(dirname(__FILE__
) . '/config.php');
33 $identifier = required_param('identifier', PARAM_STRINGID
);
34 $component = required_param('component', PARAM_COMPONENT
);
35 $lang = required_param('lang', PARAM_LANG
); // TODO: maybe split into separate scripts
36 $ajax = optional_param('ajax', 0, PARAM_BOOL
);
41 $SESSION->lang
= $lang; // does not actually modify session because we do not use cookies here
43 $sm = get_string_manager();
45 $PAGE->set_url('/help.php');
46 $PAGE->set_pagelayout('popup');
47 $PAGE->set_context(context_system
::instance());
50 @header
('Content-Type: text/plain; charset=utf-8');
53 if (!$sm->string_exists($identifier.'_help', $component)) {
54 // strings on disk-cache may be dirty - try to rebuild it and check again
55 $sm->load_component_strings($component, current_language(), true);
58 $data = new stdClass();
60 if ($sm->string_exists($identifier.'_help', $component)) {
61 $options = new stdClass();
62 $options->trusted
= false;
63 $options->noclean
= false;
64 $options->smiley
= false;
65 $options->filter
= false;
66 $options->para
= true;
67 $options->newlines
= false;
68 $options->overflowdiv
= !$ajax;
70 $data->heading
= format_string(get_string($identifier, $component));
71 // Should be simple wiki only MDL-21695
72 $data->text
= format_text(get_string($identifier.'_help', $component), FORMAT_MARKDOWN
, $options);
74 $helplink = $identifier . '_link';
75 if ($sm->string_exists($helplink, $component)) { // Link to further info in Moodle docs
76 $link = get_string($helplink, $component);
77 $linktext = get_string('morehelp');
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' : '';
85 $completedoclink = html_writer
::tag('div', $OUTPUT->doc_link($link, $linktext), array('class' => 'helpdoclink'));
88 $data->text
= html_writer
::tag('p',
89 html_writer
::tag('strong', 'TODO') . ": missing help string [{$identifier}_help, {$component}]");
93 echo json_encode($data);
95 echo $OUTPUT->header();
96 if (isset($data->heading
)) {
97 echo $OUTPUT->heading($data->heading
, 1, 'helpheading');
100 if (isset($completedoclink)) {
101 echo $completedoclink;
103 echo $OUTPUT->footer();