Site integration (boards)

From Online Manual

Jump to: navigation, search

Many people would like to learn to do stuff such as what is done at simplemachines.org and other SMF sites where the content is loaded even on non SMF pages.

Have you ever seen a website that includes information taken directly from an SMF powered forum? Many people have use for including information from their forum on to their website, and thus use integration between their website and forum to help make the user feel well connected. An example can be found directly at the Simple Machines website, which uses the site's top menu inside the forum and extracts the latest news posted on the news board on the main page.

It is not difficult to accomplish this for your own website and forum with the use of SSI.php. for more information about SSI.php see

This tutorial assumes that you have some level of HTML and PHP knowledge.

From the most simplest things, up to building a whole site, SSI can be used sparingly or extensively.

Let's say you wanted to create a page that displays board information.

<?php

// Get SSI into the mix.
include_once(dirname(dirname(__FILE__)) . '/Demo/SSI.php');

// What boards do we want to load?
$myboards = array(1, 2, 3);

// This is simple.. For each board, load the info and remove the junk.
foreach ($myboards as $board)
{
// With $board set as the current board this function will use it to load the board.
loadBoard();

// If we got nothing it must be an error.
if (empty($board_info))
die('Hey, ' . $board . ' is empty');

// Clean up and only use the stuff we want.
$context['boards'][$board] = array(
'id' => $board_info['id'],
'name' => $board_info['name'],
'description' => $board_info['description'],
'moderators' => array(),
);

// Moderators contain too much junk. We can fix this.
if (!empty($board_info['moderators']))
foreach ($board_info['moderators'] as $temp_mod)
$context['boards'][$board]['moderators'][] = $temp_mod['name'];
}

// Get rid of the unnecessary.
unset($myboards, $board_info);

// Header..
echo '
<html>
<head>
<title>Test Document</title>
</head>
<body>
<table border="1">';

// Now we output.
foreach ($context['boards'] as $b)
{
echo '
<tr>
<td colspan="3">', $b['name'], '</td>
</tr>
<tr>
<td></td>
<td>Desciption</td>
<td>', $b['description'], '</td>
</tr>
<tr>
<td></td>
<td>Moderators</td>
<td>', implode(', ', $b['moderators']), '</td>
</tr>';
}

// Echo footer.
echo '
</table>
</body>
</html>';

?>

This script would output board information from boards with IDs of 1, 2 and 3. So we get something like:

General Discussion
   Description    Feel free to talk about anything and everything in this board.
   Moderators    
FAQ Discussion
   Description    FAQ Discussion
   Moderators    test
Feedback
   Description    
   Moderators

And our board Information is now on another page on our site but not within SMF visibly.

Thus allowing you to put your site information where ever you want it on your site. The script is very well commented and easy to follow and should work as long as the path to SSI.php is changed to your own path and you change the boards you wish to use. This is just an example file. More functionality can be done and more information can be included. The best way to get information would be to add a little script to output what information is possible to get from each board. So we find in the script:

 // Moderators contain to much junk. We can fix this
if(!empty($board_info['moderators']))
foreach($board_info['moderators'] as $temp_mod)
$context['boards'][$board]['moderators'][] = $temp_mod['name'];

and after it add:

 echo '<pre>';
print_r($board_info);
echo '</pre>';

This now is outputting a whole bunch of information that is possible to use. Following the correct array you can correctly include information into your site that even this script does not yet handle.