New help thing.

This commit is contained in:
James Cole
2016-10-23 17:33:53 +02:00
parent 19e9f382e4
commit 48b0620629
5 changed files with 49 additions and 67 deletions

View File

@@ -26,47 +26,39 @@ class Help implements HelpInterface
{
/**
*
* @param string $key
* @param string $route
* @param string $language
*
* @return string
*/
public function getFromCache(string $key): string
public function getFromCache(string $route, string $language): string
{
return Cache::get($key);
return Cache::get('help.' . $route . '.' . $language);
}
/**
* @param string $language
* @param string $route
*
* @return array
* @return string
*/
public function getFromGithub(string $language, string $route): array
public function getFromGithub(string $language, string $route): string
{
$uri = sprintf('https://raw.githubusercontent.com/JC5/firefly-iii-help/master/%s/%s.md', $language, $route);
$routeIndex = str_replace('.', '-', $route);
$title = trans('help.' . $routeIndex);
$content = [
'text' => '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>',
'title' => $title,
];
$result = Requests::get($uri);
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
$result = Requests::get($uri);
if ($result->status_code === 200) {
$content['text'] = $result->body;
$content = $result->body;
}
if (strlen(trim($content['text'])) == 0) {
$content['text'] = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
if (strlen(trim($content)) == 0) {
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
}
$converter = new CommonMarkConverter();
$content['text'] = $converter->convertToHtml($content['text']);
$converter = new CommonMarkConverter();
$content = $converter->convertToHtml($content);
return $content;
@@ -84,27 +76,26 @@ class Help implements HelpInterface
}
/**
*
* @param string $route
* @param string $language
*
* @return bool
*/
public function inCache(string $route):bool
public function inCache(string $route, string $language):bool
{
return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
return Cache::has('help.' . $route . '.' . $language);
}
/**
*
* @param string $route
* @param string $language
* @param array $content
* @param string $content
*
* @internal param $title
*/
public function putInCache(string $route, string $language, array $content)
public function putInCache(string $route, string $language, string $content)
{
Cache::put('help.' . $route . '.text.' . $language, $content['text'], 10080); // a week.
Cache::put('help.' . $route . '.title.' . $language, $content['title'], 10080);
Cache::put('help.' . $route . '.' . $language, $content, 10080); // a week.
}
}