vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [How-To] Use API for Private Messages (https://vborg.vbsupport.ru/showthread.php?t=120186)

harmor19 07-02-2006 10:00 PM

[How-To] Use API for Private Messages
 
Have you ever wanted to create a hack that'll private message users when they reach a certain point in the script?
For instance say you wanted to private message user "abc" when he or she reaches the end of the form.

The first thing you'll need to do is require "includes/class_dm.php" along with "global.php".

I have put the Private Message API into a function. I decided to do this in my own script due to the repetiveness.

PHP Code:

function pm_api($fromuserid$fromusername$title$message$recipients)
{
    global 
$vbulletin$botpermissions;
    
    
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);
        
$pmdm->set('fromuserid'$fromuserid);
        
$pmdm->set('fromusername'$fromusername);
        
$pmdm->set('title'$title);
        
$pmdm->set('message'$message);
        
$pmdm->set_recipients($recipients$botpermissions);
        
$pmdm->set('dateline'TIMENOW); 
        
$pmdm->save();
        unset(
$pmdm);
        
        return 
$pmdm;
    


Now that you have the function you'll need to create a method to use with it.
Let's say you owned a auction type forum and wanted to private message an user after they've entered their product's information into the form.

PHP Code:

$fromuserid 1;
        
$fromusername "Auctioneer";
        
$title "Your Entry is Being Reviewed";
        
$message "Hello ".$vbulletin->userinfo['username'].",
                      We are now reviewing your entry."
;
         
$recipients $vbulletin->userinfo['username'];

pm_api($fromuserid$fromusername$title$message$recipients); 

To put it all together
PHP Code:

<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT''test'); 

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
'./includes/class_dm.php');

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude str_replace('clientscript'$vbulletin->options['bburl'] . '/clientscript'$headinclude);

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

//create a function for the Private Message API.
function pm_api($fromuserid$fromusername$title$message$recipients)
{
    global 
$vbulletin$botpermissions;
    
    
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);
        
$pmdm->set('fromuserid'$fromuserid);
        
$pmdm->set('fromusername'$fromusername);
        
$pmdm->set('title'$title);
        
$pmdm->set('message'$message);
        
$pmdm->set_recipients($recipients$botpermissions);
        
$pmdm->set('dateline'TIMENOW); 
        
$pmdm->save();
        unset(
$pmdm);
        
        return 
$pmdm;
    
}

$fromuserid 1;
        
$fromusername "Auctioneer";
        
$title "Your Entry is Being Reviewed";
        
$message "Hello ".$vbulletin->userinfo['username'].",
                      We are now reviewing your entry."
;
         
$recipients $vbulletin->userinfo['username'];

pm_api($fromuserid$fromusername$title$message$recipients);

?>


akanevsky 07-03-2006 01:12 AM

I believe this article was already posted.

harmor19 07-03-2006 02:30 AM

I searched for "private message api" and only my thread came up.

Code Monkey 07-03-2006 03:41 AM

<a href="https://vborg.vbsupport.ru/showthread.php?t=82786" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=82786</a>

From over a year ago. It is listed in the summary of How To's that is stickied in this forum.

harmor19 07-03-2006 07:32 AM

Well that sucks, well I explain another approach to do it.

pyro.699 07-03-2006 12:42 PM

No, thankyou!
I dont know how, but you solved my Pm Counters not updating problem! When no-one else wanted to answer it!

Thanks a ton!
~Cody Woolaver

harmor19 07-03-2006 12:46 PM

Quote:

Originally Posted by pyro.699
No, thankyou!
I dont know how, but you solved my Pm Counters not updating problem! When no-one else wanted to answer it!

Thanks a ton!
~Cody Woolaver

You're Welcome.

Honestly I don't know where it would update the counters. Perhaps the 'save()' function?

I'm glad you found my tutorial useful.

pyro.699 07-03-2006 12:53 PM

nope, i had a save ^^; its actchually still puzzling, because all you had wa puting it in a function, and adding return and unset.... which shouldent have made any differance! but, whats with the global at the top? i never had that...
(my guess is that its because it is in a function)

Code Monkey 07-03-2006 01:34 PM

No need to return a value.

PHP Code:

unset($pmdm);
        
return 
$pmdm


harmor19 07-03-2006 01:59 PM

Quote:

Originally Posted by pyro.699
nope, i had a save ^^; its actchually still puzzling, because all you had wa puting it in a function, and adding return and unset.... which shouldent have made any differance! but, whats with the global at the top? i never had that...
(my guess is that its because it is in a function)

The reason I globalize "$vbulletin" and "$botpermissions" is to carry the value of those two variables into the function (I think that's how to explain it).
If I haven't have globalized those two the API would be rendered useless.



Quote:

Originally Posted by JumpD
No need to return a value.

PHP Code:

unset($pmdm);
        
return 
$pmdm


I can remove those two tidbits?
It's been a while but I think I tried to use the function without returning the value and it didn't work. I could be wrong though.


All times are GMT. The time now is 01:33 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01355 seconds
  • Memory Usage 1,771KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete