Skip to content

A simple phpBB3 extension to locally store the content of a post being written, to avoid losing everything after a crash or session expiration.

License

Notifications You must be signed in to change notification settings

GwynethLlewelyn/post-local-storage

Repository files navigation

Logo

post-local-storage

Locally store the content of a post in the phpBB forum software

A simple phpBB3 extension to use the browser's local storage for preventing the content of a post to be lost after a crash or session expiration.

Reasoning

You know how it is. You've taken four hours to write your latest masterpiece to show off to the world on a phpBB forum. You press Submit and... well, your session had expired, so everything is lost. Irretrievably so. Pressing 'back' on the browser will not help. What to do?... well, nothing, really.

You're used to WYSIWYG editors, where such things never happen in the 2020s, so naturally enough you didn't save a copy before you posted the article. But, alas, there is no official WYSIWYG editor in phpBB, for various reasons.

Why, oh why, didn't phpBB save your data?

Well, there is the 'Draft' facility, but that doesn't work as well as it should. Unless you have an extension for that, by default, forum users have to manually press Save Draft — and it will mean that some things (such as attachments) will be lost anyway. Drafts are also stored on the phpBB database, on the backend, so if something goes wrong with your connection and/or the database connection... you'll lose your draft as well.

This extension tries to replicate the most basic solution to the above issues. It uses your browser's local storage facility, which can be accessed using JavaScript. Although details differ between browsers, in general, each will persist the data across crashes. It should also be able to deal with most issues of lost typed content on posts (including on Quick Reply) as well as on Private Messages (PMs), as well as eliminating stale content taking up wasted space on the browser's local storage facility (at least, up to a point). Of course, all of this is only possible for one browser on one computer (as opposed to "Save Draft", which should work across browsers/computers/physical locations).

Installation

If you're reading this on GitHub, then all you need is to either download the last package (on the left) and unzip it to the ext directory under the root of your phpBB3 installation.

Alternatively, you can always grab the latest version with git clone https://github.com/GwynethLlewelyn/post-local-storage. The plugin itself is inside gwynethllewelyn/postlocalstorage. These are the files to upload to your phpBB installation (you'll probably need to create all directories first, e.g. under ext, create gwynethllewelyn/postlocalstorage).

Then go to the ACP > Extensions, on the sidebar: Extension Management | Manage extensions and activate Post Local Storage.

There is no further configuration required.

Upgrading

There was a bug on the versions prior to 1.0.5 (bad JSON indentation on composer.json) which effectively prevented the automatic version-checking mechanism to work as it should. As a consequence, automatic upgrades are only triggered for versions 1.0.6 and up. This mostly means that anyone running a version before 1.0.5 will never get a notification to upgrade. Sorry!

The format of the object saved to the local storage has changed twice — first to add a timestamp (to allow some automatic cleanup of stale data on storage), and second, for saving the contents of the subject line as well, not only the content in the textarea (main body of the article post). The current version of the plugin should be able to retrieve objects from the browser's local storage using the old format and save them using the new one, without loss of data.

While doing these changes, I noticed that the HTML attributes for a Quick Reply changed subtly from those used on a regular reply. This meant slightly tweaking the DOM-transversing functionality so that this plugin works with both. Hopefuly there are no further exceptions, but, if you encounter them, feel free to report those cases as well!

Current testing

Since I have just a limited access to a testing environment, it's worth pointing out that, currenty, my own testing just includes browsers on macOS Big Sur, namely, Brave (Chromium-based), Safari, Firefox, and Microsoft Edge (also Chromium-based). Others, such as Opera, or any mobile/TV-based browser were not tested. phpBB3 is running as a native PHP-based application under nginx + php 8.2/8.3 on a Ubuntu Linux 22.0.4 LTS bare metal server hosted in Germany.

Additionally, there are "mock" pages (coming with the GitHub package, but not with the phpBB3 plugin itself) that allow me to do some testing under different circumstances (I found some weird bugs that way!), beyond those that are handled by the automated CI tools that I'm currently using.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

kylesands
kylesands

💻 🤔
gvp9000
gvp9000

💻 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

More acknowledgements

Many thanks to @Tread and @cabot for gently 'persuading' me to publish this code as a phpBB3.3 extension, by pointing me to all the appropriate bits and pieces of code to be 'assembled' into an extension. Yay!

Kudos to @gvp9000 for finding & fixing an obscure bug that affects Firefox and submitting lots of code to fix this.

Kudos to @kylesands for pointing out and providing a fix for incorrect local storage deletion during Preview as well as for continuing overall support.

Thanks to @TrekRed for suggesting that the subject field gets saved as well.

Logo designed by DALL·E 2.

phpBB3 Logo CodeQL Codacy Badge Codacy Security Scan Liberapay All Contributors