Firefox PHP

Module: Facebook URL Fixer

Posted by Phil Connolly 
All files from this thread

File Name File Size   Posted by Date  
facebook_url_fixer.php 769 bytes open | download Phil Connolly 08/03/2011 Read message
Module: Facebook URL Fixer
November 22, 2010 06:10PM
Facebook has a silly bug which messes up Phorum URLs. In a nutshell, Facebook has to encode URLs submitted to their Graph, but when it comes time to decode that URL back into its working form, they forget to decode commas, leaving %2C in places that Phorum expects to see commas. Here is some chatter about this: [www.phorum.org]

Probably Facebook will fix their bug. In the meantime, why wait? Here is a simple module that works around it, based on Maurice's idea in the above thread, and the very fortunate foresight of the Phorum team to place a parse_request hook just before query strings are parsed.

Enjoy,

-phil.

Change log:
August 3, 2011 - skip decoding when Phorum's redirect.php is the executing script



Edited 1 time(s). Last edit at 08/03/2011 08:20PM by Phil Connolly.
Attachments:
open | download - facebook_url_fixer.php (769 bytes)
Re: Module: Facebook URL Fixer
August 03, 2011 05:10AM
I just wanna report an issue.

In our General Forum Settings, we can specify whether after submitting a post, the user is redirected to the list page or the newly posted message itself on the read page. I personally have selected the latter, so users see their post after submitting it.

When this module is activated, new topic will redirect to the message as it should, but all replies to topics get redirected to the list page. In other words, the setting to redirect to the read page instead of the list page seems to be ignore when replying to posts and having this module activated.


Robert Angle
Phorum lover, nothing more.
Ruminations
Re: Module: Facebook URL Fixer
August 03, 2011 07:26AM
Wierd... so I traced through Phorum code, and also hooked up fiddler and watched what was happening between my browser and the server.

When redirect_after_post = 'read', I can see Phorum is trying to do what you want, jump to the last message of the thread, and its full URL contains an anchor (#). Phorum has some twiddling it does in the case it must redirect to an anchor from a POSTed page (such as replying to a post), mainly to overcome an Internet Explorer bug which strips the anchor, and in this case Phorum wraps the redirect in a special case script (no surprise, it is named redirect.php) which sends the browser to the correct URL, including the anchor. The destination URL is first encoded by Phorum and then decoded by redirect.php, but my little module didn't know all that so goes ahead and decodes the URL itself, thereby messing up redirect.php, and leaving Phorum with a bogus URL which it defaults to the forum list page.

I wrote that summary not expecting you would care one way or the other of the technical issue, may be you do, but mainly so any Phorum experts can provide a tip to workaround this. My initial thought is to just test if redirect.php is the page being accessed and if so skip the facebook-fixing decoding. That would be easy, but maybe there are other cases similar to this I should be aware of?

I'll make a change based on what I know tomorrow.

-phil.
Re: Module: Facebook URL Fixer
August 03, 2011 08:24PM
Update release today: fixed the problem where the module was decoding URLs that are wrapped by Phorum's redirect.php script. Thanks to Robert Angle for discovering this one.
Re: Module: Facebook URL Fixer
December 22, 2011 09:52PM
Thanks Phil. This bug has been open on Facebook for over a year now, so I'm not holding my breath....

[bugs.developers.facebook.net]

___
Skye Nott
Corvus Digital
Re: Module: Facebook URL Fixer
February 09, 2012 01:52AM
Just a quick note. Hotmail has the same problem, except (guess what) it uses lowercase %2c instead of %2C like Facebook does.
Anyway, easy to patch your code to handle that too, just add a replacement and chage strpos to stripos

Language: PHP
if(strtolower($self[count($self)-1]) !== ';redirect.php'; && stripos($_SERVER[';QUERY_STRING';], ';%2C';) !== false) { // Override the query string. global $PHORUM_CUSTOM_QUERY_STRING; $PHORUM_CUSTOM_QUERY_STRING = str_replace(';%2C';,';,';,$_SERVER[';QUERY_STRING';]); # Facebook $PHORUM_CUSTOM_QUERY_STRING = str_replace(';%2c';,';,';,$_SERVER[';QUERY_STRING';]); # Hotmail $PHORUM_CUSTOM_QUERY_STRING = str_replace(';%3D';,';=';,$PHORUM_CUSTOM_QUERY_STRING); }

___
Skye Nott
Corvus Digital
Re: Module: Facebook URL Fixer
March 31, 2012 09:40PM
Whoops, the code above has a bug (overwrites PHORUM_CUSTOM_QUERY_STRING in the 2c case).
Should just use the case insensitive versions like so:

Language: PHP
if(strtolower($self[count($self)-1]) !== ';redirect.php'; && stripos($_SERVER[';QUERY_STRING';], ';%2C';) !== false) { // Override the query string. global $PHORUM_CUSTOM_QUERY_STRING; $PHORUM_CUSTOM_QUERY_STRING = str_ireplace(';%2C';,';,';,$_SERVER[';QUERY_STRING';]); # Facebook cap, Hotmail lower $PHORUM_CUSTOM_QUERY_STRING = str_ireplace(';%3D';,';=';,$PHORUM_CUSTOM_QUERY_STRING); }

___
Skye Nott
Corvus Digital



Edited 2 time(s). Last edit at 03/31/2012 09:51PM by Skye Nott.
Sorry, only registered users may post in this forum.

Click here to login