|
Re: Changing old forum URLs in all messages [message #21966 is a reply to message #21964] |
Wed, 05 January 2005 14:54 |
Ilia
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 #21973 is a reply to message #21972] |
Wed, 05 January 2005 17:36 |
Ilia
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 |
|
naudefj
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 |
Ilia
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 #22528 is a reply to message #22523] |
Sun, 06 February 2005 12:03 |
|
naudefj
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 |
srchild
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
|
|
|
|