News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[Tip/Trick]Add Buddy Button On Post

Started by NeoXII, March 13, 2011, 08:44:44 PM

Previous topic - Next topic

NeoXII

Hello  :),
How can I add Buddy fuction on post as attachment?

Thank You very much!


Arantor

You need to provide more information like the version of SMF you're using and the theme you're using if you hope for anyone to take time out to make this for you...

NeoXII

Yes...
Version of SMF 2.0RC4
Theme is from DzinerStudio but Displaytemplate.php is original SMF.

Thank you!

Hj Ahmad Rasyid Hj Ismail

Do you still need help with this NeoXII?

NeoXII


Hj Ahmad Rasyid Hj Ismail

#5
EDITED: This mod is now fully working! Thanks to Kays for helping with this tips and tricks.

Here is the code that you need to change in Display.template.php. Find:
// Show a link to the member's profile.
echo '
', $message['member']['link'], '
</h4>
<ul class="reset smalltext" id="msg_', $message['id'], '_extra_info">';

Change to:
// Show a link to the member's profile.
echo '
', $message['member']['link'], '
</h4>
<ul class="reset smalltext" id="msg_', $message['id'], '_extra_info">';

// Can they add this member as a buddy?
if($context['user']['is_logged'] &&  !$message['member']['is_guest'] && $message['member']['id'] != $context['user']['id'])
                {
echo '
<li class="smalltext">
<span id="userstatus">
<a href="', $scripturl, '?action=buddy;u=', $message['member']['id'], ';topic=', $context['current_topic'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($message['member']['is_buddy'] ? 'remove' : 'add')], ']</a>
</span>
</li>'; }



To make the text appear, you need to open index.english.php, find:

?>

And change that to:

$txt['buddy_add'] = 'Add To Buddy List';
$txt['buddy_remove'] = 'Remove From Buddy List';

?>


You may change the wording to simpler one as IMO it is quite long.

Lastly for stoping it from redirecting to profile upon clicking the add or remove buddy text, you need to modify your Subs-Members.php. Try to find:
// Update the settings.
updateMemberData($user_info['id'], array('buddy_list' => implode(',', $user_info['buddies'])));

// Redirect back to the profile
redirectexit('action=profile;u=' . $_REQUEST['u']);


Change it to:
// Update the settings.
updateMemberData($user_info['id'], array('buddy_list' => implode(',', $user_info['buddies'])));

// Redirect back to the profile
if (isset($_GET['topic']))
redirectexit('topic=' . $_GET['topic'] . ';msg' . $_GET['msg'] . '#msg' . $_GET['msg']);
else
redirectexit('action=profile;u=' . $_REQUEST['u']);


And that is it. I wish you all the best and good luck!

Kays

I think that this:


;u=', $context['id_member'],


should be:


;u=', $message['member']['id'],



If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Hj Ahmad Rasyid Hj Ismail

Thanks Kays. I edited the above. It is now working. But it goes to Profile page. Is there anyway we can make it stay in Display page?

Kays

To go back to the post you'll need to include both the topic and message ids for that post into the link.


<a href="', $scripturl, '?action=buddy;u=', $message['member']['id'], ';topic=', $context['current_topic'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($message['member']['is_buddy'] ? 'remove' : 'add')], ']</a>


Then in the function that adds buddies to your list. At the end there should be a redirectexit to the profile page. Change that to an if/else statement so that if $_GET['topic] is set then redirect back to the topic. If not, redirect to the profile


if (isset($_GET['topic']))
   redirectexit(topic=' . $_GET['topic'] . ';msg' . $_GET['msg'] . '#msg' . $_GET['msg']);
else
  redirectexit('to the profile page'); // Not quite the exact code since I'm not looking at that function. :)


Just out of curiosity. Does this work as it is suppose to?


$txt['buddy_' . ($message['member']['is_buddy'] ? 'remove' : 'add')], ']

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Hj Ahmad Rasyid Hj Ismail

#9
Thanks for further guidance Kays. I will test them further and update here.


[', $txt['buddy_' . ($message['member']['is_buddy'] ? 'remove' : 'add')], ']

This code works 90%. It shows option to remove if poster is a buddy and to add if poster is not a buddy. 10% problem is that it shows even in the member's own poster info (i.e. option to add own self.). Funny isn't it. For that, I am still testing to make it better.

A shot of this mod.

Kays

Cool, that's nice to know. I was wondering about $message['member']['is_buddy']

For the 10% problem. don't show the link if $message['member']['id'] == $context['user']['id']

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Hj Ahmad Rasyid Hj Ismail

Actually, my main guide is IchBin old Buddy Highlight mod (last update is for SMF 1.1.3). Should one wishes to highlight buddy post in a thread, then partly, this mod is still a useful guideline as $message['member']['is_buddy'] which is working in 1.x branch is also working in 2.0 Gold. I can't, however, get this mod to fully work on Message Index yet nor can I create a different mod based on it and other mods yet.  :(

I'll test your solutions to the last 10% problem and update here later.

Hj Ahmad Rasyid Hj Ismail

#12
Great news. The 10% problem is solved as per Kays' advice and the mod is now better too.

The only thing left is to make sure it won't get to profile page when the add or remove buddy button is clicked upon. I still haven't successfully figure it out how to solve this part yet. It is not a problem but will make this mod a better one. Fell free to contribute guys.  ;D

The is done and is fully working! Please refer to the above updated post for the fully working mod.

Please do move this to tips and tricks too.  :D

Kays

Great, glad you got it all figured out. :)

A suggestion though. My fault partly since my logic was incorrect. ::)

Also added several checks since it might show for guests and if guests can post,they can't be your buddy.. :)

Change:


// Can they add this member as a buddy?
if($message['member']['id'] == $context['user']['id']) { }
else {


to:


// Can they add this member as a buddy?
if($context['user']['is_logged'] &&  !$message['member']['is_guest'] && $message['member']['id'] != $context['user']['id'])
                {
echo '


Moving this to Tips and Tricks

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

NeoXII

 :o

Wow! ahrasis! Kays!
Thank you very much!

:)


Realinfo

I want to add this on my forum........... But in many posts it's described............. Please make it in one posts all the changes those need to make to add this function..............

Hj Ahmad Rasyid Hj Ismail

Quote from: Realinfo on August 27, 2012, 10:25:50 PM
I want to add this on my forum........... But in many posts it's described............. Please make it in one posts all the changes those need to make to add this function..............

It is all in reply #5 above: http://www.simplemachines.org/community/index.php?topic=426109.msg3129052#msg3129052

Realinfo

Ok........... So reply #5 has everything for that i need to make change............. Thanks............ I will try and tell


Hj Ahmad Rasyid Hj Ismail

So, Realinfo, how was it? Is it working as it should be?

Advertisement: