SimplePortal

Support => English Support => Topic started by: Tarista on June 18, 2014, 02:34:31 PM

Title: IF-statement targeting the front/portal page?
Post by: Tarista on June 18, 2014, 02:34:31 PM
Hi,

I'm using the code below inside a custom php block to target a second inactive block loaded inside it and different depending on circumstances.
Now I want to add (1) one which targets the portal page / frontpage only and (2) one which shows only on the simpleportal pages. The second I can image would be something along the lines of current_action == page, but regarding the frontpage I don't know, there is no action in the url.

Thank you! :)

edit: Seems 'page' doesn't work, or I'm writing it incorrectly.
I know I can add a block that displays on all (sp_)pages but I have it written all in the same custom block and would like to have it that way if possible :)

Also, the block is visible only on Portal and the (Simple Portal) Pages, so it would be enough/workable if I could either use the statement to hide it on Portal OR Show it only on Pages if it's too complicated to make two statements :)

The code is from you guys originally, I have just modified it a bit. Here it show on board 5 but I would like to change it as described above.
Code: [Select]
global $context;
if ((empty($context['current_action']) && empty($context['current_topic']) && isset($context['current_board']) && $context['current_board'] == 5) || (isset($context['current_action']) && ($context['current_action'] == 'post' || $context['current_action'] == 'post2' || empty($context['current_topic'])) && isset($context['current_board']) && $context['current_board'] == 5))
{
-Displays on board 5-
}
Title: Re: IF-statement targeting the front/portal page?
Post by: AngelinaBelle on June 26, 2014, 04:05:16 PM
The portal page is the page with no actions, no boards, no pages, nothing whatsoever.
In index.php, it is found by process of elimination.  When simpleportal is NOT installed, SMF does boardindex when nothing else is going on.

and you are correct that page is not an action.  You can go right to the query string to see if 'page' is one of the query string variables  --
isset($_GET['page']) && (! empty($_GET['page']))
Title: Re: IF-statement targeting the front/portal page?
Post by: Tarista on June 27, 2014, 11:10:24 AM
That makes sense. Might be hard to target it then, and for my purpose not actually necessary. :)

I got it working by using the code you mentioned instead. :D Thank you!
I am not familiar with using query string variables to check like that, I guess that something you learn after a while. Not sure how it actually works and where the query strings are defined, but Hey, it works :D
Title: Re: IF-statement targeting the front/portal page?
Post by: AngelinaBelle on June 27, 2014, 12:43:13 PM
Php provides GET variables for you.  SMF tries to make them safe for you.
Title: Re: IF-statement targeting the front/portal page?
Post by: Tarista on June 27, 2014, 12:48:33 PM
Sounds reasonable :) And the above code is safe, correct? I understand the choice of words but  I'm just double-checking to make sure since you said tries.
Title: Re: IF-statement targeting the front/portal page?
Post by: AngelinaBelle on June 27, 2014, 01:15:53 PM
I am not a dev.  So you should talk to a REAL SMF dev for a better understanding of how SMF sanitizes the query string, and what dangers that can and cannot leave behind.

That said, and remember I am not a dev, since you are not actually trying to use the value of the get variable, you are not at much risk for the contents of it.

The most important thing is that, whatever code you write, if you are going to show some content, that you do not circumvent or skip the code that is always checking whether the user is allowed to see or do whatever the URL says they want to try to do.  So if you look at simpleportal code, before it serves a block or page, it checks that the person is allowed to see it.

You are probably not doing this, but I don't see your code so I don't know what you are trying to do.

And I am not a dev, so I would be very slow and unsure of myself checking for security problems.
Title: Re: IF-statement targeting the front/portal page?
Post by: Tarista on June 27, 2014, 01:40:56 PM
Thank you for that answer :) It makes sense what you are telling me and I do understand that you cannot tell me it's completely safe because you can't know that for sure :)

I can't see that what I'm trying to do is creating a problem. So I hope not.

I'm using the code from a thread here to display a couple of deactivated blocks containing BBC-code. I need to use PHP around it to style it and have some of them randomized. I use the code from above so some display on the portal page and some only on simpleportal pages.

All my logged in members can see the BBC-blocks and only a logged in user can see the PHP block which contains the code (so the check should be there atleast). I've build a special left-side menu of content in one php-block so to speak so that my moderator can change the content in the menu around using the BBC-blocks I load into it. If that makes any sense at all. :)

That was the easiest way to get the design to work for us and for it to be user-friendly to my moderators.

So I'm not using it outside of SMF or the portal, I'm actually using it inside the portal and only to display some BBC-styled text content :) And from what I understand reading your reply that should be fine. :)


Code: (this is what I'm using) [Select]
global $context;
if (isset($_GET['page']) && (! empty($_GET['page'])))
{
echo '<div class="sp_leftStyle">';

$block = current(getBlockInfo(false, 26, false, false));  // Load block info
$block['style'] = sportal_parse_style('explode', $block['style'], true);  //Parse block style parameters.
template_block($block); // Output the block.
echo '</div>';
Title: Re: IF-statement targeting the front/portal page?
Post by: AngelinaBelle on June 29, 2014, 09:33:09 PM
Yep.  I'm just cautioning you to use the standard SMF and simpleportal ways of checking permission, and to ask experienced SMF devs for advice about all that.

How is your little project going?
Title: Re: IF-statement targeting the front/portal page?
Post by: Tarista on July 25, 2014, 07:31:57 AM
I'm sorry for the late reply, it's vacation time for me so I have been away for a while.

It's going well though :) Thank you for the replies and the information. I will be careful what I do, security is of course a high concern of mine.
Title: Re: IF-statement targeting the front/portal page?
Post by: ccbtimewiz on September 23, 2015, 07:09:38 PM
I'm just going through some old topics, and thought it would be nice to mention that the action you're looking for is 'home' as SMF is separated into 'forum'. You can also use 'portal'.

Eg,

Code: [Select]
if ($context['current_action'] == 'home')
     echo 'This only is showing on the home page!';
SimplePortal 2.3.8 © 2008-2024, SimplePortal