Completed
Push — master ( 16270d...f28230 )
by Michael
03:23
created

submit.php (2 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       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Publisher
16
 * @subpackage      Action
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
include_once __DIR__ . '/header.php';
23
xoops_loadLanguage('admin', PUBLISHER_DIRNAME);
24
25
// Get the total number of categories
26
$categoriesArray = $publisher->getHandler('category')->getCategoriesForSubmit();
27
28
if (!$categoriesArray) {
29
    redirect_header('index.php', 1, _MD_PUBLISHER_NEED_CATEGORY_ITEM);
30
    //    exit();
31
}
32
33
$groups       = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
34
$gpermHandler = xoops_getModuleHandler('groupperm');
35
$moduleId     = $publisher->getModule()->getVar('mid');
36
37
$itemId = XoopsRequest::getInt('itemid', XoopsRequest::getInt('itemid', 0, 'POST'), 'GET');
38
if ($itemId != 0) {
39
    // We are editing or deleting an article
40
    $itemObj = $publisher->getHandler('item')->get($itemId);
41
    if (!(publisherUserIsAdmin() || publisherUserIsAuthor($itemObj) || publisherUserIsModerator($itemObj))) {
42
        redirect_header('index.php', 1, _NOPERM);
43
        //        exit();
44
    }
45
    if (!publisherUserIsAdmin() || !publisherUserIsModerator($itemObj)) {
46
        if ('del' === XoopsRequest::getString('op', '', 'GET') && !$publisher->getConfig('perm_delete')) {
47
            redirect_header('index.php', 1, _NOPERM);
48
            //            exit();
49
        } elseif (!$publisher->getConfig('perm_edit')) {
50
            redirect_header('index.php', 1, _NOPERM);
51
            //            exit();
52
        }
53
    }
54
55
    $categoryObj = $itemObj->getCategory();
56
} else {
57
    // we are submitting a new article
58
    // if the user is not admin AND we don't allow user submission, exit
59 View Code Duplication
    if (!(publisherUserIsAdmin() || ($publisher->getConfig('perm_submit') == 1 && (is_object($GLOBALS['xoopsUser']) || ($publisher->getConfig('perm_anon_submit') == 1))))) {
60
        redirect_header('index.php', 1, _NOPERM);
61
        //        exit();
62
    }
63
    $itemObj     = $publisher->getHandler('item')->create();
64
    $categoryObj = $publisher->getHandler('category')->create();
65
}
66
67
if ('clone' === XoopsRequest::getString('op', '', 'GET')) {
68
    $formtitle = _MD_PUBLISHER_SUB_CLONE;
69
    $itemObj->setNew();
70
    $itemObj->setVar('itemid', 0);
71
} else {
72
    $formtitle = _MD_PUBLISHER_SUB_SMNAME;
73
}
74
75
//$op = '';
76
$op = 'add';
77
if (XoopsRequest::getString('additem', '', 'POST')) {
78
    $op = 'post';
79
} elseif (XoopsRequest::getString('preview', '', 'POST')) {
80
    $op = 'preview';
81
}
82
83
$op = XoopsRequest::getString('op', XoopsRequest::getString('op', $op, 'POST'), 'GET');
84
85
$allowedEditors = publisherGetEditors($gpermHandler->getItemIds('editors', $groups, $moduleId));
86
$formView       = $gpermHandler->getItemIds('form_view', $groups, $moduleId);
87
88
// This code makes sure permissions are not manipulated
89
$elements = array(
90
    'summary',
91
    'available_page_wrap',
92
    'item_tag',
93
    'image_item',
94
    'item_upload_file',
95
    'uid',
96
    'datesub',
97
    'status',
98
    'item_short_url',
99
    'item_meta_keywords',
100
    'item_meta_description',
101
    'weight',
102
    'allowcomments',
103
    'dohtml',
104
    'dosmiley',
105
    'doxcode',
106
    'doimage',
107
    'dolinebreak',
108
    'notify',
109
    'subtitle',
110
    'author_alias'
111
);
112
foreach ($elements as $element) {
113
    if (XoopsRequest::getString('element', '', 'POST') && !in_array(constant('PublisherConstants::PUBLISHER_' . strtoupper($element)), $formView)) {
114
        redirect_header('index.php', 1, _MD_PUBLISHER_SUBMIT_ERROR);
115
        //        exit();
116
    }
117
}
118
//unset($element);
119
120
$itemUploadFile = XoopsRequest::getArray('item_upload_file', array(), 'FILES');
121
122
//stripcslashes
123
switch ($op) {
124 View Code Duplication
    case 'del':
125
        $confirm = XoopsRequest::getInt('confirm', '', 'POST');
126
127
        if ($confirm) {
128
            if (!$publisher->getHandler('item')->delete($itemObj)) {
129
                redirect_header('index.php', 2, _AM_PUBLISHER_ITEM_DELETE_ERROR . publisherFormatErrors($itemObj->getErrors()));
130
                //                exit();
131
            }
132
            redirect_header('index.php', 2, sprintf(_AM_PUBLISHER_ITEMISDELETED, $itemObj->getTitle()));
133
            //            exit();
134
        } else {
135
            include_once $GLOBALS['xoops']->path('header.php');
136
            xoops_confirm(array('op' => 'del', 'itemid' => $itemObj->itemid(), 'confirm' => 1, 'name' => $itemObj->getTitle()), 'submit.php',
137
                          _AM_PUBLISHER_DELETETHISITEM . " <br>'" . $itemObj->getTitle() . "'. <br> <br>", _AM_PUBLISHER_DELETE);
138
            include_once $GLOBALS['xoops']->path('footer.php');
139
        }
140
        exit();
141
        break;
142
    case 'preview':
143
        // Putting the values about the ITEM in the ITEM object
144
        $itemObj->setVarsFromRequest();
145
146
        $xoopsOption['template_main'] = 'publisher_submit.tpl';
147
        include_once $GLOBALS['xoops']->path('header.php');
148
        $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
149
        $xoTheme->addScript(PUBLISHER_URL . '/assets/js/publisher.js');
150
        include_once PUBLISHER_ROOT_PATH . '/footer.php';
151
152
        $categoryObj = $publisher->getHandler('category')->get(XoopsRequest::getInt('categoryid', 0, 'POST'));
153
154
        $item                 = $itemObj->toArraySimple();
155
        $item['summary']      = $itemObj->body();
156
        $item['categoryPath'] = $categoryObj->getCategoryPath(true);
157
        $item['who_when']     = $itemObj->getWhoAndWhen();
158
        $item['comments']     = -1;
159
        $xoopsTpl->assign('item', $item);
160
161
        $xoopsTpl->assign('op', 'preview');
162
        $xoopsTpl->assign('module_home', publisherModuleHome());
163
164
        if ($itemId) {
165
            $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_EDIT_ARTICLE);
166
            $xoopsTpl->assign('langIntroTitle', _MD_PUBLISHER_EDIT_ARTICLE);
167
            $xoopsTpl->assign('langIntroText', '');
168 View Code Duplication
        } else {
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...
169
            $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_SUB_SNEWNAME);
170
            $xoopsTpl->assign('langIntroTitle', sprintf(_MD_PUBLISHER_SUB_SNEWNAME, ucwords($publisher->getModule()->name())));
171
            $xoopsTpl->assign('langIntroText', $publisher->getConfig('submit_intro_msg'));
172
        }
173
174
        $sform = $itemObj->getForm($formtitle, true);
175
        $sform->assign($xoopsTpl);
176
        include_once $GLOBALS['xoops']->path('footer.php');
177
        exit();
178
179
        break;
180
181
    case 'post':
182
        // Putting the values about the ITEM in the ITEM object
183
        // print_r($itemObj->getVars());
184
        $itemObj->setVarsFromRequest();
185
        //print_r($_POST);
186
        //print_r($itemObj->getVars());
187
        //exit;
188
189
        // Storing the item object in the database
190
        if (!$itemObj->store()) {
191
            redirect_header('javascript:history.go(-1)', 2, _MD_PUBLISHER_SUBMIT_ERROR);
192
            //            exit();
193
        }
194
195
        // attach file if any
196
        if ($itemUploadFile && $itemUploadFile['name'] != '') {
197
            $fileUploadResult = publisherUploadFile(false, true, $itemObj);
198
            if ($fileUploadResult !== true) {
199
                redirect_header('javascript:history.go(-1)', 3, $fileUploadResult);
200
                exit;
201
            }
202
        }
203
204
        // if autoapprove_submitted. This does not apply if we are editing an article
205
        if (!$itemId) {
206
            if ($itemObj->getVar('status') == PublisherConstants::PUBLISHER_STATUS_PUBLISHED /*$publisher->getConfig('perm_autoapprove'] ==  1*/) {
207
                // We do not not subscribe user to notification on publish since we publish it right away
208
209
                // Send notifications
210
                $itemObj->sendNotifications(array(PublisherConstants::PUBLISHER_NOTIFY_ITEM_PUBLISHED));
211
212
                $redirect_msg = _MD_PUBLISHER_ITEM_RECEIVED_AND_PUBLISHED;
213
                redirect_header($itemObj->getItemUrl(), 2, $redirect_msg);
214
            } else {
215
                // Subscribe the user to On Published notification, if requested
216
                if ($itemObj->getVar('notifypub')) {
217
                    include_once $GLOBALS['xoops']->path('include/notification_constants.php');
218
                    $notificationHandler = xoops_getHandler('notification');
219
                    $notificationHandler->subscribe('item', $itemObj->itemid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
220
                }
221
                // Send notifications
222
                $itemObj->sendNotifications(array(PublisherConstants::PUBLISHER_NOTIFY_ITEM_SUBMITTED));
223
224
                $redirect_msg = _MD_PUBLISHER_ITEM_RECEIVED_NEED_APPROVAL;
225
            }
226
        } else {
227
            $redirect_msg = _MD_PUBLISHER_ITEMMODIFIED;
228
            redirect_header($itemObj->getItemUrl(), 2, $redirect_msg);
229
        }
230
        redirect_header('index.php', 2, $redirect_msg);
231
        //        exit();
232
233
        break;
234
235
    case 'add':
236
    default:
237
        $xoopsOption['template_main'] = 'publisher_submit.tpl';
238
        include_once $GLOBALS['xoops']->path('header.php');
239
        $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
240
        $GLOBALS['xoTheme']->addScript(PUBLISHER_URL . '/assets/js/publisher.js');
241
        include_once PUBLISHER_ROOT_PATH . '/footer.php';
242
243
        //mb        $itemObj->setVarsFromRequest();
244
245
        $xoopsTpl->assign('module_home', publisherModuleHome());
246
        if ('clone' === XoopsRequest::getString('op', '', 'GET')) {
247
            $xoopsTpl->assign('categoryPath', _CO_PUBLISHER_CLONE);
248
            $xoopsTpl->assign('langIntroTitle', _CO_PUBLISHER_CLONE);
249
        } elseif ($itemId) {
250
            $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_EDIT_ARTICLE);
251
            $xoopsTpl->assign('langIntroTitle', _MD_PUBLISHER_EDIT_ARTICLE);
252
            $xoopsTpl->assign('langIntroText', '');
253 View Code Duplication
        } else {
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...
254
            $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_SUB_SNEWNAME);
255
            $xoopsTpl->assign('langIntroTitle', sprintf(_MD_PUBLISHER_SUB_SNEWNAME, ucwords($publisher->getModule()->name())));
256
            $xoopsTpl->assign('langIntroText', $publisher->getConfig('submit_intro_msg'));
257
        }
258
        $sform = $itemObj->getForm($formtitle, true);
259
        $sform->assign($xoopsTpl);
260
261
        include_once $GLOBALS['xoops']->path('footer.php');
262
        break;
263
}
264