numbers

Add commas to your forum’s stats

These quick few code changes, though small, are one of the best accessibility enhancements you can make to your forum. Using PHP number_format(), convert the statistics on your board from random digits to human-readable numbers.

What we’re trying to achieve

Take a look at this article’s featured image. What we’ll be trying to achieve in this article is neatly separated statistics across your forum. Presently in phpBB when you have a number longer then 3 digits there are no separators, for example: “1234″. We’ll be using the PHP number_format() function to automagically insert commas where necessary – so rather than being a value from a database, it’s a human-readable number: eg: “1,234″.

Preparation

To complete this tutorial, you’ll need a decent Source Code Editor. You’ll also need to be confident enough performing the following steps around raw PHP code, which you may not be familiar with.

Step 1) Required Edits

This is the most important step as it allows the language file to accept non-integer paramaters. Failure to complete this step will mean this tweak won’t work no matter what edits you make to other files – for example instead of seeing “12,500″ you’ll just see “12″.

Open: /language/en/common.php

Find:

'TOTAL_POSTS_OTHER' => 'Total posts <strong>%d</strong>',
'TOTAL_POSTS_ZERO'  => 'Total posts <strong>0</strong>',
'TOPIC_REPORTED'    => 'This topic has been reported',
'TOTAL_TOPICS_OTHER'=> 'Total topics <strong>%d</strong>',
'TOTAL_TOPICS_ZERO' => 'Total topics <strong>0</strong>',
'TOTAL_USERS_OTHER' => 'Total members <strong>%d</strong>',

Replace with:

'TOTAL_POSTS_OTHER' => 'Total posts <strong>%s</strong>',
'TOTAL_POSTS_ZERO'  => 'Total posts <strong>0</strong>',
'TOPIC_REPORTED'    => 'This topic has been reported',
'TOTAL_TOPICS_OTHER'=> 'Total topics <strong>%s</strong>',
'TOTAL_TOPICS_ZERO' => 'Total topics <strong>0</strong>',
'TOTAL_USERS_OTHER' => 'Total members <strong>%s</strong>',

Step 2) Index page

This step will cover all of the statistics which appear on the index page. Starting off with the overall topic, member and post counts.

Open: root/index.php

Find:

'TOTAL_POSTS'   => sprintf($user->lang[$l_total_post_s], $total_posts),
'TOTAL_TOPICS'  => sprintf($user->lang[$l_total_topic_s], $total_topics),
'TOTAL_USERS'   => sprintf($user->lang[$l_total_user_s], $total_users),

Replace with:

'TOTAL_POSTS'   => sprintf($user->lang[$l_total_post_s], number_format($total_posts)),
'TOTAL_TOPICS'  => sprintf($user->lang[$l_total_topic_s], number_format($total_topics)),
'TOTAL_USERS'   => sprintf($user->lang[$l_total_user_s], number_format($total_users)),

For the “topics” and “posts” columns:

Open: /includes/functions_display.php

Find:

'TOPICS'                => $row['forum_topics'],

Replace with:

'TOPICS'                => number_format($row['forum_topics']),

Find:

$post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';

Replace with:

$post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? number_format($row['forum_posts']) : '';

Step 3) Viewforum

Now we’re going to add the function to the “replies” and “views” columns in viewforum.php

Open: root/viewforum.php

Find:

'REPLIES'           => $replies,
'VIEWS'             => $row['topic_views'],

Replace with:

'REPLIES'           => number_format($replies),
'VIEWS'             => number_format($row['topic_views']),

Step 4) Post count

Let’s go a step further and reward those high-posting members with a comma when they pass 1,000 posts.

Open: root/viewtopic.php

Find:

'posts'         => $row['user_posts'],

Replace with:

'posts'         => number_format($row['user_posts']),

Step 5) Search results

Finally we’re going to make sure the “replies” and “views” counts in search results get the same treatment.

Open: root/search.php

Find:

'TOPIC_REPLIES'     => $replies,
'TOPIC_VIEWS'       => $row['topic_views'],

Replace with:

'TOPIC_REPLIES'     => number_format($replies),
'TOPIC_VIEWS'       => number_format($row['topic_views']),

And that’s your lot! Upload all modified files, refresh your browser and watch those little beauties appear! (You might also need to purge your cache using the button on the ACP front page).

Support / Donations

If you run into trouble, support for this guide is freely available over on the Support Forum. If you’d like to make a donation as a token of your appreciation you can do so here. And if I’ve missed anything, you can let me know here. Magic.