vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Limiting Maximum Friends (https://vborg.vbsupport.ru/showthread.php?t=183364)

Jenosavel 06-24-2008 01:59 AM

Limiting Maximum Friends
 
My vbulletin forum is going to be integrated along with a web game that has graphics intensive friends options. Because of this I need to be able to lower the maximum allowed friends a user can have. However, I can't seem to find any way to set this through the admin control panel, nor can I find any variables in the php code which control this.

I know in version 3.6.7 you could search for the "> 1000" bit of code and adjust the limit through that. However 3.7.1, what I'm working with now, doesn't seem to have that anymore.

Does anyone know if there's even a limit on the number of friends a user can have in 3.7.1? And if there is, how would one go about adjusting it?

Jenosavel 06-25-2008 05:25 PM

Well, seeing as no one's responded, I'm going to assume no one knew a quick way to go about creating a friends cap. I ended up creating one, though it's not pretty and requires editing the profile.php file.


To start with, anywhere at the top of profile.php where the global variables are being declared, add one of your own to use as your maximum cap. Obviously set it to whatever you want your cap to be.
PHP Code:

$friendlimit 1000

After that there are three sections of code we'll need to edit in various places: Request addlist, Post addlist, and Post updatelist. They each get used at different times, it seems, so there is quite a bit of code repetition.

$_REQUEST['do'] == 'addlist'
Near the top, just before
PHP Code:

if ($vbulletin->GPC['userlist'] == 'buddy' OR $vbulletin->GPC['userlist'] == 'friend'

you'll need to add in
PHP Code:

$numresult $db->query_read("
    SELECT COUNT(*) AS friendcount FROM " 
TABLE_PREFIX "userlist AS userlist 
    WHERE userlist.userid = " 
$vbulletin->userinfo['userid'] . 
    AND friend = 'yes'
"
);
$numarray $db->fetch_array($numresult);
$myfriendcount $numarray["friendcount"];
global 
$friendlimit



Then a little further down, just inside of this if statement
PHP Code:

if ($vbulletin->GPC['userlist'] == 'friend'

you need to add
PHP Code:

if ($myfriendcount >= $friendlimit)
    eval(
print_standard_redirect("You cannot have more than $friendlimit friends."falsetrue));
else 




$_POST['do'] == 'doaddlist'
This code is almost identical to the previous section, and so are the pieces we're going to add.

At the beginning, just after this referrer check
PHP Code:

if ($vbulletin->url == $vbulletin->options['forumhome'] . '.php')
{
    
$vbulletin->url 'member.php?' $vbulletin->session->vars['sessionurl'] . "u=$userinfo[userid]";


Add in the same query from above
PHP Code:

$numresult $db->query_read("
    SELECT COUNT(*) AS friendcount FROM " 
TABLE_PREFIX "userlist AS userlist 
    WHERE userlist.userid = " 
$vbulletin->userinfo['userid'] . 
    AND friend = 'yes'
"
);
$numarray $db->fetch_array($numresult);
$myfriendcount $numarray["friendcount"];
global 
$friendlimit



Then inside the 'friend' part of the case statement
PHP Code:

switch ($vbulletin->GPC['userlist'])
{
    case 
'friend'

Add the count check again.
PHP Code:

if ($myfriendcount >= $friendlimit)
    eval(
print_standard_redirect("You cannot have more than $friendlimit friends."falsetrue)); 




$_POST['do'] == 'updatelist'
This one is a bit different than the previous two and requires more edits.

Pretty much right at the 'profile_updatelist_start' hook, add the query again:
PHP Code:

$numresult $db->query_read("
    SELECT COUNT(*) AS friendcount FROM " 
TABLE_PREFIX "userlist AS userlist 
    WHERE userlist.userid = " 
$vbulletin->userinfo['userid'] . 
    AND friend = 'yes'
"
);
$numarray $db->fetch_array($numresult);
$myfriendcount $numarray["friendcount"];
global 
$friendlimit



Then, after the last AND of this if statement, but before the closing parenthesis
PHP Code:

if
(
    
$vbulletin->GPC_exists['makefriends']
    AND 
$vbulletin->options['socnet'] & $vbulletin->bf_misc_socnet['enable_friends']
    AND 
$vbulletin->userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends']
    AND 
$userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends']


Add the line
PHP Code:

AND $myfriendcount $friendlimit 



Now, right before this if statement
PHP Code:

if
(
    !(
$vbulletin->options['socnet'] & $vbulletin->bf_misc_socnet['enable_friends'])
    OR !(
$vbulletin->userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends'])
    OR !(
$userinfo['permissions']['genericpermissions2'] & $vbulletin->bf_ugp_genericpermissions2['canusefriends'])
    OR 
$vbulletin->userinfo['userid'] == $userinfo['userid']
)
{
    continue;


Add the following
PHP Code:

if ($myfriendcount >= $friendlimit)
    break;
else 




Lastly, find the line
PHP Code:

if ($vbulletin->GPC['incomingaction'] == 'accept'

And replace it with
PHP Code:

if ($vbulletin->GPC['incomingaction'] == 'accept' && ($myfriendcount $friendlimit)) 




That seems to be catching all paths to friend adding and filtering it appropriately.


All times are GMT. The time now is 03:10 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.01093 seconds
  • Memory Usage 1,765KB
  • 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
  • (16)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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