mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-22 08:56:39 -06:00
Remove references to help
This commit is contained in:
parent
944864ed25
commit
ddabfbc1ad
@ -1,163 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Help.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Help;
|
||||
|
||||
use Cache;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use Log;
|
||||
use Route;
|
||||
|
||||
/**
|
||||
* Class Help.
|
||||
*/
|
||||
class Help implements HelpInterface
|
||||
{
|
||||
/** @var string The cache key */
|
||||
public const CACHEKEY = 'help_%s_%s';
|
||||
/** @var string The user agent. */
|
||||
protected $userAgent = 'Firefly III v%s';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->userAgent = sprintf($this->userAgent, config('firefly.version'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get from cache.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFromCache(string $route, string $language): string
|
||||
{
|
||||
$line = sprintf(self::CACHEKEY, $route, $language);
|
||||
|
||||
return Cache::get($line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text from GitHub.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getFromGitHub(string $route, string $language): string
|
||||
{
|
||||
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/main/%s/%s.md', $language, $route);
|
||||
Log::debug(sprintf('Trying to get %s...', $uri));
|
||||
$opt = ['headers' => ['User-Agent' => $this->userAgent]];
|
||||
$content = '';
|
||||
$statusCode = 500;
|
||||
$client = app(Client::class);
|
||||
try {
|
||||
$res = $client->request('GET', $uri, $opt);
|
||||
$statusCode = $res->getStatusCode();
|
||||
$content = trim($res->getBody()->getContents());
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::info($e->getMessage());
|
||||
//Log::info($e->getTraceAsString());
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Status code is %d', $statusCode));
|
||||
|
||||
if ('' !== $content) {
|
||||
Log::debug('Content is longer than zero. Expect something.');
|
||||
$converter = new CommonMarkConverter();
|
||||
$content = (string)$converter->convertToHtml($content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we have the route?
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute(string $route): bool
|
||||
{
|
||||
return Route::has($route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is in cache?
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inCache(string $route, string $language): bool
|
||||
{
|
||||
$line = sprintf(self::CACHEKEY, $route, $language);
|
||||
$result = Cache::has($line);
|
||||
if ($result) {
|
||||
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
|
||||
}
|
||||
if (!$result) {
|
||||
Log::debug(sprintf('Cache does not have this entry: %s', 'help.' . $route . '.' . $language));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put help text in cache.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
* @param string $content
|
||||
*/
|
||||
public function putInCache(string $route, string $language, string $content): void
|
||||
{
|
||||
$key = sprintf(self::CACHEKEY, $route, $language);
|
||||
if ('' !== $content) {
|
||||
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));
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* HelpInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Help;
|
||||
|
||||
/**
|
||||
* Interface HelpInterface.
|
||||
*/
|
||||
interface HelpInterface
|
||||
{
|
||||
/**
|
||||
* Get the help text from cache.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFromCache(string $route, string $language): string;
|
||||
|
||||
/**
|
||||
* Get the help text from GitHub.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFromGitHub(string $route, string $language): string;
|
||||
|
||||
/**
|
||||
* Is the route a known route?
|
||||
*
|
||||
* @param string $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRoute(string $route): bool;
|
||||
|
||||
/**
|
||||
* Is the help text in cache?
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inCache(string $route, string $language): bool;
|
||||
|
||||
/**
|
||||
* Put the result in cache.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
* @param string $content
|
||||
*/
|
||||
public function putInCache(string $route, string $language, string $content);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* HelpController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* Class HelpController.
|
||||
*/
|
||||
class HelpController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show help for a route.
|
||||
*
|
||||
* @param string $route
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function show(string $route): JsonResponse
|
||||
{
|
||||
/** @var string $language */
|
||||
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$html = $this->getHelpText($route, $language);
|
||||
|
||||
return response()->json(['html' => $html]);
|
||||
}
|
||||
|
||||
}
|
@ -57,66 +57,6 @@ trait RequestInformation
|
||||
return $parts['host'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the help text.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
final protected function getHelpText(string $route, string $language): string // get from internet.
|
||||
{
|
||||
$help = app(HelpInterface::class);
|
||||
// get language and default variables.
|
||||
$content = '<p>' . trans('firefly.route_has_no_help') . '</p>';
|
||||
|
||||
// if no such route, log error and return default text.
|
||||
if (!$help->hasRoute($route)) {
|
||||
Log::error('No such route: ' . $route);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
// help content may be cached:
|
||||
if ($help->inCache($route, $language)) {
|
||||
$content = $help->getFromCache($route, $language);
|
||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
// get help content from Github:
|
||||
$content = $help->getFromGitHub($route, $language);
|
||||
$originalLanguage = $language;
|
||||
// content will have 0 length when Github failed. Try en_US when it does:
|
||||
if ('' === $content) {
|
||||
$language = 'en_US';
|
||||
|
||||
// also check cache first:
|
||||
if ($help->inCache($route, $language)) {
|
||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||
|
||||
return $help->getFromCache($route, $language);
|
||||
}
|
||||
$baseHref = route('index');
|
||||
$helpString = sprintf(
|
||||
'<p><em><img alt="" src="%s/v1/images/flags/%s.png" /> %s</em></p>', $baseHref, $originalLanguage, (string)trans('firefly.help_translating')
|
||||
);
|
||||
$content = $helpString . $help->getFromGitHub($route, $language);
|
||||
}
|
||||
|
||||
// help still empty?
|
||||
if ('' !== $content) {
|
||||
$help->putInCache($route, $language, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
return '<p>' . trans('firefly.route_has_no_help') . '</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of triggers.
|
||||
*
|
||||
|
20
composer.lock
generated
20
composer.lock
generated
@ -1771,16 +1771,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v8.81.0",
|
||||
"version": "v8.82.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "9cc0efd724ce67a190b1695ba31a27bbb1ae9177"
|
||||
"reference": "411d5243c58cbf12b0fc89cab1ceb50088968c27"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/9cc0efd724ce67a190b1695ba31a27bbb1ae9177",
|
||||
"reference": "9cc0efd724ce67a190b1695ba31a27bbb1ae9177",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/411d5243c58cbf12b0fc89cab1ceb50088968c27",
|
||||
"reference": "411d5243c58cbf12b0fc89cab1ceb50088968c27",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1940,7 +1940,7 @@
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"time": "2022-01-25T16:41:46+00:00"
|
||||
"time": "2022-02-01T16:13:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/passport",
|
||||
@ -2085,16 +2085,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/serializable-closure",
|
||||
"version": "v1.0.5",
|
||||
"version": "v1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/serializable-closure.git",
|
||||
"reference": "25de3be1bca1b17d52ff0dc02b646c667ac7266c"
|
||||
"reference": "65c9faf50d567b65d81764a44526545689e3fe63"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/25de3be1bca1b17d52ff0dc02b646c667ac7266c",
|
||||
"reference": "25de3be1bca1b17d52ff0dc02b646c667ac7266c",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/65c9faf50d567b65d81764a44526545689e3fe63",
|
||||
"reference": "65c9faf50d567b65d81764a44526545689e3fe63",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2140,7 +2140,7 @@
|
||||
"issues": "https://github.com/laravel/serializable-closure/issues",
|
||||
"source": "https://github.com/laravel/serializable-closure"
|
||||
},
|
||||
"time": "2021-11-30T15:53:04+00:00"
|
||||
"time": "2022-02-01T16:29:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/ui",
|
||||
|
9
public/v1/js/ff/help.js
vendored
9
public/v1/js/ff/help.js
vendored
@ -17,7 +17,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** global: token, helpPageTitle, noHelpForPage,noHelpForPageTitle */
|
||||
/** global: token, helpPageTitle */
|
||||
$(function () {
|
||||
"use strict";
|
||||
$('#help').click(showHelp);
|
||||
@ -36,12 +36,7 @@ function showHelp(e) {
|
||||
$('#helpBody').html('<span class="fa fa-refresh fa-spin"></span>');
|
||||
$('#helpModal').modal('show');
|
||||
$('#helpTitle').html(helpPageTitle);
|
||||
$.getJSON('help/' + encodeURI(route)).done(function (data) {
|
||||
$('#helpBody').html(data.html);
|
||||
}).fail(function () {
|
||||
$('#helpBody').html('<p class="text-danger">' + noHelpForPage + '</p>');
|
||||
$('#helpTitle').html(noHelpForPageTitle);
|
||||
});
|
||||
$('#helpBody').html(helpPageBody);
|
||||
$('#reenableGuidance').unbind('click').click(function () {
|
||||
enableGuidance(route, specialPage);
|
||||
return false;
|
||||
|
@ -87,10 +87,8 @@ return [
|
||||
'flash_info_multiple' => 'There is one message|There are :count messages',
|
||||
'flash_error_multiple' => 'There is one error|There are :count errors',
|
||||
'net_worth' => 'Net worth',
|
||||
'route_has_no_help' => 'There is no help for this route.',
|
||||
'help_for_this_page' => 'Help for this page',
|
||||
'no_help_could_be_found' => 'No help text could be found.',
|
||||
'no_help_title' => 'Apologies, an error occurred.',
|
||||
'help_for_this_page_body' => 'You can find more information about this page <a href="https://docs.firefly-iii.org/">in the documentation</a>.',
|
||||
'two_factor_welcome' => 'Hello!',
|
||||
'two_factor_enter_code' => 'To continue, please enter your two factor authentication code. Your application can generate it for you.',
|
||||
'two_factor_code_here' => 'Enter code here',
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% extends "./v1/layout/install" %}
|
||||
{% extends "./layout/install" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="login-box-body">
|
||||
|
@ -48,8 +48,7 @@ var acc_config_new = {format: accountingConfig};
|
||||
|
||||
// strings and translations used often:
|
||||
var helpPageTitle = "{{ trans('firefly.help_for_this_page')|escape('js') }}";
|
||||
var noHelpForPage = "{{ trans('firefly.no_help_could_be_found')|escape('js') }}";
|
||||
var noHelpForPageTitle = "{{ trans('firefly.no_help_title')|escape('js') }}";
|
||||
var helpPageBody = "{{ trans('firefly.help_for_this_page_body')|escape('js') }}";
|
||||
|
||||
var edit_selected_txt = "{{ trans('firefly.mass_edit')|escape('js') }}";
|
||||
var edit_bulk_selected_txt = "{{ trans('firefly.bulk_edit')|escape('js') }}";
|
||||
|
@ -589,16 +589,6 @@ Route::group(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Help Controller.
|
||||
*/
|
||||
Route::group(
|
||||
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'help', 'as' => 'help.'],
|
||||
static function () {
|
||||
Route::get('{route}', ['uses' => 'HelpController@show', 'as' => 'show']);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* JScript Controller.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user