Completed
Pull Request — master (#16)
by Michael
01:51
created

include/storyform.inc.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
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
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author         XOOPS Development Team
18
 */
19
20
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
$moduleDirName = basename(dirname(__DIR__));
22
xoops_load('utility', $moduleDirName);
23
xoops_loadLanguage('calendar');
24
25
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
26
require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
27
require_once XOOPS_ROOT_PATH . '/modules/news/config.php';
28
29
if (!isset($subtitle)) {
30
    $subtitle = '';
31
}
32
33
$sform = new XoopsThemeForm(_NW_SUBMITNEWS, 'storyform', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/submit.php');
34
$sform->setExtra('enctype="multipart/form-data"');
35
$sform->addElement(new XoopsFormText(_NW_TITLE, 'title', 50, 255, $title), true);
36
$sform->addElement(new XoopsFormText(_NW_SUBTITLE, 'subtitle', 50, 255, $subtitle), false);
37
38
// Topic's selection box
39
if (!isset($xt)) {
40
    $xt = new NewsTopic();
41
}
42
if (0 == $xt->getAllTopicsCount()) {
43
    redirect_header('index.php', 4, _NW_POST_SORRY);
44
}
45
46
require_once XOOPS_ROOT_PATH . '/class/tree.php';
47
$allTopics  = $xt->getAllTopics($xoopsModuleConfig['restrictindex'], 'news_submit');
48
$topic_tree = new XoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
49
50 View Code Duplication
if (NewsUtility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    $topic_select = $topic_tree->makeSelectElement('topic_id', 'topic_title', '--', $topicid, false, 0, '', _NW_TOPIC);
52
    $sform->addElement($topic_select);
53
} else {
54
    $topic_select = $topic_tree->makeSelBox('topic_id', 'topic_title', '-- ', $topicid, false);
55
    $sform->addElement(new XoopsFormLabel(_NW_TOPIC, $topic_select));
56
}
57
58
//If admin - show admin form
59
//TODO: Change to "If submit privilege"
60
61 View Code Duplication
if ($approveprivilege) {
62
    //Show topic image?
63
    $sform->addElement(new XoopsFormRadioYN(_AM_TOPICDISPLAY, 'topicdisplay', $topicdisplay));
64
    //Select image position
65
    $posselect = new XoopsFormSelect(_AM_TOPICALIGN, 'topicalign', $topicalign);
66
    $posselect->addOption('R', _AM_RIGHT);
67
    $posselect->addOption('L', _AM_LEFT);
68
    $sform->addElement($posselect);
69
    //Publish in home?
70
    //TODO: Check that pubinhome is 0 = no and 1 = yes (currently vice versa)
71
    $sform->addElement(new XoopsFormRadioYN(_AM_PUBINHOME, 'ihome', $ihome, _NO, _YES));
72
}
73
74
// News author
75
76 View Code Duplication
if ($approveprivilege && is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
77
    if (!isset($newsauthor)) {
78
        $newsauthor = $xoopsUser->getVar('uid');
79
    }
80
    $memberHandler = xoops_getHandler('member');
81
    $usercount     = $memberHandler->getUserCount();
82
    if ($usercount < $cfg['config_max_users_list']) {
83
        $sform->addElement(new XoopsFormSelectUser(_NW_AUTHOR, 'author', true, $newsauthor), false);
84
    } else {
85
        $sform->addElement(new XoopsFormText(_NW_AUTHOR_ID, 'author', 10, 10, $newsauthor), false);
86
    }
87
}
88
89
$editor = NewsUtility::getWysiwygForm(_NW_THESCOOP, 'hometext', $hometext, 15, 60, 'hometext_hidden');
90
$sform->addElement($editor, true);
91
92
//Extra info
93
//If admin -> if submit privilege
94
95
if ($approveprivilege) {
96
    $editor2 = NewsUtility::getWysiwygForm(_AM_EXTEXT, 'bodytext', $bodytext, 15, 60, 'bodytext_hidden');
97
    $sform->addElement($editor2, false);
98
99 View Code Duplication
    if (xoops_isActiveModule('tag') && NewsUtility::getModuleOption('tags')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
        $itemIdForTag = isset($storyid) ? $storyid : 0;
101
        require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php';
102
        $sform->addElement(new TagFormTag('item_tag', 60, 255, $itemIdForTag, 0));
103
    }
104
105 View Code Duplication
    if (NewsUtility::getModuleOption('metadata')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
        $sform->addElement(new xoopsFormText(_NW_META_DESCRIPTION, 'description', 50, 255, $description), false);
107
        $sform->addElement(new xoopsFormText(_NW_META_KEYWORDS, 'keywords', 50, 255, $keywords), false);
108
    }
109 View Code Duplication
} else {
110
    if (xoops_isActiveModule('tag') && NewsUtility::getModuleOption('tags')) {
111
        $itemIdForTag = isset($storyid) ? $storyid : 0;
112
        require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php';
113
        $sform->addElement(new TagFormTag('item_tag', 60, 255, $itemIdForTag, 0));
114
    }
115
}
116
// Manage upload(s)
117
$allowupload = false;
118 View Code Duplication
switch ($xoopsModuleConfig['uploadgroups']) {
119
    case 1: //Submitters and Approvers
120
        $allowupload = true;
121
        break;
122
    case 2: //Approvers only
123
        $allowupload = $approveprivilege ? true : false;
124
        break;
125
    case 3: //Upload Disabled
126
        $allowupload = false;
127
        break;
128
}
129
130 View Code Duplication
if ($allowupload) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131
    if ('edit' === $op) {
132
        $sfiles   = new sFiles();
133
        $filesarr = [];
134
        $filesarr = $sfiles->getAllbyStory($storyid);
135
        if (count($filesarr) > 0) {
136
            $upl_tray     = new XoopsFormElementTray(_AM_UPLOAD_ATTACHFILE, '<br>');
137
            $upl_checkbox = new XoopsFormCheckBox('', 'delupload[]');
138
139
            foreach ($filesarr as $onefile) {
140
                $link = sprintf("<a href='%s/%s' target='_blank'>%s</a>\n", XOOPS_UPLOAD_URL, $onefile->getDownloadname('S'), $onefile->getFileRealName('S'));
141
                $upl_checkbox->addOption($onefile->getFileid(), $link);
142
            }
143
            $upl_tray->addElement($upl_checkbox, false);
144
            $dellabel = new XoopsFormLabel(_AM_DELETE_SELFILES, '');
145
            $upl_tray->addElement($dellabel, false);
146
            $sform->addElement($upl_tray);
147
        }
148
    }
149
    $sform->addElement(new XoopsFormFile(_AM_SELFILE, 'attachedfile', $xoopsModuleConfig['maxuploadsize']), false);
150
    if ('edit' === $op) {
151
        if (isset($picture) && '' !== xoops_trim($picture)) {
152
            $pictureTray = new XoopsFormElementTray(_NW_CURENT_PICTURE, '<br>');
153
            $pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/news/image/' . $picture . "'>"));
154
            $deletePicureCheckbox = new XoopsFormCheckBox('', 'deleteimage', 0);
155
            $deletePicureCheckbox->addOption(1, _DELETE);
156
            $pictureTray->addElement($deletePicureCheckbox);
157
            $sform->addElement($pictureTray);
158
        }
159
    }
160
    if (!isset($pictureinfo)) {
161
        $pictureinfo = '';
162
    }
163
    $sform->addElement(new XoopsFormFile(_NW_SELECT_IMAGE, 'attachedimage', $xoopsModuleConfig['maxuploadsize']), false);
164
    $sform->addElement(new XoopsFormText(_NW_SELECT_IMAGE_DESC, 'pictureinfo', 50, 255, $pictureinfo), false);
165
}
166
167
$option_tray = new XoopsFormElementTray(_OPTIONS, '<br>');
168
//Set date of publish/expiration
169 View Code Duplication
if ($approveprivilege) {
170
    if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
171
        $approve = 1;
172
    }
173
    $approve_checkbox = new XoopsFormCheckBox('', 'approve', $approve);
174
    $approve_checkbox->addOption(1, _AM_APPROVE);
175
    $option_tray->addElement($approve_checkbox);
176
177
    $check              = $published > 0 ? 1 : 0;
178
    $published_checkbox = new XoopsFormCheckBox('', 'autodate', $check);
179
    $published_checkbox->addOption(1, _AM_SETDATETIME);
180
    $option_tray->addElement($published_checkbox);
181
182
    $option_tray->addElement(new XoopsFormDateTime(_AM_SETDATETIME, 'publish_date', 15, $published));
183
184
    $check            = $expired > 0 ? 1 : 0;
185
    $expired_checkbox = new XoopsFormCheckBox('', 'autoexpdate', $check);
186
    $expired_checkbox->addOption(1, _AM_SETEXPDATETIME);
187
    $option_tray->addElement($expired_checkbox);
188
189
    $option_tray->addElement(new XoopsFormDateTime(_AM_SETEXPDATETIME, 'expiry_date', 15, $expired));
190
}
191
192 View Code Duplication
if (is_object($xoopsUser)) {
193
    $notify_checkbox = new XoopsFormCheckBox('', 'notifypub', $notifypub);
194
    $notify_checkbox->addOption(1, _NW_NOTIFYPUBLISH);
195
    $option_tray->addElement($notify_checkbox);
196
    if ($xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
197
        $nohtml_checkbox = new XoopsFormCheckBox('', 'nohtml', $nohtml);
198
        $nohtml_checkbox->addOption(1, _DISABLEHTML);
199
        $option_tray->addElement($nohtml_checkbox);
200
    }
201
}
202
$smiley_checkbox = new XoopsFormCheckBox('', 'nosmiley', $nosmiley);
203
$smiley_checkbox->addOption(1, _DISABLESMILEY);
204
$option_tray->addElement($smiley_checkbox);
205
206
$sform->addElement($option_tray);
207
208
//Submit buttons
209
$button_tray = new XoopsFormElementTray('', '');
210
$preview_btn = new XoopsFormButton('', 'preview', _PREVIEW, 'submit');
211
$preview_btn->setExtra('accesskey="p"');
212
$button_tray->addElement($preview_btn);
213
$submit_btn = new XoopsFormButton('', 'post', _NW_POST, 'submit');
214
$submit_btn->setExtra('accesskey="s"');
215
$button_tray->addElement($submit_btn);
216
$sform->addElement($button_tray);
217
218
//Hidden variables
219
if (isset($storyid)) {
220
    $sform->addElement(new XoopsFormHidden('storyid', $storyid));
221
}
222
223 View Code Duplication
if (!isset($returnside)) {
224
    $returnside = isset($_POST['returnside']) ? (int)$_POST['returnside'] : 0;
225
    if (empty($returnside)) {
226
        $returnside = isset($_GET['returnside']) ? (int)$_GET['returnside'] : 0;
227
    }
228
}
229
230
if (!isset($returnside)) {
231
    $returnside = 0;
232
}
233
$sform->addElement(new XoopsFormHidden('returnside', $returnside), false);
234
235
if (!isset($type)) {
236
    if ($approveprivilege) {
237
        $type = 'admin';
238
    } else {
239
        $type = 'user';
240
    }
241
}
242
$type_hidden = new XoopsFormHidden('type', $type);
243
$sform->addElement($type_hidden);
244
245
echo '<h1>' . _NW_SUBMITNEWS . '</h1>';
246
if ('' !== xoops_trim(NewsUtility::getModuleOption('submitintromsg'))) {
247
    echo "<div class='infotext'><br><br>" . nl2br(NewsUtility::getModuleOption('submitintromsg')) . '<br><br></div>';
248
}
249
250
$sform->display();
251