Making SMF static

We have a few legacy forums powered by the good software SMF (SimpleMachines Forum). Like many of the WordPress installs, it’s a pain and a security risk to keep these up-to-date when they are no longer needed as content creation platforms. So, once again I need to convert a web app into static HTML pages. This process proved a bit harder than converting WordPress to static HTML.

Step 1: Upgrade

The first thing to do is update to the latest version. This ensures that if you need to turn this back into a dynamic site, it should hopefully be compatible with whatever the latest version is at that time.

Step 2: Make it public

Next, we’ll need to make it public to guests, so that wget has access to the pages.

Go to the Admin->Features and Options page and check the “Allow guests to browse the forum” box, then click save. Now we have to change the permissions on each board separately. Or with a bit of MySQL magic, we can change them all at once using the CONCAT operator. Open of phpMyAdmin, or something else of your choice. Before we mess with the data, make a copy of the table, just in case we totally hose it.

Browse to the ‘boards’ table, and then to the SQL tab. We’re going to enter an SQL command that will pre-pend (that’s append but onto the front rather than the end) some data.

UPDATE boards SET member_groups=CONCAT('-1,', member_groups) WHERE 1

 

This will add a -1, to the beginning of each field, which makes the board viewable by guests. No need to log in, which means wget can scrape the pages and turn them into HTML.

Step 3: Edit Theme files

Now we get to play around with the theme files to get rid of forum specific items that we won’t need, like links to member info, the login, help, and search links, and anything else that we don’t want.

Here are some items to delete or alter, and the files I found them in for our home-made theme based off of an old default theme.

index.template.php

  • Add a title
  • Get rid of date stamp
  • Get rid of the main menu (Home, Help, Search, Login, etc)

BoardIndex.template.php

  • Search for [‘member’][‘link’] and change it to [‘member’][‘name’] This will take out all links to member profile pages.

Display.template.php

  • Search for [‘member’][‘link’] and change it to [‘member’][‘name’] This will take out all links to member profile pages.
  • Get rid of the drop down menu to select pages.

MessageIndex.template.php

  • Search for [‘member’][‘link’] and change it to [‘member’][‘name’] This will take out all links to member profile pages.
  • Delete the ‘Jump to’ drop-down box and the icons explaining post/board types

Step 4: Fix the URLs

As it stands, SMF has some pretty ugly URLs. There are a couple of mods that I could never get to work. But editing a file and adding an .htaccess file seems to do the trick.

Open the Sources/QueryString.php file and look for the line like this:

$scripturl = $boardurl . '/index.php';

and get rid of the /index.php

Now create a .htaccess file in the root of the forum (in the same folder as the Settings.php file). It should look similar to this:

RewriteEngine On
RewriteBase /7tah/forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /7tah/forum/index.php [L]

 

Step 5: Wget it

Now we run wget on the command line to grab the pages.

wget --mirror -P static-forum -nH -np -p -k -E --cut-dirs=2 http://domain.com/path/forum/

All of the static HTML files will now be located in a directory called static-forum.

Step 6: Fix filenames

Some filenames will be a bit broken. Specifically the style.css has an extra “?fin11” in the html files where the file is called. Also, it get’s name that way. So fix that by changing the name of the file to just style.css (it’s in your Theme directory). Then run this one-line command to search and replace throughout all of the static html files (run the command when you are in the static-forum directory.

find . -name '*.html' -type f -exec perl -pi -e 's/style.css%3Ffin11/style.css/g' {} \;

 

This will look for all of the references to the style.css%3Ffin11 file and change them to style.css. Then the pretty colors and formatting will work. Just for clarification, the %3F is code for a question mark. It shows up as such in the HTML source when viewing from a browser, but is displayed as such in the actual code.

Don’t forget to change the the actual name of the css file to style.css.

Step 7: Protect it

Depending on  your needs, you may want to password protect your new static forum with an htaccess account. The good peoples at Dynamic Drive have an helpful tool for making the two files necessary to make this happen. Just plug in your desired user name, password, and location of the htpasswd file, and then it’s copy and paste into those files on the server.

I change the last line of the htaccess file to require user username so that it works only with the given user, not any valid. But since it only pulls from the specified htpasswd file, it’s kind of pointless.

Step 8: Backup the old

It’s a good idea to make a backup of the database and site files before getting rid of them. I just make a mysqldump of the database, throw it in the forum folder, and then make a tar or zip file of that and put the file in the new static forum folder for safe keeping.

Step 9: That’s it.

Sit back and relax. Your forum is interactive no longer.

Share and Enjoy:
  • Print
  • PDF
  • RSS

Related Posts: