Advertisement:

Author Topic: [Tip/Trick]Add Buddy Button On Post  (Read 37004 times)

Offline NeoXII

  • Semi-Newbie
  • *
  • Posts: 52
[Tip/Trick]Add Buddy Button On Post
« on: March 13, 2011, 08:44:44 PM »
Hello  :),
How can I add Buddy fuction on post as attachment?

Thank You very much!

« Last Edit: August 07, 2011, 12:08:58 PM by Kays »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,041
    • Arantor on GitHub
Re: Add Buddy Button On Post
« Reply #1 on: March 13, 2011, 08:46:07 PM »
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...
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline NeoXII

  • Semi-Newbie
  • *
  • Posts: 52
Re: Add Buddy Button On Post
« Reply #2 on: March 13, 2011, 09:24:11 PM »
Yes...
Version of SMF 2.0RC4
Theme is from DzinerStudio but Displaytemplate.php is original SMF.

Thank you!

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: Add Buddy Button On Post
« Reply #3 on: August 04, 2011, 10:53:02 PM »
Do you still need help with this NeoXII?

Offline NeoXII

  • Semi-Newbie
  • *
  • Posts: 52
Re: Add Buddy Button On Post
« Reply #4 on: August 05, 2011, 08:33:07 PM »
Yes ahrasis,
thank you!

 :)

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: Add Buddy Button On Post
« Reply #5 on: August 06, 2011, 11:03:01 PM »
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:
Code: [Select]
// 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:
Code: [Select]
// 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:
Code: [Select]
?>And change that to:
Code: [Select]
$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:
Code: [Select]
// 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:
Code: [Select]
// 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!
« Last Edit: September 07, 2011, 09:57:03 AM by ahrasis »

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: Add Buddy Button On Post
« Reply #6 on: August 06, 2011, 11:46:36 PM »
I think that this:

Code: [Select]
;u=', $context['id_member'],

should be:

Code: [Select]
;u=', $message['member']['id'],

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

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: Add Buddy Button On Post
« Reply #7 on: August 07, 2011, 12:33:52 AM »
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?

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: Add Buddy Button On Post
« Reply #8 on: August 07, 2011, 08:37:24 AM »
To go back to the post you'll need to include both the topic and message ids for that post into the link.

Code: [Select]
<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

Code: [Select]
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?

Code: [Select]
$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

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: Add Buddy Button On Post
« Reply #9 on: August 07, 2011, 08:47:53 AM »
Thanks for further guidance Kays. I will test them further and update here.

Code: [Select]
[', $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.
« Last Edit: August 07, 2011, 09:03:02 AM by ahrasis »

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: Add Buddy Button On Post
« Reply #10 on: August 07, 2011, 09:05:40 AM »
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

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: Add Buddy Button On Post
« Reply #11 on: August 07, 2011, 10:20:38 AM »
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.

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: Add Buddy Button On Post
« Reply #12 on: August 07, 2011, 10:42:39 AM »
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
« Last Edit: August 21, 2011, 06:18:56 PM by ahrasis »

Offline Kays

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,973
  • Gender: Male
    • Kayssplace
Re: Add Buddy Button On Post
« Reply #13 on: August 07, 2011, 12:06:48 PM »
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:

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

to:

Code: [Select]
// 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

Offline NeoXII

  • Semi-Newbie
  • *
  • Posts: 52
Re: [Tip/Trick]Add Buddy Button On Post
« Reply #14 on: August 08, 2011, 03:23:01 AM »
 :o

Wow! ahrasis! Kays!
Thank you very much!

 :)


Offline Realinfo

  • Full Member
  • ***
  • Posts: 626
    • Real Info
Re: [Tip/Trick]Add Buddy Button On Post
« Reply #15 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..............

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: [Tip/Trick]Add Buddy Button On Post
« Reply #16 on: August 28, 2012, 11:56:07 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

Offline Realinfo

  • Full Member
  • ***
  • Posts: 626
    • Real Info
Re: [Tip/Trick]Add Buddy Button On Post
« Reply #17 on: August 31, 2012, 10:08:02 AM »
Ok........... So reply #5 has everything for that i need to make change............. Thanks............ I will try and tell

Offline tommoty

  • Semi-Newbie
  • *
  • Posts: 29
    • Siam E-cig Club
Re: [Tip/Trick]Add Buddy Button On Post
« Reply #18 on: September 09, 2012, 07:41:59 AM »
 ;)

Offline ahrasis

  • SMF Hero
  • ******
  • Posts: 4,921
  • Gender: Male
  • Busy mode is on.
    • ahrasis on GitHub
    • ahrasis on LinkedIn
    • ElkArte Malaysia
Re: [Tip/Trick]Add Buddy Button On Post
« Reply #19 on: September 28, 2012, 02:26:49 AM »
So, Realinfo, how was it? Is it working as it should be?