Skip to content

Commit

Permalink
i18n of date time in page lists
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-peugnet committed Nov 5, 2022
1 parent 0aed353 commit df8dd77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
6 changes: 2 additions & 4 deletions app/class/Controllerhome.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,14 @@ public function deepsearch(): array
return ['regex' => $regex, 'searchopt' => $searchopt];
}

public function listquery()
public function listquery(): void
{
if (isset($_POST['query']) && $this->user->iseditor()) {
$datas = array_merge($_POST, $_SESSION['opt']);
$this->optlist = new Optlist();
$this->optlist->hydrate($datas);
$this->optlist = new Optlist($datas);
if (!empty($this->optlist->bookmark())) {
$this->optlist->resetall();
}
$coucou = $this->optlist;
}
}

Expand Down
33 changes: 29 additions & 4 deletions app/class/Optlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Wcms;

use IntlDateFormatter;

class Optlist extends Opt
{
protected $title = 1;
Expand All @@ -17,6 +19,11 @@ class Optlist extends Opt
/** @var string $bookmark Associated bookmark ID */
protected string $bookmark = "";

public function __construct(array $datas = [])
{
parent::__construct($datas);
}

public function parsehydrate(string $encoded)
{
parse_str(ltrim($encoded, "?"), $datas);
Expand Down Expand Up @@ -63,12 +70,30 @@ public function listhtml(array $pagelist, Page $currentpage, Servicerender $rend
$content .= '<span class="description">' . $page->description() . '</span>';
}
if ($this->date()) {
$date = $page->date('pdate');
$content .= "<time datetime=\"$date\">$date</time>\n";
$dateattr = $page->date('pdate');
$formater = new IntlDateFormatter(
$currentpage->lang(),
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE
);
$date = $formater->format($page->date());
$formater = new IntlDateFormatter(
$currentpage->lang(),
IntlDateFormatter::FULL,
IntlDateFormatter::NONE
);
$datetitle = $formater->format($currentpage->date());
$content .= "<time datetime=\"$dateattr\" title=\"$datetitle\">$date</time>\n";
}
if ($this->time()) {
$time = $page->date('ptime');
$content .= "<time datetime=\"$time\">$time</time>\n";
$timeattr = $page->date('ptime');
$formater = new IntlDateFormatter(
$currentpage->lang(),
IntlDateFormatter::NONE,
IntlDateFormatter::SHORT
);
$time = $formater->format($page->date());
$content .= "<time datetime=\"$timeattr\">$time</time>\n";
}
if ($this->author()) {
$usermanager = new Modeluser();
Expand Down

0 comments on commit df8dd77

Please sign in to comment.