Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 02:52 am EST

Geeklog Forums

loading rightblocks from the header


Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
i'm making a new theme that requires me to load the rightblocks from the header rather than the footer--it's a div-nesting issue.
anyway, can this be done from within the template files (i know it cant but thought maybe you guys know something i don't) or do i have to modify COM_siteHeader() and COM_siteFooter()?
Is there an easy way?
i figure if i add rightblocks.thtml to the header array and remove it from the footer array, that would be a good start. any clues?

it's just that this theme I'm working on cant employ the sandwich idea without breaking everytime any other page than index.php is called. I'm nesting the right blocks in the content area to account for an expanding content area when the rightblocks are not called--it's a css thing.
You'll see what i mean when i release it. it's really cool.
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
ok I DID IT
but i did a sloppy job.
i just added to the array and then added the appropriate stuff at com_showblocks...
now i have a problem due to my sloppiness (sortof)... i neglected to consider the bit about whether rightblocks were enabled or not. that means that now they load from the header ALL the time--again, not quite what i want. but i don't know how to fix this cuz the enabling/disabling of the rightblocks is done right in the call to the footer. i'm confusing myself now. bbiab
 Quote

Status: offline

drshakagee

Forum User
Full Member
Registered: 10/01/03
Posts: 231
I have come across the same problem with no (reasonable) solution. It sure would be nice if you could call the right blocks before the content, but without a tad of hacking (as you found out), its not possible. Perhaps in a future version they will consider it but I doubt it.
Yes I am mental.
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
i got it!
instead of loading the right blocks from the header, why not just load the left blocks from the footer? haven't tried it yet but it seems at first glance like it would work--after editing the COMs.
another option may be, and please someone correct me if i'm way off, to make my own COM_siteHeader() and throw it into the functions file of the theme to which it must apply thereby not editing any core GL files. I think that may work based on this nifty piece of code that i just noticed in the COM_siteHeader():
Text Formatted Code
    // If the theme implemented this for us then call their version instead.

    $function = $_CONF['theme'] . '_siteHeader';

    if( function_exists( $function ))
    {
        return $function( $what );
    }

 
what do you think?
 Quote

Status: offline

Demonhood

Forum User
Junior
Registered: 07/12/04
Posts: 15
I'm also looking for a solution to this problem. I need to be able to call the blocks like this:
left
right
middle

What files are you guys mentioning editing? I've only been editing the .thtml files thus far. Do I need to attack the PHP files to get this to work?
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512

here's the deal with loading right blocks from the header.
It isn't a problem to load right blocks from the header--it's a can do. It isn't even a problem to extend the center column (remember we are talking about CSS-P here) when the right blocks aren't supposed to show up.

The problem is that unless you modify the GL core, you will not be able to say, "i want rightblocks on this page, but not that one." You will either have blocks, or you won't--across the board. This is because the parameter passed to COM_siteFooter is not passed to COM_siteHeader. Even that is not a big hurdle to overcome.

The big hurdle is this: whereas COM_siteFooter() either passes a parameter or not, calling rightblocks or not, throughout GL core pages, COM_siteHeader does not pass a parameter anywhere, by default. You have to go in and edit GL core files. You can do this of course and it won't affect other themes that call the right blocks from the footer, but it sure is a hasle and when you upgrade, well, good luck.

so here is what you can do to load the rightblocks from the header:

First, in an attempt to modify the GL core as little as possible, I copied the function COM_siteHeader to my theme's function.php file. From there I made a few adjustments including passing an extra parameter to the function. Here is that function:

Text Formatted Code
/**
* Returns the site header
*
* @param        string      $what       If 'none' then no left blocks are returned, if 'menu' (default) then right blocks are returned
* @param        boolean     $rightblock     Whether or not to show blocks on right hand side default is no
* @return   string  This returns formated HTML containing the site header
*
*/

// This function loads the rightblocks from the header.  be sure to remove or comment out
// your {rightblocks} from your footer.thtml, or you'll probably get something you don't expect.
// By default, the rightblocks are not displayed.
// This function is a modified copy of COM_siteheader from lib-common.php and is called from COM_siteheader.
// The COM_siteheader will be looking for "$_CONF['theme'] . '_siteHeader'" thus the theme
// name replaces "COM" in the function name.
// If you have no particular need to load the rightblocks from the header then DON'T!

// terry is the name of this theme, incase you were wondering.
function terry_siteHeader( $what = 'menu' , $rightblock = false )
{
    global $_CONF, $_USER, $LANG01, $_COM_VERBOSE, $topic, $LANG_BUTTONS, $LANG_CHARSET;
    global $_TABLES, $HTTP_POST_VARS, $HTTP_GET_VARS;

    $header = new Template( $_CONF['path_layout'] );
    $header->set_file( array(
        'header'        => 'header.thtml',
        'menuitem'      => 'menuitem.thtml',
        'menuitem_last' => 'menuitem_last.thtml',
        'menuitem_none' => 'menuitem_none.thtml',
        'leftblocks'    => 'leftblocks.thtml',
        'rightblocks'   => 'rightblocks.thtml'
        ));

    $pagetitle = '';
    if( isset( $_CONF['pagetitle'] ))
    {
        $pagetitle = $_CONF['pagetitle'];
    }
    if( empty( $pagetitle ))
    {
        $pagetitle = $_CONF['site_slogan'];
    }
    if( !empty( $pagetitle ))
    {
        $pagetitle = ' - ' . $pagetitle;
    }
    $header->set_var( 'page_title', $_CONF['site_name'] . $pagetitle );

    $header->set_var( 'background_image', $_CONF['layout_url'] . '/images/bg.gif' );
    $header->set_var( 'site_url', $_CONF['site_url'] );
    $header->set_var( 'layout_url', $_CONF['layout_url'] );
    $header->set_var( 'site_mail', "mailto:{$_CONF['site_mail']}" );
    $header->set_var( 'site_name', $_CONF['site_name'] );
    $header->set_var( 'site_slogan', $_CONF['site_slogan'] );
    $rdf = substr_replace( $_CONF['rdf_file'], $_CONF['site_url'], 0,
                           strlen( $_CONF['path_html'] ) - 1 );
    $header->set_var( 'rdf_file', $rdf );
    $header->set_var( 'rss_url', $rdf );

    $msg = $LANG01[67] . ' ' . $_CONF['site_name'];

    if( !empty( $_USER['username'] ))
    {
        $msg .= ', ' . $_USER['username'];
    }

    $curtime =  COM_getUserDateTimeFormat();

    $header->set_var( 'welcome_msg', $msg );
    $header->set_var( 'datetime', $curtime[0] );
    $header->set_var( 'site_logo', $_CONF['layout_url'] . '/images/logo.gif' );
    $header->set_var( 'css_url', $_CONF['layout_url'] . '/style.css' );
    $header->set_var( 'theme', $_CONF['theme'] );

    if( empty( $LANG_CHARSET ))
    {
        $charset = $_CONF['default_charset'];

        if( empty( $charset ))
        {
            $charset = "iso-8859-1";
        }
    }
    else
    {
        $charset = $LANG_CHARSET;
    }

    $header->set_var( 'charset', $charset );

    // Now add variables for buttons like e.g. those used by the Yahoo theme
    $header->set_var( 'button_home', $LANG_BUTTONS[1] );
    $header->set_var( 'button_contact', $LANG_BUTTONS[2] );
    $header->set_var( 'button_contribute', $LANG_BUTTONS[3] );
    $header->set_var( 'button_links', $LANG_BUTTONS[4] );
    $header->set_var( 'button_polls', $LANG_BUTTONS[5] );
    $header->set_var( 'button_calendar', $LANG_BUTTONS[6] );
    $header->set_var( 'button_sitestats', $LANG_BUTTONS[7] );
    $header->set_var( 'button_personalize', $LANG_BUTTONS[8] );
    $header->set_var( 'button_search', $LANG_BUTTONS[9] );
    $header->set_var( 'button_advsearch', $LANG_BUTTONS[10] );

    // Now add nested template for menu items

    // contribute link
    if( empty( $topic ))
    {
        $contributelink = $_CONF['site_url'] . '/submit.php?type=story';
        $header->set_var( 'current_topic', '' );
    }
    else
    {
        $contributelink = $_CONF['site_url']
                        . '/submit.php?type=story&topic=' . $topic;
        $header->set_var( 'current_topic', '&topic=' . $topic );
    }

    $allowedCounter = 0;
    $header->set_var( 'menuitem_url', $contributelink );
    $header->set_var( 'menuitem_text', $LANG01[71] );
    $header->parse( 'menu_elements', 'menuitem', true );
    if(( isset( $_USER['uid'] ) && ( $_USER['uid'] > 1 )) ||
        (( $_CONF['loginrequired'] == 0 ) && ( $_CONF['submitloginrequired'] == 0 )))
    {
        $header->parse( 'allowed_menu_elements', 'menuitem', true );
        $allowedCounter++;
    }

    // links link
    $header->set_var( 'menuitem_url', $_CONF['site_url'] . '/links.php' );
    $header->set_var( 'menuitem_text', $LANG01[72] );
    $header->parse( 'menu_elements', 'menuitem', true );
    if(( isset( $_USER['uid'] ) && ( $_USER['uid'] > 1 )) ||
        (( $_CONF['loginrequired'] == 0 ) && ( $_CONF['linksloginrequired'] == 0 )))
    {
        $header->parse( 'allowed_menu_elements', 'menuitem', true );
        $allowedCounter++;
    }

    // polls link
    $header->set_var( 'menuitem_url', $_CONF['site_url'] . '/pollbooth.php' );
    $header->set_var( 'menuitem_text', $LANG01[73] );
    $header->parse( 'menu_elements', 'menuitem', true );
    if(( isset( $_USER['uid'] ) && ( $_USER['uid'] > 1 )) ||
        (( $_CONF['loginrequired'] == 0 ) && ( $_CONF['pollsloginrequired'] == 0 )))
    {
        $header->parse( 'allowed_menu_elements', 'menuitem', true );
        $allowedCounter++;
    }

    // calendar link
    $header->set_var( 'menuitem_url', $_CONF['site_url'] . '/calendar.php' );
    $header->set_var( 'menuitem_text', $LANG01[74] );
    $header->parse( 'menu_elements', 'menuitem', true );
    if(( isset( $_USER['uid'] ) && ( $_USER['uid'] > 1 )) ||
        (( $_CONF['loginrequired'] == 0 ) && ( $_CONF['calendarloginrequired'] == 0 )))
    {
        $header->parse( 'allowed_menu_elements', 'menuitem', true );
        $allowedCounter++;
    }

    // Get plugin menu options
    $plugin_menu = PLG_getMenuItems();

    if( $_COM_VERBOSE )
    {
        COM_errorLog( 'num plugin menu items in header = ' . count( $plugin_menu ), 1 );
    }

    if( count( $plugin_menu ) == 0 )
    {
        $header->parse( 'plg_menu_elements', 'menuitem_none', true );
    }
    else
    {
        for( $i = 1; $i <= count( $plugin_menu ); $i++ )
        {
            $header->set_var( 'menuitem_url', current( $plugin_menu ));
            $header->set_var( 'menuitem_text', key( $plugin_menu ));

            if( $i == count( $plugin_menu ))
            {
                $header->parse( 'plg_menu_elements', 'menuitem_last', true );
            }
            else
            {
                $header->parse( 'plg_menu_elements', 'menuitem', true );
            }

            next( $plugin_menu );
        }
    }

    // Search link
    $header->set_var( 'menuitem_url', $_CONF['site_url'] . '/search.php' );
    $header->set_var( 'menuitem_text', $LANG01[75] );
    $header->parse( 'menu_elements', 'menuitem', true );
    if(( isset( $_USER['uid'] ) && ( $_USER['uid'] > 1 )) ||
        (( $_CONF['loginrequired'] == 0 ) && ( $_CONF['searchloginrequired'] == 0 )))
    {
        $header->parse( 'allowed_menu_elements', 'menuitem', true );
        $allowedCounter++;
    }

    // Stats link
    $header->set_var( 'menuitem_url', $_CONF['site_url'] . '/stats.php' );
    $header->set_var( 'menuitem_text', $LANG01[76] );
    $header->parse( 'menu_elements', 'menuitem_last', true );
    if(( isset( $_USER['uid'] ) && ( $_USER['uid'] > 1 )) ||
        (( $_CONF['loginrequired'] == 0 ) && ( $_CONF['statsloginrequired'] == 0 )))
    {
        $header->parse( 'allowed_menu_elements', 'menuitem', true );
        $allowedCounter++;
    }

    if( $allowedCounter == 0 )
    {
        $header->set_var( 'allowed_menu_elements', '' );
    }

    if( $what <> 'none' )
    {
        // Now show any blocks -- need to get the topic if not on home page
        if( !isset( $HTTP_GET_VARS['topic'] ))
        {
            if( isset( $HTTP_GET_VARS['story'] ))
            {
                $sid = COM_applyFilter( $HTTP_GET_VARS['story'] );
            }
            elseif( isset( $HTTP_GET_VARS['sid'] ))
            {
                $sid = COM_applyFilter( $HTTP_GET_VARS['sid'] );
            }
            elseif( isset( $HTTP_POST_VARS['story'] ))
            {
                $sid = COM_applyFilter( $HTTP_POST_VARS['story'] );
            }
            if( !empty( $sid ))
            {
                $topic = DB_getItem( $_TABLES['stories'], 'tid', "sid='$sid'" );
            }
        }
        else
        {
            $topic = COM_applyFilter( $HTTP_GET_VARS['topic'] );
        }
        $header->set_var( 'geeklog_blocks', COM_showBlocks( 'left', $topic ));
        $header->parse( 'left_blocks', 'leftblocks', true );
    }
    else
    {
        $header->set_var( 'geeklog_blocks', '' );
        $header->set_var( 'left_blocks', '' );
    }
        //call the right blocks
    if( $rightblock )
    {
        $rblocks = COM_showBlocks( 'right', $topic );
    }
    if( $rightblock && !empty( $rblocks ))
    {
        $header->set_var( 'geeklog_blocks', $rblocks );
        $header->parse( 'right_blocks', 'rightblocks', true);
    }
    else
    {
        $header->set_var( 'geeklog_blocks', '' );
        $header->set_var( 'right_blocks', '' );
    }

    // Call any plugin that may want to include Extra Metatags or Javascript functions
    $header->set_var( 'plg_headercode', PLG_getHeaderCode());

    // The following line allows users to embed PHP in their templates.  This
    // is almost a contradition to the reasons for using templates but this may
    // prove useful at times...don't use PHP in templates if you can live without it

    $tmp = $header->parse( 'index_header', 'header' );

    ob_start();
    eval( '?>' . $tmp );
    $retval = ob_get_contents();
    ob_end_clean();

    return $retval;
}




 

Second, because this function is called from COM_siteHeader in lib-common.php, the parameter being passed to theme_siteHeader is done from COM_siteHeader. So here is GL core modified a little as I could get away with--these are the default lines that I am going to edit:

Text Formatted Code
function COM_siteHeader( $what = 'menu' )
{
    global $_CONF, $_USER, $LANG01, $_COM_VERBOSE, $topic, $LANG_BUTTONS, $LANG_CHARSET;
    global $_TABLES, $HTTP_POST_VARS, $HTTP_GET_VARS;

    // If the theme implemented this for us then call their version instead.

    $function = $_CONF['theme'] . '_siteHeader';

    if( function_exists( $function ))
    {
        return $function( $what );
    }




 

Here are the modified lines:

Text Formatted Code
function COM_siteHeader( $what = 'menu' , $rightblock = false )
{
    global $_CONF, $_USER, $LANG01, $_COM_VERBOSE, $topic, $LANG_BUTTONS, $LANG_CHARSET;
    global $_TABLES, $HTTP_POST_VARS, $HTTP_GET_VARS;

    // If the theme implemented this for us then call their version instead.

    $function = $_CONF['theme'] . '_siteHeader';

    if( function_exists( $function ))
    {
        return $function( $what , $rightblock );
    }




 

Third and last, if you want right blocks anywhere you need to pass the parameter to COM_siteHeader, for example, in your core file index.php, calling COM_siteHeader with blocks enabled would look like this: COM_siteHeader('',true);
If you don't want rightblocks on a particular page, just leave COM_siteHeader the way it is, ie, COM_siteHeader();

...and that's the way it is.

oh yeah, don't forget to actually write {right_blocks} into your header.thtml.

 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Well, there it is... My latest contribution to the war on tables.
It's called purplerose and you can get it here.

see this thread for changes to the theme's function file and readme necessary to make the theme work. It loads the right blocks from the header.
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
here is how to load the rightblocks from your custom Com-siteHeader and you don't have to modify the GL core.
First: create your custom Com_siteHeader by copying the one from lib-common.php and paste it into your theme's function.php file.
Second: name it "yourthemename_siteHeader( $what = 'menu' )" replacing "Com" with "yourthemename."
Third: add the following code, which will load the right blocks on the index page and whatever other page you specify in the array.
If you don't want right blocks, just empty the array as well as $siteurl if you don't want rightblocks on the index page.
Text Formatted Code

    //call the right blocks
    $clicked = "http://";
    $clicked .= $_SERVER['HTTP_HOST'];
    $clicked .= $_SERVER['REQUEST_URI'];
    $siteurl = $_CONF['site_url']."/";
    $address = array($_CONF['site_url'].'/index.php', 'otherPagesFromWhichToLoadRightBlocks',);
        //default vars
    $header->set_var( 'geeklog_blocks', '' );
    $header->set_var( 'right_blocks', '' );
        //loads rightblocks if site url is called.
    if (( $siteurl != '') && ( $siteurl == $clicked )){
        $rightblock = true;
        if( $rightblock ) {
            $rblocks = COM_showBlocks( 'right', $topic );
        }
        if( $rightblock && !empty( $rblocks )) {
            $header->set_var( 'geeklog_blocks', $rblocks );
            $header->parse( 'right_blocks', 'rightblocks', true);
        }
        else {
            $header->set_var( 'geeklog_blocks', '' );
            $header->set_var( 'right_blocks', '' );
        }
    }
        //loads rightblocks if address from array is called.
    elseif (!empty( $address )){
        $rightblock = true;
        foreach ($address as $val){
            if (eregi($val, $clicked)) {
                if( $rightblock ) {
                    $rblocks = COM_showBlocks( 'right', $topic );
                }
                if( $rightblock && !empty( $rblocks )) {
                    $header->set_var( 'geeklog_blocks', $rblocks );
                    $header->parse( 'right_blocks', 'rightblocks', true);
                }
                else {
                    $header->set_var( 'geeklog_blocks', '' );
                    $header->set_var( 'right_blocks', '' );
                }
            }
        }
    }

 
 Quote

All times are EST. The time is now 02:52 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content