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