Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles

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
  #82  
Old 06-19-2007, 10:57 PM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Any new/novel solutions to the problem of PMs not updating in their count #? I dont want to do the digitalcrowd method of manually incrementing the # in teh database because it seems to sometimes update correctly and not other times.

Is there a way to tell vb to reasses the PM count using a built in function?
Reply With Quote
  #83  
Old 06-20-2007, 05:21 PM
Adib Adib is offline
 
Join Date: Oct 2004
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by jwocky View Post
Any new/novel solutions to the problem of PMs not updating in their count #? I dont want to do the digitalcrowd method of manually incrementing the # in teh database because it seems to sometimes update correctly and not other times.

Is there a way to tell vb to reasses the PM count using a built in function?
Yes, I'd like to know this as well. Doesn't vb have a built in function to do this? I'm very hesitant of making a database call to vb's database if I don't have to.
Reply With Quote
  #84  
Old 06-28-2007, 02:45 AM
nuk3 nuk3 is offline
 
Join Date: Jan 2005
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adib View Post
Yes, I'd like to know this as well. Doesn't vb have a built in function to do this? I'm very hesitant of making a database call to vb's database if I don't have to.

In private.php:

Code:
// ###################### Start pm update counters #######################
// update the pm counters for $vbulletin->userinfo
function build_pm_counters()
{
	global $vbulletin;

	$pmcount = $vbulletin->db->query_first("
		SELECT
			COUNT(pmid) AS pmtotal,
			SUM(IF(messageread = 0 AND folderid >= 0, 1, 0)) AS pmunread
		FROM " . TABLE_PREFIX . "pm AS pm
		WHERE pm.userid = " . $vbulletin->userinfo['userid'] . "
	");

	$pmcount['pmtotal'] = intval($pmcount['pmtotal']);
	$pmcount['pmunread'] = intval($pmcount['pmunread']);

	if ($vbulletin->userinfo['pmtotal'] != $pmcount['pmtotal'] OR $vbulletin->userinfo['pmunread'] != $pmcount['pmunread'])
	{
		// init user data manager
		$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
		$userdata->set_existing($vbulletin->userinfo);
		$userdata->set('pmtotal', $pmcount['pmtotal']);
		$userdata->set('pmunread', $pmcount['pmunread']);
		$userdata->save();
	}
}

Give that a whirl.
Reply With Quote
  #85  
Old 09-01-2007, 08:15 PM
workplaybiz workplaybiz is offline
 
Join Date: Jan 2006
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How Can I Send A Private Message To Users As Soon As They Make Their 10th Post?
Reply With Quote
  #86  
Old 02-07-2008, 08:58 PM
rwoscott rwoscott is offline
 
Join Date: Jan 2007
Location: Melbourne
Posts: 142
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Punky Guy View Post
Is there a way I can call this from a link or button? Some hook I could use?
I'd like to know how to do this as well.

Anyone got any help on this?
Reply With Quote
  #87  
Old 02-26-2008, 09:27 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

FYI, there seems to be a new function within the PM datamanager in version 3.7.0, which is needed for sending automatic PMs (such as in the welcome pm)

$pmdm->set_info('is_automated', true);
Reply With Quote
  #88  
Old 03-08-2008, 07:09 PM
xxclixxx xxclixxx is offline
 
Join Date: Mar 2008
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am receiving an error that the user has PMs disabled, when the user doesn't. Any ideas? I'm attempting to send a PM to the main administrator account.

Code:
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY); 
$pmdm->set_info('savecopy', 1); 
$pmdm->set('fromuserid', $userid); 
$pmdm->set('fromusername', $username); 
$pmdm->set('title', 'this is a title'); 
$pmdm->set('message', 'this is a message'); 
$pmdm->set_recipients('xxclixxx', $permissions); 
$pmdm->set('dateline', TIMENOW); 

$pmdm->pre_save(); 

// process errors if there are any 
$errors = $pmdm->errors;
($userid and $username are properly filled during the test. It works if I send to the test account, but not to the admin account.)
Reply With Quote
  #89  
Old 03-14-2008, 12:00 PM
xxclixxx xxclixxx is offline
 
Join Date: Mar 2008
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I found mferguson's modification fixed the problem I was having:

PHP Code:
$pmdm->set_info('receipt'false);
$pmdm->set_info('savecopy'false);
$pmdm->overridequota true
I think it was the overridequota that did it.
Reply With Quote
  #90  
Old 03-28-2008, 06:46 PM
Axor Axor is offline
 
Join Date: Oct 2006
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

how does it works to send html in the private message?
i want to send a javascript to open a popup window with a picture.

the pm will be sent automatically

thx 4 help
Reply With Quote
  #91  
Old 07-15-2008, 08:15 PM
Jase2 Jase2 is offline
 
Join Date: Dec 2007
Location: USA
Posts: 1,575
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Andreas,

The following bit:

PHP Code:
$pmdm->set('message'"Hello\nI am a Bot and would like to give you a warm welcome :)"); 
How would I go about changing this to a phrase, so that users can have the message however they like. Is it possible?

Thanks.

-- Jason
Reply With Quote
Reply

Thread Tools

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 06:27 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.05032 seconds
  • Memory Usage 2,308KB
  • 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
  • (6)bbcode_php
  • (4)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
  • (3)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