@@ -25,212 +25,212 @@ |
||
25 | 25 | */ |
26 | 26 | class Certificate |
27 | 27 | { |
28 | - /** |
|
29 | - * Pattern to extract information from a file name. |
|
30 | - * Specific to the author's workflow. |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Tree $tree |
|
37 | - */ |
|
38 | - private $tree; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string $path |
|
42 | - * */ |
|
43 | - private $path; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string|null $city |
|
47 | - * $city */ |
|
48 | - private $city; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string|null $filename |
|
52 | - */ |
|
53 | - private $filename; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var string|null $extension |
|
57 | - */ |
|
58 | - private $extension; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var string|null $type |
|
62 | - */ |
|
63 | - private $type; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var string|null $description |
|
67 | - */ |
|
68 | - private $description; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var Date|null $date |
|
72 | - */ |
|
73 | - private $date; |
|
74 | - |
|
75 | - /** |
|
76 | - * Contructor for Certificate |
|
77 | - * |
|
78 | - * @param Tree $tree |
|
79 | - * @param string $path |
|
80 | - */ |
|
81 | - public function __construct(Tree $tree, string $path) |
|
82 | - { |
|
83 | - $this->tree = $tree; |
|
84 | - $this->path = $path; |
|
85 | - $this->extractDataFromPath($path); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Populate fields from the filename, based on a predeterminate pattern. |
|
90 | - * Logic specific to the author. |
|
91 | - * |
|
92 | - * @param string $path |
|
93 | - */ |
|
94 | - protected function extractDataFromPath(string $path): void |
|
95 | - { |
|
96 | - $path_parts = pathinfo($path); |
|
97 | - $this->city = $path_parts['dirname']; |
|
98 | - $this->filename = $path_parts['filename']; |
|
99 | - $this->extension = $path_parts['extension'] ?? ''; |
|
100 | - |
|
101 | - if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
102 | - $this->type = $match['type']; |
|
103 | - $this->description = $match['descr']; |
|
104 | - |
|
105 | - $day = $match['day'] ?? ''; |
|
106 | - $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
107 | - $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
108 | - $year = $match['year'] ?? ''; |
|
109 | - |
|
110 | - $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
111 | - } else { |
|
112 | - $this->description = $this->filename; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get the family tree of the certificate |
|
118 | - * |
|
119 | - * @return Tree |
|
120 | - */ |
|
121 | - public function tree(): Tree |
|
122 | - { |
|
123 | - return $this->tree; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Get the path of the certificate in the file system. |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function path(): string |
|
132 | - { |
|
133 | - return $this->path; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * The the path of the certificate, in a Gedcom canonical form. |
|
138 | - * |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function gedcomPath(): string |
|
142 | - { |
|
143 | - return str_replace('\\', '/', $this->path); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get the certificate name. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function name(): string |
|
152 | - { |
|
153 | - return $this->filename ?? ''; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the certificate's city (the first level folder). |
|
158 | - * |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function city(): string |
|
162 | - { |
|
163 | - return $this->city ?? ''; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Get the certificate's date. Extracted from the file name. |
|
168 | - * |
|
169 | - * @return Date |
|
170 | - */ |
|
171 | - public function date(): Date |
|
172 | - { |
|
173 | - return $this->date ?? new Date(''); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Get the certificate's type. Extracted from the file name. |
|
178 | - * |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function type(): string |
|
182 | - { |
|
183 | - return $this->type ?? ''; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Get the certificate's description. Extracted from the file name. |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public function description(): string |
|
191 | - { |
|
192 | - return $this->description ?? ''; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get the certificate's description to be used for sorting. |
|
197 | - * This is based on surnames (at least 3 letters) found in the file name. |
|
198 | - * |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function sortDescription(): string |
|
202 | - { |
|
203 | - $sort_prefix = ''; |
|
204 | - if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
205 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
206 | - return $match[1]; |
|
207 | - }, $matches)) . '_'; |
|
208 | - } |
|
209 | - return $sort_prefix . $this->description(); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Get the certificate's MIME type. |
|
214 | - * |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - public function mimeType(): string |
|
218 | - { |
|
219 | - return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Get the base parameters to be used in url referencing the certificate. |
|
224 | - * |
|
225 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
229 | - { |
|
230 | - $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
231 | - return [ |
|
232 | - 'tree' => $this->tree->name(), |
|
233 | - 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
234 | - ]; |
|
235 | - } |
|
28 | + /** |
|
29 | + * Pattern to extract information from a file name. |
|
30 | + * Specific to the author's workflow. |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Tree $tree |
|
37 | + */ |
|
38 | + private $tree; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string $path |
|
42 | + * */ |
|
43 | + private $path; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string|null $city |
|
47 | + * $city */ |
|
48 | + private $city; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string|null $filename |
|
52 | + */ |
|
53 | + private $filename; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var string|null $extension |
|
57 | + */ |
|
58 | + private $extension; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var string|null $type |
|
62 | + */ |
|
63 | + private $type; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var string|null $description |
|
67 | + */ |
|
68 | + private $description; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var Date|null $date |
|
72 | + */ |
|
73 | + private $date; |
|
74 | + |
|
75 | + /** |
|
76 | + * Contructor for Certificate |
|
77 | + * |
|
78 | + * @param Tree $tree |
|
79 | + * @param string $path |
|
80 | + */ |
|
81 | + public function __construct(Tree $tree, string $path) |
|
82 | + { |
|
83 | + $this->tree = $tree; |
|
84 | + $this->path = $path; |
|
85 | + $this->extractDataFromPath($path); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Populate fields from the filename, based on a predeterminate pattern. |
|
90 | + * Logic specific to the author. |
|
91 | + * |
|
92 | + * @param string $path |
|
93 | + */ |
|
94 | + protected function extractDataFromPath(string $path): void |
|
95 | + { |
|
96 | + $path_parts = pathinfo($path); |
|
97 | + $this->city = $path_parts['dirname']; |
|
98 | + $this->filename = $path_parts['filename']; |
|
99 | + $this->extension = $path_parts['extension'] ?? ''; |
|
100 | + |
|
101 | + if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
102 | + $this->type = $match['type']; |
|
103 | + $this->description = $match['descr']; |
|
104 | + |
|
105 | + $day = $match['day'] ?? ''; |
|
106 | + $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
107 | + $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
108 | + $year = $match['year'] ?? ''; |
|
109 | + |
|
110 | + $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
111 | + } else { |
|
112 | + $this->description = $this->filename; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get the family tree of the certificate |
|
118 | + * |
|
119 | + * @return Tree |
|
120 | + */ |
|
121 | + public function tree(): Tree |
|
122 | + { |
|
123 | + return $this->tree; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Get the path of the certificate in the file system. |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function path(): string |
|
132 | + { |
|
133 | + return $this->path; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * The the path of the certificate, in a Gedcom canonical form. |
|
138 | + * |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function gedcomPath(): string |
|
142 | + { |
|
143 | + return str_replace('\\', '/', $this->path); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get the certificate name. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function name(): string |
|
152 | + { |
|
153 | + return $this->filename ?? ''; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the certificate's city (the first level folder). |
|
158 | + * |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function city(): string |
|
162 | + { |
|
163 | + return $this->city ?? ''; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Get the certificate's date. Extracted from the file name. |
|
168 | + * |
|
169 | + * @return Date |
|
170 | + */ |
|
171 | + public function date(): Date |
|
172 | + { |
|
173 | + return $this->date ?? new Date(''); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Get the certificate's type. Extracted from the file name. |
|
178 | + * |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function type(): string |
|
182 | + { |
|
183 | + return $this->type ?? ''; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Get the certificate's description. Extracted from the file name. |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + public function description(): string |
|
191 | + { |
|
192 | + return $this->description ?? ''; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get the certificate's description to be used for sorting. |
|
197 | + * This is based on surnames (at least 3 letters) found in the file name. |
|
198 | + * |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function sortDescription(): string |
|
202 | + { |
|
203 | + $sort_prefix = ''; |
|
204 | + if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
205 | + $sort_prefix = implode('_', array_map(function ($match) { |
|
206 | + return $match[1]; |
|
207 | + }, $matches)) . '_'; |
|
208 | + } |
|
209 | + return $sort_prefix . $this->description(); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Get the certificate's MIME type. |
|
214 | + * |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + public function mimeType(): string |
|
218 | + { |
|
219 | + return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Get the base parameters to be used in url referencing the certificate. |
|
224 | + * |
|
225 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
229 | + { |
|
230 | + $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
231 | + return [ |
|
232 | + 'tree' => $this->tree->name(), |
|
233 | + 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
234 | + ]; |
|
235 | + } |
|
236 | 236 | } |
@@ -202,11 +202,11 @@ |
||
202 | 202 | { |
203 | 203 | $sort_prefix = ''; |
204 | 204 | if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
205 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
205 | + $sort_prefix = implode('_', array_map(function($match) { |
|
206 | 206 | return $match[1]; |
207 | - }, $matches)) . '_'; |
|
207 | + }, $matches)).'_'; |
|
208 | 208 | } |
209 | - return $sort_prefix . $this->description(); |
|
209 | + return $sort_prefix.$this->description(); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -19,112 +19,112 @@ |
||
19 | 19 | */ |
20 | 20 | class Watermark |
21 | 21 | { |
22 | - /** |
|
23 | - * Default font color for watermarks |
|
24 | - * @var string DEFAULT_COLOR |
|
25 | - * */ |
|
26 | - public const DEFAULT_COLOR = '#4D6DF3'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Default maximum font size for watermarks |
|
30 | - * @var string DEFAULT_SIZE |
|
31 | - * */ |
|
32 | - public const DEFAULT_SIZE = 18; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $text |
|
36 | - */ |
|
37 | - private $text; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string $color; |
|
41 | - */ |
|
42 | - private $color; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @var int $size |
|
47 | - */ |
|
48 | - private $size; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for Watermark data class |
|
52 | - * |
|
53 | - * @param string $text |
|
54 | - * @param string $color |
|
55 | - * @param int $size |
|
56 | - */ |
|
57 | - public function __construct(string $text, string $color, int $size) |
|
58 | - { |
|
59 | - $this->text = $text; |
|
60 | - $this->color = $color; |
|
61 | - $this->size = $size; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Get the watermark text. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function text(): string |
|
70 | - { |
|
71 | - return $this->text; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the watermark font color. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function color(): string |
|
80 | - { |
|
81 | - return $this->color; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get the watermark maximum font size. |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public function size(): int |
|
89 | - { |
|
90 | - return $this->size; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Return an estimate of the size in pixels of the watermark text length. |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function textLengthEstimate(): int |
|
99 | - { |
|
100 | - return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Decrease the font size if necessary, based on the image width. |
|
105 | - * |
|
106 | - * @param int $width |
|
107 | - */ |
|
108 | - public function adjustSize(int $width): void |
|
109 | - { |
|
110 | - $len = mb_strlen($this->text); |
|
111 | - while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
112 | - $this->size--; |
|
113 | - if ($this->size == 2) { |
|
114 | - return; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Return an estimate of the size in pixels of a text in a specified font size. |
|
121 | - * |
|
122 | - * @param int $text_length |
|
123 | - * @param int $font_size |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - private function stringLengthEstimate(int $text_length, int $font_size): int |
|
127 | - { |
|
128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
129 | - } |
|
22 | + /** |
|
23 | + * Default font color for watermarks |
|
24 | + * @var string DEFAULT_COLOR |
|
25 | + * */ |
|
26 | + public const DEFAULT_COLOR = '#4D6DF3'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Default maximum font size for watermarks |
|
30 | + * @var string DEFAULT_SIZE |
|
31 | + * */ |
|
32 | + public const DEFAULT_SIZE = 18; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $text |
|
36 | + */ |
|
37 | + private $text; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string $color; |
|
41 | + */ |
|
42 | + private $color; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @var int $size |
|
47 | + */ |
|
48 | + private $size; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for Watermark data class |
|
52 | + * |
|
53 | + * @param string $text |
|
54 | + * @param string $color |
|
55 | + * @param int $size |
|
56 | + */ |
|
57 | + public function __construct(string $text, string $color, int $size) |
|
58 | + { |
|
59 | + $this->text = $text; |
|
60 | + $this->color = $color; |
|
61 | + $this->size = $size; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Get the watermark text. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function text(): string |
|
70 | + { |
|
71 | + return $this->text; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the watermark font color. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function color(): string |
|
80 | + { |
|
81 | + return $this->color; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get the watermark maximum font size. |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public function size(): int |
|
89 | + { |
|
90 | + return $this->size; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Return an estimate of the size in pixels of the watermark text length. |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function textLengthEstimate(): int |
|
99 | + { |
|
100 | + return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Decrease the font size if necessary, based on the image width. |
|
105 | + * |
|
106 | + * @param int $width |
|
107 | + */ |
|
108 | + public function adjustSize(int $width): void |
|
109 | + { |
|
110 | + $len = mb_strlen($this->text); |
|
111 | + while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
112 | + $this->size--; |
|
113 | + if ($this->size == 2) { |
|
114 | + return; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Return an estimate of the size in pixels of a text in a specified font size. |
|
121 | + * |
|
122 | + * @param int $text_length |
|
123 | + * @param int $font_size |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + private function stringLengthEstimate(int $text_length, int $font_size): int |
|
127 | + { |
|
128 | + return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
129 | + } |
|
130 | 130 | } |
@@ -125,6 +125,6 @@ |
||
125 | 125 | */ |
126 | 126 | private function stringLengthEstimate(int $text_length, int $font_size): int |
127 | 127 | { |
128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
128 | + return $text_length * (int)ceil(($font_size + 2) * 0.5); |
|
129 | 129 | } |
130 | 130 | } |
@@ -31,73 +31,73 @@ |
||
31 | 31 | */ |
32 | 32 | class CertificatesList implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var CertificatesModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var CertificateFilesystemService $certif_filesystem |
|
43 | - */ |
|
44 | - private $certif_filesystem; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
48 | - */ |
|
49 | - private $url_obfuscator_service; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Constructor for CertificatesList Request Handler |
|
54 | - * |
|
55 | - * @param ModuleService $module_service |
|
56 | - */ |
|
57 | - public function __construct( |
|
58 | - ModuleService $module_service, |
|
59 | - CertificateFilesystemService $certif_filesystem, |
|
60 | - UrlObfuscatorService $url_obfuscator_service |
|
61 | - ) { |
|
62 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
63 | - $this->certif_filesystem = $certif_filesystem; |
|
64 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * {@inheritDoc} |
|
69 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
70 | - */ |
|
71 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
72 | - { |
|
73 | - if ($this->module === null) { |
|
74 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
75 | - } |
|
76 | - |
|
77 | - $tree = $request->getAttribute('tree'); |
|
78 | - assert($tree instanceof Tree); |
|
79 | - |
|
80 | - $title = I18N::translate('Certificates'); |
|
81 | - |
|
82 | - $cities = array_map(function (string $item): array { |
|
83 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
84 | - }, $this->certif_filesystem->cities($tree)); |
|
85 | - |
|
86 | - $city = $request->getQueryParams()['cityobf'] ?? $request->getAttribute('cityobf') ?? ''; |
|
87 | - |
|
88 | - if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
89 | - $title = I18N::translate('Certificates for %s', $city); |
|
90 | - $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
91 | - } |
|
92 | - |
|
93 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
94 | - 'title' => $title, |
|
95 | - 'tree' => $tree, |
|
96 | - 'module_name' => $this->module->name(), |
|
97 | - 'cities' => $cities, |
|
98 | - 'selected_city' => $city, |
|
99 | - 'certificates_list' => $certificates ?? collect(), |
|
100 | - 'url_obfuscator_service' => $this->url_obfuscator_service |
|
101 | - ]); |
|
102 | - } |
|
34 | + use ViewResponseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var CertificatesModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var CertificateFilesystemService $certif_filesystem |
|
43 | + */ |
|
44 | + private $certif_filesystem; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
48 | + */ |
|
49 | + private $url_obfuscator_service; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Constructor for CertificatesList Request Handler |
|
54 | + * |
|
55 | + * @param ModuleService $module_service |
|
56 | + */ |
|
57 | + public function __construct( |
|
58 | + ModuleService $module_service, |
|
59 | + CertificateFilesystemService $certif_filesystem, |
|
60 | + UrlObfuscatorService $url_obfuscator_service |
|
61 | + ) { |
|
62 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
63 | + $this->certif_filesystem = $certif_filesystem; |
|
64 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * {@inheritDoc} |
|
69 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
70 | + */ |
|
71 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
72 | + { |
|
73 | + if ($this->module === null) { |
|
74 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
75 | + } |
|
76 | + |
|
77 | + $tree = $request->getAttribute('tree'); |
|
78 | + assert($tree instanceof Tree); |
|
79 | + |
|
80 | + $title = I18N::translate('Certificates'); |
|
81 | + |
|
82 | + $cities = array_map(function (string $item): array { |
|
83 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
84 | + }, $this->certif_filesystem->cities($tree)); |
|
85 | + |
|
86 | + $city = $request->getQueryParams()['cityobf'] ?? $request->getAttribute('cityobf') ?? ''; |
|
87 | + |
|
88 | + if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
89 | + $title = I18N::translate('Certificates for %s', $city); |
|
90 | + $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
91 | + } |
|
92 | + |
|
93 | + return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
94 | + 'title' => $title, |
|
95 | + 'tree' => $tree, |
|
96 | + 'module_name' => $this->module->name(), |
|
97 | + 'cities' => $cities, |
|
98 | + 'selected_city' => $city, |
|
99 | + 'certificates_list' => $certificates ?? collect(), |
|
100 | + 'url_obfuscator_service' => $this->url_obfuscator_service |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | $title = I18N::translate('Certificates'); |
81 | 81 | |
82 | - $cities = array_map(function (string $item): array { |
|
82 | + $cities = array_map(function(string $item): array { |
|
83 | 83 | return [$this->url_obfuscator_service->obfuscate($item), $item]; |
84 | 84 | }, $this->certif_filesystem->cities($tree)); |
85 | 85 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
91 | 91 | } |
92 | 92 | |
93 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
93 | + return $this->viewResponse($this->module->name().'::certificates-list', [ |
|
94 | 94 | 'title' => $title, |
95 | 95 | 'tree' => $tree, |
96 | 96 | 'module_name' => $this->module->name(), |
@@ -30,51 +30,51 @@ |
||
30 | 30 | */ |
31 | 31 | class AdminTreesPage implements RequestHandlerInterface |
32 | 32 | { |
33 | - use ViewResponseTrait; |
|
33 | + use ViewResponseTrait; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var CertificatesModule|null $module |
|
37 | - */ |
|
38 | - private $module; |
|
35 | + /** |
|
36 | + * @var CertificatesModule|null $module |
|
37 | + */ |
|
38 | + private $module; |
|
39 | 39 | |
40 | - /** |
|
41 | - * |
|
42 | - * @var TreeService $tree_service |
|
43 | - */ |
|
44 | - private $tree_service; |
|
40 | + /** |
|
41 | + * |
|
42 | + * @var TreeService $tree_service |
|
43 | + */ |
|
44 | + private $tree_service; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Constructor for Admin Trees request handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - * @param TreeService $tree_service |
|
51 | - */ |
|
52 | - public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
53 | - { |
|
54 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
55 | - $this->tree_service = $tree_service; |
|
56 | - } |
|
46 | + /** |
|
47 | + * Constructor for Admin Trees request handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + * @param TreeService $tree_service |
|
51 | + */ |
|
52 | + public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
53 | + { |
|
54 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
55 | + $this->tree_service = $tree_service; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | - */ |
|
62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | - { |
|
64 | - $this->layout = 'layouts/administration'; |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | + */ |
|
62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | + { |
|
64 | + $this->layout = 'layouts/administration'; |
|
65 | 65 | |
66 | - if ($this->module === null) { |
|
67 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
68 | - } |
|
66 | + if ($this->module === null) { |
|
67 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
68 | + } |
|
69 | 69 | |
70 | - $trees = $this->tree_service->all(); |
|
71 | - if ($trees->count() == 1) { |
|
72 | - return redirect(route(AdminConfigPage::class, ['tree' => $trees->first()])); |
|
73 | - } |
|
70 | + $trees = $this->tree_service->all(); |
|
71 | + if ($trees->count() == 1) { |
|
72 | + return redirect(route(AdminConfigPage::class, ['tree' => $trees->first()])); |
|
73 | + } |
|
74 | 74 | |
75 | - return $this->viewResponse($this->module->name() . '::admin/trees', [ |
|
76 | - 'title' => $this->module->title(), |
|
77 | - 'trees' => $this->tree_service->all() |
|
78 | - ]); |
|
79 | - } |
|
75 | + return $this->viewResponse($this->module->name() . '::admin/trees', [ |
|
76 | + 'title' => $this->module->title(), |
|
77 | + 'trees' => $this->tree_service->all() |
|
78 | + ]); |
|
79 | + } |
|
80 | 80 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | return redirect(route(AdminConfigPage::class, ['tree' => $trees->first()])); |
73 | 73 | } |
74 | 74 | |
75 | - return $this->viewResponse($this->module->name() . '::admin/trees', [ |
|
75 | + return $this->viewResponse($this->module->name().'::admin/trees', [ |
|
76 | 76 | 'title' => $this->module->title(), |
77 | 77 | 'trees' => $this->tree_service->all() |
78 | 78 | ]); |
@@ -37,128 +37,128 @@ |
||
37 | 37 | */ |
38 | 38 | class CertificateImage implements RequestHandlerInterface |
39 | 39 | { |
40 | - /** |
|
41 | - * @var CertificatesModule|null $module |
|
42 | - */ |
|
43 | - private $module; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var CertificateFilesystemService $certif_filesystem |
|
47 | - */ |
|
48 | - private $certif_filesystem; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var CertificateImageFactory $certif_image_factory |
|
52 | - */ |
|
53 | - private $certif_image_factory; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var CertificateDataService $certif_data_service |
|
57 | - */ |
|
58 | - private $certif_data_service; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
62 | - */ |
|
63 | - private $url_obfuscator_service; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor for Certificate Image Request Handler |
|
67 | - * |
|
68 | - * @param ModuleService $module_service |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - ModuleService $module_service, |
|
72 | - CertificateFilesystemService $certif_filesystem, |
|
73 | - CertificateDataService $certif_data_service, |
|
74 | - UrlObfuscatorService $url_obfuscator_service |
|
75 | - ) { |
|
76 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
77 | - $this->certif_filesystem = $certif_filesystem; |
|
78 | - $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem); |
|
79 | - $this->certif_data_service = $certif_data_service; |
|
80 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
86 | - */ |
|
87 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
88 | - { |
|
89 | - if ($this->module === null) { |
|
90 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
91 | - } |
|
92 | - |
|
93 | - $tree = $request->getAttribute('tree'); |
|
94 | - assert($tree instanceof Tree); |
|
95 | - |
|
96 | - $user = $request->getAttribute('user'); |
|
97 | - assert($user instanceof UserInterface); |
|
98 | - |
|
99 | - $certif_path = $request->getAttribute('cid'); |
|
100 | - $certificate = null; |
|
101 | - if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
102 | - $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
103 | - } |
|
104 | - |
|
105 | - if ($certificate === null) { |
|
106 | - return $this->certif_image_factory |
|
107 | - ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | - ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
|
109 | - ; |
|
110 | - } |
|
111 | - |
|
112 | - $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user); |
|
113 | - $watermark = $use_watermark ? $this->watermark($request, $certificate) : null; |
|
114 | - |
|
115 | - return $this->certif_image_factory->certificateFileResponse( |
|
116 | - $certificate, |
|
117 | - $use_watermark, |
|
118 | - $watermark |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get watermark data for a certificate. |
|
124 | - * |
|
125 | - * @param ServerRequestInterface $request |
|
126 | - * @param Certificate $certificate |
|
127 | - * @return Watermark |
|
128 | - */ |
|
129 | - private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark |
|
130 | - { |
|
131 | - $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR); |
|
132 | - $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
|
133 | - $text = $this->watermarkText($request, $certificate); |
|
134 | - |
|
135 | - return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Get the text to be watermarked for a certificate. |
|
140 | - * |
|
141 | - * @param ServerRequestInterface $request |
|
142 | - * @param Certificate $certificate |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string |
|
146 | - { |
|
147 | - $sid = $request->getQueryParams()['sid'] ?? ''; |
|
148 | - if ($sid !== '') { |
|
149 | - $source = Registry::sourceFactory()->make($sid, $certificate->tree()); |
|
150 | - } else { |
|
151 | - $source = $this->certif_data_service->oneLinkedSource($certificate); |
|
152 | - } |
|
153 | - |
|
154 | - if ($source !== null && $source->canShowName()) { |
|
155 | - $repo = $source->facts(['REPO'])->first(); |
|
156 | - if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) { |
|
157 | - return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName())); |
|
158 | - } |
|
159 | - return $source->fullName(); |
|
160 | - } |
|
161 | - $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT'); |
|
162 | - return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.'); |
|
163 | - } |
|
40 | + /** |
|
41 | + * @var CertificatesModule|null $module |
|
42 | + */ |
|
43 | + private $module; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var CertificateFilesystemService $certif_filesystem |
|
47 | + */ |
|
48 | + private $certif_filesystem; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var CertificateImageFactory $certif_image_factory |
|
52 | + */ |
|
53 | + private $certif_image_factory; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var CertificateDataService $certif_data_service |
|
57 | + */ |
|
58 | + private $certif_data_service; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
62 | + */ |
|
63 | + private $url_obfuscator_service; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor for Certificate Image Request Handler |
|
67 | + * |
|
68 | + * @param ModuleService $module_service |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + ModuleService $module_service, |
|
72 | + CertificateFilesystemService $certif_filesystem, |
|
73 | + CertificateDataService $certif_data_service, |
|
74 | + UrlObfuscatorService $url_obfuscator_service |
|
75 | + ) { |
|
76 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
77 | + $this->certif_filesystem = $certif_filesystem; |
|
78 | + $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem); |
|
79 | + $this->certif_data_service = $certif_data_service; |
|
80 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
86 | + */ |
|
87 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
88 | + { |
|
89 | + if ($this->module === null) { |
|
90 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
91 | + } |
|
92 | + |
|
93 | + $tree = $request->getAttribute('tree'); |
|
94 | + assert($tree instanceof Tree); |
|
95 | + |
|
96 | + $user = $request->getAttribute('user'); |
|
97 | + assert($user instanceof UserInterface); |
|
98 | + |
|
99 | + $certif_path = $request->getAttribute('cid'); |
|
100 | + $certificate = null; |
|
101 | + if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
102 | + $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
103 | + } |
|
104 | + |
|
105 | + if ($certificate === null) { |
|
106 | + return $this->certif_image_factory |
|
107 | + ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | + ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
|
109 | + ; |
|
110 | + } |
|
111 | + |
|
112 | + $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user); |
|
113 | + $watermark = $use_watermark ? $this->watermark($request, $certificate) : null; |
|
114 | + |
|
115 | + return $this->certif_image_factory->certificateFileResponse( |
|
116 | + $certificate, |
|
117 | + $use_watermark, |
|
118 | + $watermark |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get watermark data for a certificate. |
|
124 | + * |
|
125 | + * @param ServerRequestInterface $request |
|
126 | + * @param Certificate $certificate |
|
127 | + * @return Watermark |
|
128 | + */ |
|
129 | + private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark |
|
130 | + { |
|
131 | + $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR); |
|
132 | + $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
|
133 | + $text = $this->watermarkText($request, $certificate); |
|
134 | + |
|
135 | + return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Get the text to be watermarked for a certificate. |
|
140 | + * |
|
141 | + * @param ServerRequestInterface $request |
|
142 | + * @param Certificate $certificate |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string |
|
146 | + { |
|
147 | + $sid = $request->getQueryParams()['sid'] ?? ''; |
|
148 | + if ($sid !== '') { |
|
149 | + $source = Registry::sourceFactory()->make($sid, $certificate->tree()); |
|
150 | + } else { |
|
151 | + $source = $this->certif_data_service->oneLinkedSource($certificate); |
|
152 | + } |
|
153 | + |
|
154 | + if ($source !== null && $source->canShowName()) { |
|
155 | + $repo = $source->facts(['REPO'])->first(); |
|
156 | + if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) { |
|
157 | + return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName())); |
|
158 | + } |
|
159 | + return $source->fullName(); |
|
160 | + } |
|
161 | + $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT'); |
|
162 | + return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.'); |
|
163 | + } |
|
164 | 164 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | if ($certificate === null) { |
106 | 106 | return $this->certif_image_factory |
107 | - ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
107 | + ->replacementImageResponse((string)StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | 108 | ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
109 | 109 | ; |
110 | 110 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
133 | 133 | $text = $this->watermarkText($request, $certificate); |
134 | 134 | |
135 | - return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
135 | + return new Watermark($text, $color, is_numeric($size) ? (int)$size : Watermark::DEFAULT_SIZE); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -34,80 +34,80 @@ |
||
34 | 34 | */ |
35 | 35 | class CertificatePage implements RequestHandlerInterface |
36 | 36 | { |
37 | - use ViewResponseTrait; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var CertificatesModule|null $module |
|
41 | - */ |
|
42 | - private $module; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var CertificateFilesystemService $certif_filesystem |
|
46 | - */ |
|
47 | - private $certif_filesystem; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var CertificateDataService $certif_data_service |
|
51 | - */ |
|
52 | - private $certif_data_service; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
56 | - */ |
|
57 | - private $url_obfuscator_service; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Constructor for CertificatePage Request Handler |
|
62 | - * |
|
63 | - * @param ModuleService $module_service |
|
64 | - * @param CertificateFilesystemService $certif_filesystem |
|
65 | - * @param CertificateDataService $certif_data_service |
|
66 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
67 | - */ |
|
68 | - public function __construct( |
|
69 | - ModuleService $module_service, |
|
70 | - CertificateFilesystemService $certif_filesystem, |
|
71 | - CertificateDataService $certif_data_service, |
|
72 | - UrlObfuscatorService $url_obfuscator_service |
|
73 | - ) { |
|
74 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
75 | - $this->certif_filesystem = $certif_filesystem; |
|
76 | - $this->certif_data_service = $certif_data_service; |
|
77 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * {@inheritDoc} |
|
82 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
83 | - */ |
|
84 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
85 | - { |
|
86 | - if ($this->module === null) { |
|
87 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
88 | - } |
|
89 | - |
|
90 | - $tree = $request->getAttribute('tree'); |
|
91 | - assert($tree instanceof Tree); |
|
92 | - |
|
93 | - $certif_path = $request->getAttribute('cid'); |
|
94 | - if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
95 | - $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
96 | - } |
|
97 | - |
|
98 | - if (!isset($certificate)) { |
|
99 | - FlashMessages::addMessage('The requested certificate is not valid.'); |
|
100 | - return redirect(route(TreePage::class, ['tree' => $tree->name()])); |
|
101 | - } |
|
102 | - |
|
103 | - return $this->viewResponse($this->module->name() . '::certificate-page', [ |
|
104 | - 'title' => I18N::translate('Certificate - %s', $certificate->name()), |
|
105 | - 'tree' => $tree, |
|
106 | - 'module_name' => $this->module->name(), |
|
107 | - 'certificate' => $certificate, |
|
108 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
109 | - 'linked_individuals' => $this->certif_data_service->linkedIndividuals($certificate), |
|
110 | - 'linked_families' => $this->certif_data_service->linkedFamilies($certificate) |
|
111 | - ]); |
|
112 | - } |
|
37 | + use ViewResponseTrait; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var CertificatesModule|null $module |
|
41 | + */ |
|
42 | + private $module; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var CertificateFilesystemService $certif_filesystem |
|
46 | + */ |
|
47 | + private $certif_filesystem; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var CertificateDataService $certif_data_service |
|
51 | + */ |
|
52 | + private $certif_data_service; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
56 | + */ |
|
57 | + private $url_obfuscator_service; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Constructor for CertificatePage Request Handler |
|
62 | + * |
|
63 | + * @param ModuleService $module_service |
|
64 | + * @param CertificateFilesystemService $certif_filesystem |
|
65 | + * @param CertificateDataService $certif_data_service |
|
66 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
67 | + */ |
|
68 | + public function __construct( |
|
69 | + ModuleService $module_service, |
|
70 | + CertificateFilesystemService $certif_filesystem, |
|
71 | + CertificateDataService $certif_data_service, |
|
72 | + UrlObfuscatorService $url_obfuscator_service |
|
73 | + ) { |
|
74 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
75 | + $this->certif_filesystem = $certif_filesystem; |
|
76 | + $this->certif_data_service = $certif_data_service; |
|
77 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * {@inheritDoc} |
|
82 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
83 | + */ |
|
84 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
85 | + { |
|
86 | + if ($this->module === null) { |
|
87 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
88 | + } |
|
89 | + |
|
90 | + $tree = $request->getAttribute('tree'); |
|
91 | + assert($tree instanceof Tree); |
|
92 | + |
|
93 | + $certif_path = $request->getAttribute('cid'); |
|
94 | + if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
95 | + $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
96 | + } |
|
97 | + |
|
98 | + if (!isset($certificate)) { |
|
99 | + FlashMessages::addMessage('The requested certificate is not valid.'); |
|
100 | + return redirect(route(TreePage::class, ['tree' => $tree->name()])); |
|
101 | + } |
|
102 | + |
|
103 | + return $this->viewResponse($this->module->name() . '::certificate-page', [ |
|
104 | + 'title' => I18N::translate('Certificate - %s', $certificate->name()), |
|
105 | + 'tree' => $tree, |
|
106 | + 'module_name' => $this->module->name(), |
|
107 | + 'certificate' => $certificate, |
|
108 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
109 | + 'linked_individuals' => $this->certif_data_service->linkedIndividuals($certificate), |
|
110 | + 'linked_families' => $this->certif_data_service->linkedFamilies($certificate) |
|
111 | + ]); |
|
112 | + } |
|
113 | 113 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | return redirect(route(TreePage::class, ['tree' => $tree->name()])); |
101 | 101 | } |
102 | 102 | |
103 | - return $this->viewResponse($this->module->name() . '::certificate-page', [ |
|
103 | + return $this->viewResponse($this->module->name().'::certificate-page', [ |
|
104 | 104 | 'title' => I18N::translate('Certificate - %s', $certificate->name()), |
105 | 105 | 'tree' => $tree, |
106 | 106 | 'module_name' => $this->module->name(), |
@@ -29,71 +29,71 @@ |
||
29 | 29 | */ |
30 | 30 | class AdminConfigAction implements RequestHandlerInterface |
31 | 31 | { |
32 | - /** |
|
33 | - * @var CertificatesModule|null $module |
|
34 | - */ |
|
35 | - private $module; |
|
36 | - |
|
37 | - /** |
|
38 | - * Constructor for Admin Config Action request handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - */ |
|
42 | - public function __construct(ModuleService $module_service) |
|
43 | - { |
|
44 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | - */ |
|
51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | - { |
|
53 | - $tree = $request->getAttribute('tree'); |
|
54 | - assert($tree instanceof Tree); |
|
55 | - |
|
56 | - $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
57 | - |
|
58 | - if ($this->module === null) { |
|
59 | - FlashMessages::addMessage( |
|
60 | - I18N::translate('The attached module could not be found.'), |
|
61 | - 'danger' |
|
62 | - ); |
|
63 | - return redirect($admin_config_route); |
|
64 | - } |
|
65 | - |
|
66 | - $params = (array) $request->getParsedBody(); |
|
67 | - |
|
68 | - $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string) Auth::PRIV_HIDE); |
|
69 | - $tree->setPreference( |
|
70 | - 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
71 | - $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string) Auth::PRIV_HIDE |
|
72 | - ); |
|
73 | - $tree->setPreference('MAJ_CERTIF_WM_DEFAULT', $params['MAJ_CERTIF_WM_DEFAULT'] ?? ''); |
|
74 | - |
|
75 | - $watermark_font_size = $params['MAJ_CERTIF_WM_FONT_MAXSIZE'] ?? ''; |
|
76 | - if (is_numeric($watermark_font_size) && $watermark_font_size > 0) { |
|
77 | - $tree->setPreference('MAJ_CERTIF_WM_FONT_MAXSIZE', $params['MAJ_CERTIF_WM_FONT_MAXSIZE']); |
|
78 | - } |
|
79 | - |
|
80 | - // Only accept valid color for MAJ_WM_FONT_COLOR |
|
81 | - $watermark_color = $params['MAJ_CERTIF_WM_FONT_COLOR'] ?? ''; |
|
82 | - if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
83 | - $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
84 | - } |
|
85 | - |
|
86 | - // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
87 | - $cert_root_dir = $params['MAJ_CERTIF_ROOTDIR'] ?? ''; |
|
88 | - $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir); |
|
89 | - $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
90 | - $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
91 | - |
|
92 | - FlashMessages::addMessage( |
|
93 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
94 | - 'success' |
|
95 | - ); |
|
96 | - |
|
97 | - return redirect($admin_config_route); |
|
98 | - } |
|
32 | + /** |
|
33 | + * @var CertificatesModule|null $module |
|
34 | + */ |
|
35 | + private $module; |
|
36 | + |
|
37 | + /** |
|
38 | + * Constructor for Admin Config Action request handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + */ |
|
42 | + public function __construct(ModuleService $module_service) |
|
43 | + { |
|
44 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | + */ |
|
51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | + { |
|
53 | + $tree = $request->getAttribute('tree'); |
|
54 | + assert($tree instanceof Tree); |
|
55 | + |
|
56 | + $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
57 | + |
|
58 | + if ($this->module === null) { |
|
59 | + FlashMessages::addMessage( |
|
60 | + I18N::translate('The attached module could not be found.'), |
|
61 | + 'danger' |
|
62 | + ); |
|
63 | + return redirect($admin_config_route); |
|
64 | + } |
|
65 | + |
|
66 | + $params = (array) $request->getParsedBody(); |
|
67 | + |
|
68 | + $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string) Auth::PRIV_HIDE); |
|
69 | + $tree->setPreference( |
|
70 | + 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
71 | + $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string) Auth::PRIV_HIDE |
|
72 | + ); |
|
73 | + $tree->setPreference('MAJ_CERTIF_WM_DEFAULT', $params['MAJ_CERTIF_WM_DEFAULT'] ?? ''); |
|
74 | + |
|
75 | + $watermark_font_size = $params['MAJ_CERTIF_WM_FONT_MAXSIZE'] ?? ''; |
|
76 | + if (is_numeric($watermark_font_size) && $watermark_font_size > 0) { |
|
77 | + $tree->setPreference('MAJ_CERTIF_WM_FONT_MAXSIZE', $params['MAJ_CERTIF_WM_FONT_MAXSIZE']); |
|
78 | + } |
|
79 | + |
|
80 | + // Only accept valid color for MAJ_WM_FONT_COLOR |
|
81 | + $watermark_color = $params['MAJ_CERTIF_WM_FONT_COLOR'] ?? ''; |
|
82 | + if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
83 | + $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
84 | + } |
|
85 | + |
|
86 | + // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
87 | + $cert_root_dir = $params['MAJ_CERTIF_ROOTDIR'] ?? ''; |
|
88 | + $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir); |
|
89 | + $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
90 | + $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
91 | + |
|
92 | + FlashMessages::addMessage( |
|
93 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
94 | + 'success' |
|
95 | + ); |
|
96 | + |
|
97 | + return redirect($admin_config_route); |
|
98 | + } |
|
99 | 99 | } |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | return redirect($admin_config_route); |
64 | 64 | } |
65 | 65 | |
66 | - $params = (array) $request->getParsedBody(); |
|
66 | + $params = (array)$request->getParsedBody(); |
|
67 | 67 | |
68 | - $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string) Auth::PRIV_HIDE); |
|
68 | + $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string)Auth::PRIV_HIDE); |
|
69 | 69 | $tree->setPreference( |
70 | 70 | 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
71 | - $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string) Auth::PRIV_HIDE |
|
71 | + $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string)Auth::PRIV_HIDE |
|
72 | 72 | ); |
73 | 73 | $tree->setPreference('MAJ_CERTIF_WM_DEFAULT', $params['MAJ_CERTIF_WM_DEFAULT'] ?? ''); |
74 | 74 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | // Only accept valid folders for MAJ_CERT_ROOTDIR |
87 | 87 | $cert_root_dir = $params['MAJ_CERTIF_ROOTDIR'] ?? ''; |
88 | 88 | $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir); |
89 | - $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
89 | + $cert_root_dir = trim($cert_root_dir, '/').'/'; |
|
90 | 90 | $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
91 | 91 | |
92 | 92 | FlashMessages::addMessage( |
@@ -30,44 +30,44 @@ |
||
30 | 30 | */ |
31 | 31 | class AdminConfigPage implements RequestHandlerInterface |
32 | 32 | { |
33 | - use ViewResponseTrait; |
|
33 | + use ViewResponseTrait; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var CertificatesModule|null $module |
|
37 | - */ |
|
38 | - private $module; |
|
35 | + /** |
|
36 | + * @var CertificatesModule|null $module |
|
37 | + */ |
|
38 | + private $module; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for Admin Config page request handler |
|
42 | - * |
|
43 | - * @param ModuleService $module_service |
|
44 | - */ |
|
45 | - public function __construct(ModuleService $module_service) |
|
46 | - { |
|
47 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
48 | - } |
|
40 | + /** |
|
41 | + * Constructor for Admin Config page request handler |
|
42 | + * |
|
43 | + * @param ModuleService $module_service |
|
44 | + */ |
|
45 | + public function __construct(ModuleService $module_service) |
|
46 | + { |
|
47 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | - */ |
|
54 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | - { |
|
56 | - $this->layout = 'layouts/administration'; |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | + */ |
|
54 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | + { |
|
56 | + $this->layout = 'layouts/administration'; |
|
57 | 57 | |
58 | - if ($this->module === null) { |
|
59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | - } |
|
58 | + if ($this->module === null) { |
|
59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | + } |
|
61 | 61 | |
62 | - $tree = $request->getAttribute('tree'); |
|
63 | - assert($tree instanceof Tree); |
|
62 | + $tree = $request->getAttribute('tree'); |
|
63 | + assert($tree instanceof Tree); |
|
64 | 64 | |
65 | - $data_folder = Registry::filesystem()->dataName(); |
|
65 | + $data_folder = Registry::filesystem()->dataName(); |
|
66 | 66 | |
67 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
68 | - 'title' => $this->module->title(), |
|
69 | - 'tree' => $tree, |
|
70 | - 'data_folder' => $data_folder |
|
71 | - ]); |
|
72 | - } |
|
67 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
68 | + 'title' => $this->module->title(), |
|
69 | + 'tree' => $tree, |
|
70 | + 'data_folder' => $data_folder |
|
71 | + ]); |
|
72 | + } |
|
73 | 73 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | |
65 | 65 | $data_folder = Registry::filesystem()->dataName(); |
66 | 66 | |
67 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
67 | + return $this->viewResponse($this->module->name().'::admin/config', [ |
|
68 | 68 | 'title' => $this->module->title(), |
69 | 69 | 'tree' => $tree, |
70 | 70 | 'data_folder' => $data_folder |
@@ -24,12 +24,12 @@ |
||
24 | 24 | */ |
25 | 25 | class SourceCertificate extends AbstractElement |
26 | 26 | { |
27 | - /** |
|
28 | - * {@inheritDoc} |
|
29 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
30 | - */ |
|
31 | - public function canonical($value): string |
|
32 | - { |
|
33 | - return strtr($value, '\\', '/'); |
|
34 | - } |
|
27 | + /** |
|
28 | + * {@inheritDoc} |
|
29 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
30 | + */ |
|
31 | + public function canonical($value): string |
|
32 | + { |
|
33 | + return strtr($value, '\\', '/'); |
|
34 | + } |
|
35 | 35 | } |