Skip to content

Commit c57acea

Browse files
Chore: clean up excessive debug messages
Many were useful during debugging, but not any more.
1 parent ad6f713 commit c57acea

File tree

4 files changed

+74
-60
lines changed

4 files changed

+74
-60
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
... are most welcome!
44

5-
Mora _complex_ ones should be (preferably!) as a Pull Request (PR) on GitHub.
5+
More _complex_ ones should be (preferably!) as a Pull Request (PR) on GitHub.
66

77
And don't forget to (automatically) add yourself as a contributor: https://allcontributors.org/docs/en/bot/usage
88

@@ -14,4 +14,6 @@ I used to zip things properly (on a Mac) with:
1414

1515
However, since having found that GitHub _will_ deal with automatically creating the zip file *without* even needing an intermediate step when packaging everything together. My new command is now:
1616

17-
`git archive -9 -o postlocalstorage.zip HEAD gwynethllewelyn/** `
17+
`git archive -9 -o postlocalstorage.zip HEAD gwynethllewelyn/** `
18+
19+
It's still somewhat experimental, though...

gwynethllewelyn/postlocalstorage/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A simple phpBB3 extension to locally store the content of a post being written, to avoid losing everything after a crash or session expiration.",
55
"homepage": "https://github.com/GwynethLlewelyn/post-local-storage",
66
"version": "1.2.1",
7-
"time": "2024-04-22",
7+
"time": "2024-04-26",
88
"license": "GPL-2.0-only",
99
"keywords": [
1010
"phpbb",

gwynethllewelyn/postlocalstorage/event/listener.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ static public function getSubscribedEvents()
7575
*/
7676
public function check_expiry_time($event)
7777
{
78-
error_log('[phpBB3 postlocalstorage] checking for expiry time...' . empty($event) ? '(empty event data)' : '(we got something on the event data)');
78+
// The following code is unneeded, it's just here to avoid errors/warnings
79+
// from the many code-checking tools. (gwyneth 20230426)
80+
if (!empty($event))
81+
{
82+
error_log('[phpBB3 postlocalstorage] checking for expiry time... (we got something on the event data)');
83+
}
7984

8085
try
8186
{
@@ -89,19 +94,19 @@ public function check_expiry_time($event)
8994
}
9095
catch (Exception $e)
9196
{
92-
error_log('[phpBB3 postlocalstorage] Something is wrong with session_length: ' . $e->getMessage());
97+
error_log('[phpBB3 postlocalstorage] Something is wrong with `\$session_length`: ' . $e->getMessage());
9398
$session_length = 0;
9499
}
95100
$session_expiry_time = $this->time_now + $session_length;
96101

97-
error_log(
102+
/* error_log(
98103
'[phpBB3 postlocalstorage] check_expiry_time: $this->time_now is '
99104
. $this->time_now
100105
. ' $session_length is '
101106
. $session_length
102107
. '; Total is: '
103108
. $session_expiry_time
104-
);
109+
); */
105110

106111
$this->template->assign_vars(array(
107112
'EXPIRY_TIME' => $session_expiry_time,

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

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// If there is no localStorage support, give up
2525
if (!message.localStorage) {
26-
console.debug("no local storage support");
26+
console.debug("[phpBB3 postlocalstorage] no local storage support");
2727
return;
2828
}
2929
/**
@@ -33,7 +33,7 @@
3333
const textarea = document.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, skipping");
36+
console.debug("[phpBB3 postlocalstorage] no phpBB3 content body textarea found, skipping");
3737
return;
3838
}
3939
/**
@@ -42,7 +42,7 @@
4242
*/
4343
const subject = document.querySelector('input[name="subject"]');
4444
if (!subject) {
45-
console.debug("no phpBB3 subject line found");
45+
console.debug("[phpBB3 postlocalstorage] no phpBB3 subject line found");
4646
// I have not decided what to do in this case! Possibly just:
4747
// subject = "(no subject)";
4848
}
@@ -56,16 +56,16 @@
5656
// @see https://www.phpbb.com/customise/db/extension/postlocalstorage/support/topic/246616?p=877489#p877489
5757
//if key.includes (viewforum.php) then exit
5858
if (key.includes("viewforum.php")) {
59-
console.debug("viewforum, no message box");
59+
// console.debug("[phpBB3 postlocalstorage] viewforum, no message box");
6060
return;
6161
}
6262

63-
// POSTING
64-
//possible key formats
65-
//./phpBB3/posting.php?mode=edit&p=xxxxx#preview#preview#preview#preview .......
66-
//./phpBB3/posting.php?mode=quote&p=xxxxx#preview#preview#preview#preview .......
67-
//./phpBB3/posting.php?mode=reply&t=yyyyy#preview#preview#preview#preview .......
68-
//Remove all "#preview" strings at the end
63+
// ## POSTING
64+
// possible key formats
65+
// ./phpBB3/posting.php?mode=edit&p=xxxxx#preview#preview#preview#preview .......
66+
// ./phpBB3/posting.php?mode=quote&p=xxxxx#preview#preview#preview#preview .......
67+
//. /phpBB3/posting.php?mode=reply&t=yyyyy#preview#preview#preview#preview .......
68+
// Remove all "#preview" strings at the end
6969
else if (key.includes("posting.php?mode=")) {
7070
if (key.endsWith("#preview")) {
7171
var count_hash = key.split("#").length - 1;
@@ -75,65 +75,69 @@
7575
}
7676
}
7777

78-
// PM'ing
79-
//possible key formats
78+
// ## PM'ing
79+
// possible key formats
8080

81-
//1st case
82-
//./phpBB3/ucp.php?i=pm&mode=compose
83-
//do nothing
81+
// - 1st case
82+
// ./phpBB3/ucp.php?i=pm&mode=compose
83+
// do nothing
8484

85-
//2nd case
86-
//./phpBB3/ucp.php?i=ucp_pm&mode=compose returns
87-
//./phpBB3/ucp.php?i=pm&mode=compose
85+
// - 2nd case
86+
// ./phpBB3/ucp.php?i=ucp_pm&mode=compose returns
87+
// ./phpBB3/ucp.php?i=pm&mode=compose
8888
else if (key.includes("ucp.php?i=ucp_pm&mode=compose")) {
8989
key = key.split("?")[0].concat("?i=pm&mode=compose");
9090
}
9191

92-
//3rd case
93-
//./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns
94-
//./phpBB3/ucp.php?i=pm&mode=compose
92+
// - 3rd case
93+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns
94+
// ./phpBB3/ucp.php?i=pm&mode=compose
9595
else if (key.includes("ucp.php?i=pm&mode=compose&action=post")) {
9696
key = key.split("?")[0].concat("?i=pm&mode=compose");
9797
}
9898

99-
//4th case
100-
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&f=xxx&p=yyy returns
101-
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
102-
//5th case
103-
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&f=xxx&p=yyy returns
104-
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
105-
//6th case
106-
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&f=xxx&p=yyy returns
107-
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
108-
109-
else if (key.includes("ucp.php?i=pm&mode=compose&action=reply&f=") || key.includes("ucp.php?i=pm&mode=compose&action=forward&f=") || key.includes("ucp.php?i=pm&mode=compose&action=quote&f=")) {
99+
// - 4th case
100+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&f=xxx&p=yyy returns
101+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
102+
// - 5th case
103+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&f=xxx&p=yyy returns
104+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
105+
// - 6th case
106+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&f=xxx&p=yyy returns
107+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
108+
else if (
109+
key.includes("ucp.php?i=pm&mode=compose&action=reply&f=")
110+
|| key.includes("ucp.php?i=pm&mode=compose&action=forward&f=")
111+
|| key.includes("ucp.php?i=pm&mode=compose&action=quote&f=")) {
110112
var fpos = key.indexOf("&f="),
111113
ppos = key.indexOf("&p=");
112114
if (fpos > -1 && ppos > fpos) {
113115
key = key.substring(0, fpos) + key.substring(ppos);
114116
}
115117
}
116118

117-
//7th case
118-
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&sid=sssssssssssssssssssssssssss&p=yyy returns
119-
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
120-
//8th case
121-
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&sid=sssssssssssssssssssssssssss&p=yyy returns
122-
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
123-
//9th case
124-
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
125-
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
126-
else if (key.includes("ucp.php?i=pm&mode=compose&action=reply&sid=")
119+
// - 7th case
120+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&sid=sssssssssssssssssssssssssss&p=yyy returns
121+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
122+
// - 8th case
123+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&sid=sssssssssssssssssssssssssss&p=yyy returns
124+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
125+
// - 9th case
126+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
127+
// ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
128+
else if (
129+
key.includes("ucp.php?i=pm&mode=compose&action=reply&sid=")
127130
|| key.includes("ucp.php?i=pm&mode=compose&action=forward&sid=")
128-
|| key.includes("ucp.php?i=pm&mode=compose&action=quote&sid=")) {
131+
|| key.includes("ucp.php?i=pm&mode=compose&action=quote&sid=")
132+
) {
129133
var sipos = key.indexOf("&sid="),
130134
pipos = key.indexOf("&p=");
131135
if (sipos > -1 && pipos > sipos) {
132136
key = key.substring(0, sipos) + key.substring(pipos);
133137
}
134138
}
135139
else {
136-
console.debug("no appropriate message key or pm key found");
140+
console.debug("[phpBB3 postlocalstorage] no appropriate post message key or PM key found");
137141
}
138142

139143
/**
@@ -172,15 +176,15 @@
172176
if (Date.now() - data.timestamp > FRESHNESS_INTERVAL) {
173177
// Remove stale data. A new item will be added as soon as the user clicks a key.
174178
message.localStorage.removeItem(key);
175-
console.debug("stale data found; removing from localStorage");
179+
console.debug("[phpBB3 postlocalstorage] stale data found; removing from localStorage");
176180
return;
177181
}
178182
// Data is still considered "fresh" enough, so we replace the value of the textarea with
179183
// what we have on the localStorage.
180184
textarea.value = data?.content ?? "";
181185
// same checking for subject.
182186
subject.value = data?.subject ?? "";
183-
console.debug("textarea content successfully restored");
187+
console.debug("[phpBB3 postlocalstorage] textarea content successfully restored");
184188
} else {
185189
// We don't know if the existing data is stale or not, since it comes from pre-1.1.0 times.
186190
// So, upgrade object to the new format, i.e. add a timestamp to existing content.
@@ -205,15 +209,15 @@
205209
// Note: if the visibilitychange event is being used, one should check to see if the visibilityState
206210
// is 'hidden' or 'visible'; but we're going to save to storage in both cases.
207211
if (message.visibilityState === "hidden") {
208-
console.debug("Saving existing text before moving tab to background");
212+
console.debug("[phpBB3 postlocalstorage] Saving existing text before moving tab to background");
209213
}
210214
if (textarea.value) {
211215
item = JSON.stringify({ "content": textarea.value, "subject": (subject?.value ?? ""), "timestamp": Date.now() });
212216
message.localStorage.setItem(key, item);
213-
console.debug("Existing subject & content saved to localStorage");
217+
// console.debug("[phpBB3 postlocalstorage] Existing subject & content saved to localStorage");
214218
} else {
215219
message.localStorage.removeItem(key);
216-
console.debug("Empty textarea -- remove existing content & subject in localStorage");
220+
console.debug("[phpBB3 postlocalstorage] Empty textarea -- remove existing content & subject in localStorage");
217221
}
218222
}
219223
// When the user presses a key just *once* inside the textarea, run the storage function when the page is unloaded.
@@ -262,7 +266,7 @@
262266
*/
263267
const expiryTime = parseInt(document.getElementById('expiry-time')?.innerText.trim(), 10);
264268
const dateNow = Math.floor(Date.now() / 1000); // we get milliseconds, so we need to convert to seconds.
265-
console.debug("Date.now() in seconds is " + dateNow + " and expiryTime is " + expiryTime);
269+
// console.debug("[phpBB3 postlocalstorage] `Date.now()` in seconds is " + dateNow + " and `expiryTime` is " + expiryTime);
266270

267271
//the if statement for deleting local storage in PM'ing, because expiryTime = 0, it must be fixed
268272
//if (!key.includes("ucp.php")) {
@@ -282,11 +286,14 @@
282286
// Kudos to @kylesands for this (gwyneth 20240416)
283287
// Fixed lack of translation issue by using the 'name' value instead, but if either does
284288
// not exist, localStorage will remain untouched.
285-
if (document.activeElement.tagName?.toLowerCase() == "input" && document.activeElement.name?.toLowerCase() == "post") { // Added to only clear on Input button with Submit value
289+
if (
290+
document.activeElement.tagName?.toLowerCase() == "input"
291+
&& document.activeElement.name?.toLowerCase() == "post"
292+
) { // Added to only clear on Input button with Submit value
286293
message.localStorage.removeItem(key);
287294
message.removeEventListener(unloadEvent, updateStorage);
288-
console.debug("Text submitted (not in preview!); removed from localStorage");
295+
// console.debug("[phpBB3 postlocalstorage] Text submitted (not in preview!); removed from localStorage");
289296
}
290297
}
291298
);
292-
})(this, this.document);
299+
})(this, this.document);

0 commit comments

Comments
 (0)