-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.php
148 lines (132 loc) · 3.48 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
$catlist = array(
"mame" => "MAME",
);
function getpostnumber($post)
{
$extract = explode("_", $post);
return (int)$extract[0];
}
function getposttimestamp($post)
{
$extract = explode("_", $post);
$day = $extract[1] % 100;
$month = ((int)($extract[1] / 100)) % 100;
$year = (int)($extract[1] / 10000);
return mktime(12, 0, 0, $month, $day, $year);
}
function getpostcategory($post)
{
$extract = explode("_", $post);
return $extract[2];
}
// error_reporting(E_ALL);
$monthlist = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
// Extract parameters
$category = "";
$date = "";
$post = "";
$count = 7;
$start = 0;
$prevurl = "";
$nexturl = "?page=2";
$pagenum = "";
if (isset($_GET["page"]) && preg_match("/\\A[1-9][0-9]*\\Z/", $_GET["page"]))
{
$pagenum = intval($_GET["page"]) - 1;
$start = $pagenum * $count;
$prevurl = "?page=" . ($pagenum);
$nexturl = "?page=" . ($pagenum + 2);
}
if (isset($_GET["p"]) && preg_match("/\\A[1-9][0-9]*\\Z/", $_GET["p"]))
{
$postnum = intval($_GET["p"]);
$post = sprintf("%05d", $postnum % 100000);
$count = 1;
}
if (isset($_GET["m"]) && $_GET["m"] != "")
{
$date = $_GET["m"];
$prevurl = $prevurl . "&m=" . $date;
$nexturl = $nexturl . "&m=" . $date;
}
if (isset($_GET["cat"]) && $_GET["cat"] != "")
{
$category = $_GET["cat"];
$prevurl = $prevurl . "&cat=" . $category;
$nexturl = $nexturl . "&cat=" . $category;
}
// Specify the path to where the diffs are located
$postpath = $_SERVER["DOCUMENT_ROOT"] . "/posts";
// Build an array of post files
$postfiles = array();
$months = array();
$categories = array();
if (($dir = opendir($postpath)) != false)
{
while (($curfile = readdir($dir)) != false)
{
$extract = explode("_", $curfile);
if (count($extract) == 3)
{
if ($extract[2] == "hidden" && $category != "hidden")
continue;
if ($extract[1] > 20050000)
{
$aindex = (int)($extract[1] / 100);
if (!array_key_exists($aindex, $months))
$months[$aindex] = 0;
$months[$aindex] += 1;
}
if ($extract[2] != "")
{
$aindex = $extract[2];
if (!array_key_exists($aindex, $categories))
$categories[$aindex] = 0;
$categories[$extract[2]] += 1;
}
if ($post != "" && $post == $extract[0])
$post = $curfile;
if ($date != "" && $date != substr($extract[1], 0, 6))
continue;
if ($category != "" && $category != $extract[2])
continue;
$postfiles[] = $curfile;
}
}
closedir($dir);
}
// Sort the array
rsort($postfiles);
// get the key of the element if we have a specific post
if ($post != "")
{
$start = array_search($post, $postfiles);
if ($start > 0)
{
$extract = explode("_", $postfiles[$start -1]);
$prevurl = "?p=" . (int)$extract[0];
}
if ($start < count($postfiles) - 1)
{
$extract = explode("_", $postfiles[$start + 1]);
$nexturl = "?p=" . (int)$extract[0];
}
}
// Determine the entries we want
if ($start >= 0)
$entries = array_slice($postfiles, $start, $count);
else
$entries = array();
// Compute a title for the page
$pagetitle = "MAME";
if ($category != "")
$pagetitle = $pagetitle . " in " . $catlist[$category];
else if ($date != "")
$pagetitle = $pagetitle . " from " . $monthlist[$date % 100] . " " . (int)($date / 100);
// Either HTML or RSS
if (isset($_GET["feed"]) && $_GET["feed"] != "")
require("gennews-rss.php");
else
require("gennews-html.php");
?>