diff options
author | Mario <mario@mariovavti.com> | 2024-04-30 06:59:20 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-04-30 06:59:20 +0000 |
commit | ce15852b9a57a6c77531186ed24a389ebce8524e (patch) | |
tree | ad04cef0d545c5e5e24e76060b6c32d65363d48e /Zotlabs/Lib/Traits/HelpHelper.php | |
parent | 48cec945051d259a06871d937ad998a1bd3e22ec (diff) | |
parent | 7c34a3676d294c9a1acc69f71ab3061074509160 (diff) | |
download | volse-hubzilla-ce15852b9a57a6c77531186ed24a389ebce8524e.tar.gz volse-hubzilla-ce15852b9a57a6c77531186ed24a389ebce8524e.tar.bz2 volse-hubzilla-ce15852b9a57a6c77531186ed24a389ebce8524e.zip |
Merge branch 'rework-help-module' into 'dev'
Rework Help module + begin tests for Setup module
See merge request hubzilla/core!2120
Diffstat (limited to 'Zotlabs/Lib/Traits/HelpHelper.php')
-rw-r--r-- | Zotlabs/Lib/Traits/HelpHelper.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Zotlabs/Lib/Traits/HelpHelper.php b/Zotlabs/Lib/Traits/HelpHelper.php new file mode 100644 index 000000000..f0dca35d0 --- /dev/null +++ b/Zotlabs/Lib/Traits/HelpHelper.php @@ -0,0 +1,68 @@ +<?php + +namespace Zotlabs\Lib\Traits; + +use CommerceGuys\Intl\Language\LanguageRepository; + +trait HelpHelper { + + // PHP versions before 8.2 does not support trait constants, + // Leave this commented out until we drop support for PHP 8.1. + // + // const VALID_FILE_EXT = ['md', 'bb', 'html']; + + private string $file_name = ''; + private string $file_type = ''; + + /** + * Determines help language. + * + * If the language was specified in the URL, override the language preference + * of the browser. Default to English if both of these are absent. + * + * Updates the `$lang` property of the module. + */ + private function determine_help_language() { + + $language_repository = new LanguageRepository; + $languages = $language_repository->getList(); + + if(array_key_exists(argv(1), $languages)) { + $lang = argv(1); + $from_url = true; + } else { + $lang = \App::$language; + if(! isset($lang)) + $lang = 'en'; + + $from_url = false; + } + + $this->lang = array('language' => $lang, 'from_url' => $from_url); + } + + /** + * Find the full path name of the file, given it's base path and + * the language of the request. + * + * @param string $base_path The path of the file to find, relative to the + * doc root path, and without the extension. + */ + private function find_help_file(string $base_path, string $lang): void { + + // Use local variable until we can use trait constants. + $valid_file_ext = ['md', 'bb', 'html']; + + $base_path = "doc/{$lang}/${base_path}"; + + foreach ($valid_file_ext as $ext) { + $path = "{$base_path}.{$ext}"; + if (file_exists($path)) { + $this->file_name = $path; + $this->file_type = $ext; + + break; + } + } + } +} |