header_contents.php logic

So I am in the process of modifying the header of my site.  However I want the header to change depending on which page the user is visiting.

For example I have a header that is a little bigger and contains details that are relevant when a user first comes to the site.  However once the user logs in and is using the sub-pages I want the content to take priority so I want to use a header that is much smaller and less obtrusive.  So in short: on main page (root/index of site) you see the big header, anywhere else you see the small header.

What logic would I use to determine if I am on the index page so I can dynamically choose which header elements to display?

Thanks.

  • Thanks for the response but this isn't exactly what I was asking.  Let me clarify.  Whether they are logged in or out is not the important part, but what page they are on.  I only want them to see the big header on the index page (whether logged in or not) and on every other page they get the smaller version.

    There is probably a simple ELGG method for returning the URL or part of the URL.  I am sure if it is not built into ELGG there is way to do with PHP.

    I thought I would start here to see if anyone else had already done this.  Plus I have found that in posting these types of questions I have often learned better ways of implementing ideas and, as always, learn more about ELGG.  If ELGG has a method for doing this, I would rather use it in place of re-inventing the wheel (and adding overhead) with my own php.

    Thanks again.

  • So I have something working now.

    if ($_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] == substr(strrchr($vars[url], ":"), 3)){DISPLAY_LARGE_HEADER}

    This logic will return true if we are at the base URL (and therefore at the index page). I am not 100% happy with this since it has to match perfectly to get the larger header.  I will have to be very careful that DNS and apache are set up correctly to ensure that the access URL is the same as the URL contained in $vars[url].  For example on a local dev install I can access the site using either 127.0.0.1 or localhost but only one of these scenarios could match the $vars[ur].

    Like I said, if I am careful I can probably prevent this from happening.  Plus the worst case scenario is that the smaller header shows up on the home page.  That wouldn't really be that bad.

    Also if I wanted to make the above logic available in a boolean method that could be used througout ELGG (i.e., isHomePage()), where would I put that?

  • I'm not getting this maybe..

    'whether logged in or not..'

    Your logged in users will be taken away from the index page anyway, (ex, redirected to dashboard.. profile.. or whatever other page). am I right?

    If that's the case, then it makes more sense using imcobarn's argument using isloggedin, because it will be the only circumstance where users see the index page. 

    Having said that, I probably don't understand what the scenario is in this case so the idea may not be what you're looking for.

     

     

  • While you are right about the default behavior of ELGG, it is not the only possible behavior.  it is simple to modify the login so they are returned to whichever page they initiated the login from (which is how I will configure my site). 

    The bigger concern is that there will be plenty of public content that a user will be able to view while not logged in.  I do not want the user seeing the big header in those scenarios (taking screen real estate away from the content).

  • I am still unclear on this, but curious to find out.. So, here are some pointers that might help you, me or anyone else understand what we are dealing with:

    1. Registered and non-registered visitors see index page.. index page contains large header and login form.

    2. User logs in, and goes back to the same page they logged in from "forward($_SERVER['HTTP_REFERER']);".. user sees small header + full content.

    3. Visitor does not log in, but they click a link.. they go to a page.. they see small header + partial content.

    Is this scenario correct?

    In other words: Example:

    if(isloggedin()){

    if($_SERVER['HTTP_REFERER']==$vars['url']){

    show_small_header;

    show_all_content;

    }else{

    show_small_header;

    show_all_content;

    }

    }else{

    if($_SERVER['SERVER_NAME']==$vars['url']){

    show_big_header;

    }else{

    show_small_header;

    show_partial_content;

    }

    }

     

    Does this make sense?

     

  • By the way Daniel, do you really want to redirect your visitor back to the index page after login?

    I say this because:

    if($_SERVER['HTTP_REFERER']==$vars['url']){

    forward(dashboard..profile.. or whatever other page you want);

    }else{

    forward($_SERVER['HTTP_REFERER']);

    }

     

    And this might solve your problem, because then all you have to do is control the content display based on whether they are logged in or not.

    if(isloggedin()){

    show this and that;

    }else{

    show this but not that;

    }

     

     

  • I think for the most part you are understanding it ok.  But you are making it a bit more complex than needed.  There are basically two scenarios:

    1. On Index Page: All users (logged in and logged out) see large header

    2. On Sub pages / Internal Content: All users (logged in and logged out) see smaller header.

    Granted when you are logged out you will have access to a very small subset of the actual content (only see what has been marked as public). 

    Right now my login form is available from any page (part of the header_contents.php) but is only visible if the user has not yet logged on.  This solves one of my bigest pet peeves of this site (and the default ELGG) and that is that you have to go all the back to the index to log in.  And once you have logged in you then have to navigate all the way back to where you wanted to be (granted the brower buttons and history can help with that).

    There are also elements of the topbar that I am keeping visible even when logged out (mainly the search bar).  In all honesty, the top bar would be a great place for a persistant login link as well.

    And yes, I have been thinking about the downside of having a user re-directed back to the index page after a login from the index page.  Most likely I will use the same logic I posted above to disable the 'returntoreferer' variable from the index page.  So when logging in from the index page you will get the default ELGG behavior and be redirected to the dashboard.

  • Ok.. Lets analyse this:

    "1. On Index Page: All users (logged in and logged out) see large header."

    Since you are going to redirect logged in users from index page to the dashboard (or any other page you want), we can't say: 'logged in user on the index page'. This is because it wont happen. The way to view the index page is when your user is not logged.. once they log in, they'll go some where else, if they click 'a link or button marked home and link to your site name', elgg would still take them to the dashboard, simply because they are logged in.. The only way for them to view that index page again is to log out. Therefore, Index page will be for non-logged in user only.

    "2. On Sub pages / Internal Content: All users (logged in and logged out) see smaller header."

    Very simple:

    If you go to your pageshells/pageshell.php.. You probably see something like this:

     

     

    <?php

    if(isloggedin()){

    ?>

    <?php echo elgg_view('page_elements/header', $vars); ?>

    <?php echo elgg_view('page_elements/elgg_topbar', $vars); ?>

    <?php 

    } else {

    ?>

     

    <?php echo elgg_view('page_elements/header', $vars); ?>

    <?php echo elgg_view('page_elements/header_contents', $vars); ?>

    <?php 

    }

    ?>

     

     

    Remove the if(loggedin)... so it should be like this:

     

    <?php echo elgg_view('page_elements/header', $vars); ?>

    <?php echo elgg_view('page_elements/elgg_topbar', $vars); ?>

    <?php echo elgg_view('page_elements/header_contents', $vars); ?>

     

     

     

    Ok, notice how we kept the topbar and header_contents visible to everyone (logged in and logged out).. Obviously, the topbar or header_contents will represent your small header (non index header).

     

    This leaves us with a few more tasks.. 

    1. Since we have the topbar visible to everyone now, we will need to tell it not to display the appropriate links to logged in and non-logged in users.. So, we go to page_elements/elgg_topbar.php.. From there we can do the following: (I will use the page_elements/elgg_topbar.php in Elgg 1.5 core as a guide):

    Line 18: if(isloggedin()) { 

    we leave that as it is because this will tell the topbar what to show in the case of a logged in user..

    Line 84: } this closes the if(isloggedin()) argument... We will need to move that up a few lines.. specifically, to line 71. This will leave all the topbar content for the loggedin user in tact, but removes the (loggedin) requirement as a condition to display the search bar. (which means that anyone can now see tha search bar).

    Now we go back to line 71 where we closed the if(isloggedin()) argument and we add..

    else {

    By adding this, as you would know, we are now telling the topbar to display different things to non-logged in users.. This may be a link to register, and a link to login... Since the topbar is a small narrow area, you probably link the register link to the register page, and for login, you probably deploy JQuery to drop/slide down your login form (this will meet your preference to have the login in the topbar).. of course, you can also add whatever content, links..etc.

    We then close that argument just before the 'html' for the search area. That way we are giving access to search to everyone.

    This would conclude the topbar issue.

    Use the same logic the header content which now does not have your login form.. You probably do this (just an idea):

    if(isloggedin()){

    echo "You are logged in as" . $vars['user']->name . ".";

    } else {

    echo "Hello Visitor";

    }

    Another thing you might want to consider is leaving the tools links in the topbar visible even to non-logged in users to drop down the links to groups.. and other content that can be public.. This is because if the user is not logged in, and even if they click on the groups link, Elgg will show only public groups anyway.. so there is no harm leaving it there.. as matter of fact it will save you tampering some where else to achieve that.

    You can use the same argument for your content to display this or that depending on whether your user is logged in or not.

    If I was trying to achieve your plan, that's how I would approach it and I would stay clear from calls to retrieve url's because as you would know this can be problematic in some cases.

    Finally, since your registration link will now be displayed on every page (for non logged in users), if a visitor decides to register, you can then carry the (referer url) through to the registration page in a variable, then code your registration action file (register) to retrieve that, and after registration success, to send the user back to that page.. the user looks up to the topbar, and they see the login link.. drop down that form and log in and continue with their business on the site.

    If this is not what you're looking for, I hope it gave you some ideas anyway.

    -Carlos

  • First off thanks for trying to help.  Your logic is great but you are working under the assumption that I am not using a custom_index (default ELGG behaviors).  Currently my index is visible to logged in users well.  I may change this,  But currently my index page contains info that I don't mind logged in users getting back to.

    However I now have a much simpler solution.  I have recently discovered the concept of "context" within ELGG.  All I have to do is set the context of my index page to something unique

    set_context("custom_index");

    Then my logic is simple.


    <?php
        if(get_context() == "custom_index"){
    ?>
    ----Bigger header----
    <?php } else { ?>

    ----smaller header---- 

    Thanks again for your input.