-
Notifications
You must be signed in to change notification settings - Fork 5
/
image_browser.php
169 lines (138 loc) · 5.46 KB
/
image_browser.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?
// message board image browser v.3
// include the configuration file
require('config.inc.php');
// overwrite the title
$config['title'] = "Riceboy Image Browser";
// establish a connection with the database or notify an admin with the error string
$mysqli_link = mysqli_connect($config['db_host'],$config['db_user'],$config['db_pass'],$config['db_name']) or error($config['db_errstr'],$config['admin_email'],'mysqli_connect(' . $config['db_host'] . ',' . $config['db_user'] . ',' . $config['db_pass'] . ')' . "\n".mysqli_error());
// handle authentication if necessary
if ($config['auth_required'] == true) {
// begin a session
session_start();
if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
$query = 'select username from ' . $locations['auth_table'] . ' where username = "' . $_SESSION['username'] . '" and password = "' . $_SESSION['password'] . '"';
$result = mysqli_query($mysqli_link, $query) or error($config['db_errstr'],$config['admin_email'],$query."\n".mysqli_error());
if (mysqli_num_rows($result) != 1) {
// destroy the erroneous session
session_destroy();
// leave
header('Location: ' . $locations['login']);
exit();
}
} else {
// leave
header('Location: ' . $locations['login']);
exit();
}
}
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'>
<head>
<title><?=$config['title']?></title>
<link rel="stylesheet" type="text/css" href="<?=$locations['css']?>">
</head>
<body class='body'>
<?
// setup the table rotation scheme
if ($config['rotate_tables'] == 'daily')
$t = date('mdy');
elseif ($config['rotate_tables'] == 'weekly')
$t = strftime('%y%W');
elseif ($config['rotate_tables'] == 'monthly')
$t = date('my');
elseif ($config['rotate_tables'] == 'yearly')
$t = date('Y');
else
$t = date('mdy');
$tablename = ($config['rotate_tables'] ? $locations['posts_table'].'_'.$t : $locations['posts_table']);
$query = 'select ' . $tablename . '.id, ' . $tablename . '.message_author, ' . $tablename . '.message_subject, ' .
'date_format(' . $tablename . '.date,"%m/%d/%Y - %l:%i:%s %p") as date,' . $locations['images_table'] . '.image_url ' .
'from ' . $tablename . ', ' . $locations['images_table'] . ' ' .
'where ' . (!$config['rotate_tables'] ? $tablename . '.t = "' . $t . '" and ' : '') . $locations['images_table'] . '.t = "' . $t . '" and ' . $locations['images_table'] . '.id = ' . $tablename . '.id ' .
'order by ' . $tablename . '.date desc';
$result = mysqli_query($mysqli_link, $query) or error($config['db_errstr'],$config['admin_email'],$query."\n".mysqli_error());
print "<!-- $query -->\n";
if (mysqli_num_rows($result) == 0) {
?>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='borderoutline'>
<table width='100%' border='0' cellspacing='1' cellpadding='4'>
<tr class='titlelarge'>
<td colspan='2'>No images to display.</td>
</tr>
<tr class='main'>
<td colspan='2'><a href='<?=$locations['forum']?>'>Back to the Forum</a></td>
</tr>
<tr class='main'>
<td colspan='2'>
<blockquote>
<?
} else {
if (isset($_REQUEST['page']) && is_numeric($_REQUEST['page'])) {
if ($_REQUEST['page'] <= mysqli_num_rows($result))
mysqli_data_seek($result, $_REQUEST['page'] - 1);
} else {
$_REQUEST['page'] = 1;
}
$count = 0;
while ($row = mysqli_fetch_array($result)) {
if ($count == 0) {
?>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='borderoutline'>
<table width='100%' border='0' cellspacing='1' cellpadding='4'>
<tr class='titlelarge'>
<td colspan='2'><?=$row['message_subject']?></td>
</tr>
<tr class='main'>
<td colspan='2'>
<?
$prevpage = $_REQUEST['page'] - 1;
$nextpage = $_REQUEST['page'] + 1;
if ($prevpage == 0 && $nextpage > mysqli_num_rows($result))
print "[Previous Image | Next Image]<br />\n";
elseif ($prevpage == 0)
print "[Previous Image | <a href='" . $locations['image_browser'] . "?page=" . $nextpage . "'>Next Image</a>]<br />\n";
elseif ($nextpage > mysqli_num_rows($result))
print "[<a href='" . $locations['image_browser'] . "?page=" . $prevpage . "'>Previous Image</a> | Next Image]<br />\n";
else
print "[<a href='" . $locations['image_browser'] . "?page=" . $prevpage . "'>Previous Image</a> | <a href='" . $locations['image_browser'] . "?page=" . $nextpage . "'>Next Image</a>]<br />\n";
?>
<a href='<?=$locations['forum']?>'>Back to the Forum</a>
</td>
</tr>
<tr class='main'>
<td colspan='2'>
Posted by <?=$row['message_author']?> on <?=$row['date']?>
<a href='<?=$locations['forum']?>?d=<?=$row['id']?>&t=<?=$t?>'>(See Complete Post)</a>
<hr />
<img src='<?=$row['image_url']?>' border='0' alt=''>
</td>
</tr>
<tr class='main'>
<td colspan='2'>
<blockquote><br />
<?
print "<a href='". $locations['image_browser'] . "?page=" . $_REQUEST['page'] . "'>" . $row['message_subject'] . "</a> - " . $row['message_author'] . " (" . $row['date']. ")<br />\n";
} else {
$temppage = $_REQUEST['page'] + $count;
print "<a href='" . $locations['image_browser'] . "?page=" . $temppage . "'>" . $row['message_subject'] . "</a> - " . $row['message_author'] . " (" . $row['date'] . ")<br />\n";
}
$count++;
}
}
?>
</blockquote>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>