Advertisement:

Author Topic: Converting links embedded into posts  (Read 5955 times)

Offline Raptus

  • Semi-Newbie
  • *
  • Posts: 20
Converting links embedded into posts
« on: October 09, 2005, 10:26:22 AM »
Hello, I succesfully converted a phpBB Forum into SMF 1.0.5, and because of the different URL scheme this makes all links embedded into posts linking between different topics broken. I have partially fixed it now, needing help on a last issue.

I changed to a new domain, too, so I first ran the following SQL query to convert all links to the new domain:

Code: [Select]
UPDATE smf_messages SET body = REPLACE(body, 'www.olddomain.com/forum', 'forum.newdomain.com');
phpBB uses a URL scheme like viewtopic.php?=topicid while SMFs is like index.php?topic=topicid, so I used:

Code: [Select]
UPDATE smf_messages SET body = REPLACE(body, 'forum.newdomain.com/viewtopic.php?t=', 'forum.newdomain.com/index.php?topic=');
Additionally I left a php script at the original location which redirects the browser to the new domain and correct topic in case someone follows an external, outdated link.

The remaining problem is that in phpBB you can have links pointing to specific posts only, (viewtopic.php?p=2345), but SMF requires the link to contain topicid + postid (index.php?topic=123.msg2345#msg2345), so I cannot convert them with a (simple) query/script. A conversion script would need to do a DB lookup to check to which topicid a certain postid belongs to and add the missing ?topic=topicid to the URL string.

Any suggestions?
Thanx in advance.

Offline Oldiesmann

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,925
  • Gender: Male
  • Ask me about the function DB :)
    • oldiesmann on Facebook
    • Oldiesmann on GitHub
    • https://www.linkedin.com/in/michaeleshom on LinkedIn
    • @oldiesmann on Twitter
    • Archie Comics Fan Forum
Re: Converting links embedded into posts
« Reply #1 on: October 11, 2005, 01:35:47 PM »
Well, your best bet for now would be to do the following:

1. Run this query in phpMyAdmin:

Code: [Select]
UPDATE smf_messages SET body = REPLACE(body, 'www.olddomain.com/viewtopic.php?p=', 'forum.newdomain.com/viewtopic.php?p=');
Then, put this in a file, save it as viewtopic.php and upload it to your SMF directory:

Code: [Select]
<?php
include_once(&#39;SSI.php&#39;);
if(isset($_REQUEST[&#39;p&#39;]))
{
    
$query db_query("SELECT ID_TOPIC FROM {$db_prefix}messages WHERE ID_MSG = &#39;$_REQUEST[p]&#39;"__FILE____LINE__);
    
$topic mysql_result($query0);
    
header(&#39;Location: http://forum.newdomain.com/index.php?topic=&#39; . $topic . &#39;.msg&#39; . $_REQUEST[&#39;p&#39;] . &#39;#msg&#39; . $_REQUEST[&#39;p&#39;]);
}
?>

That's about the easiest way to do it.
Michael Eshom
Cincy Space - now open!

Offline Raptus

  • Semi-Newbie
  • *
  • Posts: 20
Re: Converting links embedded into posts
« Reply #2 on: October 11, 2005, 03:27:47 PM »
Hey, thanks a lot, worked like a charm  :)

Offline HWB

  • Semi-Newbie
  • *
  • Posts: 55
Re: Converting links embedded into posts
« Reply #3 on: November 19, 2005, 11:43:01 PM »
I have also tried that code and being that my databases prefix is now phpbb2 it did not work.

Offline Oldiesmann

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,925
  • Gender: Male
  • Ask me about the function DB :)
    • oldiesmann on Facebook
    • Oldiesmann on GitHub
    • https://www.linkedin.com/in/michaeleshom on LinkedIn
    • @oldiesmann on Twitter
    • Archie Comics Fan Forum
Re: Converting links embedded into posts
« Reply #4 on: November 24, 2005, 11:52:31 AM »
So change the database prefix to phpbb2_ in that first query...
Michael Eshom
Cincy Space - now open!

Offline KB

  • Semi-Newbie
  • *
  • Posts: 62
Re: Converting links embedded into posts
« Reply #5 on: April 01, 2006, 11:25:32 PM »
Hey Oldiesman....this is probably one of those stupid questions but....

Would the above query and php file method work for links to internal boards (links contained in older posts of course) or would you have to run separate queries/files for links like "?board=" or "?action=" ???

Or is it possible to begin with?

Im in the process of changing to bluehost and my "old" domain will have to be an "add on" domain to the one Ive just registered with them as primary....thus my file structure is now messed up and Ive got broken links all over the place!!

Thanks!

Offline ormuz

  • Full Member
  • ***
  • Posts: 689
Re: Converting links embedded into posts
« Reply #6 on: April 13, 2008, 03:49:18 PM »
Is this solution still working?

Well, your best bet for now would be to do the following:

1. Run this query in phpMyAdmin:

Code: [Select]
UPDATE smf_messages SET body = REPLACE(body, 'www.olddomain.com/viewtopic.php?p=', 'forum.newdomain.com/viewtopic.php?p=');
Then, put this in a file, save it as viewtopic.php and upload it to your SMF directory:

Code: [Select]
<?php
include_once('SSI.php');
if(isset(
$_REQUEST['p']))
{
    
$query db_query("SELECT ID_TOPIC FROM {$db_prefix}messages WHERE ID_MSG = '$_REQUEST[p]'"__FILE____LINE__);
    
$topic mysql_result($query0);
    
header('Location: http://forum.newdomain.com/index.php?topic=' $topic '.msg' $_REQUEST['p'] . '#msg' $_REQUEST['p']);
}
?>

That's about the easiest way to do it.

Offline Raptus

  • Semi-Newbie
  • *
  • Posts: 20
Re: Converting links embedded into posts
« Reply #7 on: April 13, 2008, 04:16:31 PM »
Yes.