Skip to content

Commit 799d227

Browse files
Fix: minor polishing to get session time o work
1 parent 22546a0 commit 799d227

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

gwynethllewelyn/postlocalstorage/event/listener.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(\phpbb\template\template $template, \phpbb\user $use
5050
$this->user = $user;
5151
$this->request = $request;
5252
$this->config = $config;
53-
$this->time_now - time(); // assign current time.
53+
$this->time_now = time(); // assign current time.
5454
}
5555

5656

@@ -61,7 +61,7 @@ public function __construct(\phpbb\template\template $template, \phpbb\user $use
6161
*/
6262
static public function getSubscribedEvents()
6363
{
64-
error_log('[phpBB3 postlocalstorage] my getSubscribedEvents was called!');
64+
// error_log('[phpBB3 postlocalstorage] my getSubscribedEvents was called!');
6565
return [
6666
'core.modify_submit_post_data' => 'check_expiry_time',
6767
'core.posting_modify_template_vars' => 'check_expiry_time',
@@ -75,7 +75,8 @@ static public function getSubscribedEvents()
7575
*/
7676
public function check_expiry_time($event)
7777
{
78-
error_log('[phpBB3 postlocalstorage] Dumping \$event in check_expiry_time()' + print_r($event, true));
78+
// error_log('[phpBB3 postlocalstorage] Dumping \$event in check_expiry_time()' + print_r($event, true));
79+
error_log('[phpBB3 postlocalstorage] checking for expiry time...');
7980

8081
try
8182
{
@@ -92,8 +93,11 @@ public function check_expiry_time($event)
9293
error_log('[phpBB3 postlocalstorage] Something is wrong with session_length: ' . $e->getMessage());
9394
$session_length = 0;
9495
}
95-
// The extra 60 seconds is really just a safeguard.
96-
$session_expiry_time = $this->time_now + $session_length + 60;
96+
$session_expiry_time = $this->time_now + $session_length;
97+
98+
error_log('[phpBB3 postlocalstorage] check_expiry_time: $this->time_now is ' . $this->time_now
99+
. ' $session_length is ' . $session_length
100+
. '; Total is: ' . $session_expiry_time);
97101

98102
$this->template->assign_vars(array(
99103
'EXPIRY_TIME' => $session_expiry_time,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<div id="expiry-time" style="visibility: hidden; display: none;">
3-
{% if EXPIRY_TIME %}
4-
{{ EXPIRY_TIME }}
5-
{% else %}
3+
{%- if EXPIRY_TIME -%}
4+
{{- EXPIRY_TIME -}}
5+
{%- else -%}
66
0
7-
{% endif %}
7+
{%- endif -%}
88
</div>
99
{% INCLUDEJS '@gwynethllewelyn_postlocalstorage/postlocalstorage_functions.js' %}

gwynethllewelyn/postlocalstorage/styles/all/template/postlocalstorage_functions.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
var textarea = doc.querySelector('textarea[name="message"]');
3434
// no point in being around if this is nil; also: avoids crashing below (gwyneth 20220303)
3535
if (!textarea) {
36-
console.debug("no phpBB3 content body textarea found");
36+
console.debug("no phpBB3 content body textarea found, skipping");
3737
return;
3838
}
3939
/**
@@ -178,8 +178,10 @@
178178
* Retrieve the session expiry time that was stamped on the post submit page.
179179
* @type {number}
180180
*/
181-
const expiry_time = document.getElementById('expiry-time').innerText;
182-
if (Date.now > expiry_time) {
181+
const expiry_time = document.getElementById('expiry-time').innerText.trim();
182+
const dateNow = Date.now();
183+
console.debug("Date.now() is " + dateNow + " and expiry_time is " + expiry_time);
184+
if (dateNow > expiry_time) {
183185
// We won't clear anything if the session already expired, so return.
184186
return;
185187
}

0 commit comments

Comments
 (0)