Home

Your premium source for custom modification services for phpBB

  logo

HomeForumsBlogMOD ManagerFAQSearchRegisterLogin

Comments November 11, 2008

User Selectable Board Width

Filed under: MOD Writing — Dave Rathbun @ 11:57 pm CommentsComments (6) 

I got an interesting request for a feature on a new board I’m working on tonight. This is a phpBB2 board (of course :) ) and I am using a variation on subSilver. That template is “fluid” meaning the width will expand to fit the size of the window. Years ago having a site expand to fit the window was okay. Now that some people are using 1600×1200 pixel resolutions it can be hard to read. The human eye / brain simply can’t scan a line of text that far without losing track of where you are. I solve this myself by running my browsers at less than full screen, but that’s my choice. If someone else chooses to run their browser window stretched over two high-resolution monitors that should be there choice as well.

Where is this going? Based on the remarks made earlier tonight I worked out a really quick and easy MOD for phpBB2 (and the idea would work just as well for phpBB3). It’s a few bits of code that allow users to set a fixed width for the board (by pixel count) or opt for a full screen display. It took about an hour from initial concept to execution. :)

Building the User Selectable Board Width MOD

Step one is creating a place to store this information.

alter table phpbb_users
add user_board_width smallint(5) unsigned not null default 0;

I opted to use smallint(5) because the highest value I anticipate is 1600. The MySQL smallint data type goes up to 65535 for an unsigned value, so that should be plenty. The default value is defined as 0, which my code will interpret as full screen. Any other value will be used as the screen width.

Step 2 is to let the user enter something into that new value. Here’s what that looks like:

Screen Shot

The code to build the selector and handle the user input value is all in includes/usercp_register.php which is the dual-purpose register and edit profile program.

What I did next I will call step 2.5 since it would not really be necessary. I added admin control that lets the board owner set the default width in case the user doesn’t pick anything. The value for that is stored in the phpbb_config table and therefore added to the $board_config array.

Step 4 is to collect the user preference and pass it to the template. That process takes place in includes/page_header.php like this:

'TABLE_WIDTH' => (intval($userdata['user_board_width']) == 0 ? $board_config['default_board_width'] : intval($userdata['user_board_width'])),

As you can see, if the $userdata array contains a zero value for the board width, the default value entered by the board admin will be used. Otherwise the user profile option is converted to an integer and sent to the template. That’s all the coding that was required. The template changes are even easier.

subSilver Template Changes

For subSilver the final step is very simple. Open the overall_header and find the top table that contains the rest of the page structure. It starts out looking like this:

<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">

Change it to this, and you’re done:

<table width="{TABLE_WIDTH}" cellspacing="0" cellpadding="0" border="0" align="center">

Fluid versus Fixed Design Debate

The debate over fixed versus fluid design can be as contentious as the debate comparing Mac to PC or IE to FF. Well, perhaps not that bad, but I’ve seen it get close. ;) As a user, I perfer fluid sites so I can resize the window to fit my preferences. As a designer I think fixed width designs are easier to create. Making something scale well from 800 pixels all the way up to 1600 pixels (or beyond) is quite a challenge. When I was looking for templates for one of my blogs, I found that the ratio of fixed to fluid templates was probably about 5:1 (five fixed for every one fluid). And many of the fluid templates were … less than useful.

The subSilver template is a great example of a style that works both ways. For any style that fits the same pattern, having this simple MOD installed puts the choice back into the hands (and mouse) of your user. I think that’s a good thing.

I will be writing up the full MOD install and posting it in my MOD Catalog so that it’s available on this site.

6 Comments »

  1. Not to sound like a big braggart, but I did that a year ago, except it was either a choice between 100% and 600 px. To the user, these options were Wide, and Narrow, respectively. :-)

    I didn’t use a board config since that’s unnecessary for my implementation. I just did an if/else.

    Comment by Dog Cow — November 12, 2008 @ 6:27 pm

  2. That works too. :) I’m certainly not aware of every single MOD Request that goes through at phpbb.com, but I had never seen this one. I’m sure your users appreciate it, and it’s certainly simple.

    You’re right that the admin panel bit is not necessary, especially for a single board installation. But some folks are not comfortable editing the code at all, so having it there was intended for those users that might install the MOD once I get it written up.

    Comment by Dave Rathbun — November 12, 2008 @ 10:57 pm

  3. Looks good and interesting, I will certainly test the MOD to see if I can use it on my custom template. ;)

    Comment by dogs and things — November 13, 2008 @ 9:28 am

  4. Well, it turns out my memory was a bit faulty, but I wrote a blog entry about it last August (linked from my name) which has the exact details.

    As I recall, I in the page footer I made a template variable which was S_WIDTH, I think, and also I added a template switch, because having narrow would turn off the site trackers which show latest posts, gallery pictures, and blog entries. Having it set to wide would then show the trackers once again. I’ve since changed the layout so now the site is always flexible to whatever size the browser window is. The option has just been renamed to “Show Trackers: yes/no?”

    Comment by Dog Cow — November 13, 2008 @ 10:43 am

  5. Few details to be found in that blog entry, honestly speakin’ :)

    Thanks for the link anyways.

    Comment by dogs and things — November 13, 2008 @ 1:46 pm

  6. It was written for the users of the site, not for programmers. Anyway, it just has the actual measurements I ended up going with.

    Comment by Dog Cow — November 13, 2008 @ 3:46 pm

RSS feed for comments on this post.

Leave a comment

Tags allowed in comments:
<a href="" title=""> <acronym title=""> <blockquote cite=""> <code> <strong> <em> <u> <sup> <sub> <strike>

Confirm submission by clicking only the marked checkbox:

 **             

Powered by WordPress