|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @category Module |
|
14
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
15
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
16
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use Xmf\Request; |
|
|
|
|
|
|
20
|
|
|
use XoopsModules\Suico\{ |
|
21
|
|
|
IshotHandler |
|
22
|
|
|
}; |
|
23
|
|
|
|
|
24
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'suico_index.tpl'; |
|
25
|
|
|
require __DIR__ . '/header.php'; |
|
26
|
|
|
/** |
|
27
|
|
|
* Factory of pictures created |
|
28
|
|
|
*/ |
|
29
|
|
|
$ishotFactory = new IshotHandler($xoopsDB); |
|
30
|
|
|
$uid_voted = Request::getInt('uid_voted', 0, 'POST'); |
|
31
|
|
|
$ishot = Request::getInt('ishot', 0, 'POST'); |
|
32
|
|
|
$uid_voter = (int)$xoopsUser->getVar('uid'); |
|
33
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
34
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
|
35
|
|
|
} |
|
36
|
|
|
/** |
|
37
|
|
|
* Verify if user is trying to vote for himself |
|
38
|
|
|
*/ |
|
39
|
|
|
if ($uid_voter === $uid_voted) { |
|
40
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_CANTVOTEOWN); |
|
41
|
|
|
} |
|
42
|
|
|
/** |
|
43
|
|
|
* Verify that this user hasn't voted or added this user yet |
|
44
|
|
|
*/ |
|
45
|
|
|
$criteria_uidvoter = new Criteria( |
|
46
|
|
|
'uid_voter', |
|
47
|
|
|
$uid_voter |
|
48
|
|
|
); |
|
49
|
|
|
$criteria_uidvoted = new Criteria('uid_voted', $uid_voted); |
|
50
|
|
|
$criteria = new CriteriaCompo($criteria_uidvoter); |
|
51
|
|
|
$criteria->add($criteria_uidvoted); |
|
52
|
|
|
if (0 === $ishotFactory->getCount($criteria)) { |
|
53
|
|
|
$vote = $ishotFactory->create(true); |
|
54
|
|
|
$vote->setVar('uid_voted', $uid_voted); |
|
55
|
|
|
$vote->setVar('uid_voter', $uid_voter); |
|
56
|
|
|
if (1 === $ishot) { |
|
57
|
|
|
$vote->setVar('ishot', 1); |
|
58
|
|
|
} else { |
|
59
|
|
|
$vote->setVar('ishot', 0); |
|
60
|
|
|
} |
|
61
|
|
|
$ishotFactory->insert2($vote); |
|
62
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_VOTED); |
|
63
|
|
|
} else { |
|
64
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_ALREADYVOTED); |
|
65
|
|
|
} |
|
66
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
|
67
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: