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

Re: extension - viewonline.php?

Post by wintstar » Mon Mar 24, 2014 4:04 pm

nickvergessen wrote: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) 
Thus, it is updated faster

Code: Select all

    public function add_page_viewonline($event)
    {
        global $user, $phpbb_container, $phpEx;
        
        if (strrpos($event['row']['session_page'], 'app.' . $phpEx . '/foo') === 0)

        switch ($event['on_page'][1])
        {
            case 'app':
                {
                    $event['location'] = $user->lang('VIEWING_FOO');
                    $event['location_url'] = $phpbb_container->get('controller.helper')->route('foo_main_controller');
                }
            break;
        }
    }  
Also thank you @nickvergessen :)

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4882
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 6:25 pm

I only used strrpos to get away from having to use $phpEx.

But if it must be there, then your original is fine, and more exact:

Code: Select all

if ($event['row']['session_page'] === 'app.' . $phpEx . '/foo')
strrpos would be good if you want a catch-all to display the same name/link for any of your possible controller pages (like paginated pages)

like
/foo
/foo/1
/foo/settings
/foo/user

whatever... but you all wanted them to say the viewer is on the same page name, i.e.: "foo"
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4882
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 6:39 pm

Strike the above... if there are URL params, things break!

The best option is what nickvergessen said:

Code: Select all

global $phpEx;
if (strrpos($event['row']['session_page'], 'app.' . $phpEx . '/foo') === 0) 
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

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

Re: extension - viewonline.php?

Post by VSE » Tue Mar 25, 2014 6:16 am

This can be simplified even further, by the way! No need for the switch/case statements:

Code: Select all

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

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

Post Reply

Return to “Extension Writers Discussion”