From: brettp Date: Wed, 17 Mar 2010 19:09:09 +0000 (+0000) Subject: Added config options for tabs and menu items. X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=ff6f2152bb6f0a759bffbcc213a82aecc0237ae6;p=lorea%2Felgg.git Added config options for tabs and menu items. git-svn-id: http://code.elgg.org/elgg/trunk@5431 36083f99-b078-4883-b0ff-0f9b5a30f544 --- diff --git a/actions/admin/menu_items.php b/actions/admin/menu_items.php new file mode 100644 index 000000000..b271e1c2b --- /dev/null +++ b/actions/admin/menu_items.php @@ -0,0 +1,36 @@ + $info) { + $menu_urls[$info->value->url] = $info; +} + +foreach ($featured_urls as $url) { + if (array_key_exists($url, $menu_urls)) { + $featured_url_info[] = $menu_urls[$url]; + } +} + +// set_config() always returns 0 so can't check for failures +set_config('menu_items_featured_urls', $featured_url_info); +set_config('menu_items_hide_toolbar_entries', $hide_toolbar_entries); + +system_message(elgg_echo('admin:menu_items:saved')); + +forward($_SERVER['HTTP_REFERER']); \ No newline at end of file diff --git a/admin/menu_items.php b/admin/menu_items.php new file mode 100644 index 000000000..5642957e1 --- /dev/null +++ b/admin/menu_items.php @@ -0,0 +1,21 @@ + get_register('menu') +); + +$main_box = elgg_view("admin/menu_items", $vars); +$content = elgg_view_layout("one_column_with_sidebar", $main_box); + +page_draw(elgg_echo('admin:plugins'), $content); \ No newline at end of file diff --git a/engine/lib/admin.php b/engine/lib/admin.php index c8ca90a2f..8d9ffeba0 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -48,17 +48,12 @@ function admin_init() { register_action('admin/user/resetpassword', false, "", true); register_action('admin/user/makeadmin', false, "", true); register_action('admin/user/removeadmin', false, "", true); + register_action('admin/site/update_basic', false, "", true); + register_action('admin/menu_items', false, "", true); - // Register some actions - register_action('admin/site/update_basic', false, "", true); // Register basic site admin action // Page handler - register_page_handler('admin','admin_settings_page_handler'); - -// if (isadminloggedin()) { -// global $is_admin; -// $is_admin = true; -// } + register_page_handler('admin', 'admin_settings_page_handler'); } /** @@ -74,6 +69,7 @@ function admin_pagesetup() { add_submenu_item(elgg_echo('admin:site'), $CONFIG->wwwroot . 'pg/admin/site/'); add_submenu_item(elgg_echo('admin:user'), $CONFIG->wwwroot . 'pg/admin/user/'); add_submenu_item(elgg_echo('admin:plugins'), $CONFIG->wwwroot . 'pg/admin/plugins/'); + add_submenu_item(elgg_echo('admin:menu_items'), $CONFIG->wwwroot . 'pg/admin/menu_items/'); } } @@ -94,6 +90,7 @@ function admin_settings_page_handler($page) { case 'statistics' : $path = $CONFIG->path . "admin/statistics.php"; break; case 'plugins' : $path = $CONFIG->path . "admin/plugins.php"; break; case 'site' : $path = $CONFIG->path . "admin/site.php"; break; + case 'menu_items' : $path = $CONFIG->path . 'admin/menu_items.php'; break; } } @@ -136,8 +133,8 @@ function send_admin_message($subject, $message) { */ function list_admin_messages($limit = 10) { return elgg_list_entities(array( - 'type' => 'object', - 'subtype' => 'admin_message', + 'type' => 'object', + 'subtype' => 'admin_message', 'limit' => $limit )); } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 95292a2d7..5a7fca837 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1453,11 +1453,12 @@ function get_register($register_name) { * @param string $menu_name The name of the menu item * @param string $menu_url The URL of the page * @param array $menu_children Optionally, an array of submenu items (not currently used) - * @param string $context (not used and will likely be deprecated) + * @param string $context * @return true|false Depending on success */ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "") { global $CONFIG; + if (!isset($CONFIG->menucontexts)) { $CONFIG->menucontexts = array(); } @@ -1466,8 +1467,12 @@ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = "" $context = get_plugin_name(); } + $value = new stdClass(); + $value->url = $menu_url; + $value->context = $context; + $CONFIG->menucontexts[] = $context; - return add_to_register('menu', $menu_name, $menu_url, $menu_children); + return add_to_register('menu', $menu_name, $value, $menu_children); } /** @@ -2884,6 +2889,50 @@ function elgg_api_test($hook, $type, $value, $params) { return $value; } +/** + * Sorts out the topbar menu and the featured URLs + * and saves them to $CONFIG->menu_items = array ('featured_urls' and 'toolbar') + * + */ +function ui_page_setup() { + global $CONFIG; + + $hide_toolbar_dupes = get_config('menu_items_hide_toolbar_entries') == 'yes' ? TRUE : FALSE; + $menu_items = get_register('menu'); + $featured_urls_info = get_config('menu_items_featured_urls'); + $toolbar = array(); + $featured_urls = array(); + $featured_urls_sanitised = array(); + + // easier to compare with in_array() than embedded foreach()es + $valid_urls = array(); + foreach ($menu_items as $info) { + $valid_urls[] = $info->value->url; + } + + // make sure the url is a valid link. + // this prevents disabled plugins leaving behind + // valid links when no using a pagehandler. + foreach ($featured_urls_info as $info) { + if (in_array($info->value->url, $valid_urls)) { + $featured_urls[] = $info->value->url; + $featured_urls_sanitised[] = $info; + } + } + + // add toolbar entries if not hiding dupes. + foreach ($menu_items as $name => $info) { + if (!($hide_toolbar_dupes && in_array($info->value->url, $featured_urls))) { + $toolbar[] = $info; + } + } + + $CONFIG->menu_items = array( + 'featured_urls' => $featured_urls_sanitised, + 'toolbar' => $toolbar + ); +} + /** * Some useful constant definitions */ @@ -2898,4 +2947,6 @@ define('ELGG_ENTITIES_NO_VALUE', 0); register_elgg_event_handler('init', 'system', 'elgg_init'); register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000); -register_plugin_hook('unit_test', 'system', 'elgg_api_test'); \ No newline at end of file +register_plugin_hook('unit_test', 'system', 'elgg_api_test'); + +register_elgg_event_handler('pagesetup', 'system', 'ui_page_setup', 1000); \ No newline at end of file diff --git a/engine/lib/users.php b/engine/lib/users.php index a0bdeabc5..46ccd8dc3 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -1628,7 +1628,7 @@ function users_init() { // add Friends to tools menu - if profile mod is running if ( isloggedin() && is_plugin_enabled('profile') ) { $user = get_loggedin_user(); - add_menu(elgg_echo('friends'), $CONFIG->wwwroot . "pg/friends/" . $user->username); + add_menu(elgg_echo('friends'), $CONFIG->wwwroot . "pg/friends/" . $user->username, array(), 'core:friends'); } register_page_handler('friends', 'friends_page_handler'); diff --git a/languages/en.php b/languages/en.php index a84000039..f93e6c655 100644 --- a/languages/en.php +++ b/languages/en.php @@ -510,6 +510,11 @@ To remove a widget drag it back to the Widget gallery.", 'admin:user:removeadmin:yes' => "User is no longer an admin.", 'admin:user:removeadmin:no' => "We could not remove administrator privileges from this user.", + 'admin:menu_items' => 'Menu Items', + 'admin:menu_items:description' => 'Select which menu items you want to show as featured links. You can optionally remove these items from the dropdown menu.', + 'admin:menu_items:hide_toolbar_entries' => 'Remove links from tool bar menu?', + 'admin:menu_items:saved' => 'Menu items saved.', + /** * User settings */ diff --git a/views/default/admin/menu_items.php b/views/default/admin/menu_items.php new file mode 100644 index 000000000..68f3688d8 --- /dev/null +++ b/views/default/admin/menu_items.php @@ -0,0 +1,61 @@ + $info) { + $menu_sorted[$info->name] = $info->value->url; +} + +ksort($menu_sorted); + +$pulldown_values = array_flip($menu_sorted); +$pulldown_values[''] = elgg_echo('none'); + +echo elgg_view_title(elgg_echo('admin:menu_items')); +echo elgg_view('output/longtext', array('value' => elgg_echo("admin:menu_items:description"))); + +$form_body = ''; + +// @todo Could probably make this number configurable +for ($i=0; $i<7; $i++) { + if (array_key_exists($i, $featured_urls)) { + $current_value = $featured_urls[$i]->value->url; + } else { + $current_value = ''; + } + + $form_body .= elgg_view('input/pulldown', array( + 'options_values' => $pulldown_values, + 'internalname' => 'featured_urls[]', + 'value' => $current_value + )); +} +$form_body .= '

'; +$form_body .= ''; +$form_body .= elgg_view('input/pulldown', array( + 'internalname' => 'menu_items_hide_toolbar_entries', + 'internalid' => 'menu_items_hide_toolbar_entries', + 'value' => get_config('menu_items_hide_toolbar_entries'), + 'options_values' => array( + 'yes' => elgg_echo('option:yes'), + 'no' => elgg_echo('option:no') +))); + +$form_body .= '

'; +$form_body .= elgg_view('input/submit', array('value' => elgg_echo('save'))); + +echo elgg_view('input/form', array( + 'body' => $form_body, + 'action' => "{$vars['url']}action/admin/menu_items" +)); \ No newline at end of file diff --git a/views/default/navigation/site_nav.php b/views/default/navigation/site_nav.php index 8431188d8..965eb7e63 100644 --- a/views/default/navigation/site_nav.php +++ b/views/default/navigation/site_nav.php @@ -2,67 +2,21 @@ /** * Main site-wide navigation **/ - -echo "
"; -echo " +
'; \ No newline at end of file diff --git a/views/default/navigation/topbar_tools.php b/views/default/navigation/topbar_tools.php index 0e0eec097..2e48a4a85 100644 --- a/views/default/navigation/topbar_tools.php +++ b/views/default/navigation/topbar_tools.php @@ -9,8 +9,7 @@ * @link http://elgg.org/ * */ - -$menu = get_register('menu'); +$menu = $vars['config']->menu_items['toolbar']; if (is_array($menu) && sizeof($menu) > 0) { $alphamenu = array(); @@ -26,7 +25,7 @@ if (is_array($menu) && sizeof($menu) > 0) {