Introduction

Dino offers a very flexible user management, though others would say it doesn't offer any at all.

This means that Dino is open to customization. For example: You can easily integrate Dino with other systems such as the popular board systems MyBB and SMF. These are especially well suited for this kind of integration as both offer nice APIs that fulfill everything Dino needs.

Now, the big question is: What kind of "integration" is possible? Short answer: You can use the complete userdatabase from these systems, including their login and registration. Therefore if a user logs into Dino, he'll be logged into the board as well - the other way works just as well.

There's a problem though: The way through which Dino checks access rights is different from those of most common systems. It doesn't have a "group" concept and it is based on a negative ruleset. Therefore you cannot allow a user to do something, but you can forbit him to do it. By leveraging a different source of users you lose the standard user-management that defined the rules.

Thus the most difficult aspect of the integration is to map the access management of the new source to the way Dino works. This introduction will only show how to handle the administration panel, as this is the only rule defined by the Dino-core. Everything else is up to Dinos modules/plugins/components.

MyBB

The first thing you'll have to do is to install Dino and MyBB. It doesn't matter what you install first. Example of your directory structure:

  • / (contains dino
  • /board (contains mybb)

Thus the mybb will be placed within a "board" directory within Dinos structure.

Because of the lack of namespaces in PHP you'll have to modify both Dino and the MyBB to work together. The problem here is the function named "get_user", which has been defined in both, MyBB and Dino. Both are essential for the application, so there's no way around them. The good part is that both define a different number of arguments: Dinos get_user has none, MyBBs has one.

Open /lib/utilities.php and replace the entire get_user function with this code:

  1. function &get_user() {
  2.     // hack for mybb (it defines the same function)
  3.     if(func_num_args() == 0) {
  4.         // this is for dino
  5.         if(!isset($GLOBALS['singleton']['User'])) {
  6.             require_once(DSCMS_ROOT . '/lib/user.impl.php');
  7.             $GLOBALS['singleton']['User'] = new UserImpl();
  8.         }
  9.         return $GLOBALS['singleton']['User'];
  10.     } else {
  11.         // this is the mybb implementation
  12.         return my_get_user(func_get_arg(0));
  13.     }
  14. }
  15.  

Now, before you safe and close the file, you'll also add the import of the board system here. Look for the stripslashes_array function and add the following code directly before it:

  1. if(!defined('IN_MYBB')) {
  2.     define("IN_MYBB", true);
  3. }
  4. chdir('./board'); // MODIFY this line to match the path to your mybb installation
  5. require_once('./global.php');
  6. chdir('./..'); // MODIFY this line too, it should be the path from the mybb installation to dino
  7.  

And place this at the top of the file (after <?php):

  1. define('IN_DINO', true);
  2.  

The last step is to replace the content of /lib/user.impl.php with this:

  1. <?php
  2. require_once('./lib/user.interface.php');
  3.  
  4. class UserImpl extends User {
  5.     private $mybb;
  6.     function UserImpl() {
  7.         global $mybb;
  8.         $this->mybb = $mybb;
  9.     }
  10.    
  11.     function isLoggedIn() {
  12.         return isset($this->mybb->user['uid']) && $this->mybb->user['uid'] != 0;
  13.     }
  14.    
  15.     function login($name, $pass) {
  16.         // happens automatically
  17.     }
  18.    
  19.     function logout() {
  20.         // not used by Dino anyway
  21.     }
  22.    
  23.     function can($key) {
  24.         // map the "admin"-key to mybbs "cancp"-permission
  25.         $keys = array('admin'=>'cancp');
  26.         if(isset($keys[$key])) {
  27.             return $this->mybb->usergroup[$keys[$key]];
  28.         }
  29.         // new code that uses mybb keys?
  30.         if(isset($this->mybb->usergroup[$key])) {
  31.             return $this->mybb->usergroup[$key];
  32.         }
  33.         // this is a problem
  34.         return true;
  35.     }
  36.    
  37.     function get($key) {
  38.         return isset($this->mybb->user[$key]) ? $this->mybb->user[$key] : $this->mybb->usergroup[$key];
  39.     }
  40. }
  41. ?>
  42.  

The line of code directly after the comment // this is a problem is critical because it will enable a user to do everything that doesn't require administration rights. Therefore you should map more keys to Dino if you have installed any modules that use permissions for users. This is not the case with any of Dinos standard modules, though. The other reason you might want to add more mappings is to allow finer control of access for administrative modules. With mapping above you'd allow every user with "cancp"-permission to do everything in the administration area. Anyway, the code above should be good enough for most use-cases.

Now we need to modify the MyBB. Open /inc/functions.php and search for "function get_user($uid)" and replace it with "function my_get_user($uid)". Place the following code after the function definition:

  1. if(!defined('IN_DINO')) {
  2.     function get_user($uid) {
  3.         return my_get_user($uid);
  4.     }
  5. }
  6.  

You're done.

SMF

The first thing you'll have to do is to install Dino and the SMF. It doesn't matter what you install first. Example of your directory structure:

  • / (contains dino
  • /board (contains smf)

Thus the smf will be placed within a "board" directory within Dinos structure.

Both systems define a function called "is_admin", but Dinos is deprecated so you should be safe to remove it if it isn't used by any of your specific modules. Thus open /lib/utilities.php, search for is_admin and remove the complete function (or rename it to "dino_is_admin" or something like that).

Now replace the contents of /lib/user.impl.php with the following code:

  1. <?php
  2. require_once('./lib/user.interface.php');
  3. class UserImpl extends User {
  4.     var $user;
  5.    
  6.     function UserImpl() {
  7.         require_once(DSCMS_ROOT . '/board/SSI.php');
  8.         $this->user = $user_info;
  9.     }
  10.    
  11.     function login($username, $password) {
  12.         // ignore this, handled by the board
  13.         return $this->isLoggedIn();
  14.     }
  15.    
  16.     function isLoggedIn() {
  17.         return !$this->user['is_guest'];
  18.     }
  19.    
  20.     function can($key) {
  21.         // map Dino keys to smf-keys
  22.         $keys = array('admin'=>'is_admin');
  23.         if(isset($keys[$key])) {
  24.             return $this->user[$keys[$key]];
  25.         }
  26.         // allow everything else. This is a problem!
  27.         return true;
  28.     }
  29.    
  30.     function get($key) {
  31.         return isset($this->user[$key]) ? $this->user[$key] : null;
  32.     }
  33.    
  34.     function logout() {
  35.         ssi_logout();
  36.     }
  37. }
  38. ?>
  39.  

Note that in order to make your code safer you really should add more mappings. See the mybb-tutorial for the reasons behind this.

You're done.