forked from aerograf/xtorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratefile.php
102 lines (97 loc) · 4.11 KB
/
ratefile.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
<?php
include __DIR__ . '/header.php';
global $myts;
if (!empty($_POST['submit']))
{
if (empty($xoopsUser))
{
$ratinguser = 0;
}
else
{
$ratinguser = $xoopsUser -> getVar('uid');
}
// Make sure only 1 anonymous from an IP in a single day.
$anonwaitdays = 1;
$ip = getenv('REMOTE_ADDR');
$lid = (int)$_POST['lid'];
$cid = (int)$_POST['cid'];
$rating = (int)$_POST['rating'];
// Check if Rating is Null
if ('--' == $rating)
{
redirect_header('ratefile.php?cid=' . $cid . '&lid=' . $lid . '', 4, _MD_XTORRENT_NORATING);
exit();
}
// Check if Download POSTER is voting (UNLESS Anonymous users allowed to post)
if (0 != $ratinguser)
{
$result = $xoopsDB -> query('SELECT submitter FROM ' . $xoopsDB -> prefix('xtorrent_downloads') . ' WHERE lid=' . $lid);
while (list($ratinguserDB) = $xoopsDB -> fetchRow($result))
{
if ($ratinguserDB == $ratinguser)
{
redirect_header('index.php', 4, _MD_XTORRENT_CANTVOTEOWN);
exit();
}
}
// Check if REG user is trying to vote twice.
$result = $xoopsDB -> query('SELECT ratinguser FROM ' . $xoopsDB -> prefix('xtorrent_votedata') . ' WHERE lid=' . $lid);
while (list($ratinguserDB) = $xoopsDB -> fetchRow($result))
{
if ($ratinguserDB == $ratinguser)
{
redirect_header('index.php', 4, _MD_XTORRENT_VOTEONCE);
exit();
}
}
}
else
{
// Check if ANONYMOUS user is trying to vote more than once per day.
$yesterday = (time() - (86400 * $anonwaitdays));
$result = $xoopsDB -> query('SELECT COUNT(*) FROM '
. $xoopsDB -> prefix('xtorrent_votedata')
. ' WHERE lid='
. $lid
. " AND ratinguser=0 AND ratinghostname = '"
. $ip
. "' AND ratingtimestamp > "
. $yesterday);
list($anonvotecount) = $xoopsDB -> fetchRow($result);
if ($anonvotecount >= 1)
{
redirect_header('index.php', 4, _MD_XTORRENT_VOTEONCE);
exit();
}
}
// All is well. Add to Line Item Rate to DB.
$newid = $xoopsDB -> genId($xoopsDB -> prefix('xtorrent_votedata') . '_ratingid_seq');
$datetime = time();
$sql = sprintf("INSERT INTO %s (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (%u, %u, %u, %u, '%s', %u)", $xoopsDB -> prefix('xtorrent_votedata'), $newid, $lid, $ratinguser, $rating, $ip, $datetime);
$xoopsDB -> query($sql);
// All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB.
xtorrent_updaterating($lid);
$ratemessage = _MD_XTORRENT_VOTEAPPRE . '<br>' . sprintf(_MD_XTORRENT_THANKYOU, $xoopsConfig['sitename']);
redirect_header('index.php', 4, $ratemessage);
exit();
}
else
{
$GLOBALS['xoopsOption']['template_main'] = 'xtorrent_ratefile.tpl';
include XOOPS_ROOT_PATH . '/header.php';
$lid = (int)$_GET['lid'];
$cid = (int)$_GET['cid'];
$imageheader = xtorrent_imageheader();
$result = $xoopsDB -> query('SELECT title FROM ' . $xoopsDB -> prefix('xtorrent_downloads') . ' WHERE lid=' . $lid);
list($title) = $xoopsDB -> fetchRow($result);
$xoopsTpl -> assign('file', [
'id' => $lid,
'cid' => $cid,
'title' => $myts -> htmlSpecialChars($title),
'imageheader' => $imageheader
]);
$xoopsTpl -> assign('navitem', 1);
include XOOPS_ROOT_PATH . '/footer.php';
}
include __DIR__ . '/footer.php';