View Single Post
  #1  
Old 05-17-2011, 07:52 AM
Eliasen Eliasen is offline
 
Join Date: Feb 2011
Location: Denmark
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to send a PM from outside vbulletin

-Solved-
EDIT 30/07-2011: Sorry everyone! I completely forgot to show how I solved this issue, so here it is!

I cannot remember where I found this, and I take no credit for this code.

First you need a php file called "pm-script.php" (or whatever you feel like).
Then past this code into this newly created file:
PHP Code:
<?php
function vbulletin_send_pm(
    
$site$sender_username$sender_password
    
$recipient$title ''$message ''$iconid '0'
){
    
$cookiefile tempnam("/tmp""cookies"); 
    
/* create a temporary file to store cookies.
   this should work on most systems and is more
   flexible than specifying path explicitly */
 
    
$ch curl_init();
    
//General options
    //curl_setopt($ch, CURLOPT_HEADER, true); //For debugging
    //Masquerade as Firefox
    
curl_setopt($chCURLOPT_USERAGENT'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
    
curl_setopt($chCURLOPT_RETURNTRANSFER1); 
    
curl_setopt($chCURLOPT_FOLLOWLOCATION1); //Follow redirects
    
curl_setopt($chCURLOPT_COOKIEFILE$cookiefile);
    
curl_setopt($chCURLOPT_COOKIEJAR$cookiefile);
    
//PHP >= 5.1.0
    
curl_setopt($chCURLOPT_AUTOREFERERtrue);
 
    
/** *************************************************
             Log In
    ****************************************************/
 
    
curl_setopt($chCURLOPT_URL$site.'login.php?do=login');
    
curl_setopt($chCURLOPT_POSTtrue); 
    
curl_setopt($chCURLOPT_REFERER$site.'index.php'); 
 
    
/* The fields of the login form.*/
    
$postfields = array(
        
'vb_login_username'    => $sender_username,
        
'vb_login_password' => ''//Interestingly enough, this doesn't need to be set.
        //'cookieuser' => '1', //"Remember me"
        
's' => '',
        
'securitytoken' => 'guest',
        
'do' => 'login',
        
'vb_login_md5password' => md5($sender_password), //hash the password
        
'vb_login_md5password_utf' => md5($sender_password), //UTF? Looks the same to me.
     
);
 
    
$postfields http_build_query($postfields'''&'); //PHP >= 5.1.2
    
curl_setopt($chCURLOPT_POSTFIELDS$postfields); 
 
    
$result curl_exec ($ch);
    
//There will be a redirection link if the login was successful
    
if (preg_match('/index.php\?s=(\w{32})/'$result$matches)){
        
$s_key $matches[1]; //not used 
    
} else {
        return 
false;
    }
 
    
/** *************************************************
         Retrieve the PM page to get the security token 
    ****************************************************/
    
curl_setopt($chCURLOPT_URL$site.'private.php?do=newpm');
    
curl_setopt($chCURLOPT_POSTfalse);
    
$html curl_exec($ch);
    if (
preg_match('/<input\s+type="hidden"\s+name="securitytoken"\s+value="([\w\-]+)"\s*\/?>/i'$html$matches)){
        
$security_token $matches[1];
    } else {
        return 
false;
    }
 
    
/** *************************************************
             Send the PM
    ****************************************************/
    
curl_setopt($chCURLOPT_URL$site.'private.php?do=insertpm');
    
curl_setopt($chCURLOPT_POSTtrue);
    
//curl_setopt($ch, CURLOPT_REFERER, $site.'private.php?do=newpm');
 
    /* PM form fields */
    
$postfields = array(
        
'recipients' => $recipient,
        
'bccrecipients' => '',
        
'title' => $title,
        
'message' => $message,
        
'wysiwyg' => '0',
        
'iconid' => $iconid,
        
's' => ''//might need to use $s_key here
        
'securitytoken' => $security_token,
        
'do' => 'insertpm',
        
'pmid' => '',
        
'forward' => '',
        
'button' => 'Submit Message',
        
'savecopy' => '0'//save the message in "Sent" folder
        
'parseurl' => '1'//automatically parse URLs in the message
     
);
 
    
$postfields http_build_query($postfields'''&');
    
curl_setopt($chCURLOPT_POSTFIELDS$postfields);
 
    
$result curl_exec ($ch);
    
//Note : I don't verify if the message was actually sent.  
    //If everything went well so far it probably was.
 
    /** ****************************************************
       Done. Close connections and kill the cookie-file.
    ********************************************************/
    
curl_close ($ch); 
    
unlink($cookiefile);
    return 
true;
}
?>
To send a PM from a non-VB page, include this php file in your non-VB page, and use the following function to send a pm:

PHP Code:
vbulletin_send_pm("http://url-to-your-forum.com/forum/""from-username""user-password""Recipient-user-ID""PM Title!""PM Content"); 
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01235 seconds
  • Memory Usage 1,840KB
  • 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