Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 1304
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

List pages in the menu

Started by MomemtumMori, July 14, 2011, 09:03:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MomemtumMori

I just completed this handy edit which lists pages into the menu bar and I tought it would benefit to some people since I have been looking for something similar for some time now.

It query the db to lists the first 10 pages,
displays them in the menu bar at the end, but before the logout/login button and
it checks permission to only display pages the user is allowed to see in the menu.

The only modified file is Sources/Subs.php
function setupMenuContext()
{
// [...] The begining stays the same

// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'] . '-' . empty($context['disable_sp']), $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])
{
/* EDIT - START - */
$request = $smcFunc['db_query']('', '
SELECT title, namespace, allowed_groups, permission_type
FROM {db_prefix}sp_pages
LIMIT 10'
);

$pages = array();
while ($row = $smcFunc['db_fetch_row']($request))
            $pages[$row[0]] = array(
'title' => $row[0],
'href' => $scripturl . '/page,' . $row[1] . '.html',
'show' => sp_allowed_to('page', $row[1], $row[2], $row[3]),
'sub_buttons' => array(
),
);

$smcFunc['db_free_result']($request);
/* EDIT - END - */

$buttons = array(
'home' => array(
'title' => $txt['home'],
'href' => $modSettings['sp_portal_mode'] == 3 && empty($context['disable_sp']) ? $modSettings['sp_standalone_url'] : $scripturl,
'show' => true,
'sub_buttons' => array(
),
'is_last' => $context['right_to_left'],
),

// [...] Other buttons

'mlist' => array(
'title' => $txt['members_title'],
'href' => $scripturl . '?action=mlist',
'show' => $context['allow_memberlist'],
'sub_buttons' => array(
'mlist_view' => array(
'title' => $txt['mlist_menu_view'],
'href' => $scripturl . '?action=mlist',
'show' => true,
),
'mlist_search' => array(
'title' => $txt['mlist_search'],
'href' => $scripturl . '?action=mlist;sa=search',
'show' => true,
'is_last' => true,
),
),
),
);

/* EDIT - START - */
$buttons_end = array(
'login' => array(
'title' => $txt['login'],
'href' => $scripturl . '?action=login',
'show' => $user_info['is_guest'],
'sub_buttons' => array(
),
),
'register' => array(
'title' => $txt['register'],
'href' => $scripturl . '?action=register',
'show' => $user_info['is_guest'],
'sub_buttons' => array(
),
'is_last' => !$context['right_to_left'],
),
'logout' => array(
'title' => $txt['logout'],
'href' => $scripturl . '?action=logout;%1$s=%2$s',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
'is_last' => !$context['right_to_left'],
),
);

$buttons = array_merge($buttons, $pages, $buttons_end);
/* EDIT - END - */

// Allow editing menu buttons easily.
call_integration_hook('integrate_menu_buttons', array(&$buttons));

// [...] Rest of the function is unchanged
}


And again, I hope this helps somebody ;)