Track Users

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
User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Track Users

Post by LuigiMdg » Sat Jan 27, 2018 10:00 am

Hi..
How to track user's when is online and viewing an external custom page..?

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Track Users

Post by posey » Sat Jan 27, 2018 11:48 am

https://github.com/phpbb-extensions/boa ... r.php#L121

https://github.com/phpbb-extensions/pag ... r.php#L128

Are two examples on how you can do it.
These are explicit for the 'Who is online' page, but the method/idea can be used elsewhere aswell.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Re: Track Users

Post by LuigiMdg » Sun Jan 28, 2018 2:12 am

It's ok, but I've tested in localhost with 2 browser..
If I write one of the two scripts and taking the function:

Code: Select all

viewonline_page($eventName)
They do not show the $eventName in the Who's Online..
Otherwise in addition to the title I would pass the url and the game would be done..!
However, the page on which I would like to insert the code for tracking users, is a page written in PHP and HTML, but where users are logged in through a script that allows them to access their profile directly from the personalized page..
So there should not be any problems like this with the tracker.. Right?

User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Re: Track Users

Post by LuigiMdg » Mon Feb 05, 2018 4:23 pm

Please help me :(

User avatar
GanstaZ
Registered User
Posts: 334
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Track Users

Post by GanstaZ » Mon Feb 05, 2018 6:21 pm

There are 2 beautiful examples above. There's everything you need for your code.

User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Re: Track Users

Post by LuigiMdg » Sat Feb 10, 2018 6:39 pm

GanstaZ wrote:
Mon Feb 05, 2018 6:21 pm
There are 2 beautiful examples above. There's everything you need for your code.
Yes.. But when I try to import the event listener, this is the error:

Code: Select all

Interface 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface' not found
I've try to install the complete extension and include the file but the result is the same error

User avatar
GanstaZ
Registered User
Posts: 334
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Track Users

Post by GanstaZ » Sat Feb 10, 2018 10:12 pm

How & what do you import? In your own listener class you need to have something like this to use symfony subscriber:

Code: Select all

<?php
/**
* ...
*
*/

namespace path\to\file;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Event listener
*/
class listener implements EventSubscriberInterface
or

Code: Select all

<?php
/**
* ...
*
*/

namespace path\to\file;

/**
* Event listener
*/
class listener implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Then subscribe

Code: Select all

	/**
	* Assign functions defined in this class to event listeners in the core
	*
	* @return array
	* @static
	* @access public
	*/
	static public function getSubscribedEvents()
	{
		return array(
			'core.viewonline_overwrite_location' => 'your_method_name',
		);
	}
	
	public function your_method_name($event)
	{
	    if ($event['on_page'][1] === 'app')
            {
                ...
            }
	}

User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Re: Track Users

Post by LuigiMdg » Wed Apr 04, 2018 11:26 pm


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

Re: Track Users

Post by Mick » Thu Apr 05, 2018 8:20 am

Doubtful, that’s a mod for 3.0.
"The more connected we get the more alone we become" - Kyle Broflovski

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

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Track Users

Post by posey » Sat Apr 07, 2018 8:53 am

What have you already tried ?

Your listener.php inside the event folder of your extension:

Code: Select all

<?php

namespace acme\demo\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Event listener
*/
class listener implements EventSubscriberInterface
{
	/**
	* Assign functions defined in this class to event listeners in the core
	*
	* @return array
	* @static
	* @access public
	*/
	static public function getSubscribedEvents()
	{
		return array(
			'core.viewonline_overwrite_location'	=> 'viewonline_page',
		);
	}

	/**
	* Show users as viewing the Custom Page on Who Is Online page
	*
	* @param \phpbb\event\data $event The event object
	* @return void
	* @access public
	*/
	public function viewonline_page($event)
	{
		if ($event['on_page'][1] === 'custompage' && strrpos($event['row']['session_page'], 'custompage') === 0)
		{
			$event['location'] = 'Custom page title';
			$event['location_url'] = 'Custom page link (url)';
		}
	}
}
Replace the namespace, where acme is the vendor and demo to your extension name.
In the viewonline_page($event) function, replace custompage (twice) with the slug of your custom page, relative to the phpBB's root path.
Then replace the Custom page title and Custom page link (url) accordingly.

And your services.yml should look like this:

Code: Select all

services:
    acme.demo.listener:
        class: acme\demo\event\listener
        tags:
            - { name: event.listener }
Where acme (vendor) and demo (extension) are replaced accordingly.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Re: Track Users

Post by LuigiMdg » Sun Apr 08, 2018 3:09 pm

I've read your answer:
viewtopic.php?f=71&t=1620685&start=15#p11426415

I followed this procedure, but it did not work ..!

I think users are not shown in the list because it lacks some include function [/ i], could you tell me which one I should include in order to recognize the position based on the page?

Furthermore, I would like to give the same result for several pages ..

PS: I've inserted this in View Online page:

Code: Select all

		case 'fanta_ippica':
			$location = 'Sta giocando a Fanta Ippica';
			$location_url = append_sid("{$phpbb_root_path}fanta_ippica.$phpEx");
		break;
And this in my custom page:

Code: Select all

	define('IN_PHPBB', true); 
	$phpbb_root_path = './'; 
	$phpEx = substr(strrchr(__FILE__, '.'), 1); 
	include($phpbb_root_path . 'common.' . $phpEx); 
	include($phpbb_root_path . 'includes/bbcode.' . $phpEx); 
	include($phpbb_root_path . 'includes/functions_display.' . $phpEx); 

        // Start session management 
	$user->session_begin(); 
	$auth->acl($user->data); 
	$user->setup('viewforum');

User avatar
LuigiMdg
Registered User
Posts: 132
Joined: Sat Jan 10, 2015 9:12 pm
Contact:

Re: Track Users

Post by LuigiMdg » Tue Apr 10, 2018 5:24 pm

I've found a very very simple solution.. I've used the function session_create and added the case to viewonline :D

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 4 guests