|
6 | 6 | App::plugin('bnomei/recently-modified', [ |
7 | 7 | 'options' => [ |
8 | 8 | 'query' => "site.index(true).sortBy('modified', 'desc').onlyModifiedByUser", |
9 | | - 'format' => null, |
| 9 | + 'format' => function($datetime): string { |
| 10 | + $handler = kirby()->option('date.handler') ?? 'date'; |
| 11 | + $formats = [ |
| 12 | + 'date' => 'Y/m/d H:i:s', |
| 13 | + 'intl' => 'yyyy/MM/dd HH:mm:ss', // https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax |
| 14 | + 'strftime' => '%Y/%m/%d %H:%M:%S' |
| 15 | + ]; |
| 16 | + $format = $formats[$handler] ?? $formats['date']; |
| 17 | + |
| 18 | + return Str::date($datetime, $format, $handler); |
| 19 | + }, |
10 | 20 | 'info' => function (\Kirby\Cms\Page $page) { |
11 | | - return $page->modified(option('bnomei.recently-modified.format')); |
| 21 | + return option('bnomei.recently-modified.format')($page->modified()); |
12 | 22 | }, |
13 | 23 | 'link' => function (\Kirby\Cms\Page $page) { |
14 | 24 | return $page->panel()->url(); |
|
29 | 39 | return $user ? (string)$user->nameOrEmail() : ''; |
30 | 40 | }, |
31 | 41 | 'datetime' => function () { |
32 | | - return $this->model()->modified(option('bnomei.recently-modified.format')); |
| 42 | + return option('bnomei.recently-modified.format')($this->model()->modified()); |
33 | 43 | }, |
34 | 44 | ], |
35 | 45 | ], |
|
192 | 202 | $id = explode('?', ltrim(str_replace(['/pages/', '/_drafts/', '+', ' '], ['/', '/', '/', '/'], $id), '/'))[0]; |
193 | 203 | $kirby = App::instance(null, true); |
194 | 204 |
|
195 | | - $handler = $kirby->option('date.handler') ?? 'date'; |
196 | | - $formats = [ |
197 | | - 'date' => 'Y/m/d H:i:s', |
198 | | - 'intl' => 'yyyy/MM/dd HH:mm:ss', // https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax |
199 | | - 'strftime' => '%Y/%m/%d %H:%M:%S' |
200 | | - ]; |
201 | | - $format = $kirby->option('bnomei.recently-modified.format') ?? $formats[$handler] ?? $formats['date']; |
202 | | - |
203 | 205 | if ($id === 'site') { |
204 | 206 | $user = site()->findRecentlyModifiedByUser(); |
205 | 207 | $username = $user ? (string)$user->nameOrEmail() : ''; |
206 | 208 | return [ |
207 | 209 | 'auser' => $username, |
208 | | - 'datetime' => Str::date(site()->modifiedTimestamp(), $format, $handler), |
| 210 | + 'datetime' => option('bnomei.recently-modified.format')(site()->modifiedTimestamp()), |
209 | 211 | ]; |
210 | 212 | } |
211 | 213 | if ($page = $kirby->page($id)) { |
212 | 214 | $user = $page->findRecentlyModifiedByUser(); |
213 | 215 | $username = $user ? (string)$user->nameOrEmail() : ''; |
214 | 216 | return [ |
215 | 217 | 'auser' => $username, |
216 | | - 'datetime' => $page->modified($format, $handler), |
| 218 | + 'datetime' => option('bnomei.recently-modified.format')($page->modified()), |
217 | 219 | ]; |
218 | 220 | } |
219 | 221 | return \Kirby\Http\Response::json([], 404); |
|
0 commit comments