TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 728
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 378
  • Total: 378

Conditional Block (probably the most useful block in the universe)

Started by akulion, February 01, 2007, 03:10:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

houston

Quote from: JPDeni on February 01, 2007, 10:18:37 PM
houston, you need an actual number instead of the # in


elseif (in_array(#, $user_info['groups']))


Something like


elseif (in_array(1, $user_info['groups']))


Thanks I will give it a try.

Cheers

Thurnok

Quote from: iowamf on February 01, 2007, 08:52:11 PM
Thurnok, I take it you don't use the Menu Manager in TinyPortal or did you modify the source code to apply the conditionals?

I use the menu manager in TinyPortal for some of my sites in addition to a php block that I create my own conditional menu within, and others where I do not use the TP Menu at all.  The example I showed was all a single php block menu.

If you use the TinyPortal menu, you are forced to make an all encompassing security check for the menu.  So basically, anyone you give permission to see the menu block, sees all the menu items.  Creating a php block and making your own conditional menu gives you a bit more flexibility, though makes you go through a bit more effort to setup and maintain.

Don't be surprised if you see this flexibility appear in the TP menu manager in the future however.  ;)


Thurnok

Quote from: iowamf on February 01, 2007, 09:00:59 PM
Why not use double quotes? Both of these will work, but the double quotes seems easier:

echo "something entered was: $some_string <br />";
// double quotes vs single quotes usage
echo 'env is '.$env.' action_string is '.$action_string.'<br />';


Development style is something that has been debated since the begining of programming.  For the most part, as long as you are consistent (except where it is prohibitive to be so), you will be fine.

I try to use single quotes for all my echo statements because I use an editor with syntax coloring.  So for myself, I prefer to see where I have variables being inserted into some text string by the very easily distinguished break in the quoted color of the line.  To illustrate what I mean, here's two examples of how my code would look shown in both ways:

// calculate how much they've won jay!
$dollars += $new_winnings;
if ($dollars <= 0){
   echo 'Sorry, but you are a total loser! - But we mean it in the nicest way.';
} else {
   echo 'Ok... we have an announcement! < br />';
   echo 'Are you ready?< br />';
   echo 'Well ready or not...< br />';
   echo 'You just won '.$new_winnings.' dollars!  Congratulations!';
   echo 'You now have '.$dollars.' dollars total!  Wow!';
   echo 'Now I bet you are glad we told you...< br />';
   echo 'Right?< br />';
}

// do some other stuff
// blah blah blah


vs.

// calculate how much they've won jay!
$dollars += $new_winnings;
if ($dollars <= 0){
   echo "Sorry, but you are a total loser! - But we mean it in the nicest way.";
} else {
   echo "Ok... we have an announcement! < br />";
   echo "Are you ready?< br />";
   echo "Well ready or not...< br />";
   echo "You just won $new_winnings dollars!  Congratulations!";
   echo "You now have $dollars dollars total!  Wow!";
   echo "Now I bet you are glad we told you...< br />";
   echo "Right?< br />";
}

// do some other stuff
// blah blah blah



So when I'm looking at my code, I can more readily see where my variables are being used... anyway... just my perspective.. everyone has their own coding style, its the one that works for you that really matters.  ;)

iowamf

would you mind posting the php for your example? (thanks)

Contrary to the title of this thread, a conditional block (and menu) is quite useful.

Quote from: Thurnok on February 02, 2007, 04:10:32 AM
Quote from: iowamf on February 01, 2007, 08:52:11 PM
Thurnok, I take it you don't use the Menu Manager in TinyPortal or did you modify the source code to apply the conditionals?

The example I showed was all a single php block menu.


bloc

Conditional content is useful, and it works splendid in php blocks. But since its so much one can do wih it, its hard to specify a blocktype using it. Simply becasue its limited only by php itself.

If we were to use multiple blocks for this rather than everything in one block, it would mean to create 3 blocks that were shown just for members, guests and a certain membergroup. That might be more manageble ..but also means that control over what-is-what is needed. And admin sees them all lol :) That is something I need to correct, or supply a setting to turn off.

bloc

On second thought - grouping of blocks would be helpful. Having for example 4-5 blocks that only showed for different people, but in the same spot, could be grouped and hidden aprt from the first. One click and they could unfold to show themselves.

Thurnok

@iowamf
If you mean the php block for the menu I used as an example, sure, here it is:


global  $scripturl, $context, $user_info;
////////////////////////////////////////////////////
// ALL USERS  -  Including Guests
////////////////////////////////////////////////////
echo '
<div class="smalltext">
<b>General</b><br /><hr />
<font size="2">
<a href="'.$scripturl.'"> Home</a><br />
<a href="'.$scripturl.'?action=forum"> Forum</a><br />
<a href="'.$scripturl.'?cat=155"> Member Chronicles</a><br />
</font><br />';

////////////////////////////////////////////////////
// REGISTERED USERS ONLY
////////////////////////////////////////////////////
if ($context['user']['is_logged']){
echo '
<b>Members</b><br /><hr />
<font size="2">
<a href="'.$scripturl.'?action=pm"> My Messages</a><br />
<a href="'.$scripturl.'?action=profile"> My Profile</a><br />
<a href="'.$scripturl.'?page=15"> My Custom Page</a><br />';

if ($context['allow_calendar']){
echo '
<a href="'.$scripturl.'?action=calendar"> KoN Calendar</a><br />';
}

echo '
<a href="'.$scripturl.'?action=mlist"> Member List</a><br />
<a href="'.$scripturl.'?action=who"> Who\'s Online?</a><br />
<a href="'.$scripturl.'?action=stats"> Statistics</a><br />
<a href="'.$scripturl.'?action=search"> Search</a><br />
<a href="'.$scripturl.'?action=help"> Help Center</a><br />
</font><br />';
}

////////////////////////////////////////////////////
// KON MEMBERS ONLY  -  (group 14)
////////////////////////////////////////////////////
if (in_array(14, $user_info['groups']) || $context['user']['is_admin']){
echo '
<b>KoN Menu</b><br /><hr />
<font size="2">
<a href="'.$scripturl.'?action=tpmod;dl=0"> Downloads</a><br />
<a href="'.$scripturl.'?page=10"> Personal Calendar</a><br />
<a href="'.$scripturl.'?action=tpmod;sa=submitarticle"> Submit Article</a><br />
</font><br />';
}

////////////////////////////////////////////////////
// ALL USERS  -  Including Guests
////////////////////////////////////////////////////
echo '
<b>Utils</b><br /><hr />
<font size="2">
<a href="'.$scripturl.'?page=14"> Random Password</a><br />
</font><br />';

////////////////////////////////////////////////////
// ALL USERS  -  Including Guests
////////////////////////////////////////////////////
echo '
<b>Other Sites</b><br /><hr />
<font size="2">
<a href="http://tpblocks.ccs-net.com" target="_blank"> Thurnok\'s TP Blocks</a><br />
<a href="http://www.ccs-net.com/guilds/justice" target="_blank"> Justice Website</a><br />
<a href="http://www.ccs-net.com/guilds/divine" target="_blank"> Divine Website</a><br />
</font><br />';

////////////////////////////////////////////////////
// ADMINS ONLY
////////////////////////////////////////////////////
if ($context['user']['is_admin']){
echo '
<b>Admin</b><br /><hr />
<font size="2">
<a href="'.$scripturl.'?action=admin"> Admin Panel</a><br />
</font><br />';
}

echo'</div>';

Lord Anubis

This is useful, but I am having a problem...

Okay I have a VIP section, and I want the VIP (non-post based member group) to see "Thanks for your support"

and I want non-VIP to see, "Subscribe here"

Well the issue comes with the post based group, when a VIP member has "Thanks for your support" since they also are in a post based group it will still show "Subscribe here"

Is there a way for it to differentiate between the non-post based group and the post based membergroup, so that it doesn't do this?

satcom

Hello to all ,
This question is in the wrong thread I'm sure but i'll give it a go.

What I want to do is in Thurnok's random picture gallery, which I'll put in a center block and say have 3 latest pictures. I'd like to have a title up the top in the same block above the pics (centered) or an image of fancy text eg. Members photo gallery - latest photos.

How would I do this ?
I can put echo '< br />'; before the script to get it away from the top edge
so it looks a bit more even thats about it. I just cant work out how to put text or an image in there.


thanks- darren

Hairy

Quote from: Lord Anubis on September 13, 2007, 08:31:36 PM
This is useful, but I am having a problem...

Okay I have a VIP section, and I want the VIP (non-post based member group) to see "Thanks for your support"

and I want non-VIP to see, "Subscribe here"

Well the issue comes with the post based group, when a VIP member has "Thanks for your support" since they also are in a post based group it will still show "Subscribe here"

Is there a way for it to differentiate between the non-post based group and the post based membergroup, so that it doesn't do this?

This should do what you want, just replace the "#" with the VIP membergroup number and the http:// links to the place for them to subscribe.

    if ($user_info['is_guest'])
    echo '<a href=http://yoursite.com/index.php?action=register> Subscribe Here!</a><br/><br/>';

    elseif (in_array(#, $user_info['groups']))
    echo ' Thanks For Your Support!<br/><br/>';

    else
    echo '<a href=http://yoursite.com/index.php?action=register> Subscribe Here!</a><br/><br/>';

This website is proudly hosted on Crocweb Cloud Website Hosting.