mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-7442 Changed search order for help files to be more consistent with language files (backwards compatible)
This commit is contained in:
parent
a840456731
commit
20cc8f6066
1 changed files with 52 additions and 44 deletions
96
help.php
96
help.php
|
@ -37,8 +37,10 @@ if (!empty($file)) {
|
||||||
// _local language packs take precedence
|
// _local language packs take precedence
|
||||||
$xlangs = array();
|
$xlangs = array();
|
||||||
foreach ($langs as $lang) {
|
foreach ($langs as $lang) {
|
||||||
$xlangs[] = $lang . '_local';
|
if (!empty($lang)) {
|
||||||
$xlangs[] = $lang;
|
$xlangs[] = $lang . '_local';
|
||||||
|
$xlangs[] = $lang;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$langs = $xlangs;
|
$langs = $xlangs;
|
||||||
unset($xlangs);
|
unset($xlangs);
|
||||||
|
@ -46,53 +48,59 @@ if (!empty($file)) {
|
||||||
$langs = array($forcelang);
|
$langs = array($forcelang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Define possible locations for help file similar to locations for language strings
|
||||||
|
// Note: Always retain module directory as before
|
||||||
|
$locations = array();
|
||||||
|
if ($module == 'moodle') {
|
||||||
|
$locations[$CFG->dataroot.'/lang/'] = $file;
|
||||||
|
$locations[$CFG->dirroot.'/lang/'] = $file;
|
||||||
|
} else {
|
||||||
|
$modfile = $module.'/'.$file;
|
||||||
|
$locations[$CFG->dataroot.'/lang/'] = $modfile;
|
||||||
|
$locations[$CFG->dirroot.'/lang/'] = $modfile;
|
||||||
|
|
||||||
|
if (strpos($module, 'block_') === 0) { // It's a block help file
|
||||||
|
$block = substr($module, 6);
|
||||||
|
$locations[$CFG->dirroot .'/blocks/'.$block.'/lang/'] = $block.'/'.$file;
|
||||||
|
} else if (strpos($module, 'report_') === 0) { // It's a report help file
|
||||||
|
$report = substr($module, 7);
|
||||||
|
$locations[$CFG->dirroot .'/'.$CFG->admin.'/report/'.$report.'/lang/'] = $report.'/'.$file;
|
||||||
|
$locations[$CFG->dirroot .'/course/report/'.$report.'/lang/'] = $report.'/'.$file;
|
||||||
|
} else if (strpos($module, 'format_') === 0) { // Course format
|
||||||
|
$format = substr($module,7);
|
||||||
|
$locations[$CFG->dirroot .'/course/format/'.$format.'/lang/'] = $format.'/'.$file;
|
||||||
|
} else { // It's a normal activity
|
||||||
|
$locations[$CFG->dirroot .'/mod/'.$module.'/lang/'] = $module.'/'.$file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Work through the possible languages, starting with the most specific.
|
// Work through the possible languages, starting with the most specific.
|
||||||
foreach ($langs as $lang) {
|
while (!$helpfound && (list(,$lang) = each($langs)) && !empty($lang)) {
|
||||||
if (empty($lang)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Work out which directory the help files live in.
|
while (!$helpfound && (list($locationprefix,$locationsuffix) = each($locations))) {
|
||||||
if ($lang == 'en_utf8') {
|
$filepath = $locationprefix.$lang.'/help/'.$locationsuffix;
|
||||||
$helpdir = $CFG->dirroot;
|
|
||||||
} else {
|
|
||||||
$helpdir = $CFG->dataroot;
|
|
||||||
}
|
|
||||||
$helpdir .= "/lang/$lang/help";
|
|
||||||
|
|
||||||
// Then which file in there we should be serving.
|
// Now, try to include the help text from this file, if we can.
|
||||||
if ($module == 'moodle') {
|
if (file_exists_and_readable($filepath)) {
|
||||||
$filepath = "$helpdir/$file";
|
$helpfound = true;
|
||||||
} else {
|
@include($filepath); // The actual helpfile
|
||||||
$filepath = "$helpdir/$module/$file";
|
|
||||||
|
|
||||||
// If that does not exist, try a fallback into the module code folder.
|
// Now, we process some special cases.
|
||||||
if (!file_exists($filepath)) {
|
$helpdir = $locationprefix.$lang.'/help';
|
||||||
$filepath = "$CFG->dirroot/mod/$module/lang/$lang/help/$module/$file";
|
if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) {
|
||||||
|
include_help_for_each_module($file, $langs, $helpdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The remaining horrible hardcoded special cases should be delegated to modules somehow.
|
||||||
|
if ($module == 'moodle' and ($file == 'resource/types.html')) { // RESOURCES
|
||||||
|
include_help_for_each_resource($file, $langs, $helpdir);
|
||||||
|
}
|
||||||
|
if ($module == 'moodle' and ($file == 'assignment/types.html')) { // ASSIGNMENTS
|
||||||
|
include_help_for_each_assignment_type();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reset($locations);
|
||||||
// Now, try to include the help text from this file, if we can.
|
|
||||||
if (file_exists_and_readable($filepath)) {
|
|
||||||
$helpfound = true;
|
|
||||||
@include($filepath); // The actual helpfile
|
|
||||||
|
|
||||||
// Now, we process some special cases.
|
|
||||||
if ($module == 'moodle' and ($file == 'index.html' or $file == 'mods.html')) {
|
|
||||||
include_help_for_each_module($file, $langs, $helpdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The remaining horrible hardcoded special cases should be delegated to modules somehow.
|
|
||||||
if ($module == 'moodle' and ($file == 'resource/types.html')) { // RESOURCES
|
|
||||||
include_help_for_each_resource($file, $langs, $helpdir);
|
|
||||||
}
|
|
||||||
if ($module == 'moodle' and ($file == 'assignment/types.html')) { // ASSIGNMENTS
|
|
||||||
include_help_for_each_assignment_type();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Having found some help, we break out of the loop over languages.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The help to display was given as an argument to this function.
|
// The help to display was given as an argument to this function.
|
||||||
|
@ -161,7 +169,7 @@ function include_help_for_each_resource($file, $langs, $helpdir) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
require_once($CFG->dirroot .'/mod/resource/lib.php');
|
require_once($CFG->dirroot .'/mod/resource/lib.php');
|
||||||
$typelist = resource_get_resource_types();
|
$typelist = resource_get_types();
|
||||||
$typelist['label'] = get_string('resourcetypelabel', 'resource');
|
$typelist['label'] = get_string('resourcetypelabel', 'resource');
|
||||||
|
|
||||||
foreach ($typelist as $type => $name) {
|
foreach ($typelist as $type => $name) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue