MyBB Bolt-On Instructions

Home » Projects » MyBB Bolt-On » Instructions

To set up the MyBB Bolt-On, you need to have MODx and MyBB installed on the same server.

The bolt-on should work with MODx 0.9.5 and greater, and MyBB 1.2.x and greater.


Step 1

  1. Download the core functions in the mybb_functions.txt file here and rename the file to mybb_functions.php
  2. To upload the file to your MODx snippets folder via your file manager, follow these steps:
    1. Login to your MODx Manager at www.yoursite.com/modx_install_dir/manager
    2. Click on the Resources tab, then click the Manage Files menu item beneath
    3. Click on the assets folder name, then the snippets folder name
    4. Click on New Folder and create a new folder called mybb
    5. Click on the mybb folder name, then use the browse button to locate the mybb_functions.php file which you just downloaded and click the Upload File button
  3. The core functions have now been uploaded

Step 2

  1. In your MODx Manager, click on the Resources tab, then on the Manage Resources menu item
  2. Click on the Snippets tab and then on the New Snippet link at the top of the snippet list
  3. Give your new snippet the title MyBB
  4. Copy and paste the code below into the Snippet code (PHP) box and click the Save button beneath it
  5. The snippet that runs the whole thing has now been saved

<?php
# MyBB Bolt-On
# by Peter Burlingham

# Version 0.5 - December 2006
# Full usage instructions: http://www.acronymity.co.uk/projects/mybb_bolt_on/instructions.html


### Settings ###
// Path to MyBB (with trailing slash)
$mybb_path = "/home/yoursite/public_html/mybb/";
// Path to snippets folder
$snippet_path = $modx->config['base_path'] . "assets/snippets/mybb/";

// Required globals to make this work
global $mybb, $db, $cache, $plugins, $displaygroupfields, $grouppermignore, $groupzerogreater, $lang, $fpermfields;

// Get our usable functions
require_once($snippet_path.'mybb_functions.php');

// Un-comment to get a lot of MyBB vars.
//echo "<pre>";
//print_r($mybb);
//echo "</pre>";
//exit;


// So what are we doing?
switch ($get_me_my) {

### Display user info based on forum group settings ###
case 'userinfo':
  // Default groups: Guest = 1, Member = 2, Super Moderator = 3, Admin = 4, Validating = 5, Moderator = 6, Banned = 7
  // Pass the board URL
  $modx->setPlaceholder('mybb.url', $mybb->settings['bburl']);
  if (($mybb->user['usergroup'] == 1) || ($mybb->user['usergroup'] == 5) || ($mybb->user['usergroup'] == 7)) {
    // For guests...
    $modx->setPlaceholder('mybb.showuserinfo', '{{MyBB_UserLoggedOut}}');
  }  else {
    // For everyone else...
    // Get new topic and post info
    $newinfo = latestposts($db,$mybb);
    $modx->setPlaceholder('mybb.uid', $mybb->user['uid']);
    $modx->setPlaceholder('mybb.username', $mybb->user['username']);
    $modx->setPlaceholder('mybb.newmsg', (integer)$mybb->user['pms_new']);
    $modx->setPlaceholder('mybb.newtopic', $newinfo['newthreads']);
    $modx->setPlaceholder('mybb.newpost', $newinfo['newposts']);
    $modx->setPlaceholder('mybb.showuserinfo', '{{MyBB_UserLoggedIn}}');
  }
break;


### Show forum statistics ###
case 'stats':
  // Grab the stats from the forum cache
  $stats = $cache->read("stats");

  // Parse the stats template
  $modx->setPlaceholder('mybb.nummembers', $stats['numusers']);
  $modx->setPlaceholder('mybb.numthreads', $stats['numthreads']);
  $modx->setPlaceholder('mybb.numposts', $stats['numposts']);
  $modx->setPlaceholder('mybb.newmember', $stats['lastusername']);
  $modx->setPlaceholder('mybb.newuid', $stats['lastuid']);
break;


### Show online users ###
case 'online':
  $online = onlinelist($db,$mybb,$cache);
  // What shall we separate the list of users with? A comma, a middot, or anything else of your choice.
  $separator = ' · ';
  // When displaying online users, shall we apply colouring styles to their name as in the forums for different groups?
  $forumstyle = 1;
  
  $modx->setPlaceholder('mybb.numonline', $online['count']);
  $modx->setPlaceholder('mybb.numguests', $online['guests']);
  $modx->setPlaceholder('mybb.nummembers', $online['members']);

  // Go through online users if there are any and put together a list
  if ($online['members'] >= 1) {

    $onlinelist = '';
    $i = 1;
    foreach ($online['users'] as $user) {
      if ($forumstyle == 1) {
        $onlinelist .= '<a href="'.$mybb->settings['url'].'/member.php?action=profile&uid='.$user['uid'].'">'.$user['forumnamestyle'].'</a>';
      } else {
        $onlinelist .= '<a href="'.$mybb->settings['url'].'/member.php?action=profile&uid='.$user['uid'].'">'.$user['name'].'</a>';
      }
      if ($i < $online['count']) {
        $onlinelist .= $separator;
      }
      $i++;
    }

    $modx->setPlaceholder('mybb.showlist', $onlinelist);
    $modx->setPlaceholder('mybb.onlinelist', '{{MyBB_OnlineList}}');
    
  }
break;


### Show forum topics (news headlines) ###
// Sample call   -  
// Change the forum topics are grabbed from by changing the fid to your news forum's ID.
// To get topics from more than one forum, separate your fid's wtith a comma eg. &fid=2,3,6,11
// Change number of topics returned by changing the limit to whatever you desire. A really high limit will return more topics and slow your page down though!

case 'headlines':
  $modx->setPlaceholder('mybb.url', $mybb->settings['bburl']);
    
  $fid = (isset($fid))? $fid : 2;
  $limit = (isset($limit))? $limit : 10;

  $headlines = headlines($db,$mybb,$cache,$templates,$parser,$fid,$limit);
  $articlelist = "";
  $i = 1;
  if (!empty($headlines)) {
    foreach ($headlines as $headline) {
      $modx->setPlaceholder('mybb.arttitle', $headline['subject']);
      $modx->setPlaceholder('mybb.artdate', $headline['dateline']);
      $modx->setPlaceholder('mybb.artcontent', $headline['message']);
      $modx->setPlaceholder('mybb.artauthor', $headline['username']);
      $modx->setPlaceholder('mybb.artid', $headline['tid']);
      $modx->setPlaceholder('mybb.artcomments', $headline['replies']);

      // Very fancy and un-documented MODx function - lucky I found it or I'd have template bits in my snippet (eww!)
      $articlelist .= $modx->mergePlaceholderContent($modx->mergeChunkContent("{{MyBB_NewsArticle}}"));

      // Add a divider chunk below every article except the last one. Counting the headlines array instead of using our $limit variable in case there's less than $limit articles returned in the query y'see?
      if ($i  < count($headlines)) {
        $articlelist .= "{{MyBB_NewsDivider}}";
      }
      $i++;
    }
  } else {
    $articlelist = "There were no news topics found in the forum you specified.";
  }
  $modx->setPlaceholder('mybb.newsarticles', $articlelist);
break;


### Show latest posts ###
// Sample call   -  
// Change limit to the number of latest posts you want to display.
// Change the trim to how many characters you want the title to be trimmed to. Set to zero to skip trimming.
// Change the format the date and time are displayed in as per www.php.net/date

case 'latest_posts':
  $modx->setPlaceholder('mybb.url', $mybb->settings['bburl']);

  $limit = (isset($limit))? $limit : 5;
  $trim = (isset($trim))? $trim : 25;
  $dateformat = "jS M 'y";
  $timeformat = "g:ia";

  $lastxposts = lastxposts($db,$mybb,$limit,$trim,$dateformat,$timeformat);
  $postlist = "";
  $i = 1;
  if (!empty($lastxposts)) {
    foreach ($lastxposts as $post) {
      $modx->setPlaceholder('mybb.postid', $post['tid']);
      $modx->setPlaceholder('mybb.posttitle', $post['subject']);
      $modx->setPlaceholder('mybb.postdate', $post['lastpostdate']);
      $modx->setPlaceholder('mybb.posttime', $post['lastposttime']);
      //if ($post['lastposteruid']
      $modx->setPlaceholder('mybb.postauthor', $post['lastposter']);

      // Very fancy and un-documented MODx function - lucky I found it or I'd have template bits in my snippet (eww!)
      $postlist .= $modx->mergePlaceholderContent($modx->mergeChunkContent("{{MyBB_LatestPost}}"));
      $i++;
    }
  } else {
    $postlist = "There are no topics to display.";
  }
  $modx->setPlaceholder('mybb.lastxposts', $postlist);
break;


### Show upcoming events ###
// Sample call   -  
// Change limit to the number of events you want to display.
// Change the trim to how many characters you want the title to be trimmed to. Set to zero to skip trimming.
// Change the format the date and time are displayed in as per www.php.net/date

case 'upcoming_events':
  $modx->setPlaceholder('mybb.url', $mybb->settings['bburl']);

  $limit = (isset($limit))? $limit : 5;
  $trim = (isset($trim))? $trim : 25;
  $dateformat = "jS M 'y";

  $nextxevents = nextxevents($db,$mybb,$limit,$trim,$dateformat);
  $eventlist = "";
  $i = 1;
  if (!empty($nextxevents)) {
    foreach ($nextxevents as $event) {
      $modx->setPlaceholder('mybb.eventid', $event['eid']);
      if (isset($event['short_subject'])) {
        $modx->setPlaceholder('mybb.eventtitle', $event['short_subject']);
      } else {
        $modx->setPlaceholder('mybb.eventtitle', $event['subject']);
      }
      $modx->setPlaceholder('mybb.eventalt', $event['subject']);
      $modx->setPlaceholder('mybb.eventdate', $event['format_date']);
      

      // Very fancy and un-documented MODx function - lucky I found it or I'd have template bits in my snippet (eww!)
      $eventlist .= $modx->mergePlaceholderContent($modx->mergeChunkContent("{{MyBB_UpcomingEvent}}"));
      $i++;
    }
  } else {
    $eventlist = "There are no events to display.";
  }
  $modx->setPlaceholder('mybb.nextxevents', $eventlist);
break;


### Pass me my slippers and pipe ###
case 'slippers_n_pipe':
  echo "Mmmf... that's better. Now fetch me a cup of Earl Grey.";
break;
}

return '';
?>

Step 3

  1. Create the MyBB chunks below by doing the following:
    1. In your MODx Manager, click on the Resources tab, then on the Manage Resources menu item
    2. Click on the Chunks tab on the resources screen and then on the New Chunk link
    3. Enter the name of the chunk (see titles above each chunk)
    4. Copy and paste the chunk content below into the Chunk Code (HMTL) box and click the Save button att he bottom of the screen
  2. Repeat until all chunks have been added - you may wish to categorise your chunks for neatness.

MyBB_LatestPost

<li>
  <strong><a href="[+mybb.url+]/showthread.php?tid=[+mybb.postid+]">
  [+mybb.posttitle+]</a></strong><br />
  posted [+mybb.postdate+] at [+mybb.posttime+] by [+mybb.postauthor+]
</li>

MyBB_LatestPosts

&limit - the number of topic titles you want to display
&trim -  the number of characters you wish to trim event titles down to. Change to zero if you want to grab the full title.

[!MyBB? &get_me_my=`latest_posts` &limit=5 &trim=25!]

<h3>Latest Posts</h3>
<br />
<ul>
  [+mybb.lastxposts+]
</ul>

MyBB_NewsArticle

<h4>[+mybb.arttitle+]</h4>
<h5>Posted on [+mybb.artdate+] by [+mybb.artauthor+]</h5>
<br />
[+mybb.artcontent+]<br />
<br />
<center><a href="[+mybb.url+]/showthread.php?tid=[+mybb.artid+]">View Comments ([+mybb.artcomments+])</a> &middot; <a href="[+mybb.url+]/printthread.php?tid=[+mybb.artid+]">Print Article</a> &middot; <a href="[+mybb.url+]/showthread.php?tid=[+mybb.artid+]">Post Comment</a></center>

MyBB_NewsDivider

<br />
<br />
<div style="border-top-style: dotted; border-top-color: #cccccc; border-top-width: 1px;">&nbsp;</div>

MyBB_NewsHeadlines

&fid - the forum ID you wish to get topics from. Separatemultiple forum IDs with a comma to grab topics from multiple forums eg. &fid=2,3,16
&limit - the number of topics you want to display

[!MyBB? &get_me_my=`headlines` &fid=2 &limit=10!]

<h3>News Headlines</h3>
<br />
[+mybb.newsarticles+]

MyBB_Online

[!MyBB? &get_me_my=`online`!]

<h2>Users Online</h2>
<ul>
  <li>[+mybb.numonline+] users online</li>
  <li>[+mybb.numguests+] guests</li>
  <li>[+mybb.nummembers+] members</li>
  [+mybb.onlinelist+]<br />
  <li><a href="[+mybb.url+]/online.php">View Details</a></li>
</ul>

MyBB_OnlineList

<br />
[+mybb.showlist+]
<br />

MyBB_Showstats

[!MyBB? &get_me_my=`stats`!]

<h2>Site Statistics</h2>
<ul>
  <li>[+mybb.nummembers+] members</li>
  <li>[+mybb.numthreads+] threads</li>
  <li>[+mybb.numposts+] posts</li>
  <br />
  <li>Newest member: <a href="[+mybb.url+]/member.php?action=profile&uid=[+mybb.newuid+]">[+mybb.newmember+]</a></li>
</ul>

MyBB_UpcomingEvent

<li>
  <strong><a href="[+mybb.url+]/calendar.php?action=event&eid=[+mybb.eventid+]" alt="[+mybb.eventalt+]" title="[+mybb.eventalt+]">[+mybb.eventtitle+]</a></strong> - [+mybb.eventdate+]
</li>

MyBB_UpcomingEvents

&limit - the number of events you want to display.
&trim - the number of characters you wish to trim event titles down to. Change to zero if you want to grab the full title.

[!MyBB? &get_me_my=`upcoming_events` &limit=5 &trim=25!]

<h3>Upcoming Events</h3>
<br />
<ul>
  [+mybb.nextxevents+]
</ul>

MyBB_UserInfo

[!MyBB? &get_me_my=`userinfo`!]

[+mybb.showuserinfo+]

MyBB_UserLoggedIn

<h2>Welcome [+mybb.username+]!</h2>
<ul>
  <li><a href="[+mybb.url+]/usercp.php">Control Panel</a></li>
  <li><a href="[+mybb.url+]/private.php">[+mybb.newmsg+] new messages</a></li>
  <li><a href="[+mybb.url+]/search.php?action=getnew">[+mybb.newtopic+] new topics</a></li>
  <li><a href="[+mybb.url+]/search.php?action=getnew">[+mybb.newpost+] new posts</a></li>
  <br />
  <li><a href="[+mybb.url+]/member.php?action=logout&uid=[+mybb.uid+]">Log Out</a></li>
</ul>

MyBB_UserLoggedOut

<h2>Welcome Guest!</h2> <ul>   <li><a href="[+mybb.url+]/member.php?action=login">Log In</a></li>   <li><a href="[+mybb.url+]/member.php?action=register">Register</a></li> </ul>

Step 4

  • You can now use the following chunk calls in your templates and pages.
  • For inclusion in templates:

    • {{MyBB_UserInfo}}
    • {{MyBB_ShowStats}}
    • {{MyBB_Online}}

  • For inclusion in pages:

    • {{MyBB_LatestPosts}}
    • {{MyBB_UpcomingEvents}}
    • {{MyBB_NewsHeadlines}}

  • You may of course call these chunks anywhere you like, however since the UserInfo, ShowStats and Onlin chunks usually appear on every page, it makes more sense to add them into your template and use the rest only in those pages as and when you need them.
And there we have it! An easy set of functions to bolt MyBB data onto MODx using template chunks that you can easily alter to suit your layout!