Created
September 5, 2010 23:57
-
-
Save cash/566454 to your computer and use it in GitHub Desktop.
Elgg Menu API for 1.8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add an item to an Elgg menu | |
* | |
* @param string $menu The name of the menu: site, page, userhover, userprofile, groupprofile, or any custom menu | |
* @param string $id The unique identifier for this menu item. An example is blog:add | |
* @param string $title The localized title string for this menu item | |
* @param string $url The URL for this menu item | |
* @param array $options An associative array of menu options including: tooltip, parent, context, or custom option. | |
* tooltip: string that is used as the title element of the link | |
* parent: the $id of the item's parent | |
* context: array of context strings (see elgg_get_context()) | |
*/ | |
function elgg_add_menu_item($menu, $id, $title, $url, $options = array()) { | |
} | |
/** | |
* Remove an item from a menu | |
* | |
* @param string $menu The name of the menu | |
* @param string $id The unique identifier for this menu item | |
*/ | |
function elgg_remove_menu_item($menu, $id) { | |
} | |
/** | |
* Render a menu | |
* | |
* @param string $menu The name of the menu | |
* @param array $vars An associative array of display options for the menu | |
* @return string | |
*/ | |
function elgg_view_menu($menu, $vars) { | |
$vars['name'] = $menu; | |
// give plugins a chance to add menu items just before creation - supports context sensitive menus (ex. user hover) | |
trigger_plugin_hook('register', "menu:$menu", NULL, $vars); | |
// sort menu and determine selected item | |
menu object/array = trigger_plugin_hook('prepare', 'menu', menu object/array, $vars); | |
if (elgg_view_exists("navigation/menu/$menu")) { | |
return elgg_view("navigation/menu/$menu", $vars); | |
} else { | |
return elgg_view("navigation/menu/default", $vars); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Blog boot loader snippet | |
*/ | |
function blog_init() { | |
// add a menu item to site navigation menu | |
$url = elgg_get_config('wwwroot') . 'pg/blog/'; | |
elgg_add_menu_item('site', 'blog', elgg_echo('blog:title'), $url); | |
// add sidebar menu item for all site blogs | |
$options = array('context' => array('blog')); | |
$url = elgg_get_config('wwwroot') . 'pg/blog/'; | |
elgg_add_menu_item('page', 'blog', elgg_echo('blog:all'), $url, $options); | |
register_plugin_hook('register', 'menu:page', 'blog_register_sidebar_menu'); | |
register_plugin_hook('register', 'menu:userhover', 'blog_register_userhover_menu'); | |
} | |
function blog_register_sidebar_menu($hook, $type, $return_value, $params) { | |
if (get_context() != 'blog') { | |
return; | |
} | |
$page_owner = elgg_get_page_owner(); | |
$viewer = get_loggedin_user(); | |
$wwwroot = elgg_get_config('wwwroot'); | |
// my blogs | |
$options = array('context' => array('blog')); | |
$url = "{$wwwroot}pg/blog/$viewer->username"; | |
elgg_add_menu_item('page', 'blog:my', elgg_echo('blog:my'), $url, $options); | |
// page owner's blogs | |
$options = array('context' => array('blog')); | |
$url = "{$wwwroot}pg/blog/$page_owner->username"; | |
$title = elgg_echo('blog:their', $page_owner->name); | |
elgg_add_menu_item('page', 'blog:their', $title, $url, $options); | |
} | |
function blog_register_userhover_menu($hook, $type, $return_value, $params) { | |
$user = $params['user']; | |
$wwwroot = elgg_get_config('wwwroot'); | |
$url = "{$wwwroot}pg/blog/$user->username"; | |
$title = elgg_echo('blog:their', $user->name); | |
elgg_add_menu_item('page', 'blog:their:hover', $title, $url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment