Issues (76)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/Contents.php (7 issues)

1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsfaq;
4
5
/*
6
 You may not change or alter any portion of this comment or credits of
7
 supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit
9
 authors.
10
11
 This program is distributed in the hope that it will be useful, but
12
 WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
16
/**
17
 * Contents (FAQ) and Handler Class Definitions
18
 *
19
 * @author    John Neill
20
 * @author    XOOPS Module Development Team
21
 * @copyright Copyright (c) 2001-2017 {@link https://xoops.org XOOPS Project}
22
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
23
 * @since     ::   1.23
24
 */
25
26
use Xmf\Module\Admin;
27
28
/**
29
 * Contents handles CRUD operations for FAQs
30
 *
31
 * @author   ::    John Neill
32
 * @copyright:: Copyright (c) 2009
33
 */
34
final class Contents extends \XoopsObject
35
{
36
    private $contents_id;
37
    private $contents_cid;
38
    private $contents_title;
39
    private $contents_contents;
40
    private $contents_publish;
41
    private $contents_weight;
42
    private $contents_active;
43
    private $dohtml;
44
    private $doxcode;
45
    private $dosmiley;
46
    private $doimage;
47
    private $dobr;
48
49
    /**
50
     * @var string contains this modules directory name
51
     */
52
    protected $dirname;
53
54
    /**
55
     * Constructor
56
     */
57
    public function __construct()
58
    {
59
        $this->dirname = \basename(\dirname(__DIR__));
60
        \xoops_load('constants', $this->dirname);
61
62
        parent::__construct();
63
        $this->initVar('contents_id', \XOBJ_DTYPE_INT, null, false);
64
        $this->initVar('contents_cid', \XOBJ_DTYPE_INT, Constants::DEFAULT_CATEGORY, false);
65
        $this->initVar('contents_title', \XOBJ_DTYPE_TXTBOX, null, true, 255);
66
        $this->initVar('contents_contents', \XOBJ_DTYPE_TXTAREA, null, false);
67
        $this->initVar('contents_publish', \XOBJ_DTYPE_INT, \time(), false);
68
        $this->initVar('contents_weight', \XOBJ_DTYPE_INT, Constants::DEFAULT_WEIGHT, false);
69
        $this->initVar('contents_active', \XOBJ_DTYPE_INT, Constants::ACTIVE, false);
70
        $this->initVar('dohtml', \XOBJ_DTYPE_INT, Constants::SET, false);
71
        $this->initVar('doxcode', \XOBJ_DTYPE_INT, Constants::SET, false);
72
        $this->initVar('dosmiley', \XOBJ_DTYPE_INT, Constants::SET, false);
73
        $this->initVar('doimage', \XOBJ_DTYPE_INT, Constants::SET, false);
74
        $this->initVar('dobr', \XOBJ_DTYPE_INT, Constants::SET, false);
75
    }
76
77
    /**
78
     * Display Content (FAQ)
79
     *
80
     * @return string
81
     */
82
    public function __toString(): string
83
    {
84
        return (string)$this->getVar('contents_title', 's');
85
    }
86
87
    /**
88
     * Display the Content (FAQ) Editor form for Admin
89
     */
90
    public function displayForm(): void
91
    {
92
        echo $this->renderForm();
93
    }
94
95
    /**
96
     * Displays the Content (FAQ) Editor form for Admin
97
     */
98
    public function renderForm()
99
    {
100
        /** @var CategoryHandler $categoryHandler */
101
        /** @var Helper $helper */
102
        $helper          = Helper::getHelper($this->dirname);
103
        $categoryHandler = $helper->getHandler('Category');
104
        $catCount        = $categoryHandler->getCount();
105
        if (empty($catCount)) {
106
            \xoops_error(\_AM_XOOPSFAQ_ERROR_NO_CATS_EXIST, '');
107
            \xoops_cp_footer();
108
            exit();
109
        }
110
111
        require_once $GLOBALS['xoops']->path('/class/xoopsformloader.php');
112
113
        $caption = ($this->isNew()) ? \_AM_XOOPSFAQ_CREATE_NEW : \sprintf(\_AM_XOOPSFAQ_MODIFY_ITEM, $this->getVar('contents_title'));
0 ignored issues
show
It seems like $this->getVar('contents_title') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
        $caption = ($this->isNew()) ? \_AM_XOOPSFAQ_CREATE_NEW : \sprintf(\_AM_XOOPSFAQ_MODIFY_ITEM, /** @scrutinizer ignore-type */ $this->getVar('contents_title'));
Loading history...
114
        $form    = new \XoopsThemeForm($caption, 'content', $_SERVER['REQUEST_URI'], 'post', true);
115
        //        $form->addElement(new \XoopsFormHiddenToken());
116
        $form->addElement(new \XoopsFormHidden('op', 'save'));
117
        $form->addElement(new \XoopsFormHidden('contents_id', $this->getVar('contents_id', 'e')));
0 ignored issues
show
It seems like $this->getVar('contents_id', 'e') can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
        $form->addElement(new \XoopsFormHidden('contents_id', /** @scrutinizer ignore-type */ $this->getVar('contents_id', 'e')));
Loading history...
118
119
        // Active
120
        $contents_active = new \XoopsFormRadioYN(\_AM_XOOPSFAQ_E_CONTENTS_ACTIVE, 'contents_active', $this->getVar('contents_active', 'e'), ' ' . \_YES, ' ' . \_NO);
0 ignored issues
show
It seems like $this->getVar('contents_active', 'e') can also be of type array and array; however, parameter $value of XoopsFormRadioYN::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

120
        $contents_active = new \XoopsFormRadioYN(\_AM_XOOPSFAQ_E_CONTENTS_ACTIVE, 'contents_active', /** @scrutinizer ignore-type */ $this->getVar('contents_active', 'e'), ' ' . \_YES, ' ' . \_NO);
Loading history...
121
        $contents_active->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_ACTIVE_DESC);
122
        $form->addElement($contents_active, false);
123
124
        // Title
125
        $contents_title = new \XoopsFormText(\_AM_XOOPSFAQ_E_CONTENTS_TITLE, 'contents_title', 50, 150, $this->getVar('contents_title', 'e'));
0 ignored issues
show
It seems like $this->getVar('contents_title', 'e') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

125
        $contents_title = new \XoopsFormText(\_AM_XOOPSFAQ_E_CONTENTS_TITLE, 'contents_title', 50, 150, /** @scrutinizer ignore-type */ $this->getVar('contents_title', 'e'));
Loading history...
126
        $contents_title->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_TITLE_DESC);
127
        $form->addElement($contents_title, true);
128
129
        // Category
130
        $catCriteria        = new \CriteriaCompo();
131
        $catCriteria->order = 'ASC';
132
        $catCriteria->setSort('category_order');
133
        $objects      = $categoryHandler->getList($catCriteria);
134
        $contents_cid = new \XoopsFormSelect(\_AM_XOOPSFAQ_E_CONTENTS_CATEGORY, 'contents_cid', $this->getVar('contents_cid', 'e'), 1, false);
135
        $contents_cid->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_CATEGORY_DESC);
136
        $contents_cid->addOptionArray($objects);
137
        $form->addElement($contents_cid);
138
139
        // Weight
140
        $contents_weight = new \XoopsFormText(\_AM_XOOPSFAQ_E_CONTENTS_WEIGHT, 'contents_weight', 5, 5, $this->getVar('contents_weight', 'e'));
141
        $contents_weight->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_WEIGHT_DESC);
142
        $form->addElement($contents_weight, false);
143
144
        // Editor
145
        $editorConfigs = [];
146
        $options_tray  = new \XoopsFormElementTray(\_AM_XOOPSFAQ_E_CONTENTS_CONTENT, '<br>');
147
        if (\class_exists('XoopsFormEditor')) {
148
            // $editorConfigs = array('editor' => $GLOBALS['xoopsConfig']['general_editor'],
149
            $editorConfigs     = [
150
                'editor' => $helper->getConfig('use_wysiwyg', 'dhtmltextarea'),
151
                'rows'   => 25,
152
                'cols'   => '100%',
153
                'width'  => '100%',
154
                'height' => '600px',
155
                'name'   => 'contents_contents',
156
                'value'  => $this->getVar('contents_contents', 'e'),
157
            ];
158
            $contents_contents = new \XoopsFormEditor('', 'contents_contents', $editorConfigs);
159
        } else {
160
            $contents_contents = new \XoopsFormDhtmlTextArea('', 'contents_contents', $this->getVar('contents_contents', 'e'), '100%', '100%');
0 ignored issues
show
'100%' of type string is incompatible with the type integer expected by parameter $rows of XoopsFormDhtmlTextArea::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

160
            $contents_contents = new \XoopsFormDhtmlTextArea('', 'contents_contents', $this->getVar('contents_contents', 'e'), /** @scrutinizer ignore-type */ '100%', '100%');
Loading history...
'100%' of type string is incompatible with the type integer expected by parameter $cols of XoopsFormDhtmlTextArea::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

160
            $contents_contents = new \XoopsFormDhtmlTextArea('', 'contents_contents', $this->getVar('contents_contents', 'e'), '100%', /** @scrutinizer ignore-type */ '100%');
Loading history...
It seems like $this->getVar('contents_contents', 'e') can also be of type array and array; however, parameter $value of XoopsFormDhtmlTextArea::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

160
            $contents_contents = new \XoopsFormDhtmlTextArea('', 'contents_contents', /** @scrutinizer ignore-type */ $this->getVar('contents_contents', 'e'), '100%', '100%');
Loading history...
161
        }
162
        $options_tray->addElement($contents_contents);
163
        $options_tray->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_CONTENT_DESC);
164
165
        \xoops_load('XoopsEditorHandler');
166
        $editorHandler = \XoopsEditorHandler::getInstance();
167
        $editorList    = $editorHandler->getList(true);
168
        if (isset($editorConfigs['editor']) && \in_array($editorConfigs['editor'], \array_flip($editorList), true)) {
169
            $form->addElement(new \XoopsFormHidden('dohtml', Constants::NOTSET));
170
            $form->addElement(new \XoopsFormHidden('dobr', Constants::SET));
171
        } else {
172
            $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml', 'e'));
173
            $html_checkbox->addOption(1, \_AM_XOOPSFAQ_E_DOHTML);
174
            $options_tray->addElement($html_checkbox);
175
176
            $breaks_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr', 'e'));
177
            $breaks_checkbox->addOption(1, \_AM_XOOPSFAQ_E_BREAKS);
178
            $options_tray->addElement($breaks_checkbox);
179
        }
180
181
        $doimage_checkbox = new \XoopsFormCheckBox('', 'doimage', $this->getVar('doimage', 'e'));
182
        $doimage_checkbox->addOption(1, \_AM_XOOPSFAQ_E_DOIMAGE);
183
        $options_tray->addElement($doimage_checkbox);
184
185
        $xcodes_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode', 'e'));
186
        $xcodes_checkbox->addOption(1, \_AM_XOOPSFAQ_E_DOXCODE);
187
        $options_tray->addElement($xcodes_checkbox);
188
189
        $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley', 'e'));
190
        $smiley_checkbox->addOption(1, \_AM_XOOPSFAQ_E_DOSMILEY);
191
        $options_tray->addElement($smiley_checkbox);
192
193
        $form->addElement($options_tray);
194
195
        $contents_publish = new \XoopsFormTextDateSelect(\_AM_XOOPSFAQ_E_CONTENTS_PUBLISH, 'contents_publish', 20, (int)$this->getVar('contents_publish'), $this->isNew());
196
        $contents_publish->setDescription(\_AM_XOOPSFAQ_E_CONTENTS_PUBLISH_DESC);
197
        $form->addElement($contents_publish);
198
199
        $form->addElement(new \XoopsFormButtonTray('contents_form', \_SUBMIT, 'submit'));
200
201
        return $form->render();
202
    }
203
204
    /**
205
     * Get the FAQ Active/Inactive icon to display
206
     *
207
     * @return string HTML <img> tag representing current active status
208
     */
209
    public function getActiveIcon(): string
210
    {
211
        if ($this->getVar('contents_active') > Constants::INACTIVE) {
212
            $icon = '<img src="' . Admin::iconUrl('green.gif', '16') . '" alt="' . \_YES . '">';
213
        } else {
214
            $icon = '<img src="' . Admin::iconUrl('red.gif', '16') . '" alt="' . \_NO . '">';
215
        }
216
217
        return $icon;
218
    }
219
220
    /**
221
     * Get the timestamp for when Content (FAQ) was published
222
     *
223
     * @param int|string $timestamp Unix timestamp
224
     *
225
     * @return string formatted timestamp on success, false on failure
226
     */
227
    public function getPublished($timestamp = ''): string
228
    {
229
        if (!$this->getVar('contents_publish')) {
230
            return '';
231
        }
232
233
        return \formatTimestamp($this->getVar('contents_publish'), $timestamp);
234
    }
235
}
236