[RFC|Merged] page_header/page_footer override hooks

These requests for events in core phpBB have been merged into 3.1/Ascraeus and will be available with the next release.
Post Reply
User avatar
Erik Frèrejean
Registered User
Posts: 207
Joined: Thu Oct 25, 2007 2:25 pm
Location: surfnet
Contact:

[RFC|Merged] page_header/page_footer override hooks

Post by Erik Frèrejean »

I touched on an event with this behavior here. I'm proposing an event that will allow complete overruling of the phpBB page_header() and page_footer() functions.

I'll take the Support Toolkit as example here, the toolkit doesn't rely on the phpBB page_header() and page_footer() functions but uses its own replacement methods to handle the tasks usually performed by these functions. The problem starts when you want to use a login system and call login_box() (there are some other locations within the phpBB core with this behavior) this function calls page_header preventing the third party application from using the correct "header" function. This behavior can cause unexpected behavior for the third party application as certain logic that will be present in its own header/footer functions won't be executed and on the other side the third party app might or might not initialise all information the phpBB function simply expect to have available causing other problems.
An other solution would be to copy all code from login_box and call a custom version which only calls the applications header/footer but this causes a lot of un-needed code duplication.

Determining whether the phpBB function has to be ignored will be done by passing a variable ($page_header_override, $page_footer_override) into the hook which is defaulted to false. If the event is designed to override the phpBB function it will set this variable to true at which point phpBB will ignore the rest of the function (the same basic idea is applied with the "old" hook system, for example in append_sid)

The parameters that will be passed into the hook will be those that are used to call the regular functions and the skip variable. For the page_header override hook this are:

Code: Select all

$vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override');
and for the page_footer hook:

Code: Select all

$vars = array('run_cron', 'page_footer_override');
Some related discussion on IRC:

Code: Select all

[2012-03-29 06:31:05] <nn-> erik| please specify where in the code you want to have the event
[2012-03-29 06:31:11] <nn-> and what its parameters should be
[2012-03-29 06:31:24] <nn-> all of our parameters are in/out
[2012-03-29 06:31:38] <nn-> to return a flag from listener you have to pass a boolean in as a parameter
[2012-03-29 06:31:41] <nn-> something like $show_header
[2012-03-29 06:31:52] <nn-> then you can change it in the listener
[2012-03-29 06:32:09] <nn-> accordingsy you need to also specify what code will become conditional on that flag
[2012-03-29 06:32:28] <nn-> and what the behavior would be if that code does not run, in the event the flag is changed to false
[2012-03-29 06:33:02] <erik|iOS_> Okay.
[2012-03-29 06:33:30] <erik|iOS_> I'll investigate a bit more on the workings of the event handler
[2012-03-29 06:46:46] |<-- rahulr92 has left freenode (Ping timeout: 252 seconds)
[2012-03-29 06:51:29] <erik|iOS_> nn-: would it be acceptable it the event sets an "skip" argument in the return data and than add an `if (skip) return;` the line after the dispatcher call?
[2012-03-29 06:51:51] |<-- JanSch_ has left freenode (Ping timeout: 260 seconds)
[2012-03-29 06:54:07] <unknownbliss> nn-: Why is the old hooks system still there? It should probably either be removed or added to extensions.
[2012-03-29 06:54:12] <unknownbliss> CC: igorw
[2012-03-29 06:54:51] <nn-> unknownbliss: let's not get carried away
[2012-03-29 06:55:08] <nn-> and one thing at a time
[2012-03-29 06:55:22] <unknownbliss> fair point
[2012-03-29 06:55:42] <unknownbliss> But doing the latter [b]should[/b] just be a few lines of code
[2012-03-29 06:55:49] <nn-> erik| yes probably
[2012-03-29 06:55:57] <nn-> except there is no "return data"
[2012-03-29 06:56:01] <nn-> all parameters are in and out
[2012-03-29 06:56:15] <nn-> unknownbliss: feel free to take a stab at it
[2012-03-29 06:56:19] <nickvergessen> <@erik|iOS_> nn-: would it be acceptable it the event sets an "skip" argument in the return data and than add an `if (skip) return;` the line after the dispatcher call?
[2012-03-29 06:56:26] <nickvergessen> was my first and best idea aswell so far
[2012-03-29 06:57:07] <erik|iOS_> I understand that but if you add an "skip = false" in you could change that to true in the event. Right?
[2012-03-29 06:57:17] <nn-> yes
[2012-03-29 06:57:46] <nickvergessen> we can also add that parameter in the other function?
[2012-03-29 06:57:54] <nickvergessen> so we dont have to edit all places=
[2012-03-29 06:58:22] <erik|iOS_> Okay. I need to get a lot more familliar with the event system :?
[2012-03-29 06:58:36] <unknownbliss> nn-: After I've finished more important stuff
[2012-03-29 06:58:55] <unknownbliss> erik|iOS_: Most of the events stuff you need to know about is symfony
[2012-03-29 06:59:02] <nn-> http://wiki.phpbb.com/Category:Events_and_Listeners
[2012-03-29 06:59:25] <unknownbliss> erik|iOS_: Just a note though, we use a event dispatcher wrapper
[2012-03-29 07:00:04] <unknownbliss> erik|iOS_: Look through https://github.com/phpbb/phpbb3/pull/529
[2012-03-29 07:00:14] <nn-> unknownbliss: https://github.com/phpbb/phpbb3/pull/571 ;)
[2012-03-29 07:00:40] <unknownbliss> hm... Thats got all the events in so the diff is rather large and more difficult to digest
[2012-03-29 07:00:53] <erik|iOS_> Okay. Thanks :)
[2012-03-29 07:01:36] <unknownbliss> oh I just opened the link, I assumed it was the hooks v2 PR.
[2012-03-29 07:02:13] <unknownbliss> I'll have a look at that later on
[2012-03-29 07:02:32] <nn-> erik| but generally speaking your proposal seems sensible
[2012-03-29 07:02:56] |<-- Raimon|iPad has left freenode (Quit: Colloquy for iPhone - http://colloquy.mobi)
[2012-03-29 07:02:57] <nn-> certainly we can take action based on what a listener returns
Available on .com
Support Toolkit developer

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] page_header/page_footer hooks

Post by MichaelC »

Please could you detail a proposal as per viewtopic.php?f=111&t=42685 with this as a note.

I'm sure this is possible and I'll look into it with the symfony events dispatcher.

On a side note if it does not have that functionality the old hooks system from olympus remains and that could be used to do this and then just add extensions functionality to it.
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

igorw
Registered User
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] page_header/page_footer hooks

Post by igorw »

Unknown Bliss wrote:I'm sure this is possible and I'll look into it with the symfony events dispatcher.
Sure would be possible by using `EventDispatcherInterface::hasListeners($eventName)`. But I'm not sure if it's a good idea.

User avatar
Erik Frèrejean
Registered User
Posts: 207
Joined: Thu Oct 25, 2007 2:25 pm
Location: surfnet
Contact:

Re: [RFC] page_header/page_footer override hooks

Post by Erik Frèrejean »

Updated initial post and implemented per the discussion last week. Hopefully I didn't miss anything ;)
https://github.com/unknownbliss/phpbb3/pull/1
Last edited by Erik Frèrejean on Mon Apr 02, 2012 10:40 am, edited 1 time in total.
Reason: Pull request against correct fork/branch
Available on .com
Support Toolkit developer

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC|Merged] page_header/page_footer override hooks

Post by MichaelC »

Implemented (forgot to post that here).
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

leorads
Registered User
Posts: 1
Joined: Tue Mar 24, 2015 5:15 pm

Re: [RFC|Merged] page_header/page_footer override hooks

Post by leorads »

Hello,
Meal Replacement Shakes
I'm still learning phpbb and I was looking for a hook similar to this one.
WoW Gold Tycoon
So I would like to know if this hook is implemented on the last stable version 3.1.3 released on February this year ? Because I can't find the event dispatcher where it's implemented.
Best Phone Grip
Thanks for your time and help

Kind Regards
Leora V. D.
Last edited by leorads on Mon Nov 23, 2015 7:31 pm, edited 1 time in total.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1903
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: [RFC|Merged] page_header/page_footer override hooks

Post by DavidIQ »

https://github.com/michaelcullum/phpbb/ ... befacR4533

https://github.com/michaelcullum/phpbb/ ... befacR4846

Some of the code looks a little different now but it's still the same event names.
Image

Post Reply