Thread: Integration with vBulletin - vbulletin-xml-rpc-server for instant Desktop Notification
View Single Post
  #52  
Old 10-22-2008, 04:30 PM
ZomgStuff ZomgStuff is offline
 
Join Date: Feb 2007
Posts: 469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've got it figured out, for those who don't use prefix's for their tables here are the two changes
forum.php
PHP Code:
<?php
/**
 * forum.php
 * 
 * This file contains user relevant functions. 
 * 
 * @author  Sword^Fish <swordfish@nsuers.com>
 * @version 1
 * @since   Release 1
 * @package vbulletin-xml-rpc-server
 * 
*/
require_once("server.php");

/**
 * returns detail of latest thread
 *
 * @global Database $GLOBALS['DB']  database connection object
 * @param  string   $args[0] token
 * @return array
 * @todo   check usergroup permission
*/

function forum_latest_thread($method_name$args$app_data)
{
    
    
$obj_token = new Token($args[0]);
    
/* check: token is assigned to an user */
    
if($obj_token->userid == null)
    {        
        return array(
'faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_TOKEN_INVALID']['code'],
                     
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_TOKEN_INVALID']['string']);    
        
    } 
    
/* check: token is alive (not expired) */
    
if($obj_token->is_alive == 0)
    {        
        return array(
'faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_TOKEN_EXPIRED']['code'],
                     
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_TOKEN_EXPIRED']['string']);        
    }     
    
    
/* we shall use this token, so increase  usages counter */        
    
$obj_token->update_count($obj_token->token);
                
    
/* prepare query string */            
    
$query="SELECT 
                f.forumid AS forum_id, f.title AS forum_name,
                t.threadid AS topic_id, t.title AS topic_title,
                p.postid AS post_id, p.dateline AS post_time,
                u.userid AS user_id, u.username
            FROM thread t, forum f, post p, user u 
            WHERE   t.threadid = p.threadid
                AND f.forumid  = t.forumid
                AND p.postid   = t.lastpostid 
                AND p.userid   = u.userid                 
            ORDER BY t.lastpostid DESC LIMIT 1"
;
                
    
/* run query string */
    
$rows $GLOBALS['DB']->run($query);

    if(
$rows)
    {
        return 
$rows[0];
    }    
    return array(
'faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_FAIL']['code'],
                 
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_FAIL']['string']);    
}
?>
user.php
PHP Code:
<?php
/**
 * user.php
 * 
 * This file contains user relevant functions.
 * 
 * @author  Sword^Fish <swordfish@nsuers.com>
 * @version 1
 * @since   Release 1
 * @package vbulletin-xml-rpc-server
*/

require_once("server.php");

/**
 * authenticates a user and returns user id
 * Check for valid username and password.
 * Username must be associated with a registered account in vBulletin database.
 * User account must be verified one. 
 *
 * @global Database $GLOBALS['DB']  database connection object
 * @param  string $args[0] username
 * @param  string $args[1] password
 * @return mixed  returns int userid or array on login failure
 * @todo   check for verified account
 * @todo   check for banned account
*/

function user_login($method_name$args$app_data)
{    
    
    
//checkpost: valid username
    
if(_is_valid_username($args[0]) == false)
    {
        return array(
'faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['USER_SERVICE_USERNAME_DNE']['code'],
                     
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['USER_SERVICE_USERNAME_DNE']['string']);                
    }
    
/* TODO: checkpost: email verified */
    
    /* TODO: checkpost: userid is not in banned group */
    
    /* checkpost: valid password */
    
$GLOBALS['DB']->set_entity("user"," ");    
    
$resource $GLOBALS['DB']->fetch(array("userid"), 
                                         
$filter = array("username LIKE '{$args[0]}'",
                                                      
" AND ",
                                                      
"password LIKE MD5(CONCAT(MD5('" $args[1] . "'), salt))"),
                                      
null,
                                      
0,
                                      
1);    

    if(
$resource/* valid query returned valid user id */
    
{
        
        
/* create token */
        
$token $GLOBALS['OBJ_TOKEN']->create($resource[0]['userid']);     
        if(
$token/* return token string */
        
{            
            return (string)
$token;
        } else {
            return array(
'faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_TOKEN_GENERATION']['code'],
                         
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_TOKEN_GENERATION']['string']);
        }
                
    } elseif(
$resource === false) { /* query error */
        
return array('faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_FAIL']['code'],
                     
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['SERVICE_FAIL']['string']);        
        
    }
    
/* login is invalid */    
    
return array('faultCode'   => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['USER_SERVICE_LOGIN']['code'],
                 
'faultString' => $GLOBALS['VBULLETIN_XML_RPC_ERROR_DB']['USER_SERVICE_LOGIN']['string']);        
}

/**
 * verifies userid existence
 *
 * @global Database $GLOBALS['DB']  database connection object
 * @param  int      $userid         userid
 * @return boolean 
*/
function _is_valid_username($username)
{
    
$GLOBALS['DB']->set_entity("user"," ");
    return 
$GLOBALS['DB']->check_record($username'username');
}

?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01114 seconds
  • Memory Usage 1,856KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete