diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-03-17 19:09:09 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-03-17 19:09:09 +0000 |
commit | ff6f2152bb6f0a759bffbcc213a82aecc0237ae6 (patch) | |
tree | a0ed026661677ab315069274ca05f7395e6248c5 | |
parent | 99d5f4b0d22e99109da860dd9118265c883a668e (diff) | |
download | elgg-ff6f2152bb6f0a759bffbcc213a82aecc0237ae6.tar.gz elgg-ff6f2152bb6f0a759bffbcc213a82aecc0237ae6.tar.bz2 |
Added config options for tabs and menu items.
git-svn-id: http://code.elgg.org/elgg/trunk@5431 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/admin/menu_items.php | 36 | ||||
-rw-r--r-- | admin/menu_items.php | 21 | ||||
-rw-r--r-- | engine/lib/admin.php | 17 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 57 | ||||
-rw-r--r-- | engine/lib/users.php | 2 | ||||
-rw-r--r-- | languages/en.php | 5 | ||||
-rw-r--r-- | views/default/admin/menu_items.php | 61 | ||||
-rw-r--r-- | views/default/navigation/site_nav.php | 76 | ||||
-rw-r--r-- | views/default/navigation/topbar_tools.php | 5 |
9 files changed, 202 insertions, 78 deletions
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 @@ +<?php +/** + * Save menu items. + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + */ + +$featured_urls = get_input('featured_urls', array()); +$hide_toolbar_entries = get_input('menu_items_hide_toolbar_entries', 'yes'); +$featured_url_info = array(); + +// save the full information from the menu item into the config table +// this will be checked upon display that it is still valid (based upon url) +$menu_items = get_register('menu'); +$menu_urls = array(); + +foreach ($menu_items as $name => $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 @@ +<?php +/** + * Elgg administration menu items + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + */ + +require_once(dirname(dirname(__FILE__)) . "/engine/start.php"); +admin_gatekeeper(); + +$vars = array( + 'menu_items' => 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); } /** @@ -2885,6 +2890,50 @@ function elgg_api_test($hook, $type, $value, $params) { } /** + * 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 */ define('ACCESS_DEFAULT', -1); @@ -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 <b>Widget gallery</b>.", '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 @@ +<?php +/** + * Elgg administration menu items + * + * @package Elgg + * @subpackage Core + * @author Curverider Ltd + * @link http://elgg.org/ + */ + +$menu_items = $vars['menu_items']; +$featured_urls = get_config('menu_items_featured_urls'); + +// get an alphabetical sort of the items + urls +foreach ($menu_items as $name => $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 .= '<br /><br />'; +$form_body .= '<label for="menu_items_hide_toolbar_entries">' + . elgg_echo('admin:menu_items:hide_toolbar_entries') . '</label>'; +$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 .= '<br /><br />'; +$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 "<div id='elgg_main_nav' class='clearfloat'>"; -echo "<ul class='navigation'>"; -if(is_plugin_enabled('riverdashboard')){ - if(get_context() == 'riverdashboard') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}mod/riverdashboard/\" title='Activity'><span>Activity</span></a></li>"; -} -if(is_plugin_enabled('thewire') && isloggedin()){ - if(get_context() == 'thewire') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}mod/thewire/everyone.php\" title='The Wire'><span>" . elgg_echo('thewire:title') . "</span></a></li>"; -} -if(is_plugin_enabled('conversations') && isloggedin()){ - if(get_context() == 'conversations') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}mod/conversations/all.php\" title='Conversations'><span>" . elgg_echo('conversations') . "</span></a></li>"; -} -if(is_plugin_enabled('blog')){ - if(get_context() == 'blog') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}mod/blog/all.php\" title='Blogs'><span>Blogs</span></a></li>"; -} -if(is_plugin_enabled('pages')){ - if(get_context() == 'pages') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}mod/pages/all.php\" title='Pages'><span>Pages</span></a></li>"; -} -if(is_plugin_enabled('file')){ - if(get_context() == 'file') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}pg/file/world/world/\" title='Files'><span>Files</span></a></li>"; -} -if(is_plugin_enabled('bookmarks')){ - if(get_context() == 'bookmarks') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}mod/bookmarks/all.php\" title='Bookmarks'><span>Bookmarks</span></a></li>"; -} -if(is_plugin_enabled('groups')){ - if(get_context() == 'groups') - $selected = 'class="selected"'; - else - $selected = ""; - echo "<li {$selected}><a href=\"{$vars['url']}pg/groups/world/\" title='Groups'><span>". elgg_echo('groups') . "</span></a></li>"; +$featured = $vars['config']->menu_items['featured_urls']; +$current_context = get_context(); + +echo '<div id="elgg_main_nav" class="clearfloat"> + <ul class="navigation">'; + +foreach ($featured as $info) { + $selected = ($info->value->context == $current_context) ? 'class="selected"' : ''; + $title = htmlentities($info->name, ENT_QUOTES, 'UTF-8'); + $url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8'); + + echo "<li $selected><a href=\"$url\" title=\"$title\"><span>$title</span></a></li>"; } -echo "</ul>"; -echo "</div>"; -?>
\ No newline at end of file +echo ' + </ul> +</div>';
\ 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) { <ul> <?php foreach($alphamenu as $item) { - echo "<li><a href=\"{$item->value}\">" . $item->name . "</a></li>"; + echo "<li><a href=\"{$item->value->url}\">" . $item->name . "</a></li>"; } ?> </ul> |