aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-27 14:20:22 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-12-27 14:20:22 +0000
commit4c94f8809f1131e2d8e073518195b6b65b26aceb (patch)
tree461af7e0e4414871c519acdef84ce397fa534325
parent543e50d2aabfbd3c116cbb670018c66fae535955 (diff)
downloadelgg-4c94f8809f1131e2d8e073518195b6b65b26aceb.tar.gz
elgg-4c94f8809f1131e2d8e073518195b6b65b26aceb.tar.bz2
improved menu creation for on demand menus and integrated hover menu items into profile owner block
git-svn-id: http://code.elgg.org/elgg/trunk@7724 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/classes/ElggMenuBuilder.php6
-rw-r--r--engine/classes/ElggMenuItem.php11
-rw-r--r--engine/lib/users.php16
-rw-r--r--engine/lib/views.php25
-rw-r--r--mod/blog/start.php6
-rw-r--r--mod/bookmarks/start.php6
-rw-r--r--mod/file/start.php6
-rw-r--r--mod/logbrowser/start.php6
-rw-r--r--mod/messages/start.php14
-rw-r--r--mod/pages/start.php6
-rw-r--r--mod/profile/views/default/profile/css.php100
-rwxr-xr-xmod/profile/views/default/profile/ownerblock.php85
-rw-r--r--views/default/navigation/menu/user_hover.php2
13 files changed, 132 insertions, 157 deletions
diff --git a/engine/classes/ElggMenuBuilder.php b/engine/classes/ElggMenuBuilder.php
index b57ea6e18..3528eaef8 100644
--- a/engine/classes/ElggMenuBuilder.php
+++ b/engine/classes/ElggMenuBuilder.php
@@ -18,10 +18,8 @@ class ElggMenuBuilder {
*
* @param string $name Identifier of the menu
*/
- public function __construct($name) {
- global $CONFIG;
-
- $this->menu = $CONFIG->menus[$name];
+ public function __construct($menu) {
+ $this->menu = $menu;
}
/**
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index f2eb1534f..2205ebc89 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -318,15 +318,14 @@ class ElggMenuItem {
/**
* Get the menu link
*
- * @todo add styling
+ * @params array $vars Options to pass to output/url
*
* @return string
*/
- public function getLink() {
- $vars = array(
- 'href' => $this->url,
- 'text' => $this->title
- );
+ public function getLink(array $vars = array()) {
+ $vars['href'] = $this->url;
+ $vars['text'] = $this->title;
+
return elgg_view('output/url', $vars);
}
}
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 353575307..a87b241a2 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -1493,17 +1493,17 @@ function elgg_user_hover_menu($hook, $type, $return, $params) {
$url = elgg_add_action_tokens_to_url($url);
$item = new ElggMenuItem('addfriend', $text, $url);
$item->setSection('action');
- elgg_register_menu_item('user_hover', $item);
+ $return[] = $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);
+ $return[] = $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);
+ $return[] = $item;
}
}
@@ -1532,14 +1532,16 @@ function elgg_user_hover_menu($hook, $type, $return, $params) {
$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);
+ $return[] = $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);
+ $return[] = $item;
}
+
+ return $return;
}
/**
@@ -1566,8 +1568,10 @@ function elgg_user_admin_menu($hook, $type, $return, $params) {
$url = "action/admin/user/$action?guid={$user->guid}";
$url = elgg_add_action_tokens_to_url($url);
$item = new ElggMenuItem($action, elgg_echo($action), $url);
- elgg_register_menu_item('user_admin', $item);
+ $return[] = $item;
}
+
+ return $return;
}
/**
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 1e309f5bd..b5240b431 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -657,27 +657,30 @@ function elgg_view_layout($layout_name, $vars = array()) {
* @since 1.8.0
*/
function elgg_view_menu($menu_name, array $vars = array()) {
-
+ global $CONFIG;
+
$vars['name'] = $menu_name;
$sort_by = elgg_get_array_value('sort_by', $vars, 'title');
- // Give plugins a chance to add menu items just before creation.
- // This supports context sensitive menus (ex. user hover).
- elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, NULL);
+ $menu = $CONFIG->menus[$menu_name];
+
+ // Give plugins a chance to add menu items just before creation.
+ // This supports context sensitive menus (ex. user_hover).
+ $menu = elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, $menu);
- $builder = new ElggMenuBuilder($menu_name);
+ $builder = new ElggMenuBuilder($menu);
$vars['menu'] = $builder->getMenu($sort_by);
$vars['selected_item'] = $builder->getSelected();
// Let plugins modify the menu
- $vars['menu'] = elgg_trigger_plugin_hook('prepare', "menu:$menu_name", $vars, $vars['menu']);
+ $vars['menu'] = elgg_trigger_plugin_hook('prepare', "menu:$menu_name", $vars, $vars['menu']);
- if (elgg_view_exists("navigation/menu/$menu_name")) {
- return elgg_view("navigation/menu/$menu_name", $vars);
- } else {
- return elgg_view("navigation/menu/default", $vars);
- }
+ if (elgg_view_exists("navigation/menu/$menu_name")) {
+ return elgg_view("navigation/menu/$menu_name", $vars);
+ } else {
+ return elgg_view("navigation/menu/default", $vars);
+ }
}
/**
diff --git a/mod/blog/start.php b/mod/blog/start.php
index f3cd31770..1c0cc8b21 100644
--- a/mod/blog/start.php
+++ b/mod/blog/start.php
@@ -229,14 +229,16 @@ function blog_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "pg/blog/owner/{$params['entity']->username}";
$item = new ElggMenuItem('blog', elgg_echo('blog'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
} else {
if ($params['entity']->blog_enable != "no") {
$url = "pg/blog/group/{$params['entity']->guid}/owner";
$item = new ElggMenuItem('blog', elgg_echo('blog:group'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
}
}
+
+ return $return;
}
/**
diff --git a/mod/bookmarks/start.php b/mod/bookmarks/start.php
index 062193517..8550878b6 100644
--- a/mod/bookmarks/start.php
+++ b/mod/bookmarks/start.php
@@ -321,14 +321,16 @@ function bookmarks_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "pg/bookmarks/owner/{$params['user']->username}";
$item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
} else {
if ($params['entity']->bookmarks_enable != "no") {
$url = "pg/bookmarks/owner/{$params['entity']->username}";
$item = new ElggMenuItem('bookmarks', elgg_echo('bookmarks:group'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
}
}
+
+ return $return;
}
/**
diff --git a/mod/file/start.php b/mod/file/start.php
index bb291680e..3376befeb 100644
--- a/mod/file/start.php
+++ b/mod/file/start.php
@@ -147,14 +147,16 @@ function file_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "pg/file/owner/{$params['entity']->username}";
$item = new ElggMenuItem('file', elgg_echo('file'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
} else {
if ($params['entity']->file_enable != "no") {
$url = "pg/file/owner/{$params['entity']->username}";
$item = new ElggMenuItem('file', elgg_echo('file:group'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
}
}
+
+ return $return;
}
/**
diff --git a/mod/logbrowser/start.php b/mod/logbrowser/start.php
index 62beafe87..dd3c24bee 100644
--- a/mod/logbrowser/start.php
+++ b/mod/logbrowser/start.php
@@ -23,10 +23,12 @@ function logbrowser_init() {
* Add to the user hover menu
*/
function logbrowser_user_hover_menu($hook, $type, $return, $params) {
- $user = $params['user'];
+ $user = $params['entity'];
$url = "pg/admin/overview/logbrowser/?user_guid={$user->guid}";
$item = new ElggMenuItem('logbrowser', elgg_echo('logbrowser:explore'), $url);
$item->setSection('admin');
- elgg_register_menu_item('user_hover', $item);
+ $return[] = $item;
+
+ return $return;
}
diff --git a/mod/messages/start.php b/mod/messages/start.php
index 861f219b2..e8f5105b2 100644
--- a/mod/messages/start.php
+++ b/mod/messages/start.php
@@ -311,12 +311,16 @@ 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'];
+ $user = $params['entity'];
- $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);
+ if (isloggedin() && get_loggedin_userid() != $user->guid) {
+ $url = "mod/messages/send.php?send_to={$user->guid}";
+ $item = new ElggMenuItem('send', elgg_echo('messages:sendmessage'), $url);
+ $item->setSection('action');
+ $return[] = $item;
+ }
+
+ return $return;
}
diff --git a/mod/pages/start.php b/mod/pages/start.php
index ebf102be0..1c8290327 100644
--- a/mod/pages/start.php
+++ b/mod/pages/start.php
@@ -83,14 +83,16 @@ function pages_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "pg/pages/owner/{$params['entity']->username}";
$item = new ElggMenuItem('pages', elgg_echo('pages'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
} else {
if ($params['entity']->pages_enable != "no") {
$url = "pg/pages/owned/group:{$vars['entity']->guid}";
$item = new ElggMenuItem('pages', elgg_echo('pages:group'), $url);
- elgg_register_menu_item('owner_block', $item);
+ $return[] = $item;
}
}
+
+ return $return;
}
/**
diff --git a/mod/profile/views/default/profile/css.php b/mod/profile/views/default/profile/css.php
index 754276c69..1d1f1ccb1 100644
--- a/mod/profile/views/default/profile/css.php
+++ b/mod/profile/views/default/profile/css.php
@@ -29,98 +29,60 @@
/* ***************************************
ownerblock in sidebar
*************************************** */
-#profile-sidebar #owner_block {
+#profile-owner-block {
background-color: #eeeeee;
- padding:15px;
+ padding: 15px;
}
-#owner_block .owner_block_icon.large {
+.owner_block_icon {
overflow: hidden;
+ margin-bottom: 10px;
}
-#owner_block .profile_actions {
- margin-top:10px;
-}
-#owner_block .profile_actions a.elgg-action-button {
- margin-bottom:4px;
+#profile-owner-block a.elgg-action-button {
+ margin-bottom: 4px;
display: table;
}
-/* ownerblock links to owners tools */
-#owner_block .owners_content_links {
- border-top:1px dotted #cccccc;
- margin-top:4px;
- padding-top:2px;
-}
-#owner_block .owners_content_links ul {
- margin:0;
- padding:0;
-}
-#owner_block .owners_content_links ul li {
- display:block;
- float:left;
- width:95px;
- font-size: 90%;
-}
-/* profile pages - ownerblock links to owners tools */
-.owner_block_links {
- margin-top:5px;
-}
-.owner_block_links ul {
- margin:0;
- padding:0;
- list-style: none;
-}
-.owner_block_links ul li.selected a {
- background: #4690D6;
- color:white;
-}
-.owner_block_links ul li a {
- display:block;
- -webkit-border-radius: 8px;
+.profile-content-menu a {
+ display: block;
+ -webkit-border-radius: 8px;
-moz-border-radius: 8px;
- background-color:white;
- margin:3px 0 5px 0;
- padding:2px 4px 2px 8px;
+ background-color: white;
+ margin: 3px 0 5px 0;
+ padding: 2px 4px 2px 8px;
}
-.owner_block_links ul li a:hover {
- background:#0054A7;
- color:white;
- text-decoration:none;
+.profile-content-menu a:hover {
+ background: #0054A7;
+ color: white;
+ text-decoration: none;
}
-
/* ***************************************
admin menu in sidebar
*************************************** */
-.owner_block_links .admin_menu_options {
+.profile-admin-menu {
display: none;
}
-.owner_block_links ul.admin_menu {
- background-color:white;
+.profile-admin-menu-wrapper a {
+ display: block;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
- cursor:pointer;
-}
-.owner_block_links ul.admin_menu li a {
background-color: white;
- color:red;
- margin-bottom:0;
+ margin: 3px 0 5px 0;
+ padding: 2px 4px 2px 8px;
}
-.owner_block_links ul.admin_menu li a:hover {
- color:black;
+.profile-admin-menu-wrapper {
+ background-color: white;
+ -webkit-border-radius: 8px;
+ -moz-border-radius: 8px;
}
-.owner_block_links ul.admin_menu li ul.admin_menu_options li a {
- color:red;
- background-color:white;
- display:block;
- margin:0px;
- padding:2px 4px 2px 13px;
+.profile-admin-menu-wrapper li a {
+ background-color: white;
+ color: red;
+ margin-bottom: 0;
}
-.owner_block_links ul.admin_menu li ul.admin_menu_options li a:hover {
- color:black;
- background:none;
- text-decoration: underline;
+.profile-admin-menu-wrapper a:hover {
+ color: black;
}
-
/* ***************************************
full profile info panel
*************************************** */
diff --git a/mod/profile/views/default/profile/ownerblock.php b/mod/profile/views/default/profile/ownerblock.php
index 2197164cb..ac0cb5b54 100755
--- a/mod/profile/views/default/profile/ownerblock.php
+++ b/mod/profile/views/default/profile/ownerblock.php
@@ -21,69 +21,62 @@ if (!$user) {
$more_info = '';
-$location = elgg_view("output/tags",array('value' => $user->location));
+$location = elgg_view("output/tags", array('value' => $user->location));
-$icon = elgg_view("profile/icon",array('entity' => $user, 'size' => 'large', 'override' => 'true'));
+$icon = elgg_view("profile/icon", array(
+ 'entity' => $user,
+ 'size' => 'large',
+ 'override' => 'true'
+));
$icon_class = "large";
-// @todo pull out into menu
-$profile_actions = "";
-if (isloggedin() && (get_loggedin_userid() == elgg_get_page_owner_guid())) {
- $profile_actions = "<div class='clearfix profile_actions'>";
- $profile_actions .= "<a href='".elgg_get_site_url()."pg/profile/{$user->username}/edit/details' class='elgg-action-button'>". elgg_echo('profile:edit') ."</a>";
- $profile_actions .= "<a href='".elgg_get_site_url()."pg/avatar/edit/{$user->username}' class='elgg-action-button'>". elgg_echo('avatar:edit') ."</a>";
- $profile_actions .= "</div>";
-} else {
- $profile_actions = "<div class='profile_actions'>";
- if (isloggedin()) {
- if (get_loggedin_userid() != $user->getGUID()) {
- if ($user->isFriend()) {
- $url = elgg_get_site_url()."action/friends/remove?friend={$user->getGUID()}";
- $url = elgg_add_action_tokens_to_url($url);
- $profile_actions .= "<a href=\"$url\" class='elgg-action-button'>" . elgg_echo('friend:remove') . "</a>";
- } else {
- $url = elgg_get_site_url()."action/friends/add?friend={$user->getGUID()}";
- $url = elgg_add_action_tokens_to_url($url);
- $profile_actions .= "<a href=\"$url\" class='elgg-action-button'>" . elgg_echo('friend:add') . "</a>";
- }
- }
- }
- if (is_plugin_enabled('messages') && isloggedin()) {
- $profile_actions .= "<a href=\"".elgg_get_site_url()."mod/messages/send.php?send_to={$user->guid}\" class='elgg-action-button'>". elgg_echo('messages:send') ."</a>";
+// grab the actions and admin menu items from user hover
+$menu = elgg_trigger_plugin_hook('register', "menu:user_hover", array('entity' => $user), array());
+$builder = new ElggMenuBuilder($menu);
+$menu = $builder->getMenu();
+$actions = elgg_get_array_value('action', $menu, array());
+$admin = elgg_get_array_value('admin', $menu, array());
+
+$profile_actions = '';
+if (isloggedin() && $actions) {
+ $profile_actions = '<ul class="elgg-menu">';
+ foreach ($actions as $action) {
+ $profile_actions .= '<li>' . $action->getLink(array('class' => 'elgg-action-button')) . '</li>';
}
- $profile_actions .= "</div>";
+ $profile_actions .= '</ul>';
}
-
// if admin, display admin links
$admin_links = '';
if (isadminloggedin() && get_loggedin_userid() != elgg_get_page_owner_guid()) {
- $params = array(
- 'user' => elgg_get_page_owner(),
- 'toggle' => true,
- 'sort_by' => 'order',
- );
- $admin_links = elgg_view_menu('user_admin', $params);
- $admin_links = "<div class=\"owner_block_links\">$admin_links</div>";
+ $admin_links = '<ul class="profile-admin-menu-wrapper">';
+ $admin_links .= '<li><a class="elgg-toggle" id="elgg-toggler-admin-menu">Admin options&hellip;</a>';
+ $admin_links .= '<ul class="profile-admin-menu" id="elgg-togglee-admin-menu">';
+ foreach ($admin as $menu_item) {
+ $admin_links .= elgg_view('navigation/menu/elements/item', array('item' => $menu_item));
+ }
+ $admin_links .= '</ul>';
+ $admin_links .= '</li>';
+ $admin_links .= '</ul>';
}
// content links
-$menu = elgg_view_menu('owner_block', array('entity' => elgg_get_page_owner()));
+$content_menu = elgg_view_menu('owner_block', array(
+ 'entity' => elgg_get_page_owner(),
+ 'class' => 'profile-content-menu',
+));
//contruct the display
$display = <<<EOT
-<div id="owner_block">
- <div class="owner_block_icon {$icon_class}">
- {$icon}
- </div>
- {$more_info}
- {$profile_actions}
- <div class="owner_block_links">
- $menu
+<div id="profile-owner-block">
+ <div class="owner_block_icon $icon_class">
+ $icon
</div>
- <!-- if admin user -->
- {$admin_links}
+ $more_info
+ $profile_actions
+ $content_menu
+ $admin_links
</div>
EOT;
diff --git a/views/default/navigation/menu/user_hover.php b/views/default/navigation/menu/user_hover.php
index e8c5d0cbc..7f64c4a10 100644
--- a/views/default/navigation/menu/user_hover.php
+++ b/views/default/navigation/menu/user_hover.php
@@ -4,6 +4,8 @@
*
* Register for the 'register', 'menu:user_hover' plugin hook to add to the user
* hover menu. There are three sections: action, default, and admin.
+ *
+ * @uses $vars['menu'] Menu array provided by elgg_view_menu()
*/
$user = $vars['entity'];