diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-27 02:14:56 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-27 02:14:56 +0000 |
commit | 543e50d2aabfbd3c116cbb670018c66fae535955 (patch) | |
tree | d84b51988a755c03f8794e3c11cf38b78015ea65 /engine/lib | |
parent | 07a1585f3eee1211aeaf55ea436135f637520102 (diff) | |
download | elgg-543e50d2aabfbd3c116cbb670018c66fae535955.tar.gz elgg-543e50d2aabfbd3c116cbb670018c66fae535955.tar.bz2 |
moved most of the code for the user hover menu into the new menu system
git-svn-id: http://code.elgg.org/elgg/trunk@7723 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/elgglib.php | 4 | ||||
-rw-r--r-- | engine/lib/users.php | 70 |
2 files changed, 71 insertions, 3 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 2ca1f90e3..8d2b8ed91 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1616,13 +1616,13 @@ function elgg_http_build_url(array $parts, $html_encode = TRUE) { * tokens. * * @param str $url Full action URL - * @param bool $html_encode HTML encode the url? + * @param bool $html_encode HTML encode the url? (default: false) * * @return str URL with action tokens * @since 1.7.0 * @link http://docs.elgg.org/Tutorials/Actions */ -function elgg_add_action_tokens_to_url($url, $html_encode = TRUE) { +function elgg_add_action_tokens_to_url($url, $html_encode = FALSE) { $components = parse_url(elgg_normalize_url($url)); if (isset($components['query'])) { diff --git a/engine/lib/users.php b/engine/lib/users.php index c9ac6603e..353575307 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -382,7 +382,7 @@ function user_remove_friend($user_guid, $friend_guid) { * @return bool */ function user_is_friend($user_guid, $friend_guid) { - return check_entity_relationship($user_guid, "friend", $friend_guid); + return check_entity_relationship($user_guid, "friend", $friend_guid) !== false; } /** @@ -1476,6 +1476,73 @@ function user_avatar_hook($hook, $entity_type, $returnvalue, $params){ } /** + * Setup the default user hover menu + */ +function elgg_user_hover_menu($hook, $type, $return, $params) { + $user = $params['entity']; + + if (isloggedin()) { + if (get_loggedin_userid() != $user->guid) { + if ($user->isFriend()) { + $url = "action/friends/remove?friend={$user->guid}"; + $text = elgg_echo('friend:remove'); + } else { + $url = "action/friends/add?friend={$user->guid}"; + $text = elgg_echo('friend:add'); + } + $url = elgg_add_action_tokens_to_url($url); + $item = new ElggMenuItem('addfriend', $text, $url); + $item->setSection('action'); + elgg_register_menu_item('user_hover', $item); + } else { + $url = "pg/profile/$user->username/edit"; + $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); + $item->setSection('action'); + elgg_register_menu_item('user_hover', $item); + + $url = "pg/avatar/edit/$user->username"; + $item = new ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url); + $item->setSection('action'); + elgg_register_menu_item('user_hover', $item); + } + } + + // prevent admins from banning or deleting themselves + if (get_loggedin_userid() == $user->guid) { + return; + } + + if (isadminloggedin()) { + $actions = array(); + if (!$user->isBanned()) { + $actions[] = 'ban'; + } else { + $actions[] = 'unban'; + } + $actions[] = 'delete'; + $actions[] = 'resetpassword'; + if (!$user->isAdmin()) { + $actions[] = 'makeadmin'; + } else { + $actions[] = 'removeadmin'; + } + + foreach ($actions as $action) { + $url = "action/admin/user/$action?guid={$user->guid}"; + $url = elgg_add_action_tokens_to_url($url); + $item = new ElggMenuItem($action, elgg_echo($action), $url); + $item->setSection('admin'); + elgg_register_menu_item('user_hover', $item); + } + + $url = "pg/profile/$user->username/edit"; + $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); + $item->setSection('admin'); + elgg_register_menu_item('user_hover', $item); + } +} + +/** * Setup the user admin menu */ function elgg_user_admin_menu($hook, $type, $return, $params) { @@ -1682,6 +1749,7 @@ function users_init() { elgg_register_menu_item('page', $params); } + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); elgg_register_plugin_hook_handler('register', 'menu:user_admin', 'elgg_user_admin_menu'); elgg_register_action("register", '', 'public'); |