ThemeController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. *
  10. * @return Response
  11. */
  12. public function getThemes(Response $response): Response
  13. {
  14. $apiJson = json_decode(file_get_contents('https://bootswatch.com/api/4.json'));
  15. $out = [];
  16. $out['Default - Bootstrap 4 default theme'] = 'https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css';
  17. foreach ($apiJson->themes as $theme) {
  18. $out["{$theme->name} - {$theme->description}"] = $theme->cssMin;
  19. }
  20. return json($response, $out);
  21. }
  22. /**
  23. * @param Request $request
  24. * @param Response $response
  25. *
  26. * @return Response
  27. */
  28. public function applyTheme(Request $request, Response $response): Response
  29. {
  30. if (!is_writable(BASE_DIR.'static/bootstrap/css/bootstrap.min.css')) {
  31. $this->session->alert(lang('cannot_write_file'), 'danger');
  32. return redirect($response, route('system'));
  33. }
  34. file_put_contents(BASE_DIR.'static/bootstrap/css/bootstrap.min.css', file_get_contents(param($request, 'css')));
  35. return redirect($response, route('system'));
  36. }
  37. }