-
Notifications
You must be signed in to change notification settings - Fork 16
/
manage_page.php
231 lines (201 loc) · 7.42 KB
/
manage_page.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/*
* This file is part of kusaba.
*
* kusaba 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 2 of the License, or (at your option) any later
* version.
*
* kusaba 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
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Manage panel for administrative/moderator operations
*
* The manage panel is used for changing configurations, adding/modifying/deleting
* boards, locking/stickying/deleting posts, banning users, and more. The manage
* panel is able to be logged in to by both administrators and moderators, however
* moderators will be restricted to only the boards which they moderate, and cannot
* perform any actions on the "Administration:" link-line.
*
* @package kusaba
*/
session_set_cookie_params(60 * 60 * 24 * 100); /* 100 Days */
session_start();
require 'config.php';
require KU_ROOTDIR . 'lib/dwoo.php';
require KU_ROOTDIR . 'inc/functions.php';
require KU_ROOTDIR . 'inc/classes/manage.class.php';
require KU_ROOTDIR . 'inc/classes/board-post.class.php';
require KU_ROOTDIR . 'inc/classes/bans.class.php';
$dwoo_data->assign('styles', explode(':', KU_MENUSTYLES));
$manage_class = new Manage();
$bans_class = new Bans();
if (isset($_GET['graph'])) {
$manage_class->ValidateSession();
require KU_ROOTDIR . 'lib/graph/phpgraphlib.php';
if (isset($_GET['type'])) {
if ($_GET['type'] == 'day' || $_GET['type'] == 'week' || $_GET['type'] == 'postnum' || $_GET['type'] == 'unique' || $_GET['type'] == 'posttime') {
$graph = new PHPGraphLib(600, 600);
if ($_GET['type'] == 'day') {
$setTitle = 'Posts per board in past 24hrs';
$graph->setTitle($setTitle);
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
if (count($results) > 0) {
$data = array();
foreach ($results as $line) {
$posts = $tc_db->GetOne("SELECT HIGH_PRIORITY COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `timestamp` > " . (time() - 86400) . "");
$data = array_merge($data, array($line['name'] => $posts));
}
}
} elseif ($_GET['type'] == 'week') {
$setTitle = 'Posts per board in past week';
$graph->setTitle($setTitle);
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
if (count($results) > 0) {
$data = array();
foreach ($results as $line) {
$posts = $tc_db->GetOne("SELECT HIGH_PRIORITY COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `timestamp` > " . (time() - 604800) . "");
$data = array_merge($data, array($line['name'] => $posts));
}
}
} elseif ($_GET['type'] == 'postnum') {
$setTitle = 'Total posts per board';
$graph->setTitle($setTitle);
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
if (count($results) > 0) {
$data = array();
foreach ($results as $line) {
$posts = $tc_db->GetOne("SELECT `id` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " ORDER BY `id` DESC LIMIT 1");
$data = array_merge($data, array($line['name'] => $posts));
}
}
} elseif ($_GET['type'] == 'unique') {
$setTitle = 'Unique user posts per board';
$graph->setTitle($setTitle);
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
if (count($results) > 0) {
$data = array();
foreach ($results as $line) {
$posts = $tc_db->GetOne("SELECT COUNT(DISTINCT `ipmd5`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `IS_DELETED` = 0");
$data = array_merge($data, array($line['name'] => $posts));
}
}
} elseif ($_GET['type'] == 'posttime') {
$setTitle = 'Average #minutes between posts (past week), boards without posts in past week not shown';
$graph->setTitle($setTitle);
$results = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "boards` ORDER BY `name` ASC");
if (count($results) > 0) {
$data = array();
foreach ($results as $line) {
$posts = $tc_db->GetAll("SELECT `timestamp` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $line['id'] . " AND `timestamp` > " . (time() - 604800) . " ORDER BY `id` ASC");
if (count($posts) > 0) {
$i = 0;
$lastpost_time = 0;
$times = array();
foreach ($posts as $post) {
$i++;
if ($i > 1) {
$times[] = ($post['timestamp'] - $lastpost_time);
}
$lastpost_time = $post['timestamp'];
}
$times_sum = array_sum($times);
if ($times_sum > 0) {
$times_sum = ($times_sum / 60);
$times_avg = ($times_sum / count($times));
} else {
$times_avg = 0;
}
} else {
$times_avg = 0;
}
if ($times_avg > 0) {
$data = array_merge($data, array($line['name'] => $times_avg));
}
}
}
}
if ($posts <= 0){
header ("Content-type: image/png");
$handle = ImageCreate (600, 50) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($handle, 255, 0, 0);
ImageString ($handle, 5, 5, 18, $setTitle." : none", $txt_color);
ImagePng ($handle);
} else {
$graph->addData($data);
$graph->setGradient('red', 'maroon');
$graph->setTextColor('black');
$graph->createGraph();
}
}
}
die();
}
/* Does nothing if the user isn't logged in */
$manage_class->SetModerationCookies();
/* Decide what needs to be done */
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'announcements';
switch ($action) {
case 'logout':
$manage_class->Logout();
break;
case 'showlogin':
$manage_class->LoginForm();
break;
case 'login':
$manage_class->CheckLogin();
/* Halts execution if not validated */
$manage_class->ValidateSession();
manage_page();
break;
case 'getip':
if ($manage_class->ValidateSession(true))
manage_page($action);
break;
default:
/* Halts execution if not validated */
$manage_class->ValidateSession();
manage_page($action);
break;
}
/* Show a particular manage function */
function manage_page($action = 'announcements') {
global $manage_class, $tpl_page;
$manage_class->Header();
if (is_callable(array($manage_class, $action))) {
$manage_class->$action();
} else {
$tpl_page .= sprintf(_gettext('%s not implemented.'), $action);
}
$manage_class->Footer();
}
/* Check if a tab is currently open */
function pagetaken_check($pagename) {
global $action;
$tab_is_selected = false;
$pages = array('home', 'administration', 'boards', 'moderation');
foreach ($pages as $page) {
if (isset($_GET[$page])) {
$tab_is_selected = true;
}
}
if ($tab_is_selected && isset($_GET[$pagename])) {
return true;
} else {
/* Special workaround for index page */
if ($pagename == 'home' && ($action == 'announcements' || $action == '') && !$tab_is_selected) {
return true;
} else {
return false;
}
}
}
?>