aboutsummaryrefslogtreecommitdiff
path: root/app/Models/ReadingMode.php
blob: 51ff26fd5eeb68f808128af355cd637edd5a1ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php

/**
 * Manage the reading modes in FreshRSS.
 */
class FreshRSS_ReadingMode {

	protected string $id;
	protected string $name;
	protected string $title;
	/** @var array{'c':string,'a':string,'params':array<string,mixed>} */
	protected array $urlParams;
	protected bool $isActive = false;

	/**
	 * ReadingMode constructor.
	 * @param array{'c':string,'a':string,'params':array<string,mixed>} $urlParams
	 */
	public function __construct(string $id, string $title, array $urlParams, bool $active) {
		$this->id = $id;
		$this->name = _i($id);
		$this->title = $title;
		$this->urlParams = $urlParams;
		$this->isActive = $active;
	}

	public function getId(): string {
		return $this->id;
	}

	public function getName(): string {
		return $this->name;
	}

	public function setName(string $name): FreshRSS_ReadingMode {
		$this->name = $name;
		return $this;
	}

	public function getTitle(): string {
		return $this->title;
	}

	public function setTitle(string $title): FreshRSS_ReadingMode {
		$this->title = $title;
		return $this;
	}

	/** @return array{'c':string,'a':string,'params':array<string,mixed>} */
	public function getUrlParams(): array {
		return $this->urlParams;
	}

	/** @param array{'c':string,'a':string,'params':array<string,mixed>} $urlParams */
	public function setUrlParams(array $urlParams): FreshRSS_ReadingMode {
		$this->urlParams = $urlParams;
		return $this;
	}

	public function isActive(): bool {
		return $this->isActive;
	}

	public function setIsActive(bool $isActive): FreshRSS_ReadingMode {
		$this->isActive = $isActive;
		return $this;
	}

	/**
	 * @return array<FreshRSS_ReadingMode> the built-in reading modes
	 */
	public static function getReadingModes(): array {
		$actualView = Minz_Request::actionName();
		$defaultCtrl = Minz_Request::defaultControllerName();
		$isDefaultCtrl = Minz_Request::controllerName() === $defaultCtrl;
		$urlOutput = Minz_Request::currentRequest();

		$readingModes = [
			new FreshRSS_ReadingMode(
				"view-normal",
				_t('index.menu.normal_view'),
				array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'normal']),
				($isDefaultCtrl && $actualView === 'normal')
			),
			new FreshRSS_ReadingMode(
				"view-global",
				_t('index.menu.global_view'),
				array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'global']),
				($isDefaultCtrl && $actualView === 'global')
			),
			new FreshRSS_ReadingMode(
				"view-reader",
				_t('index.menu.reader_view'),
				array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'reader']),
				($isDefaultCtrl && $actualView === 'reader')
			)
		];

		return $readingModes;
	}
}