Using phpBB as your MovableType comment engine in 23847392 easy steps (geekery, meta)
It's not difficult (especially if you already have phpBB set up and working), but it's time-consuming.
2008/03/31 Note that I'm not actively developing this anymore. Notably I have no plans of upgrading it to work with phpBB 3.
2005/02/22 Added a 'url' column to the table; now recent discussion can work a bit better for people who use fancy-pants archive URLs (at least for new installations; if anyone needs help populating their table for existing installations just let me know).
2004/07/02 Added some more anti-spam measures.
2004/11/20 Some more wording changes to hopefully clear up a few parts of the installation.
But first, you might ask why this might be a good idea. After all, doesn't MovableType already have a built-in comment engine, and doesn't MT-Blacklist already solve the spam problem? To an extent (though it's not yet a silver bullet), but there are still other reasons to move to phpBB:
- Optional user registration — wouldn't it be nice if people could ensure that other people can't post as them?
- Discussions involve more than just the weblog author posting and random people responding to the author. There is an interchange between multiple users. So, it'd be nice if users could track replies to their posts too.
- Better moderation interface — if you've ever tried to delete multiple comments from multiple weblog entries, you know how frustrating it is in MT to have to wait for one thread's comments to finish deleting before you can start deleting on another thread, because of the stupid Javascript-based "dialog box" for comment moderation. phpBB's UI is actually designed to act like a webpage, not a Windows app.
- A homogenous comment engine landscape makes it easy for spammers to come up with single catch-all spam tactics. A variety of comment engines makes their life more difficult.
- Better comment search capabilities.
- Private entries
- And the main reason I wanted to do this: I already had a perfectly-good forum which took a lot of effort to install and so on, which nobody uses. I didn't want to see the effort go to waste. :D
Before you begin
In order for the best results, you need a few basic things:- Basic programming skills — not necessarily in PHP (this was my first original piece of PHP code, actually), but just in basic programming concepts in general.
- An understanding of how directory layouts are put together — basically, understanding the difference between absolute and relative paths, and how this relates to a website compared to the actual file system it's based on.
- Knowledge of how to apply examples to your own ideas — like MovableType's default templates, this stuff is only intended as a starting point. With this code you can make the level of integration between MovableType and phpBB as complex or as simple as you want.
- Access to a raw SQL command line (to set up the table), since writing an installer for this would be much more complex than just giving the one SQL command which is needed...
Of course, the instructions are always being refined and worked on, so if there's something which is unclear or confusing (or if you have any ideas on how to improve any part of this), feel free to post a comment!
So, let's go on to the actual installation.
Have both MovableType and phpBB installed and working.
(Duh.)Well, not quite duh. Both things need to be running from the same server, and need to be on the same hostname/domain/etc. So you can't have, for example, weblog.trikuare.cx and forum.trikuare.cx and expect it to work as described here - it has to be trikuare.cx/weblog/ and trikuare.cx/forum/. It's possible to get it working across sites (as long as they're still hosted on the same server and account and so on, or even if they're on different servers in some cases), but tricky and outside the scope of this writeup.
Have MT emit all pages as PHP instead of raw HTML.
This is pretty simple; just go into "weblog config," then select "configuration," then scroll down a bunch and change the archive extension from 'html' to 'php'. Then go to "templates," then edit all of your index templates to have them emit the file with a .php extension instead of .html. (Yes, that includes the main index.) Also, be sure to delete any old index.html so it doesn't override the index.php.
Rebuild, and fix all of your broken permalinks.
This is the time-consuming bit. First, you have to go through your weblog entries and then make sure that any internal linking you have going on points to the current .php version, rather than current .html. Then you have to worry about external links into your weblog, search engines, and so on. So, there's an easier way to handle this, which is less elegant but keeps things from breaking. Assuming that you have shell access on your webhost, log in, go into your archive directory, and then run this simple command:
- phpBB Fetch All 2.0.4 or later
- Insert Post
- My own integration script (install it into the forum's top-level directory)
Note that you can call the table and columns whatever you want (in case the default names step on your SQL implementation), but make sure to change the respective settings at the top of integrate.inc if you do.
Create a place for threads to be put.
Create a new forum, which is set so that only administrators can post to it. (You'll definitely want a separate forum for this stuff; one look at the fluffyblog forum area will show you why.)Optionally, create a posting bot user, which will be what creates all of the threads (it's nice to keep it separate from your own account for a number of reasons). It doesn't actually have to have administrative access, since the thread creation stuff bypasses it nicely; this weblog's forumbot doesn't even have logins enabled (accomplished by setting "user is active" to "no" from the user administration page).
Prepare your weblog for accessing phpBB.
In order to make use of phpBB functionality, your weblog's pages need to know how to access it. Like in most programming languages, we do this simply by "including" a module, similar to a .h file in C/C++.At the very top of each page template (even before the <DOCTYPE> tag if you have it) you need to put code which looks something like this:
<?php
$phpbb_root_path = "[relative path to phpBB]";
include($phpbb_root_path . 'integrate.inc');
include($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
include($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);
include($phpbb_root_path . 'mods/phpbb_fetch_all/users.' . $phpEx);
$display_userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($display_userdata);
?>
That bit which says [relative path to phpBB] needs to be replaced with the actual relative path to phpBB. The relative path is the way you get from one place to another without any known fixed reference point. The way you determine the relative path is fairly simple:
- Start out totally empty
- For each directory you have to go up, add
../ - For each directory you have to go down, add its name ending with a /
../../../phpBB2/, so the full line of code would be
Another common configuration is where you have the weblog as the top-level directory for your site and the forum directly beneath it (for example, http://foo.bar/ for the weblog and http://foo.bar/forum/ for phpBB). In this case, the relative path from the top-level directory would just be "forum/". Note that a relative path never begins with a /.
Get MT to create phpBB threads as needed.
Create a new template module (from the "templates" screen in MT). Call it GetForum, and give it this content:<$MTInclude module="GetForum"$>, which expands to all of the ugly crap needed to get the post's thread ID.Note that you can change the format of the message as much as you like, but the content will be set in stone (barring manual editing later) once the thread is created. There's no easy way to rebuild the first post on each thread right now (and any way which would come later would still be horrible and kludgy), so be sure you're happy with the format now.
Also note that this format (with <a href> instead of that [url] crap) might not work if you haven't configured phpBB to allow the A tag in posts. [url] sucks for a number of reasons, not the least of which being that it forces target="_blank" which, especially in this case, makes the integration between the weblog and the forum very annoying.
Also, that code isn't quite finished yet; notice the FORUM_ID, BOT_ID and USER_ID? The first one is the ID of the forum which posts go into, the second is user ID of the posting bot, and the last one is your user ID (so that you'll be emailed notifications to comment posts). (To get the user ID, look at their entry on the member list. For example, my ID is 2, which you can see by looking at the URL.)
Finally, that code above sets the thread creation time to the time when the PHP script runs, rather than the time of the weblog entry. It's simpler than trying to account for timezone issues and clock skew and so on, and it's not as if the thread creation time will be visible on the weblog entry anyway, so there's no point in really worrying about it. (I did for a while and all it caused was headaches.)
Change your comment display and form.
This is where the little switch gets thrown that replaces your comment engine. The rest of this document is just to give better integration with the rest of MT and the comments; after performing this step and rebuilding the weblog, you'll (hopefully) have a working MT-phpBB setup!So, the first thing you want to do is back up your templates, because we're about to change them a whole bunch.
Done with that? Good!
This comment engine is incompatible with the popup-based comment viewing thing. But that's okay, because the popup-based comment viewing thing is an absolutely atrocious user interface for quite a few reasons which I won't get into. But, this means that you need all comments to happen on the individual entry archive listings, which means that permalinks must point to it. So, change your weblog configuration to have "individual entry archive" as the default permalink destination.
Go to the individual archive template and replace your entire comment listing and posting form with this ugly garbage, adjusted for your own CSS: (this isn't exactly what I do — I put a lot of the functionality into a PHP include file — but it's a good starting point)
<div class="comments-head"><a name="comments"></a>Comments</div>
<MTEntryIfAllowComments>
<MTComments>
<!-- insert whatever you normally do to display a MovableType comment here -->
</MTComments>
<?
$thread_id = <$MTInclude module="GetForum"$>;
$CFG['posts_limit'] = 0; // Unless you really feel like implementing pagination
$CFG['posts_order'] = 'p.post_time ASC'; // to make the comments go in the right oder
// put other phpbb_fetch_all configuration stuff here as appropriate
// (see fetch_all's documentation for details)
$posts = phpbb_fetch_thread($thread_id);
for ($i = 1; $i < count($posts); $i++)
{
echo "
<div class=\"comments-body\">
<div class=\"posted\">
(<a name=\"#fp$i\" href=\"#fp$i\">$i</a>) <span class=\"subject\">";
echo ($posts[$i]['post_subject']);
echo "</span> by <span class=\"author\">";
if ($posts[$i]['user_id'] != -1)
echo "<a href=\"" . $phpbb_root_path . "profile.php?mode=viewprofile&u=" . $posts[$i]['user_id'] . "\">" . $posts[$i]['username'] . "</a>";
else
echo $posts[$i]['post_username'] . " (unregistered)";
echo "</span> on <span class=\"posttime\">" . $posts[$i]['date'] .
" " . $posts[$i]['time'] . "</span></div>" .
$posts[$i]['post_text'];
echo "</div>";
}
echo "<a href=\"".$phpbb_root_path."posting.php?mode=reply&t=".
$thread_id."\">Post a comment</a> (<a href=\"".$phpbb_root_path.
"viewtopic.php?t=".$thread_id."\">view forum</a>)<br>
(comments powered by <a href=\"http://beesbuzz.biz/blog/e/000425.php\">phpBB_integrate</a>)";
?>
</div>
</MTEntryIfAllowComments>
</div>
The summary is that basically you're replacing everything inside <MTEntryIfCommentsOpen>...</MTEntryIfCommentsOpen> (including the tags) with that php function, which prints out the php thread and provides a link for posting a comment. You still want to keep the old comment display (you don't want to throw out all of those old comments, right?) but don't want to keep the old comment form.
You may notice that there's no new comment form, and just a link to the reply page. It's possible to get a full comment form in there, but it's a bit of work and it makes registered users a LOT harder to deal with. It also makes it much easier for spammers to spam. However, if you really want it, HexAngel has written up how to add a comment form to the page.
So, as soon as you rebuild the site, you should be using phpBB for all new comments. Post a test comment, and remove or otherwise disable mt-comments.cgi (otherwise scripts can still post to your entries).
The rest of this is just icing.
Get the correct comment counts.
In your weblog you probably have a few places where you have something like$commentcount = <$MTEntryCommentCount$>;
if ($thread_id = GetThread("mt_<$MTEntryID$>")) {
$thread = phpbb_fetch_topics($thread_id);
$commentcount += ($thread?$thread[0]['topic_replies']:0);
}
printf ("<a href=\"<$MTEntryPermalink$>?comments=$commentcount\">$commentcount Comment" . ($commentcount != 1?'s':'') . "</a>");
?>
Recent discussion list
If you have a box for recent discussions, you'll have to adapt it for the new comment engine. It won't include discussions in the old comment engine, but that shouldn't matter for long anyway. Here's the PHP in my discussion box (more or less); adapt it for your own needs:<?
$sql = "SELECT t.topic_title, i.source, t.topic_replies, t.topic_id, i.url FROM " .
TOPICS_TABLE . " as t, " .
POSTS_TABLE . " as p, " .
INTEGRATE_TABLE . " as i " .
"WHERE t.forum_id = 11 AND t.topic_last_post_id = p.post_id
AND t.topic_replies > 0 AND t.topic_id = i.topic
ORDER BY t.topic_type DESC, p.post_time DESC LIMIT $lastn";
$result = $db->sql_query($sql);
while (($row = $db->sql_fetchrow($result)))
{
$numcomments = $row['topic_replies'];
$link = $row['url']?$row['url']:sprintf("<$MTArchiveURL$>/%06d.php?comments=$numcomments",
substr($row['source'], 3));
$title = $row['topic_title'];
if (strlen($title) > 30)
$title = substr($title, 0, 28) . "…";
echo "<li><a href=\"$link\">" .
$title . "</a> (" .
$numcomments .
")</li>\n";
}
?>
Also note that this will not work if you use permalink URLs which are different than the MovableType default of e.g. 000123.php. In the future I may fix this behavior if so requested.
Rebuild your site.
if all went well, you should be done.If not, well, feel free to post a comment here, because my installation actually works. ;)
Care and Feeding
From now on, pretty much all maintenance tasks happen from the phpBB end of things. You can still select whether comments are on or off from the MovableType end of things (with "open" or "none"), but closing comments happens from the phpBB side (by locking the thread). If you delete an entire thread in phpBB it'll be recreated the next time the entry is viewed, so if you want to kill comments and keep them gone you should probably turn off comments for the entry first.If you missed this step above, you should definitely remove or disable mt-comments.cgi; otherwise spammers will still be able to spam your entries, and what's worse is the spam will appear above all legitimate comments.
If you want to back up your phpBB database (for migration to another server or for safety or whatever), it's better to just use a raw SQL dump, because the phpBB backup/restore process doesn't always restore all of the necessary data. If you do use the built-in database backup mechanism, make sure to put "integrate" (or whatever you named your table) into the custom table list. (Otherwise none of your threads will be associated to your weblog entries anymore, and all-new empty threads will be created.)
If you change your archive permalinks, you'll probably want the 'url' table column to get updated. If so, just uncomment the line in GetMessage (in integrate.inc) which comes right before // Thread already exists, yay!. After a while you'll probably want to re-comment it, though.
Then the next time the page is viewed, the permalink column will be updated, so things like the recent discussion list and so on will use the new URL. (This won't update the permalink in the forum bot's post, however. Also it will incur a bit more of a hit on your database, though the actual performance impact is probably minimal.)
Some extra hints/tips
Since the whole point for me to move to phpBB was to reduce spam, you might want to take some simple anti-spammer measures for the phpBB side of things:- Write a robots.txt site for your file which looks something like this:
This will prevent spammers from finding your forum (via Google or other search engines) as a place for easy registrations (since even incactive registrations can still be used to spam links onto your memberlist).User-agent: * Disallow: /forum/posting.php Disallow: /forum/profile.php Disallow: /forum/memberlist.php
- For even tighter protection against spam registrations, try a couple of simple mods (which prevent the use of the member list as a link farm).
- Also, there are phpBB spambots now, so stop those guys dead too.
- Don't just use my boilerplate code! Learn how to interface with phpbb_fetch_all in order to get more niftier stuff going. Like, adding in avatar icons and session stuff (like with my login/logout/register links here), polls, or whatever! This code is just a starting point, just as the default MovableType templates aren't intended to be the final look and feel of your weblog. You've probably spent a lot of time customizing your MT display, so why stick to the basics for phpBB-MT integration?
- Put commonly-used code into a PHP include file. It makes maintenance a lot easier, and also lets mod_php do some bytecode caching and so on. (I won't go into detail about this step, since hopefully by the time you get to this point you'll have enough basic skills with PHP to simply look at that file and figure out what needs to be done.)
Comments
Archived discussions:
phpBB_integrate support
archived phpBB_MT posts, round 2
Even more archived phpBB-integrate support thread posts
Theological poop! More phpBB+MT support!
The only thing I want to do differently is make it selective, for certain posts, and others just use comments. Hm, but if I could only do one, I'd use phpBB.
Thanks, gonna try this tonight (if real life permits).
<MTIfAllowComments>
<!-- Insert MT comment display here -->
<MTIfCommentsOpen>
<!-- insert MT comment form here -->
<MTElse>
<!-- insert phpBB comment display and forum link here -->
</MTElse>
</MTIfCommentsOpen>
</MTIfAllowComments>
That way, if you have comments set to 'closed' it will use phpBB, 'open' it will use MT, and 'none' it'll use neither.
There's a quick fix solution for folks on Apache servers with MOD_REWRITE installed. All they have to do is add a redirection rule to the .htaccess file.
Something like this, I imagine, NOT TESTED!!!
RewriteEngine on
RewriteBase /MyBuggyBlog
RewriteRule (.+\.)html $1php [R]
RewriteRule archives/(.+\.)html archives/$1php [R]
Which basically gets executed as
Whenever some user looks for a file in the MyBuggyBlog directory OR
the archives directory in MyBuggyBlog
Check and see if the file they're looking for ends with ".html"
If it does, give them the file of the same name ending with ".php"
Oh yeah, [R], so update the URL in the user's browser address bar
Of course, you can leave the [R] out and your visitors will think they're looking at an html page.
MOD_REWRITE is your friend.
Of course, if you've got a ton of legit HTML in your blog directories, you're going to have that issue to deal with now.
cheers,
p.
your display code assumes comments listed in desending order, from oldest to newest. I've got mine set for ascending, newest to oldest, which the display code above displays incorrectly (misses the most recent post, then lists the Bot post last.)
I hard-coded a solution into your display code as follows
for ($i = 0, $di=1; $i < count($posts)-1; $i++, $di++)
{
echo "
<div class=\"comments-body\">
<div class=\"posted\">
(<a name=\"#fp$di\" href=\"#fp$di\">$di</a>) <span class=\"subject\">";
It would be better to create a decision statement to determine the current sort order and preset loop parameters appropriately, but I was too lazy to look up the necessary variable or MT Tag required.
Cheers,
p.
Not to be rude or anything, but seriously. This isn't expensive supported software here, this is a simple phpBB plugin I wrote for the purpose of integrating external content management systems with phpBB, and a series of instructions detailing how I specifically went about integrating MT with phpBB for my weblog. The entire programming reference is available to you, just as it is with MT templates. If you want to write your own functionality, you're free to do it.
It's not up to me to support every possible permutation of layout, template, and MT configuration that other people may be interested in. I'm just giving people a good starting point by showing how I happened to go about doing it.
I don't want to create a thread on my message board everytime I create a new entry in my blog. But if people want to comment on my entry I want them to be able to click "Comment on entry" and THEN create the thread.
Otherwise it's just going to be lots of empty threads, because people don't comment on all my entries.
Is this possible?!
Thanks so much in advance.
That's basically how Fluffy's code works. The only difference is threads are also created when someone clicks "View Forum" as well.
However, you can still use my code to do the delayed-creation behavior which you want. For example, you can have it so that at the very top of the page, before any HTML is emitted, you have something like:
<?
if (($mode = _GET["redir"])) {
$thread = GetThread("mt_<$MTEntryID$>");
if (! $thread)
$thread = GetMessage(...);
if ($mode == "post")
prog = "reply.".$phpex;
else
prog = "viewtopic.".$phpex;
$url = $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF'])
. "/" .$phpbb_root_path . $prog . "?t=" . $thread;
header("Location: " . $url);
exit;
}
?>
then change your comment display to use GetThread() instead of GetMessage(), and have the links point to "?redir=view" or "?redir=post" instead.
It just takes a little imagination.
I'd rather keep the instructions as simple as possible. As they are, they're already too complex for many people to follow. Advanced functionality could be implemented by advanced users.
MT comments migrated to phpBB would be useful in terms of the stuff you could then do with them, but if you want to do that you'd have to do it yourself.
The way I'd go about doing it is something like making a special index template which just poots out code with something like (note: this is rather incomplete)
<MTEntries>
<? $thread = <MTInclude module="GetForum">; ?>
<MTComments>
<? /* whatever the syntax is for posting a reply to a thread, using "<MTCommentAuthor>" as the username, and "<MTCommentBody escape="qq">" for the post text*/ ?>
</MTComments>
</MTEntries>
and then build this page and view it *exactly* once (delete it afterwards).
You'll also then want to disable the MT comment display so that the comments aren't duplicated.
Also, dealing with comment post times is a pain as well since you'll have to convert dates between a few different formats (MT doesn't provide a reasonable date format which PHP can understand off the bat) and you'll need to make sure that the initial post time of the phpBB thread comes before the individual comment's times, or else the sort order will be messed up since for some reason, phpBB and phpbb_fetch_all both sort the comment listing by date rather than just using the inherent strict ordering of post ID, which can also lead to some pretty wacky behavior since it's possible for a reply to display before the comment it's replying to, or even before the head of the thread, though at least phpBB doesn't treat the thread head as a special post (unlike some forum software like UBB).
So, short answer: Yes, it's possible, but I don't recommend it.
Anyway, there are three kinds of posts for two classes -- 101 Journals, 101 Discussion, 101 Announcements and 102 Journals, 102 Discussion and 102 Announcements. I'd like these to go into separate forums for student commenting.
Is is possible to customize the mod so it crossposts from certain categories?
Thanks,
Professor K
professor at kosub dot org
http://english.kosub.org
As far as doing what you want, it's a little difficult, but not too bad if you know slightly-less-basic PHP than what you need to know to install this stuff to begin with. The basic idea is on the pages which use the GetForum module (so in your individual archive template, or in the forumfuncs.inc file or whatever) you'd have this somewhere before the actual <MTInclude module="GetForum">:
<?
$CategoryMap = array(
'101 Journals' => 5,
'101 Discussion' => 6,
'101 Announcements' => 7
);
?>
where for each array entry, the first bit (before the =>) is the MT category name, and the second bit is the corresponding forum ID. Then you'd change the FORUM_ID in your GetForum module to be
instead of the single forum. Though this won't do any error checking of its own, so phpBB will probably complain loudly if you misspell the category name.
Since phpBB uses globally-unique topic and post IDs and all of the other code just works with those (and doesn't care about the forum), no other changes are necessary (e.g. to the thread display code or whatever).
I hope this helps.
Canīt i just use .html files parsed as php by the apache server avoiding missing files ?
.htacess
<
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
>
I already have two php powerful scripts running that were only .php files...
phpBB2 got released; do you think that your system is compatible with it?
I also noticed that some people expressed interest for compatibility with dynamic publishing; do you have the intention to check into it?
It's really a GREAT system, it should replace MT default comment system, in my opinion. Keep up the good work
Is there a way to set it up so that phpbb allows unregistered users to post, but they have to type in the graphical code (with the random numbers and letters)?
The person who has been occasionally posting spam has been posting manually, and coming specifically to this entry for some reason (it seems to be on some sort of manual spam list that this idiot from Poland thinks is a suitable target). Adding a CAPTCHA wouldn't do anything to stop them. I don't want to make comment posting registration-only, but I'm getting pretty close to that point... Meh.
It's only one person and every time they do it I add their IP address to a ban list which keeps them away for another few days. Anyway, I just added their ISP's entire IP block to the blacklist, so that should stop this particular spammer once and for all. I've also done a few things to prevent other spammers from even finding my weblog as a potential spam target (like redirecting them elsewhere if they show up from certain search phrases and so on).
I am trying to convert your script to work with Wordpress. I have suceeded in bypassing all the function errors (wordpress and phpbb share function names) and have the script working for the most part. I have only change the script within the module to pull the information out of Wordpress, but I am getting a preg() empty error which corresponds to line 118 and 98 in the functions_post.php file of phpbb. I realize this may be out of your realm, but I hope you could point me in the right direction.
I have the system pulling the values from the SQL database for Wordpress and then putting them into the GetMessage module (Im using a plugin instead).
$post = $wp_query->post;
$id = $post->ID;
$p_title = single_post_title();
$link = get_permalink();
$content = $post->post_content;
echo "$content $link $p_title $id";//only to show the values.
$thread_id = GetMessage("test_" . "$id", 21, 3, "$p_title", "$content", 0, 3, "$link");
It correctly puts the information into the integrate table and begins making entries in the phpbb_post tables, but it doesnt put either the subject or the message.
Within your script, you used MT(tag) encode="qq". Why did you? (This may be related to my problem.)
Thanks for any help you can provide.
WDuluoz
Anyway, the reason for
encode_php="qq"is just to tell MT that the message is going to be embedded into a double-quoted string. MT basically acts as an HTML preprocessor, and so when you insert a tag like<MTEntryText>it just enters the text verbatim; theencode_php="qq"turns all "s into \"s. So if your entry looks like:then the resulting code would be something like
Since you already have the entry text in a PHP variable there is no need to do any additional encoding. There's also no need to put it into quotes; just do e.g.
I don't think that has anything to do with the problem you're having, though (
"$foo"and$fooare functionally equivalent, though the first one's a little bit slower and takes more memory to execute).Also, GetMessage has to be a module in MovableType because MT just emits static pages; it's not a real function that's getting called, and all the variables etc. need to be pre-filled when the page is emitted. It's more or less irrelevant to the discussion except that maybe you're doing something freaky in your WP "plugin" - all you need to do is call the GetMessage function in integrate.inc.
Another thing: you can speed things up a lot by using GetThread() instead of GetMessage(), and only calling GetMessage() if GetThread() fails. e.g. something like (assuming your WP code is already correct to begin with):
$post = $wp_query->post;
$id = "test_" . $post->ID;
if (!($thread_id = GetThread($id))) {
$thread_id = GetMessage($id, 21, 3, single_post_title(),
$post->post_content, 0, 3, get_permalink();
}
Thanks
Reading the documentation in integrate.inc and phpbb_fetch_all should be useful.
All the archived posts in MT show the correct conversation from phpbb. However, as soon as someone posts in one of those threads the former conversation is lost and a new topic is created in phpbb. And of course, that topic now only has one post in it.
Any idea how I might be able to fix that?
By the way, if you're doing multiple weblogs from the same MT installation, it's not necessary to do anything special — MT already maintains global entry ID uniqueness. (I didn't know that when I wrote the message, since at the time I'd only ever used MT with a single weblog at once.)
BTW, my site is at www.challies.com if you want to check it out and see if you notice anything out-of-whack.
I'm doing some changes to the site and am a little worried that if I do a rebuild I'll somehow disconnect all those old topics from their forum entries (though I don't think that will happen).
A site rebuild won't affect anything on the phpBB side. The link is based only on the MT entry ID, which never changes.
It seems to have resolved itself. That's odd, but I'm not going to complain. I had to clean up a few older entries, but other than that it's good to go.
Hey, I'd love to implement pagination, especially for those threads where there are a couple hundred comments. Could you give me some tips (remembering I'm not so good with this PHP stuff) about how I might do that?
for ($i = 1 + $_GET["start"]; $i < $_GET["start"] + 20 && $i < count($posts); $i++), and then after the main thread loop add things to the bottom of the page to go to ?start=0, ?start=10, etc. up to the size of the thread, with code like:for ($i = 1; $i < count($posts); $i += 10) {
echo '<a href="?start=' . $i . '">[' . ($page++) . ']</a> ';
}
Also, phpbb_fetch_all already has some functions built-in to deal with pagination but I've never gotten them to work very well (though I haven't tried much, since I"m not a fan of pagination, and instead prefer to just clean up threads or divert them over to the forum proper).
generate_paginationthat'll do a lot of the work of generating a "1 2 3 ... 343 344 345 346 347 ... 567 568" style pagination thingamabob.Here's a bit where I used it in another custom module:
$template->assign_vars(array(
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $per_page )
+ 1 ), ceil( $total_logs / $per_page )),
));
which would put said "pagination thingamabob" in
{PAGINATION}and a page number in{PAGE_NUMBER}Has anyone tried this system with MT 3.2? It looks like the new version will be ready any day now. I presume it won't hurt anything...
3.2 has been released. Who wants to try it first? It looks like a major update...
Of course, I won't know if that's successful until it's done and I make a new entry, since right now it's just static PHP pages which happened to be generated by MT.
It's worth mentioning that most of 3.2's new features are still just stuff that this integration stuff has provided for a couple years now.
I'll look forward to hearing about your success. The only feature I really care about is Trackback moderation. The rest is pretty disappointing IMO - especially the fact that they still have no media manager to list the graphics I've uploaded...
Aside from having to remove their index.html. Someday I need to get around to moving my weblog content to a directory other than the MT installation directory. What a major PITA, though...
And everything still works, does it? I was a little concerned about how they'd handle the old-style archive links (ie postnumber.php rather than month/date/year.php
So is there any reason not to go ahead and upgrade ASAP?
How do I mimic the "Reply" you have on your individual entry archive above each post?
And...
How do I have phpbb return to the individual entry archive instead of defaulting into the forum thread after someone posts?
2. Someday I'll get around to releasing my mod for that, but it requires a pretty invasive set of changes to posting.php. But it's what the 'url' column in phpbb_integrate is for.
I currently use this setup with three different blogs within one install of Movabletype. I'm wondering if there is a way of listing the last X threads that have been commented on and have it pull not only from one forum but from any of the three that use this system. So rather than having 3 lists of updated comments I'd have only one. Is that possible? If so, can you let me know how?
$link = sprintf("http://www.mysite.com/blog1/archives/%06d.php#comments", substr($row['source'], 3));
So should I go ahead and move to the latest verison of integrate.inc, or might that mess things up? If I move to the latest version of integrate.inc and use the new RecentDiscussion() will everything still work?
It'll take a while (meaning, until the next search engine crawl) for all of the updated URL values to propagate into the table, but you can force the issue by just running all of your MT pages directly with something like:
ls *.php | xargs -n 1 php
It's pretty moot, though, since typically if someone posts a comment to an entry it'll be because they've viewed the page and thus have updated the URL column. (Convenient.)
This is also happening on the individual pages:
<!-- query SELECT * FROM phpbb_integrate WHERE source = 'mt_1111' LIMIT 1 failed -->Could not obtain userdata from user table on /home/gadget/public_html/phpbb/integrate.inc:131, SELECT * FROM phpbb_users WHERE user_id = 3
I've checked my config.php for phpBB which is correct, and I've checked the user 3 and he is active. This error happened when I switched from one host to another, nothing changed in the code. I'm about to tear my hair out - your help figuring this out is greatly appreciated!
I did a full mysql dump/restore of the entire phpbb database when I moved, and the integrate table is there. I just double-checked and the query works from phpMyAdmin, but not when called from CommentsLink.
That's the baffling part - the forum is working fine! Here is the link.
I really, really appreciate the help. This link might also be useful. Thanks!
On purpose - for SEO.
Ok, here is where I am at. Finally got it to connect to the database by adding the following to integrate.inc:
include_once($phpbb_root_path . 'common.'.$phpEx);
include_once($phpbb_root_path . 'mods/netclectic/includes/functions_insert_post.'.$phpEx);
//added by mike
global $db;
#$db = $db->db_connect_id;
mysql_select_db("gadget_phpbb", $db->db_connect_id);
//end add
/***** Configuration *****/
Apparently my ad server software uses the same connection name, so it was connecting to the wrong database.
Now I have a seperate issue where threads are being created multiple times. Here is the link.
I have no idea why this is happening. Any chance I could hire you for an hour to help me get this sorted out? I'm sure if you could look at it you'd be able to sort it out far more quickly than I.
Also, look at the phpbb_integrate table to see if all those threads are being registered to the same source key.
So...I'm transitioning back to MT's commenting (blech) but would like to preserve the 16 months worth of comments in phpbb. Is there a way I can integrate those into my MT individual templates without much overhead?
Porting the comments back to MT would be pretty difficult, but one stopgap thing you could do is just statically emit all of your comment threads into include files by making DisplayThread() see if, say, thread_1123.inc exists, and if so, include()ing it, and if not, poot all the comments into that. (For extra cool points you could also have it delete that .inc file if a comment gets posted to the thread so the comments just get pseudo-statically generated, MT-style, though that would probably involve hacking on phpBB itself.)
Maybe I'll write a caching layer for phpbb_integrate to help sites scale anyway.
link to the phpnews: http://newsphp.sourceforge.net/
Another way is to separate the comment stuff out into an internal stub which is just @included via HTTP, though then you lose the ability to use the phpBB login information from the calling app. Or you can do the @include AJAX-style but then you lose the ability to get comments indexed by Google and your site read by people running non-AJAX-compatible browsers.
These issues are a big part of why I don't like PHP as a language. There's no easy way to just namespace stuff or sequester it away. An app needs to be written specifically to be embeddable as a library, and basically no PHP apps are embeddable.
The reason phpBB and MT get along so well is that they don't know anything about each other; MT just emits HTML as far as it cares, and then that HTML happens to include the php necessary to embed phpBB. So they're completely separate.
An okay long-term solution is to just make a version of the phpBB libraries which are explicitly embeddable, and which basically just share a db schema with phpBB. However that's a huge amount of work, and would be extremely fragile. So the best long-term solution is to just make an embeddable commenting library and then build a forum around THAT. This is something I've thought a lot about on and off but of course I don't really have the time/energy to do that, especially since phpBB still suits my needs more or less these days.
I've loved your implementation of this integration and have been quite a fan. But, now that movable type's commenting system has developed, I'm tempted to go back for several reasons.
The MT-Blacklist is much more efficient at blocking comment spam than it used to be.
There are further solutions for fighting spam such as akismet that can be plugged into the commenting system.
With the default form system, it's pretty easy to let users interact with your blog compared to making them sign in to phpBB. I also enjoy the ease of use it provides.
I'm aware that all three of these and others are pretty much possible on phpBB as well, but I also see an unsure future for phpBB as the next version, 3.0, has taken years to develop and I'm not how modern the code will be (meaning standards compliant, accessible, usable, etc). I do, however, really enjoy the way phpBB easily handles the comments and all the expandability that this system provides for the comments.
You're a god for writing this and releasing it to the public, but I'm curious to know your opinion concerning someone in my position (of which I'm sure there are probably others). Thanks again for all your hard work!
phpBB 3.0 does seem to have some major problems in that as hard as it was to integrate 2.x with other sites, 3.0 has gone even MORE overcomplex and less embeddable. I haven't evaluated the code directly though; it's possible that it might be cleaner and more modular (I hope it is, anyway, since 2.x's code is terrible) and hopefully some of the long-standing problems with it (a glut of copy-paste code instead of modular functions, way too many global variables with bizarre side-effects, etc.) have been addressed.
Also, note that with decent anti-spam mods, you can safely allow anon comments on phpBB. I've been allowing anon posting (of replies, rather than new threads) on my forum for a few months now and haven't had a lot of trouble with spam as a result.
I mean, far be it from me to defend phpBB or anything - frankly it sucks a LOT and the only reason I even went with it was that it sucked less than the other forums available at the time - but I don't think MT's comment engine is a step in the right direction. In particular, it ties comments specifically to entries, and MT's own entry model leaves a lot to be desired as well.
A much better system would be an embeddable comment engine which is designed specifically to work within other things as well as on its own, and which allows pluggable identity modules (TypeKey and OpenID themselves are good starts but they still need better admin-level control, no to mention the lack of real uptake so far).
The big thing for me is that with my phpBB hacks I can do a lot more flexibility regarding actual forum use, e.g. friends-only entries and reply tracking and so on. I see reply tracking as the big killer app for any comment engine, too; sure, WordPress and MT support per-entry comment RSS feeds but managing subscriptions to those is a huge pain in the ass with the current state of RSS readers. I do have ideas on how a browser could provide a seamless, transparent subscription-discovery mechanism to the end user which would Just Work but it'd require support from the browser itself (though it could be done as e.g. a Firefox mod or a SIMBL plugin for Safari or something).
When I log out from within phpBB, it's just fine. The only difference I can see is that there's a redirect on the anchor link in the post whereas there's not one in the forum itself. However, my forumfuncs.inc is probably two or more years old so I'm not confident that it's functioning right.
http://asuh.com/community/forumfuncs.inc
remind me, is that the phpbb_sessions row in the database that I just empty? I see that row and phpbb_sessions_keys in phpmyadmin. i shouldn't empty both of those, right?Nevermind, I went ahead and emptied the phpbb_sessions after a little research. I'm not sure if this is true but when I try to log out and there's no sid attached to the end of the page name, it gives me that invalid_session problem. Right now, even though I'm logged in on my site, none of the log out links have sids attached.
It's basically to replaced some of the append_sid with sid=$userdata['session_id'], but I'm not sure why that's different and how it'll make a difference? What do you think?
In theory, there shouldn't be any trouble getting things to work with MT4 though, unless they've done something silly like require all pages to be generated dynamically or whatever.