Passed
Pull Request — master (#24)
by Michael
27:32 queued 12:57
created

pollresults.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
/*
3
               XOOPS - PHP Content Management System
4
                   Copyright (c) 2000-2020 XOOPS.org
5
                      <https://xoops.org>
6
 This program is free software; you can redistribute it and/or modify
7
 it under the terms of the GNU General Public License as published by
8
 the Free Software Foundation; either version 2 of the License, or
9
 (at your option) any later version.
10
11
 You may not change or alter any portion of this comment or credits
12
 of supporting developers from this source code or any supporting
13
 source code which is considered copyrighted (c) material of the
14
 original comment or credit authors.
15
16
 This program is distributed in the hope that it will be useful,
17
 but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 GNU General Public License for more details.
20
21
 You should have received a copy of the GNU General Public License
22
 along with this program; if not, write to the Free Software
23
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24
*/
25
26
/**
27
 * Poll Results page for the XoopsPoll Module
28
 *
29
 * @copyright ::  {@link https://xoops.org/ XOOPS Project}
30
 * @license   ::    {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later}
31
 * @subpackage:: admin
32
 * @since     ::         1.0
33
 * @author    ::     {@link https://www.myweb.ne.jp/ Kazumi Ono (AKA onokazu)}
34
 **/
35
36
use Xmf\Module\Admin;
37
use Xmf\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are 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.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
38
use XoopsModules\Newbb;
39
use XoopsModules\Xoopspoll\{
40
    Constants,
41
    Helper,
42
    Poll,
43
    Renderer
44
};
45
46
/**
47
 * @uses xoops_load() method used to load classes
48
 * @uses redirect_header() function used to send user to another location after completing task(s)
49
 * @uses $GLOBALS['xoops']::path gets XOOPS directory information
50
 * @uses xoops_getModuleHandler() to load handler for this module's class(es)
51
 */
52
require_once \dirname(__DIR__, 2) . '/mainfile.php';
53
54
$pollId = Request::getInt('poll_id', 0);
55
$helper = Helper::getInstance();
56
/*
57
 * check to see if we want to show polls created by the forum (newbb) module
58
 */
59
if ($GLOBALS['xoopsModuleConfig']['hide_forum_polls']) {
60
    /** @var \XoopsModuleHandler $moduleHandler */
61
    $moduleHandler = xoops_getHandler('module');
62
    $newbbModule   = $moduleHandler->getByDirname('newbb');
63
    if ($newbbModule instanceof \XoopsModule && $newbbModule->isactive()) {
64
        /** @var Newbb\TopicHandler $topicHandler */
65
        $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
66
        $tCount       = $topicHandler->getCount(new \Criteria('poll_id', $pollId, '='));
67
        if (!empty($tCount)) {
68
            $pollId = 0; // treat it as if no poll requested
69
        }
70
    }
71
}
72
73
if (empty($pollId)) {
74
    redirect_header('index.php', Constants::REDIRECT_DELAY_NONE);
75
}
76
$GLOBALS['xoopsOption']['template_main'] = 'xoopspoll_results.tpl';
77
require $GLOBALS['xoops']->path('header.php');
78
79
$pollHandler = $helper->getHandler('Poll');
80
$pollObj     = $pollHandler->get($pollId);
81
if (($pollObj instanceof Poll)) {
82
    /* make sure the poll has started */
83
    if ($pollObj->getVar('start_time') > time()) {
84
        redirect_header('index.php', Constants::REDIRECT_DELAY_NONE);
85
    }
86
87
    /* assign variables to template */
88
    $renderer = new Renderer($pollObj, $helper);
89
    $renderer->assignResults($GLOBALS['xoopsTpl']);
90
91
    $visReturn  = $pollObj->isResultVisible();
92
    $isVisible  = true === $visReturn;
93
    $visibleMsg = $isVisible ? '' : $visReturn;
94
95
    $GLOBALS['xoopsTpl']->assign(
96
        [
97
            'visible_msg'    => $visibleMsg,
98
            'disp_votes'     => $GLOBALS['xoopsModuleConfig']['disp_vote_nums'],
99
            'back_link_icon' => Admin::iconUrl('', '16') . '/back.png',
100
            'back_link'      => $GLOBALS['xoops']->url('modules/xoopspoll/index.php'),
101
            'back_text'      => _BACK,
102
        ]
103
    );
104
} else {
105
    redirect_header('index.php', Constants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSPOLL_ERROR_INVALID_POLLID);
106
}
107
require $GLOBALS['xoops']->path('include/comment_view.php');
108
require_once XOOPS_ROOT_PATH . '/footer.php';
109