Add support for user defined locale and timezone in date/time prints, remove deprecated PHP strftime

This commit is contained in:
Léo Serre 2022-02-01 21:13:27 +01:00
parent 3a497bbb64
commit 7ec61dbc63
7 changed files with 26 additions and 14 deletions

View File

@ -6,17 +6,29 @@ ini_set("session.cookie_lifetime",60*60*24*30);
session_start();
$user = new Kabano\User();
$user->rank = "visitor"; // All users are visitors
if(isset($_SESSION['userid'])) {
$user->checkID($_SESSION['userid']);
if ($user->checkID($_SESSION['userid'])) {
$user->updateLoginDate();
//setlocale(LC_ALL, $config['locales'][$user->locale][4]);
$config['locale'] = $user->locale;
$config['timezone'] = $user->timezone;
}
else {
session_destroy();
$config['locale'] = locale_get_default();
$config['timezone'] = date_default_timezone_get();
$user->rank = "visitor"; // All users are visitors
}
}
else {
$config['locale'] = locale_get_default();
$config['timezone'] = date_default_timezone_get();
$user->rank = "visitor"; // All users are visitors
}
$user->date_format = new IntlDateFormatter($config['locale'], IntlDateFormatter::LONG, IntlDateFormatter::NONE, $config['timezone']);
$user->datetime_format = new IntlDateFormatter($config['locale'], IntlDateFormatter::LONG, IntlDateFormatter::SHORT, $config['timezone']);
$user->datetimeshort_format = new IntlDateFormatter($config['locale'], IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, $config['timezone']);
?>

View File

@ -213,7 +213,7 @@ class User
$this->visit_date = date('r');
$this->register_date = date('r');
$this->locale = "fr_FR";
$this->timezone = "CEST";
$this->timezone = "Europe/Paris";
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n");

View File

@ -27,7 +27,7 @@
<p class="article_legend">
<a class="article_link" href="<?=$config['rel_root_folder']?>blog/<?=$row->permalink?>">Lire la suite...</a>
<span class="article_infos">
Le <? echo strftime('%e %B %G',strtotime($row->update_date)) ?> par
Le <? echo datefmt_format($user->date_format,strtotime($row->update_date)) ?> par
<? if ($user->rankIsHigher("registered")) { ?>
<a href="<?=$config['rel_root_folder']?>user/p/<?=$row->author?>"><?=$row->author_name?></a>
<? }

View File

@ -15,7 +15,7 @@
<select id="bloghistory">
<? $i = 0;
foreach ($blogHistory->objs as $row) { ?>
<option <?=$row->version_id==$blogArticle->version_id?'selected':''?> value="<?=$i?>"><?=$row->is_archive=="f"?'&bull; ':''?><? echo strftime('%d/%m/%Y %H:%M:%S',strtotime($row->update_date)) ?></option>
<option <?=$row->version_id==$blogArticle->version_id?'selected':''?> value="<?=$i?>"><?=$row->is_archive=="f"?'&bull; ':''?><? echo datefmt_format($user->datetimeshort_format,strtotime($row->update_date)) ?></option>
<? $i++;
} ?>
</select>
@ -45,7 +45,7 @@
else { ?>
<?=$blogArticle->author_name?>
<? } ?>
le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($blogArticle->creation_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
le <? echo datefmt_format($user->datetime_format,strtotime($blogArticle->creation_date)) ?></p>
<!-- COMMENTS -->
@ -83,7 +83,7 @@
<? } else { ?>
<?=$comment->author_obj->name?>
<? } ?>
le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($comment->update_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small>
le <? echo datefmt_format($user->datetime_format,strtotime($comment->update_date)) ?></p>
<? if (($user->rankIsHigher("moderator") || $user->id == $comment->author) && $comment->is_public == 't') { ?>
<span class="delete_link"><a href="<?=$config['rel_root_folder']?>blog/<?=$blogArticle->permalink?>/delete_comment/<?=$comment->id?>"><i class="fas fa-trash"></i> Effacer le commentaire</a></span>
<? } ?>

View File

@ -45,8 +45,8 @@
<a class="username" href="<?=$config['rel_root_folder']?>user/p/<?=$row->id?>"><?=$row->name?></a>
</td>
<td><?=$row->get_rank()?></td>
<td><? echo strftime('%e %B %G',strtotime($row->register_date)) ?></td>
<td><? echo strftime('%e %B %G',strtotime($row->visit_date)) ?></td>
<td><? echo datefmt_format($user->date_format,strtotime($row->register_date)) ?></td>
<td><? echo datefmt_format($user->date_format,strtotime($row->visit_date)) ?></td>
<td>
<? if ($row->website != "") { ?>
<a target="_blank" href="<?=$row->website?>">Site internet <span class="external-link"><i class="fas fa-external-link-alt"></i></span></a>

View File

@ -24,8 +24,8 @@
</aside>
<div id="description">
<p>Langue : <?=$userProfile->get_locale()?></p>
<p>Inscrit le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($userProfile->register_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
<p>Dernière connexion le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($userProfile->visit_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
<p>Inscrit le <? echo datefmt_format($user->datetime_format,strtotime($userProfile->register_date)) ?></p>
<p>Dernière connexion le <? echo datefmt_format($user->datetime_format,strtotime($userProfile->visit_date)) ?></p>
<p><?=$userProfile->get_rank()?></p>
<p>
<? if ($userProfile->website != "") { ?>

View File

@ -15,7 +15,7 @@
<select id="wikihistory">
<? $i = 0;
foreach ($wikiHistory->objs as $row) { ?>
<option <?=$row->version_id==$wikiPage->version_id?'selected':''?> value="<?=$i?>"><?=$row->is_archive=="f"?'&bull; ':''?><? echo strftime('%d/%m/%Y %H:%M:%S',strtotime($row->update_date)) ?></option>
<option <?=$row->version_id==$wikiPage->version_id?'selected':''?> value="<?=$i?>"><?=$row->is_archive=="f"?'&bull; ':''?><? echo datefmt_format($user->datetimeshort_format,strtotime($row->update_date)) ?></option>
<? $i++;
} ?>
</select>
@ -38,7 +38,7 @@
<?=$wikiPage->content_html?>
</div>
<p id="wikiTimestamp">Page mise à jour le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($wikiPage->update_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
<p id="wikiTimestamp">Page mise à jour le <? echo datefmt_format($user->datetime_format,strtotime($wikiPage->update_date)) ?></p>
<div style="clear: both;"> </div>
</section>