This is the code for the comments box that some plugins use:
if (isset($vars['entity']) && isloggedin()) {
$form_body = "<div class=\"contentWrapper\"><p class='longtext_editarea'><label>".elgg_echo("generic_comments:text")."<br />" . elgg_view('input/longtext',array('internalname' => 'generic_comment')) . "</label></p>";
$form_body .= "<p>" . elgg_view('input/hidden', array('internalname' => 'entity_guid', 'value' => $vars['entity']->getGUID()));
$form_body .= elgg_view('input/submit', array('value' => elgg_echo("post"))) . "</p></div>";
echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$vars['url']}action/comments/add"));
}
Now I want to make that comment box only available for friends. I know I need to add a variable to this code:
if (isset($vars['entity']) && isloggedin())
(add an && isaFriend) but I don't know how to do it or if there's a variable that has the relationship type that I can use to make this work.
Any help will be appreciatted
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- rjcalifornia@rjcalifornia
rjcalifornia - 0 likes
- Matt Beckett@Beck24
Matt Beckett - 0 likes
- rjcalifornia@rjcalifornia
rjcalifornia - 0 likes
- rjcalifornia@rjcalifornia
rjcalifornia - 0 likes
You must log in to post replies.Ok, So I found the isFriend() function, but how do I call it from root/views/default/comments/form/edit.php
You need the user object of the person you're checking, and isFriend() will tell you if they're a friend of the currently logged in user.
For example, code to see if you are a friend would be something like this:
Note that the isFriend() method only checks for a friend of the currently logged in user. If you want to check for other users there are other methods on that same reference page.
So for your exmple I'm assuming you mean that you want the form to be accessible to the friends of the content owner. Something like this should work:
Thanks Matt Beckett! It works as expected! =)
It should be part of user's privacy control ;)
One las thing, sorry hehe
In order to show the comments box to the owner too should I add
|| $owner or && owner
???