Home Page
Archive > Posts > Tags > WebSite
Search:

Getting HTML from Simple Machine Forum (SMF) Posts

When I first created my website 10 years ago, from scratch, I did not want to deal with writing a comment system with HTML markups. And in those days, there weren’t plugins for everything like there is today. My solution was setting up a forum which would contain a topic for every Project, Update, and Post, and have my pages mirror the linked topic’s posts.

I had just put in a quick hack at the time in which the pulled SMF message’s body had links converted from bbcode (there might have been 1 other bbcode I also hooked). I had done this with regular expressions, which was a nasty hack.

So anywho, I finally got around to writing a script that converts SMF messages’ bbcode to HTML and caches it. You can download it here, or see the code below. The script is optimized so that it only ever needs to load SMF code when a post has not yet been cached. Caching happens during the initial loading of an SMF post within the script’s main function, and is discarded if the post is changed.

The script requires that you run the query on line #3 of itself in your SMF database. Directly after that are 3 variables you need to set. The script assumes you are already logged in to the appropriate user. To use it, call “GFTP\GetForumTopicPosts($ForumTopicID)”. I have the functions split up so you can do individual posts too if needed (requires a little extra code).


<?
//This SQL command must be ran before using the script
//ALTER TABLE smf_messages ADD body_html text, ADD body_md5 char(32) DEFAULT NULL;

namespace GFTP;

//Forum database variables
global $ForumInfo;
$ForumInfo=Array(
    'DBName'=>'YourDatabase_smf',
    'Location'=>'/home/YourUser/www',
    'MessageTableName'=>'smf2_messages',
);

function GetForumTopicPosts($ForumTopicID)
{
    //Change to the forum database
    global $ForumInfo;
    $CurDB=mysql_fetch_row(mysql_query('SELECT database()'))[0];
    if($CurDB!=$ForumInfo['DBName'])
        mysql_select_db($ForumInfo['DBName']);
    $OldEncoding=SetEncoding(true);

    //Get the posts
    $PostsInfos=Array();
    $PostsQuery=mysql_query('SELECT '.implode(', ', PostFields())." FROM $ForumInfo[MessageTableName] WHERE id_topic='".intval($ForumTopicID).
        "' AND approved=1 ORDER BY id_msg ASC LIMIT 1, 9999999");
    if($PostsQuery) //If query failed, do not process
        while(($PostInfo=mysql_fetch_assoc($PostsQuery)) && ($PostsInfos[]=$PostInfo))
            if(md5($PostInfo['body'])!=$PostInfo['body_md5']) //If the body md5s do not match, get new value, otherwise, use cached value
                ProcessPost($PostsInfos[count($PostsInfos)-1]); //Process the lastest post as a reference

    //Restore from the forum database
    if($CurDB!=$ForumInfo['DBName'])
        mysql_select_db($CurDB);
    SetEncoding(false, $OldEncoding);

    //Return the posts
    return $PostsInfos;
}

function ProcessPost(&$PostInfo) //PostInfo must have fields id_msg, body, body_md5, and body_html
{
    //Load SMF
    global $ForumInfo;
    if(!defined('SMF'))
    {
        global $context;
        require_once(rtrim($ForumInfo['Location'], DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'SSI.php');
        mysql_select_db($ForumInfo['DBName']);
        SetEncoding();
    }

    //Update the cached body_html field
    $ParsedCode=$PostInfo['body_html']=parse_bbc($PostInfo['body']);
    $EscapedHTMLBody=mysql_escape_string($ParsedCode);
    $BodyMD5=md5($PostInfo['body']);
    mysql_query("UPDATE $ForumInfo[MessageTableName] SET body_html='$EscapedHTMLBody', body_md5='$BodyMD5' WHERE id_msg=$PostInfo[id_msg]");
}

//The fields to select in the Post query
function PostFields() { return Array('id_msg', 'poster_time', 'id_member', 'subject', 'poster_name', 'body', 'body_md5', 'body_html'); }

//Swap character encodings. Needs to be set to utf8
function SetEncoding($GetOld=false, $NewSet=Array('utf8', 'utf8', 'utf8'))
{
    //Get the old charset if required
    $CharacterVariables=Array('character_set_client', 'character_set_results', 'character_set_connection');
    $OldSet=Array();
    if($GetOld)
    {
        //Fill in variables with default in case they are not found
        foreach($CharacterVariables as $Index => $Variable)
            $OldSet[$Variable]='utf8';

        //Query for the character sets and update the OldSet array
        $Query=mysql_query('SHOW VARIABLES LIKE "character_%"');
        while($VariableInfo=mysql_fetch_assoc($Query))
            if(isset($OldSet[$VariableInfo['Variable_name']]))
                $OldSet[$VariableInfo['Variable_name']]=$VariableInfo['Value'];

        $OldSet=array_values($OldSet); //Turn back into numerical array
    }

    //Change to the new database encoding
    $CompiledSets=Array();
    foreach($CharacterVariables as $Index => $Variable)
        $CompiledSets[$Index]=$CharacterVariables[$Index].'="'.mysql_escape_string($NewSet[$Index]).'"';
    mysql_query('SET '.implode(', ', $CompiledSets));

    //If requested, return the previous values
    return $OldSet;
}
?>
Lets Encrypt HTTPS Certificates

After a little over a year of waiting, Let’s Encrypt has finally opened its doors to the public! Let’s Encrypt is a free https certificate authority, with the goal of getting the entire web off of http (unencrypted) and on to https. I consider this a very important undertaking, as encryption is one of the best ways we can fight illegal government surveillance. The more out there that is encrypted, the harder it will be to spy on people.

I went ahead and got it up and running on 2 servers today, which was a bit of a pain in the butt. It [no longer] supports Python 2.6, and was also very unhappy with my CentOS 6.4 cPanel install. Also, when you first run the letsencrypt-auto executable script as instructed by the site, it opens up your package manager and immediately starts downloading LOTS of packages. I found this to be quite anti-social, especially as I had not yet seen anywhere, or been warned, that it would do this before I started the install, but oh well. It is convenient. The problem in cPanel was that a specific library, libffi, was causing problems during the install.


To fix the Python problem for all of my servers, I had to install Python 2.7 as an alt Python install so it wouldn’t mess with any existing infrastructure using Python 2.6. After that, I also set the current alias of “python” to “python2.7” so the local shell would pick up on the correct version of Python.


As root in a clean directory:
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar -xzvf Python-2.7.8.tgz
cd Python-2.7.8
./configure --prefix=/usr/local
make
make altinstall
alias python=python2.7

The cPanel lib problem was caused by libffi already being installed as 3.0.9-1.el5.rf, but yum wanted to install its devel package as version 3.0.5-3.2.el6.x86_64 (an older version). It did not like running conflicting versions. All that was needed to fix the problem was to manually download and install the same devel version as the current live version.

wget http://pkgs.repoforge.org/libffi/libffi-devel-3.0.9-1.el5.rf.x86_64.rpm
rpm -ivh libffi-devel-3.0.9-1.el5.rf.x86_64.rpm

Unfortunately, the apache plugin was also not working, so I had to do a manual install with “certonly” and “--webroot”.


And that was it; letsencrypt was ready to go and start signing my domains! You can check out my current certificate, issued today, that currently has 13 domains tied to it!

Getting caught back up
I hate it when life gets too busy

As previously mentioned, I had been trying to do an update every day on my site last month. Unfortunately, unforeseen circumstances revolving around work and Thanksgiving family obligations for almost an entire week made this impossible :-\. So I’ll try to make up the rest of the posts this month :-). At least I got in 23 in a row before I was overwhelmed.

Another Post-A-Day Month
Here we go again

A number of my friends are participating in this year’s NaNoWriMo (National Novel Writing Month), which I was also personally debating participating in. While I wanted to, the deciding factor was I couldn’t come up with a plot I really wanted to write about, and forcing myself to write about something I wasn’t passionate about wouldn’t be any fun. In lieu of this, and to honor the spirit of the project, I decided I would instead get at least one piece of content updated on my site every day this month, which takes just as, if not more, effort. Besides, this course is slightly more productive. ^_^;

Old Home Pages
I like archiving

My domain has undergone many changes over the years, a few of which I have cataloged below. I found these old home pages as I’ve been going back through all my old websites and their scripts, and consolidating and organizing the information. Hopefully there will be more stuff to follow from this effort, including more web scripts.

2002

As mentioned in other posts, my online handle before Dakusan was DarkSide. I have also been using Hyrulean Productions as my company name for, I believe, about 12 years, but I often misspelled it, oops.

FREE SPACE IS NO LONGER OFFERED. SORRY.
All sites below are now closed and remain viewable for archiving and history purposes.

.Dakusan's Domain Dakusan's Domain Info Sasami's Ragnarok World Sasami's Ragnarok World HyNES: Nintendo Emulator
This page designed for 1024x768 resolution at max colors.

RABiD BUNNY FEVER

2004

This one was done by Adam Shen, who is the designer for most other websites I have worked on.

As you may have noticed, I took his original layered-design and turned it into an animated flash, viewable on my current home page (no www).

Dakusan's Domain: Projects Eternal Realms Sasami's Ragnarok World HyNES: Nintendo Emulator Dakusan's Domain Info Dakusan's Domain
Welcome everyone!
It’s about time too

I’ve been working on this site for a long time and had been planning on announcing it to my friends and family since its inception. Unfortunately, I always felt it just wasn’t ready yet, so I never got around to it.

The site has now been going for a few years with over 250 pages of content and downloads available for about half of my projects. I have also recently (finally) gotten up the commenting system, forums, and searching the site, so I feel the time is ripe to let everyone know about it that might be interested :-).


Welcome all and hope you enjoy!

256th Page
Nothing to see here
This post marks my 256th page of content on this website, yay, go me :-). That’s it... nothing else to report...
Site Expansion Progress
200 pages and counting...

This officially marks the 200th page for this site, yay! The full list of everything can be found on the Site Map (Not counting stuff in Ragnarok, Hynes, or Archive lists for posts and updates). About half of the pages have been within the last 4 months too. Just thought I’d mention it... makes me happy I’ve gone through and gotten so much up and organized :-).

I’ll also from here on out try to make sure to get content up on the live website right after I finish creating it. I have this bad habit of letting things queue up on my local testbed web server that I run on my laptop where I create everything.

End of Posting Spree
Yay, 32 posts in 31 days! :-D
I’m now going to be seriously cutting back on the posting schedule and making it a bit more erratic as keeping up with writing this amount of content was way too hard for me x.x; .
Wedding Completed, Yay
Weddings (when participating in) are so much work...

It is now 4:44pm MST (5:44 CST, which is the time zone my website runs on) and I’m currently sitting in the Salt Lake City [Utah] Airport (SLC) with children crying all around me and businessman talking loudly on their cells... people, wee. Thank Thor for headphones + music :-).

Unfortunately, this airport, like most other airports AFAIK, does not provide free public WiFi (Wireless Internet) (examples off the top of my head are Dallas Fort/Worth [DFW] and Austin [AUS]). Phoenix (PHX) did provide free WiFi though, which was really nice. It was (and is, as I am flying there in a few hours for a layover) probably one of the nicest airports I have been to in a while. It even had lots of rows of comfy seats with small 1/.5 ft or so tables between them that had 2 electrical plugs on them, which was all very nicely designed and ergonomic too. Anywho, without access to the internet, I am stuck in 2D land (Snow Crash reference ^_^; ) and am withdrawn from the outside world.

You may notice however that this post is dated while I should be offline. Most of my work and entries for my site are done/posted on my laptop which runs a local web server, and then I move over batches of changes at once when I am finished. I will probably stop this practice once my website is more complete, but at the moment, it works better, and assures I have local backups. This is why, if anyone noticed, why 4 days of posts suddenly showed up yesterday :-). I’ve been on the move lately so I hadn’t had time to do a data transfer.

ANYWAYS, Luis’ wedding was really nice, though a ton of work. As one of the groomsmen I was trying to help out with stuff all day, which all the groomsmen were helping lots too. The bridesmaids had it super easy! I was on my feet almost all day in a heavy suit running around taking pictures, videos, and fixing things, but it was worth it. I’m so happy for Luis, and glad everything went so well ^_^.

Unfortunately, I was not allowed to be there for the actual marriage part (called a Sealing) as it was a Mormon/LDS (Church of Latter Day Saints) ceremony, which takes place in one of their temples, which is sacred and only practicing Mormon adults who have been confirmed are allowed in. Oh well ^_^;. There were probably 50 or so people in the temple to witness the ceremony and 5-10 people waiting outside with me. There were a couple hundred people that showed up for the reception though; the hall was one large mass of people!

There’s not many pictures I want to share publicly here from the event (this is not the place for their personal pictures :-) ), but I do have a couple; especially some I had taken of me in the suit I wore all day, as it’ll probably be a long time before anyone sees me in a formal suit again! ^_^; ... though it is nice to feel respectable sometimes and dress like that.

The weekend was well worth the expensive flight up here (and the suit), as myself and everyone had tons of fun and I got to meet a lot of great new people, and see a lot of old friends I haven’t had the opportunity to hang with for a while. It seems everyone is moving into opposite directions around the country :-\ ... or all the Mormons are just conglomerating in the LDS capitol of the world (Salt Lake City), but we won’t talk about that ^_^;.


The Happy Couple The Groom and I Me Dollar Dancing with the Bride
The Happy Couple The Groom and I Me Dollar Dancing with the Bride
Me (Jeffrey Riaboy)
Me (Jeffrey Riaboy)
Getting the site going
It has been too long
Hi all,

It has now been well over a year since I started working on this web site, and it’s still not even remotely completed. I wanted to have everything finished before a launch, but I realized long ago that would not happen, as there is too much I want from this site, so I will be launching as soon as I can, and updating sections as I go. I had gotten a great deal of it done the first month or two that I had started on it in October of 2006, but then real life kicked in and I lost track of it, and haven’t really touched it since.


Many of the upcoming posts in the near future will be ‘retro posts’ in which I formed the idea sometime in the last year, and jotted down the basic premise to write about more fully later.


I’ll probably be keeping most of my posts geared towards technical stuff, though I am also trying to get most of the non technical stuff out of the way first, too, and I’ll try to update 3-4 times a week, in an every-other day type of schedule, more often if I feel like it or am inspired, as soon as the site is launched.

Welcome to Dakusan's Domain
A new beginning...

I figure near the beginning of this blog (which I will never call this section a blog beyond this point as it gives an inappropriate connotation for what I am trying to do with this site...), I should mention a little bit about myself and my personality. For starters, my name is Jeffrey Riaboy, and I’ve gone by the handle Dakusan for many many years. I’m currently a 25 year old male [I edit this one post and try to keep it up to date] who is mostly freelance, but I hold some steady contract jobs, none of which I can really talk about. I am a 100% self taught programmer/computer scientist/engineer, hacker/reverse engineer, computer repair expert, network engineer, server administrator, etc... [computer] nerd. I spend most of my life and time on computers, though I do get around socially with my small clique of friends :-). My 2 main purposes for this site are to inform people who wish to listen of my learning experiences and discoveries which I find worthy to share, and to get a good archive up of all my life’s work.


I will be trying to keep most of the posts here more towards a computer/technical nature, as I assume that is why anyone visiting this site would be here, but I always have a lot to talk about on other topics so there will be a lot of other stuff too, sorry ^_^;. These non-technical posts will much more frequent the beginnings of my archives so I can get them out of the way. I have a... rather large... backlog list of topics to talk about.


You will find out in the posts to come that I like to poke at things and complain about problems which should be fixed. I spend a large amount of my time making sure everything is working right for a great many people in many ways, and I wish other people would do the same for others and their projects. This is why I vent/rant. Sure, I could get involved in every [open source] project that I like and spearhead the things I see as weaknesses, but alas, there are only so many hours in a day.

You will also find I am quite blatant and honest to a T on anything I discuss. I take this personality quirk IRL to an extreme too, which often gets me in trouble :-).


I try to program as often as possible in C/C++. My favorite aspect of programming is optimization and getting things to work as fast and as best as they can. Unfortunately, a large part of programming [in the “real world”] is engineering the code so that anyone could jump in and work with it; so code layout/design and my personal syntax style are also large on the priority list these days.

I dabble in most all the other mainstream computer languages too. I highly subscribe to “the right tool for the job” philosophy. Which fortunately 99% of the time can keep me away from such travesties as .NET and Java! I work every now and then on “quickies” in VB and PHP. I also work a little too much in JavaScript and Flash (and PHP of course, but I enjoy it in a way), which have become necessities due to the web being such a large market these days.


One of my first big projects was my NES emulator, Hynes. Unfortunately, the emulation community at that time was full of a lot of strife (this was right after the UltraHLE release of 99). Due to my fear of my project being misused and released with a Trojan, I never really got into the open source community. (I now look back at that and wonder why I was so worried... of course, that was before the open source community was really mainstream too)... I am trying to remedy this though and am going back and fixing up all my old projects for release on the web as time permits, which unfortunately, means this will take a very long time :-).


Anyways, I think this pretty much lets you know what this site is for now, who I am, and what to expect. I hope I can keep you interested ^_^. Enjoy.


P.S. You might also notice, which can often be a bad thing, that when I write stuff, I type ALOT. Mostly because I talk online how I talk IRL... bleh.


P.P.S. You may have noticed a long gap between the first post and this one, and many subsequent ones. That is because after making the first post, I decided I needed to build up a real website to host everything, and make it a “big” project. So, further content was put on hold while I worked up everything needed for the launch, and life continued between other posts after that too :-).