SimplePortal

Customization => Custom Coding => Topic started by: MomemtumMori on July 14, 2011, 09:03:02 PM

Title: List pages in the menu
Post by: MomemtumMori on July 14, 2011, 09:03:02 PM
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
Code: [Select]
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 ;)
SimplePortal 2.3.8 © 2008-2024, SimplePortal