Closed (fixed)
Project:
Buddylist
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Oct 2006 at 01:56 UTC
Updated:
23 May 2007 at 23:33 UTC
I posted this in the post installation forum (http://drupal.org/node/90424), however this is probably a more appropriate location. I'm trying to add the functionality of automatically adding a buddy into the buddylist for every new user registration. I'm assuming that adding the following code, or something like it, to a user registration function, would do the trick.
db_query('INSERT INTO {buddylist} (received, uid, buddy, timestamp) VALUES (1, %d, %d, %d)' , $user->uid , '1', time());
Question 1: is this the correct line, syntax and all, for this functionality?
Question 2: what function, or where, can I add this to achieve this functionality?
Any help is greatly appreciated.
-Jesse
Comments
Comment #1
rkn-dupe commentedHave you seen this:
http://drupal.org/node/75884
Comment #2
apt94jesse commentedThanks for the response, I had seen that, but that seems to be more of a "how they want it done" rather than "how it can be done."
I got my functionality to work like this. I added these lines in the page.tpl.php:
As you can see, I query the buddylist table, count the entries where the current user has buddies. If that count is 0, then it executes the insert query adding the default buddy. This way, whenever a new user logs in for the first time, their buddy count is of course 0, so it adds the buddy into the table.
Comment #3
vm commentedThanks for the snippet.
scenario. user logs in , snippet sees no buddies, snippets adds default buddy. user deletes default buddy. logs out, logs back in, default buddy added again ?
Comment #4
apt94jesse commentedGood point. Honestly I'm not worried about it because for my site I don't really want users to be able to delete the admin. Your scenario forgot to say that "user deletes default buddy and has no other buddies." Feel free to come up with a better function to add this sql code to, mine was chosen as the first one to work, not the best one.
Thanks for the interest, though, I hope someone wiser than me comes up with a better solution.
Comment #5
apt94jesse commentedIn case anyone is interested, I fixed the above scenario by adding these two lines to the user.module. This actually executes two queries, one is adding a default buddy, the other is sending an opening private message from said buddy.
The first query adds the buddy. Just change the '1' near the end to change the default buddy. I used 1 because I want the admin to be the default.
The second query sends the pm. Change the MESSAGE SUBJECT and MESSAGE CONTENT sections to suit your needs.
And now for placement. This is works in 4.7.4. You need to open your user.module file and navigate to the user_save function.
Find the following lines of code:
The commented line should start at line 212.
Then just insert the two queries directly after those lines.
Mine looks as follows:
As I just implemented this, there may be some bugs. I have determined that the user_save function is used both to update information and to save a new user. I tested to see if the queries were executed when a user updates their account info, and they don't appear to.
Should anyone know of a better way to do this, let me know, or tell me what I'm doing wrong.
-Jesse
Comment #6
fagoplease do it properly and provide a patch for it.
you can react on user-creation by using hook_user()
Comment #7
apt94jesse commentedI'm honestly not quite sure how to do that. If someone with more knowledge than me would like to do so, go right ahead. I'm just happy that a solution exists.
Comment #8
rkn-dupe commentedsubscribe
Comment #9
kbahey commentedFago
I wrote a contrib module for 5.x that adds a predefined user to the buddy list for new users.
I can commit it to the contrib directory directly. Are you Ok with that?
Comment #10
robertdouglass commentedKhalid, please feel free to give buddylist any loving treatment that you feel it needs. It is not getting much attention from me at the moment, so your help is very welcome.
Comment #11
kbahey commentedThere is now a module called buddylistautoadd under the contrib directory that does this.
Comment #12
droople commentedPlease supply the download link
thank you
Comment #13
kbahey commentedThere is no download link needed.
It is included already in the download of buddylist.
Comment #14
(not verified) commented