TinyPortal

Development => Support => Topic started by: lebisol on October 19, 2007, 11:58:33 PM

Title: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 19, 2007, 11:58:33 PM
Hello there,
Quick PHP question.
How do I detect that I am on "hompage" or "domain.com/index.php"
I have tried:
if($settings['TPortal_front_type']!='home')
echo 'not @ main page';

but this is more of a stab in a dark than anythign...
Thanks!!!

p.s. we should have "code" for Message Icon  ;)
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: IchBin on October 20, 2007, 12:01:05 AM
if ($context['TPortal']['is_front']) checks to see if you are on the frontpage.

Don't forget to global $context if you are putting it into a block or something.
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 20, 2007, 12:13:22 AM
Hi IchBin,
I tried:
if ($context['TPortal']['is_front'])
   echo 'index page';
   else echo 'somewhere else';
Still not working. on eg. domain.com/index.php?page=xx

I am trying to implement 'global back button' but want to hide it only on front/index page.

Global var $context is defined.
Thanks!
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: IchBin on October 20, 2007, 01:50:50 AM
Can you show me the code so I can see where and what you are doing?
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 20, 2007, 02:39:56 AM
sure thing, here is the snip:

function template_main_below()
{
global $context, $settings, $options, $scripturl, $txt;
echo'
    irrelevant HTML goes here';
// Global Back Button
if ($context['TPortal']['is_front'])
echo' ';
else echo'
<a href="JavaScript:history.back();"><img src="', $settings['images_url'], '/h_backbutton.gif" alt="Go Back" width="68" height="21" /></a>';
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: IchBin on October 20, 2007, 03:38:35 AM
If you want it to "not" appear on the frontpage then just check if its not equal to the frontpage.

if (!$context['TPortal']['is_front'])
echo'your button here';


Just tested this in a block and it worked for me.
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 20, 2007, 04:43:42 AM
it works for the 'pages' from top menu but not for articles that are linked/visited from the front page...hm...I suppose it would not matter that I am not using phpcode/article but rather in the template it self?!

In other words:
fails on:
site.com/index.php?page=xx
works on:
site.com/index.php?action=abc
???
Thanks for looking into this!
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: bloc on October 20, 2007, 09:36:22 AM
is_front only check if you are on the "frontpage" where all is listed, not single article or category listing. They are strictly not "frontpage" anymore.. Also, it doesnt take into account other actions for example.

The best way is to check for 3 things:

if(!isset($_GET['action']) && !isset($_GET['board']) && !isset($_GET['topic']))

This WILL hit "true" when not in the forum, not in any "action" - but on entry page, any article and category
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 20, 2007, 07:43:23 PM
Thanks block!
That still is not covering all pages....so
How about uising request.URL or URI?:

$homebase="http://domain.com/index.php"
$currentURL= $_SERVER['REQUEST_URI'];

if($currentURL == $homebase){
echo "Your are at home no button needed";
} else {
echo "You been browsing, there is history, show button";
}


but again, my php skills are few days old...issues with $_SERVER variable

Again this is not a back-breaking feature, users can certainly hit back button on browser, it is more of a decorative/gui addon.
Thanks!
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: IchBin on October 20, 2007, 09:43:06 PM
You're going to have to be more specific about where you want it to work, and where you don't want it to work lebisol.
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 20, 2007, 11:13:37 PM
anywhere but the frontpage...
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: IchBin on October 20, 2007, 11:25:47 PM
if(!$context['TPortal']['is_front'] || isset($_GET['page']))
echo 'You are not on the frontpage. on the main page';


Since it checks to see if you are on the frontpage, "or" page is set in the URL this should work for the rest as well.
Title: Re: [PHP] If not on 'domain.com/index.php'
Post by: lebisol on October 21, 2007, 02:06:39 AM
Thanks so much, that did it!