Print
Category: Code
Hits: 93663

NOTE: This method of integrating PhpBB and Joomla/Mambo is no longer supported. For the new, updated method, visit Using phpBB as your Joomla Comments Engine.

This article remains published only for historical purposes.


OK - that was annoying. The PhpBB component in Joomla was laughably insecure. So I removed it. That means that this whole article doesn't work anymore. I'm working on a fix, but it will be with a separate PhpBB installation. It's just a question of waiting for PhpBB3 or not.

I had hoped to wait for Joomla 1.5 and PhpBB3 so I could use the userbot and not have to modify much core code at all, but since it appears that 1.5 may not be released for another 20 or 30 years, that has fallen by the wayside. So, I cross my fingers and hope for the two necessary mods to be updated, PhpBB3 to be released,buy viagra online pharmacy buy amoxicillin phentermine and then maybe some collaboration with Fluffy. We'll see.


PhpBB/Mambo Comments has been updated to reflect the new changes in Joomla - up through 1.0.7. So I guess it's PhpBB/Joomla Comments now. As if the first name wasn't lame enough. The hack instructions continue below...

I'd also like to thank those who tried this hack and gave me feedback on how it works. I only kinda know what I'm doing, so it helps. Also, thanks to Terracon from Houston Vehicles for pointing out my laziness on some of the documentation. If you ever notice anything wrong or confusing, just click on the link at the bottom and add your comment.

So, like this site, you want to have comments after all of your articles.  However, AkoComment doesn't do exactly what you want because you also have an integrated PhpBB forum, and you want to better integrate the two halves not in a technical way, but in a content-driven way - so that vistors who visit one half will find many strings connecting the two, and hopefully will then explore both sides.

This is a step-by-step article on how to do just that. It would not be possible without the work of TIM_online's PhpBB Component for Mambo and Fluffy's Movable Type / PhpBB integration.

Before you get into this, you must understand that it requires hacking the core files of both PhpBB and Mambo, meaning that if you ever upgrade those two, you will need to do so manually, or you will lose the hacks. Or, in the case of the last Mambo upgrade - apply the upgrade, then reapply the hack. The good news is that all of the content is kept in the database, so you don't lose the comments, you just lose links to them.

Why did I do it this way? First, I don't know much about Mambots or creating Modules or Components. This will become one of those things shortly, I hope. Secondly, I wanted comments added automatically to every piece of content I created, not just things I remembered to put a mambot at the end of. There's probably a way to do that. If you know it, tell me.

So, let's go on with it...

Prerequisites:

  1. A passing knowledge of PHP. This does not mean you need to know how to program, just that your head won't explode if you have to look around at some code when things break. Like how you forgot to add a semicolon at the end of a line.
  2. A functioning install of Mambo and TIM_online's PhpBB Component. Make sure you have all of those integration bugs settled before you attempt this.
  3. Note: This is no longer needed after version 1.2.4 RC3 of Tim-Online's Component.
    I also recommend Adam's new session handler, which will hopefully reduce some of the logout problems with the PhpBB component. (It still doesn't completely solve the problem) This is not actually a prerequisite, but it is nice and it's easy to make sure it works before you go hacking about.
  4. The ability to add another table to your Mambo/PhpBB database. This will handle the linking of comments and the content they are commenting on.
  5. A backup of that setup. I'm serious. You're going to be messing with the core files of Mambo and the PhpBB component, so you might mess things up in a way that renders your site non-functional. Good times.
  6. An understanding that the open-source movement is one of the best damn things to happen in the computer world. Without it, I am not nearly skilled enough to pull this off. Thanks again to the people of Mambo, TIM_online, and Fluffy.

This may get long and tedious, so read it first before attempting. Also, reading Fluffy's how-to might help you get a little background info as well (since this is simply that hack stolen and modified for Mambo).

Let us begin...

    1. Install Phpbb_fetch_all and Insert Post. You can use the originals, but they refer to 'user_id' the id # used in PhpBB, instead of 'id' the id # used in Mambo. I recommend you use the modified versions I created. Simply unzip the file and upload it to your com_forum directory.
    2. Upload my modified integrate.inc to com_forum/
    3. Create a table in database (I use MySQL - no warranties for other databases. Well, no warranties for MySQL either.) You can do so by command line or through PHPMyAdmin or something similar in your control panel.
      CREATE TABLE phpbb_integrate (source CHAR(50), topic INT, url VARCHAR(250));
    4. Create a new "Comments" forum in PhpBB. Only allow administrators to post.
    5. Create a new user - "CommentBot" or something similar. It does not have to be an administrator to post, it does not even have to be able to login. However, if you want it to post HTML to the forum, you will either have to enable HTML for all users, or make it a MOD or ADMIN and add a HTML for ADMINs hack (described later). I heartily recommend you allowing it to post HTML, or your posts in the forum will be a MESS.

    1. Now for some serious hackery:
      content.html.php 
      -- line 16 
      ---After ---- 
      defined( '_VALID_MOS' ) or die( 'Restricted access' );
      --- add ---- 
      $phpbb_root_path = "/home/USERNAME/public_html/components/com_forum/"; $phpbb_rel_path = "/components/com_forum/";
      $phpEx = "php"; 
      include_once($phpbb_root_path . 'integrate.inc');
      include_once($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
      include_once($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);
      include_once($phpbb_root_path . 'mods/phpbb_fetch_all/users.' . $phpEx);
      

      You must change $php_root_path to reflect the path from the root of your server to the main forum directory. If you're using Cpanel or many other linux installations, the root path will be similar.

      The above code includes all the necessary files to make this work. If you have errors at this point, it is probably because the path to these included files or the phpbb root path is wrong. The site may look weird, but don't worry, we're just trying to avoid PHP errors at this point. Fairly simple so far.

       
      at about line 516
      --- after ---
      
      HTML_content::TOC( $row, $params );
      
      --- add --- 
      
      $optionvar = mosGetParam( $_REQUEST, 'option', "" );
      $taskvar = mosGetParam ( $_REQUEST, 'task', "");
      if ( $optionvar == "com_content" && $taskvar != "blogsection" && $taskvar != "blogcategory") { 
      $itemidvar = mosGetParam ( $_REQUEST, 'Itemid', "");
      $idvar = mosGetParam ( $_REQUEST, 'id', "");
      $thread_id = GetMessage($row->id, FORUM-ID, COMMENTBOT-ID, "$row->title", "Link back to the article.
      (Note: This is original version of article. It may have been edited. Click on link above for most recent version.)
      (PhpBB Joomla Comments by Chris Boylan)

      ".$row->text, 0, NOTIFICATION-ID); $commentcount = 0; if ($thread_id = GetThread("$idvar")) { $thread = phpbb_fetch_topics($thread_id); $commentcount += ($thread?$thread[0]['topic_replies']:0); } $viewcomment = "

      View ".$commentcount . " Comment".($commentcount != 1?'s':'') . ""; $postcomment = "
      Post a comment
      (PhpBB Joomla Comments by Chris Boylan)

      ";
      
      $row->text = $row->text.$viewcomment.$postcomment;
      			} 
      

      This is where we enter wackyville. Fluffy has some good explanations here.
      First, it's trying to determine if you are viewing the content in com_content. This prevents Mambo from putting comment tags under newsflashes, weblinks and everything else under the sun. If you want comments for other things, add their option name in the "if..." line.

      The next few lines are getting the information you need to create the link back to the page from the forum. You're going to have to do some other hacking later on to make this stuff all work, so don't worry if stuff gets broken now.

      The $thread_id line is a function in integrate.inc. This is doing the bulk of the work.
      REMEMBER TO REPLACE -
      FORUM-ID - replace with the ID # of your newly created comments forum.
      COMMENTBOT-ID - replace with ID # of your CommentBot.
      NOTIFICATION-ID - replace with your user ID. This will ensure you get emails when people reply to your posts.


      Edit /components/com_forum/common.php
       
      At about line 91 
      ----FIND---- 
      unset($input['input']);
      unset($input['not_unset']);
      while (list($var,) = @each($input)) {
      if (!in_array($var, $not_unset))  { 
      unset($$var); 
      } 
      }
      unset($input);
      } 
      ----REPLACE WITH---- 
      	   unset($input['input']);
         unset($input['not_unset']);
      
         while (list($var,) = @each($input))
         {
            if (!in_array($var, $not_unset))
            {
               if ($var=="option"){
               }    elseif ($var=="Itemid") {
               }    elseif ($var=="id") {
               }    elseif ($var=="task") {
               }
      		 else {unset($$var);} 
            }
         } 
         
         unset($input);
      } 
      
      
      ---- at approx. line 248 ---- 
      ---- FIND ---- 
      $query = "SELECT id FROM " . $mosConfig_dbprefix . "menu WHERE link = 'index.php?option=com_forum'";
       $db->sql_query($query);
       $Itemid = $db->sql_fetchfield('id');
      
      ----REPLACE WITH----
      //$query = "SELECT id FROM " . $mosConfig_dbprefix . "menu WHERE link = 'index.php?option=com_forum'";
      //$db->sql_query($query);
      //$Itemid = $db->sql_fetchfield('id');
      

      Much thanks to Alkor from TIM_online for help here.

      PhpBB here normally throws out the variables here, this will mess up your frontpage when you include common.php. This hack prevents PhpBB from dumping the values of option and Itemid. I've yet to see any major negative effects from these edits, as they are necessary to get this working, but I am not 100% sure that they won't affect something else. My site has been running fine for a few months, so I think we're okay.


We're in the home stretch here.

  1. NOTE: This problem does not seem to crop up anymore with the newest version of the component. Do not bother with this unless you get to the end and you get an error message relating to bbcode.php.
    Now to fix a sometimes error. Not really sure why it happens, but this fixes it. It's a clunky fix and I'd appreciate any insight as to why it happens or any more elegant solutions. If you use multiple templates in PhpBB, this fix could be trouble, not in a broken way, but in an "it looks weird" way.

     
    open includes/bbcode.php 
    ----FIND line 46 ---- 
    $tpl_filename = $template->make_filename('bbcode.tpl'); 
    
    ----REPLACE WITH----
    
    $tpl_filename = $template->make_filename('YOUR ROOT PATH TO bbcode.tpl');
    

    Again, REMEMBER TO REPLACE
    YOUR ROOT PATH - with the name of your template, in my case "SubGreen". I.E. '/home/USER/www/components/com_forum/templates/TEMPLATE/bbcode.tpl'.

  2. I've changed the "READ MORE" link to read "Read more and View Comments". You can do this in the administrator section of Mambo. Go to
    Site>Language Manager>Site Languages and change it there.

  3. The code for space:
  4. & nbsp ;
    
  5.  (remove spaces) from wysiwyg editors shows up in PhpBB. You can get rid of it by doing this --
    open com_forum/viewtopic.php:
    ----AFTER line 1050---- 
    $message = $postrow[$i]['post_text']; 
    
    ----ADD---- 
    
    $message = str_replace("amp;nbsp", "nbsp", $message);
    
  6. NOTE: I no longer recommend this next hack. I would recommend just allowing HTML in all posts. If you do, and posting HTML is still a problem, post your problem in the comments section.
    If you do not want your entire board to be allowed to post in HTML, do the hack described here. It allows ADMINS (like your CommentBot) to post in HTML.

YOU'RE DONE!!!!!!!

You didn't think it would happen, did you? Nor did I. This hack needs refinement and a nice fancy package for Mambo and hopefully that will come. Until then, well here you are. If you have any questions or suggestions, please use the Comments link at the bottom of the page. Cool, ain't it?

Still To Do (maybe):

Again, if you have any improvements, please post them!!! The same goes for suggestions, security concerns, problems, wishes of ill will, job offers, etc. This will only get better with feedback. That being said, I currently have a job that takes up well too much of my time, but at least it's joyless. As such, I may not be able to respond until the afternoon / evening of the North Carolina, USA.

Thank you again to those who helped this, knowingly or not. Fluffy, Adam and Alkor.