2004-09-29 18:19:39 +00:00
|
|
|
<?php
|
2006-08-22 22:04:06 +00:00
|
|
|
/**
|
|
|
|
* help.php - Displays help page.
|
|
|
|
*
|
|
|
|
* Prints a very simple page and includes
|
|
|
|
* page content or a string from elsewhere.
|
|
|
|
* Usually this will appear in a popup
|
|
|
|
* See {@link helpbutton()} in {@link lib/moodlelib.php}
|
|
|
|
*
|
|
|
|
* @author Martin Dougiamas
|
|
|
|
* @package moodlecore
|
|
|
|
*/
|
|
|
|
require_once('config.php');
|
|
|
|
|
|
|
|
// Get URL parameters.
|
2009-03-30 02:21:27 +00:00
|
|
|
$file = optional_param('file', '', PARAM_PATH);
|
|
|
|
$text = optional_param('text', 'No text to display', PARAM_CLEAN);
|
2006-08-22 22:04:06 +00:00
|
|
|
$module = optional_param('module', 'moodle', PARAM_ALPHAEXT);
|
|
|
|
$forcelang = optional_param('forcelang', '', PARAM_SAFEDIR);
|
2008-01-19 22:00:39 +00:00
|
|
|
$skiplocal = optional_param('skiplocal', 0, PARAM_INT); // shall _local help files be skipped?
|
2009-07-27 10:33:00 +00:00
|
|
|
$fortooltip = optional_param('fortooltip', 0, PARAM_INT);
|
2006-08-22 22:04:06 +00:00
|
|
|
|
2009-06-12 12:08:25 +00:00
|
|
|
$PAGE->set_course($COURSE);
|
|
|
|
|
2009-10-15 03:43:28 +00:00
|
|
|
$url = new moodle_url($CFG->wwwroot.'/help.php');
|
|
|
|
if ($file !== '') {
|
|
|
|
$url->param('file', $file);
|
|
|
|
}
|
|
|
|
if ($text !== 'No text to display') {
|
|
|
|
$url->param('text', $text);
|
|
|
|
}
|
|
|
|
if ($module !== 'moodle') {
|
|
|
|
$url->param('module', $module);
|
|
|
|
}
|
|
|
|
if ($forcelang !== '') {
|
|
|
|
$url->param('forcelang', $forcelang);
|
|
|
|
}
|
|
|
|
if ($skiplocal !== 0) {
|
|
|
|
$url->param('skiplocal', $skiplocal);
|
|
|
|
}
|
|
|
|
if ($fortooltip !== 0) {
|
|
|
|
$url->param('fortooltip', $fortooltip);
|
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
// We look for the help to display in lots of different places, and
|
|
|
|
// only display an error at the end if we can't find the help file
|
|
|
|
// anywhere. This variable tracks that.
|
|
|
|
$helpfound = false;
|
|
|
|
|
2008-04-10 11:50:52 +00:00
|
|
|
// Buffer output so that we can examine it later to extract metadata (page title)
|
|
|
|
ob_start();
|
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
if (!empty($file)) {
|
|
|
|
// The help to display is from a help file.
|
2009-03-30 02:21:27 +00:00
|
|
|
list($filepath, $foundlang) = string_manager::instance()->find_help_file($file, $module, $forcelang, $skiplocal);
|
2006-08-22 22:12:17 +00:00
|
|
|
|
2009-03-30 02:21:27 +00:00
|
|
|
if ($filepath) {
|
|
|
|
$helpfound = true;
|
|
|
|
@include($filepath); // The actual helpfile
|
2007-01-12 12:29:42 +00:00
|
|
|
|
2009-03-30 02:21:27 +00:00
|
|
|
// Now, we process some special cases.
|
|
|
|
if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) {
|
|
|
|
include_help_for_each_module($file, $forcelang, $skiplocal);
|
|
|
|
}
|
|
|
|
if ($module == 'question' && $file == 'types.html') {
|
|
|
|
include_help_for_each_qtype();
|
2006-08-22 22:04:06 +00:00
|
|
|
}
|
2007-01-12 12:29:42 +00:00
|
|
|
|
2009-03-30 02:21:27 +00:00
|
|
|
// The remaining horrible hardcoded special cases should be delegated to modules somehow.
|
|
|
|
if ($module == 'moodle' && $file == 'assignment/types.html') { // ASSIGNMENTS
|
|
|
|
include_help_for_each_assignment_type($forcelang, $skiplocal);
|
2006-08-22 22:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The help to display was given as an argument to this function.
|
|
|
|
echo '<p>'.s($text).'</p>'; // This param was already cleaned
|
|
|
|
$helpfound = true;
|
|
|
|
}
|
2004-09-29 18:19:39 +00:00
|
|
|
|
2008-04-10 11:50:52 +00:00
|
|
|
// Finish buffer
|
2009-03-30 02:21:27 +00:00
|
|
|
$output = ob_get_contents();
|
2009-07-27 10:33:00 +00:00
|
|
|
|
2008-04-10 11:50:52 +00:00
|
|
|
ob_end_clean();
|
|
|
|
|
2009-07-27 10:33:00 +00:00
|
|
|
if ($fortooltip) {
|
|
|
|
echo shorten_text($output, 400, false, '<span class="readmore">' . get_string('clickhelpiconformoreinfo') . '</span>');
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2008-04-10 11:50:52 +00:00
|
|
|
// Determine title
|
2009-03-30 02:21:27 +00:00
|
|
|
$title = get_string('help'); // Default is just 'Help'
|
|
|
|
$matches = array();
|
2008-04-10 11:50:52 +00:00
|
|
|
// You can include a <title> tag to override the standard behaviour:
|
|
|
|
// 'Help - title contents'. Otherwise it looks for the text of the first
|
|
|
|
// heading: 'Help - heading text'. If there aren't even any headings
|
|
|
|
// you just get 'Help'
|
2009-03-30 02:21:27 +00:00
|
|
|
if (preg_match('~^(.*?)<title>(.*?)</title>(.*)$~s', $output, $matches)) {
|
2008-04-10 11:50:52 +00:00
|
|
|
// Extract title
|
2009-03-30 02:21:27 +00:00
|
|
|
$title = $title.' - '.$matches[2];
|
2008-04-10 11:50:52 +00:00
|
|
|
// Strip title from output
|
2009-03-30 02:21:27 +00:00
|
|
|
$output = $matches[1].$matches[3];
|
2008-04-10 11:50:52 +00:00
|
|
|
} else if(preg_match('~<h[0-9]+(\s[^>]*)?>(.*?)</h[0-9]+>~s',$output,$matches)) {
|
|
|
|
// Use first heading as title (obviously leave it in output too). Strip
|
|
|
|
// any tags from inside
|
2009-03-30 02:21:27 +00:00
|
|
|
$matches[2] = preg_replace('~<[^>]*>~s','',$matches[2]);
|
|
|
|
$title = $title.' - '.$matches[2];
|
2008-04-10 11:50:52 +00:00
|
|
|
}
|
|
|
|
|
2008-04-30 03:49:12 +00:00
|
|
|
// use ##emoticons_html## to replace the emoticons documentation
|
|
|
|
if(preg_match('~(##emoticons_html##)~', $output, $matches)) {
|
2008-09-25 10:07:11 +00:00
|
|
|
$output = preg_replace('~(##emoticons_html##)~', get_emoticons_list_for_help_file(), $output);
|
2008-04-30 03:49:12 +00:00
|
|
|
}
|
|
|
|
|
2008-04-10 11:50:52 +00:00
|
|
|
// Do the main output.
|
2009-10-15 03:43:28 +00:00
|
|
|
$PAGE->set_generaltype('popup');
|
2009-09-07 07:20:14 +00:00
|
|
|
$PAGE->set_title($title);
|
|
|
|
echo $OUTPUT->header();
|
2009-08-18 05:20:12 +00:00
|
|
|
echo $OUTPUT->box_start();
|
2008-04-10 11:50:52 +00:00
|
|
|
print $output;
|
2009-08-18 05:20:12 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2002-07-21 08:34:25 +00:00
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
// Display an error if necessary.
|
|
|
|
if (!$helpfound) {
|
2009-08-18 05:20:12 +00:00
|
|
|
echo $OUTPUT->notification('Help file "'. $file .'" could not be found!');
|
2006-08-22 22:04:06 +00:00
|
|
|
}
|
2002-10-13 10:06:01 +00:00
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
// End of page.
|
2009-08-06 02:52:39 +00:00
|
|
|
echo $OUTPUT->close_window_button();
|
2009-03-30 02:21:27 +00:00
|
|
|
echo '<p class="helpindex"><a href="help.php?file=index.html">'. get_string('helpindex') .'</a></p>';
|
2009-03-02 14:14:19 +00:00
|
|
|
|
|
|
|
// Offer a link to the alternative help file language
|
2009-03-30 02:21:27 +00:00
|
|
|
$currentlang = current_language();
|
2009-03-30 06:11:32 +00:00
|
|
|
if ($file && $helpfound && ($foundlang != 'en_utf8' || ($forcelang == 'en_utf8' && current_language() != 'en_utf8'))) {
|
2009-03-30 02:21:27 +00:00
|
|
|
$url = new moodle_url();
|
|
|
|
if ($foundlang != 'en_utf8') {
|
|
|
|
$url->param('forcelang', 'en_utf8');
|
|
|
|
$nextlangname = get_string('english');
|
2009-03-02 14:14:19 +00:00
|
|
|
} else {
|
2009-03-30 02:21:27 +00:00
|
|
|
$url->param('forcelang', $currentlang);
|
2009-03-02 14:14:19 +00:00
|
|
|
$nextlangname = get_string('thislanguage');
|
|
|
|
}
|
2009-03-30 02:21:27 +00:00
|
|
|
echo '<p><a href="' . $url->out() . '">' . get_string('showthishelpinlanguage', 'moodle', $nextlangname) . '</a></p>';
|
2009-03-02 14:14:19 +00:00
|
|
|
}
|
2003-10-21 02:30:42 +00:00
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
$CFG->docroot = ''; // We don't want a doc link here
|
2009-08-06 14:21:34 +00:00
|
|
|
echo $OUTPUT->footer();
|
2006-08-22 22:04:06 +00:00
|
|
|
|
|
|
|
function file_exists_and_readable($filepath) {
|
|
|
|
return file_exists($filepath) and is_file($filepath) and is_readable($filepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some functions for handling special cases ========================================
|
|
|
|
|
2009-03-30 02:21:27 +00:00
|
|
|
function include_help_for_each_module($file, $forcelang, $skiplocal) {
|
2008-05-15 21:40:00 +00:00
|
|
|
global $CFG, $DB;
|
2006-08-22 22:04:06 +00:00
|
|
|
|
2009-03-30 02:21:27 +00:00
|
|
|
if (!$modules = $DB->get_records('modules', array('visible'=> 1))) {
|
|
|
|
print_error('nomodules', 'debug'); // Should never happen
|
2006-08-22 22:04:06 +00:00
|
|
|
}
|
2009-03-30 02:21:27 +00:00
|
|
|
|
|
|
|
// Horrible hack to show the help about grades here too.
|
2008-03-21 15:05:51 +00:00
|
|
|
$grade = new stdClass();
|
|
|
|
$grade->name = 'grade';
|
|
|
|
$modules[] = $grade;
|
2006-08-22 22:04:06 +00:00
|
|
|
|
|
|
|
foreach ($modules as $mod) {
|
|
|
|
$strmodulename = get_string('modulename', $mod->name);
|
|
|
|
$modulebyname[$strmodulename] = $mod;
|
|
|
|
}
|
2008-01-07 16:46:35 +00:00
|
|
|
ksort($modulebyname, SORT_LOCALE_STRING);
|
2006-08-22 22:04:06 +00:00
|
|
|
|
|
|
|
foreach ($modulebyname as $mod) {
|
2009-03-30 02:21:27 +00:00
|
|
|
list($filepath, $foundlang) = string_manager::instance()->find_help_file($file, $mod->name, $forcelang, $skiplocal);
|
|
|
|
if ($filepath) {
|
|
|
|
echo '<hr />';
|
|
|
|
include($filepath);
|
2002-07-21 08:34:25 +00:00
|
|
|
}
|
2003-06-12 11:35:12 +00:00
|
|
|
}
|
2006-08-22 22:04:06 +00:00
|
|
|
}
|
2003-06-12 11:35:12 +00:00
|
|
|
|
2009-02-26 07:07:40 +00:00
|
|
|
function include_help_for_each_qtype() {
|
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir . '/questionlib.php');
|
|
|
|
global $QTYPES;
|
|
|
|
$types = question_type_menu();
|
|
|
|
$fakeqtypes = array();
|
|
|
|
foreach ($types as $qtype => $localizedname) {
|
|
|
|
if ($QTYPES[$qtype]->is_real_question_type()) {
|
|
|
|
include_help_for_qtype($qtype, $localizedname);
|
|
|
|
} else {
|
|
|
|
$fakeqtypes[$qtype] = $localizedname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($fakeqtypes as $qtype => $localizedname) {
|
|
|
|
include_help_for_qtype($qtype, $localizedname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function include_help_for_qtype($qtype, $localizedname) {
|
|
|
|
echo '<h2>' . $localizedname . "</h2>\n\n";
|
|
|
|
echo '<p>' . get_string($qtype . 'summary', 'qtype_' . $qtype) . "</p>\n\n";
|
|
|
|
}
|
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
function include_help_for_each_assignment_type() {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once($CFG->dirroot .'/mod/assignment/lib.php');
|
|
|
|
$typelist = assignment_types();
|
2006-08-22 22:12:17 +00:00
|
|
|
|
2006-08-22 22:04:06 +00:00
|
|
|
foreach ($typelist as $type => $name) {
|
2009-03-30 02:21:27 +00:00
|
|
|
echo '<h2>'.$name.'</h2>';
|
2006-08-22 22:04:06 +00:00
|
|
|
echo get_string('help'.$type, 'assignment');
|
2009-03-30 02:21:27 +00:00
|
|
|
echo '<hr />';
|
2006-08-22 22:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-02 07:09:26 +00:00
|
|
|
?>
|