-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.php
More file actions
130 lines (123 loc) · 4.43 KB
/
examples.php
File metadata and controls
130 lines (123 loc) · 4.43 KB
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
<?php
/*
This file is part of WebDRIP Designer
Copyright (C) 2013-2022 Jasper Vries
WebDRIP Designer is free software: you can redistribute it and/or
modify it under the terms of version 3 of the GNU General Public
License as published by the Free Software Foundation.
WebDRIP Designer 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 WebDRIP Designer. If not, see <http://www.gnu.org/licenses/>.
*/
//send headers
include('headers.inc.php');
//historylist
if (is_numeric($_GET['s'])) {
//max number of entries
//calculated from window area, set to a minimum of 10
$num_w = max(1, floor(($_GET['w'] - 16) / 208));
$num_h = max(1, floor(($_GET['h'] - 32) / 144));
$num = max(1, ($num_w * $num_h));
//connect db
include('config.cfg.php');
$db['link'] = mysqli_connect($cfg_db['host'], $cfg_db['user'], $cfg_db['pass'], $cfg_db['db']);
//get number of items
$qry = "SELECT `image_md5` FROM `history`";
//limit by ip or cookie
if (($_GET['l'] == 'user') || ($_GET['l'] == 'cookie')) {
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($ip);
$qry .= " WHERE `user_id` IN (SELECT `id` FROM `users`
WHERE `ip` = '".mysqli_real_escape_string($db['link'], $ip)."'
AND `hostname` = '".mysqli_real_escape_string($db['link'], $hostname)."'";
//limit by cookie
if ($_GET['l'] == 'cookie') {
//get cookie unique id
$cookie = $_COOKIE[$cfg_cookie['history']];
$qry .= " AND `cookie` = '".mysqli_real_escape_string($db['link'], $cookie)."'";
}
$qry .= ")";
}
$res = mysqli_query($db['link'], $qry);
$num_entries = mysqli_num_rows($res);
//decide next page
if (($_GET['s'] + $num) >= $num_entries) $nextpage = 0;
else $nextpage = $_GET['s'] + $num;
//decide previous page
$prevpage = $_GET['s'] - $num;
//select from database
$qry = "SELECT `history`.`image_md5` FROM `history` LEFT JOIN `users` ON `history`.`user_id` = `users`.`id`";
//limit by ip or cookie
if (($_GET['l'] == 'user') || ($_GET['l'] == 'cookie')) {
$qry .= " WHERE `user_id` IN (SELECT `id` FROM `users`
WHERE `ip` = '".mysqli_real_escape_string($db['link'], $ip)."'
AND `hostname` = '".mysqli_real_escape_string($db['link'], $hostname)."'";
//limit by cookie
if ($_GET['l'] == 'cookie') {
$qry .= " AND `cookie` = '".mysqli_real_escape_string($db['link'], $cookie)."'";
}
$qry .= ")";
}
$qry .= " ORDER BY `timestamp` DESC LIMIT ".$_GET['s'].",".$num;
$res = mysqli_query($db['link'], $qry);
//create result array
$result = array();
while ($row = mysqli_fetch_row($res)) {
$result[] = $row[0];
}
//output to browser
echo json_encode(array('i' => $result, 'o' => $nextpage, 'n' => $prevpage, 't' => $num_entries));
}
//examples
else {
//decide number of entries
$num = 20;
if (is_numeric($_GET['h'])) {
$maxheight = min(2000, $_GET['h']);
}
else {
$maxheight = 265;
}
//connect db
include('config.cfg.php');
$db['link'] = mysqli_connect($cfg_db['host'], $cfg_db['user'], $cfg_db['pass'], $cfg_db['db']);
//select from database
$qry = "SELECT `image_md5`, `image_raw` FROM `history`";
if (($_GET['l'] == 'user') || ($_GET['l'] == 'cookie')) {
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($ip);
$qry .= " WHERE `user_id` IN (SELECT `id` FROM `users`
WHERE `ip` = '".mysqli_real_escape_string($db['link'], $ip)."'
AND `hostname` = '".mysqli_real_escape_string($db['link'], $hostname)."'";
//limit by cookie
if ($_GET['l'] == 'cookie') {
//get cookie unique id
$cookie = $_COOKIE[$cfg_cookie['history']];
$qry .= " AND `cookie` = '".mysqli_real_escape_string($db['link'], $cookie)."'";
}
$qry .= ")";
}
$qry .= " ORDER BY `timestamp` DESC LIMIT ".$num;
$res = mysqli_query($db['link'], $qry);
//create result array
$result = array();
while ($row = mysqli_fetch_row($res)) {
//add to result list
$result[] = $row[0];
//calculate image height
$image = json_decode($row[1], TRUE);
if ($image['t']['c'][0] > 0) { //prevent div by zero
$height = min(96, round($image['t']['c'][1] * 144 / $image['t']['c'][0])) + 4;
}
$maxheight -= $height;
if ($maxheight < 0) {
break;
}
}
//output to browser
echo json_encode($result);
}
?>