Script to convert a FluxBB forum into static HTML pages
To archive a forum or only some threads, an HTML converter.
This script is useful if you no longer want to maintain a forum, and reuse the database or simply delete it. Content manager is always the target of spammers trying to find loopholes in the code to access the site as admins. If the forum is abandoned, the CMS will no longer be updated and it will become increasingly vulnerable over time. Converting it to HTML avoid any risk.
You may also want to append a thread in a page of the site.
Content of the archive
- forum2html.php The conversion script.
- forum.css The stylesheet to be included in the static pages.
- template.php A model of static page.
- bubble.png An image used by the default style.
You can replace the contents of the template.php page by the template of your site. But beware it is loaded by the PHP script through the loadHTMLFile method which has limitations.
Similarly, the default style that shows the messages in a comic bubble can be changed.
Using the fluxBB2HTML program
Preferably the script and other files from the archive, including template.php, will be placed at the root of the fluxBB forum. This will allows to access configuration files without to change their paths.
It is best to change the name of the script if it should remain in place for long: otherwise visitors could run it from the browser ...
The program has an interface that allows you to enter a topic number, or a range between two numbers. Click the Convert button to start the automatic convertion of dynamic pages into static pages. The latter will be stored in the same directory as the script so normally in the directory of the original forum.
Their URL is formed by the word "forum", followed by the keywords in the title of the topic, separated by a hyphen, followed by the number of the topic.
Once HTML pages are generated, you can either
- Create an index page with a link to each. The links are already created by the interface.
- Or place links to generated pages in the pages of the site.
- Or take the tag <div class="forum"> with its contents and include it in another page of the site where the discussion is relevant. Do not forget to also include a link to the stylesheet forum.css. The code to copy starts at the comment <!--Generated by fluxBB2HTML--> and ends at <!--End of thread--> </ div>.
When the conversion is complete you can delete the database and erase all fluxBB files.
You can disable the conversion of BB tags to HTML in messages by setting $TRANSLATE_BB to false at the beginning of the script.
Redirects
URLs for dynamic pages converted to HTML are not redirected. You must add a redirect in the .htaccess file if needed. Redirection is only useful if the topic has many backlinks.
If a thread has been integrated into a page on the site, it is not suitable for the dynamic URL to be redirected here, due to SEO issues.
How the program works
The script includes the config.php file that contains the access codes to the database and table prefix.
It also includes cache/cache_config.php that contains the date format possibly defined by the administrator of the forum.
FluxBB tables used by the script
Topics
id | poster | subject | posted | ... | moved_to |
# of the thread | Title of the thread | null if not moved |
What interests us is the id used to select one or several topics, the title, so the subject field, and the field moved_to to be null if the topic is not moving, otherwise it is ignored .
Posts
id | poster | message | posted | ... | topic_id |
User name | Content | Date | # of the thread |
In the program, we retain the message posted, the author's name, the date. You could retain other information if desired, in which case you will have to develop the program.
Topic_id is the number of the thread that is shared by all the posts in the thread. the message ID has no use to us.
If you want to display information about the author as the date of registration, as the software fluxBB does, you must then consult an extra table, users, but the current script does not. In the HTML version the author's name is a simple text field and not a link to a card like in fluxBB.
SQL commands
To select the threads whose numbers have been given as parameters:
if(intval($starting) == intval($ending))
$condition = "((id = '$starting') AND (moved_to IS NULL))";
else
$condition = "((id >= '$starting') AND (id <= '$ending') AND (moved_to IS NULL))"; $sql = "SELECT id, subject, posted, moved_to FROM $tabletopics WHERE $condition ORDER BY posted ASC";
Note the tests whether the thread has been moved, in which case the field moved_to is not null and the topic is ignored.
To select all messages in the same thread:
$query = "SELECT poster, message, posted FROM $tableposts WHERE topic_id='$id'";
We use the same identifier that is stored here in the topic_id column and we select useful information: user name, message content, date.