diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-16 11:50:53 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-27 19:45:02 +0100 |
commit | 36e6d88dbfd753665224664d5214f39ccfbbf6a5 (patch) | |
tree | 7a4a8a7ec50d571d0de554cd80bb74750ae24569 /application/Utils.php | |
parent | c2cd15dac2bfaebe6d32f7649fbdedc07400fa08 (diff) | |
download | Shaarli-36e6d88dbfd753665224664d5214f39ccfbbf6a5.tar.gz Shaarli-36e6d88dbfd753665224664d5214f39ccfbbf6a5.tar.zst Shaarli-36e6d88dbfd753665224664d5214f39ccfbbf6a5.zip |
Feature: add weekly and monthly view/RSS feed for daily page
- Heavy refactoring of DailyController
- Add a banner like in tag cloud to display monthly and weekly links
- Translations: t() now supports variables with optional first letter
uppercase
Fixes #160
Diffstat (limited to 'application/Utils.php')
-rw-r--r-- | application/Utils.php | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/application/Utils.php b/application/Utils.php index bc1c9f5d..db046893 100644 --- a/application/Utils.php +++ b/application/Utils.php | |||
@@ -327,6 +327,23 @@ function format_date($date, $time = true, $intl = true) | |||
327 | } | 327 | } |
328 | 328 | ||
329 | /** | 329 | /** |
330 | * Format the date month according to the locale. | ||
331 | * | ||
332 | * @param DateTimeInterface $date to format. | ||
333 | * | ||
334 | * @return bool|string Formatted date, or false if the input is invalid. | ||
335 | */ | ||
336 | function format_month(DateTimeInterface $date) | ||
337 | { | ||
338 | if (! $date instanceof DateTimeInterface) { | ||
339 | return false; | ||
340 | } | ||
341 | |||
342 | return strftime('%B', $date->getTimestamp()); | ||
343 | } | ||
344 | |||
345 | |||
346 | /** | ||
330 | * Check if the input is an integer, no matter its real type. | 347 | * Check if the input is an integer, no matter its real type. |
331 | * | 348 | * |
332 | * PHP is a bit messy regarding this: | 349 | * PHP is a bit messy regarding this: |
@@ -454,16 +471,20 @@ function alphabetical_sort(&$data, $reverse = false, $byKeys = false) | |||
454 | * Wrapper function for translation which match the API | 471 | * Wrapper function for translation which match the API |
455 | * of gettext()/_() and ngettext(). | 472 | * of gettext()/_() and ngettext(). |
456 | * | 473 | * |
457 | * @param string $text Text to translate. | 474 | * @param string $text Text to translate. |
458 | * @param string $nText The plural message ID. | 475 | * @param string $nText The plural message ID. |
459 | * @param int $nb The number of items for plural forms. | 476 | * @param int $nb The number of items for plural forms. |
460 | * @param string $domain The domain where the translation is stored (default: shaarli). | 477 | * @param string $domain The domain where the translation is stored (default: shaarli). |
478 | * @param array $variables Associative array of variables to replace in translated text. | ||
479 | * @param bool $fixCase Apply `ucfirst` on the translated string, might be useful for strings with variables. | ||
461 | * | 480 | * |
462 | * @return string Text translated. | 481 | * @return string Text translated. |
463 | */ | 482 | */ |
464 | function t($text, $nText = '', $nb = 1, $domain = 'shaarli') | 483 | function t($text, $nText = '', $nb = 1, $domain = 'shaarli', $variables = [], $fixCase = false) |
465 | { | 484 | { |
466 | return dn__($domain, $text, $nText, $nb); | 485 | $postFunction = $fixCase ? 'ucfirst' : function ($input) { return $input; }; |
486 | |||
487 | return $postFunction(dn__($domain, $text, $nText, $nb, $variables)); | ||
467 | } | 488 | } |
468 | 489 | ||
469 | /** | 490 | /** |