Skip to content

Commit 520b153

Browse files
committed
[FIX] PHP 8.1 Deprecated: Function strftime() is deprecated
1 parent 848438e commit 520b153

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

core/src/Core.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,17 +3534,13 @@ public function updateValidatedUserSession()
35343534
if ($userId != false) {
35353535
Models\ActiveUserSession::where('internalKey', $userId)->delete();
35363536
Models\ActiveUserSession::where('sid', $this->sid)->delete();
3537-
try {
3538-
Models\ActiveUserSession::updateOrCreate([
3539-
'internalKey' => $userId,
3540-
'sid' => $this->sid,
3541-
], [
3542-
'lasthit' => $this->time,
3543-
'ip' => $_SESSION['ip'],
3544-
]);
3545-
} catch (\Exception $exception) {
3546-
3547-
}
3537+
Models\ActiveUserSession::updateOrCreate([
3538+
'internalKey' => $userId,
3539+
'sid' => $this->sid,
3540+
], [
3541+
'lasthit' => $this->time,
3542+
'ip' => $_SESSION['ip'],
3543+
]);
35483544
}
35493545
}
35503546

@@ -4658,7 +4654,7 @@ public function toDateFormat($timestamp = 0, $mode = '')
46584654
);
46594655
$strTime = $formatter->format($timestamp);
46604656
} elseif ($mode === 'formatOnly') {
4661-
$strTime = $dateFormat;
4657+
$strTime = $this->getConfig('datetime_format');
46624658
}
46634659
} else {
46644660
if (empty($mode)) {

core/src/Legacy/Modifiers.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use EvolutionCMS\Interfaces\ModifiersInterface;
44
use EvolutionCMS\Models\SiteTemplate;
55
use EvolutionCMS\Support\DataGrid;
6+
use IntlDateFormatter;
67

78
class Modifiers implements ModifiersInterface
89
{
@@ -851,7 +852,21 @@ public function getValueFromPreset($key, $value, $cmd, $opt)
851852
if (strpos($opt, '%') !== false) {
852853
return strftime($opt, 0 + $value);
853854
} else {
854-
return date($opt, 0 + $value);
855+
if (extension_loaded('intl')) {
856+
// https://www.php.net/manual/en/class.intldateformatter.php
857+
// https://www.php.net/manual/en/datetime.createfromformat.php
858+
$formatter = new IntlDateFormatter(
859+
evolutionCMS()->getConfig('manager_language'),
860+
IntlDateFormatter::MEDIUM,
861+
IntlDateFormatter::MEDIUM,
862+
null,
863+
null,
864+
$opt
865+
);
866+
return $formatter->format(0 + $value);
867+
} else {
868+
return date($opt, 0 + $value);
869+
}
855870
}
856871
case 'time':
857872
if (empty($opt)) {

manager/views/page/2.blade.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,21 @@
133133
$html = '<p>[%no_active_users_found%]</p>';
134134
} else {
135135
$now = $modx->timestamp($_SERVER['REQUEST_TIME']);
136-
$ph['now'] = strftime('%H:%M:%S', $now);
136+
if (extension_loaded('intl')) {
137+
// https://www.php.net/manual/en/class.intldateformatter.php
138+
// https://www.php.net/manual/en/datetime.createfromformat.php
139+
$formatter = new IntlDateFormatter(
140+
evolutionCMS()->getConfig('manager_language'),
141+
IntlDateFormatter::MEDIUM,
142+
IntlDateFormatter::MEDIUM,
143+
null,
144+
null,
145+
"hh:mm:ss"
146+
);
147+
$ph['now'] = $formatter->format($now);
148+
} else {
149+
$ph['now'] = strftime('%H:%M:%S', $now);
150+
}
137151
$timetocheck = ($now - (60 * 20)); //+$server_offset_time;
138152
$html = '
139153
<div class="card-body">
@@ -163,14 +177,29 @@
163177
$webicon = $activeUser['internalKey'] < 0 ? '<i class="[&icon_globe&]"></i>' : '';
164178
$ip = $activeUser['ip'] === '::1' ? '127.0.0.1' : $activeUser['ip'];
165179
$currentaction = EvolutionCMS\Legacy\LogHandler::getAction($activeUser['action'], $activeUser['id']);
180+
if (extension_loaded('intl')) {
181+
// https://www.php.net/manual/en/class.intldateformatter.php
182+
// https://www.php.net/manual/en/datetime.createfromformat.php
183+
$formatter = new IntlDateFormatter(
184+
evolutionCMS()->getConfig('manager_language'),
185+
IntlDateFormatter::MEDIUM,
186+
IntlDateFormatter::MEDIUM,
187+
null,
188+
null,
189+
"hh:mm:ss"
190+
);
191+
$lasthit = $formatter->format($modx->timestamp($activeUser['lasthit']));
192+
} else {
193+
$lasthit = strftime('%H:%M:%S', $modx->timestamp($activeUser['lasthit']));
194+
}
166195
$userList[] = array(
167196
$idle,
168197
'',
169198
$activeUser['username'],
170199
$webicon,
171200
abs($activeUser['internalKey']),
172201
$ip,
173-
strftime('%H:%M:%S', $modx->timestamp($activeUser['lasthit'])),
202+
$lasthit,
174203
$currentaction
175204
);
176205
}
@@ -280,7 +309,7 @@
280309
'title' => '[%welcome_title%]',
281310
'body' => '
282311
<div class="wm_buttons card-body">' .
283-
($modx->hasPermission("new_document") ? '
312+
($modx->hasPermission("new_document") ? '
284313
<span class="wm_button">
285314
<a target="main" href="index.php?a=4">
286315
<i class="'. $_style['icon_document'] . $_style['icon_size_2x'] . $_style['icon_size_fix'] . '"></i>
@@ -294,31 +323,31 @@
294323
</a>
295324
</span>
296325
' : '') .
297-
($modx->hasPermission("assets_images") ? '
326+
($modx->hasPermission("assets_images") ? '
298327
<span class="wm_button">
299328
<a target="main" href="media/browser/mcpuk/browse.php?filemanager=media/browser/mcpuk/browse.php&type=images">
300329
<i class="'. $_style['icon_camera'] . $_style['icon_size_2x'] . $_style['icon_size_fix'] . '"></i>
301330
<span>[%images_management%]</span>
302331
</a>
303332
</span>
304333
' : '') .
305-
($modx->hasPermission("assets_files") ? '
334+
($modx->hasPermission("assets_files") ? '
306335
<span class="wm_button">
307336
<a target="main" href="media/browser/mcpuk/browse.php?filemanager=media/browser/mcpuk/browse.php&type=files">
308337
<i class="'. $_style['icon_files'] . $_style['icon_size_2x'] . $_style['icon_size_fix'] . '"></i>
309338
<span>[%files_management%]</span>
310339
</a>
311340
</span>
312341
' : '') .
313-
($modx->hasPermission("bk_manager") ? '
342+
($modx->hasPermission("bk_manager") ? '
314343
<span class="wm_button">
315344
<a target="main" href="index.php?a=93">
316345
<i class="'. $_style['icon_database'] . $_style['icon_size_2x'] . $_style['icon_size_fix'] . '"></i>
317346
<span>[%bk_manager%]</span>
318347
</a>
319348
</span>
320349
' : '') .
321-
($modx->hasPermission("change_password") ? '
350+
($modx->hasPermission("change_password") ? '
322351
<span class="wm_button">
323352
<a target="main" href="index.php?a=28">
324353
<i class="'. $_style['icon_lock'] . $_style['icon_size_2x'] . $_style['icon_size_fix'] . '"></i>
@@ -351,7 +380,7 @@
351380
<td>[%yourinfo_total_logins%]</td>
352381
<td><b>[[$_SESSION[\'mgrLogincount\']:math(\'%s+1\')]]</b></td>
353382
</tr>' .
354-
($modx->hasPermission("change_password") ? '
383+
($modx->hasPermission("change_password") ? '
355384
356385
' : '') . '
357386
</table>

0 commit comments

Comments
 (0)