Refactor the help module

This commit is contained in:
Mike Macgirvin 2023-02-10 06:45:30 +11:00
parent 2753db10f2
commit 37a46e7f6a
2 changed files with 30 additions and 15 deletions

View file

@ -3139,6 +3139,9 @@ class Activity
if (is_array($location) && array_key_exists('type', $location) && $location['type'] === 'Place') {
if (array_key_exists('name', $location)) {
$s['location'] = escape_tags($location['name']);
// Look for something resembling latitude/longitude coordinates in the place name and set the
// coordinates appropriately. This technically isn't supported but is provided as a convenience
// to reduce support requests.
$latlon = '/(?<!\d)([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)),\s*([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))(?!\d)/';
if (preg_match($latlon,$s['location'], $matches)) {
$s['lat'] = floatval($matches[1]);

View file

@ -81,18 +81,31 @@ class Help extends Controller
killme();
}
$heading = '';
if (argc() === 1) {
$files = self::listdir('doc');
if (argc() === 1) {
$cmd = 'doc';
}
else {
$cmd = str_replace('help/', 'doc/', App::$cmd);
}
if (! is_dir($cmd)) {
$content = get_help_content();
}
else {
$files = self::listdir($cmd);
if ($files) {
usort($files, [ 'self','usort_basename']);
usort($files, ['self', 'usort_basename']);
foreach ($files as $file) {
$language = '';
if (! str_contains(z_mime_content_type($file), 'text')) {
continue;
}
if ((!strpos($file, '/site/')) && file_exists(str_replace('doc/', 'doc/site/', $file))) {
$file = str_replace('doc/', 'doc/site/', $file);
}
if (!is_dir($file) && !str_contains(z_mime_content_type($file), 'text')) {
continue;
}
if (strpos($file, 'README')) {
@ -100,26 +113,22 @@ class Help extends Controller
}
if (preg_match('/\/(..|..-..)\//', $file, $matches)) {
$language = $matches[1];
} else {
$language = t('Unknown language');
}
if ($language === substr(App::$language, 0, 2)) {
$language = '';
if ($language === substr(App::$language, 0, 2)) {
$language = '';
}
}
$link = str_replace(['doc/', '.mc', '.txt'], ['help/', '', ''], $file);
$displayName = str_replace('_',' ', $link);
$displayName = str_replace('_', ' ', $link);
if (str_contains($link, '/global/') || str_contains($link, '/media/')) {
continue;
}
$content .= '<div class="nav-pills"><a href="' . $link . '">' . ucfirst(basename($displayName)) . '</a>' . (($language) ? " [$language]" : '') . '</div>' . EOL;
}
}
} else {
$content = get_help_content();
}
return replace_macros(Theme::get_template('help.tpl'), [
'$title' => t('$Projectname Documentation'),
'$tocHeading' => t('Contents'),
@ -140,6 +149,9 @@ class Help extends Controller
if (!$handle) {
return $results;
}
if ($path === 'doc') {
return ['doc/guide', 'doc/develop'];
}
while (false !== ($file = readdir($handle))) {
if ($file === '.' || $file === '..') {
continue;