Firefox PHP

Phorum 3->5 link parser: Advice requested

Posted by sheik 
Phorum 3->5 link parser: Advice requested
January 28, 2005 06:38AM
My first mods to the Phorum 5 codebase will probably be to implement a parser that recognises an old Phorum 3 link and redirects to the correct Phorum 5 link.
In other words, Phorum 3 sites which have a large number of links to posts which they do not want to lose, will be able to use this mod to restore them.

I have checked out the serialised "offset" data that the Phorum3->5 upgrader creates and it should be fairly easy to hack the code to do what I want.

It would be nicer to write it as a module though.

However, I don't know if a module could hook at a low enough level to do a true HTTP Code 301 (moved permanently) header?
I know I could write something which just displays a page with a meta-refresh to the correct URL, but this wouldn't be as slick (or search engine friendly) as a proper HTTP header.
To output such a header, I need to do it before any other output from Phorum - is there a hook that will let me do this?

Thanks,

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Phorum 3->5 link parser: Advice requested
January 28, 2005 06:49AM
just do it in the common-hook ... which is loaded in common.php which should be loaded first at every page.


Thomas Seifert
Re: Phorum 3->5 link parser: Advice requested
January 28, 2005 06:53AM
Thanks Thomas,
I didn't know if any output was sent by the time the common hook was reached.
Like I say, it will take me time to learn the Phorum 5 way of doing things :-)

/\

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
pat
Re: Phorum 3->5 link parser: Advice requested
January 28, 2005 10:52AM
Hi Sheik,

I am highly interested in such a script, too. But unable to write it - maybe you could share the script, once your done...

thanx
pat
Re: Phorum 3->5 link parser working!
January 28, 2005 05:07PM
OK, I have good news and bad news.

The good news is that I have my old links working again! I've tested about 15 URLs so far and they seem fine (not a comprehensive test yet I know).
eg:
[www.cantonese.sheik.co.uk]

The bad news is that I started out learning how to write a module, and got as far as saving settings in the admin and coding my "hook".
Unfortunately though, by the time common.php is parsed the URL is already rewritten. As the common hook only kicks in after common.php has been parsed, my module therefore doesn't work :(.

Now please bear in mind that I hadn't looked at the Phorum 5 code before yesterday, so if I am glaringly wrong about this please have patience.
The problem as far as I can tell is that by the time the common hook is called, $_SERVER["QUERY_STRING"] doesn't contain the old "f=x,i=y=t=z" style URL.

To be honest, once I realised this I didn't investigate too much, I just moved my code directly into common.php and got it working.

It would be nice to share this as my first module but if that isn't easily possible I will just post my hack directly.

I haven't written the code to parse forum links or profile links yet, but if people need them then I could do.

Many, many thanks to whichever developer decided to write those beautiful offset values in during the upgrade process! :D

I should also say that the Phorum 5 source code is written really clearly. It was ludicrously easy to extract the offsets within common.php.

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz




Edited 1 time(s). Last edit at 01/28/2005 05:07PM by sheik.
Re: Phorum 3->5 link parser working!
January 28, 2005 07:19PM
maybe I'm wrong, need to try it out, but it seems to me like the query_string isn't changed in common.php at all, so it should contain the full url.
will check it out tomorrow.


Thomas Seifert
Re: Phorum 3->5 link parser: Advice requested
January 30, 2005 01:53PM
sheik, did you try to just output $_SERVER in your module? was the QUERY_STRING changed there already?


Thomas Seifert
Re: Phorum 3->5 link parser working!
January 30, 2005 01:57PM
Thomas,
If it any help, the code I've added to common.php is at approx line 117, directly after the database functions are opened up:

phorum_db_load_settings();

...at this point, the original URL is still intact and my code can work without problems.

So, worst case, perhaps a new hook to hook in just after this point could be created?

By the way, my code uses an HTTP 301 "Moved Permanently" redirect so Google should reindex all the old links to point at their new location.
To the person in another thread that was worried about the new "Page Number" format of Phorum 5 - it doesn't seem to matter, provided you link to the correct message ID Phorum 5 will go to the correct page within a thread.

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Phorum 3->5 link parser working!
January 30, 2005 02:00PM
No, I was talking about your module ... as I told, I see no change to QUERY_STRING so I doubt a new hook is really needed. will check that.


Thomas Seifert
Re: Phorum 3->5 link parser: Advice requested
January 30, 2005 02:02PM
Thomas,
I was trying to access the original GET arguments in the URL via $_SERVER["QUERY_STRING"].
By the time my module was called (using the common hook) this had been changed to just "0" I think (it had been changed anyway).
I know this because I was appending $_SERVER["QUERY_STRING"] to one of the language files as a quick way of getting debugging output.

There is a fair amount of URL parsing in common.php, to check against invalid parameters - I suspect the problem is located there.

By the way, if you remember, please call me Adam :)

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Phorum 3->5 link parser working!
January 30, 2005 02:05PM
Here is a code snippet:

function mod_phorum3links_common()
{
GLOBAL $PHORUM;
GLOBAL $_SERVER;
$querystring = $_SERVER["QUERY_STRING"];
$msg = " <small>(Query string=$querystring)</small>";
$PHORUM["DATA"]["LANG"]["ForumList"] .= $msg;
}

...this was the code I used to discover that my query string had been overwritten.

Regards,

/\

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Phorum 3->5 link parser working!
January 30, 2005 02:23PM
I just put
print_var($_SERVER);
right before the hook is called.
then I opened up:
[<myhost>]
and got in the output ...
[QUERY_STRING] => f=1&i=4&t=43

So, the query string is fine.

> GLOBAL $_SERVER;

is not needed. $_SERVER is a superglobal already ... maybe that messes up your query-string?

I'd check out $_GET for f, i and t variables and decide on their values what to do. phorum5-urls don't contain them as variables if I didn't miss something.


Thomas Seifert
Re: Phorum 3->5 link parser working!
January 30, 2005 02:51PM
I'm not sure what is going wrong with mine Thomas, as it still gave me a value of "0" even when I commented out the incorrect "global" declaration.

However, as per your suggestion I have changed my module just to hit the $_GET array directly and it now works.

The files may be grabbed at:
[celerity.co.uk]

I will post the info to the Modules forum.

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Sorry, only registered users may post in this forum.

Click here to login