ok i found everything and iv got it all set up, only one problem now, when i try to delete my test user it tells me im not authorize to perform this action, so......im sorry iv done lots of searching i cant find where to change it from a admin action to a user action......any ideas where that might be?
You'd have to unregister the action, then reregister it for authenticated users. That's assuming the action file doesn't have admin_gatekeeper() in it, in which case you won't be able to do anything with it anyway.
Honestly, you're better off using a new action. The action you're trying to use can delete any arbitrary user if you're an admin. Trying to hijack that action for anyone to use could lead to a security issue where a non admin could delete another account. There are ways to avoid this using your method of hijacking that action, but that would require more work than just writing a new action.
Read the action file to see how the user deletion is done, then implement that in your own action that doesn't require a guid to be passed, but gets the currently logged in user to delete.
if you've 'found everything... all set up... not authorize to perform this action...' -> you're doing something very wrongly in the wrong place - but it's kinda hard to say what's really happening without seeing your code - and without such details - the rest of us got no idea what you're coding and where @ ? ;-X
You need to hook into the register, menu:topbar hook and remove the item with the name "friends."
Your callback would like something like this: https://gist.github.com/1888009
FYI: I found this information by checking the HTML. All menus in Elgg have classes that let you guess the menu names. If you look at the menu item's <li> tag you'll see the class "elgg-menu-item-messages". Look up the DOM to the <ul> tag and you'll see the class "elgg-menu elgg-menu-topbar elgg-menu-topbar-default".
These classes mean you're looking at the menu item named "friends" in the "default" section of the menu named "topbar".
Brett, wouldn't it be wonderful to have another hook before 'register' in the factory, which would allow to use register/unregister api, without having to iterate through the return array on 'register' to find the menu in question?
@Ismayil - I actually forgot about the unregister function. In this case you CAN use it because the friends menu item is registered by core. So you can replace the hook with elgg_unregister_menu_item('topbar', 'friends'). That's much simpler :)
get 500 internal server error when trying to send the gift
no change in the wording at all still UserA has sent a GIFT to UserB
code.....
<?php
/**
* Elgg Gifts plugin
* Send gifts to you friends
*
* @package Gifts
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Christian Heckelmann
* @copyright Christian Heckelmann
* @link http://www.heckelmann.info
*/
// only logged in users
gatekeeper();
action_gatekeeper();
// get the form input
$receiver = get_input('send_to');
$gift_id = get_input('gift_id');
$body = get_input('body');
$cost = get_input('giftcost');
$access = get_input('access');
$sender = get_entity(elgg_get_logged_in_user_guid());
// No Friend selected?
if (empty($receiver) || empty($gift_id)) {
register_error(elgg_echo("gifts:blank"));
forward("gifts/".$sender->name."/sendgift");
}
// Userpoints
$useuserpoints = elgg_get_plugin_setting('useuserpoints', 'gifts');
if($useuserpoints == 1 && function_exists('userpoints_subtract')) {
$pTemp = userpoints_get(elgg_get_logged_in_user_guid());
$points = $pTemp['approved'];
// Set new Point Value
if(userpoints_subtract(elgg_get_logged_in_user_guid(), $cost, 'gifts')) {
system_message(elgg_echo('gifts:pointsuccess'));
}else{
system_message(elgg_echo('gifts:pointfail'));
}
}
// create a gifts object
$gift = new ElggObject();
$gift->description = $body;
$gift->receiver = $receiver;
$gift->gift_id = $gift_id;
$gift->subtype = "gift";
$gift->description = "value";
$gift->access_id = $access;
$gift->owner_guid = elgg_get_logged_in_user_guid();
// save to database
$gift->save();
$sender = get_entity(elgg_get_logged_in_user_guid());
$msgto = get_entity($receiver);
// send mail notification
global $CONFIG;
notify_user($msgto->getGUID(), $sender->getGUID(), elgg_echo('gifts:mail:subject'),
sprintf(
elgg_echo('gifts:mail:body'),
$sender->name,
$CONFIG->wwwroot . "gifts/" . $msgto->username . "/index"
)
);
// Add to river
[0] := Gift Name <- 'Gift-Text' ? <-- $body | Description ??
add_to_river('river/object/gifts/create','gifts',$gift->owner_guid,$gift->discription,$gift->receiver);
system_message(elgg_echo('gifts:sendok'));
// display gift
forward("gifts/".$sender->name."/sent");
'500' means diddley in this context ;) --- caused by *anything (else) at all... yr server logs will say what's causing #500. my guess = you did(or not do) <something *else> to trigger '500'; code above is north & south poles apart re: 500. and by the way - the code i pasted is suggested pseudo (commented out:-oO) code only not full & real code b/c not wanna steal fun of discovering solution from the send.php code by oneself ;-P -> can be fun..
To be able to include the name of the gift in the river entry you first need to modify the add_to_river() call in /action/send.php because this function only allows to include two Elgg object guids to be used in the river entry. Currently, the user sending the gift is included as "subject_guid" and the user receiving the gift is included as "object_guid". Unfortunately, it's not possible to retrieve the gift name later on using these Elgg objects. But by changing the line to
add_to_river('river/object/gifts/create','gifts',$gift->owner_guid,$gift->getGUID());
the gift name will be accessible and the receiver name can also be retrieved.
The second problem is to handle river entries for gifts sent that were created prior the change. Unfortunately, these entries will not be changeable and will still not include the gift name. So, the file views/default/river/object/create.php has to be modified accordingly:
<?php
/**
* Elgg Gifts plugin
* Send gifts to you friends
*
* @package Gifts
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Christian Heckelmann
* @copyright Christian Heckelmann
* @link http://www.heckelmann.info
*/
// THANK YOU DDFUSION
// Added Fix from DDFusion
$performed_by = get_entity($vars['item']->subject_guid);
$gift = get_entity($vars['item']->object_guid);
if($gift->receiver) {
$performed_on = get_entity($gift->receiver);
$object = get_entity($gift->receiver);
$gifttext = elgg_get_plugin_setting('gift_'.$gift->gift_id, 'gifts');
} else {
$performed_on = get_entity($vars['item']->object_guid);
$object = get_entity($vars['item']->object_guid);
$gifttext = elgg_echo("gifts:gift");
}
$person_link = "<a href=\"{$performed_by->getURL()}\">{$performed_by->name}</a>";
$object_link = "<a href=\"{$performed_on->getURL()}\">{$performed_on->name}</a>";
$gift = "<a href=\"{$vars['url']}gifts/{$_SESSION['user']->username}/index\">{$gifttext}</a>";
$string = sprintf(elgg_echo("gifts:river"), $object_link, $gift) . " <a href=\"{$performed_by->getURL()}\">" . $performed_by->name . "</a> ";
echo elgg_view('river/elements/layout', array(
'item' => $vars['item'],
'message' => $string,
));
You might also want to modify the language strings accordingly, or even include two different strings for old and new river entries. Additionally, it seems necessary to add the language string
'river:gifts:object:default' => "A new gift was sent!",
to the language file, because this string is called by Elgg automatically (maybe starting with Elgg 1.8.3?).
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.