Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Redirect phpBB urls to Vanilla after import (script)

edited September 2008 in Vanilla 1.0 Help
Hey all,

I'm in the midst of my first Vanilla installation, an upgrade of a four-year-old phpBB forum. I used the phpBB migrator v0.5eB with Vanilla 1.1.2 and was golden... until I realized that all my old links would be broken. And Google wouldn't take kindly to that.

So I wrote a script to fix my problem. Not sure just how "hacky" it is, but it works for me! More notes in the file header.

The following code should be pasted into a file called phpbbredirect.php in the Vanilla root directory:

<?php /* Description: Redirects urls from phpBB to their Vanilla counterparts. The script assumes you have migrated your phpBB database with a migrator that leaves the "legacy" phpBB IDs in the Vanilla database. It also requires that you redirect your old traffic to this file. The following two .htaccess lines should do the trick: RewriteRule ^viewforum.php /phpbbredirect.php [NC,QSA,L] RewriteRule ^viewtopic.php /phpbbredirect.php [NC,QSA,L] This script is known to handle mod_rewrite url-writing as well as having the Vanilla forum live in a subdirectory. On errors it should fail nicely. I'm sure this could be done more elegantly as an add-on, but this works for me so I'm calling this project "done." :-) Please feel free to improve on this code; I hereby release it into the public domain. Cheers, Luke */ include("appg/settings.php"); $Configuration['SELF_URL'] = 'redirect.php'; include("appg/init_ajax.php"); include($Configuration['LIBRARY_PATH'].'Vanilla/Vanilla.Functions.php'); $PhpBBForumID = ForceIncomingInt('f', 0); $PhpBBTopicID = ForceIncomingInt('t', 0); $PhpBBPostID = ForceIncomingInt('p', 0); $PhpBBUserID = ForceIncomingInt('u', 0); if ($PhpBBForumID > 0) { $s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); $s->SetMainTable('Category', ''); $s->AddSelect(array('phpBBforumid', 'CategoryID'), ''); $s->AddWhere('', 'phpBBforumid', '', $PhpBBForumID, '='); $ResultSet = $Context->Database->Select($s, 'PhpBBRedirector', 'SpaghettiCode', 'Error looking up CategoryID.'); $Row = $Context->Database->GetRow($ResultSet); $CategoryID = $Row['CategoryID']; if (!($CategoryID > 0)) { header("location: ".GetUrl($Configuration, "index.php")); die(); } header("location: ".GetUrl($Context->Configuration, 'index.php', '', 'CategoryID', $CategoryID)); die(); } if (($PhpBBTopicID > 0) || ($PhpBBPostID > 0)) { $s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); if ($PhpBBTopicID > 0) { $s->SetMainTable('Discussion', ''); $s->AddSelect(array('phpBBtopicid', 'DiscussionID'), ''); $s->AddWhere('', 'phpBBtopicid', '', $PhpBBTopicID, '='); } else { $s->SetMainTable('Comment', ''); $s->AddSelect(array('phpBBpostid', 'DiscussionID'), ''); $s->AddWhere('', 'phpBBpostid', '', $PhpBBPostID, '='); } $ResultSet = $Context->Database->Select($s, 'PhpBBRedirector', 'SpaghettiCode', 'Error looking up DiscussionID.'); $Row = $Context->Database->GetRow($ResultSet); $DiscussionID = $Row['DiscussionID']; if (!($DiscussionID > 0)) { header("location: ".GetUrl($Configuration, "index.php")); die(); } $DiscussionManager = $Context->ObjectFactory->NewContextObject($Context, 'DiscussionManager'); $Discussion = $DiscussionManager->GetDiscussionById($DiscussionID); header("location: ".GetUnreadQuerystring($Discussion, $Configuration)); die(); } /* * Theoretically, one could catch phpBB's "profile.php?mode=viewprofile&u=__" * links and redirect those too, using much the same idea. But I'll leave * that as an exercise to the reader. :-) */ // if ($PhpBBUserID > 0) { // } // If all else fails... header("location: ".GetUrl($Configuration, "index.php")); die(); ?>

Comments

This discussion has been closed.