|
Re: Changing old forum URLs in all messages [message #21966 is a reply to message #21964] |
Wed, 05 January 2005 09:54   |
Ilia
 Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
remove from buddy list ignore all messages by this user
|
|
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 #22106 is a reply to message #21973] |
Sat, 15 January 2005 08:27   |
 |
naudefj
 Messages: 3771 Registered: December 2004
Karma: 27
|
Senior Member Administrator Core Developer |
add to buddy list ignore all messages by this user
|
|
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 #22528 is a reply to message #22523] |
Sun, 06 February 2005 07:03   |
 |
naudefj
 Messages: 3771 Registered: December 2004
Karma: 27
|
Senior Member Administrator Core Developer |
add to buddy list ignore all messages by this user
|
|
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 16:27   |
srchild
 Messages: 88 Registered: December 2003 Location: UK
Karma: 1
|
Member |
add to buddy list ignore all messages by this user
|
|
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
|
|
|
|