[eluser]Benely[/eluser]
Im trying to adapt a MyBB class for use inside Codeigniter, I've made it in to library and heres the code:
Code:
<?php
class MyLib
{
var $cache;
var $config;
var $db;
var $mybb;
var $mybb_path = 'forums';
var $parser;
/**
* Constructor
*
* @param object $mybb Pass the Super MyBB Object as a reference so we can work with it
* @param object $db Pass the MyBB Database Handler as a reference so we can work with is
*/
function MyBBIntegrator(&$mybb, &$db, &$cache, &$plugins, &$lang, &$config)
{
$this->mybb =& $mybb;
$this->db =& $db;
$this->cache = $cache;
$this->plugins =& $plugins;
$this->lang =& $lang;
$this->config =& $config;
define('MYBB_ADMIN_DIR', MYBB_ROOT.$this->config['admin_dir'].'/');
require_once MYBB_ROOT.'inc/class_parser.php';
$this->parser = new postParser;
}
/**
* Shows a message for errors occuring in this class.
* Afterwards it stops the script
*
* @param string $message The error message
*/
function _errorAndDie($message)
{
echo '<div style="width:92%; margin:4px auto; border:1px #DDD solid; background:#F1F1F1; padding:5px; color:#C00; font-weight:bold;">An error occured during script run.<br />'.$message.'</div>';
die;
}
/**
* Escapes a value for DB usage
*
* @param mixed $value Any value to use with the database
* @return string
*/
function dbEscape($value)
{
return $this->db->escape_string($value);
}
/**
* Returns data of a user
* Refers to: inc/functions.php
*
* @param integer $user_id ID of User to fetch data from (0 = own user)
* @return array
*/
function getUser($user_id = 0)
{
// If given user id is 0, we use the own User ID
if ($user_id == 0)
{
return get_user($this->mybb->user['uid']);
}
// Otherwise we fetch info from given User ID
else
{
return get_user($user_id);
}
}
/**
* Is the user logged in?
*
* @return boolean
*/
function isLoggedIn()
{
// If the user is logged in, he has an UID
if ($this->mybb->user['uid'] != 0)
{
return true;
}
else
{
return false;
}
}
/**
* Logout procedure
*
* @return boolean
*/
function logout()
{
// If the user is not logged in at all, we make him believe that the logout procedure workedjust fine
if (!$this->isLoggedIn())
{
return true;
}
// Check session ID if we have one
if($this->mybb->input['sid'] && $this->mybb->input['sid'] != $this->mybb->session->sid)
{
return false;
}
// Otherwise, check logoutkey
else if (!$this->mybb->input['sid'] && $this->mybb->input['logoutkey'] != $this->mybb->user['logoutkey'])
{
return false;
}
// Clear essential login cookies
my_unsetcookie("mybbuser");
my_unsetcookie("sid");
// The logged in user data will be updated
if($this->mybb->user['uid'])
{
$time = TIME_NOW;
$lastvisit = array(
"lastactive" => $time-900,
"lastvisit" => $time,
);
$this->db->update_query("users", $lastvisit, "uid='".$this->mybb->user['uid']."'");
$this->db->delete_query("sessions", "sid='".$this->mybb->session->sid."'");
}
// If there are any hooks to run, we call them here
$this->plugins->run_hooks("member_logout_end");
return true;
}
}
The problem I have is I have no idea how to initialize it, what I would normally do is include "global.php" from MyBB and then create a class passing the variables in to it, but with CodeIgniter this causes problems I'n guessing due to $db?
Code:
Fatal error: Call to a member function simple_select() on a non-object in /home/test_ser/public_html/forums/inc/class_datacache.php on line 79
I was just wondering if anyone had any idea about this, I'd be in your debt forever.