Previous Thread
Next Thread
Print Thread
Hop To
#128560 05/01/2006 9:08 PM
Joined: Apr 2006
Posts: 116
F
member
member
F Offline
Joined: Apr 2006
Posts: 116
I am trying to integrate flashchat http://www.tufat.com with my .threads CMS and the good thing is that someone has already written an integration module for 6.5.??? threads. It half works and causes errors when trying to add AI bot to the chat which runs but doesn't do anything. If however one specifies not to integrate with .threads the bot works. Rick, here is the ubbCMS module. I appreciate if you could have a quick glance and tell me if you think there is something there that shouldn't be there, cheers! (the errors seem to occure when requests involve the word 'user')

Code
  

<?php
/************************************************************************/
//!!! IMPORTANT NOTE
//!!! FlashChat 4.4.0 and higher support a new user role: ROLE_MODERATOR
//!!! Please edit the getUser and getRoles function if you need use of
//!!! the new moderator role. This change has not yet been applied.
/************************************************************************/

// integration class for UBB.Threads (www.ubbcentral.com/ubbthreads/)


$ubb_root_path = realpath(dirname(__FILE__) . '/../../../') . '/';

require_once($ubb_root_path . 'includes/config.inc.php');

class UBBCMS {

    function UBBCMS() {

        $this->loginStmt = new Statement("SELECT U_Username, U_Laston, U_Password,U_Number,U_Language,U_TempPass,U_Approved,U_Banned,U_CoppaUser FROM   {$GLOBALS['config']['tbprefix']}Users WHERE  U_LoginName = ? LIMIT 1");
        $this->updateSessionStmt = new Statement("UPDATE {$GLOBALS['config']['tbprefix']}Users SET    U_Laston   = ?, U_SessionId = ? WHERE  U_Username = ?");
        $this->getUserStmt = new Statement("SELECT U_Username as login, U_Number as id, U_Status as status FROM {$GLOBALS['config']['tbprefix']}Users WHERE  U_Number = ? LIMIT 1");
        $this->getUsersStmt = new Statement("SELECT U_Username as login, U_Number as id FROM {$GLOBALS['config']['tbprefix']}Users");
        $this->userid = isset($_COOKIE["w3t_myid"]) ? $_COOKIE["w3t_myid"] : NULL;
    }

    function isLoggedIn() {
        return $this->userid;
    }

    function getRoles($status) {
        $rv = NULL;

        if ($status == "Administrator" || $status == "Moderator")
            $rv = ROLE_ADMIN;
        elseif ($status == "User")
            $rv = ROLE_USER;
        else
            $rv = ROLE_SPY;

        return $rv;
    }

    function getUserProfile($userid) {

        if ($userid == SPY_USERID) $rv = NULL;

        elseif ($user = $this->getUser($userid)) {
            $rv = ($id = $this->isLoggedIn() && ($id == $userid)) ? $GLOBALS["config"]["phpurl"] . "/login.php?Cat=0&myhome=1" : $GLOBALS["config"]["phpurl"] . "/showprofile.php?Cat=0&User={$userid}";
        }

        return $rv;
    }


    function getUser($userid) {

        $rs = $this->getUserStmt->process($userid);
        $rv = $rs->next();

        if($rv) {
            $rv["roles"] = $this->getRoles($rv["status"]);
        }
        return $rv;
    }

    // taken from ubbt.inc.php

    function ubbt_setcookie($name,$value="",$time=0,$cookiepath="") {

        if (!$cookiepath) {
            $cookiepath = $GLOBALS['config']['cookiepath'];
            if ($GLOBALS['config']['search_urls'] && !$cookiepath) {
                $cookiepath = "/";
            }
        }
        if (($GLOBALS['config']['tracking'] == "cookies") || ($name == "{$GLOBALS['config']['tbprefix']}ubbt_pass") || ($name == "{$GLOBALS['config']['tbprefix']}ubbt_dob")) {
            setcookie("$name","$value",$time,$cookiepath);
        }
        else {
            session_register($name);
            $name = $value;
        }

    }

    function login($login, $password) {

        $goodPassword = false;

        $rs = $this->loginStmt->process(addslashes($login));
        $rec = $rs->next();

        if ($rec) {
            // check if user is banned
            if ($rec["U_Banned"]) return NULL;

            // allow login only with permanent password. Ignore the temporary password
            if (md5($password) != $rec["U_Password"]) return NULL;

            if (!$rec["U_Laston"]) {
                $laston = time() + $GLOBALS["config"]["adjustime"] * 3600;
            }
            $this->ubbt_setcookie("{$GLOBALS['config']['cookieprefix']}w3t_myid",$rec['U_Number'],time()+$GLOBALS['config']['cookieexp']);

            $this->updateSessionStmt->process(time() + $GLOBALS["config"]["adjustime"] * 3600, md5(rand(0,32767)), addslashes($login));


            return $rec['U_Number'];

        }

    }

	function userInRole($userid, $role) {
		if($user = $this->getUser($userid)) {
			return ($user['roles'] == $role);
		}
		return false;
	}

    function logout() {

    }

    function getUsers() {
        $this->getUsersStmt->process();
    }

	function getGender($userid) {
        // 'M' for Male, 'F' for Female, NULL for undefined
        return NULL;
    }
}

$GLOBALS['fc_config']['db'] = array(
                'host' => $GLOBALS["config"]["dbserver"],
                'user' => $GLOBALS["config"]["dbuser"],
                'pass' => $GLOBALS["config"]["dbpass"],
                'base' => $GLOBALS["config"]["dbname"],
                'pref' => $GLOBALS["config"]["tbprefix"] . 'fc_',
                );

$GLOBALS['fc_config']['cms'] = new UBBCMS();


foreach($GLOBALS['fc_config']['languages'] as $k => $v) {
    $GLOBALS['fc_config']['languages'][$k]['dialog']['login']['moderator'] = '';
}

?>



#128561 05/02/2006 1:12 PM
Joined: Apr 2006
Posts: 116
F
member
member
F Offline
Joined: Apr 2006
Posts: 116
Ahahahaha just found the bug in this code that was responsible. Can you find it? <img src="https://www.ubbcentral.com/boards/images/graemlins/grin.gif" alt="" /> <img src="https://www.ubbcentral.com/boards/images/graemlins/grin.gif" alt="" /> <img src="https://www.ubbcentral.com/boards/images/graemlins/grin.gif" alt="" />

#128562 05/02/2006 7:50 PM
Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
Blah, I have trouble debugging my own code let alone someone elses <img src="https://www.ubbcentral.com/boards/images/graemlins/laugh.gif" alt="" />

#128563 05/03/2006 11:38 AM
Joined: Apr 2006
Posts: 116
F
member
member
F Offline
Joined: Apr 2006
Posts: 116
I am not really a programmer, but yeah, I know what you mean <img src="https://www.ubbcentral.com/boards/images/graemlins/wink.gif" alt="" />

function getUsers() returns nothing, you call it and expect an array but in fact get silence...because someone forgot to type "return". <img src="https://www.ubbcentral.com/boards/images/graemlins/shocked.gif" alt="" />

#128564 05/03/2006 6:35 PM
Joined: Jun 2006
Posts: 23
M
stranger
stranger
M Offline
Joined: Jun 2006
Posts: 23
I am not PHP programmer, but in Perl if you don't have return it will return the value of the variable that happens to be on the last line of the subroutine.


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
spam issues
by ECNet - 03/19/2024 11:45 PM
Who's Online Now
0 members (), 686 guests, and 131 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)