Created
December 2, 2009 21:39
-
-
Save phred/247626 to your computer and use it in GitHub Desktop.
Vanilla 2 plugin to maintain Vanilla 1 links after the upgrade.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => '[email protected]', | |
'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