feat: squelette de l'extension Read More (config, i18n)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vincent BourdonandClaude Opus 5.5 committed 2026-11-06 18:57:47 +01:00
1 parent bb8d03eaab
commit d8b334767d
10 files changed
+193

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
final class ReadMoreExtension extends Minz_Extension {
public const DEFAULT_HEIGHT = 250;
public const MIN_HEIGHT = 100;
public const MAX_HEIGHT = 2000;
#[\Override]
public function init(): void {
$this->registerTranslates();
if (!FreshRSS_Context::hasUserConf()) {
return;
}
Minz_View::appendStyle($this->getFileUrl('read-more.css'));
Minz_View::appendScript($this->getFileUrl('read-more.js'));
$this->registerHook(Minz_HookType::JsVars, $this->jsVars(...));
}
public static function clampHeight(int $height): int {
return max(self::MIN_HEIGHT, min(self::MAX_HEIGHT, $height));
}
public function getCollapsedHeight(): int {
return self::clampHeight($this->getUserConfigurationInt('collapsed_height') ?? self::DEFAULT_HEIGHT);
}
/**
* Pass parameters to read-more.js via `window.context.extensions`.
* @param array<mixed> $vars
* @return array<mixed>
*/
public function jsVars(array $vars): array {
$vars['read_more'] = [
'collapsed_height' => $this->getCollapsedHeight(),
'label' => _t('ext.read_more.button'),
];
return $vars;
}
#[\Override]
public function handleConfigureAction(): void {
$this->registerTranslates();
if (Minz_Request::isPost()) {
$height = Minz_Request::paramInt('collapsed_height') ?: self::DEFAULT_HEIGHT;
$this->setUserConfigurationValue('collapsed_height', self::clampHeight($height));
}
}
}