1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Module: Soapbox |
4
|
|
|
* Version: v 1.5 |
5
|
|
|
* Release Date: 23 August 2004 |
6
|
|
|
* Author: hsalazar |
7
|
|
|
* Licence: GNU |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
use Xmf\Request; |
11
|
|
|
|
12
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
13
|
|
|
//if (!isset($_POST['submit'])) { |
14
|
|
|
// exit; |
15
|
|
|
//} |
16
|
|
|
//if (!isset($_POST['lid'])) { |
17
|
|
|
// exit; |
18
|
|
|
//} |
19
|
|
|
|
20
|
|
|
if (!Request::hasVar('submit', 'POST') || !Request::hasVar('lid', 'POST')) { |
21
|
|
|
exit; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
if (Request::hasVar('submit', 'POST')) { //($_POST['submit']) { |
25
|
|
|
//------------------------- |
26
|
|
|
// if (!$GLOBALS['xoopsSecurity']->check()) { |
27
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
28
|
|
|
redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
29
|
|
|
} |
30
|
|
|
//------------------------- |
31
|
|
|
$ratinguser = is_object($xoopsUser) ? $xoopsUser->uid() : 0; |
32
|
|
|
if (function_exists('floatval')) { |
33
|
|
|
$rating = $_POST['rating'] ? (float)$_POST['rating'] : 0; |
34
|
|
|
} else { |
35
|
|
|
$rating = $_POST['rating'] ? \Xmf\Request::getInt('rating', 0, 'POST') : 0; |
36
|
|
|
} |
37
|
|
|
$lid = $_POST['lid'] ? \Xmf\Request::getInt('lid', 0, 'POST') : 0; |
38
|
|
|
|
39
|
|
|
// Make sure only 1 anonymous from an IP in a single day. |
40
|
|
|
$anonwaitdays = 1; |
41
|
|
|
$ip = getenv('REMOTE_ADDR'); |
42
|
|
|
// Check if Rating is Null |
43
|
|
|
if (empty($rating) || empty($lid)) { |
44
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_NORATING); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
//module entry data handler |
48
|
|
|
/** @var \XoopsModules\Soapbox\EntrydataHandler $entrydataHandler */ |
49
|
|
|
$entrydataHandler = new \XoopsModules\Soapbox\EntrydataHandler(); |
50
|
|
|
//get entry object |
51
|
|
|
$_entryob = $entrydataHandler->getArticleOnePermcheck($lid, true); |
52
|
|
|
if (!is_object($_entryob)) { |
53
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php', 1, _MD_SOAPBOX_CANTVOTEOWN); |
54
|
|
|
} |
55
|
|
|
// Check if Download POSTER is voting (UNLESS Anonymous users allowed to post) |
56
|
|
|
if (0 !== $ratinguser) { |
57
|
|
|
//get category object |
58
|
|
|
$_categoryob = $_entryob->_sbcolumns; |
59
|
|
|
if (!is_object($_categoryob)) { |
|
|
|
|
60
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php', 1, 'no column'); |
61
|
|
|
} |
62
|
|
|
if ($_categoryob->getVar('author') === $ratinguser) { |
63
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_CANTVOTEOWN); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
//uid check |
67
|
|
|
//uid check |
68
|
|
|
$criteria = new \CriteriaCompo(); |
69
|
|
|
$criteria->add(new \Criteria('lid', $lid)); |
70
|
|
|
$criteria->add(new \Criteria('ratinguser', $ratinguser)); |
71
|
|
|
$ratinguservotecount = $entrydataHandler->getVotedataCount($criteria); |
72
|
|
|
unset($criteria); |
73
|
|
|
if ($ratinguservotecount > 0) { |
74
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_VOTEONCE); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Check if ANONYMOUS user is trying to vote more than once per day. |
79
|
|
|
if (0 === $ratinguser) { |
80
|
|
|
$yesterday = (time() - (86400 * $anonwaitdays)); |
81
|
|
|
//uid check |
82
|
|
|
$criteria = new \CriteriaCompo(); |
83
|
|
|
$criteria->add(new \Criteria('lid', $lid)); |
84
|
|
|
$criteria->add(new \Criteria('ratinguser', 0)); |
85
|
|
|
$criteria->add(new \Criteria('ratinghostname', $ip)); |
86
|
|
|
$criteria->add(new \Criteria('ratingtimestamp', $yesterday, '>')); |
87
|
|
|
$anonvotecount = $entrydataHandler->getVotedataCount($criteria); |
88
|
|
|
unset($criteria); |
89
|
|
|
if ($anonvotecount > 0) { |
90
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_VOTEONCE); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$_votedataob = $entrydataHandler->createVotedata(true); |
95
|
|
|
// $_votedataob->cleanVars(); |
96
|
|
|
$_votedataob->setVar('lid', $lid); |
97
|
|
|
$_votedataob->setVar('ratinguser', $ratinguser); |
98
|
|
|
$_votedataob->setVar('rating', $rating); |
99
|
|
|
$_votedataob->setVar('ratinghostname', $ip); |
100
|
|
|
$_votedataob->setVar('ratingtimestamp', time()); |
101
|
|
|
// Save to database |
102
|
|
|
if (!$entrydataHandler->insertVotedata($_votedataob, true)) { |
103
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_CANTVOTEOWN); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// All is well. Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. |
107
|
|
|
// updaterating( $lid ); |
108
|
|
|
if (!$entrydataHandler->updateRating($_entryob)) { |
109
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_UNKNOWNERROR); |
110
|
|
|
} else { |
111
|
|
|
$ratemessage = _MD_SOAPBOX_VOTEAPPRE . '<br>' . sprintf(_MD_SOAPBOX_THANKYOU, $myts->htmlSpecialChars($xoopsConfig['sitename'])); |
112
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, $ratemessage); |
113
|
|
|
} |
114
|
|
|
// exit(); |
115
|
|
|
} else { |
116
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?articleID=' . $lid, 1, _MD_SOAPBOX_UNKNOWNERROR); |
117
|
|
|
// exit(); |
118
|
|
|
} |
119
|
|
|
|