Embed SMF into CMSMS (no SMF modification necessary) - Updated

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
Gizmo

Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by Gizmo »

Howto: Fully and Properly Embed SMF (forum software)  into CMSMS

Updated updated notes: These instructions were written for 0.11b5. Obviously stuff has changed, and where I only included line numbers and not function names or surrounding code in order to place the changes, that might make this process a bit tricky. I might go through the recent code someday and update this guide, but until then, you're on your own!

Updated notes: Well, I got this working. I ain't saying it's pretty, just that it can be done. I've revised and combined my posts into this one. Good luck!

I won't go into the background, but suffice it to say that I needed this to happen, so I made it happen. I think that this is functionality is somewhat sought after, so I thought to share it. It's nothing fancy or complicated, it's actually quite simple. I've been up the past 36 hours getting this to work and putting a site together, so please pardon the breivity of these instructions. I'm simply recounting from memory what I did, I may have forgotten something. Otherwise you just need some basic PHP know-how to get it working. I'm sure lots of people here can help you if you need help with this.

Basic Installation

Step 1: Install CMSMS and SMF. Doesn't matter where. You can use an existing installation perfectly fine.

Adding Content through CMS Admin

Step 2: Go into CMSMS and make a PHP code page. I'm not sure why there isn't simply a page/content type for 'PHP code' with the default installation. Maybe there is, I just haven't seen it. Anyway the way I did it was to simply make a "Custom tag". Call it "forum" and enter the following:

Code: Select all

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, $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);
You probably don't need everything there in the 'globals' list. I simply stuck in a snippet of code to list off all the global variables that SMF used, then stuck them all in there.

Step 3: Go into CMSMS and make a new page. Call it 'Forums' or whatever you like. For the content, just put in {forum} to call your custom tag code. Go to your CMSMS site and browse to your Forums page. That's it. You should see your SMF forums embeded into the content area of your CMSMS website. If not then you just need to do some troubleshooting.

Now you simply need a few little fixes to get things fully embeded and working seamlessly.

Step 4: Set the "Forums" page as the Default page for your CMSMS website. This is necessary so that all calls which don't contain a "page=..." reference (ie, all the forum calls) will get passed to the forum scripts. The setback here is that the intro page to your site now has to point to the Forums. There are ways to address this. One such way would be to fiddle with your local Apache directives to set a new Index page, such as  index.php?page=IntroPage. Then set your original intro page's name to 'IntroPage' - that way anyone who access www.yoursite.com/ can get your original intro page.

Modifying SMF

Step 5: Edit SMF's Settings.php (after you have your forum installed and running) and change $boardurl to point to the base url where you've installed CMSMS (like 'http://www.yoursite.com/'). This is the only alteration to SMF files that is required.

Ok, now you should have a working forum embeded into your CMSMS website that you can actually click around and use.  There are now just two additional fixes required.

Modifying CMS

Step 6: Recent changes to the way CMS handles templates and caching has introduced some difficulties in this approach to embeding SMF. Basically what happens though is that the first time the page loads, its contents (whatever forum page you happen to be viewing) gets cached and then whenever you try to view another forum page, you get your first page back again, only displayed in a completely improper way. See this thread for more details on this. Anyway, I didn't have the time  or energy to go digging through the CMS-Smarty templating system, so I instituted a nasty quick fix. I disabled caching completely.

This may or may not be a good thing for you to do, I wouldn't advocate you do this for your particular setup unless you were sure of what you were doing (and the additional load on your webserver). It's just a way to get this to work, I leave it to someone else to implement a better fix.

To disable caching for ALL CMS PAGES (make sure you understand what it is you're doing):

Open lib\into content.function.php. Around line 50, replace

Code: Select all

$this->caching = true; 
with

Code: Select all

$this->caching = false;
Yes, this will kill your load times, yes this is a pretty drastic thing to do. Hopefully someone can devise a better fix to make this suitable for production use.

Step 7: It turns out that CMS tinkers with the superglobals (ie, $_GET) when PHP's magic_quotes_gpc is enabled, which screws up SMF when it receives the variables and thinks that they've been slashed-out (SMF does the opposite of CMSMS and assumes the request variables are all slashed - adding them in if magic_quotes is turned off). The result is that the minute you submit an apostrophe ' into a form field somewhere, you break the database.

You either need to disable magic_quotes which is easily done by adding a line to your .htaccess file, provided your server is configured to allow you to do that (recommended)

Code: Select all

php_flag magic_quotes_gpc off
Or else you need to make the following changes to CMS so that it leaves the request variables alone if we're going to be calling SMF. If you're unsure then make these changes anyway, as they won't hurt anything. To do this, open up include.php and

REPLACE (line ~ 161)

Code: Select all

if(get_magic_quotes_gpc())
with

Code: Select all

if(get_magic_quotes_gpc() &&! isset($_GET['action']))
(All SMF methods have 'action' set as a GET variable, while all CMSMS methods to not)

Step 8: If your forum handles file uploads (attachments or avatars) then you need to perform this step. If you're accessing files or pictures via the forum script, then you can't have CMSMS outputting all kinds of page junk first, otherwise your files will be corrupted. If we're downloading files, we skip CMSMS.

Open up CMSMS's index.php

Right at the top of the page, ADD the lines

Code: Select all

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

Step 9: You're done, that's all the code work. All that is needed now is cosmetic work, mainly tweaking the main SMF template. The most important thing is to CHOP the HTML header stuff. Just delete the , , , , , and tags. The rest is details. Your forum is fully integrated, your site looks good, you don't have to mess around with two seperate templates for your forum and your site, and you get to use all the features, tags, dynamic menus and such on your board.

Step 10: Go out, have a beer.

Working example

[attachment deleted by admin]
Last edited by Gizmo on Fri Feb 10, 2006 12:51 am, edited 1 time in total.
vikramdhani

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by vikramdhani »

Hi thanks for such a gr8 documentions about the embedding of smf in cmsms

i will be trying it out and if i get stuck some where i hope you will be glad to help me  :D

Thanks good job tough
sydefx

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by sydefx »

Hi,

Thanks very much for such a great tutorial.

I have done all the steps ( i hope) and when i preview the Forums page from within CMSMS it works fine!

But when i actually visit the Forums page on the active site the page is simple blank white, with the page title as the url.

Does anyone have any ideas to why this may be?

I am using the latest versions of both software.

Thanks
Piratos

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by Piratos »

Very good work !!!

:)
OnlyJC

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by OnlyJC »

What I found was if you added the line

echo " "; 

3rd line down the script for the custom tag

It fixed the blank page problem
JMaxx

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by JMaxx »

Thanks, Gizmo, works like a charm, using CMS 1.0.4 & SMF 1.1.2

It even was enough to untoggle caching of the page where the forum is embedded, so I didn't need step 6 and also step 7 was not necessary on all 2 hosts I used your tutorial on.

I had to apply the changes mentioned by OnlyJC though, so thanks for that, too.

I am using search engine friendly URLs and did override the DirectoryIndex in the .htaccess to point to a page different to the forum, so it really looks like a seamless integration.
cyberman

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by cyberman »

Daniel15 wrote: Perhaps I could try to do something similar with CMS Made Simple.
Yeah, would be very nice  :) ...
!ALeN

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by !ALeN »

Thank's for code, it's working  ;D
dlfok

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by dlfok »

Thanks for the great tutorial. The only part I have a little trouble with is Step #4. Could you elaborate on this:
There are ways to address this. One such way would be to fiddle with your local Apache directives to set a new Index page, such as  index.php?page=IntroPage.
Where is this done? What are the other ways to address the issue of setting the forum page as the default CMS page?

Thanks!
Marcel
Forum Members
Forum Members
Posts: 54
Joined: Tue Feb 20, 2007 2:17 pm

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by Marcel »

JMaxx wrote: Thanks, Gizmo, works like a charm, using CMS 1.0.4 & SMF 1.1.2

It even was enough to untoggle caching of the page where the forum is embedded, so I didn't need step 6 and also step 7 was not necessary on all 2 hosts I used your tutorial on.

I had to apply the changes mentioned by OnlyJC though, so thanks for that, too.

I am using search engine friendly URLs and did override the DirectoryIndex in the .htaccess to point to a page different to the forum, so it really looks like a seamless integration.
Jmaxx,

How in earthe did you did the DirectoryIndex?, its not working for me

The forum is now fully intergrate, but what i do in the htaccess i'am get not the same as your site

http://www.schoonenzuinig.nl

DirectoryIndex test.php?page=home

I copied the index.php to test.php, and was hoping that it was the trick you did.


Can you please help me with this, or anybody :)

Thkx!!
DJGibbon

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by DJGibbon »

I got tantalisingly close with this:
  • Set SMF up so that it thinks it's installed at the root of the site
  • Set the forum page to be the site default
  • In your .htaccess, add a line like this: DirectoryIndex index.php?page=home
This worked for me APART from that in the menu, the link to the forum came out as just / (as it was the default page) and not /index.php - so clicking on it took you to the home page, not the forum! Argh!

I've had marginally more success by:
  • Telling SMF it's installed at /smf (which it is)
  • Leaving the site default page to be the home page
  • Adding these lines to my .htaccess:
    RewriteCond %{REQUEST_URI} ^/smf/index.php
    RewriteRule ^(.+)$ index.php?page=smf&$1 [QSA]
The mod_rewrite rules redirect any requests for /smf/index.php to the CMSMS page, and append the querystring, which seems to work. You will have to change the second line (RewriteRule etc) to point to the pagename of the page with Gizmo's custom tage in.

I know the rule isn't *quite* right (I suspect it's chucking the /smf/index.php onto the redirected URL) but my mod_rewrite-fu isn't quite strong enough to get it 100% ;)

The problem with this method is that occasionally the Admin section goes bonkers and won't let me in (prompts me for my password but the correct password dumps me back to home). Also, the URLs aren't as nice as the CMSMS ones but I can live with that ;)

The next step really is to look at hacking around the auth stuff to see if it's possible/feasible to tie in with feusers . . . anyone got any experience in this field?
SimonSchaufi

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by SimonSchaufi »

How was THIS Forum included in CMSms? Does anybody know that?
cyberman

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by cyberman »

It was not really embedded - only the SMF template looks like CMSms ...
hadion
Forum Members
Forum Members
Posts: 17
Joined: Thu Apr 26, 2007 10:02 am

Re: Embed SMF into CMSMS (no SMF modification necessary) - Updated

Post by hadion »

Hello,

My forum is installed in the directory "forum". As i understood from the post and http://nl3.php.net/manual/en/function.chdir.php, I need to create the following code:

Code: Select all

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, $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("forum");
require "index.php";
chdir($here);
When I load the page my browser window becomes white instead of loading a page.

What am I doing wrong? ( using SMF 1.1.4 and CMSms 1.2.3. )
Post Reply

Return to “Tips and Tricks”