Bridging Etomite and SMF
The snippet
You'll also need another PHP file to actually display the postings from SMF under the article inside Etomite.
First, create a new snippet in Etomite named Include. Copy and paste the following code in to the new snippet.
-
if ( !isset($phpfile) || $phpfile == "" ) return "No file specified."; //check if there's a file given.
-
-
-
include $phpfile; //include
-
-
return $ob_contents;//return it to etomite.
If you're interested, what this snippet does is turn on output buffering and captures the output from the include. Otherwise Etomite would throw an error.
The PHP File
You are also going to need to create a new php file. Personally I stored mine in the assets/scripts/ folder because that made the most sense to me, but you can store it where ever you want.
For the sake of this tutorial I'm going to assume the file is saved as assets/scripts/articlethreadcache.php.
-
<?php
-
/* paf_articlethreadcache.php
-
Returns the article thread cache, rebuilding it
-
if needed. */
-
-
/* Path to cache */
-
$cachePath = '/full/path/to/a/cache/folder/';
-
{
-
}
-
-
{
-
rebuild_cache($article_id);
-
}
-
-
{
-
// Rebuild cache if more than 10 minutes old
-
{
-
rebuild_cache($article_id);
-
}
-
}
-
-
-
-
function rebuild_cache($article_id)
-
{
-
global $cachePath;
-
// Open the database record
-
{
-
return false;
-
}
-
-
-
$topic_id = $row['topic_id'];
-
-
$output = '<div class="article_discussion">';
-
$output .= '<h2 class="article_discussion_header">Discuss this article</h2>';
-
$output .= '<p class="article_discussion_subhead">Visit our forums to <a href="http://forums.photoartsforum.com/index.php?topic='.$topic_id.'.0">discuss this article</a>.</p>';
-
$output .= '</div>';
-
$output .= "\n\n";
-
-
$rs = mysql_query("SELECT posterTime, ID_TOPIC, ID_MSG, subject, posterName, body FROM smf_messages WHERE ID_TOPIC=".$topic_id." ORDER BY posterTime DESC LIMIT 5");
-
-
// Get the first posting from this thread
-
$first_id = $row_first[0];
-
-
{
-
$output .= '<p class="recent_discussions_header">Recent Discussions</p>';
-
}
-
-
{
-
if ($row['ID_MSG']!=$first_id)
-
{
-
$body_text = shorten_string(strip_bbc($row['body']), 20);
-
-
$output .= '<div class="article_discussion_single">';
-
$output .= '<a class="article_forum_link" href="http://www.example.com/index.php?topic='.$topic_id.'.msg'.$row['ID_MSG'].'#msg'.$row['ID_MSG'].'">'.$row['subject'].'</a><br>';
-
$output .= '<div class="article_forum_blurb">'.$body_text.'</div>';
-
$output .= '</div>';
-
$output .= "\n\n";
-
}
-
}
-
-
// Open file for output
-
-
}
-
-
function strip_bbc($string)
-
{
-
$retval = $string; // Just in case
-
return $retval;
-
}
-
-
function shorten_string($string, $wordsreturned)
-
/* Returns the first $wordsreturned out of $string. If string
-
contains more words than $wordsreturned, the entire string
-
is returned.
-
*/
-
{
-
$retval = $string; // Just in case of a problem
-
/* Already short enough, return the whole thing
-
*/
-
{
-
$retval = $string;
-
}
-
else
-
/* Need to chop of some words
-
*/
-
{
-
}
-
return $retval;
-
}
-
-
?>
On line 7 you're going to need to enter a path that is writeable by the web server, and it needs to be a complete path starting from the server root not from your web root.
On lines 38 & 56 you are going to need to enter the server, username, and password to connect to your MySQL databases.
I set my installation to rebuild the cache files if it's more than 10 minutes old. If you want to shorten or lengthen that time you can change it on line 22.
And most of the html that's output is wrapped in CSS classes that can be easily changed by using your external CSS files.
And the template file
Now you need to insert one line in to the template you're using for your articles. For my setup I have a separate template for articles that are being linked to the forums so that if I can use that template.
Here's the line:
-
[!Include?article_id=[*id]&phpfile=assets/scripts/articlethreadcache.php!]
Notice that we are using the variable [*id*] in the template so that it'll work for any page. You could also enter this string on individual posts if you don't want to have it on every template.
So, what's it look like?
I have a very simple article on DPI and web design that links back to the forum where you can see what it looks like article side. Notice that the most recent, in this case 2, follow up posts from the forum are displayed under the article with links back to the forum.
For the forum side, look at the posting that's tied to the article.
Help!!
I've tried to explain this as simply as possible, but it was a very convoluted process to get working so I imagine you may have some questions. Feel free to post away in the comments below and I'll see if I can help you along.
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.