ThemeController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Controllers;
  3. use Psr\Http\Message\ResponseInterface as Response;
  4. use Psr\Http\Message\ServerRequestInterface as Request;
  5. class ThemeController extends Controller
  6. {
  7. /**
  8. * @param Response $response
  9. * @return Response
  10. */
  11. public function getThemes(Response $response): Response
  12. {
  13. $apiJson = json_decode(file_get_contents('https://bootswatch.com/api/4.json'));
  14. $out = [];
  15. $out['Default - Bootstrap 4 default theme'] = 'https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css';
  16. foreach ($apiJson->themes as $theme) {
  17. $out["{$theme->name} - {$theme->description}"] = $theme->cssMin;
  18. }
  19. return json($response, $out);
  20. }
  21. /**
  22. * @param Request $request
  23. * @param Response $response
  24. * @return Response
  25. */
  26. public function applyTheme(Request $request, Response $response): Response
  27. {
  28. if (!is_writable(BASE_DIR.'static/bootstrap/css/bootstrap.min.css')) {
  29. $this->session->alert(lang('cannot_write_file'), 'danger');
  30. return redirect($response, route('system'));
  31. }
  32. file_put_contents(BASE_DIR.'static/bootstrap/css/bootstrap.min.css', file_get_contents(param($request, 'css')));
  33. return redirect($response, route('system'));
  34. }
  35. }