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
  #42  
Old 07-26-2006, 03:00 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does anyone know if there's a setting which can be used within ($pmdm->set(...)) for whether or not to parse html? In other words, if the text sent in the PM is allowed to use html?
Reply With Quote
  #43  
Old 09-30-2006, 01:05 PM
fly fly is offline
 
Join Date: Oct 2003
Posts: 1,215
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Was something changed on 3.6? This code no longer works:

PHP Code:
    // create the DM to do error checking and insert the new PM 
        
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_SILENT); 
        
$pmdm->set('fromuserid'$fromuser['userid']); 
        
$pmdm->set('fromusername'$fromuser['username']); 
        
$pmdm->set_info('receipt'false); 
        
$pmdm->set_info('savecopy'false); 
        
$pmdm->set('title'"Important information regarding your registration!"); 
        
$pmdm->set('message'"[center][b]AUTOGENERATED PM[/b][/center] "); 
        
$pmdm->set_recipients($userinfo['username'], $fromuser['permissions']); 
        
$pmdm->set('dateline'TIMENOW); 
        
$pmdm->save(); 
I haven't changed any of the code from 3.5 since the upgrade, so something in there no longer works. Any idea what it is?

Okay, I got it working, but there is no popup for the user about a PM. Any ideas?
Reply With Quote
  #44  
Old 09-30-2006, 08:18 PM
Cebby Cebby is offline
 
Join Date: Aug 2005
Location: Pittsburgh, PA
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This seems like a good place to ask

I'm creating a link in a vB powered page (template) for a user to send a PM to me on a specific subject (just like you can do with EM very easily). I want it to open the PM, address it, and fill in the title of the PM, then wait for the user to enter their message.

Can this be done in 3.6.1?
Reply With Quote
  #45  
Old 10-06-2006, 11:23 PM
DigitalCrowd's Avatar
DigitalCrowd DigitalCrowd is offline
 
Join Date: Nov 2001
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have to do this to get private messages to update correctly in most cases. In a few specific cases, I don't have too. But, don't remember off the top my head which one.

Code:
$db->query_write("UPDATE vb_user SET pmunread=pmunread+1,pmtotal=pmtotal+1 WHERE userid=$userid");
That will do the trick everytime.
Reply With Quote
  #46  
Old 11-01-2006, 04:01 AM
HPIA HPIA is offline
 
Join Date: Jul 2006
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where does this go exactly XD?
Reply With Quote
  #47  
Old 11-08-2006, 03:13 PM
CyberRanger's Avatar
CyberRanger CyberRanger is offline
 
Join Date: Mar 2004
Posts: 1,319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas
If you want to send PMs no matter if the PM box of the recipient is full or not:

PHP Code:
$botpermissions['adminpermissions'] = 2
Thx for the wonderful tutorial. I've used your guide to develop an add-on to one of my products.

The only item that I can't get working is overriding the mailbox full restriction. I've used the code above but setting adminpermissions to 2 doesn't seem to work. In class_dm_pm.php, $overridequota = false seems to need to be set to "true" but I can't figure out how to do that.

If you have a few minutes, I'd really appreciate help in figuring out how to set the variables so that the user will receive the PM even if his mailbox is full and he receives PMs only from buddies and sender is not on the list and not board staff.

I'm pretty sure that can be achieved by setting $overridequota = true, just can't figure out how to do that.

In class_dm_pm.php, line 80:

PHP Code:
var $overridequota false
while starting at line 370:
PHP Code:
        // run through recipients to check if we can insert the message
        
foreach ($users AS $lowname => $user)
        {
            if (!(
$user['options'] & $this->registry->bf_misc_useroptions['receivepm']) AND !$this->overridequota)
            {
                
// recipient has private messaging disabled
                
$this->error('pmrecipturnedoff'$user['username']);
                return 
false;
            }
            else if ((
$user['options'] & $this->registry->bf_misc_useroptions['receivepmbuddies']) AND strpos($user[buddylist] "$fromuser[userid] ") === false AND !can_moderate() AND !$this->overridequota)
            {
                
// recipient receives PMs only from buddies and sender is not on the list and not board staff
                
$this->error('pmrecipturnedoff'$user['username']);
                return 
false;
            }
            else
            { 
But I don't see anyway to set $overridequota without hacking class_dm_pm.php.

Thx!
Reply With Quote
  #48  
Old 11-09-2006, 03:31 PM
Acido Acido is offline
 
Join Date: Apr 2003
Location: Argentina
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What's the trick to Automatically parse links in text ?
Reply With Quote
  #49  
Old 11-11-2006, 08:20 PM
mrpaint's Avatar
mrpaint mrpaint is offline
 
Join Date: Sep 2004
Location: Hanoi Capital
Posts: 630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Acido
What's the trick to Automatically parse links in text ?
Just use BBCode such as [url]
[code]text

My problem is: it isn't count my auto-PM into PM's quota. I found this in the previous page but it is too.... (no word to say!)

Quote:
I have to do this to get private messages to update correctly in most cases. In a few specific cases, I don't have too. But, don't remember off the top my head which one.

Code:
$db->query_write("UPDATE vb_user SET pmunread=pmunread+1,pmtotal=pmtotal+1 WHERE userid=$userid");
That will do the trick everytime.
Any new ideas?
Reply With Quote
  #50  
Old 11-20-2006, 04:15 PM
mferguson's Avatar
mferguson mferguson is offline
 
Join Date: Jan 2003
Location: Colorado
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by CyberRanger View Post

The only item that I can't get working is overriding the mailbox full restriction. I've used the code above but setting adminpermissions to 2 doesn't seem to work. In class_dm_pm.php, $overridequota = false seems to need to be set to "true" but I can't figure out how to do that.
I had the same issue. What I found by searching through all the vB code is a couple of places where overridequota was referenced. All that is required to set this to send the PM even if the recipient's mailbox is full is to:

PHP Code:
$pmdm->overridequota true
Here is how my code looks with this:
PHP Code:
$pmdm =& datamanager_init('PM'$vbulletinERRTYPE_ARRAY);         

$pmdm->set('fromuserid'$vbulletin->userinfo['userid']);
$pmdm->set('fromusername'$vbulletin->userinfo['username']);
$pmdm->set_info('receipt'false);
$pmdm->set_info('savecopy'false);
$pmdm->overridequota true;                   // Force pm send even if recipient's mailbox is full
$pmdm->set('title'$title);
$pmdm->set('message'$message);
$pmdm->set('dateline'TIMENOW);
$pmdm->set('allowsmilie'true);            

$pmtousernames implode(';'$pmto_users);
$pmdm->set_recipients($pmtousernames$botpermissions);
$pmdm->save(); 
Hope this helps everyone that was running into similar problems.

Mark

When testing my auto send pm's code I kept seeing users that had pmpopup (popup-based pm notification) not being updated when I sent my auto pm.

If a user has pmpopup notification on this column should show as "1" in the user table. If they receive a new message and haven't read it yet it should show as "2" in the user table. The two denotes that there is an unread popup.

In the case where I was sending a message to multiple recipients I noticed that only the last of the recipients that also had pmpopup notification was having the pmpopup column updated to "2" while other's weren't.

In debuggint this problem I found that in the forums/includes/class_dm_pm.php file that line 557:

PHP Code:
$popupusers = array(); 
is reinitializing the array and therefore causes any previous userids that have pmpopup enabled to be lost (since its within a foreach loop processing all the users)

To resolve this I've commented the line out for now and also filed a bug report with vBulletin to get it resolved in a future release. I found this is 3.6.1 and also in 3.6.3.

Hope this helps some others that found problems in getting this mod working as expected.

Mark
Reply With Quote
  #51  
Old 12-14-2006, 06:38 PM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Would i need to change anything to stick this into a cron?
If so what would i change

If i dont need to change anything is it because im using 3.6.0 that its not working?
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 12:56 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.04823 seconds
  • Memory Usage 2,364KB
  • Queries Executed 25 (?)
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
  • (2)bbcode_code
  • (11)bbcode_php
  • (5)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
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (3)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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