Skip to content

Instantly share code, notes, and snippets.

@phred
Created December 2, 2009 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phred/247626 to your computer and use it in GitHub Desktop.
Save phred/247626 to your computer and use it in GitHub Desktop.
Vanilla 2 plugin to maintain Vanilla 1 links after the upgrade.
<?php if (!defined('APPLICATION')) exit();
/*
Copyright 2008, 2009 FoxyCart, LLC
This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this file. If not, see <http://www.gnu.org/licenses/>.
Contact Fred Alger at fred [dot] alger [at] foxycart [dot] com
*/
// Define the plugin:
$PluginInfo['MaintainVanilla1Links'] = array(
'Name' => 'Maintain Vanilla 1 Links',
'Description' => "Permanent redirects for old Vanilla 1 URLs",
'Version' => '1',
'Author' => "FoxyCart, LLC",
'AuthorEmail' => 'fred.alger@foxycart.com',
'AuthorUrl' => 'http://www.foxycart.com',
'RegisterPermissions' => FALSE,
'SettingsPermission' => FALSE
);
// Add this row to config.php:
// $Configuration['Routes']['comments.php'] = 'vanilla/discussion/oldcommentlink/';
class MaintainVanilla1LinksPlugin implements Gdn_IPlugin {
public function DiscussionController_OldCommentLink_Create(&$Sender) {
// $Sender doesn't have anything that lets me fetch the raw query string, so back to plain ol' PHP superglobals
$DiscussionID = $_REQUEST['DiscussionID'];
$page = $_REQUEST['page'];
$DiscussionSearch = $Sender->DiscussionModel->GetWhere(array('ImportID' => $DiscussionID));
if ($DiscussionSearch->NumRows() > 0) {
$Discussion = $DiscussionSearch->FirstRow();
header('HTTP/1.1 301 Moved Permanently');
Redirect('/discussion/'.$Discussion->DiscussionID.'/'.Format::Url($Discussion->Name));
}
else {
Redirect($Sender->Routes['Default404']);
}
}
public function Setup() {
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment