Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: NeoXII on March 13, 2011, 08:44:44 PM

Title: [Tip/Trick]Add Buddy Button On Post
Post by: NeoXII on March 13, 2011, 08:44:44 PM
Hello  :),
How can I add Buddy fuction on post as attachment?

Thank You very much!

Title: Re: Add Buddy Button On Post
Post by: Arantor 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...
Title: Re: Add Buddy Button On Post
Post by: NeoXII 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!
Title: Re: Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on August 04, 2011, 10:53:02 PM
Do you still need help with this NeoXII?
Title: Re: Add Buddy Button On Post
Post by: NeoXII on August 05, 2011, 08:33:07 PM
Yes ahrasis,
thank you!

:)
Title: Re: Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail 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:
// 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!
Title: Re: Add Buddy Button On Post
Post by: Kays on August 06, 2011, 11:46:36 PM
I think that this:


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


should be:


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


Title: Re: Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail 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?
Title: Re: Add Buddy Button On Post
Post by: Kays 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.


<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')], ']
Title: Re: Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on August 07, 2011, 08:47:53 AM
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.
(http://www.simplemachines.org/community/index.php?action=dlattach;topic=426109.0;attach=184019;image)
Title: Re: Add Buddy Button On Post
Post by: Kays 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']
Title: Re: Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail 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.
Title: Re: Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail 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 (http://www.simplemachines.org/community/index.php?topic=426109.msg3129052#msg3129052) for the fully working mod.

Please do move this to tips and tricks too.  :D
Title: Re: Add Buddy Button On Post
Post by: Kays 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:


// 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 (http://www.simplemachines.org/community/index.php?board=72.0)
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: NeoXII on August 08, 2011, 03:23:01 AM
 :o

Wow! ahrasis! Kays!
Thank you very much!

:)

Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: 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..............
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on August 28, 2012, 11:56:07 PM
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
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Realinfo 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
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: tommoty on September 09, 2012, 07:41:59 AM
 ;)
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on September 28, 2012, 02:26:49 AM
So, Realinfo, how was it? Is it working as it should be?
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Realinfo on September 28, 2012, 10:15:04 AM
Quote from: ahrasis on September 28, 2012, 02:26:49 AM
So, Realinfo, how was it? Is it working as it should be?

Ya working fine........
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on September 28, 2012, 10:09:06 PM
Good to hear that...
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Dhayzon on June 29, 2013, 12:12:12 PM
working fine........

but does not send the notification
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Draffi on July 06, 2013, 04:17:54 PM
I want to use two icons, that i`ve created, instead of a text.

can somebody give me the right code for this?

thanks in advance!

D.

add_buddy:
(http://picload.org/view/ogicodi/add_buddy.png.html)

http://picload.org/image/ogicodi/add_buddy.png

remove_buddy
(http://picload.org/view/ogicoag/remove_buddy.png.html)


http://picload.org/image/ogicoag/remove_buddy.png
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Draffi on July 06, 2013, 06:14:45 PM
Maaaannnn...it is so easy!

Editing the language file "index.xxx.php" did the trick!
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on July 08, 2013, 08:05:39 AM
Glad you solve it Draffi
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: N i g h t m a r e on September 13, 2013, 11:12:02 PM
I love this little trick, thanks for this :) Currently using this on my Un-Published forum.
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on September 17, 2013, 02:10:30 AM
You're welcome ♦PulsiveForums♦. This trick has been used in a mod. http://custom.simplemachines.org/mods/index.php?mod=3681
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: ittiphol on July 22, 2014, 10:33:40 PM
from this mod

http://custom.simplemachines.org/mods/index.php?mod=3681

how to

1 resize avatar
2 display name
3 show to index page

thank you  ;)

Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: Hj Ahmad Rasyid Hj Ismail on July 22, 2014, 10:43:24 PM
Quote from: ittiphol on July 22, 2014, 10:33:40 PM
from this mod

http://custom.simplemachines.org/mods/index.php?mod=3681

how to

1 resize avatar
2 display name
3 show to index page

thank you  ;)



This post is only for displaying the tips and tricks. For support of the relevant mod, please do refer to that mod support page here: http://www.simplemachines.org/community/index.php?topic=505334.0
Title: Re: [Tip/Trick]Add Buddy Button On Post
Post by: ittiphol on July 22, 2014, 10:49:49 PM
Quote from: ahrasis on July 22, 2014, 10:43:24 PM
Quote from: ittiphol on July 22, 2014, 10:33:40 PM
from this mod

http://custom.simplemachines.org/mods/index.php?mod=3681

how to

1 resize avatar
2 display name
3 show to index page

thank you  ;)



This post is only for displaying the tips and tricks. For support of the relevant mod, please do refer to that mod support page here: http://www.simplemachines.org/community/index.php?topic=505334.0

thank you ahrasis  ;)