Skip to content

Commit 3fdebd7

Browse files
committed
v1.0.0
- PHP code has been updated to include data types for the variables - Fixed issue with "Only variables should be passed by reference" - Added fallback option for DateTimeZone, similar to phpBB core - Move `overall_footer_body_after.html` to `styles/all`
1 parent 38c4c14 commit 3fdebd7

17 files changed

Lines changed: 104 additions & 55 deletions

.github/workflows/tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ on:
55
branches: # ... or remove this branches section to run tests on all your branches
66
- main # Main production branch
77
- master # Legacy or alternative main branch
8-
- dev/* # Any feature branches under "dev/", e.g., dev/new-feature
98

109
pull_request: # Run tests when pull requests are made on these branches in your repo,
1110
branches: # ... or remove this branches section to run tests on all your branches
1211
- main
1312
- master
14-
- dev/*
1513

1614
jobs:
1715
call-tests:
1816
name: Extension tests
1917
uses: phpbb-extensions/test-framework/.github/workflows/tests.yml@3.3.x
2018
with:
21-
EXTNAME: imcger/recenttopicsng # Your extension vendor/package name (required)
19+
EXTNAME: imcger/currenttime # Your extension vendor/package name (required)
2220
RUN_MYSQL_JOBS: 0
2321
RUN_PGSQL_JOBS: 0
2422
RUN_MSSQL_JOBS: 0

imcger/currenttime/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ It's updates the current time, user local time and world clock display every sec
55
The current time is displayed on all pages and can be configured independently of the user date format in the UCP personal settings.
66
The forum time is displayed. This may differ from the browser time due to different time zone settings.
77

8-
You can also display the users local time in the user profile and the post authors local time in the post profile.
8+
You can also display the users local time in the user profile and the authors local time in the post and pm profile.
99

1010
A world clock can be displayed above the navigation bar. This is freely configurable. Up to 6 time zones can be displayed. The settings can be made in the UCP, in the ACP and in the ACP user administration.
1111

12+
[![Tests](https://github.com/IMC-GER/phpBB-Current-Time/actions/workflows/tests.yml/badge.svg)](https://github.com/IMC-GER/RecentTopicsNG/actions/workflows/tests.yml)
13+
1214
## Screenshots
1315
![Displayed Time](https://raw.githubusercontent.com/IMC-GER/images/refs/heads/main/screenshots/currenttime/CurrentTime.gif)
1416
- [UCP Profile view](https://raw.githubusercontent.com/IMC-GER/images/refs/heads/main/screenshots/currenttime/CTWC_profile_view.jpg)
@@ -19,7 +21,7 @@ A world clock can be displayed above the navigation bar. This is freely configur
1921
- [ACP User permissions](https://raw.githubusercontent.com/IMC-GER/images/refs/heads/main/screenshots/currenttime/CTWC_ACP_permissions.jpg)
2022

2123
## Requirements
22-
- php >= 7.1.3
24+
- php >= 7.4
2325
- phpBB >= 3.3.0, < 4.0.0@dev
2426

2527
## Supported Style

imcger/currenttime/acp/acp_module.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@
1212

1313
class acp_module
1414
{
15-
/** @var $action */
16-
public $u_action;
15+
public string $u_action;
16+
public string $tpl_name;
17+
public string $page_title;
1718

18-
/** @var $tpl_name */
19-
public $tpl_name;
20-
21-
/** @var $page_title */
22-
public $page_title;
23-
24-
/** UCP module */
2519
public function main(string $id, string $mode): void
2620
{
2721
global $phpbb_container;

imcger/currenttime/composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "imcger/currenttime",
33
"type": "phpbb-extension",
4-
"description": "Refreshes the display of the current time on the index page. Show users local time and world clock.",
4+
"description": "Displays the current time on all pages, the user's local time and a world clock. The times are updated continuously.",
55
"homepage": "https://github.com/IMC-GER/phpBB-Current-Time",
6-
"version": "0.14.0",
7-
"time": "2025-06-05",
6+
"version": "1.0.0",
7+
"time": "2025-06-15",
88
"license": "GPL-2.0-only",
99
"authors": [
1010
{
@@ -13,9 +13,11 @@
1313
"role": "Developer"
1414
}
1515
],
16-
"require": {
17-
"php": ">=7.4"
18-
},
16+
"require": {
17+
"php": ">=7.4,<8.5.0@dev",
18+
"composer/installers": "~1.0",
19+
"phpbb/phpbb": ">=3.3.0,<4.0.0@dev"
20+
},
1921
"extra": {
2022
"display-name": "Current Time / World Clock",
2123
"soft-require": {

imcger/currenttime/event/main_listener.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,26 @@ public function page_header_after(): void
112112
{
113113
if (isset($clock_data[0]) && $clock_data[0] == 1 && !!$clock_data[1])
114114
{
115-
$dateTimeZone = new \DateTimeZone($clock_data[1]);
115+
try
116+
{
117+
$dateTimeZone = new \DateTimeZone($clock_data[1]);
118+
$fall_back_tz = null;
119+
}
120+
catch (\Exception $e)
121+
{
122+
// If the timezone is invalid, fall back to UTC.
123+
$dateTimeZone = new \DateTimeZone('UTC');
124+
$fall_back_tz = 'UTC';
125+
}
126+
116127
$dateTime = new \DateTime('now', $dateTimeZone);
117128

118129
$timeOffset = $dateTimeZone->getOffset($dateTime);
119-
$city = !!$clock_data[2] ? $clock_data[2] : end(explode('/', $this->language->lang(['timezones', $clock_data[1]])));
130+
$tz_local_ary = explode('/', $this->language->lang(['timezones', $clock_data[1]]));
131+
$city = !!$clock_data[2] ? $clock_data[2] : end($tz_local_ary);
120132

121133
$this->template->assign_block_vars('ctwc_clock', [
122-
'CITY' => $city,
134+
'CITY' => $fall_back_tz ?? $city,
123135
'TIMEOFFSET' => $timeOffset,
124136
]);
125137
}
@@ -167,7 +179,17 @@ public function memberlist_prepare_profile_data(object $event): void
167179
{
168180
if ($event['data']['user_ctwc_disp_localtime'] && $this->config['ctwc_show_localtime_profil'] && $this->auth->acl_get('u_ctwc_cansee_localtime'))
169181
{
170-
$dateTimeZone = new \DateTimeZone($event['data']['user_timezone']);
182+
try
183+
{
184+
$dateTimeZone = new \DateTimeZone($event['data']['user_timezone']);
185+
}
186+
catch (\Exception $e)
187+
{
188+
// If the timezone the user has selected is invalid,
189+
// do not display the incorrect time in the user profile.
190+
return;
191+
}
192+
171193
$dateTime = new \DateTime('now', $dateTimeZone);
172194

173195
$dateformat = $this->user->data['user_dateformat'];
@@ -194,7 +216,17 @@ public function viewtopic_cache_user_data(object $event): void
194216
// Store user timezone in cache data
195217
$user_cache_data = $event['user_cache_data'];
196218

197-
$dateTimeZone = new \DateTimeZone($event['row']['user_timezone']);
219+
try
220+
{
221+
$dateTimeZone = new \DateTimeZone($event['row']['user_timezone']);
222+
}
223+
catch (\Exception $e)
224+
{
225+
// If the timezone the user has selected is invalid,
226+
// do not display the incorrect time in the post profile.
227+
return;
228+
}
229+
198230
$dateTime = new \DateTime('now', $dateTimeZone);
199231

200232
$dateformat = $this->user->data['user_dateformat'];

imcger/currenttime/event/ucp_listener.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,17 @@ public function ucp_pm_view_message(object $event): void
163163
// Store user timezone in cache data
164164
$msg_data = $event['msg_data'];
165165

166-
$dateTimeZone = new \DateTimeZone($event['user_info']['user_timezone']);
166+
try
167+
{
168+
$dateTimeZone = new \DateTimeZone($event['user_info']['user_timezone']);
169+
}
170+
catch (\Exception $e)
171+
{
172+
// If the timezone the user has selected is invalid,
173+
// do not display the incorrect time in the autor profile.
174+
return;
175+
}
176+
167177
$dateTime = new \DateTime('now', $dateTimeZone);
168178

169179
$dateformat = $this->user->data['user_dateformat'];

imcger/currenttime/language/de-x-sie/info_acp_ctwc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$lang = array_merge($lang, [
2222
// Language pack author
2323
'CTWC_LANG_DESC' => 'Deutsch',
24-
'CTWC_LANG_EXT_VER' => '0.14.0',
24+
'CTWC_LANG_EXT_VER' => '1.0.0',
2525
'CTWC_LANG_AUTHOR' => 'IMC-Ger',
2626

2727
'ACP_CT_MODULE_WORLDCLOCK' => 'Current time / World clock',

imcger/currenttime/language/de/info_acp_ctwc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$lang = array_merge($lang, [
2222
// Language pack author
2323
'CTWC_LANG_DESC' => 'Deutsch',
24-
'CTWC_LANG_EXT_VER' => '0.14.0',
24+
'CTWC_LANG_EXT_VER' => '1.0.0',
2525
'CTWC_LANG_AUTHOR' => 'IMC-Ger',
2626

2727
'ACP_CT_MODULE_WORLDCLOCK' => 'Current time / World clock',

imcger/currenttime/language/en/info_acp_ctwc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$lang = array_merge($lang, [
2222
// Language pack author
2323
'CTWC_LANG_DESC' => 'English',
24-
'CTWC_LANG_EXT_VER' => '0.14.0',
24+
'CTWC_LANG_EXT_VER' => '1.0.0',
2525
'CTWC_LANG_AUTHOR' => 'IMC-Ger',
2626

2727
'ACP_CT_MODULE_WORLDCLOCK' => 'Current time / World clock',

imcger/currenttime/migrations/currenttime001.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212

1313
class currenttime001 extends \phpbb\db\migration\migration
1414
{
15-
public function effectively_installed()
15+
public function effectively_installed(): bool
1616
{
1717
return $this->db_tools->sql_column_exists(USERS_TABLE, 'user_imcger_ct_data');
1818
}
1919

20-
public static function depends_on()
20+
public static function depends_on(): array
2121
{
2222
return ['\phpbb\db\migration\data\v330\v330',];
2323
}
2424

25-
public function update_schema()
25+
public function update_schema(): array
2626
{
2727
return [
2828
'add_columns' => [
@@ -42,7 +42,7 @@ public function update_schema()
4242
];
4343
}
4444

45-
public function revert_schema()
45+
public function revert_schema(): array
4646
{
4747
return [
4848
'drop_tables' => [
@@ -56,7 +56,7 @@ public function revert_schema()
5656
];
5757
}
5858

59-
public function update_data()
59+
public function update_data(): array
6060
{
6161

6262
return [

0 commit comments

Comments
 (0)