From 3c34ddf59804767e6a7deea3e3ee6c81d4a09601 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 26 Jun 2011 15:13:50 -0400 Subject: removed buttons logic from content header view, created convenience function rather than copying and pasting, and updated the blog plugin --- engine/lib/navigation.php | 35 +++++++++++++++++++++++++++ mod/blog/lib/blog.php | 6 +++-- views/default/page/layouts/content.php | 1 - views/default/page/layouts/content/header.php | 30 ++++++++--------------- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 4b2c998a2..1cb289654 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -153,6 +153,41 @@ function elgg_is_menu_item_registered($menu_name, $item_name) { return false; } +/** + * Convenience function for registering an add content button to title menu + * + * The add URL must be $handler/add/$guid where $guid is the guid of the page owner. + * The label of the button is "$handler:add" so that must be defined in a + * language file. + * + * @param string $handler The handler to use or null to autodetect from context + * @return void + * @since 1.8.0 + */ +function elgg_register_add_button($handler = null) { + if (elgg_is_logged_in()) { + + if (!$handler) { + $handler = elgg_get_context(); + } + + $owner = elgg_get_page_owner_entity(); + if (!$owner) { + // no owns the page so this is probably an all site list page + $owner = elgg_get_logged_in_user_entity(); + } + if ($owner && $owner->canWriteToContainer()) { + $guid = $owner->getGUID(); + elgg_register_menu_item('title', array( + 'name' => 'add', + 'href' => "$handler/add/$guid", + 'text' => elgg_echo("$handler:add"), + 'link_class' => 'elgg-button elgg-button-action', + )); + } + } +} + /** * Adds a breadcrumb to the breadcrumbs stack. * diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 4d1edd50e..d13b2244e 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -92,6 +92,8 @@ function blog_get_page_content_list($container_guid = NULL) { elgg_push_breadcrumb(elgg_echo('blog:blogs')); } + elgg_register_add_button(); + // show all posts for admin or users looking at their own blogs // show only published posts for other users. if (!(elgg_is_admin_logged_in() || (elgg_is_logged_in() && $container_guid == $loggedin_userid))) { @@ -129,6 +131,8 @@ function blog_get_page_content_friends($user_guid) { elgg_push_breadcrumb($crumbs_title, "blog/owner/{$user->username}"); elgg_push_breadcrumb(elgg_echo('friends')); + elgg_register_add_button(); + if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { $return['content'] .= elgg_echo('friends:none:you'); return $return; @@ -235,7 +239,6 @@ function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) { return array( 'content' => $content, 'title' => $title, - 'buttons' => '', 'filter' => '', ); } @@ -253,7 +256,6 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) { elgg_load_js('elgg.blog'); $return = array( - 'buttons' => '', 'filter' => '', ); diff --git a/views/default/page/layouts/content.php b/views/default/page/layouts/content.php index 35d695f0a..c406c9faf 100644 --- a/views/default/page/layouts/content.php +++ b/views/default/page/layouts/content.php @@ -10,7 +10,6 @@ * @uses $vars['filter'] HTML of the content area filter (override) * @uses $vars['title'] Title text (override) * @uses $vars['context'] Page context (override) - * @uses $vars['buttons'] Content header buttons (override) * @uses $vars['filter_context'] Filter context: everyone, friends, mine * @uses $vars['class'] Additional class to apply to layout */ diff --git a/views/default/page/layouts/content/header.php b/views/default/page/layouts/content/header.php index 403da8a0a..345163bdd 100644 --- a/views/default/page/layouts/content/header.php +++ b/views/default/page/layouts/content/header.php @@ -7,9 +7,13 @@ * @uses $vars['header_override'] HTML for overriding the default header (override) * @uses $vars['title'] Title text (override) * @uses $vars['context'] Page context (override) - * @uses $vars['buttons'] Content header buttons (override) */ +if (isset($vars['buttons'])) { + // it was a bad idea to implement buttons with a pass through + elgg_deprecated_notice("Use elgg_register_menu_item() to register for the title menu", 1.0); +} + if (isset($vars['header_override'])) { echo $vars['header_override']; return true; @@ -22,27 +26,13 @@ if ($context) { $title = elgg_echo($context); } - if (isset($vars['buttons'])) { + if (isset($vars['buttons']) && $vars['buttons']) { $buttons = $vars['buttons']; } else { - if (elgg_is_logged_in() && $context) { - $owner = elgg_get_page_owner_entity(); - if (!$owner) { - // this is probably an all page - $owner = elgg_get_logged_in_user_entity(); - } - if ($owner && $owner->canWriteToContainer()) { - $guid = $owner->getGUID(); - elgg_register_menu_item('title', array( - 'name' => 'add', - 'href' => elgg_extract('new_link', $vars, "$context/add/$guid"), - 'text' => elgg_echo("$context:add"), - 'link_class' => 'elgg-button elgg-button-action', - )); - } - } - - $buttons = elgg_view_menu('title', array('sort_by' => 'priority', 'class' => 'elgg-menu-hz')); + $buttons = elgg_view_menu('title', array( + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz', + )); } echo << -- cgit v1.2.3