weekly release 2.2dev
[moodle.git] / help.php
... / ...
CommitLineData
1<?php
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
18/**
19 * Displays help via AJAX call or in a new page
20 *
21 * Use {@link core_renderer::help_icon()} or {@link addHelpButton()} to display
22 * the help icon.
23 *
24 * @copyright 2002 onwards Martin Dougiamas
25 * @package core
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28
29define('NO_MOODLE_COOKIES', true);
30
31require_once(dirname(__FILE__) . '/config.php');
32
33$identifier = required_param('identifier', PARAM_STRINGID);
34$component = required_param('component', PARAM_SAFEDIR);
35$lang = required_param('lang', PARAM_LANG); // TODO: maybe split into separate scripts
36$ajax = optional_param('ajax', 0, PARAM_BOOL);
37
38if (!$lang) {
39 $lang = 'en';
40}
41$SESSION->lang = $lang; // does not actually modify session because we do not use cookies here
42
43$sm = get_string_manager();
44
45$PAGE->set_url('/help.php');
46$PAGE->set_pagelayout('popup');
47$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
48
49if ($ajax) {
50 @header('Content-Type: text/plain; charset=utf-8');
51} else {
52 echo $OUTPUT->header();
53}
54
55if (!$sm->string_exists($identifier.'_help', $component)) {
56 // strings on-diskc cache may be dirty - try to rebuild it and check again
57 $sm->load_component_strings($component, current_language(), true);
58}
59
60if ($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;
69
70 echo $OUTPUT->heading(format_string(get_string($identifier, $component)), 1, 'helpheading');
71 // Should be simple wiki only MDL-21695
72 echo format_text(get_string($identifier.'_help', $component), FORMAT_MARKDOWN, $options);
73
74 if ($sm->string_exists($identifier.'_link', $component)) { // Link to further info in Moodle docs
75 $link = get_string($identifier.'_link', $component);
76 $linktext = get_string('morehelp');
77 echo '<div class="helpdoclink">'.$OUTPUT->doc_link($link, $linktext).'</div>';
78 }
79
80} else {
81 echo "<p><strong>TODO</strong>: missing help string [{$identifier}_help, $component]</p>";
82}
83
84if (!$ajax) {
85 echo $OUTPUT->footer();
86}