Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Send PMs (automatically)
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 06-09-2005, 10:00 PM

If you want to (automatically) send a PM to a user, you can use the Class vB_Datamanager_PM.
This class makes sure that all values are correct, handles quota for the recipients, notification eMails, etc.

Example

PHP Code:
// create the DM to do error checking and insert the new PM
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);
$pmdm->set('fromuserid'1234);
$pmdm->set('fromusername''Welcome-Bot');
$pmdm->set('title''Welcom to our Forums');
$pmdm->set('message'"Hello\nI am a Bot and would like to give you a warm welcome :)");
$pmdm->set_recipients('newuser'$botpermissions);
$pmdm->set('dateline'TIMENOW); 
If anything goes wrong you can check for errors using
PHP Code:
$pmdm->errors 
This is an erray containing the errors.

If everything is OK
PHP Code:
$pmdm->save(); 
This will send a PM to user newuser telling him
Quote:
Hello.
I am a Bot and would like to give you a warm welcome
The message will appear to be coming from User Welcom-Bot (Userid 1234).

$botpermissions must be the permissions for the sending user, but can just be empty.
If you want to send PMs no matter if the PM box of the recipient is full or not:

PHP Code:
$botpermissions['adminpermissions'] = 2
If you want, you can set other options as well ($pmdm->set_info(...)):
  • forward = 1/0 if this is a forwarded PM, Default=0
  • savecopy = 1/0 to keep a copy if the PM in outbox, Default=0
  • receipt = 1/0 to request a read-receipt, Default=0
  • parentpmid = ID of the PM you are responding to (if applicable)

Furthermore you can specify ($pmdm->set(...)):
  • iconid = ID of the message icon the PM should carry, Default=0
  • showsignature = 0/1 Whether the signature should be shown or not, Default=0
  • showsmilie = 0/1 Wheter smilies should be parsed or not, Default=1

For multiple receipients just use user1;user2;useer3.

This How-To is (C) 2005 by KirbyDE and you are not allowed to redistribute it in any way without my explicit consent.
Reply With Quote
  #2  
Old 06-10-2005, 04:37 AM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is a FANTASTIC tutorial - people can make up a zillion hacks based on this How-To.
Reply With Quote
  #3  
Old 06-10-2005, 05:56 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

KirbyDE, That is great! I just love this.

Finaly the old vB.org is BACK!
Reply With Quote
  #4  
Old 06-11-2005, 02:09 AM
Bad Bunny's Avatar
Bad Bunny Bad Bunny is offline
 
Join Date: Apr 2002
Posts: 555
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow! Lots of good stuff here. I'm so excited about this new release. Thank you so much for the tutorial, as it really does teach you something useful. Thanks!
Reply With Quote
  #5  
Old 06-12-2005, 05:05 AM
VBCoder VBCoder is offline
 
Join Date: Jun 2005
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Kirby,

Is there anyway we can get this info for the other classes?
Reply With Quote
  #6  
Old 06-13-2005, 06:17 AM
eXtremeTim eXtremeTim is offline
 
Join Date: Jun 2002
Location: eXtremewebtech.com
Posts: 1,201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by VBCoder
Kirby,

Is there anyway we can get this info for the other classes?
If I have time tommorrow I will post up one for the new reply class. Since I had a good deal of time working with it today. I now have my talkerbot hack fully using the new reply datamanager.
Reply With Quote
  #7  
Old 06-14-2005, 05:52 PM
M1th's Avatar
M1th M1th is offline
 
Join Date: Jul 2002
Location: UK
Posts: 224
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

To send PMs to more than 1 user:


Retrieving usernames:

To get a list of usernames from an array and output in the form of user1;user2;user3:

PHP Code:
    $user_names $db->query_read("
            SELECT username
            FROM " 
TABLE_PREFIX "user
            WHERE usergroupid = xx
            ORDER BY username ASC
        "
); 
replacing xx with usergroupid
PHP Code:
        $pmto_users = array();
        while (
$name $db->fetch_array($user_names))
        {
            
$pmto_users[] = $name['username'];
        }
        
$db->free_result($user_names); 
To output the $pmto_users array into the format user1;user2;user3 you do:
PHP Code:
$pmtousernames implode(';'$pmto_users); 
Finally, sending the pm -repeat all the steps mentioned by KirbyDE but replace
PHP Code:
$pmdm->set_recipients('newuser'$botpermissions); 
with:

PHP Code:
$pmdm->set_recipients($pmtousernames$botpermissions); 
[$pmtousernames would output to something like user1;user2;user3;etc]
Reply With Quote
  #8  
Old 06-27-2005, 05:41 AM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The PM data manager seems to completely kill the page when I use this function. It just does a white page and no PM is sent.
PHP Code:
function ushop_send_pm($title$text$user$from=0) {
    global 
$vbulletin;
    
    
// require the class
    
require_once(DIR '/includes/class_dm_pm.php');

    
// Who's the PM from?
    
if ($from == OR $from['userid'] == $vbulletin->userinfo['userid']) {
        
$from $vbulletin->userinfo;
    } elseif (
$from == "default") {
        
$from fetch_userinfo($vbulletin->options['ushop_pmfrom']);
    } else {
        
$from fetch_userinfo($from['userid']);
    }
    
    
// Who are we sending this PM to?
    
if (isset($user[0]['userid'])) {
        
// Sending to multiple.
        
foreach ($user as $omguser) {
            
$toarray[] = $omguser['username'];
        }
        
$to implode(";"$toarray);
    } else {
        
// Sending to one.
        
$to $user['username'];
    }
    
    
// create the DM to do error checking and insert the new PM
    
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);
    
$pmdm->set('fromuserid'$from['userid']);
    
$pmdm->set('fromusername'$from['username']);
    
$pmdm->set('title'$title);
    
$pmdm->set('message'$text);
    
$pmdm->set_recipients($to$from['permissions']);
    
$pmdm->set('dateline'TIMENOW);

    
// If no errors, save.
    
if ($pmdm->errors) {
        return 
$pmdm->errors;
    }
    
$pmdm->save();

I have since went back to using my old function which got the job done. I'll probably try fixing the version of the function that uses the data manager, but for now...
Reply With Quote
  #9  
Old 06-27-2005, 10:17 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Link14716
PHP Code:
// require the class
require_once(DIR '/includes/class_dm_pm.php'); 
Remove this line and it'll work
Reply With Quote
  #10  
Old 06-27-2005, 05:45 PM
flup's Avatar
flup flup is offline
 
Join Date: Jan 2002
Location: Maastricht, NL
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
$pmdm->set_recipients('newuser', $botpermissions);
What should that line be if it has to be send to the administrator with userid 1 (or just all administrators).
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:21 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.05064 seconds
  • Memory Usage 2,333KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (11)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (3)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete