Early Prototype: Count & display guests and users in every forum in home page

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

Prototype in early stage.
On the homepage, for each forum. I want to display how many guests and how many registered users are visiting that forum or any topic inside that forum.
Here is the code:
in

Code: Select all

/includes/functions_display.php
more or less on on line 608 (its not strict the position) add

Code: Select all

$sql_registered_online = "SELECT COUNT(DISTINCT s.session_user_id) AS num_users 
                          FROM phpbb3_sessions s, phpbb3_sessions_keys k 
                          WHERE s.session_user_id <> 0 
                          AND s.session_time >= " . (time() - 300) . " 
                          AND s.session_forum_id = $forum_id";

$result_registered_online = $db->sql_query($sql_registered_online);
$row_registered_online = $db->sql_fetchrow($result_registered_online);
$db->sql_freeresult($result_registered_online);

$sql_guests_online = "SELECT COUNT(*) AS num_guests 
                      FROM phpbb3_sessions 
                      WHERE session_user_id = 0 
                      AND session_time >= " . (time() - 300) . " 
                      AND session_forum_id = " . $forum_id;

$result_guests_online = $db->sql_query($sql_guests_online);
$row_guests_online = $db->sql_fetchrow($result_guests_online);
$db->sql_freeresult($result_guests_online);

$registered_online = $row_registered_online['num_users'];
$guests_online = $row_guests_online['num_guests'];
$users_online = $guests_online + $registered_online;
in the same file immediately after inside $forum_row = array(

Code: Select all

'GUESTS_ONLINE'			=> $guests_online,
'REGISTERED_ONLINE'		=> $registered_online,
'USERS_ONLINE'			=> $users_online,
now in

Code: Select all

/styles/prosilver/template/forumlist_body.html 
write where do you want to display these info:

Code: Select all

<!-- IF forumrow.USERS_ONLINE > 0 -->
<br/>
<b>{forumrow.USERS_ONLINE} user online:</b> <!-- ENDIF --><!-- IF forumrow.GUESTS_ONLINE > 0 --><b style="color:green;">{forumrow.GUESTS_ONLINE} ospit<!-- IF forumrow.GUESTS_ONLINE == 1 -->e<!-- ENDIF --><!-- IF forumrow.GUESTS_ONLINE > 1 -->i<!-- ENDIF --></b> <!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 0 && forumrow.GUESTS_ONLINE > 0 --><b>e</b> <!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 0 --><b style="color:#b7720b;">{forumrow.REGISTERED_ONLINE} utent<!-- IF forumrow.REGISTERED_ONLINE == 1 -->e<!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 1 -->i<!-- ENDIF --></b><!-- ENDIF -->
I hope it will be of interest to someone and maybe even a plugin will come out of it
Last edited by superdan77 on Fri Apr 28, 2023 4:06 pm, edited 1 time in total.
For very private msg, please contact me with the form @ https://www.cdlab.it
User avatar
RomaamoR
Registered User
Posts: 289
Joined: Tue Feb 24, 2015 4:45 pm
Location: Ukraine
Name: Roman

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by RomaamoR »

I like your idea. Do you want to display guests and users like this?

Image
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

RomaamoR wrote: Sat Apr 01, 2023 7:56 pm I like your idea. Do you want to display guests and users like this?

Image
This is exactly my idea!
Only thing: I'm not sure I want to list all the names of the users in a forum. A plugin option that makes you choose whether to show individual names or just the toal number of users refgistered online would be nice.
Does a plugin already exist to do this?
For very private msg, please contact me with the form @ https://www.cdlab.it
User avatar
RomaamoR
Registered User
Posts: 289
Joined: Tue Feb 24, 2015 4:45 pm
Location: Ukraine
Name: Roman

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by RomaamoR »

superdan77 wrote: Sun Apr 02, 2023 9:00 am Does a plugin already exist to do this?
No. There is no such plugin. It `s Magic HTML. :)
Tread
Registered User
Posts: 104
Joined: Thu Nov 14, 2019 9:52 pm

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by Tread »

There is an ext already but not on .com it seems a lot are making new ext's and not bothering with the hassle that this site gives with validation rubbish due to the time they take.
User avatar
warmweer
Jr. Extension Validator
Posts: 11784
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by warmweer »

Tread wrote: Sun Apr 02, 2023 12:43 pm There is an ext already but not on .com it seems a lot are making new ext's and not bothering with the hassle that this site gives with validation rubbish due to the time they take.
It looks like English and using my imagination I can guess (or imagine) a meaning but perhaps you could reword that (e.g. also explicitly name and point to the extension you mentioned)
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

RomaamoR wrote: Sun Apr 02, 2023 11:53 am
superdan77 wrote: Sun Apr 02, 2023 9:00 am Does a plugin already exist to do this?
No. There is no such plugin. It `s Magic HTML. :)
could you please share your code i can compare to mine and understand if i can do it better than that ive shared above?
For very private msg, please contact me with the form @ https://www.cdlab.it
User avatar
RomaamoR
Registered User
Posts: 289
Joined: Tue Feb 24, 2015 4:45 pm
Location: Ukraine
Name: Roman

Re: [3.3][DEV] Early Prototype: Count & display guests and users in every forum in home page

Post by RomaamoR »

superdan77 wrote: Sun Apr 02, 2023 12:57 pm
could you please share your code i can compare to mine and understand if i can do it better than that ive shared above?
This is not an extension. This is a simulation of the code in the browser debugger.
Image
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3915
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by Kailey »

This is not really an extension in development, so I've moved it to custom coding.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

Well my code do alomost that, except displaying member`s name.
Could be the beginning of a new plugin
For very private msg, please contact me with the form @ https://www.cdlab.it
User avatar
P_I
Community Team Member
Community Team Member
Posts: 2463
Joined: Tue Mar 01, 2011 8:35 pm
Location: Western Canada 🇨🇦

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by P_I »

superdan77 wrote: Sun Apr 02, 2023 6:02 pm Could be the beginning of a new plugin
The correct phpBB terminology is extension, not plugin.
Normal people… believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. – Scott Adams
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

Sorry, im new to phpbb3
For very private msg, please contact me with the form @ https://www.cdlab.it
Markus62
Registered User
Posts: 6
Joined: Sat Apr 22, 2023 5:17 am

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by Markus62 »

Hi Dan,
I made many attempts but I failed miserably, I would like to insert it to make it appear before the REPLIES column, can you kindly tell me where to paste your code? Thanks in advance

Code: Select all

/styles/prosilver/template/forumlist_body.html

Code: Select all

<!-- IF forumrow.USERS_ONLINE > 0 -->
<br/>
<b>{forumrow.USERS_ONLINE} user online:</b> <!-- ENDIF --><!-- IF forumrow.GUESTS_ONLINE > 0 --><b style="color:green;">{forumrow.GUESTS_ONLINE} ospit<!-- IF forumrow.GUESTS_ONLINE == 1 -->e<!-- ENDIF --><!-- IF forumrow.GUESTS_ONLINE > 1 -->i<!-- ENDIF --></b> <!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 0 && forumrow.GUESTS_ONLINE > 0 --><b>e</b> <!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 0 --><b style="color:#b7720b;">{forumrow.REGISTERED_ONLINE} utent<!-- IF forumrow.REGISTERED_ONLINE == 1 -->e<!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 1 -->i<!-- ENDIF --></b><!-- ENDIF -->
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

Hi,
on line 52 more or less (prosilver)

Code: Select all

<a href="{forumrow.U_VIEWFORUM}" class="forumtitle">{forumrow.FORUM_NAME}</a>
						<!-- IF forumrow.FORUM_DESC --><br />{forumrow.FORUM_DESC}<!-- ENDIF -->
						<!-- IF forumrow.USERS_ONLINE > 0 -->
						<br/>
						<b>{forumrow.USERS_ONLINE} user online:</b> <!-- ENDIF --><!-- IF forumrow.GUESTS_ONLINE > 0 --><b style="color:green;">{forumrow.GUESTS_ONLINE} ospit<!-- IF forumrow.GUESTS_ONLINE == 1 -->e<!-- ENDIF --><!-- IF forumrow.GUESTS_ONLINE > 1 -->i<!-- ENDIF --></b> <!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 0 && forumrow.GUESTS_ONLINE > 0 --><b>e</b> <!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 0 --><b style="color:#b7720b;">{forumrow.REGISTERED_ONLINE} utent<!-- IF forumrow.REGISTERED_ONLINE == 1 -->e<!-- ENDIF --><!-- IF forumrow.REGISTERED_ONLINE > 1 -->i<!-- ENDIF --></b><!-- ENDIF -->
That is under the description of forums and after a test i can confirm it works
For very private msg, please contact me with the form @ https://www.cdlab.it
User avatar
superdan77
Registered User
Posts: 55
Joined: Wed Mar 29, 2023 3:14 pm

Re: Early Prototype: Count & display guests and users in every forum in home page

Post by superdan77 »

i edited the original code:
session_user_id <> 0
instead of
session_user_id <> 1

and
WHERE session_user_id = 0
instead of
WHERE session_user_id = 1
For very private msg, please contact me with the form @ https://www.cdlab.it

Return to “phpBB Custom Coding”