Page 1 of 2

extension - viewonline.php?

Posted: Sat Mar 22, 2014 8:47 pm
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()
    {
                 ?
    } 

Re: extension - viewonline.php?

Posted: Sun Mar 23, 2014 3:48 pm
by VSE

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;
    }
}

Re: extension - viewonline.php?

Posted: Sun Mar 23, 2014 3:59 pm
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 }

Re: extension - viewonline.php?

Posted: Sun Mar 23, 2014 6:27 pm
by VSE
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

Re: extension - viewonline.php?

Posted: Sun Mar 23, 2014 6:43 pm
by wintstar
@VSE, thank you so much. :)

Re: extension - viewonline.php?

Posted: Sun Mar 23, 2014 7:02 pm
by VSE
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)

Re: extension - viewonline.php?

Posted: Sun Mar 23, 2014 7:11 pm
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 :)

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 1:34 am
by VSE
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. ;)

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 6:07 am
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':

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 11:06 am
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');
		}
	}

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 11:37 am
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 :?

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 12:03 pm
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 :(

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 3:17 pm
by VSE
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;
    }
} 

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 3:39 pm
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)

Re: extension - viewonline.php?

Posted: Mon Mar 24, 2014 3:58 pm
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 :)