Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Use Requests library to get help from Github.
James Cole28a4f724d564
diff --git a/app/Helpers/Csv/Data.php b/app/Helpers/Csv/Data.phpindex 5ccfe6222d..b45edd5211 100644--- a/app/Helpers/Csv/Data.php+++ b/app/Helpers/Csv/Data.php@@ -5,6 +5,7 @@ namespace FireflyIII\Helpers\Csv;use Crypt;use League\Csv\Reader;use Session;+use Storage;/*** Class Data@@ -253,7 +254,8 @@ class Dataprotected function loadCsvFile(){$file = $this->getCsvFileLocation();- $content = file_get_contents($file);+ $disk = Storage::disk('upload');+ $content = $disk->get($file);$contentDecrypted = Crypt::decrypt($content);$this->setCsvFileContent($contentDecrypted);}diff --git a/app/Helpers/Help/Help.php b/app/Helpers/Help/Help.phpindex b54a481224..349bad112e 100644--- a/app/Helpers/Help/Help.php+++ b/app/Helpers/Help/Help.php@@ -3,9 +3,9 @@ declare(strict_types = 1);namespace FireflyIII\Helpers\Help;use Cache;-use ErrorException;use League\CommonMark\CommonMarkConverter;use Log;+use Requests;use Route;/**@@ -23,34 +23,42 @@ class Help implements HelpInterface** @return string*/- public function getFromCache(string $key)+ public function getFromCache(string $key): string{return Cache::get($key);}/**- * @codeCoverageIgnore- *+ * @param string $language* @param string $route** @return array*/- public function getFromGithub(string $route)+ public function getFromGithub(string $language, string $route): array{- $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/en/' . e($route) . '.md';++ $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>There is no help for this route!</p>',+ 'text' => '<p>There is no help for this route, or there is no help available in your language.</p>','title' => $title,];- try {- $content['text'] = file_get_contents($uri);- } catch (ErrorException $e) {- Log::error(trim($e->getMessage()));++ Log::debug('Going to get from Github: ' . $uri);++ $result = Requests::get($uri);++ Log::debug('Status code was ' . $result->status_code . '.');++ if ($result->status_code === 200) {+ $content['text'] = $result->body;}++if (strlen(trim($content['text'])) == 0) {- $content['text'] = '<p>There is no help for this route.</p>';+ Log::debug('No actual help text for this route (even though a page was found).');+ $content['text'] = '<p>There is no help for this route, or there is no help available in your language.</p>';}$converter = new CommonMarkConverter();$content['text'] = $converter->convertToHtml($content['text']);@@ -66,7 +74,7 @@ class Help implements HelpInterface** @return bool*/- public function hasRoute(string $route)+ public function hasRoute(string $route):bool{return Route::has($route);}@@ -78,7 +86,7 @@ class Help implements HelpInterface** @return bool*/- public function inCache(string $route)+ public function inCache(string $route):bool{return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');}diff --git a/app/Helpers/Help/HelpInterface.php b/app/Helpers/Help/HelpInterface.phpindex d4805a659e..28fb689335 100644--- a/app/Helpers/Help/HelpInterface.php+++ b/app/Helpers/Help/HelpInterface.php@@ -15,34 +15,32 @@ interface HelpInterface** @return string*/- public function getFromCache(string $key);+ public function getFromCache(string $key): string;/*** @param string $route** @return array*/- public function getFromGithub(string $route);+ public function getFromGithub(string $language, string $route):array;/*** @param string $route** @return bool*/- public function hasRoute(string $route);+ public function hasRoute(string $route): bool;/*** @param string $route** @return bool*/- public function inCache(string $route);+ public function inCache(string $route): bool;/*** @param string $route* @param array $content- *- * @return void*/public function putInCache(string $route, array $content);}diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.phpindex 261496d7de..501ca5a2c8 100644--- a/app/Http/Controllers/CsvController.php+++ b/app/Http/Controllers/CsvController.php@@ -14,7 +14,6 @@ use Illuminate\Http\Request;use Input;use Log;use Preferences;-use Request as RequestFacade;use Session;use View;@@ -127,16 +126,15 @@ class CsvController extends Controller$result = json_encode($data, JSON_PRETTY_PRINT);$name = sprintf('"%s"', addcslashes('csv-configuration-' . date('Y-m-d') . '.json', '"\\'));- RequestFacade::header('Content-disposition: attachment; filename=' . $name);- RequestFacade::header('Content-Type: application/json');- RequestFacade::header('Content-Description: File Transfer');- RequestFacade::header('Connection: Keep-Alive');- RequestFacade::header('Expires: 0');- RequestFacade::header('Cache-Control: must-revalidate, post-check=0, pre-check=0');- RequestFacade::header('Pragma: public');- RequestFacade::header('Content-Length: ' . strlen($result));-- return $result;+ return response($result, 200)+ ->header('Content-disposition', 'attachment; filename=' . $name)+ ->header('Content-Type', 'application/json')+ ->header('Content-Description', 'File Transfer')+ ->header('Connection', 'Keep-Alive')+ ->header('Expires', '0')+ ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')+ ->header('Pragma', 'public')+ ->header('Content-Length', strlen($result));}/**@@ -220,8 +218,8 @@ class CsvController extends Controller// process given roles and mapping:$inputMap = Input::get('map') ?? [];- $roles = $this->wizard->processSelectedRoles(Input::get('role'));- $maps = $this->wizard->processSelectedMapping($roles, $inputMap);+ $roles = $this->wizard->processSelectedRoles(Input::get('role'));+ $maps = $this->wizard->processSelectedMapping($roles, $inputMap);Session::put('csv-map', $maps);Session::put('csv-roles', $roles);@@ -398,7 +396,7 @@ class CsvController extends Controllerreturn redirect(route('csv.index'));}- $fullPath = $this->wizard->storeCsvFile($request->file('csv')->getRealPath());+ $path = $this->wizard->storeCsvFile($request->file('csv')->getRealPath());$settings = [];$settings['date-format'] = Input::get('date_format');$settings['has-headers'] = intval(Input::get('has_headers')) === 1;@@ -424,7 +422,7 @@ class CsvController extends Controller}}- $this->data->setCsvFileLocation($fullPath);+ $this->data->setCsvFileLocation($path);$this->data->setDateFormat($settings['date-format']);$this->data->setHasHeaders($settings['has-headers']);$this->data->setMap($settings['map']);diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.phpindex 4b346ec8fd..67e177a53d 100644--- a/app/Http/Controllers/HelpController.php+++ b/app/Http/Controllers/HelpController.php@@ -2,6 +2,7 @@use FireflyIII\Helpers\Help\HelpInterface;use Log;+use Preferences;use Response;/**@@ -46,7 +47,8 @@ class HelpController extends Controllerreturn Response::json($content);}- $content = $help->getFromGithub($route);+ $language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;+ $content = $help->getFromGithub($language, $route);$help->putInCache($route, $content);