SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: rathsrants on August 12, 2010, 12:53:36 PM

Title: Menu Block Request
Post by: rathsrants on August 12, 2010, 12:53:36 PM
Here is what I am trying to do.

I am trying to build a navigation menu that uses images but only displays the ones that a user has permissions for. Pretty sure this would have to be done through the Custom PHP Block.

My current menu is built in a Custom HTML Block.

Example of my menu (member not logged in)
(http://www.ddcgaming.com/site/images/menu_top.png)
(http://www.ddcgaming.com/site/images/menu_home.png)
(http://www.ddcgaming.com/site/images/menu_bottom.png)

Member logged in would see extra options
(http://www.ddcgaming.com/site/images/menu_top.png)
(http://www.ddcgaming.com/site/images/menu_home.png)
(http://www.ddcgaming.com/site/images/menu_forum.png)
(http://www.ddcgaming.com/site/images/menu_gallery.png)
(http://www.ddcgaming.com/site/images/menu_bottom.png)

A basic example would be great to I could get this work.

Thanks Carrissis
Title: Re: Menu Block Request
Post by: excaliburj on August 12, 2010, 02:00:28 PM
I have a custom (php) menu block which only uses text links, but I think it'll give you the right idea:

Code: [Select]
global $context, $settings, $options, $scripturl, $txt, $modSettings, $user_info, $db_prefix, $smcFunc;

// Shows for everybody
echo '<a href="', $scripturl, '?action=links">Links</a><br />';
echo '<a href="', $scripturl, '?action=contact">Contact Webmaster</a>';

// Guests
if ($user_info['is_guest']) {
echo '<center>';
echo '<strong>Registration requires a <u>valid</u>, <u>active</u> email address!!!</strong><br />';
echo '</center>';
echo '<hr>';
}

// Logged in Users (with one line checking for membergroup 13)
if (!$user_info['is_guest']) {
echo '<a href="', $scripturl, '?action=dxrecent;style=full;type=last">Topics - Last 50  </a><br />';
echo '<a href="', $scripturl, '?action=dxrecent;style=full;type=hours">Topics - Last 24 hrs</a><br />';
echo '<a href="', $scripturl, '?action=dxrecent;style=full;type=notify">Topics - You\'re Watching</a><br />';
echo '<a href="', $scripturl, '?action=dxrecent;style=full;type=bookmark">Topics - You\'ve Bookmarked</a><br />';
if (in_array(13, $user_info['groups'])) {
echo '<a href="', $scripturl, '?action=dxrecent;style=full;type=unreplied">Topics - Unreplied</a><br />';
}

// Admin only
if ($user_info['is_admin']) {
echo '<a href="', $scripturl , '?action=admin;area=viewmembers;sa=browse;type=activate', '">', sprintf($txt['admin_browse_awaiting_activate'], $context['awaiting_activation']), '</a><br />';
}


You may not need all the entries in the 'global' line (the above is plucked out of a larger block which includes the DB query to check if anyone is awaiting activation for that Admin option; among other things). But you can see the lines for guests, logged in users, admins, and one only for members of a certain membergroup.
Title: Re: Menu Block Request
Post by: ccbtimewiz on August 13, 2010, 12:10:26 AM
You don't need both $db_prefix and $smcFunc in those globals, even if there was queries requesting the information.

Actually now that I think about it... you don't even need to query that information at all as most of it is loaded through Load.php's MemberContext() function and can be subsequently found in the variable $context.

At any rate, excaliburj has the right idea. Simple boolean conditions or equal statements will get the job done. Though I recommend just using $context['user'] instead of $user_info. The less globals, the better. :)

Title: Re: Menu Block Request
Post by: ccbtimewiz on August 13, 2010, 12:20:35 AM
Oh... I completely forgot to show you an example I made (and I honestly don't feel like editing my previous post, I really detest that ugly "edited" line.

My example makes use of an array... similar to how MenuContext() works in Subs.php for SMF 2.0's tabs.

Code: [Select]
<?php

global $context$scripturl;
// can_see must be a boolean,
// possible keys in $context['user'] are 'is_admin', 'is_guest', 'is_logged', 'is_mod',
$buttons = array(
array(
'link' => $scripturl,
'image' => 'http://example.com/home.png'
'can_see' => true,
),
array(
'link' => $scripturl '?action=forum',
'image' => 'http://example.com/forum.png'
'can_see' => $context['user']['is_logged'],
),
array(
'link' => $scripturl '?action=admin',
'image' => 'http://example.com/admin.png'
'can_see' => $context['user']['is_admin'],
),
);

foreach (
$buttons as $button)
{
if ($button['can_see'])
echo '
<a href="' 
$button['link'] . '"><img src="' $button['image'] . '" alt="" title="" /></a>';
}

?>
Title: Re: Menu Block Request
Post by: rathsrants on August 13, 2010, 07:22:54 AM
Thanks I will check that out tonight after work.
SimplePortal 2.3.8 © 2008-2024, SimplePortal