FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » FUDforum Suggestions » New Hook Request - COMPILER_BEFORE_OUTPUT (If it don't already exist that is ...)
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
New Hook Request - COMPILER_BEFORE_OUTPUT [message #164978] Mon, 11 April 2011 11:11 Go to next message
Dayo is currently offline  Dayo   
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
A hook placed after the forum has been loaded but BEFORE anything, including headers, has been sent, will be useful ... to me at least.

Getting tighter integration will be possible in my plugin could keep full track of requests.

For example, take this flow of events as it stands now...

  1. User requests Page X
  2. Core code determines user is not logged in
  3. User is redirected to login page
  4. Plugin uses COMPILER_FINALIZE_PAGE hook just before display
  5. Plugin send user to CMS login and feeds CMS with return params which in this case has to be front page as it has no way of knowing user actually wanted Page X.
  6. User is redirected to FUDforum Front page after login


Compared to ....

  1. User requests Page X
  2. Core code determines user is not logged in
  3. Plugin uses COMPILER_BEFORE_OUTPUT hook before redirection headers are sent
  4. Plugin sets session var "previous_request" as equal to "current_request" (which may be empty in which case "previous_request" will default to FUDforum front page) and then stores request url in session as "current_request"
  5. User is redirected to login page
  6. Plugin uses COMPILER_BEFORE_OUTPUT hook again
  7. Plugin sets session var "previous_request" as equal to "current_request" (which will not be empty) and then stores request url in session as "current_request"
  8. Plugin uses COMPILER_FINALIZE_PAGE hook just before display
  9. Plugin sends user to CMS login and feeds CMS with return params which in this case will be session var "previous_request".
  10. User is redirected to FUDforum Page X after login


The important thing is that the hook should be fired before anything is sent at all and preferably after GLOBALS.php has been loaded.

[Updated on: Mon, 11 April 2011 11:17]

Report message to a moderator

Re: New Hook Request - COMPILER_BEFORE_OUTPUT [message #164990 is a reply to message #164978] Tue, 12 April 2011 06:03 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
Not sure I understand all of this, but it is quite easy to add a new hook. For example, to add a INITCORE hook, edit core.inc (loaded after GLOBALS.php, but before any templates are called) and add:

if (defined('plugins')) plugin_call_hook('INITCORE');


PS: You can use the existing INITUSER hook to check if the users is authenticated or anonymous.
Re: New Hook Request - COMPILER_BEFORE_OUTPUT [message #164991 is a reply to message #164990] Tue, 12 April 2011 07:42 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Excellent!

Is it possible to commit the "INITCORE" call for 3.0.3?

A call to such a hook will be the only core change I'll be needing.

PS. Note that making "fud_use(db.inc)" conditional in the api file is not required as the function outputs a conditional call to db.inc.

Loving the flexibility.
Re: New Hook Request - COMPILER_BEFORE_OUTPUT [message #164995 is a reply to message #164991] Wed, 13 April 2011 09:34 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
OK. first the bad news. I finally completed the plugin, or so I thought, after slugging through. After activating and trying it however, a big, fat nothing happened.

It turns out that the documentation for the hook I was relying on, COMPILER_FINALIZE_PAGE, is, shall we say, a bit misleading.

It says, in an example of imprecise language, "Modify a page before it's written out" when it should say something like "Modify template html data before it is built as a template file".

Now. I am sure to the person that wrote it, being familiar with the application, the second meaning is obvious ... particularly since the hook has the term "COMPILER" in it but to me, I saw "Modify a page (web output page) before it is sent to the browser".

I found out the true meaning after several hours of head scratching and digging in the code.

<Side Show Begin>
Lord Raglan, at Battle of Balaclava during the Crimean war, sent an order to the 600 men of the Light Brigade to "advance rapidly to the front, follow the enemy, and try to prevent the enemy carrying away the guns". He had just watched the Heavy Brigade charge into Russians and drive them back in another area but the Russians had captured some Turkish artillery pieces and he didn't want them to retreat with those pieces.

The Light Brigade however was positioned in a valley with Russian Guns at the other end. To try to take these was suicide but being unable to read Raglan's mind, decided an order was an order and proceeded to charge the position. Half of the Light Brigade was wiped out simply because Raglan didn't say "... retreating with the guns they captured earlier from the Turks".

Imprecise language kills!
<Side Show End>



Now the good news.

All the code is ready. It just needs a hook that is called after all the output has been put together and just before the output is sent to the browser. Hopefully, this can be achieved.

Some advice on where to add such a hook will be appreciated.

Thanks a mil!

[Updated on: Wed, 13 April 2011 09:37]

Report message to a moderator

Re: New Hook Request - COMPILER_BEFORE_OUTPUT [message #165003 is a reply to message #164995] Thu, 14 April 2011 13:00 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
Sorry, I just haven't had any time to look into this. I'll try to get to it over the weekend of maybe next week.
Re: New Hook Request - COMPILER_BEFORE_OUTPUT [message #165004 is a reply to message #165003] Thu, 14 April 2011 13:09 Go to previous message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
A standard hook wouldn't work for this as the html is in several different files.
I have used a ob_start callback function to introduce one.

I'll send a patch for consideration when done.
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Embed Related Wishlist for 3.0.3
Next Topic: Allow anonymous voting in [some] polls
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Oct 21 02:53:01 EDT 2017

Total time taken to generate the page: 0.00614 seconds