forked from vanilla/vanilla
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathshowthread.php
64 lines (58 loc) · 1.59 KB
/
showthread.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Handles 301 redirecting urls from forums that were imported from phpBB or
* vBulletin into their Vanilla equivalent pages.
*/
$redirects = array(
'post' => 'discussion/comment/%1$d#Comment_%1$d',
'thread' => 'discussion/%d/redirect/%s',
'category' => 'categories/%d',
'user' => 'dashboard/profile/%d/x'
);
$type = null;
$index = 0;
if (array_key_exists('p', $_GET) && $index = $_GET['p']) {
$type = 'post';
} elseif (array_key_exists('t', $_GET) && $index = $_GET['t']) {
$type = 'thread';
} elseif (array_key_exists('f', $_GET) && $index = $_GET['f']) {
$type = 'category';
} elseif (array_key_exists('u', $_GET) && $index = $_GET['u']) {
$type = 'user';
}
switch ($type) {
case 'user':
case 'category':
case 'post':
$redirect = sprintf($redirects[$type], $index);
break;
case 'thread':
$hasPage = array_key_exists('page', $_GET);
$pageNumber = 1;
if ($hasPage) {
$oldPageNumber = $_GET['page'];
$comments = 25 * $oldPageNumber;
$pageNumber = ceil($comments / 40);
}
$pageKey = "p{$pageNumber}";
$redirect = sprintf($redirects[$type], $index, $pageKey);
break;
default:
$type = 'home';
$redirect = '/';
break;
}
if (!is_null($type)) {
header("Location: {$redirect}", true, 301);
exit();
}
header("Location: index.php", true, 301);
exit();
//$t = $_GET['t'];
//$p = $_GET['p'];
//
//if ($p) {
// header("Location: discussion/comment/$p", TRUE, 301);
//} else {
// header("Location: discussion/$t/x", TRUE, 301);
//}