firefly-iii/app/controllers/HelpController.php

44 lines
1.4 KiB
PHP
Raw Normal View History

2014-11-28 07:12:16 -06:00
<?php
2014-12-06 10:53:25 -06:00
/**
* Class HelpController
*/
2014-11-28 07:12:16 -06:00
class HelpController extends BaseController
{
2014-12-06 10:53:25 -06:00
/**
* @param $route
*
* @return \Illuminate\Http\JsonResponse
*/
2014-11-28 07:12:16 -06:00
public function show($route)
{
2014-12-14 13:40:02 -06:00
$helpText = '<p>There is no help for this route!</p>';
$helpTitle = 'Help';
2014-11-28 07:12:16 -06:00
if (!Route::has($route)) {
return Response::json(['title' => $helpTitle, 'text' => $helpText]);
}
// content in cache
if (Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text')) {
$helpText = Cache::get('help.' . $route . '.text');
$helpTitle = Cache::get('help.' . $route . '.title');
return Response::json(['title' => $helpTitle, 'text' => $helpText]);
}
2014-12-13 14:59:02 -06:00
$uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md';
2014-11-28 07:12:16 -06:00
try {
2014-12-13 14:59:02 -06:00
$content = file_get_contents($uri);
2014-11-28 07:12:16 -06:00
} catch (ErrorException $e) {
$content = '<p>There is no help for this route.</p>';
}
2014-12-14 13:40:02 -06:00
$helpText = \Michelf\Markdown::defaultTransform($content);
$helpTitle = $route;
2014-11-28 07:12:16 -06:00
2014-12-14 13:40:02 -06:00
Cache::put('help.' . $route . '.text', $helpText, 10080); // a week.
Cache::put('help.' . $route . '.title', $helpTitle, 10080);
2014-11-28 07:12:16 -06:00
return Response::json(['title' => $helpTitle, 'text' => $helpText]);
}
}