vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Send PMs (automatically) (https://vborg.vbsupport.ru/showthread.php?t=82786)

Andreas 06-09-2005 09:00 PM

Send PMs (automatically)
 
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.

Erwin 06-10-2005 03:37 AM

This is a FANTASTIC tutorial - people can make up a zillion hacks based on this How-To. :)

Logikos 06-10-2005 04:56 AM

KirbyDE, That is great! I just love this.

Finaly the old vB.org is BACK!

Bad Bunny 06-11-2005 01:09 AM

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!

VBCoder 06-12-2005 04:05 AM

Kirby,

Is there anyway we can get this info for the other classes?

eXtremeTim 06-13-2005 05:17 AM

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.

M1th 06-14-2005 04:52 PM

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]

Link14716 06-27-2005 04:41 AM

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...

Andreas 06-27-2005 09:17 AM

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 :)

flup 06-27-2005 04:45 PM

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).

Link14716 06-27-2005 05:38 PM

Quote:

Originally Posted by KirbyDE
Remove this line and it'll work :)

I probably would have figured that out if it told me instead of blank paging me. :p

Andreas 06-27-2005 05:41 PM

Suggest @ Jelsoft to call die('Class vB_Datamanager not defined') instead of just exit; :)

Chris M 06-27-2005 09:20 PM

Or just die ;)

Satan

Andreas 06-27-2005 09:26 PM

Hmm, die() without parameters does not produce any output as well, or am I wrong?

Chris M 06-28-2005 06:04 AM

No - I meant that you could suggest to Jelsoft that they could just die:p

They haven't fixed the Beta 3 issue yet :cry:

Satan

dwh 06-29-2005 09:12 PM

I don't understand how to use this? Is this a class built into 3.5? Is this code you would place in one of the files in the include directory? Or you create a new php page with functions?

Would it be possible to explain this hack in detail as if you were speaking to a very dumb person :ninja:

Andreas 06-29-2005 09:22 PM

This is not a Hack, it's Howto ;)
Class vB_Datamanager_PM is a Class that comes with vB 3.5, yes.
You can use code like this wherever you want in your vB Projects/Hacks.

dwh 06-29-2005 10:02 PM

Quote:

Originally Posted by KirbyDE
This is not a Hack, it's Howto ;)

Haha, thanks for answering the dumbo :)

Quote:

Class vB_Datamanager_PM is a Class that comes with vB 3.5, yes.
Whew. I was scared this was an add-on.


Quote:

You can use code like this wherever you want in your vB Projects/Hacks.
OK, but you need a semicolon here $pmdm->errors
right? Another dummy question, how do you get the array out of there? The "->" is throwing me off.

Andreas 06-29-2005 10:06 PM

For objects (that's an instantiated Class) you must always use ->.

$pmdm->errors was not meant to be used as a single Code-Line, it should just show which property you have to access (for example in an if) to check for errors.

dwh 06-29-2005 10:14 PM

I hate OOP :)
I guess I'll have to get used to it unfortunately.

babolo 07-05-2005 11:57 PM

Does anyone know How I can make this able to send this to new users once they register?

Alan @ CIT 09-23-2005 09:15 PM

Thanks Kirby, another very useful How-to

orban 10-07-2005 10:50 PM

How to parse URLs and email adresses in the pm text?

There must be some parameter :D

-orban

Andreas 10-07-2005 10:55 PM

No. If it contains [email] and [url] codes those will be parsed, if it does not they will (obviously) not be parsed :)

orban 10-08-2005 08:16 AM

Ooooooh!

Because I'm working on my Report to PM (without email notification in any case) plugin...

So I have to change the email template phrase I guess.

Jon@Refresh 10-25-2005 11:49 PM

does anyone know how I can pass an additional variable to $pmdm?

I want to pass a single extra 1 or 0 and I then want to detect this in the $pmdm class and act accordingly.

I know I'll have to modify the code in the $pmdm class, but I can't work out how to pass the extra boolean, and then detect it in the class.

If anyone has any ideas, I'd be very grateful :)

dwh 11-07-2005 09:03 PM

What is "touserarray" used for? It seems redundant. I can remove the data from touserarray in pmtext and it still works fine.

Antivirus 01-08-2006 05:25 AM

trying to use the PM data manager within a plugin at hook location profile_doremovelist. When the script at profile.php runs, everything works out fine, but no PM is sent. I'm stumped :ermm:

here's my code...
PHP Code:

the code i had here had errors... i didn't want to confuse anyone, so i removed it ;) 


Antivirus 01-09-2006 04:08 PM

I finally figured it out by process of elimination, my results are here if anyone wants to check out the code I used.

Thanks for this howto Andreas, i couldn't have figured this out without this thread. :)

DigitalCrowd 01-09-2006 08:18 PM

Is anybody aware why when you send a pm from a given user to another user through the use of the sendpm code in this thread and found elsewhere, that no email is sent nor does it show a pop-up that you have a PM waiting.

This is kinda worthless in that sense. I have seen others with the same issue, but no work around.

As a follow-up, it did email, but not notification online when sending a regular PM does do that.

Antivirus 01-11-2006 04:40 PM

Quote:

Originally Posted by DigitalCrowd
Is anybody aware why when you send a pm from a given user to another user through the use of the sendpm code in this thread and found elsewhere, that no email is sent nor does it show a pop-up that you have a PM waiting.

I don't have that problem, there has to be a setting in your AdminCP or UserCP that is preventing the PM alert popup for you. For me, everything works just fine, as the PM datamanager has no control over whether or not the email is sent or the popup is shown, those are settings in the AdminCP, UserCP, or vBoptions.

DigitalCrowd 01-11-2006 04:53 PM

Actually, it goes deeper than a pop-up. Even on the "Private Messages" for you under your username in the upper-right hand side of the default templates, it will show "0" even though I will have a new 1. EVEN if someone sends me a PM, it will show 1, when two are really available.

It's as though it thinks I have read it... but I haven't. It does show up as bold though likes its new , the PM area.

Antivirus 01-11-2006 04:58 PM

I'm at a loss, I am not experiencing any of those behaviors on the hack I wrote to send automatic PMs which i learned from reading this HOWTO. All the stuff in the top right, everywhere seems to work as it should on my installations of vb. Maybe it has to do with the location where you're inserting the datamanager code?

JaeTea 01-14-2006 03:44 PM

OK I'm a little confused with PMing multiple users.

Suppose I have two textfields, user1 and user2.

All I want to do is combine those two values into the format user1;user2 and input that into the "$pmdm->set_recipients" line so I can send the PM to the two users specified.

Developer 01-14-2006 04:46 PM

i am working on a new hack "Auto PM in members birthday"
i will use it as a cron jop but i have a proplem in recipient i can't make it sends the message to any member

CrazyShooter 01-23-2006 09:30 PM

I am confussed, how do i make it so that a new user will get a private message automaticly sent by me saying Welcome?

bulbasnore 02-01-2006 05:48 PM

I'm interested in some hints, or pointers to other tutorials, on how I might use this to PM a user when a mod delete's their message. I'd like to include the reason they list in the delete reason blank.

noonespecial 05-21-2006 05:23 PM

This would be great to use as a "poke" sort of feature like facebook.com has, I'm not sure exactly how to do that at all - but it would be awesome to try ...

Logikos 05-22-2006 02:18 AM

What is the "poke" feature? Never heard of it.

Alan @ CIT 05-22-2006 04:45 AM

Quote:

Originally Posted by bulbasnore
I'm interested in some hints, or pointers to other tutorials, on how I might use this to PM a user when a mod delete's their message. I'd like to include the reason they list in the delete reason blank.

Take a look at the code for my "Moderation Auto-PM" hack - this should get you started with sending PM's when a post is deleted.

Thanks,
Alan.


All times are GMT. The time now is 02:04 AM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02348 seconds
  • Memory Usage 1,861KB
  • 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
  • (1)bbcode_code_printable
  • (12)bbcode_php_printable
  • (9)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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