PagesForm   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 173
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 93
c 0
b 0
f 0
dl 0
loc 173
rs 10
wmc 14

2 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 145 10
A message() 0 14 4
1
<?php
2
3
namespace XoopsModules\Xooghost\Form;
4
5
/**
6
 * Xooghost module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xooghost
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
 */
21
22
/**
23
 * Class PagesForm
24
 */
25
class PagesForm extends \Xoops\Form\ThemeForm
26
{
27
    /**
28
     * @param \XoopsModules\Xooghost\Page|\XoopsObject|null $obj
29
     */
30
    public function __construct(\XoopsModules\Xooghost\Page $obj = null)
31
    {
32
        $this->xoopsObject = $obj;
0 ignored issues
show
Bug Best Practice introduced by
The property xoopsObject does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
34
        /** @var \XoopsModules\Xooghost\Helper $helper */
35
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
36
        $ghostConfig = $helper->loadConfig();
37
        $pageHandler = $helper->getHandler('Page');
38
        $xoops = \Xoops::getInstance();
39
40
        if ($this->xoopsObject->isNew()) {
0 ignored issues
show
Bug introduced by
The method isNew() does not exist on null. ( Ignorable by Annotation )

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

40
        if ($this->xoopsObject->/** @scrutinizer ignore-call */ isNew()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            parent::__construct(_AM_XOO_GHOST_ADD, 'form_pages', 'pages.php', 'post', true);
42
        } else {
43
            parent::__construct(_AM_XOO_GHOST_EDIT . ' : ' . $this->xoopsObject->getVar('xooghost_title'), 'form_pages', 'pages.php', 'post', true);
44
        }
45
        $this->setExtra('enctype="multipart/form-data"');
46
47
        $tabTray = new \Xoops\Form\TabTray('', 'uniqueid');
48
49
        /**
50
         * Main
51
         */
52
        $tab1 = new \Xoops\Form\Tab(_AM_XOO_TABFORM_MAIN, 'tabid-1');
53
        // Url
54
        if ($this->xoopsObject->isNew()) {
55
            $dirlist = $pageHandler->getPhpListAsArray();
0 ignored issues
show
Bug introduced by
The method getPhpListAsArray() does not exist on XoopsObjectHandler. ( Ignorable by Annotation )

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

55
            /** @scrutinizer ignore-call */ 
56
            $dirlist = $pageHandler->getPhpListAsArray();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
57
            if (count($dirlist) > 0) {
58
                $ele = new \Xoops\Form\Select('', 'xooghost_url');
59
                $ele->addOption(0, _AM_XOO_GHOST_CHOOSE);
60
                $ele->addOptionArray($dirlist);
61
                $tab1->addElement($ele);
62
            } else {
63
                $tab1->addElement(new \Xoops\Form\Text(_XOO_GHOST_URL, 'xooghost_url', 12, 100, $this->xoopsObject->getVar('xooghost_url')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getVar('xooghost_url') can also be of type string[]; however, parameter $value of Xoops\Form\Text::__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

63
                $tab1->addElement(new \Xoops\Form\Text(_XOO_GHOST_URL, 'xooghost_url', 12, 100, /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xooghost_url')), true);
Loading history...
64
            }
65
        } else {
66
            $tab1->addElement(new \Xoops\Form\Hidden('xooghost_url', $this->xoopsObject->getVar('xooghost_url')));
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getVar('xooghost_url') can also be of type string[]; however, parameter $value of Xoops\Form\Hidden::__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

66
            $tab1->addElement(new \Xoops\Form\Hidden('xooghost_url', /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xooghost_url')));
Loading history...
67
        }
68
69
        // Title
70
        $tab1->addElement(new \Xoops\Form\Text(_XOO_GHOST_TITLE, 'xooghost_title', 12, 100, $this->xoopsObject->getVar('xooghost_title')), true);
71
72
        // submitter
73
        if ($helper->isUserAdmin()) {
74
            $xooghost_uid = $this->xoopsObject->isNew() ? $xoops->user->getVar('uid') : $this->xoopsObject->getVar('xooghost_uid');
75
            $tab1->addElement(new \Xoops\Form\SelectUser(_XOO_GHOST_AUTHOR, 'xooghost_uid', true, $xooghost_uid, 1, false));
76
        } else {
77
            $xooghost_uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
78
            $tab1->addElement(new \Xoops\Form\Hidden('xooghost_uid', $xooghost_uid));
79
        }
80
81
        // Content
82
        $tab1->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_CONTENT, 'xooghost_content', $this->xoopsObject->getVar('xooghost_content'), 7, 12), true);
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getVar('xooghost_content') can also be of type string[]; however, parameter $value of Xoops\Form\TextArea::__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

82
        $tab1->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_CONTENT, 'xooghost_content', /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xooghost_content'), 7, 12), true);
Loading history...
83
84
        // image
85
        $upload_msg[] = _XOO_GHOST_CONFIG_IMAGE_SIZE . ' : ' . $ghostConfig['xooghost_image_size'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$upload_msg was never initialized. Although not strictly required by PHP, it is generally a good practice to add $upload_msg = array(); before regardless.
Loading history...
86
        $upload_msg[] = _XOO_GHOST_CONFIG_IMAGE_WIDTH . ' : ' . $ghostConfig['xooghost_image_width'];
87
        $upload_msg[] = _XOO_GHOST_CONFIG_IMAGE_HEIGHT . ' : ' . $ghostConfig['xooghost_image_height'];
88
89
        $warning_tray = new \Xoops\Form\ElementTray($this->message($upload_msg, ''));
90
        $image_tray = new \Xoops\Form\ElementTray(_XOO_GHOST_IMAGE, '');
91
92
        $image_box = new \Xoops\Form\File('', 'xooghost_image', 5000000);
0 ignored issues
show
Unused Code introduced by
The call to Xoops\Form\File::__construct() has too many arguments starting with 5000000. ( Ignorable by Annotation )

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

92
        $image_box = /** @scrutinizer ignore-call */ new \Xoops\Form\File('', 'xooghost_image', 5000000);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
93
        $image_box->setExtra("size ='70%'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

93
        /** @scrutinizer ignore-deprecated */ $image_box->setExtra("size ='70%'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
94
        $image_tray->addElement($image_box);
95
        $image_tray->addElement($warning_tray);
96
97
        $image_array = \XoopsLists:: getImgListAsArray(\XoopsBaseConfig::get('uploads-path') . '/xooghost/images');
98
        $image_select = new \Xoops\Form\Select('<br>', 'image_list', $this->xoopsObject->getVar('xooghost_image'));
99
        $image_select->addOptionArray($image_array);
100
        $image_select->setExtra("onchange='showImgSelected(\"select_image\", \"image_list\", \"" . '/xooghost/images/' . '", "", "' . \XoopsBaseConfig::get('uploads-url') . "\")'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

100
        /** @scrutinizer ignore-deprecated */ $image_select->setExtra("onchange='showImgSelected(\"select_image\", \"image_list\", \"" . '/xooghost/images/' . '", "", "' . \XoopsBaseConfig::get('uploads-url') . "\")'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
101
        $image_tray->addElement($image_select);
102
        $image_tray->addElement(new \Xoops\Form\Label('', "<br><img src='" . \XoopsBaseConfig::get('uploads-url') . '/xooghost/images/' . $this->xoopsObject->getVar('xooghost_image') . "' name='select_image' id='select_image' alt=''>"));
103
        $tab1->addElement($image_tray);
104
105
        $tabTray->addElement($tab1);
106
107
        /**
108
         * Metas
109
         */
110
        $tab2 = new \Xoops\Form\Tab(_AM_XOO_TABFORM_METAS, 'tabid-2');
111
        // Meta description
112
        $tab2->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_DESCRIPTION, 'xooghost_description', $this->xoopsObject->getVar('xooghost_description'), 7, 12));
113
114
        // Meta Keywords
115
        $tab2->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_KEYWORDS, 'xooghost_keywords', $this->xoopsObject->getVar('xooghost_keywords'), 7, 12, _XOO_GHOST_KEYWORDS_DESC));
116
        $tabTray->addElement($tab2);
117
118
        /**
119
         * Options
120
         */
121
        // Published date
122
        $tab3 = new \Xoops\Form\Tab(_AM_XOO_TABFORM_OPTIONS, 'tabid-3');
123
        $published = (0 == $this->xoopsObject->getVar('xooghost_published')) ? time() : $this->xoopsObject->getVar('xooghost_published');
124
        $tab3->addElement(new \Xoops\Form\DateTimeSelect(_XOO_GHOST_PUBLISHED, 'xooghost_published', 15, $published, false));
0 ignored issues
show
Unused Code introduced by
The call to Xoops\Form\DateTimeSelect::__construct() has too many arguments starting with false. ( Ignorable by Annotation )

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

124
        $tab3->addElement(/** @scrutinizer ignore-call */ new \Xoops\Form\DateTimeSelect(_XOO_GHOST_PUBLISHED, 'xooghost_published', 15, $published, false));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
125
126
        // display
127
        $tab3->addElement(new \Xoops\Form\RadioYesNo(_XOO_GHOST_DISPLAY, 'xooghost_online', $this->xoopsObject->getVar('xooghost_online')));
0 ignored issues
show
Bug introduced by
It seems like $this->xoopsObject->getVar('xooghost_online') can also be of type string[]; however, parameter $value of Xoops\Form\RadioYesNo::__construct() does only seem to accept null|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

127
        $tab3->addElement(new \Xoops\Form\RadioYesNo(_XOO_GHOST_DISPLAY, 'xooghost_online', /** @scrutinizer ignore-type */ $this->xoopsObject->getVar('xooghost_online')));
Loading history...
128
        $tabTray->addElement($tab3);
129
130
        /**
131
         * Tags
132
         */
133
        if ($xoops->registry()->offsetExists('XOOTAGS') && $xoops->registry()->get('XOOTAGS')) {
134
            $tagsTray = new \Xoops\Form\Tab(_AM_XOO_TABFORM_TAGS, 'tabid-tags');
135
            //            $tagsFormHandler = $xoops->getModuleForm(0, 'tags', 'xootags');
136
            //            $tagform = $tagsFormHandler->tagForm('tags', $this->xoopsObject->getVar('xooghost_id'));
137
138
            $tagsForm = new \XoopsModules\Xootags\Form\TagsForm();
0 ignored issues
show
Bug introduced by
The type XoopsModules\Xootags\Form\TagsForm 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...
139
            $tagform = $tagsForm->tagForm('tags', $this->xoopsObject->getVar('xooghost_id'));
140
141
            $tagsTray->addElement($tagform);
142
            $tabTray->addElement($tagsTray);
143
        }
144
145
        // hidden
146
        $this->addElement(new \Xoops\Form\Hidden('xooghost_id', $this->xoopsObject->getVar('xooghost_id')));
147
        $this->addElement(new \Xoops\Form\Hidden('xooghost_hits', $this->xoopsObject->getVar('xooghost_hits')));
148
        $this->addElement(new \Xoops\Form\Hidden('xooghost_rates', $this->xoopsObject->getVar('xooghost_rates')));
149
        $this->addElement(new \Xoops\Form\Hidden('xooghost_like', $this->xoopsObject->getVar('xooghost_like')));
150
        $this->addElement(new \Xoops\Form\Hidden('xooghost_dislike', $this->xoopsObject->getVar('xooghost_dislike')));
151
        $this->addElement(new \Xoops\Form\Hidden('xooghost_comments', $this->xoopsObject->getVar('xooghost_comments')));
152
153
        $this->addElement($tabTray);
154
155
        /**
156
         * Buttons
157
         */
158
        $buttonTray = new \Xoops\Form\ElementTray('', '');
159
        $buttonTray->addElement(new \Xoops\Form\Hidden('op', 'save'));
160
161
        $buttonSubmit = new \Xoops\Form\Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit');
162
        $buttonSubmit->setClass('btn btn-success');
163
        $buttonTray->addElement($buttonSubmit);
164
165
        $buttonReset = new \Xoops\Form\Button('', 'reset', \XoopsLocale::A_RESET, 'reset');
166
        $buttonReset->setClass('btn btn-warning');
167
        $buttonTray->addElement($buttonReset);
168
169
        $buttonCancel = new \Xoops\Form\Button('', 'cancel', \XoopsLocale::A_CANCEL, 'button');
170
        $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

170
        /** @scrutinizer ignore-deprecated */ $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
171
        $buttonCancel->setClass('btn btn-danger');
172
        $buttonTray->addElement($buttonCancel);
173
174
        $this->addElement($buttonTray);
175
    }
176
177
    /**
178
     * @param        $msg
179
     * @param string $title
180
     * @param string $class
181
     *
182
     * @return string
183
     */
184
    public function message($msg, $title = '', $class = 'errorMsg')
185
    {
186
        $ret = "<div class='" . $class . "'>";
187
        if ('' != $title) {
188
            $ret .= '<strong>' . $title . '</strong>';
189
        }
190
        if (is_array($msg) || is_object($msg)) {
191
            $ret .= implode('<br>', $msg);
0 ignored issues
show
Bug introduced by
It seems like $msg can also be of type object; however, parameter $pieces of implode() does only seem to accept array, 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

191
            $ret .= implode('<br>', /** @scrutinizer ignore-type */ $msg);
Loading history...
192
        } else {
193
            $ret .= $msg;
194
        }
195
        $ret .= '</div>';
196
197
        return $ret;
198
    }
199
}
200