-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate_redirection_data.php
61 lines (49 loc) · 1.71 KB
/
generate_redirection_data.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
<?php
// This file generates redirection data for shim implementations of
// viewforum.php and viewtopic.php.
require_once('config.php');
require_once('common.php');
log_info("Generating redirection data:\n");
$target_dir = trim($target_dir, '/');
mkdir_p($target_dir, 0755);
if (!file_exists("./forum-data.json")) {
error_log("ERROR: forum data not available. Run this command first:");
error_log(" php extract");
exit(1);
}
function array_dump($a) {
$output = 'array(';
foreach ($a as $key => $value) {
$output .= "'" . $key . "' => array('" . $value[0] . "', '" . $value[1] . "'),\n";
}
$output .= ")\n";
return $output;
}
log_info("Loading forum-data.json...");
$extracted = json_decode(file_get_contents("./forum-data.json"), true);
log_info("done.\n");
$by_post_id = array();
$by_topic_id = array();
// Forum and topic by post ID
foreach ($extracted['topics'] as $tid => $topic) {
$fid = $topic['fid'];
foreach ($topic['posts'] as $post) {
$by_post_id[(string)$post['post_id']] = array($fid, (string)$tid);
}
$by_topic_id[(string)$tid] = array($fid, (string)$tid);
}
$output = "<?php\n";
$output .= '$archive_base_url = "' . $archive_base_url . '";' . "\n";
$output .= '$by_post_id = ' . array_dump($by_post_id) . ";\n";
$output .= '$by_topic_id = ' . array_dump($by_topic_id) . ";\n";
$output .= "?>\n";
log_info("Writing $target_dir/redirection-data.php...");
$f = fopen($target_dir . '/redirection-data.php', 'w');
fputs($f, $output);
fclose($f);
log_info("done\n");
log_info("Copying viewforum.php and viewtopic.php to $target_dir...");
copy("./templates/viewforum.php", $target_dir . "/viewforum.php");
copy("./templates/viewtopic.php", $target_dir . "/viewtopic.php");
log_info("done\n\n");
?>