Skip to content

Commit a375f01

Browse files
committed
v0.14.0
- Changed move generate_datetime_str() to helper controller - Improved, Data types added to variables in php code - Changed php min version to 7.4
1 parent e1e41ff commit a375f01

17 files changed

Lines changed: 208 additions & 233 deletions

imcger/currenttime/acp/acp_info.php

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

1313
class acp_info {
1414

15-
public function module()
15+
public function module(): array
1616
{
1717
return [
1818
'filename' => '\imcger\currenttime\acp\acp_module',
@@ -21,12 +21,12 @@ public function module()
2121
'settings' => [
2222
'title' => 'ACP_CT_SETTINGS',
2323
'auth' => 'ext_imcger/currenttime && acl_a_board',
24-
'cat' => ['ACP_CT_MODULE_WORLDCLOCK',],
24+
'cat' => ['ACP_CT_MODULE_WORLDCLOCK', ],
2525
],
2626
'worldclock_settings' => [
2727
'title' => 'ACP_CTWC_WORLDCL_SETTINGS',
2828
'auth' => 'ext_imcger/currenttime && acl_a_board',
29-
'cat' => ['ACP_CT_MODULE_WORLDCLOCK',],
29+
'cat' => ['ACP_CT_MODULE_WORLDCLOCK', ],
3030
],
3131
],
3232
];

imcger/currenttime/acp/acp_module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class acp_module
2222
public $page_title;
2323

2424
/** UCP module */
25-
public function main($id, $mode)
25+
public function main(string $id, string $mode): void
2626
{
2727
global $phpbb_container;
2828

imcger/currenttime/composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "imcger/currenttime",
33
"type": "phpbb-extension",
44
"description": "Refreshes the display of the current time on the index page. Show users local time and world clock.",
5-
"homepage": "",
6-
"version": "0.13.0",
7-
"time": "2025-05-06",
5+
"homepage": "https://github.com/IMC-GER/phpBB-Current-Time",
6+
"version": "0.14.0",
7+
"time": "2025-06-05",
88
"license": "GPL-2.0-only",
99
"authors": [
1010
{
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.1.3"
17+
"php": ">=7.4"
1818
},
1919
"extra": {
2020
"display-name": "Current Time / World Clock",

imcger/currenttime/config/services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ services:
4141
- '@config'
4242
- '@template'
4343
- '@language'
44-
- '%imcger.currenttime.table.ctwc_data%'
44+
- '@imcger.currenttime.ctwc_helper'
4545
tags:
4646
- { name: event.listener }
4747

@@ -59,6 +59,7 @@ services:
5959
imcger.currenttime.ucp.listener:
6060
class: 'imcger\currenttime\event\ucp_listener'
6161
arguments:
62+
- '@auth'
6263
- '@config'
6364
- '@template'
6465
- '@user'

imcger/currenttime/controller/ctwc_controller.php

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,18 @@
1212

1313
class ctwc_controller
1414
{
15-
/** @var \phpbb\db\driver\driver_interface */
16-
protected $db;
17-
18-
/** @var \phpbb\request\request */
19-
protected $request;
20-
21-
/** @var \phpbb\user */
22-
protected $user;
23-
24-
/** @var \phpbb\template\template */
25-
protected $template;
26-
27-
/** @var \phpbb\language\language */
28-
protected $language;
29-
30-
/** @var \imcger\currenttime\controller\ctwc_helper */
31-
protected $ctwc_helper;
32-
33-
/** @var \phpbb\extension\manager */
34-
protected $ext_manager;
35-
36-
/** @var string Table name */
37-
protected $ctwc_data_table;
38-
39-
/** @var string phpBB root path */
40-
protected $phpbb_root_path;
41-
42-
/** @var string PHP extension */
43-
protected $phpEx;
44-
45-
/** @var string Custom form action */
46-
protected $u_action;
47-
48-
/** @var string source modul */
49-
protected $modul;
15+
protected object $db;
16+
protected object $request;
17+
protected object $user;
18+
protected object $template;
19+
protected object $language;
20+
protected object $ctwc_helper;
21+
protected object $ext_manager;
22+
protected string $ctwc_data_table;
23+
protected string $phpbb_root_path;
24+
protected string $phpEx;
25+
protected string $u_action;
26+
protected string $modul;
5027

5128
/**
5229
* Constructor
@@ -81,7 +58,7 @@ public function __construct
8158
/**
8259
* Display the options a user can configure for this extension
8360
*/
84-
public function display_options($modul)
61+
public function display_options(string $modul): void
8562
{
8663
$this->modul = $modul;
8764

@@ -169,7 +146,7 @@ public function display_options($modul)
169146
/**
170147
* Set template variables
171148
*/
172-
protected function set_template_vars(?array $user_setting = null)
149+
protected function set_template_vars(?array $user_setting = null): void
173150
{
174151
if (!isset($user_setting) && $this->modul == 'acp')
175152
{
@@ -221,7 +198,7 @@ protected function set_template_vars(?array $user_setting = null)
221198
/**
222199
* The selected action (ACP & UCP section).
223200
*/
224-
public function set_page_url($action)
201+
public function set_page_url(string $action): void
225202
{
226203
$this->u_action = $action;
227204
}

imcger/currenttime/controller/ctwc_general_settings.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,13 @@
1212

1313
class ctwc_general_settings
1414
{
15-
/** @var \phpbb\config\config */
16-
protected $config;
17-
18-
/** @var \phpbb\request\request */
19-
protected $request;
20-
21-
/** @var \phpbb\user */
22-
protected $user;
23-
24-
/** @var \phpbb\template\template */
25-
protected $template;
26-
27-
/** @var \phpbb\language\language */
28-
protected $language;
29-
30-
/** @var \phpbb\extension\manager */
31-
protected $ext_manager;
32-
33-
/** @var string Custom form action */
34-
protected $u_action;
15+
protected object $config;
16+
protected object $request;
17+
protected object $user;
18+
protected object $template;
19+
protected object $language;
20+
protected object $ext_manager;
21+
protected string $u_action;
3522

3623
/**
3724
* Constructor
@@ -57,7 +44,7 @@ public function __construct
5744
/**
5845
* Display the options a user can configure for this extension
5946
*/
60-
public function general_settings()
47+
public function general_settings(): void
6148
{
6249
$this->language->add_lang(['ucp', ]);
6350

@@ -85,7 +72,7 @@ public function general_settings()
8572
/**
8673
* Set template variables
8774
*/
88-
protected function set_template_vars()
75+
protected function set_template_vars(): void
8976
{
9077
$metadata_manager = $this->ext_manager->create_extension_metadata_manager('imcger/currenttime');
9178

@@ -103,7 +90,7 @@ protected function set_template_vars()
10390
/**
10491
* The selected action (ACP & UCP section).
10592
*/
106-
public function set_page_url($action)
93+
public function set_page_url(string $action): void
10794
{
10895
$this->u_action = $action;
10996
}

imcger/currenttime/controller/ctwc_helper.php

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

1313
class ctwc_helper
1414
{
15-
/** @var \phpbb\user */
16-
protected $user;
17-
18-
/** @var \phpbb\template\template */
19-
protected $template;
20-
21-
/** @var \phpbb\language\language */
22-
protected $language;
15+
protected object $user;
16+
protected object $template;
17+
protected object $language;
2318

2419
/**
2520
* Constructor
@@ -39,7 +34,7 @@ public function __construct
3934
/**
4035
* Options to pick a timezone and date/time
4136
*/
42-
public function timezone_select($prefix = '', $default = '')
37+
public function timezone_select(string $prefix = '', string $default = ''): void
4338
{
4439
$default_offset = '';
4540

@@ -110,6 +105,9 @@ public function timezone_select($prefix = '', $default = '')
110105

111106
/*
112107
* Creates an array of variables for the SelectBox macro
108+
*
109+
* The variable $cfg_value is a union type array|string
110+
* Not specified for reasons of compatibility with php 7
113111
*/
114112
public function select_struct($cfg_value, array $options): array
115113
{
@@ -135,7 +133,7 @@ public function select_struct($cfg_value, array $options): array
135133
/*
136134
* Creates an array of dateformat options for the SelectBox macro
137135
*/
138-
public function set_select_template_vars($date_format, $template_var)
136+
public function set_select_template_vars(string $date_format, string $template_var): void
139137
{
140138
$this->language->add_lang(['info_acp_ctwc', ], 'imcger/currenttime');
141139

@@ -154,4 +152,59 @@ public function set_select_template_vars($date_format, $template_var)
154152
$template_var => $this->select_struct($date_format, $dateformat_options),
155153
]);
156154
}
155+
156+
/*
157+
* Changes the placeholder in the date/time string for the JavaScript clock class
158+
*/
159+
public function generate_datetime_str(string $replacement, string $format): string
160+
{
161+
$pattern = [
162+
'/(?<!\\\\)g/', // hour in 12-hour format; without leading zero 1 to 12
163+
'/(?<!\\\\)G/', // hour in 24-hour format; without leading zero 0 to 23
164+
'/(?<!\\\\)h/', // hour in 12-hour format; with leading zero 01 to 12
165+
'/(?<!\\\\)H/', // hour in 24-hour format; with leading zero 00 to 23
166+
'/(?<!\\\\)i/', // minutes; with leading zero 00 to 59
167+
'/(?<!\\\\)s/', // seconds; with leading zero 00 to 59
168+
'/(?<!\\\\)a/', // Lowercase Ante meridiem and Post meridiem am or pm
169+
'/(?<!\\\\)A/', // Uppercase Ante meridiem and Post meridiem AM or PM
170+
'/(?<!\\\\)y/', // A two digit representation of a year
171+
'/(?<!\\\\)Y/', // A full numeric representation of a year
172+
'/(?<!\\\\)n/', // Numeric representation of a month, without leading zeros 1 through 12
173+
'/(?<!\\\\)m/', // Numeric representation of a month, with leading zeros 01 through 12
174+
'/(?<!\\\\)M/', // A short textual representation of a month, three letters Jan through Dec
175+
'/(?<!\\\\)jS/', // Day of the month with suffix and without leading zeros 1st to 31st
176+
'/(?<!\\\\)j/', // Day of the month without leading zeros 1 to 31
177+
'/(?<!\\\\)d/', // Day of the month, 2 digits with leading zeros 01 to 31
178+
'/(?<!\\\\)D/', // A textual representation of a day, three letters Mon through Sun
179+
'/(?<!\\\\)z1/', // The day of the year (starting from 1) 1 through 366
180+
'/(?<!\\\\)z/', // The day of the year (starting from 0) 0 through 365
181+
'/(?<!\\\\)W0S/', // Week number of year, weeks starting on Sunday 1st to 53rd
182+
'/(?<!\\\\)W7S/', // Weeks starting on Sunday, weeks count from 1st Januar 1st to 54rd
183+
// with suffix
184+
'/(?<!\\\\)WS/', // ISO 8601 week number of year, weeks starting on Monday 1st to 53rd
185+
'/(?<!\\\\)W0/', // Week number of year, weeks starting on Sunday 1 to 53
186+
'/(?<!\\\\)W7/', // Weeks starting on Sunday, weeks count from 1st Januar 1 to 54
187+
'/(?<!\\\\)W/', // ISO 8601 week number of year, weeks starting on Monday 1 to 53
188+
'/(?<!\\\\)l/', // A full textual representation of the day of the week Sunday through Saturday
189+
'/(?<!\\\\)F/', // A full textual representation of a month January through December
190+
'/(?<!\\\\)O/', // Difference to Greenwich time (GMT) without colon Example: +0200
191+
'/(?<!\\\\)P/', // Difference to Greenwich time (GMT) with colon Example: +02:00
192+
];
193+
194+
$ct_replacement = [
195+
'{\g}', '{\G}', '{\h}', '{\H}', '{\i}', '{\s}', '{\a}', '{\A}', '{\y}', '{\Y}', '{\n}',
196+
'{\m}', '{\M}', '{\j\S}', '{\j}', '{\d}', '{\D}', '{\z1}', '{\z}', '{\W0\S}', '{\W7\S}', '{\W\S}',
197+
'{\W0}', '{\W7}', '{\W}', '{\l}', '{\F}', '{\O}', '{\P}',
198+
];
199+
200+
$wc_replacement = [
201+
'{g}', '{G}', '{h}', '{H}', '{i}', '{s}', '{a}', '{A}', '{y}', '{Y}', '{n}',
202+
'{m}', '{M}', '{jS}', '{j}', '{d}', '{D}', '{z1}', '{z}', '{W0S}', '{W7S}', '{WS}',
203+
'{W0}', '{W7}', '{W}', '{l}', '{F}', '{O}', '{P}',
204+
];
205+
206+
$replacement = $replacement == 'ct' ? $ct_replacement : $wc_replacement;
207+
208+
return preg_replace($pattern, $replacement, $format);
209+
}
157210
}

imcger/currenttime/event/acp_listener.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,11 @@
1717
*/
1818
class acp_listener implements EventSubscriberInterface
1919
{
20-
/** @var \phpbb\user */
21-
protected $user;
22-
23-
/** @var config */
24-
protected $config;
25-
26-
/** @var \phpbb\template\template */
27-
protected $template;
28-
29-
/** @var \phpbb\request\request */
30-
protected $request;
31-
32-
/** @var \imcger\currenttime\controller\ctwc_helper */
33-
protected $ctwc_helper;
34-
20+
protected object $user;
21+
protected object $config;
22+
protected object $template;
23+
protected object $request;
24+
protected object $ctwc_helper;
3525

3626
/**
3727
* Constructor
@@ -55,7 +45,7 @@ public function __construct
5545
/**
5646
* Get subscribed events
5747
*/
58-
public static function getSubscribedEvents()
48+
public static function getSubscribedEvents(): array
5949
{
6050
return [
6151
'core.acp_users_prefs_modify_data' => 'acp_users_prefs_modify_data',
@@ -67,7 +57,7 @@ public static function getSubscribedEvents()
6757
/**
6858
* Modify users preferences data
6959
*/
70-
public function acp_users_prefs_modify_data($event)
60+
public function acp_users_prefs_modify_data(object $event): void
7161
{
7262
$user_setting = json_decode($event['user_row']['user_imcger_ct_data'], true);
7363
$currtime_format = !!$event['user_row']['user_ctwc_currtime_format'] ? $event['user_row']['user_ctwc_currtime_format'] : $this->user->date_format;
@@ -92,7 +82,7 @@ public function acp_users_prefs_modify_data($event)
9282
/**
9383
* Modify SQL query before users preferences are updated
9484
*/
95-
public function acp_users_prefs_modify_sql($event)
85+
public function acp_users_prefs_modify_sql(object $event): void
9686
{
9787
$user_setting = [];
9888

@@ -119,7 +109,7 @@ public function acp_users_prefs_modify_sql($event)
119109
/**
120110
* Modify users preferences data before assigning it to the template
121111
*/
122-
public function acp_users_prefs_modify_template_data($event)
112+
public function acp_users_prefs_modify_template_data(object $event): void
123113
{
124114
$user_auth = new \phpbb\auth\auth();
125115
$userdata = $user_auth->obtain_user_data($event['user_row']['user_id']);

0 commit comments

Comments
 (0)