TinyPortal

Development => Block Codes => Topic started by: akulion on February 01, 2007, 03:10:58 PM

Title: Conditional Block (probably the most useful block in the universe)
Post by: akulion on February 01, 2007, 03:10:58 PM
Hi,

This is something I learned about a year back from J.A.CORTINA down at SMF.

Its been repeated several times but it just saddens me to see that most people dont use it since it is a very powerful thing indeed!

Conditional Block

Type of block PHP

Position anywhere depending on content

Code

This is the general code for the block, I will attempt to explain it fully and give some  applications.



global $user_info;

if ($user_info['is_guest'])
echo 'CONTENT FOR GUESTS';

elseif (in_array(#, $user_info['groups']))
echo 'CONTENT FOR MEMBERS SPECIFIED';

else
echo 'CONTENT FOR OTHER MEMBERGROUPS NOT SPECIFIED ABOVE';


Replace the '#' in the 'in_array(#, $user_info['groups'])' with the number of the membergroup you want

Explanation
In the first part of the code goes any code you want which will only be displayed for guests...
example (http://path-to-peace.com/forum2): notice the red register banner and only 3 tabs displayed at the center welcome block? Well remember the layout because it is about to change...

In the 2nd part of the code you specify which membergroups can see what content, so for example you can put a seperate elseif statement for just your admin and mods, and then another one yet for VIP members and then another one for other membergroups.
Example (http://path-to-peace.com/forum2): Login using the username test and password test and see how the whole layout has changed. Remember the red register button? Its gone now! Also there are additional tabs for members and for guests there were only 3

3rd Part concludes the whole conditional statement block and can be used for everyone else who was not directly specified in the above statements. So we talked about guests, and mods and admins and VIP members- so here we put the content for everyone else which ever member group they may be in.
Example: not available because you have to be an admin or mod on my site to notice the difference, however I can just tell you that an additional menu appears for admins with quick links to common admin interface options

The End


Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: akulion on February 01, 2007, 03:15:06 PM
Understanding the Echo Statement

This is a mistake I would often make myself - and the mistake is not getting to know mr. Echo

Echo is your friend in SMF...so we must learn a few things about it.

1. echo basically prints whatever you put inside it on to your file AS IS. So it comes in handy for including scripts and text and other things in your pages.

Try this somewhere in a PHP block in TP
echo 'hello mr echo';
It will out put hello mr echo on your page as plain text

If you had put

echo 'hello <b>mr</b> echo';

The result would have been: hello mr echo
So it also can take html commands

2. Echo statements in SMF are used with single quotes '
EXAMPLE:
echo 'CONTENT FOR GUESTS';

The statement itself concludes(ends) with the ; sign. But the printing is concluded with a ' single quote.

But it is very important to understand one thing about the '
If you put a single quote anywhere in your code which you are echoing out, it will be recognized as a command to stop printing the info!

So if I put:
echo 'hello mr echo how's your wife?';

The above will give me an error, because I put a single quote in the how's
But that dosent mean we cant use any single quotes at all. We can, all we have to do is put a slash befoe it like this:

echo 'hello mr echo how\'s your wife?';
That way the ' will be ignored by your php processor.

This is a useful trick also to know when echoing out Java Script or other scripts which may be using single quotes in them.
All you would have to do is simply escape all the single quotes with a \

Example:

echo'
<a href="http://yoursite.com/mediaplayer/mp3player.html" onMouseOver="stm(Text[21],Style[1])" onMouseOut="htm()"  onclick="window.open(\'http://yoursite.com/mediaplayer/mp3player.html\',\'media\',\'height=405,width=310\'); return false;">
';


notice all the single quotes have been escaped with a \ before them.
Ofcourse the final one marks the end of the echo statement so we dont close that.

The End

PS: Im not some php expert, im just sharing the simple things I have learned :P
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: IchBin on February 01, 2007, 04:47:53 PM
I feel a doc coming on..... :D
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Ken. on February 01, 2007, 07:41:01 PM
Great lesson Aku, gave me a little more understanding of the codes we use for SMF & TP.

That thing about the back slash had been in something that I was working on earlier today, now I know what it was trying to do.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Thurnok on February 01, 2007, 07:49:42 PM
All my menus on my various sites use conditionals.

Example:
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: iowamf on February 01, 2007, 08:52:11 PM
Thanks for this thread.

Thurnok, I take it you don't use the Menu Manager in TinyPortal or did you modify the source code to apply the conditionals?

Quote from: Thurnok on February 01, 2007, 07:49:42 PM
All my menus on my various sites use conditionals.

Example:

Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: iowamf on February 01, 2007, 09:00:59 PM
Thanks for the input - quick question about quotes (the thread is already off topic) ...

Quote from: Aku on February 01, 2007, 03:15:06 PM
Understanding the Echo Statement

2. Echo statements in SMF are used with single quotes '
EXAMPLE:
echo 'CONTENT FOR GUESTS';


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 />';
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: houston on February 01, 2007, 09:48:42 PM
I seem to be getting this error. Inserted this global $user_info;

if ($user_info['is_guest'])
echo 'CONTENT FOR GUESTS';

elseif (in_array(#, $user_info['groups']))
echo 'CONTENT FOR MEMBERS SPECIFIED';

else
echo 'CONTENT FOR OTHER MEMBERGROUPS NOT SPECIFIED ABOVE';


And got this in a php block.

Parse error: parse error, unexpected T_ECHO, expecting ')' in /home/xxxxx/public_html/newforum/Sources/Load.php(1745) : eval()'d code(35) : eval()'d code on line 7
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: RoarinRow on February 01, 2007, 09:58:42 PM
I know exactly what you mean Aku   :idiot2:

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.greece.org%2Fgr-lessons%2Fgr-english%2FGif%2Fscript.gif&hash=6f230ff8d1127ec736f521d4b89a83cd934574f1)
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: 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']))
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: houston on February 01, 2007, 11:39:13 PM
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
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: 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?

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.  ;)

Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Thurnok on February 02, 2007, 05:01:35 AM
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.  ;)
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: iowamf on February 02, 2007, 11:10:07 AM
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.

Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: bloc on February 02, 2007, 12:49:20 PM
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.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: bloc on February 02, 2007, 12:51:53 PM
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.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Thurnok on February 03, 2007, 03:34:06 AM
@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>';
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: 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?
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: satcom on September 14, 2007, 04:15:13 AM
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
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Hairy on September 28, 2007, 03:06:33 AM
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/>';
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Lord Anubis on September 28, 2007, 03:43:01 AM
Thanks I will give it a try :)
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: TimUSA on October 19, 2007, 10:26:42 PM
Looking at this code:
http://www.tinyportal.net/index.php?topic=12898.msg107662#msg107662

How would i change this so that it would be based on user selected language rather than user groups?

Thanks Tim
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: jacortina on October 19, 2007, 11:21:22 PM
$user_info['language'] will hold the selected language for the user.

But you'll have to figure out the values it could be. English, for example, is "english" (lowercase). So to test for any given language, you might need to do some testing first, like adding a: echo $user_info['language'], '< br />';line to the code (make it conditional on being one that you DON'T recognize). Then you'll know what you have to add a check for.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: TimUSA on October 20, 2007, 02:27:09 AM
When I use the following code, the menu isn't changing when I change languages in my profile???

global  $scripturl, $context, $user_info;

////////////////////////////////////////////////////
// ENGLISH MEMBERS
////////////////////////////////////////////////////
if (in_array(english, $user_info['language']) || $context['user'])
{
echo '
<b>Membership</b><br />
<font size="2">
<a href="'.$scripturl.'?page=74"> Memberlist</a><br />
<a href="'.$scripturl.'?page=69"> Membership Handbook</a><br />
<a href="'.$scripturl.'?page=70"> Racing Application</a><br />

<b>Racing</b><br />
<font size="2">
<a href="'.$scripturl.'?cat=14"> Rules</a><br />
<a href="'.$scripturl.'?page=44"> Password</a><br />
<a href="'.$scripturl.'?page=56"> Tournaments</a><br />
<a href="'.$scripturl.'?page=62"> Club Championship</a><br />

<b>Web Tools</b><br />
<font size="2">
<a href="'.$scripturl.'?action=forum"> Forum</a><br />
<a href="'.$scripturl.'?action=help"> Help</a><br />
<a href="'.$scripturl.'?action=search"> Search</a><br />
<a href="'.$scripturl.'?action=profile"> Profile</a><br />
<a href="'.$scripturl.'?action=pm"> Messages</a><br />
<a href="'.$scripturl.'?action=calendar"> Calendar</a><br />
<a href="'.$scripturl.'?action=tpmod;dl"> Download</a><br />
<a href="'.$scripturl.'?action=links"> Links</a><br />
<a href="'.$scripturl.'?action=gallery"> Gallery</a><br />
<a href="'.$scripturl.'?action=invite"> Invite</a><br />

<b>Articles</b><br />
<font size="2">
<a href="'.$scripturl.'?page=39"> Fleet Racing</a><br />
<a href="'.$scripturl.'?page=63"> Team Racing</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Submit Article</a><br />
</font>';
}

////////////////////////////////////////////////////
// FRENCH MEMBERS
////////////////////////////////////////////////////
elseif (in_array(french, $user_info['language']) || $context['user'])
{
echo '
<b>Membre</b><br />
<font size="2">
<a href="'.$scripturl.'?page=74"> Liste De Membre</a><br />
<a href="'.$scripturl.'?page=69"> Manuel De Membre</a><br />
<a href="'.$scripturl.'?page=70"> Application</a><br />

<b>Emballage</b><br />
<font size="2">
<a href="'.$scripturl.'?cat=14"> Règles</a><br />
<a href="'.$scripturl.'?page=44"> Mot de passe</a><br />
<a href="'.$scripturl.'?page=56"> Tournois</a><br />
<a href="'.$scripturl.'?page=62"> Championnat De Club</a><br />

<b>Outils de Web</b><br />
<font size="2">
<a href="'.$scripturl.'?action=forum"> Forum</a><br />
<a href="'.$scripturl.'?action=help"> Aide</a><br />
<a href="'.$scripturl.'?action=search"> Recherche</a><br />
<a href="'.$scripturl.'?action=profile"> Profil</a><br />
<a href="'.$scripturl.'?action=pm"> Courrier</a><br />
<a href="'.$scripturl.'?action=calendar"> Calendrier</a><br />
<a href="'.$scripturl.'?action=tpmod;dl"> Téléchargement</a><br />
<a href="'.$scripturl.'?action=links"> Liens</a><br />
<a href="'.$scripturl.'?action=gallery"> Galerie</a><br />
<a href="'.$scripturl.'?action=invite"> Invitez</a><br />

<b>Articles en anglais</b><br />
<font size="2">
<a href="'.$scripturl.'?page=39"> Emballage De Flotte</a><br />
<a href="'.$scripturl.'?page=63"> Emballage D Équipe</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Soumettez L Article</a><br />
</font>';
}

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

echo'</div>';
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: jacortina on October 20, 2007, 02:31:37 AM
Lines like these don't need to be THAT complex:

if (in_array(english, $user_info['language']) || $context['user'])

Simply try:
if ($user_info['language'] == 'english')

Note actual string value in the single quotes (double quotes would work, too), and the two equals used in equality tests.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: TimUSA on October 20, 2007, 02:37:02 AM
Worked like a charm!
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: TimUSA on October 20, 2007, 03:08:01 AM
This worked in an article, but when I put everything into a php block i get the following error:
QuoteParse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/vskayc/public_html/Sources/Load.php(1773) : eval()'d code(35) : eval()'d code on line 98

this is my code exactly as i have put into the php block:
global  $scripturl, $context, $user_info;

////////////////////////////////////////////////////
// ENGLISH MEMBERS
////////////////////////////////////////////////////
if ($user_info['language'] == 'english')
{
echo '
<b>Membership</b><br />
<font size="2">
<a href="'.$scripturl.'?page=74"> Memberlist</a><br />
<a href="'.$scripturl.'?page=69"> Membership Handbook</a><br />
<a href="'.$scripturl.'?page=70"> Racing Application</a><br />

<b>Racing</b><br />
<font size="2">
<a href="'.$scripturl.'?cat=14"> Rules</a><br />
<a href="'.$scripturl.'?page=44"> Password</a><br />
<a href="'.$scripturl.'?page=56"> Tournaments</a><br />
<a href="'.$scripturl.'?page=62"> Club Championship</a><br />

<b>Web Tools</b><br />
<font size="2">
<a href="'.$scripturl.'?action=forum"> Forum</a><br />
<a href="'.$scripturl.'?action=help"> Help</a><br />
<a href="'.$scripturl.'?action=search"> Search</a><br />
<a href="'.$scripturl.'?action=profile"> Profile</a><br />
<a href="'.$scripturl.'?action=pm"> Messages</a><br />
<a href="'.$scripturl.'?action=calendar"> Calendar</a><br />
<a href="'.$scripturl.'?action=tpmod;dl"> Download</a><br />
<a href="'.$scripturl.'?action=links"> Links</a><br />
<a href="'.$scripturl.'?action=gallery"> Gallery</a><br />
<a href="'.$scripturl.'?action=invite"> Invite</a><br />

<b>Articles</b><br />
<font size="2">
<a href="'.$scripturl.'?page=39"> Fleet Racing</a><br />
<a href="'.$scripturl.'?page=63"> Team Racing</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Submit Article</a><br />
</font>';
}

////////////////////////////////////////////////////
// FRENCH MEMBERS
////////////////////////////////////////////////////
if ($user_info['language'] == 'french')
{
echo '
<b>Membre</b><br />
<font size="2">
<a href="'.$scripturl.'?page=74"> Liste De Membre</a><br />
<a href="'.$scripturl.'?page=69"> Manuel De Membre</a><br />
<a href="'.$scripturl.'?page=70"> Application</a><br />

<b>Emballage</b><br />
<font size="2">
<a href="'.$scripturl.'?cat=14"> Règles</a><br />
<a href="'.$scripturl.'?page=44"> Mot de passe</a><br />
<a href="'.$scripturl.'?page=56"> Tournois</a><br />
<a href="'.$scripturl.'?page=62"> Championnat De Club</a><br />

<b>Outils de Web</b><br />
<font size="2">
<a href="'.$scripturl.'?action=forum"> Forum</a><br />
<a href="'.$scripturl.'?action=help"> Aide</a><br />
<a href="'.$scripturl.'?action=search"> Recherche</a><br />
<a href="'.$scripturl.'?action=profile"> Profil</a><br />
<a href="'.$scripturl.'?action=pm"> Courrier</a><br />
<a href="'.$scripturl.'?action=calendar"> Calendrier</a><br />
<a href="'.$scripturl.'?action=tpmod;dl"> Téléchargement</a><br />
<a href="'.$scripturl.'?action=links"> Liens</a><br />
<a href="'.$scripturl.'?action=gallery"> Galerie</a><br />
<a href="'.$scripturl.'?action=invite"> Invitez</a><br />

<b>Articles en anglais</b><br />
<font size="2">
<a href="'.$scripturl.'?page=39"> Emballage De Flotte</a><br />
<a href="'.$scripturl.'?page=63"> Emballage D Équipe</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Soumettez L Article</a><br />
</font>';
}

////////////////////////////////////////////////////
// ITALIAN MEMBERS
////////////////////////////////////////////////////
if ($user_info['language'] == 'italian')
{
echo '
<b>Membri</b><br />
<font size="2">
<a href="'.$scripturl.'?page=74"> Lista Del Membro</a><br />
<a href="'.$scripturl.'?page=69"> Manuale Del Membro</a><br />
<a href="'.$scripturl.'?page=70"> Applicazione</a><br />

<b>Concorrenza</b><br />
<font size="2">
<a href="'.$scripturl.'?cat=14"> Regole</a><br />
<a href="'.$scripturl.'?page=44"> Parola d'accesso</a><br />
<a href="'.$scripturl.'?page=56"> Tornei</a><br />
<a href="'.$scripturl.'?page=62"> Campionato Del Randello</a><br />

<b>Attrezzi Di Web site</b><br />
<font size="2">
<a href="'.$scripturl.'?action=forum"> Discussione</a><br />
<a href="'.$scripturl.'?action=help"> Aiuto</a><br />
<a href="'.$scripturl.'?action=search"> Ricerca</a><br />
<a href="'.$scripturl.'?action=profile"> Profilo</a><br />
<a href="'.$scripturl.'?action=pm"> Posta</a><br />
<a href="'.$scripturl.'?action=calendar"> Calendario</a><br />
<a href="'.$scripturl.'?action=tpmod;dl"> Trasferimento</a><br />
<a href="'.$scripturl.'?action=links"> CollegamentiLiens</a><br />
<a href="'.$scripturl.'?action=gallery"> Galleria</a><br />
<a href="'.$scripturl.'?action=invite"> Inviti</a><br />

<b>Articoli in inglese</b><br />
<font size="2">
<a href="'.$scripturl.'?page=39"> Corsa Della Flotta</a><br />
<a href="'.$scripturl.'?page=63"> Corsa Della Squadra</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Presenti L'Articolo</a><br />
</font>';
}

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

echo'</div>';


I also tried tagging it with:
<?php

?>

but with no avail:(
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: jacortina on October 20, 2007, 03:16:36 AM
This is the kind of thing which will give you a "gotcha", no matter how long you code.

I'll bet you any amount that you DIDN'T use the Italian block in the article. Why?

These lines are the killers:
<a href="'.$scripturl.'?page=44"> Parola d'accesso</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Presenti L'Articolo</a><br />

See it? The extra single-quote / apostrophe? It has to be 'escaped'. Any others like this have to be escaped (possessive apostrophe-s will get you, too: Mr. Smith's ...):
<a href="'.$scripturl.'?page=44"> Parola d\'accesso</a><br />
<a href="'.$scripturl.'?tpmod;sa=submitarticle"> Presenti L\'Articolo</a><br />
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: TimUSA on October 20, 2007, 03:29:10 AM
Yep and I would venture to say that even as a newbie, I knew better. Thanks
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: wilsy on December 27, 2007, 08:56:26 AM
Hi all,

Could this be used to display only when on a certain page?

Eg.

?action=profile;u=', $context['user']['id'] ,';sa=pictures;add

Regards,

Wilsy.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: falguni1 on December 27, 2007, 09:08:47 AM
nice.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: IchBin on December 27, 2007, 04:12:31 PM
If you have some way to verify in your URL or something which page you are on for sure. For instance, if you're in your profile, in a topic, or an a certain article page you can always use PHP to detect that by grabbing the information in the $_GET array.

if (isset($_GET['page']) && $_GET['page'] == 3)
echo 'your code goes here';

This will display your code "if you're in article number 3".
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: wilsy on December 27, 2007, 05:18:19 PM
Quote from: IchBinâ,,¢ on December 27, 2007, 04:12:31 PM
If you have some way to verify in your URL or something which page you are on for sure. For instance, if you're in your profile, in a topic, or an a certain article page you can always use PHP to detect that by grabbing the information in the $_GET array.

if (isset($_GET['page']) && $_GET['page'] == 3)
echo 'your code goes here';

This will display your code "if you're in article number 3".

Hi Ichbin,

Thanks for your help, you certainly get around here and I for one am very grateful.

Thanks!

Wilsy.
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: MPDesignZ on January 01, 2008, 05:15:13 AM
Hi, I'm a little confused here. I need for my guests to not see any articles except the opening page as well, but I'm lost on to what we are doing here in this thread. Do I need to put all my content that I want hidden from guests in the php block file with the codes provided at the beginning of the thread? Or do I need to do it some other way? And I have no idea what number the guest group is in my forum. I have the default install of 1.1.4 and I have not changed guest members groups or anything of that nature.

Thanks
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: IchBin on January 01, 2008, 05:38:03 AM
The options you're seeking are not built into TP yet. So to get something to view only for a guest, and not allow guests to view other content will require you to use some custom code. Until then, you'll have to wait until TP 1.0 comes out. Guests do not have an id, because they are not registered. So you use something to check if they are a guest, or if they are logged in.

if ($context['user']['is_logged']){
    echo 'all the stuff for logged in users in between these single quotes';
}

// the above code checks to see if they are logged. If they are not logged, they are a guest and
// it will not show something unless you add and else statement.

else {
    echo 'all the stuff for guests here';
}
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: MPDesignZ on January 01, 2008, 06:17:57 AM
Thanks! :D
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: Tam on January 11, 2008, 07:48:04 PM
Quote from: IchBinâ,,¢ on January 01, 2008, 05:38:03 AM
if ($context['user']['is_logged']){
    echo 'all the stuff for logged in users in between these single quotes';
}

// the above code checks to see if they are logged. If they are not logged, they are a guest and
// it will not show something unless you add and else statement.

else {
    echo 'all the stuff for guests here';
}


I think this will work for what I am trying to do, but I have a few questions. What I am trying to do is create an article. Within the article I need to place a link that only logged in members can click-on or see. Does the above code have to go in a block or can in go in the article source?

If I have to put it in a block, can I make the block show up only with this particular article?

EDIT - Nevermind, I figured it out. TY
Title: Re: Conditional Block (probably the most useful block in the universe)
Post by: MatthewSchenker on May 16, 2008, 11:18:29 PM
Good Afternoon,
Just wanted to say, I learned more about coding reading this discussion than I did in several lessons!  Thanks for posting it.  I'm going to try toe Conditional Block soon!
Matt