diff options
-rw-r--r-- | engine/classes/ElggUser.php | 3 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 4 | ||||
-rw-r--r-- | engine/lib/users.php | 70 | ||||
-rw-r--r-- | mod/logbrowser/start.php | 11 | ||||
-rw-r--r-- | mod/messages/start.php | 15 | ||||
-rw-r--r-- | views/default/css/elements/navigation.php | 38 | ||||
-rw-r--r-- | views/default/js/elgg.php | 17 | ||||
-rw-r--r-- | views/default/navigation/menu/user_hover.php | 50 | ||||
-rw-r--r-- | views/default/profile/hover.php | 63 |
9 files changed, 196 insertions, 75 deletions
diff --git a/engine/classes/ElggUser.php b/engine/classes/ElggUser.php index eca011a36..ff449d601 100644 --- a/engine/classes/ElggUser.php +++ b/engine/classes/ElggUser.php @@ -303,10 +303,11 @@ class ElggUser extends ElggEntity /** * Determines whether or not this user is a friend of the currently logged in user * + * * @return true|false */ function isFriend() { - return $this->isFriendsWith(get_loggedin_userid()); + return $this->isFriendOf(get_loggedin_userid()); } /** 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'); diff --git a/mod/logbrowser/start.php b/mod/logbrowser/start.php index 1eda00732..62beafe87 100644 --- a/mod/logbrowser/start.php +++ b/mod/logbrowser/start.php @@ -14,18 +14,19 @@ function logbrowser_init() { elgg_extend_view('css/admin', 'logbrowser/css'); - elgg_register_plugin_hook_handler('register', 'menu:user_admin', 'logbrowser_user_admin_menu'); + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'logbrowser_user_hover_menu'); elgg_add_admin_submenu_item('logbrowser', elgg_echo('logbrowser'), 'overview'); } /** - * Add to the user admin menu + * Add to the user hover menu */ -function logbrowser_user_admin_menu($hook, $type, $return, $params) { +function logbrowser_user_hover_menu($hook, $type, $return, $params) { $user = $params['user']; $url = "pg/admin/overview/logbrowser/?user_guid={$user->guid}"; $item = new ElggMenuItem('logbrowser', elgg_echo('logbrowser:explore'), $url); - elgg_register_menu_item('user_admin', $item); -}
\ No newline at end of file + $item->setSection('admin'); + elgg_register_menu_item('user_hover', $item); +} diff --git a/mod/messages/start.php b/mod/messages/start.php index 3459bb9f8..861f219b2 100644 --- a/mod/messages/start.php +++ b/mod/messages/start.php @@ -30,7 +30,7 @@ function messages_init() { register_entity_url_handler('messages_url', 'object', 'messages'); // Extend avatar hover menu - elgg_extend_view('profile/menu/links', 'messages/menu'); + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'messages_user_hover_menu'); // Register a notification handler for site messages register_notification_handler("site", "messages_site_notify_handler"); @@ -308,6 +308,19 @@ function messages_site_notify_handler(ElggEntity $from, ElggUser $to, $subject, } /** + * Add to the user hover menu + */ +function messages_user_hover_menu($hook, $type, $return, $params) { + $user = $params['user']; + + $url = "mod/messages/send.php?send_to={$user->guid}"; + $item = new ElggMenuItem('logbrowser', elgg_echo('messages:sendmessage'), $url); + $item->setSection('action'); + elgg_register_menu_item('user_hover', $item); +} + + +/** * Register messages with ECML. * * @param string $hook diff --git a/views/default/css/elements/navigation.php b/views/default/css/elements/navigation.php index e1a3c6866..7975dde25 100644 --- a/views/default/css/elements/navigation.php +++ b/views/default/css/elements/navigation.php @@ -272,4 +272,40 @@ float: left; width: 50%; font-size: 90%; -}
\ No newline at end of file +} + +.elgg-hover-menu { + display: none; + position: absolute; + + width: 165px; + border-top: solid 1px #E5E5E5; + border-left: solid 1px #E5E5E5; + border-right: solid 1px #999999; + border-bottom: solid 1px #999999; + background-color: #FFFFFF; + -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.50); + -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.50); +} +.elgg-hover-menu > li { + border-bottom: 1px solid #dddddd; +} +.elgg-hover-menu > li:last-child { + border-bottom: none; +} +.elgg-hover-menu a { + display: block; + padding: 2px 8px; + font-size: 92%; +} +.elgg-hover-menu a:hover { + background: #cccccc; + text-decoration: none; +} +.elgg-hover-admin a { + color: red; +} +.elgg-hover-admin a:hover { + color: white; + background-color: red; +} diff --git a/views/default/js/elgg.php b/views/default/js/elgg.php index 082122b5d..3e7b30a99 100644 --- a/views/default/js/elgg.php +++ b/views/default/js/elgg.php @@ -358,25 +358,24 @@ function setup_avatar_menu(parent) { // avatar contextual menu $(".avatar_menu_button img").click(function(e) { - var submenu = $(this).parent().parent().find("div.sub_menu"); + //var submenu = $(this).parent().parent().find("div.sub_menu"); + var submenu = $(this).parent().parent().find(".elgg-hover-menu"); // close submenu if arrow is clicked & menu already open - if(submenu.css('display') == "block") { + if (submenu.css('display') == "block") { //submenu.hide(); - } - else { + } else { // get avatar dimensions var avatar = $(this).parent().parent().parent().find("div.elgg-user-icon"); //alert( "avatarWidth: " + avatar.width() + ", avatarHeight: " + avatar.height() ); // move submenu position so it aligns with arrow graphic if (e.pageX < 840) { // popup menu to left of arrow if we're at edge of page - submenu.css("top",(avatar.height()) + "px") + submenu.css("top",(avatar.height()) + "px") .css("left",(avatar.width()-15) + "px") .fadeIn('normal'); - } - else { - submenu.css("top",(avatar.height()) + "px") + } else { + submenu.css("top",(avatar.height()) + "px") .css("left",(avatar.width()-166) + "px") .fadeIn('normal'); } @@ -429,7 +428,7 @@ function setup_avatar_menu(parent) { $(document).click(function(event) { var target = $(event.target); if (target.parents(".elgg-user-icon").length == 0) { - $(".elgg-user-icon div.sub_menu").fadeOut(); + $(".elgg-hover-menu").fadeOut(); $(".avatar_menu_button").removeClass("avatar_menu_arrow"); $(".avatar_menu_button").removeClass("avatar_menu_arrow_on"); $(".avatar_menu_button").removeClass("avatar_menu_arrow_hover"); diff --git a/views/default/navigation/menu/user_hover.php b/views/default/navigation/menu/user_hover.php new file mode 100644 index 000000000..e8c5d0cbc --- /dev/null +++ b/views/default/navigation/menu/user_hover.php @@ -0,0 +1,50 @@ +<?php +/** + * User hover menu + * + * Register for the 'register', 'menu:user_hover' plugin hook to add to the user + * hover menu. There are three sections: action, default, and admin. + */ + +$user = $vars['entity']; +$actions = elgg_get_array_value('action', $vars['menu'], null); +$main = elgg_get_array_value('default', $vars['menu'], null); +$admin = elgg_get_array_value('admin', $vars['menu'], null); + +echo '<ul class="elgg-menu elgg-hover-menu">'; + +// name and username +$name_link = elgg_view('output/url', array( + 'href' => $user->getURL(), + 'text' => "<h3>$user->name</h3>@$user->username", +)); +echo "<li>$name_link</li>"; + +// actions +if (isloggedin() && $actions) { + echo '<li><ul>'; + foreach ($actions as $menu_item) { + echo elgg_view('navigation/menu/elements/item', array('item' => $menu_item)); + } + echo '</ul></li>'; +} + +// main +if ($main) { + echo '<li><ul>'; + foreach ($main as $menu_item) { + echo elgg_view('navigation/menu/elements/item', array('item' => $menu_item)); + } + echo '</ul></li>'; +} + +// admin +if (isadminloggedin() && $admin) { + echo '<li><ul class="elgg-hover-admin">'; + foreach ($admin as $menu_item) { + echo elgg_view('navigation/menu/elements/item', array('item' => $menu_item)); + } + echo '</ul></li>'; +} + +echo '</ul>'; diff --git a/views/default/profile/hover.php b/views/default/profile/hover.php index 85d6912ba..e31a99359 100644 --- a/views/default/profile/hover.php +++ b/views/default/profile/hover.php @@ -1,63 +1,16 @@ <?php -$user = $vars['entity']; -$username = $vars['username']; -$name = $vars['name']; - ?> -<div class="avatar_menu_button"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" border="0" width="15" height="15" /></div> -<div class="sub_menu"> - <h3 class="displayname"> - <a href="<?php echo $user->getURL(); ?>"> - <?php echo $name; ?> - <span class="username"> - <?php echo "@" . $username; ?> - </span> - </a> - </h3> - <ul class='sub_menu_list'> -<?php -if (isloggedin()) { - // if not looking at your own avatar menu - if ($user->getGUID() != get_loggedin_userid()) { +<div class="avatar_menu_button"> + <img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" border="0" width="15" height="15" /> +</div> - // Add / Remove friend link - $friendlinks = elgg_view('profile/menu/friendlinks',$vars); - if (!empty($friendlinks)) { - echo "<li class='user_menu_profile'>{$friendlinks}</li>"; - } - // view for plugins to extend - echo elgg_view('profile/menu/links',$vars); - } else { - // if looking at your own avatar menu - provide a couple of handy links -?> - <li class="user_menu_profile"> - <a class="edit_profile" href="<?php echo elgg_get_site_url()?>pg/profile/<?php echo $username; ?>/edit/details"> - <?php echo elgg_echo("profile:edit"); ?> - </a> - </li> - <li class="user_menu_profile"> - <a class="edit_avatar" href="<?php echo elgg_get_site_url()?>pg/profile/<?php echo $username; ?>/edit/icon"> - <?php echo elgg_echo("profile:editicon"); ?> - </a> - </li> <?php - } - // if Admin is logged in, and not looking at admins own avatar menu - if (isadminloggedin() && get_loggedin_userid() != $user->guid) { - $params = array( - 'user' => $user, - 'sort_by' => 'order', - ); - $admin_links = elgg_view_menu('user_admin', $params); - if (!empty($admin_links)) { - echo "<li class='user_menu_admin'>{$admin_links}</li>"; - } - } -} -?> - </ul> -</div>
\ No newline at end of file +echo elgg_view_menu('user_hover', $vars); + +// @todo change how to add on demand registration of menu items +global $CONFIG; +unset($CONFIG->menus['user_hover']); |