Properly Integrate SMF into CMSMS, WebsiteBaker, etc

Started by Gizmo, September 30, 2005, 02:18:41 AM

Previous topic - Next topic

Gizmo

For those of you who wish to integrate SMF into a CMS system like CMS Made Simple or Website Baker which are designed to simply manage some static pages, news, a menu, basic template etc, you can use the following method to integrate SMF into those systems.

These systems typically allow you to create content pages which execute PHP code. The idea is that you'd simply like to call SMF/index.php from within that code. There are 3 basic steps needed in order to make this work.

First, while simply slapping in a require() statement is tempting, you need to consider that when SMF starts running, it expects to be in global space when it starts setting variables, but when the page content code is executed by the CMS, you're typically nestled inside a bunch of functions. The simple solution is to pre-declare those variables as global, and the SMF code can carry on without knowing the difference. Having simply stuck in a snippet to print off the globals on the messageIndex page in SMF, we would use the following:


global $forum_version, $time_start, $maintenance, $mtitle, $mmessage, $mbname, $language, $boardurl, $webmaster_email, $cookiename, $db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_persist, $db_error_send, $boarddir, $sourcedir, $db_last_error, $db_connection, $modSettings, $memcached, $cache_hits, $cache_count, $db_cache, $db_count, $board, $topic, $scripturl, $context, $HTTP_SESSION_VARS,  $rand_code, $ban, $log_time, $timeOnlineUpdated, $old_url, $USER_AGENT, $login_SMFCookie922, $admin_time, $ID_MSG_LAST_VISIT, $unread_messages, $sc, $settings, $user_info, $user_settings, $ID_MEMBER, $txt, $board_info, $options, $db_show_debug, $language_dir, $forum_copyright;

$here = getcwd();
chdir("path/to/SMF/installation");
require "index.php";
chdir($here);


The chdir is probably not necessary, but it makes things totally transparent to both the CMS and SMF. The CMS doesn't care what it's running in the content area, SMF doesn't know it was called from another script. The variable $login_SMFCookie922 needs to be set on a site-to-site basis.

Using that, you can call SMF from another script, inside another function, and it should run just fine.

That's the main part, the rest is basically working out the details.

Second, you then change the $board_url in the Settings.php file of SMF to point to your script/CMS location instead, then set your script/CMS to call the forum "page" everytime a forum function has been requested (ie, anytime either the 'action', 'board' or 'topic' request variables are set). This can usually be easily done. In CMSMS, I just set the forum "page" as the default page for the site (which is called whenever the 'page' request variable is not set)

Third you need to make a slight modification to your script/CMS to bypass itself and call SMF directly anytime a request for a file download (attachment or avatar) has been made. This will just be something at the top of your script/CMS which looks like this:


// Bypass needed for file downloads
if (isset($_GET['action']) && strpos($_SERVER['REQUEST_URL'], 'action=dlattach')) {
require("path/to/SMF/index.php");
exit();
}


And that's pretty much it. You can call SMF inside other scripts - notably content pages for CMS's such as Website Baker or CMS Made Simple - thus allowing you to embed SMF inside the template and dynamic menus and such of your CMS. I've posted details on how to do this in CMSMS on the respective software forum.

hxxp:forum.cmsmadesimple.org/index.php/topic,1785.0.html [nonactive]

Whew it's late. Hope this helps.

Advertisement: