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

Home » FUDforum Development » Converters » Changing old forum URLs in all messages
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Changing old forum URLs in all messages [message #21964] Wed, 05 January 2005 11:20 Go to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Hi,

I've changed the WWWBoard.php converter script to maintain a table to map WWWBoard messages to FUD threads. Now I would like to scan the FUD message base and replace the old URLs with FUD style URLs. Any tips on how go get started?

Best regards.

Frank

Re: Changing old forum URLs in all messages [message #21966 is a reply to message #21964] Wed, 05 January 2005 14:54 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Well, if all in-message urls are the same that a simple str_replace() would do the trick, but you need to be very careful with this. Changing the URL will likely change the length of the message (unless the new url is shorter) in which can you can pad it with harmless characters to ensure the length remains the same.
However, if the length does not remain the same you need to make sure to update the length & offset values inside the msg table.


FUDforum Core Developer
Re: Changing old forum URLs in all messages [message #21972 is a reply to message #21966] Wed, 05 January 2005 16:19 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Hi,

Thank you very much for the reply, but this is a bit too daring for me. At first I thought I can just update the messages in a MySQL table, but they are stored in a file (msg_1). I've also verified that there are no FUDAPI methods for editing/replacing messages. Any other alternatives, or is this the only way to do it?

Best regards.

Frank
Re: Changing old forum URLs in all messages [message #21973 is a reply to message #21972] Wed, 05 January 2005 17:36 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
It only sounds difficult but it really isn't, writing of messages & reading of messages is something fudforum has functions for... So all you need to do is

while (msg in msg_table)
data = read_msg
data = replace(old_url, new_url, data)
write_msg
updat db with new length/offset


FUDforum Core Developer
Re: Changing old forum URLs in all messages [message #22106 is a reply to message #21973] Sat, 15 January 2005 13:27 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
OK, how does this look?

<?php
// Seach all messages for a string and replace with another

$seachfor    = "Frank";
$replacewith = "FRANK";

set_time_limit(-1);
ini_set('memory_limit', '128M');

include("./GLOBALS.php");
include("./fuddata/scripts/fudapi.inc.php");

$c = q("SELECT * FROM ${DBHOST_TBL_PREFIX}msg");
while ($r = db_rowobj($c)) {
  echo "ID=[" . $r->id . "], POSTER=[" . $r->poster_id . "], SUBJECT=[" . $r->subject . "]<br/>\n";

  $fp = fopen($GLOBALS['MSG_STORE_DIR'].'msg_'.$r->file_id, 'rb');
  fseek($fp, $r->foff);
  $body = fread($fp, $r->length);

  if (($p = strpos($body, $seachfor)) !== false) {
    $body = str_replace($seachfor, $replacewith, $body);
    echo "NEW BODY=[" . $body . "]<hr>\n";
    // fud_update_message($r->subject, $body, 0, $r->poster_id, $r->id);
  }
}
?>


Note that the update function is still commented out!

Best regards.

Frank
Re: Changing old forum URLs in all messages [message #22133 is a reply to message #22106] Mon, 17 January 2005 15:07 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
This is not going to work because the message function tries to perform fudcode -> html conversion and encodes any previously found HTML. The message you end up reading from a file already is HTML.

FUDforum Core Developer
Re: Changing old forum URLs in all messages [message #22477 is a reply to message #22133] Fri, 04 February 2005 16:53 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Hi Ilia,

I have to get this right before doing the final FUDforum conversion and would appreciate all the assistance I can get.

Would it help if I use any of the following functions to reverse the HTML formatting first: reverse_fmt, reverse_nl2br, and/or html_to_tags?

Best regards.

Frank
Re: Changing old forum URLs in all messages [message #22479 is a reply to message #22477] Fri, 04 February 2005 17:15 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
You'd need to do:

post_to_smiley()
html_to_tags()
apply_reverse_replace()


In that order.


FUDforum Core Developer
Re: Changing old forum URLs in all messages [message #22503 is a reply to message #22479] Sat, 05 February 2005 03:45 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Yes, it's working now! Thank you so much for your assistance.
Re: Changing old forum URLs in all messages [message #22523 is a reply to message #22503] Sun, 06 February 2005 00:06 Go to previous messageGo to next message
srchild is currently offline  srchild   United Kingdom
Messages: 88
Registered: December 2003
Location: UK
Karma: 1
Member
naudefj wrote on Sat, 05 February 2005 03:45

Yes, it's working now! Thank you so much for your assistance.


Would you like to post your final code for hacking your message base? I might want to do some of that soon Smile





Simon Child
Re: Changing old forum URLs in all messages [message #22528 is a reply to message #22523] Sun, 06 February 2005 12:03 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Final code as requested:

<?php
// Seach all messages for a string and replace with another

$seachfor    = "Frank";
$replacewith = "FRANK";

set_time_limit(-1);
ini_set('memory_limit', '128M');

include("./GLOBALS.php");
include("./FUDdata/scripts/fudapi.inc.php");

fud_use('smiley.inc');
fud_use('rev_fmt.inc');
fud_use('replace.inc');
fud_use('post_proc.inc');

$c = q("SELECT * FROM ${DBHOST_TBL_PREFIX}msg");
while ($r = db_rowobj($c)) {
  echo "ID=[" . $r->id . "], FORUM=[" . $r->thread_id . "], POSTER=[" . $r->poster_id . "], SUBJECT=[" . $r->subject . "]<br/>\n";

  $fp = fopen($GLOBALS['MSG_STORE_DIR'].'msg_'.$r->file_id, 'rb');
  fseek($fp, $r->foff);
  $body = fread($fp, $r->length);

  $body = post_to_smiley($body);
  $body = html_to_tags($body);
  $body = apply_reverse_replace($body);

  if (($p = strpos($body, $seachfor)) !== false) {
    echo "OLD BODY=[" . $body . "]<hr>\n";
    $body = str_replace($seachfor, $replacewith, $body);
    echo "NEW BODY=[" . $body . "]<hr>\n";
    fud_update_message($r->subject, $body, 0, $r->poster_id, $r->id);
  }
}
?>


Best regards.

Frank
Re: Changing old forum URLs in all messages [message #22541 is a reply to message #22528] Sun, 06 February 2005 21:27 Go to previous messageGo to next message
srchild is currently offline  srchild   United Kingdom
Messages: 88
Registered: December 2003
Location: UK
Karma: 1
Member
naudefj wrote on Sun, 06 February 2005 12:03

Final code as requested


Thanks. I'm not going to do this straightaway (too busy!) but I want to use something this to clean all email addresses out of my message base (and I'll also setup the body regex in maillist.php to stop any more getting in there) to lessen the risk of address harvesting from my forum.

But looks like I'll have to do a bit more work on it first, because I would need to match with regex rather than a straight string change, and also I would need to allow for changes in length (and I've not worked out your code yet to see if yours does that).

Cheers




Simon Child
Re: Changing old forum URLs in all messages [message #22587 is a reply to message #22541] Mon, 07 February 2005 18:53 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Hi,

srchild wrote on Sun, 06 February 2005 16:27

and also I would need to allow for changes in length (and I've not worked out your code yet to see if yours does that).


Not necessary - the code calls FUDAPI to do the dirty work for us.

Best regards.

Frank
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Preparing for final conversion: reset the DB
Next Topic: Subscribe users to topics/ forums
Goto Forum:
  

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

Current Time: Tue Jun 18 12:01:19 GMT 2024

Total time taken to generate the page: 0.02562 seconds