vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Quickly Add or Remove Users from Buddy List (https://vborg.vbsupport.ru/showthread.php?t=176803)

noonespecial 04-21-2008 07:59 PM

Quickly Add or Remove Users from Buddy List
 
I'm looking to quickly add a user into the buddylist array - or then remove it from that array with a different command.

So if user A wants to add user B to their buddylist, it runs a quick check, then alters that column (usertextfield.buddylist).

If they want to remove the buddy - it removes the ID from usertextfield.buddylist.

What's the SQL for this? Do I have to first grab all the data from buddylist, and then add the value, and then put it back in? Is there a easier way?

Lynne 04-21-2008 08:49 PM

Are you thinking of writing this as a Mod because there already is one: Buddy & Ignore List Add/Remove in Postbit I'm sure you can download that and see what the query is.

noonespecial 04-21-2008 08:55 PM

That just provides a link to send someone to the profile.php page to add buddies. That page for adding buddies is absolutely annoying.

MoT3rror 04-21-2008 09:03 PM

This is how I add friends through php.
PHP Code:

$db->query_write("
                REPLACE INTO " 
TABLE_PREFIX "userlist
                    (userid, relationid, type, friend)
                VALUES
                    (
$userid2$userid, 'buddy', 'yes'),
                    (
$userid$userid2, 'buddy', 'yes')
            "
);

$db->query_write("
                UPDATE " 
TABLE_PREFIX "user
                SET friendcount = friendcount + 1
                WHERE userid IN (
$userid2, " $userid ")
            "
);

            
$db->query_write("
                UPDATE " 
TABLE_PREFIX "user
                SET friendreqcount = IF(friendreqcount > 0, friendreqcount - 1, 0)
                WHERE userid = " 
$userid
            
);

require_once(
DIR '/includes/functions_databuild.php');
build_userlist($userid);
build_userlist($userid2); 


noonespecial 04-21-2008 09:41 PM

Quote:

Originally Posted by MoT3rror (Post 1496139)
This is how I add friends through php.
PHP Code:

$db->query_write("
                REPLACE INTO " 
TABLE_PREFIX "userlist
                    (userid, relationid, type, friend)
                VALUES
                    (
$userid2$userid, 'buddy', 'yes'),
                    (
$userid$userid2, 'buddy', 'yes')
            "
);

$db->query_write("
                UPDATE " 
TABLE_PREFIX "user
                SET friendcount = friendcount + 1
                WHERE userid IN (
$userid2, " $userid ")
            "
);

            
$db->query_write("
                UPDATE " 
TABLE_PREFIX "user
                SET friendreqcount = IF(friendreqcount > 0, friendreqcount - 1, 0)
                WHERE userid = " 
$userid
            
);

require_once(
DIR '/includes/functions_databuild.php');
build_userlist($userid);
build_userlist($userid2); 


So using a different table than VB's default?

Interesting.

MoT3rror 04-21-2008 09:47 PM

It is code for vBulletin 3.7. Probably different then 3.6 or 3.5.

noonespecial 04-21-2008 10:01 PM

Yep, it is. :-/

That's too bad - that's easier to manipulate and get at the data. 3.6 is different.

--------------- Added [DATE]1208820707[/DATE] at [TIME]1208820707[/TIME] ---------------

I ended up just doing it kinda like this:

PHP Code:

require_once('./global.php');
require_once(
DIR '/includes/functions_user.php');

$userid $vbulletin->input->clean_gpc('r''u'TYPE_UINT); 
$buddylist=explode(' 'trim($vbulletin->userinfo['buddylist']));

if (!
in_array($userid$buddylist))
{
$db->query_write("update usertextfield 
SET buddylist = '"
.$vbulletin->userinfo['buddylist'].$userid'
WHERE userid="
.$vbulletin->userinfo['userid']."
"
);
}
else
{
echo 
"Already your friend ++++head.";


--------------- Added [DATE]1208821038[/DATE] at [TIME]1208821038[/TIME] ---------------

If anyone has a better/more efficient way -- I'd love to hear it.

Thanks!


All times are GMT. The time now is 12:53 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.01193 seconds
  • Memory Usage 1,751KB
  • 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
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete