Over-riding user styles.

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Background:
As stated in an earlier question, I'm attempting to write a sports pool script compatable with the phpBB database. I've made some slow-but-sure progress. The more I do this, the more impressed I am with the folks who wrote this board script! I think I went in over my head when I started this project (considering I knew nothing about php when I started it), but I am tenacious about it, so hopefully, I'll get it. However, I do have one little snag that's been driving me nuts for about 3 days now. I've set this up primarily to use a Theme that I've named "Pools" based on the subSilver template. For members, I've set up 3 sports related board themes:
Football - based on the redIce template
Basketball - based on the subVereor template and
Hockey - based on the icicle tempate.

Example Pages for reference:
(the "Pools" theme based on subSilver is the board default theme, so you should see it OK as a guest. This is a rough draft - it will improve in time)
http://www.imagesculptor.com/pool/NFL_players.php
and
Here's the actual board in case someone needs it for reference:
http://www.imagesculptor.com/pool/index.php

Problem:
I'd like to over-ride the members profile themes when they get to the pool pages so I don't have to do this for every board style I make available. However, I don't want to affect their ability to choose their preffered style on the forum. I have created a sub-directory named "nfl" in the subSilver directory and modified the overall_header.tpl file and renamed it overall_header_nfl.tpl and subsequently modified the page_header.php file to point to the new header. The edited page_header.php file has been saved in an nfl_includes directory inside the includes directory.

The NFL _players.php file points to the desired nfl_includes/page_header.php file and works fine. However, if I've chosen a different board theme in my profile the appearance is attrocious.

What I've done:
Too much to detail everything. A big help has been the discovery of a little open source proggie called phpMyAdmin I found. I had no idea how I was even going to be able to see the database prior to discovering that! But more to the problem at hand - I think I've narrowed the culprit down to this line of code in the page_header.php file:

Code: [ Select ]
// Parse and show the overall header.
//
$template->set_filenames(array(
    'overall_header' => ( empty($gen_simple_header) ) ? 'nfl/overall_header_nfl.tpl' : 'simple_header.tpl')
);
  1. // Parse and show the overall header.
  2. //
  3. $template->set_filenames(array(
  4.     'overall_header' => ( empty($gen_simple_header) ) ? 'nfl/overall_header_nfl.tpl' : 'simple_header.tpl')
  5. );


So far so good. The revise parses the header I want for the subsilver theme. However, for the other themes, it tacks on the theme style file to the subSilver directory. In other words, the theme style sheet now looks like this football theme example:
Code: [ Select ]
<!-- link rel="stylesheet" href="templates/subSilver/templates/redIce/redIce.css" type="text/css" -->


I know that I can edit the path to the images in a given template by modifying this line in the subSilver.cfg (or whatever_board_theme.cfg):
$current_template_images = $current_template_path . "/images";
to an absolute path.

What I can't seem to locate is where I am getting the overlay of the member profile theme over the subsilver directory.

If it helps, here is the include in the NFL_players.php script for the header:
Code: [ Select ]
//
// Generate page
//

$page_title = "2003 NFL Season Pool Players";
include($phpbb_root_path . 'includes/nfl_includes/page_header.'.$phpEx);
  1. //
  2. // Generate page
  3. //
  4. $page_title = "2003 NFL Season Pool Players";
  5. include($phpbb_root_path . 'includes/nfl_includes/page_header.'.$phpEx);



Any thoughts on how I can resolve this?
Thanks.

---------------------------------------------------------------------------------------
Addendum 1
After a few hours sleep, I think I located, where to edit. I'm just not 100% sure what to edit. I located the following code in "includes/functions.php. Here's the code I believe needs modified:
Code: [ Select ]
// Set up style
    //
    if ( !$board_config['override_user_style'] )
    {
        if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
        {
            if ( $theme = setup_style($userdata['user_style']) )
            {
                return;
            }
        }
    }

    $theme = setup_style($board_config['default_style']);

    return;
}

function setup_style($style)
{
    global $db, $board_config, $template, $images, $phpbb_root_path;

    $sql = "SELECT *
        FROM " . THEMES_TABLE . "
        WHERE themes_id = $style";
    if ( !($result = $db->sql_query($sql)) )
    {
        message_die(CRITICAL_ERROR, 'Could not query database for theme info');
    }

    if ( !($row = $db->sql_fetchrow($result)) )
    {
        message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
    }

    $template_path = 'templates/' ;
    $template_name = $row['template_name'] ;

    $template = new Template($phpbb_root_path . $template_path . $template_name, $board_config, $db);

    if ( $template )
    {
        $current_template_path = $template_path . $template_name;
        @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');

        if ( !defined('TEMPLATE_CONFIG') )
        {
            message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
        }

        $img_lang = ( file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/images/lang_' . $board_config['default_lang'])) ) ? $board_config['default_lang'] : 'english';

        while( list($key, $value) = @each($images) )
        {
            if ( !is_array($value) )
            {
                $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);
            }
        }
    }

    return $row;
}

function encode_ip($dotquad_ip)
{
    $ip_sep = explode('.', $dotquad_ip);
    return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
}

function decode_ip($int_ip)
{
    $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
    return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}
  1. // Set up style
  2.     //
  3.     if ( !$board_config['override_user_style'] )
  4.     {
  5.         if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
  6.         {
  7.             if ( $theme = setup_style($userdata['user_style']) )
  8.             {
  9.                 return;
  10.             }
  11.         }
  12.     }
  13.     $theme = setup_style($board_config['default_style']);
  14.     return;
  15. }
  16. function setup_style($style)
  17. {
  18.     global $db, $board_config, $template, $images, $phpbb_root_path;
  19.     $sql = "SELECT *
  20.         FROM " . THEMES_TABLE . "
  21.         WHERE themes_id = $style";
  22.     if ( !($result = $db->sql_query($sql)) )
  23.     {
  24.         message_die(CRITICAL_ERROR, 'Could not query database for theme info');
  25.     }
  26.     if ( !($row = $db->sql_fetchrow($result)) )
  27.     {
  28.         message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
  29.     }
  30.     $template_path = 'templates/' ;
  31.     $template_name = $row['template_name'] ;
  32.     $template = new Template($phpbb_root_path . $template_path . $template_name, $board_config, $db);
  33.     if ( $template )
  34.     {
  35.         $current_template_path = $template_path . $template_name;
  36.         @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');
  37.         if ( !defined('TEMPLATE_CONFIG') )
  38.         {
  39.             message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
  40.         }
  41.         $img_lang = ( file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/images/lang_' . $board_config['default_lang'])) ) ? $board_config['default_lang'] : 'english';
  42.         while( list($key, $value) = @each($images) )
  43.         {
  44.             if ( !is_array($value) )
  45.             {
  46.                 $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value);
  47.             }
  48.         }
  49.     }
  50.     return $row;
  51. }
  52. function encode_ip($dotquad_ip)
  53. {
  54.     $ip_sep = explode('.', $dotquad_ip);
  55.     return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
  56. }
  57. function decode_ip($int_ip)
  58. {
  59.     $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
  60.     return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
  61. }


I'm about 90% sure this is where I need to make a change:
Code: [ Select ]
$template_path = 'templates/' ;
    $template_name = $row['template_name'] ;

    $template = new Template($phpbb_root_path . $template_path . $template_name, $board_config, $db);

    if ( $template )
    {
        $current_template_path = $template_path . $template_name;
        @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');

        if ( !defined('TEMPLATE_CONFIG') )
        {
            message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
        }
  1. $template_path = 'templates/' ;
  2.     $template_name = $row['template_name'] ;
  3.     $template = new Template($phpbb_root_path . $template_path . $template_name, $board_config, $db);
  4.     if ( $template )
  5.     {
  6.         $current_template_path = $template_path . $template_name;
  7.         @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg');
  8.         if ( !defined('TEMPLATE_CONFIG') )
  9.         {
  10.             message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__);
  11.         }


In English, I basically want this to happen:
"If template_name doesn't equal subSilver, then template_name equals subSilver

end Addendum 1
---------------------------------------------------------------------------------
Addendum 4
(just thinking -- I know this is out of order re: "addendums", but is $current_template_path the variable I should be looking at. Still haven't figured how that plays in -- *sighs
end Addendum 4
---------------------------------------------------------------------------------
Addendum 2

In the phpBB_themes table subSilver is row 1, theme_id 1

I'm thinking that if I insert into the above the following, I might get the result I'm looking for, but I'm either putting it in the wrong place, have the syntax wrong, or way off-track:

Code: [ Select ]
if ($template_name != subSilver)
   {
    $template_name == "subSilver";
   }
  1. if ($template_name != subSilver)
  2.    {
  3.     $template_name == "subSilver";
  4.    }


end Addendum 2
-------------------------------------------------------------------------------
Addendum 3

Nope - that didn't work and neither did several variations of it.
end Addendum 3
-------------------------------------------------------------------------------
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

There is nothing wrong with your approach, but to make your life really simply have you ever thought of just copying the part of the main template that you want to be the same for all profiles into each templates directory? By doing that you could also easily make so the pool pages look the same for all styles.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I'll have to run some comparisons on the image files and style sheets. At first glance, it may be an easier solution, however, it appears that the creators of the various styles did not necessarily stick to the naming conventions used in the subSilver theme.

It still may be easier overall to over-ride the user's style. Since I posted this, I've made some progress in understanding the variables and what is or isn't being queried from the data-base.

Since it's not critical at the moment, I've sort of set this one on the back burner for a bit and taken to understanding how to retrieve info from the database and write to it. Most of what I want to accomplish depends on a clear understanding of that.

My big question may come later when I'm trying to figure out how to make sure a player can only submit their picks once! *lol

Thanks for the suggestion. I'll play with it.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

After some serious thought and lot's of experimenting, I finally discovered how to make this work regardless of the user's style preference.

The biggest problem that I was running into is that I am using 4 template themes. The four themes are based on subSilver, redIce, icicle, and subVereor. Unfortunately, when the theme authors wrote the styles for the respective themes, they didn't consistantly use the variables or image names that were used in the subsilver theme. It was impractical to try to adjust the styles to match just one style without affecting the normal forums appearance.

The solution finally presented itself and required a minimal amount of editing. The functions which determined what theme a user was going to see based on their preferrences are initialized in the functions.php file and are called by common.php

The first step towards resolution was to save the common.php and functions.php in a unique sub directory which I placed in includes/nfl_includes

I then made one slight edit to the includes/nfl_includes/common.php to include includes/nfl_includes/functions.php instead of the normal board one which is located in includes/functions.php. This now allowed me to make modifications to the nfl_includes/functions.php file without affecting the standard forum templates.

The revision to the functions.php file were relatively minor.

I changed this:
Code: [ Select ]
//
    // Set up style
    //
    if ( !$board_config['override_user_style'] )
    {
        if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
        {
            if ( $theme = setup_style($userdata['user_style']) )
            {
                return;
            }
        }
    }

    $theme = setup_style($board_config['default_style']);

    return;
}
  1. //
  2.     // Set up style
  3.     //
  4.     if ( !$board_config['override_user_style'] )
  5.     {
  6.         if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
  7.         {
  8.             if ( $theme = setup_style($userdata['user_style']) )
  9.             {
  10.                 return;
  11.             }
  12.         }
  13.     }
  14.     $theme = setup_style($board_config['default_style']);
  15.     return;
  16. }


to this:

Code: [ Select ]
//
    // Set up style
    //
    if ( !$board_config['override_user_style'] )
    {
        if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
    
     {
            if ( $theme = setup_style($userdata['user_style']) )
            {
            //Added to default user style to subSilver
             $theme = setup_style($board_config['default_style']);
                return;
            }
        }
    }

    $theme = setup_style($board_config['default_style']);

    return;
}
//make user style always = subSilver for NFL Pool theme
if ( $userdata['user_style'] != 1)
 {
      $userdata['user_style'] = 1;
    }
  1. //
  2.     // Set up style
  3.     //
  4.     if ( !$board_config['override_user_style'] )
  5.     {
  6.         if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
  7.     
  8.      {
  9.             if ( $theme = setup_style($userdata['user_style']) )
  10.             {
  11.             //Added to default user style to subSilver
  12.              $theme = setup_style($board_config['default_style']);
  13.                 return;
  14.             }
  15.         }
  16.     }
  17.     $theme = setup_style($board_config['default_style']);
  18.     return;
  19. }
  20. //make user style always = subSilver for NFL Pool theme
  21. if ( $userdata['user_style'] != 1)
  22.  {
  23.       $userdata['user_style'] = 1;
  24.     }


Finally, I modified the include in all the pool pages from this:
Code: [ Select ]
include($phpbb_root_path . 'common.'.$phpEx);


to this:
Code: [ Select ]
include($phpbb_root_path . 'includes/nfl_includes/common.'.$phpEx);


My header, footer and body templates are all stored in a separate NFL directory within the subSilver template directory. Now I can make modifications to any templates for the pool and not affect any of the forum files.

In Summary:
This allows members to choose any theme they like for the phpBB forum pages. When they go to the NFL Pool pages all members themes are automatically converted to a standard theme I have in place for the pool, and then they are automatically reverted to their profile choice once they return to the forum pages. Took a lot of thought, but it was a great learning experience! It taught me a tremendous amount about how the variables and functions interact with each other.

An Invitation:
I expect that there may be a few here who enjoy sports. All are invited and welcome to have some fun with us and play some free sports pools this year:
Boasting Rights Sports Forums
http://www.imagesculptor.com/pool/index.php

Thank you for the prior help and advice everyone. Mods, you can now consider this subject resolved.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Thanks for the detailed explanation on what you did to solve the problem. I am glad you were able to resolve as well :)

Seems pretty simple what you did.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Yes, without a doubt it was...but being a novice at this it took a ton of thought! What is that? 2000 pounds?

Thanks BWM.

I still consder myself a novice at php, but I'm learning as quick as I can.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 90 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.