aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-05-10 16:00:52 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-05-10 16:00:52 +0000
commit37446557462b35b5c6690f7f8f739c4dd861b85b (patch)
treeef72ca9f73bf31583350af4cb174f1a6c0ff3bab /engine
parentf40da8fcaaeb193b155f8e51081bcaef468d9770 (diff)
downloadelgg-37446557462b35b5c6690f7f8f739c4dd861b85b.tar.gz
elgg-37446557462b35b5c6690f7f8f739c4dd861b85b.tar.bz2
Admin area now uses standard submenu tools.
git-svn-id: http://code.elgg.org/elgg/trunk@5992 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/admin.php139
-rw-r--r--engine/lib/elgglib.php20
-rw-r--r--engine/tests/ui/submenu.php26
3 files changed, 109 insertions, 76 deletions
diff --git a/engine/lib/admin.php b/engine/lib/admin.php
index 73e891332..81ef69baf 100644
--- a/engine/lib/admin.php
+++ b/engine/lib/admin.php
@@ -34,54 +34,75 @@ function extend_elgg_admin_page($new_admin_view, $view = 'admin/main', $priority
}
/**
- * Add an admin area section or child section (aka tab).
+ * Calculate the plugin settings submenu.
+ * This is done in a separate function called from the admin
+ * page handler because of performance concerns.
*
- * Used in conjuction with http://elgg.org/admin/section/child_section style
- * page handler.
- *
- * @param string $section_id Globally unique section id.
- * @param string $section_title Human readable section title.
- * @param string $parent_id If a child section, the parent section id. Cannot have grandchildren.
*/
-function elgg_add_admin_section($section_id, $section_title, $parent_id = NULL) {
+function elgg_admin_add_plugin_settings_sidemenu() {
global $CONFIG;
- if (!isset($CONFIG->admin_sections)) {
- $CONFIG->admin_sections = array();
+ if (!$installed_plugins = get_installed_plugins()) {
+ // nothing added because no items
+ return FALSE;
}
- // have to support adding a child section to a missing parent
- // because of plugin order problems. A plugin can extend
- // an admin section added by different plugin lower in the load priority.
- if ($parent_id) {
- if (!isset($CONFIG->admin_sections[$parent_id])) {
- $CONFIG->admin_sections[$parent_id] = array('children' => array());
- }
+ $parent_item = array(
+ 'text' => elgg_echo('admin:plugin_settings'),
+ 'id' => 'admin:plugin_settings'
+ );
+
+ elgg_add_submenu_item($parent_item, 'admin');
- if (!isset($CONFIG->admin_sections[$parent_id][$section_id])) {
- $CONFIG->admin_sections[$parent_id]['children'][$section_id] = array('title' => $section_title);
- return TRUE;
- } else {
- return FALSE;
+ foreach ($installed_plugins as $plugin_id => $info) {
+ if (!$info['active']) {
+ continue;
}
- } else {
- // children can be defined before parents
- if (!isset($CONFIG->admin_sections[$section_id])) {
- $CONFIG->admin_sections[$section_id] = array(
- 'title' => $section_title,
- 'children' => array()
- );
- return TRUE;
- } else {
- // allow to define this since children can be defined before the parent.
- $CONFIG->admin_sections[$section_id] = array(
- 'title' => $section_title
+
+ if (elgg_view_exists("settings/{$plugin_id}/edit")) {
+ $item = array(
+ 'text' => $info['manifest']['name'],
+ 'href' => "{$CONFIG->url}pg/admin/plugin_settings/$plugin_id",
+ 'parent_id' => 'admin:plugin_settings'
);
+
+ elgg_add_submenu_item($item, 'admin');
}
}
}
/**
+ * Add an admin area section or child section.
+ * This is a wrapper for elgg_add_admin_item(array(...), 'admin').
+ *
+ * Used in conjuction with http://elgg.org/admin/section_id/child_section style
+ * page handler.
+ *
+ * @param string $section_id
+ * @param string $section_title Human readable section title.
+ * @param string $parent_id If a child section, the parent section id.
+ */
+function elgg_add_admin_submenu_item($section_id, $section_title, $parent_id = NULL) {
+ global $CONFIG;
+
+ // in the admin section parents never have links
+ if ($parent_id) {
+ $href = "{$CONFIG->url}pg/admin/$parent_id/$section_id";
+ } else {
+ $href = NULL;
+ }
+
+ $item = array(
+ 'text' => $section_title,
+ 'href' => $href,
+ 'id' => $section_id,
+ 'parent_id' => $parent_id
+ );
+
+ return elgg_add_submenu_item($item, 'admin');
+}
+
+/**
* Initialise the admin page.
*/
function admin_init() {
@@ -99,31 +120,30 @@ function admin_init() {
register_action('admin/plugins/simple_update_states', FALSE, '', TRUE);
-
// admin area overview and basic site settings
- elgg_add_admin_section('overview', elgg_echo('admin:overview'));
- elgg_add_admin_section('site', elgg_echo('admin:site'));
- elgg_add_admin_section('basic', elgg_echo('admin:site:basic'), 'site');
- elgg_add_admin_section('advanced', elgg_echo('admin:site:advanced'), 'site');
+ elgg_add_admin_submenu_item('overview', elgg_echo('admin:overview'));
+ elgg_add_admin_submenu_item('site', elgg_echo('admin:site'));
+ elgg_add_admin_submenu_item('basic', elgg_echo('admin:site:basic'), 'admin:overview:site');
+ elgg_add_admin_submenu_item('advanced', elgg_echo('admin:site:advanced'), 'admin:overview:site');
// appearance
- elgg_add_admin_section('appearance', elgg_echo('admin:appearance'));
- //elgg_add_admin_section('basic', elgg_echo('admin:appearance'), 'appearance');
- elgg_add_admin_section('menu_items', elgg_echo('admin:menu_items'), 'appearance');
+ elgg_add_admin_submenu_item('appearance', elgg_echo('admin:appearance'));
+ //elgg_add_admin_submenu_item('basic', elgg_echo('admin:appearance'), 'appearance');
+ elgg_add_admin_submenu_item('menu_items', elgg_echo('admin:menu_items'), 'appearance');
// users
- elgg_add_admin_section('users', elgg_echo('admin:users'));
- elgg_add_admin_section('online', elgg_echo('admin:users:online'), 'users');
- elgg_add_admin_section('add', elgg_echo('admin:users:add'), 'users');
- elgg_add_admin_section('find', elgg_echo('admin:users:find'), 'users');
+ elgg_add_admin_submenu_item('users', elgg_echo('admin:users'));
+ elgg_add_admin_submenu_item('online', elgg_echo('admin:users:online'), 'users');
+ elgg_add_admin_submenu_item('add', elgg_echo('admin:users:add'), 'users');
+ elgg_add_admin_submenu_item('find', elgg_echo('admin:users:find'), 'users');
// plugins
- elgg_add_admin_section('plugins', elgg_echo('admin:plugins'));
- elgg_add_admin_section('simple', elgg_echo('admin:plugins:simple'), 'plugins');
- elgg_add_admin_section('advanced', elgg_echo('admin:plugins:advanced'), 'plugins');
+ elgg_add_admin_submenu_item('plugins', elgg_echo('admin:plugins'));
+ elgg_add_admin_submenu_item('simple', elgg_echo('admin:plugins:simple'), 'plugins');
+ elgg_add_admin_submenu_item('advanced', elgg_echo('admin:plugins:advanced'), 'plugins');
// handled in the admin sidemenu so we don't have to generate this on every page load.
- //elgg_add_admin_section('plugin_settings', elgg_echo('admin:plugin_settings'));
+ //elgg_add_admin_submenu_item('plugin_settings', elgg_echo('admin:plugin_settings'));
register_page_handler('admin', 'admin_settings_page_handler');
}
@@ -138,6 +158,8 @@ function admin_settings_page_handler($page) {
global $CONFIG;
admin_gatekeeper();
+ elgg_admin_add_plugin_settings_sidemenu();
+ set_context('admin');
// default to overview
if (!isset($page[0]) || empty($page[0])) {
@@ -169,7 +191,18 @@ function admin_settings_page_handler($page) {
$content = elgg_echo('admin:unknown_section');
}
- $body = elgg_view('admin/components/admin_page_layout', array('content' => $content, 'page' => $page));
+ //$body = elgg_view('admin/components/admin_page_layout', array('content' => $content, 'page' => $page));
+
+ $notices_html = '';
+ if ($notices = elgg_get_admin_notices()) {
+ foreach ($notices as $notice) {
+ $notices_html .= elgg_view_entity($notice);
+ }
+
+ $content = "<div class=\"admin_notices\">$notices_html</div>$content";
+ }
+
+ $body = elgg_view_layout('one_column_with_sidebar', $content);
page_draw($title, $body);
}
@@ -179,7 +212,7 @@ function admin_settings_page_handler($page) {
* The id is a unique ID that can be cleared once the admin
* completes the action.
*
- * eg: add_admin_notice('twitter_service_no_api',
+ * eg: add_admin_notice('twitter_services_no_api',
* 'Before your users can use Twitter services on this site, you must set up
* the Twitter API key in the <a href="link">Twitter Services Settings</a>');
*
@@ -198,7 +231,7 @@ function elgg_add_admin_notice($id, $message) {
return $admin_notice->save();
}
- return false;
+ return FALSE;
}
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 1c0d1cfc1..8d41de1cc 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -910,7 +910,7 @@ function add_submenu_item($label, $link, $group = 'default', $onclick = false, $
$item = array(
'text' => $label,
- 'url' => $link,
+ 'href' => $link,
'selected' => $selected
);
@@ -1003,7 +1003,7 @@ function elgg_add_submenu_item(array $item, $context = 'all', $group = 'default'
* @param bool $sort Sort the menu items alphabetically
* @since 1.8
*/
-function elgg_prepare_submenu($context = 'main', $sort = TRUE) {
+function elgg_prepare_submenu($context = 'main', $sort = FALSE) {
global $CONFIG;
if (!isset($CONFIG->submenu_items) || !($CONFIG->submenu_items)) {
@@ -1052,9 +1052,9 @@ function elgg_prepare_submenu($context = 'main', $sort = TRUE) {
}
// if the parent doesn't have a url, make it the first child item.
- if (isset($item->children) && $item->children && !$item->url) {
+ if (isset($item->children) && $item->children && !$item->href) {
$child = $item->children[0];
- while ($child && !isset($child->url)) {
+ while ($child && !isset($child->href)) {
if (isset($child->children) && isset($child->children[0])) {
$child = $child->children[0];
} else {
@@ -1062,11 +1062,11 @@ function elgg_prepare_submenu($context = 'main', $sort = TRUE) {
}
}
- if ($child && isset($child->url)) {
- $item->url = $child->url;
+ if ($child && isset($child->href)) {
+ $item->href = $child->href;
} else {
// @todo There are no URLs anywhere in this tree.
- $item->url = $CONFIG->url;
+ $item->href = $CONFIG->url;
}
}
}
@@ -1139,14 +1139,14 @@ function elgg_get_submenu($context = NULL, $sort = FALSE) {
while ($item = current($items)) {
$t = '';
// ignore parents created by a child but parent never defined properly
- if (!isset($item->text) || !isset($item->url) || !($item->text) || !($item->url)) {
+ if (!isset($item->text) || !isset($item->href) || !($item->text) || !($item->href)) {
next($items);
continue;
}
// try to guess if this should be selected if they don't specify
- if ((!isset($item->selected) || $item->selected === NULL) && isset($item->url)) {
- $item->selected = elgg_http_url_is_identical($_SERVER['REQUEST_URI'], $item->url);
+ if ((!isset($item->selected) || $item->selected === NULL) && isset($item->href)) {
+ $item->selected = elgg_http_url_is_identical($_SERVER['REQUEST_URI'], $item->href);
}
// traverse up the parent tree if matached to mark all parents as selected/expanded.
diff --git a/engine/tests/ui/submenu.php b/engine/tests/ui/submenu.php
index d7a156417..745364890 100644
--- a/engine/tests/ui/submenu.php
+++ b/engine/tests/ui/submenu.php
@@ -20,7 +20,7 @@ $url = "{$CONFIG->url}engine/tests/ui/submenu.php";
$items = array(
array(
'text' => 'Upper level 1',
- 'url' => "$url?upper_level_1",
+ 'href' => "$url?upper_level_1",
'id' => 'ul1'
),
array(
@@ -30,50 +30,50 @@ $items = array(
),
array(
'text' => 'Sub CD',
- 'url' => "$url?sub_cd",
+ 'href' => "$url?sub_cd",
'parent_id' => 'cd'
),
array(
'text' => 'Cup',
- 'url' => "$url?cup",
+ 'href' => "$url?cup",
'id' => 'cup'
),
array(
'text' => 'Phone',
- 'url' => "$url?phone",
+ 'href' => "$url?phone",
'id' => 'phone',
'parent_id' => 'cup'
),
array(
'text' => 'Wallet',
- 'url' => "$url?wallet",
+ 'href' => "$url?wallet",
'id' => 'wallet',
'parent_id' => 'phone'
),
array(
'text' => 'Upper level',
- 'url' => "$url?upper_level",
+ 'href' => "$url?upper_level",
'id' => 'ul'
),
array(
'text' => 'Sub Upper level',
- 'url' => "$url?sub_upper_level",
+ 'href' => "$url?sub_upper_level",
'parent_id' => 'ul'
),
array(
'text' => 'Root',
- 'url' => $url,
+ 'href' => $url,
),
array(
'text' => 'I am an orphan',
- 'url' => 'http://google.com',
+ 'href' => 'http://google.com',
'parent_id' => 'missing_parent'
),
array(
'text' => 'JS Test',
- 'url' => 'http://elgg.org',
+ 'href' => 'http://elgg.org',
'vars' => array('js' => 'onclick="alert(\'Link to \' + $(this).attr(\'href\') + \'!\'); return false;"')
)
);
@@ -86,10 +86,10 @@ add_submenu_item('Old Onclick Test', 'http://elgg.com', NULL, TRUE);
add_submenu_item('Old Selected Test', 'http://elgg.com', NULL, '', TRUE);
-elgg_add_submenu_item(array('text' => 'Not Main Test', 'url' => "$url?not_main_test"), 'not_main', 'new_menu');
-elgg_add_submenu_item(array('text' => 'Not Main C Test', 'url' => "$url?not_main_c_test"), 'not_main', 'new_menu');
+elgg_add_submenu_item(array('text' => 'Not Main Test', 'href' => "$url?not_main_test"), 'not_main', 'new_menu');
+elgg_add_submenu_item(array('text' => 'Not Main C Test', 'href' => "$url?not_main_c_test"), 'not_main', 'new_menu');
-elgg_add_submenu_item(array('text' => 'All test', 'url' => "$url?all"), 'all');
+elgg_add_submenu_item(array('text' => 'All test', 'href' => "$url?all"), 'all');
//set_context('not_main');