-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsubmit.php
More file actions
251 lines (234 loc) · 9.97 KB
/
submit.php
File metadata and controls
251 lines (234 loc) · 9.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/**
* Module: Soapbox
* Version: v 1.5
* Release Date: 23 August 2004
* Author: hsalazar
* Licence: GNU
*/
use Xmf\Request;
use XoopsModules\Soapbox;
require dirname(dirname(__DIR__)) . '/mainfile.php';
/** @var Soapbox\Helper $helper */
$helper = Soapbox\Helper::getInstance();
//global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
//----------------------------------------------
//allowsubmit
if (null !== $helper->getConfig('allowsubmit') || 1 !== $helper->getConfig('allowsubmit')) {
redirect_header('index.php', 1, _NOPERM);
}
//guest
if (!is_object($xoopsUser)) {
redirect_header('index.php', 1, _NOPERM);
}
//require XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/gtickets.php';
$xoopsConfig['module_cache'] = 0; //disable caching since the URL will be the same, but content different from one user to another
require XOOPS_ROOT_PATH . '/header.php';
$myts = \MyTextSanitizer:: getInstance();
//----------------------------------------------
//post op check
$op = 'form';
if (\Xmf\Request::hasVar('post', 'POST')) {
$op = 'post';
} elseif (\Xmf\Request::hasVar('edit', 'POST')) {
$op = 'edit';
}
$op = Request::getString('op', 'check', 'POST');
//----------------------------------------------
//post or get articleID check
$articleID = 0;
if (\Xmf\Request::hasVar('articleID', 'GET')) {
$articleID = \Xmf\Request::getInt('articleID', 0, 'GET');
}
if (\Xmf\Request::hasVar('articleID', 'POST')) {
$articleID = \Xmf\Request::getInt('articleID', 0, 'POST');
}
//----------------------------------------------
//user group , edit_uid
$thisgrouptype = XOOPS_GROUP_USERS;
if ($xoopsUser->isAdmin($xoopsModule->mid())) {
$thisgrouptype = XOOPS_GROUP_ADMIN;
}
$edit_uid = $xoopsUser->getVar('uid');
$name = $xoopsUser->getVar('uname');
//-------------------------------------
/** @var \XoopsModules\Soapbox\EntrydataHandler $entrydataHandler */
$entrydataHandler = new \XoopsModules\Soapbox\EntrydataHandler();
//-------------------------------------
//get can edit category object
if (XOOPS_GROUP_ADMIN === $thisgrouptype) {
$canEditCategoryobArray = $entrydataHandler->getColumns(null, true);
} else {
$canEditCategoryobArray = $entrydataHandler->getColumnsByAuthor($edit_uid, true);
}
if (empty($canEditCategoryobArray) || 0 === count($canEditCategoryobArray)) {
redirect_header('index.php', 1, _MD_SOAPBOX_NOCOLEXISTS);
}
//----------------------------------------------
//main
switch ($op) {
case 'post':
//-------------------------
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors());
}
//-------------------------
//articleID check
if (\Xmf\Request::hasVar('articleID', 'POST')) {
$_entryob = $entrydataHandler->getArticleOnePermcheck($articleID, true, true);
if (!is_object($_entryob)) {
redirect_header('index.php', 1, _NOPERM);
break;
}
} else {
$_entryob = $entrydataHandler->createArticle(true);
// $_entryob->cleanVars();
}
//set
$_entryob->setVar('uid', $edit_uid);
if (\Xmf\Request::hasVar('columnID', 'POST')) {
$_entryob->setVar('columnID', \Xmf\Request::getInt('columnID', 0, 'POST'));
}
//get category object
if (!isset($canEditCategoryobArray[$_entryob->getVar('columnID')])) {
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/index.php', 2, _NOPERM);
}
$_categoryob = $canEditCategoryobArray[$_entryob->getVar('columnID')];
//checkbox not post when value is false
if (XOOPS_GROUP_ADMIN !== $thisgrouptype) {
$_entryob->setVar('html', 0);
$_entryob->setVar('smiley', 1);
$_entryob->setVar('xcodes', 1);
$_entryob->setVar('breaks', 1);
}
if (\Xmf\Request::hasVar('weight', 'POST')) {
$_entryob->setVar('weight', \Xmf\Request::getInt('weight', 0, 'POST'));
}
if (\Xmf\Request::hasVar('commentable', 'POST')) {
$_entryob->setVar('commentable', \Xmf\Request::getInt('commentable', 0, 'POST'));
}
if (\Xmf\Request::hasVar('offline', 'POST')) {
$_entryob->setVar('offline', \Xmf\Request::getInt('offline', 0, 'POST'));
}
if (\Xmf\Request::hasVar('block', 'POST')) {
$_entryob->setVar('block', \Xmf\Request::getInt('block', 0, 'POST'));
}
if (\Xmf\Request::hasVar('notifypub', 'POST')) {
$_entryob->setVar('notifypub', \Xmf\Request::getInt('notifypub', 0, 'POST'));
}
//datesub
$datesubnochage = \Xmf\Request::getInt('datesubnochage', 0, 'POST');
$datesub_date_sl = isset($_POST['datesub']) ? (int)strtotime($_POST['datesub']['date']) : 0;
$datesub_time_sl = \Xmf\Request::getInt('datesub', 0, 'POST');
$datesub = isset($_POST['datesub']) ? $datesub_date_sl + $datesub_time_sl : 0;
if (!$datesub || $_entryob->_isNew) {
$_entryob->setVar('datesub', time());
} else {
if (!$datesubnochage) {
$_entryob->setVar('datesub', $datesub);
}
}
if (\Xmf\Request::hasVar('headline', 'POST')) {
$_entryob->setVar('headline', $_POST['headline']);
}
if (\Xmf\Request::hasVar('lead', 'POST')) {
$_entryob->setVar('lead', $_POST['lead']);
}
if (\Xmf\Request::hasVar('bodytext', 'POST')) {
$_entryob->setVar('bodytext', $_POST['bodytext']);
}
if (\Xmf\Request::hasVar('artimage', 'POST')) {
$_entryob->setVar('artimage', $_POST['artimage']);
}
//autoapprove
if (XOOPS_GROUP_ANONYMOUS === $thisgrouptype || 1 !== $helper->getConfig('autoapprove')) {
$_entryob->setVar('submit', 1);
$_entryob->setVar('offline', 1);
} else {
$_entryob->setVar('submit', 0);
if (\Xmf\Request::hasVar('submit', 'POST')) {
$_entryob->setVar('submit', \Xmf\Request::getInt('submit', 0, 'POST'));
}
$_entryob->setVar('offline', 0);
}
if (\Xmf\Request::hasVar('teaser', 'POST')) {
$_entryob->setVar('teaser', $_POST['teaser']);
}
$autoteaser = \Xmf\Request::getInt('autoteaser', 0, 'POST');
$charlength = \Xmf\Request::getInt('teaseramount', 0, 'POST');
if ($autoteaser && $charlength) {
$_entryob->setVar('teaser', xoops_substr($_entryob->getVar('bodytext', 'none'), 0, $charlength));
}
// Save to database
if (!$entrydataHandler->insertArticle($_entryob)) {
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/index.php', 2, _MD_SOAPBOX_ERRORSAVINGDB);
break;
}
if (XOOPS_GROUP_ANONYMOUS === $thisgrouptype || 1 !== $helper->getConfig('autoapprove')) {
// Notify of to admin only for approve
$entrydataHandler->newArticleTriggerEvent($_entryob, 'article_submit');
} else {
// Notify of to admin only for new_article
$entrydataHandler->newArticleTriggerEvent($_entryob, 'new_article');
}
if ($_entryob->getVar('submit')) {
redirect_header('index.php', 2, _MD_SOAPBOX_RECEIVED);
} else {
redirect_header('index.php', 2, _MD_SOAPBOX_RECEIVEDANDAPPROVED);
}
exit();
break;
case 'form':
case 'edit':
default:
$name = $xoopsUser->getVar('uname');
//-------------------------
if (!empty($articleID)) {
//articleID check
$_entryob = $entrydataHandler->getArticleOnePermcheck($articleID, true, true);
if (!is_object($_entryob)) {
redirect_header('index.php', 1, _NOPERM);
}
//get category object check
//get category object
if (!isset($canEditCategoryobArray[$_entryob->getVar('columnID')])) {
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/index.php', 2, _MD_SOAPBOX_ERRORSAVINGDB);
}
$_categoryob = $canEditCategoryobArray[$_entryob->getVar('columnID')];
} else {
// there's no parameter, so we're adding an entry
$_entryob = $entrydataHandler->createArticle(true);
// $_entryob->cleanVars();
}
//get vars mode E
$entry_vars = $_entryob->getVars();
foreach ($entry_vars as $k => $v) {
$e_articles[$k] = $_entryob->getVar($k, 'E');
}
$module_img_dir = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/assets/images/icon/';
echo "<div id='moduleName'><img src='"
. $module_img_dir
. "open.png' width='36' height='24'> "
. $xoopsModule->name()
. " <img src='"
. $module_img_dir
. "close.png' width='36' height='24'></div><div id='pagePath'><a href='"
. XOOPS_URL
. "'>"
. _MD_SOAPBOX_HOME
. "</a> • <a href='"
. XOOPS_URL
. '/modules/'
. $xoopsModule->dirname()
. "/'>"
. $xoopsModule->name()
. '</a> • '
. _MD_SOAPBOX_SUBMITART
. '</div>';
echo "<div style='margin: 8px 0; line-height: 160%; width: 100%;'>" . _MD_SOAPBOX_GOODDAY . '<b>' . $name . '</b>, ' . _MD_SOAPBOX_SUB_SNEWNAMEDESC . '</div>';
require_once __DIR__ . '/include/storyform.inc.php';
//$xoopsTpl->assign("xoops_module_header", '<link rel="stylesheet" type="text/css" href="style.css">');
$xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/assets/css/style.css">');
require XOOPS_ROOT_PATH . '/footer.php';
break;
}