extension.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. final class UserCSSExtension extends Minz_Extension {
  4. public string $css_rules = '';
  5. private const FILENAME = 'style.css';
  6. #[\Override]
  7. public function init(): void {
  8. parent::init();
  9. $this->registerTranslates();
  10. if ($this->hasFile(self::FILENAME)) {
  11. Minz_View::appendStyle($this->getFileUrl(self::FILENAME, isStatic: false));
  12. }
  13. }
  14. #[\Override]
  15. public function handleConfigureAction(): void {
  16. parent::init();
  17. $this->registerTranslates();
  18. if (Minz_Request::isPost()) {
  19. $css_rules = Minz_Request::paramString('css-rules', plaintext: true);
  20. $this->saveFile(self::FILENAME, $css_rules);
  21. FreshRSS_UserDAO::touch();
  22. // Redirect (Post/Redirect/Get) so the next page is built after the save,
  23. // with a fresh cache-busting URL for the updated stylesheet
  24. Minz_Request::good(_t('feedback.conf.updated'), [
  25. 'c' => 'extension', 'a' => 'configure', 'params' => ['e' => $this->getName()],
  26. ]);
  27. }
  28. $this->css_rules = '';
  29. if ($this->hasFile(self::FILENAME)) {
  30. $this->css_rules = htmlspecialchars($this->getFile(self::FILENAME) ?? '', ENT_NOQUOTES, 'UTF-8');
  31. }
  32. }
  33. }