News:

Wondering if this will always be free?  See why free is better.

Main Menu

Buddies Block

Started by Mr. Pedram, June 06, 2013, 09:54:41 AM

Previous topic - Next topic

margarett

Yeah, I don't know the mod's code (and I'm on the mobile now) but the content is probably loaded in profile context, so it will have nothing to display.
You probably need to reproduce the Sources code also...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 23, 2014, 04:50:25 PM
Yeah, I don't know the mod's code (and I'm on the mobile now) but the content is probably loaded in profile context, so it will have nothing to display.
You probably need to reproduce the Sources code also...

Found this in profile.php:

   // Buddies Source!

foreach($context['member']['buddies'] as $buddy)
    {
   loadMemberData($buddy);
   loadMemberContext($buddy);
    }
   $context['can_bb_view'] = allowedTo('bb_view_any') && !$context['user']['is_owner'] || (allowedTo('bb_view_own') && $context['user']['is_owner']);
   
    //End Buddy Source!


Also found this in ManageSettings:
// Enable Buddies Block?
array('check', 'bb_enable'),
array('check', 'bb_icon'),
array('int', 'bb_number'),
array('check', 'cbhbi'),
array('check', 'cbhmi'),
array('check', 'enable_default_avatar'),
array('text', 'default_male_avatar_url'),
array('text', 'default_female_avatar_url'),
array('text', 'default_avatar_url', 'subtext' => $txt['default_avatar_path']),
array('check', 'default_avatar_opacity'),
);


This looked promising in ManagePermissions:
$permissionList = array(
'membergroup' => array(
'smfgallery_view' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_add' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_edit' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_delete' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_comment' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_report' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_autoapprove' => array(false, 'smfgallery', 'smfgallery'),
'smfgallery_manage' => array(false, 'smfgallery', 'smfgallery'),
'view_stats' => array(false, 'general', 'view_basic_info'),
'view_mlist' => array(false, 'general', 'view_basic_info'),
'who_view' => array(false, 'general', 'view_basic_info'),
'search_posts' => array(false, 'general', 'view_basic_info'),
'karma_edit' => array(false, 'general', 'moderate_general'),
'pm_read' => array(false, 'pm', 'use_pm_system'),
'sp_admin' => array(false, 'sp', 'sp'),
'sp_manage_settings' => array(false, 'sp', 'sp'),
'sp_manage_blocks' => array(false, 'sp', 'sp'),
'sp_manage_articles' => array(false, 'sp', 'sp'),
'sp_manage_pages' => array(false, 'sp', 'sp'),
'sp_manage_shoutbox' => array(false, 'sp', 'sp'),
'sp_add_article' => array(false, 'sp', 'sp'),
'sp_auto_article_approval' => array(false, 'sp', 'sp'),
'sp_remove_article' => array(false, 'sp', 'sp'),
'pm_send' => array(false, 'pm', 'use_pm_system'),
'calendar_view' => array(false, 'calendar', 'view_basic_info'),
'calendar_post' => array(false, 'calendar', 'post_calendar'),
'calendar_edit' => array(true, 'calendar', 'post_calendar', 'moderate_general'),
'admin_forum' => array(false, 'maintenance', 'administrate'),
'manage_boards' => array(false, 'maintenance', 'administrate'),
'manage_attachments' => array(false, 'maintenance', 'administrate'),
'manage_smileys' => array(false, 'maintenance', 'administrate'),
'edit_news' => array(false, 'maintenance', 'administrate'),
'access_mod_center' => array(false, 'maintenance', 'moderate_general'),
'moderate_forum' => array(false, 'member_admin', 'moderate_general'),
'manage_membergroups' => array(false, 'member_admin', 'administrate'),
'manage_permissions' => array(false, 'member_admin', 'administrate'),
'manage_bans' => array(false, 'member_admin', 'administrate'),
'send_mail' => array(false, 'member_admin', 'administrate'),
'issue_warning' => array(false, 'member_admin', 'moderate_general'),
'profile_view' => array(true, 'profile', 'view_basic_info', 'view_basic_info'),
'profile_identity' => array(true, 'profile', 'edit_profile', 'moderate_general'),
'profile_extra' => array(true, 'profile', 'edit_profile', 'moderate_general'),
'profile_title' => array(true, 'profile', 'edit_profile', 'moderate_general'),
'profile_remove' => array(true, 'profile', 'delete_account', 'moderate_general'),
'profile_server_avatar' => array(false, 'profile', 'use_avatar'),
'profile_upload_avatar' => array(false, 'profile', 'use_avatar'),
'profile_remote_avatar' => array(false, 'profile', 'use_avatar'),'bb_view' => array(true, 'profile', 'view_basic_info', 'view_basic_info'),


I think that's about all that I could see that would pertain to this issue in the Sources.

margarett

Nop, just the Profile.php part. The rest is for permissions (that are loaded everywhere IIRC) and for the admin settings. But even the profile code misses something. The part of getting each user's buddies.

I would need to check that on the computer. Anyway that seems quite a heavy code to run... If you have, say, 100 friends, you'll run 100 loadMemberData and 100 loadMemberContext. Ouch! :o
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Indeed, that's a killer. I would instead suggest:

$loaded = loadMemberData($context['member']['buddies']);
foreach($loaded as $buddy)
    {
   loadMemberContext($buddy);
    }


instead of:
foreach($context['member']['buddies'] as $buddy)
    {
   loadMemberData($buddy);
   loadMemberContext($buddy);
    }


Not only does this reduce the database query count considerably from 2-3 per user to 2-3 flat (and possibly, depending on what you're trying to do, you could even get that down to 1), it even protects you against loading member data for a member that doesn't exist, e.g. deleted account that wasn't purged from buddies properly.

samborabora

Quote from: ‽ on July 23, 2014, 05:40:01 PM
Indeed, that's a killer. I would instead suggest:

$loaded = loadMemberData($context['member']['buddies']);
foreach($loaded as $buddy)
    {
   loadMemberContext($buddy);
    }


instead of:
foreach($context['member']['buddies'] as $buddy)
    {
   loadMemberData($buddy);
   loadMemberContext($buddy);
    }


Not only does this reduce the database query count considerably from 2-3 per user to 2-3 flat (and possibly, depending on what you're trying to do, you could even get that down to 1), it even protects you against loading member data for a member that doesn't exist, e.g. deleted account that wasn't purged from buddies properly.

Nice, I'll try switching this out with your replacement to see how things improve, maybe the mod author could take a look too if it severely reduces load.

What is buddy block doing exactly that would be preventing this from displaying on the front page? Isn't it just accessing info taht you can see on your own buddies list anyways? This is the hard part, finding which aprt of the chain is preventing it from displaying in an SP block (which I beleive is exactly the same as showing it on Board Index, in this case)

margarett

You are right. But the code in Profile.php doesn't run out of the Profile area. That's why the content is empty in BoardIndex (or in your SP block)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 23, 2014, 06:06:42 PM
You are right. But the code in Profile.php doesn't run out of the Profile area. That's why the content is empty in BoardIndex (or in your SP block)

What controls where it does run? Can it be copied into another template so it runs in there?

margarett

Yup. In your case it should probably go into your SP block

What controls where it runs is SMF's core. That's why you have so many Sources and so many templates. So that you run only what needs to be ran.
This mod was intended to show its content in the Profile area. So there would be no reason for that computation to be "wasted" in places where the content isn't needed ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on July 23, 2014, 06:37:03 PM
Yup. In your case it should probably go into your SP block

What controls where it runs is SMF's core. That's why you have so many Sources and so many templates. So that you run only what needs to be ran.
This mod was intended to show its content in the Profile area. So there would be no reason for that computation to be "wasted" in places where the content isn't needed ;)

Right, I placed it above, like so:
   // Buddies Source!

foreach($context['member']['buddies'] as $buddy)
    {
   loadMemberData($buddy);
   loadMemberContext($buddy);
    }
   $context['can_bb_view'] = allowedTo('bb_view_any') && !$context['user']['is_owner'] || (allowedTo('bb_view_own') && $context['user']['is_owner']);
   
    //End Buddy Source!

// Start Buddies Block!

if (!empty($modSettings['bb_enable']) && $context['can_bb_view'])
   {
     echo'
<div class="cat_bar">
<h3 class="catbg">
<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/online.gif" alt="" class="icon" />
', $txt['buddies'], ' <span>(', count($context['member']['buddies']), ')</span></span></h3></div>
<div class="windowbg">
<span class="topslice"><span></span></span>
<div class="buddy_block">';

   // Show Buddies!

     global $memberContext;
if (empty($modSettings['bb_number']))
          $modSettings['bb_number'] = 20;
          $i=0;
foreach($context['member']['buddies'] as $buddy)
   {
if (++$i > $modSettings['bb_number'])
break;
          $buddy = $memberContext[$buddy];
     echo '
<a title="', $buddy['name'], '" href="', $scripturl, '?action=profile;u=', $buddy['id'], '">
<div id="basicavatar" class="buddy_avatar">', $buddy['avatar']['image'], '</div></a>';
   }

   // If don't have buddy!
if (empty($buddy) && (!$context['user']['is_owner']))
     echo '
<span class="buddy">', $context['member']['name'], '', $txt['empty_bb'], '</span>';

if (empty($buddy) && ($context['user']['is_owner']))
     echo'
<span class="buddy">', $txt['empty_bb_owner'], '<a href="', $scripturl, '?action=profile;area=lists;u=', $context['id_member'], '">', $txt['empty_bb_owner_link'], '</a></span>';

   // End Buddies Block!


But it still no worky, and it isn't giving any sort of errors or anything so it's difficult to tell what it doesn't like about this?

margarett

Because context -> member -> buddies isn't probably loaded. I'm pretty sure you are missing a database query somewhere before that. Again, I'd need to check the code :(
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Well, $context['member'] is the member whose profile you're looking at. If you're elsewhere, e.g. boardindex, you're not looking at someone's profile, so $context['member'] doesn't exist. Whose buddies should you be considering displaying then?

samborabora

Quote from: ‽ on July 23, 2014, 06:46:45 PM
Well, $context['member'] is the member whose profile you're looking at. If you're elsewhere, e.g. boardindex, you're not looking at someone's profile, so $context['member'] doesn't exist. Whose buddies should you be considering displaying then?

On the block I plan on only displaying my own, the current user's buddies.

Arantor

In which case you want $user_info['buddies'] and you will want to rewrite some of the other code where it tries to compare it to the current user.

ittiphol

how to show on index page  ???

gaurav09

Quote from: gaurav09 on July 22, 2014, 09:52:48 PM
i installed : http://www.simplemachines.org/community/index.php?topic=505334.0
and it is awesome mod but a problem in it :(
in profile buddies images are showing so big that it's coming in full page..And big images are not resizing itself into small.
Moreover buddies block is coming in between description of a user.
=========================
http://i.imgur.com/ogV4i7u.jpg
http://i.imgur.com/8V85WwR.jpg
=============================
i am using 2.0.8 smf version.

please fix the error.
please help me also   :'( :'(

Mr. Pedram

Quote from: gaurav09 on July 24, 2014, 04:17:49 AM
Quote from: gaurav09 on July 22, 2014, 09:52:48 PM
i installed : http://www.simplemachines.org/community/index.php?topic=505334.0
and it is awesome mod but a problem in it :(
in profile buddies images are showing so big that it's coming in full page..And big images are not resizing itself into small.
Moreover buddies block is coming in between description of a user.
=========================
http://i.imgur.com/ogV4i7u.jpg
http://i.imgur.com/8V85WwR.jpg
=============================
i am using 2.0.8 smf version.

please fix the error.
please help me also   :'( :'(

It's css issue probably, check index.css, make sure about mod's css:


.buddy_block
{
overflow: auto;
padding-left: 15px;
}
.buddy
{
font-family: Tahoma;
font-size: 11px;
font-weight: bold;
text-align: center;
}
.buddy_avatar {
display: inline-block;
float: left;
margin-right: 4px;
margin-bottom: 4px;
    width: 35px;
    height: 35px;
    border: 1px solid white;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    background:url(../../../avatars/noavatar.png);
}
.buddy_avatar img {
    width: 35px;
    height: auto;
    position: relative;
}
#basicavatar img.avatar
{
    display: block;
    margin: 0px 0 0 0;
}
My Modifications:
» Loading For SMF
» Buddies Block
» Redirect Links
» Birthdate On Registration
» PM Warning
» Instagram
» Add Table,Td,Tr Button
» Search Topic & Board Button
Browse All...

gaurav09

Quote from: Mr. Pedram on July 25, 2014, 04:57:01 AM
Quote from: gaurav09 on July 24, 2014, 04:17:49 AM
Quote from: gaurav09 on July 22, 2014, 09:52:48 PM
i installed : http://www.simplemachines.org/community/index.php?topic=505334.0
and it is awesome mod but a problem in it :(
in profile buddies images are showing so big that it's coming in full page..And big images are not resizing itself into small.
Moreover buddies block is coming in between description of a user.
=========================
http://i.imgur.com/ogV4i7u.jpg
http://i.imgur.com/8V85WwR.jpg
=============================
i am using 2.0.8 smf version.

please fix the error.
please help me also   :'( :'(

It's css issue probably, check index.css, make sure about mod's css:


.buddy_block
{
overflow: auto;
padding-left: 15px;
}
.buddy
{
font-family: Tahoma;
font-size: 11px;
font-weight: bold;
text-align: center;
}
.buddy_avatar {
display: inline-block;
float: left;
margin-right: 4px;
margin-bottom: 4px;
    width: 35px;
    height: 35px;
    border: 1px solid white;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    background:url(../../../avatars/noavatar.png);
}
.buddy_avatar img {
    width: 35px;
    height: auto;
    position: relative;
}
#basicavatar img.avatar
{
    display: block;
    margin: 0px 0 0 0;
}

No it has same code,..i previously desabled this mod,..but when i enable it,..it become corrected it self  ::) ::)
But it's location, that means block is showing between member details..
http://i.imgur.com/ogV4i7u.jpg

please fix it !!

samborabora

Quote from: ‽ on July 23, 2014, 07:08:54 PM
In which case you want $user_info['buddies'] and you will want to rewrite some of the other code where it tries to compare it to the current user.

Okay, I've replaced the occurrences, no idea where to start rewriting next, which parts does it try to compare?

samborabora

Just realized, I was thinking this buddies block showed you only your currently online buddies, rather than all buddies avatrs, both online and offline. Can it be easily adjusted to only include those of currently online buddies?

samborabora

This doesn't relate to Buddies Block, but if anyone wants to know how to doe exactly what I wanted:

<?php

global $smcFunc$sourcedir$scripturl$modSettings;

require_once(
$sourcedir '/Subs-MembersOnline.php');

$options = array(
'show_hidden' => allowedTo('moderate_forum'),
'sort' => 'log_time',
'reverse_sort' => true,
);
$return getMembersOnlineStats($options);

if (empty(
$return['users_online']))
return;

$buddies = array();
foreach (
$return['users_online'] as $user)
{
if ($user['is_buddy'])
$buddies[$user['id']] = $user['href'];
}

if (empty(
$buddies))
return;

$request $smcFunc['db_query']('''
SELECT
m.id_member, m.avatar, a.id_attach,
a.attachment_type, a.filename
FROM {db_prefix}members AS m
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
WHERE m.id_member = {array_int:members}'
,
array(
'members' => array_keys($buddies),
)
);
$avatars = array();
while (
$row $smcFunc['db_fetch_assoc']($request))
$avatars[$row['id_member']] = $row['avatar'] == '' ? ($row['id_attach'] > ? (empty($row['attachment_type']) ? $scripturl '?action=dlattach;attach=' $row['id_attach'] . ';type=avatar' $modSettings['custom_avatar_url'] . '/' $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' $row['avatar']);
$smcFunc['db_free_result']($request);

foreach (
$buddies as $id => $href)
echo '<a href="'$href'"><img src="'$avatars[$id], '" alt="" style="width: 30px; height: 30px;" /></a>';


Thanks to the SP forums for this ;)

Advertisement: