Passed
Pull Request — master (#73)
by
unknown
05:59 queued 03:12
created

votepolls.php (6 issues)

Labels
Severity
1
<?php
2
//
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2020 XOOPS.org                        //
6
//                       <https://xoops.org>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
use Xmf\Request;
29
use XoopsModules\Xoopspoll;
0 ignored issues
show
The type XoopsModules\Xoopspoll was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use XoopsModules\Xoopspoll\Constants;
0 ignored issues
show
The type XoopsModules\Xoopspoll\Constants was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
32
require_once __DIR__ . '/header.php';
33
$poll_id  = Request::getInt('poll_id', Request::getInt('poll_id', 0, 'POST'), 'GET');
34
$topic_id = Request::getInt('topic_id', Request::getInt('topic_id', 0, 'POST'), 'GET');
35
$forum    = Request::getInt('forum', Request::getInt('forum', 0, 'POST'), 'GET');
36
37
///** @var Newbb\TopicHandler $topicHandler */
38
//$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic');
39
$topicObject = $topicHandler->get($topic_id);
40
if (!$topicHandler->getPermission($topicObject->getVar('forum_id'), $topicObject->getVar('topic_status'), 'vote')) {
41
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _NOPERM);
42
}
43
44
if (!Request::getInt('option_id', 0, 'POST')) {
45
    // irmtfan - add error message - simple url
46
    redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id={$topic_id}", 1, _MD_NEWBB_POLL_NOOPTION);
47
}
48
// poll module
49
$pollModuleHandler = $moduleHandler->getByDirname($GLOBALS['xoopsModuleConfig']['poll_module']);
50
if (is_object($pollModuleHandler) && $pollModuleHandler->getVar('isactive')) {
51
    // new xoopspoll module
52
    if ($pollModuleHandler->getVar('version') >= 140) {
53
        xoops_load('constants', $GLOBALS['xoopsModuleConfig']['poll_module']);
54
        xoops_loadLanguage('main', $GLOBALS['xoopsModuleConfig']['poll_module']);
55
56
        /** @var \XoopsModules\Xoopspoll\PollHandler $xpPollHandler */
57
        $xpPollHandler = Xoopspoll\Helper::getInstance()->getHandler('Poll');
0 ignored issues
show
The type XoopsModules\Xoopspoll\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
        /** @var \XoopsModules\Xoopspoll\LogHandler $xpLogHandler */
59
        $xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log');
60
        /** @var \XoopsModules\Xoopspoll\Poll $pollObject */
61
        $pollObject = $xpPollHandler->get($poll_id); // will create poll if poll_id = 0 exist
62
        // old xoopspoll or umfrage or any clone from them
63
    } else {
64
        require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModuleConfig']['poll_module'] . '/include/constants.php');
65
        $classPoll  = $topicObject->loadOldPoll();
66
        $pollObject = new $classPoll($poll_id); // will create poll if poll_id = 0 exist
67
    }
68
} else {
69
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_POLLMODULE_ERROR);
70
}
71
72
$mail_author = false;
73
// new xoopspoll module
74
if ($pollModuleHandler->getVar('version') >= 201) {
75
//    $classConstants = \XoopsModules\Xoopspoll\Constants;
76
    if (is_object($pollObject)) {
77
        if ($pollObject->getVar('multiple')) {
78
            $optionId = Request::getInt('option_id', 0, 'POST');
79
            $optionId = (array)$optionId; // type cast to make sure it's an array
80
            $optionId = array_map('\intval', $optionId); // make sure values are integers
81
        } else {
82
            $optionId = Request::getInt('option_id', 0, 'POST');
83
        }
84
        if (!$pollObject->hasExpired()) {
85
            $msg = constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . '_MUSTLOGIN');
86
            //@todo:: add $url to all redirects
87
            //            $url = $GLOBALS['xoops']->buildUrl("index.php", array('poll_id' => $poll_id));
88
            if ($pollObject->isAllowedToVote()) {
89
                $thisVoter     = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : null;
90
                $votedThisPoll = $xpLogHandler->hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'), $thisVoter);
91
                if (!$votedThisPoll) {
92
                    /* user that hasn't voted before in this poll or module preferences allow it */
93
                    $voteTime = time();
94
                    if ($pollObject->vote($optionId, xoops_getenv('REMOTE_ADDR'), $voteTime)) {
95
                        if (!$xpPollHandler->updateCount($pollObject)) { // update the count and save in db
96
                            echo $pollObject->getHtmlErrors();
97
                            exit();
98
                        }
99
                        $msg = constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . '_THANKSFORVOTE');
100
                    } else {
101
                        /* there was a problem registering the vote */
102
                        redirect_header($GLOBALS['xoops']->buildUrl('index.php', ['poll_id' => $poll_id]), Constants::REDIRECT_DELAY_MEDIUM, constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . '_VOTE_ERROR'));
103
                    }
104
                } else {
105
                    $msg = constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . '_ALREADYVOTED');
106
                }
107
                /* set anon user vote (and the time they voted) */
108
                if (!is_object($GLOBALS['xoopsUser'])) {
109
                    xoops_load('pollUtility', $GLOBALS['xoopsModuleConfig']['poll_module']);
110
                    /** @var \XoopsModules\Xoopspoll\Utility $classPollUtility */
111
                    $classPollUtility = new \XoopsModules\Xoopspoll\Utility();
0 ignored issues
show
The type XoopsModules\Xoopspoll\Utility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
112
                    $classPollUtility::setVoteCookie($poll_id, $voteTime, 0);
113
                }
114
            } else {
115
                $msg = constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . '_CANNOTVOTE');
116
            }
117
        } else {
118
            /* poll has expired so just show the results */
119
            $msg = constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . 'SORRYEXPIRED');
120
        }
121
    } else {
122
        $msg = constant('_MD_' . mb_strtoupper($GLOBALS['xoopsModuleConfig']['poll_module']) . '_ERROR_INVALID_POLLID');
123
    }
124
    if (null !== $url) {
125
        redirect_header($url, Constants::REDIRECT_DELAY_MEDIUM, $msg);
126
    } else {
127
        redirect_header($GLOBALS['xoops']->buildUrl('viewtopic.php', ['topic_id' => $topic_id]), Constants::REDIRECT_DELAY_MEDIUM, $msg);
128
    }
129
    // old xoopspoll or umfrage or any clone from them
130
} else {
131
    $classLog = $classPoll . 'Log';
132
    if (is_object($GLOBALS['xoopsUser'])) {
133
        if ($classLog::hasVoted($poll_id, Request::getString('REMOTE_ADDR', '', 'SERVER'), $GLOBALS['xoopsUser']->getVar('uid'))) {
134
            $msg = _PL_ALREADYVOTED;
0 ignored issues
show
The constant _PL_ALREADYVOTED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
135
            setcookie("newbb_polls[{$poll_id}]", 1);
136
        } else {
137
            // irmtfan save ip to db
138
            $pollObject->vote(Request::getInt('option_id', 0, 'POST'), Request::getString('REMOTE_ADDR', '', 'SERVER'), $GLOBALS['xoopsUser']->getVar('uid'));
139
            $pollObject->updateCount();
140
            $msg = _PL_THANKSFORVOTE;
0 ignored issues
show
The constant _PL_THANKSFORVOTE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
141
            setcookie("newbb_polls[{$poll_id}]", 1);
142
        }
143
    } else {
144
        if ($classLog::hasVoted($poll_id, Request::getString('REMOTE_ADDR', '', 'SERVER'))) {
145
            $msg = _PL_ALREADYVOTED;
146
            setcookie("newbb_polls[{$poll_id}]", 1);
147
        } else {
148
            $pollObject->vote(Request::getInt('option_id', 0, 'POST'), Request::getString('REMOTE_ADDR', '', 'SERVER'));
149
            $pollObject->updateCount();
150
            $msg = _PL_THANKSFORVOTE;
151
            setcookie("newbb_polls[{$poll_id}]", 1);
152
        }
153
    }
154
}
155
// irmtfan - simple url
156
redirect_header("viewtopic.php?topic_id={$topic_id}", 1, $msg);
157