extension - viewonline.php?

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

extension - viewonline.php?

Post by wintstar »

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
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5176
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by MattF »

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;
    }
}
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
wintstar
Registered User
Posts: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

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
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5176
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by MattF »

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
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
wintstar
Registered User
Posts: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

@VSE, thank you so much. :)
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5176
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by MattF »

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)
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
wintstar
Registered User
Posts: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

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
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5176
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by MattF »

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. ;)
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
wintstar
Registered User
Posts: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

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 »

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: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

@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: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

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
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5176
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: extension - viewonline.php?

Post by MattF »

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;
    }
} 
Formerly known as VSEMy ExtensionsPlease 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 »

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: 317
Joined: Sat Mar 07, 2009 12:39 pm

Re: extension - viewonline.php?

Post by wintstar »

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”