phpBB SnippetsStatistics manipulation

Post Reply
User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England
Contact:

Statistics manipulation

#1

Post by Restless Rancor » October 15th, 2018, 7:20 pm


This snippet enables you to manipulate the numbers displayed on the index's statistics display.
It also enables you to prevent hidden forums (a staff forum for example) from being counted in the display.


It comes in three parts. Read them carefully:
  1. Ignore Private Forums in Statistics. [Go to...]
  2. Statistics Manipulation. [Go to...]
  3. Comma separation in numbers integration.
    1. Ignore Private Forums in Statistics Integration. [Go to...]
    2. Statistics Manipulation Integration. [Go to...]
You can install Parts 1 and 2, or both.
Only follow Part 3 if you have this snippet installed already. If you do, you can install Parts 3a and 3b, or both.

Note: Before you ask, because someone will, we only utilize Part 3a of this snippet on this forum.
Also Note: My original request for this code has been released as an extension for phpBB 3.2.3. This snippet still works but is untested with the extension. I'll get to that soon. [Extension Link]



Tested On:


Part 1: Ignore Private Forums In Statistics. [Go to top]

Open root/index.php

Find:

Code: Select all

// Assign index specific vars
$template->assign_vars(array(
	'TOTAL_POSTS'	=> $user->lang('TOTAL_POSTS_COUNT', (int) $config['num_posts']),
	'TOTAL_TOPICS'	=> $user->lang('TOTAL_TOPICS', (int) $config['num_topics']),
Replace with:

Code: Select all

$sql = 'SELECT forum_id, forum_posts_approved, forum_topics_approved
        FROM ' . FORUMS_TABLE . '
        WHERE ' . $db->sql_in_set('forum_id', array(FORUM_ID, FORUM_ID2));
$result = $db->sql_query($sql);

$hidden_posts = 0;
$hidden_topics = 0;
while ($row = $db->sql_fetchrow($result))
{
    $hidden_posts  += (int) $row['forum_posts_approved'];
    $hidden_topics += (int) $row['forum_topics_approved'];
}
$db->sql_freeresult($result);

// Assign index specific vars
$template->assign_vars(array(
	'TOTAL_POSTS'	=> $user->lang('TOTAL_POSTS_COUNT', (int) $config['num_posts'] - $hidden_posts),
	'TOTAL_TOPICS'	=> $user->lang('TOTAL_TOPICS', (int) $config['num_topics'] - $hidden_topics),
Change FORUM_ID and FORUM_ID2 to the forum ID's of the forums you want to exclude from the statistics. For example, that line could show:
WHERE ' . $db->sql_in_set('forum_id', array(5,6,11));
which will hide forum 5, 6 and 11 from the statistics.
Note: You'll need to Resynchronise statistics and post counts via your ACP when you delete a topic/post.


Part 2: Statistics Manipulation. [Go to top]

Open root/index.php

To manipulate Total Posts:
Find:

Code: Select all

'TOTAL_POSTS'	=> $user->lang('TOTAL_POSTS_COUNT', (int) $config['num_posts'] - $hidden_posts),
In-Line Find:

Code: Select all

$config['num_posts'] - $hidden_posts
In-Line Add After:

Code: Select all

 +x
To manipulate Total Topics:
Find:

Code: Select all

'TOTAL_TOPICS'	=> $user->lang('TOTAL_TOPICS', (int) $config['num_topics'] - $hidden_topics),
In-Line Find:

Code: Select all

$config['num_topics'] - $hidden_topics
In-Line Add After:

Code: Select all

 +x
To manipulate Total Users:
Find:

Code: Select all

'TOTAL_USERS'	=> $user->lang('TOTAL_USERS', (int) $config['num_users']),
In-Line Find:

Code: Select all

$config['num_users']
In-Line Add After:

Code: Select all

 +x
Replace x with the number to increase, replace + with an alternative arithmetic operator if needed:

To use multiplication or division you must remember BIDMAS. An example of total posts multiplied by 100:
($config['num_posts'] - $hidden_posts)*100),
(Total Posts take away hidden posts) multiplied by 100
The number starts at $ so the opening parenthesis is placed before it. The number ends before ), so the closing parenthesis goes before it.
Don't get confused by the closing ), - this is not part of the number.

Usable Arithmetic Operators:
+ Sum of $x and $y
- Difference of $x and $y
Must consider BIDMAS:
* Product of $x and $y
% Remainder of $x divided by $y
** Result of raising $x to the $y'th power
Source

Example of multiple uses, again remember BIDMAS:
(($config['num_users'])+3)**6),
((2 actual members) plus 3) multiply by the power of 6) = 15625

Note: This only effects statistics displayed on the index page.
If you haven't applied the changes in Part 1 you won't see - $hidden_posts or - $hidden_topics but maths is maths, just remember to use BIDMAS.


Part 3a: Comma separation in numbers integration: Ignore Private Forums In Statistics: [Go to top]

Open root/index.php

Find:

Code: Select all

// Assign index specific vars
$template->assign_vars(array(
Add before:

Code: Select all

$sql = 'SELECT forum_id, forum_posts_approved, forum_topics_approved
        FROM ' . FORUMS_TABLE . '
        WHERE ' . $db->sql_in_set('forum_id', array(FORUM_ID, FORUM_ID2));
$result = $db->sql_query($sql);

$hidden_posts = 0;
$hidden_topics = 0;
while ($row = $db->sql_fetchrow($result))
{
    $hidden_posts  += (int) $row['forum_posts_approved'];
    $hidden_topics += (int) $row['forum_topics_approved'];
}
$db->sql_freeresult($result);
Find:

Code: Select all

'TOTAL_POSTS'   => $user->lang('TOTAL_POSTS_COUNT', number_format((int) $config['num_posts'])),
'TOTAL_TOPICS'   => $user->lang('TOTAL_TOPICS', number_format((int) $config['num_topics'])),
Replace with:

Code: Select all

	'TOTAL_POSTS'   => $user->lang('TOTAL_POSTS_COUNT', number_format((int) $config['num_posts'] - $hidden_posts)),
	'TOTAL_TOPICS'   => $user->lang('TOTAL_TOPICS', number_format((int) $config['num_topics'] - $hidden_topics)),
Change FORUM_ID and FORUM_ID2 to the forum ID's of the forums you want to exclude from the statistics. For example, that line could show:
WHERE ' . $db->sql_in_set('forum_id', array(5,6,11));
which will hide forum 5, 6 and 11 from the statistics.
Note: You'll need to Resynchronise statistics and post counts via your ACP when you delete a topic/post.

Part 3b: Comma separation in numbers integration: Statistics Manipulation: [Go to top]

Open root/index.php

To manipulate Total Posts:
Find:

Code: Select all

'TOTAL_POSTS'	=> $user->lang('TOTAL_POSTS_COUNT', number_format((int) $config['num_posts'] - $hidden_posts)),
In-Line Find:

Code: Select all

$config['num_posts'] - $hidden_posts
In-Line Add After:

Code: Select all

 +x
To manipulate Total Topics:
Find:

Code: Select all

'TOTAL_TOPICS'	=> $user->lang('TOTAL_TOPICS', number_format((int) $config['num_topics'] - $hidden_topics)),
In-Line Find:

Code: Select all

$config['num_topics'] - $hidden_topics
In-Line Add After:

Code: Select all

 +x
To manipulate Total Users:
Find:

Code: Select all

'TOTAL_USERS'	=> $user->lang('TOTAL_USERS', number_format((int) $config['num_users'])),
In-Line Find:

Code: Select all

$config['num_users']
In-Line Add After:

Code: Select all

 +x
Replace x with the number to increase, replace + with an alternative arithmetic operator if needed:

To use multiplication or division you must remember BIDMAS. An example of total posts multiplied by 100:
($config['num_posts'] - $hidden_posts)*100)),
(Total Posts take away hidden posts) multiplied by 100
The number starts at $ so the opening parenthesis is placed before it. The number ends before )), so the closing parenthesis goes before it.
Don't get confused by the closing )), - this is not part of the number.

Usable Arithmetic Operators:
+ Sum of $x and $y
- Difference of $x and $y
Must consider BIDMAS:
* Product of $x and $y
% Remainder of $x divided by $y
** Result of raising $x to the $y'th power
Source

Example of multiple uses, again remember BIDMAS:
(($config['num_users'])+3)**6),
((2 actual members) plus 3) multiply by the power of 6) = 15625

Note: This only effects statistics displayed on the index page.
If you haven't applied the changes in Part 3a you won't see - $hidden_posts or - $hidden_topics but maths is maths, just remember to use BIDMAS.
Changelog:
► Show Spoiler


These aren't the droids you're looking for.

Post Reply

Topic Subscribers

1 user subscribed to this topic: Restless Rancor