extension - viewonline.php?

Discussion forum for Extension Writers regarding Extension Development.
User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

extension - viewonline.php?

Post by wintstar » Sat Mar 22, 2014 8:47 pm

In 3.0.12 you could insert an extra page with

Code: Select all

		case 'foo':
			$location = $user->lang['FOO'];
			$location_url = append_sid("{$phpbb_root_path}foo.$phpEx");
		break;
How to do this in 3.1.0?

Code: Select all

core.viewonline_overwrite_location

	static public function getSubscribedEvents()
	{
		return array(
			'core.viewonline_overwrite_location'						=> 'add_page_viewonline',      
		);
	}

    public function add_page_viewonline()
    {
                 ?
    } 

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4883
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by VSE » Sun Mar 23, 2014 3:48 pm

Code: Select all

public function add_page_viewonline($event)
{
    global $user, $phpbb_root_path, $phpEx;

    switch ($event['on_page'][1])
    {
        case 'foo':
            $event['location'] = $user->lang['FOO'];
            $event['location_url'] = append_sid("{$phpbb_root_path}foo.$phpEx");
        break;
    }
}
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Sun Mar 23, 2014 3:59 pm

Thank you. How, then would look like the routing.yml. ?['on_page'][1])?

Code: Select all

foo_main_controller:
    pattern: /foo
    defaults: { _controller: demo.foo.controller:display }

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4883
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by VSE » Sun Mar 23, 2014 6:27 pm

Actually, do this:

routing.yml:

Code: Select all

foo_main_controller:
    pattern: /foo
    defaults: { _controller: demo.foo.controller:display }
your event function:

Code: Select all

public function add_page_viewonline($event)
{
    global $user, $phpbb_container;

    switch ($event['on_page'][1])
    {
        case 'app':
            $event['location'] = $user->lang('FOO');
            $event['location_url'] = $phpbb_container->get('controller.helper')->route('foo_main_controller');
        break;
    }
}
EDIT: I updated the example to actually work
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Sun Mar 23, 2014 6:43 pm

@VSE, thank you so much. :)

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4883
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by VSE » Sun Mar 23, 2014 7:02 pm

Actually this is a little buggy though. Other extensions doing the same thing can overwrite yours. We'll have to find out what is best to use in the case argument. 'app' or something else? Will probably require development changes to support extensions (multiple extensions that is)
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Sun Mar 23, 2014 7:11 pm

Yes, I have also noticed. That's why I could not solve it. It's still in development. So far I am very pleased with the extension system. You are all doing a good job. Keep it up. :)


EDIT: @VSE, It works :)

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4883
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by VSE » Mon Mar 24, 2014 1:34 am

posted a bug ticket: http://tracker.phpbb.com/browse/PHPBB3-12299

Extensions with front controllers should be able to add themselves to the who is online viewing page. ;)
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Mon Mar 24, 2014 6:07 am

Right. With several extensions always only one displayed in the online user listings.

EDIT:

case 'app': should be connected to the controller of the Extensions. Database of phpbb_ext should ext_name from the extension are read. It would then be assigned to only one extension.
case 'demo/foo':

User avatar
nickvergessen
Former Team Member
Posts: 4397
Joined: Mon Apr 30, 2007 5:33 pm
Location: Stuttgart, Germany
Name: Joas Schilling
Contact:

Re: extension - viewonline.php?

Post by nickvergessen » Mon Mar 24, 2014 11:06 am

You should use something like:

Code: Select all

	if ($event['on_page'][1] == 'app')
	{
		if ($event['row']['session_page'] === 'app.' . $this->php_ext . '/news')
		{
			$event['location_url'] = $this->helper->route('newspage_base');
			$event['location'] = $this->user->lang('VIEWONLINE_NEWS');
		}
	}
No Support via PM

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Mon Mar 24, 2014 11:37 am

@nickvergessen, do you mean

Code: Select all

    public function add_page_viewonline($event)
    {      
       if ($event['on_page'][1] == 'app')
       {
          if ($event['row']['session_page'] === 'app.' . $this->php_ext . '/foo')
          {
             $event['location_url'] = $this->helper->route('foo_main');
             $event['location'] = $this->user->lang('VIEWING_FOO');
          }
       }
    } 
thats not works :?

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Mon Mar 24, 2014 12:03 pm

VSE wrote:posted a bug ticket: http://tracker.phpbb.com/browse/PHPBB3-12299

Extensions with front controllers should be able to add themselves to the who is online viewing page. ;)
nickvergessen has closed the ticket :(

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4883
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by VSE » Mon Mar 24, 2014 3:17 pm

This is what works

Code: Select all

public function add_page_viewonline($event)
{
    global $user, $phpbb_container;

    switch ($event['on_page'][1])
    {
        case 'app':
            if (strrpos($event['row']['session_page'], '/foo'))
            {
                $event['location'] = $user->lang('FOO');
                $event['location_url'] = $phpbb_container->get('controller.helper')->route('foo_main_controller');
            }
        break;
    }
} 
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
nickvergessen
Former Team Member
Posts: 4397
Joined: Mon Apr 30, 2007 5:33 pm
Location: Stuttgart, Germany
Name: Joas Schilling
Contact:

Re: extension - viewonline.php?

Post by nickvergessen » Mon Mar 24, 2014 3:39 pm

strrpos() is dangerous. If the gallery has gallery/news it would be overwritten by the newspage:
You should add app.php and check for "is at the beginning":

Code: Select all

global $phpEx;
if (strrpos($event['row']['session_page'], 'app.' . $phpEx . '/foo') === 0)
No Support via PM

User avatar
wintstar
Registered User
Posts: 280
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar » Mon Mar 24, 2014 3:58 pm

Yes it works. When a guest when he changes sides but it takes some time until it is the correct page display. I have tested it with my extensions Dashboard and Imprint. 3 times I've had to reload the page until it was displayed correctly.

Many thanks! VSE :)

Post Reply

Return to “Extension Writers Discussion”