Fake random activity

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
Post Reply
Rbix
Registered User
Posts: 9
Joined: Sat Nov 03, 2018 5:26 pm

Fake random activity

Post by Rbix » Sat Nov 03, 2018 5:33 pm

Hi,

I'm trying to set some fake activity on my brand new community. The code below seems to work fine, but I have two little issues:
1. Every page refresh I get a random list of new fake users. How can I set this, that it will only be execute when the users activity list should be updated?
2. For some reason, my Admin user is not always showing up in the activity list. When I logged-in with a regular user (that not in the fake list) it seems to be fine.

functions.php

Code: Select all

$my_fake_users = array(48,49,50,51,52);
shuffle($my_fake_users );
$fake_users_to_show = rand(1, 4);
$fake_selected = array_slice($my_fake_users , $fake_users_to_show );
$online_users = array(
		'online_users'			=> fake_selected,
		'hidden_users'			=> array(),
		'total_online'			=> 0,
		'visible_online'		=> sizeof(fake_selected),
		'hidden_online'			=> 0,
		'guests_online'			=> 0,
	);
Thanks in advance :)

User avatar
ViolaF
Registered User
Posts: 1422
Joined: Tue Aug 14, 2012 11:52 pm

Re: Fake random activity

Post by ViolaF » Sat Nov 03, 2018 5:40 pm

Rbix wrote:
Sat Nov 03, 2018 5:33 pm
functions.php

Code: Select all

$my_fake_users = array(48,49,50,51,52);
shuffle($my_fake_users );
$fake_users_to_show = rand(1, 4);
$fake_selected = array_slice($my_fake_users , $fake_users_to_show );
$online_users = array(
		'online_users'			=> $fake_selected,
		'hidden_users'			=> array(),
		'total_online'			=> 0,
		'visible_online'		=> sizeof($fake_selected),
		'hidden_online'			=> 0,
		'guests_online'			=> 0,
	);

Rbix
Registered User
Posts: 9
Joined: Sat Nov 03, 2018 5:26 pm

Re: Fake random activity

Post by Rbix » Sat Nov 03, 2018 5:58 pm

Sorry, but I didn't quite understand if there is something new in the code that I shoulde have been noticed.
Last edited by Mick on Sun Nov 04, 2018 11:51 am, edited 1 time in total.
Reason: Removed unnecessary quoting.

User avatar
Toxyy
Registered User
Posts: 594
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: Fake random activity

Post by Toxyy » Sat Nov 03, 2018 6:55 pm

Rbix wrote:
Sat Nov 03, 2018 5:58 pm
Sorry, but I didn't quite understand if there is something new in the code that I shoulde have been noticed.
You forgot the $ sign on some vars
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

My extensions:
[3.2][BETA] Anonymous Posts || [3.2][RC] Show User Activity

Rbix
Registered User
Posts: 9
Joined: Sat Nov 03, 2018 5:26 pm

Re: Fake random activity

Post by Rbix » Sun Nov 04, 2018 5:15 am

Toxyy wrote:
Sat Nov 03, 2018 6:55 pm
You forgot the $ sign on some vars
My mistake, I changed the names of the variables here, but in my code it is fine.
My issues are still remaining,
Last edited by Mick on Sun Nov 04, 2018 11:53 am, edited 1 time in total.
Reason: Removed unnecessary quoting.

User avatar
Toxyy
Registered User
Posts: 594
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: Fake random activity

Post by Toxyy » Sun Nov 04, 2018 5:36 am

Rbix wrote:
Sun Nov 04, 2018 5:15 am
My mistake, I changed the names of the variables here, but in my code it is fine.
My issues are still remaining,

Code: Select all

$my_fake_users = array(48,49,50,51,52);
$seed = floor(time()/(60*5));
srand($seed);
$fake_users_to_show = rand(1, 4);
$fake_selected = array_slice($my_fake_users , $fake_users_to_show );
array_push($fake_selected, 2);
shuffle($fake_selected);
$online_users = array(
		'online_users'			=> $fake_selected,
		'hidden_users'			=> array(),
		'total_online'			=> 0,
		'visible_online'		=> sizeof($fake_selected),
		'hidden_online'			=> 0,
		'guests_online'			=> 0,
	);
This solves your problems, it always adds the user #2 to the list and shuffles after that. It also makes a new random list every 5 minutes.
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

My extensions:
[3.2][BETA] Anonymous Posts || [3.2][RC] Show User Activity

Rbix
Registered User
Posts: 9
Joined: Sat Nov 03, 2018 5:26 pm

Re: Fake random activity

Post by Rbix » Sun Nov 04, 2018 7:26 am

Thank you!

Is there an explanation why I need to add my admin user (ID 2) manually? Why this issue doesn't occur on other users?

Thanks.
Last edited by Mick on Sun Nov 04, 2018 11:54 am, edited 1 time in total.
Reason: Removed unnecessary quoting.

User avatar
Toxyy
Registered User
Posts: 594
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: Fake random activity

Post by Toxyy » Sun Nov 04, 2018 10:04 am

As a prelude, I'm answering questions based on your snippet, not its inclusion in phpbb.

You make an array of some 2 digit IDs. You then shuffle them, pick a random few of them, and display them. I don't know what your admin ID is, but I do know that if you randomly pick a few from a list, you're not going to always get a specific one. So I changed it, so that it adds a specific ID after picking a random few. Change the 2 to your admin ID. In hindsight its not as random as having two shuffles, but whatever.
Last edited by Mick on Sun Nov 04, 2018 11:55 am, edited 1 time in total.
Reason: Removed unnecessary quoting.
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

My extensions:
[3.2][BETA] Anonymous Posts || [3.2][RC] Show User Activity

Rbix
Registered User
Posts: 9
Joined: Sat Nov 03, 2018 5:26 pm

Re: Fake random activity

Post by Rbix » Sun Nov 04, 2018 11:38 am

Thanks for the reply.

I don't want to include my admin user. I meant that when I'm logged in to the board with my admin user, it doesn't appear on the activity list when this code is active. When I'm in with a different user (that its ID is not in the code also), everything is fine. The question is, why it is only happen with my admin user.
Last edited by Mick on Sun Nov 04, 2018 11:56 am, edited 1 time in total.
Reason: Removed unnecessary quoting.

User avatar
Mick
Support Team Member
Support Team Member
Posts: 20366
Joined: Fri Aug 29, 2008 9:49 am
Location: Cardiff

Re: Fake random activity

Post by Mick » Sun Nov 04, 2018 11:49 am

@All: Please use the Quote function only when it is needed to make your reply clear and only quote the parts necessary not the whole post every time. Excessive quoting (especially of long messages and/or multiple images) makes reading the post extremely difficult. Nobody wants to read the same post over and over, thanks.
"The more connected we get the more alone we become" - Kyle Broflovski

There are no ‘threads’ in phpBB, they are topics.

Rbix
Registered User
Posts: 9
Joined: Sat Nov 03, 2018 5:26 pm

Re: Fake random activity

Post by Rbix » Mon Nov 05, 2018 6:43 pm

Toxyy wrote:
Sun Nov 04, 2018 10:04 am
As a prelude, I'm answering questions based on your snippet, not its inclusion in phpbb.
Is there a way to add them to the session users? So the their online status will be green?

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 6 guests