Extend help pages.

This commit is contained in:
James Cole 2016-11-02 14:33:57 +01:00
parent b980b5baea
commit 2ddd4314f1
4 changed files with 29 additions and 13 deletions

View File

@ -26,6 +26,8 @@ use Route;
*/
class Help implements HelpInterface
{
/** @var string */
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36';
/**
* @param string $route
@ -51,9 +53,10 @@ class Help implements HelpInterface
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
Log::debug(sprintf('Trying to get %s...', $uri));
$opt = ['useragent' => $this->userAgent];
$content = '';
try {
$result = Requests::get($uri);
$result = Requests::get($uri, [], $opt);
} catch (Requests_Exception $e) {
Log::error($e);
@ -71,6 +74,9 @@ class Help implements HelpInterface
$converter = new CommonMarkConverter();
$content = $converter->convertToHtml($content);
}
if (strlen($content) === 0) {
Log::warning('Raw content length is zero.');
}
return $content;
@ -95,7 +101,7 @@ class Help implements HelpInterface
*/
public function inCache(string $route, string $language):bool
{
$line = sprintf('help.%s.%s', $route, $language);
$line = sprintf('help.%s.%s', $route, $language);
$result = Cache::has($line);
if ($result) {
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
@ -119,7 +125,11 @@ class Help implements HelpInterface
public function putInCache(string $route, string $language, string $content)
{
$key = sprintf('help.%s.%s', $route, $language);
Log::debug(sprintf('Will store entry in cache: %s', $key));
Cache::put($key, $content, 10080); // a week.
if (strlen($content) > 0) {
Log::debug(sprintf('Will store entry in cache: %s', $key));
Cache::put($key, $content, 10080); // a week.
return;
}
Log::info(sprintf('Will not cache %s because content is empty.', $key));
}
}

View File

@ -44,7 +44,6 @@ class HelpController extends Controller
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
$alternative = false;
if (!$help->hasRoute($route)) {
Log::error('No such route: ' . $route);
@ -54,7 +53,7 @@ class HelpController extends Controller
if ($help->inCache($route, $language)) {
$content = $help->getFromCache($route, $language);
Log::debug('Help text was in cache.');
Log::debug(sprintf('Help text %s was in cache.', $language));
return Response::json($content);
}
@ -63,13 +62,15 @@ class HelpController extends Controller
// get backup language content (try English):
if (strlen($content) === 0) {
$language = 'en_US';
$content = $help->getFromGithub($language, $route);
$alternative = true;
}
if ($alternative && strlen($content) > 0) {
$content = '<p><em>' . strval(trans('firefly.help_may_not_be_your_language')) . '</em></p>' . $content;
$language = 'en_US';
if ($help->inCache($route, $language)) {
Log::debug(sprintf('Help text %s was in cache.', $language));
$content = $help->getFromCache($route, $language);
}
if (!$help->inCache($route, $language)) {
$content = $help->getFromGithub($language, $route);
$content = '<p><em>' . strval(trans('firefly.help_may_not_be_your_language')) . '</em></p>' . $content;
}
}
if (strlen($content) === 0) {

View File

@ -72,6 +72,8 @@ return [
'destination_accounts' => 'Destination account(s)',
'user_id_is' => 'Your user id is <strong>:user</strong>',
'field_supports_markdown' => 'This field supports <a href="https://en.support.wordpress.com/markdown-quick-reference/">Markdown</a>.',
'need_more_help' => 'If you need more help using Firefly III, please <a href="https://github.com/JC5/firefly-iii/issues">open a ticker on Github</a>.',
// repeat frequencies:
'repeat_freq_yearly' => 'yearly',

View File

@ -148,6 +148,9 @@
</div>
<div class="modal-body" id="helpBody">&nbsp;</div>
<div class="modal-footer">
<small class="pull-left">
{{ 'need_more_help'|_ }}
</small>
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button>
</div>
</div>