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

include/storyform.original.php (6 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
xoops_loadLanguage('calendar');
22
23
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
24
require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
25
require_once XOOPS_ROOT_PATH . '/modules/news/config.php';
26
27
if (!isset($subtitle)) {
28
    $subtitle = '';
29
}
30
if (!isset($pictureinfo)) {
31
    $pictureinfo = '';
32
}
33
34
$sform = new XoopsThemeForm(_NW_SUBMITNEWS, 'storyform', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/submit.php');
35
$sform->setExtra('enctype="multipart/form-data"');
36
$sform->addElement(new XoopsFormText(_NW_TITLE, 'title', 50, 255, $title), true);
37
$sform->addElement(new XoopsFormText(_NW_SUBTITLE, 'subtitle', 50, 255, $subtitle), false);
38
39
// Topic's selection box
40
if (!isset($xt)) {
41
    $xt = new NewsTopic();
42
}
43
if (0 == $xt->getAllTopicsCount()) {
44
    redirect_header('index.php', 4, _NW_POST_SORRY);
45
}
46
47
require_once XOOPS_ROOT_PATH . '/class/tree.php';
48
$allTopics  = $xt->getAllTopics($xoopsModuleConfig['restrictindex'], 'news_submit');
49
$topic_tree = new XoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
50
51
$moduleDirName = basename(dirname(__DIR__));
52
xoops_load('utility', $moduleDirName);
53
54 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...
55
    //    $topic_select = $topic_tree->makeSelBox('topic_id', 'topic_title', '-- ', $topicid, false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
56
    $topic_select = $topic_tree->makeSelectElement('topic_id', 'topic_title', '--', $topicid, false, 0, '', _NW_TOPIC);
57
    $sform->addElement($topic_select);
58
} else {
59
    $topic_select = $topic_tree->makeSelBox('topic_id', 'topic_title', '-- ', $topicid, false);
60
    $sform->addElement(new XoopsFormLabel(_NW_TOPIC, $topic_select));
61
}
62
63
//If admin - show admin form
64
//TODO: Change to "If submit privilege"
65 View Code Duplication
if ($approveprivilege) {
66
    //Show topic image?
67
    $sform->addElement(new XoopsFormRadioYN(_AM_TOPICDISPLAY, 'topicdisplay', $topicdisplay));
68
    //Select image position
69
    $posselect = new XoopsFormSelect(_AM_TOPICALIGN, 'topicalign', $topicalign);
70
    $posselect->addOption('R', _AM_RIGHT);
71
    $posselect->addOption('L', _AM_LEFT);
72
    $sform->addElement($posselect);
73
    //Publish in home?
74
    //TODO: Check that pubinhome is 0 = no and 1 = yes (currently vice versa)
75
    $sform->addElement(new XoopsFormRadioYN(_AM_PUBINHOME, 'ihome', $ihome, _NO, _YES));
76
}
77
78
// News author
79 View Code Duplication
if ($approveprivilege && is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
80
    if (!isset($newsauthor)) {
81
        $newsauthor = $xoopsUser->getVar('uid');
82
    }
83
    $memberHandler = xoops_getHandler('member');
84
    $usercount     = $memberHandler->getUserCount();
85
    if ($usercount < $cfg['config_max_users_list']) {
86
        $sform->addElement(new XoopsFormSelectUser(_NW_AUTHOR, 'author', true, $newsauthor), false);
87
    } else {
88
        $sform->addElement(new XoopsFormText(_NW_AUTHOR_ID, 'author', 10, 10, $newsauthor), false);
89
    }
90
}
91
92
$editor = NewsUtility::getWysiwygForm(_NW_THESCOOP, 'hometext', $hometext, 15, 60, 'hometext_hidden');
93
$sform->addElement($editor, true);
94
95
//Extra info
96
//If admin -> if submit privilege
97
if ($approveprivilege) {
98
    $editor2 = NewsUtility::getWysiwygForm(_AM_EXTEXT, 'bodytext', $bodytext, 15, 60, 'bodytext_hidden');
99
    $sform->addElement($editor2, false);
100
101 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...
102
        $itemIdForTag = isset($storyid) ? $storyid : 0;
103
        require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php';
104
        $sform->addElement(new TagFormTag('item_tag', 60, 255, $itemIdForTag, 0));
105
    }
106
107 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...
108
        $sform->addElement(new xoopsFormText(_NW_META_DESCRIPTION, 'description', 50, 255, $description), false);
109
        $sform->addElement(new xoopsFormText(_NW_META_KEYWORDS, 'keywords', 50, 255, $keywords), false);
110
    }
111
}
112
113
// Manage upload(s)
114
$allowupload = false;
115 View Code Duplication
switch ($xoopsModuleConfig['uploadgroups']) {
116
    case 1: //Submitters and Approvers
117
        $allowupload = true;
118
        break;
119
    case 2: //Approvers only
120
        $allowupload = $approveprivilege ? true : false;
121
        break;
122
    case 3: //Upload Disabled
123
        $allowupload = false;
124
        break;
125
}
126
127 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...
128
    if ('edit' === $op) {
129
        $sfiles   = new sFiles();
130
        $filesarr = [];
131
        $filesarr = $sfiles->getAllbyStory($storyid);
132
        if (count($filesarr) > 0) {
133
            $upl_tray     = new XoopsFormElementTray(_AM_UPLOAD_ATTACHFILE, '<br>');
134
            $upl_checkbox = new XoopsFormCheckBox('', 'delupload[]');
135
136
            foreach ($filesarr as $onefile) {
137
                $link = sprintf("<a href='%s/%s' target='_blank'>%s</a>\n", XOOPS_UPLOAD_URL, $onefile->getDownloadname('S'), $onefile->getFileRealName('S'));
138
                $upl_checkbox->addOption($onefile->getFileid(), $link);
139
            }
140
            $upl_tray->addElement($upl_checkbox, false);
141
            $dellabel = new XoopsFormLabel(_AM_DELETE_SELFILES, '');
142
            $upl_tray->addElement($dellabel, false);
143
            $sform->addElement($upl_tray);
144
        }
145
    }
146
    $sform->addElement(new XoopsFormFile(_AM_SELFILE, 'attachedfile', $xoopsModuleConfig['maxuploadsize']), false);
147
    if ('edit' === $op) {
148
        if (isset($picture) && '' !== xoops_trim($picture)) {
149
            $pictureTray = new XoopsFormElementTray(_NW_CURENT_PICTURE, '<br>');
150
            $pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/news/image/' . $picture . "'>"));
151
            $deletePicureCheckbox = new XoopsFormCheckBox('', 'deleteimage', 0);
152
            $deletePicureCheckbox->addOption(1, _DELETE);
153
            $pictureTray->addElement($deletePicureCheckbox);
154
            $sform->addElement($pictureTray);
155
        }
156
    }
157
    $sform->addElement(new XoopsFormFile(_NW_SELECT_IMAGE, 'attachedimage', $xoopsModuleConfig['maxuploadsize']), false);
158
    $sform->addElement(new XoopsFormText(_NW_SELECT_IMAGE_DESC, 'pictureinfo', 50, 255, $pictureinfo), false);
159
}
160
161
$option_tray = new XoopsFormElementTray(_OPTIONS, '<br>');
162
//Set date of publish/expiration
163 View Code Duplication
if ($approveprivilege) {
164
    if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
165
        $approve = 1;
166
    }
167
    $approve_checkbox = new XoopsFormCheckBox('', 'approve', $approve);
168
    $approve_checkbox->addOption(1, _AM_APPROVE);
169
    $option_tray->addElement($approve_checkbox);
170
171
    $check              = $published > 0 ? 1 : 0;
172
    $published_checkbox = new XoopsFormCheckBox('', 'autodate', $check);
173
    $published_checkbox->addOption(1, _AM_SETDATETIME);
174
    $option_tray->addElement($published_checkbox);
175
176
    $option_tray->addElement(new XoopsFormDateTime(_AM_SETDATETIME, 'publish_date', 15, $published));
177
178
    $check            = $expired > 0 ? 1 : 0;
179
    $expired_checkbox = new XoopsFormCheckBox('', 'autoexpdate', $check);
180
    $expired_checkbox->addOption(1, _AM_SETEXPDATETIME);
181
    $option_tray->addElement($expired_checkbox);
182
183
    $option_tray->addElement(new XoopsFormDateTime(_AM_SETEXPDATETIME, 'expiry_date', 15, $expired));
184
}
185
186 View Code Duplication
if (is_object($xoopsUser)) {
187
    $notify_checkbox = new XoopsFormCheckBox('', 'notifypub', $notifypub);
188
    $notify_checkbox->addOption(1, _NW_NOTIFYPUBLISH);
189
    $option_tray->addElement($notify_checkbox);
190
    if ($xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
191
        $nohtml_checkbox = new XoopsFormCheckBox('', 'nohtml', $nohtml);
192
        $nohtml_checkbox->addOption(1, _DISABLEHTML);
193
        $option_tray->addElement($nohtml_checkbox);
194
    }
195
}
196
$smiley_checkbox = new XoopsFormCheckBox('', 'nosmiley', $nosmiley);
197
$smiley_checkbox->addOption(1, _DISABLESMILEY);
198
$option_tray->addElement($smiley_checkbox);
199
200
$sform->addElement($option_tray);
201
202
//TODO: Approve checkbox + "Move to top" if editing + Edit indicator
203
204
//Submit buttons
205
$button_tray = new XoopsFormElementTray('', '');
206
$preview_btn = new XoopsFormButton('', 'preview', _PREVIEW, 'submit');
207
$preview_btn->setExtra('accesskey="p"');
208
$button_tray->addElement($preview_btn);
209
$submit_btn = new XoopsFormButton('', 'post', _NW_POST, 'submit');
210
$submit_btn->setExtra('accesskey="s"');
211
$button_tray->addElement($submit_btn);
212
$sform->addElement($button_tray);
213
214
//Hidden variables
215
if (isset($storyid)) {
216
    $sform->addElement(new XoopsFormHidden('storyid', $storyid));
217
}
218
219 View Code Duplication
if (!isset($returnside)) {
220
    $returnside = isset($_POST['returnside']) ? (int)$_POST['returnside'] : 0;
221
    if (empty($returnside)) {
222
        $returnside = isset($_GET['returnside']) ? (int)$_GET['returnside'] : 0;
223
    }
224
}
225
226
if (!isset($returnside)) {
227
    $returnside = 0;
228
}
229
$sform->addElement(new XoopsFormHidden('returnside', $returnside), false);
230
231
if (!isset($type)) {
232
    if ($approveprivilege) {
233
        $type = 'admin';
234
    } else {
235
        $type = 'user';
236
    }
237
}
238
$type_hidden = new XoopsFormHidden('type', $type);
239
$sform->addElement($type_hidden);
240
$sform->display();
241