Completed
Pull Request — master (#12)
by
unknown
01:54
created

submit.php (3 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Module: Lexikon - glossary module
4
 * Author: hsalazar
5
 * Licence: GNU
6
 */
7
8
include __DIR__ . '/header.php';
9
$GLOBALS['xoopsOption']['template_main'] = 'lx_submit.tpl';
10
include XOOPS_ROOT_PATH . '/header.php';
11
12
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
13
14
global $xoTheme, $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
15
16
$result = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('lxcategories') . '');
17 View Code Duplication
if ($xoopsDB->getRowsNum($result) == '0' && $xoopsModuleConfig['multicats'] == '1') {
18
    redirect_header('index.php', 1, _AM_LEXIKON_NOCOLEXISTS);
19
}
20
21
$op = 'form';
22
23
if (isset($_POST['post'])) {
24
    $op = trim('post');
25
} elseif (isset($_POST['edit'])) {
26
    $op = trim('edit');
27
}
28
29 View Code Duplication
if (!function_exists('mb_ucfirst') && function_exists('mb_substr')) {
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...
30
   function mb_ucfirst($string) {  
0 ignored issues
show
The function mb_ucfirst() has been defined more than once; this definition is ignored, only the first definition in index.php (L43-47) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
31
   $string = mb_ereg_replace("^[\ ]+","", $string);  
32
   $string = mb_strtoupper(mb_substr($string, 0, 1, "UTF-8"), "UTF-8").mb_substr($string, 1, mb_strlen($string), "UTF-8" );  
33
   return $string;  
34
   }  
35
}
36
37
$suggest = isset($_GET['suggest']) ? (int)((int)$_GET['suggest']) : 0;
38
39
if ($suggest > 0) {
40
    $terminosql = $xoopsDB->query('SELECT term FROM '
41
                                  . $xoopsDB->prefix('lxentries')
42
                                  . ' WHERE datesub < '
43
                                  . time()
44
                                  . " AND datesub > 0 AND request = '1' AND entryID = '"
45
                                  . $suggest
46
                                  . "'");
47
    list($termino) = $xoopsDB->fetchRow($terminosql);
48
} else {
49
    $termino = '';
50
}
51
//--- Permissions ---
52
$gpermHandler = xoops_getHandler('groupperm');
53
$groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
54
$module_id    = $xoopsModule->getVar('mid');
55
$perm_itemid  = isset($_POST['categoryID']) ? (int)$_POST['categoryID'] : 0;
56
if (!$gpermHandler->checkRight('lexikon_submit', $perm_itemid, $groups, $module_id)) {
57
    redirect_header('javascript:history.go(-1)', 3, _MD_LEXIKON_MUSTREGFIRST);
58
}
59
$totalcats    = $gpermHandler->getItemIds('lexikon_submit', $groups, $module_id);
60
$permitsubmit = count($totalcats);
61
if ($permitsubmit == 0 && $xoopsModuleConfig['multicats'] == '1') {
62
    redirect_header('index.php', 3, _NOPERM);
63
}
64
switch ($op) {
65
    case 'post':
66
        //--- Captcha
67
        if ($xoopsModuleConfig['captcha'] != 0) {
68
            xoops_load('XoopsCaptcha');
69
            if (@include_once XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php') {
70
                $xoopsCaptcha = XoopsCaptcha::getInstance();
71
                if (!$xoopsCaptcha->verify()) {
72
                    echo $xoopsCaptcha->getMessage();
73
                    redirect_header('javascript:history.go(-1)', 2, _CAPTCHA_INVALID_CODE);
74
                }
75
            }
76
        }
77
        //-------
78
79
        global $xoTheme, $xoopsUser, $xoopsModule, $xoopsModuleConfig;
80
        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/Utility.php';
81
        $myts = MyTextSanitizer:: getInstance();
82
        //permissions
83
        $gpermHandler = xoops_getHandler('groupperm');
84
        $groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
85
        $module_id    = $xoopsModule->getVar('mid');
86
        $perm_itemid  = isset($_POST['categoryID']) ? (int)$_POST['categoryID'] : 0;
87
88
        $html = 1;
89
        if ($xoopsUser) {
90
            $uid = $xoopsUser->getVar('uid');
91
            if ($xoopsUser->isAdmin($xoopsModule->mid())) {
92
                $html = empty($html) ? 0 : 1;
93
            }
94
        } else {
95
            if (!is_object($xoopsUser)
96
                && $gpermHandler->checkRight('lexikon_submit', $perm_itemid, $groups, $module_id)
97
            ) {
98
                $uid = 0;
99
            } else {
100
                redirect_header('index.php', 3, _NOPERM);
101
            }
102
        }
103
104
        $block     = isset($block) ? (int)$block : 1;
105
        $smiley    = isset($smiley) ? (int)$smiley : 1;
106
        $xcodes    = isset($xcodes) ? (int)$xcodes : 1;
107
        $breaks    = isset($breaks) ? (int)$breaks : 1;
108
        $notifypub = !empty($_POST['notifypub']) ? 1 : 0;
109
110
        if ($xoopsModuleConfig['multicats'] == 1) {
111
            $categoryID = (int)$_POST['categoryID'];
112
        } else {
113
            $categoryID = 1;
114
        }
115
        $term       = $myts->addSlashes($myts->censorString($_POST['term']));
116
        $definition = $myts->addSlashes($myts->censorString($_POST['definition']));
117
        $ref        = $myts->addSlashes($myts->censorString($_POST['ref']));
118
        $url        = $myts->addSlashes($_POST['url']);
119
        if (empty($url)) {
120
            $url = '';
121
        }
122
        // this is for terms with umlaut or accented initials
123
        $term4sql = LexikonUtility::sanitizeFieldName($myts->htmlspecialchars($_POST['term']));
124
        $init     = mb_substr($term4sql, 0, 1);
125
        $init     = preg_match('/[a-zA-Zа-яА-Я0-9]/', $init) ? mb_strtoupper($init) : '#';
126
        
127
        $datesub = time();
128
129
        $submit      = 1;
130
        $offline     = 1;
131
        $request     = 0;
132
        $block       = 1;
133
        $autoapprove = 0;
134
135
        if ($gpermHandler->checkRight('lexikon_approve', $perm_itemid, $groups, $module_id)) {
136
            $submit      = 0;
137
            $offline     = 0;
138
            $autoapprove = 1;
139
        }
140
        // verify that the term not exists
141 View Code Duplication
        if (LexikonUtility::isTermPresent($term, $xoopsDB->prefix('lxentries'))) {
142
            redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_ITEMEXISTS . '<br>' . $term);
143
        }
144
        $result = $xoopsDB->query('INSERT INTO '
145
                                  . $xoopsDB->prefix('lxentries')
146
                                  . " (entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub ) VALUES ('', '$categoryID', '$term', '$init', '$definition', '$ref', '$url', '$uid', '$submit', '$datesub', '$html', '$smiley', '$xcodes', '$breaks','$block', '$offline', '$notifypub')");
147
        $newid  = $xoopsDB->getInsertId();
148
        // Increment author's posts count
149 View Code Duplication
        if (is_object($xoopsUser) && empty($entryID) && $autoapprove) {
150
            $memberHandler = xoops_getHandler('member');
151
            $submitter     = $memberHandler->getUser($uid);
152
            if (is_object($submitter)) {
153
                $submitter->setVar('posts', $submitter->getVar('posts') + 1);
154
                $res = $memberHandler->insertUser($submitter, true);
155
                unset($submitter);
156
            }
157
        }
158
        // trigger Notification
159
        if (!empty($xoopsModuleConfig['notification_enabled'])) {
160
            global $xoopsModule;
161
            if ($newid == 0) {
162
                $newid = $xoopsDB->getInsertId();
163
            }
164
            $notificationHandler   = xoops_getHandler('notification');
165
            $tags                  = [];
166
            $shortdefinition       = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 45));
167
            $tags['ITEM_NAME']     = $term;
168
            $tags['ITEM_BODY']     = $shortdefinition;
169
            $tags['DATESUB']       = formatTimestamp($datesub, 'd M Y');
170
            $tags['ITEM_URL']      = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/entry.php?op=mod&entryID=' . $newid;
171
            $sql                   = 'SELECT name FROM '
172
                                      . $xoopsDB->prefix('lxcategories')
173
                                      . ' WHERE categoryID='
174
                                      . $categoryID;
175
            $result                = $xoopsDB->query($sql);
176
            $row                   = $xoopsDB->fetchArray($result);
177
            $tags['CATEGORY_NAME'] = $row['name'];
178
            $tags['CATEGORY_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID;
179
            if ($xoopsModuleConfig['autoapprove'] == 1) {
180
                $notificationHandler->triggerEvent('category', $categoryID, 'new_post', $tags);
181
                $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
182
                //sample: $notificationHandler->triggerEvent($category, $item_id, $events, $tags, $user_list=array(), $module_id=null, $omit_user_id=null)
183
            } else {
184
                $notificationHandler->triggerEvent('global', 0, 'term_submit', $tags);
185
                $notificationHandler->triggerEvent('category', 0, 'term_submit', $tags);
186
                if ($notifypub) {
187
                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
188
                    $notificationHandler->subscribe('term', $newid, 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
189
                }
190
            }
191
        }
192
        if ($result) {
193
            if (!is_object($xoopsUser)) {
194
                $username = _MD_LEXIKON_GUEST;
195
                $usermail = '';
196 View Code Duplication
            } else {
197
                $username = $xoopsUser->getVar('uname', 'E');
198
                $result   = $xoopsDB->query('select email from ' . $xoopsDB->prefix('users') . " WHERE uname='$username'");
199
                list($usermail) = $xoopsDB->fetchRow($result);
200
            }
201
202
            if ($xoopsModuleConfig['mailtoadmin'] == 1) {
203
                $adminMessage = sprintf(_MD_LEXIKON_WHOSUBMITTED, $username);
204
                $adminMessage .= '<b>' . $term . "</b>\n";
205
                $adminMessage .= '' . _MD_LEXIKON_EMAILLEFT . " $usermail\n";
206
                $adminMessage .= "\n";
207
                if ($notifypub == '1') {
208
                    $adminMessage .= _MD_LEXIKON_NOTIFYONPUB;
209
                }
210
                $adminMessage .= "\n" . $_SERVER['HTTP_USER_AGENT'] . "\n";
211
                $subject      = $xoopsConfig['sitename'] . ' - ' . _MD_LEXIKON_DEFINITIONSUB;
212
                $xoopsMailer  = xoops_getMailer();
213
                $xoopsMailer->useMail();
214
                $xoopsMailer->multimailer->isHTML(true);
215
                $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
216
                $xoopsMailer->setFromEmail($usermail);
217
                $xoopsMailer->setFromName($xoopsConfig['sitename']);
218
                $xoopsMailer->setSubject($subject);
219
                $xoopsMailer->setBody($adminMessage);
220
                $xoopsMailer->send();
221
                $messagesent = sprintf(_MD_LEXIKON_MESSAGESENT, $xoopsConfig['sitename']) . '<br>' . _MD_LEXIKON_THANKS1 . '';
222
            }
223
224
            //if ($xoopsModuleConfig['autoapprove'] == 1) {
225
            if ($autoapprove == 1) {
226
                redirect_header('index.php', 2, _MD_LEXIKON_RECEIVEDANDAPPROVED);
227 View Code Duplication
            } else {
228
                //send received mail
229
                if ($xoopsModuleConfig['mailtosender'] == 1 && $usermail) {
230
                    $conf_subject = _MD_LEXIKON_THANKS3;
231
                    $userMessage  = sprintf(_MD_LEXIKON_GOODDAY2, $username);
232
                    $userMessage  .= "\n\n";
233
                    $userMessage  .= sprintf(_MD_LEXIKON_THANKYOU3, $xoopsConfig['sitename']);
234
                    $userMessage  .= "\n";
235
                    $userMessage  .= sprintf(_MD_LEXIKON_SUBMISSIONSENT, $xoopsConfig['sitename']);
236
                    $userMessage  .= "\n";
237
                    $userMessage  .= "--------------\n";
238
                    $userMessage  .= '' . $xoopsConfig['sitename'] . ' ' . _MD_LEXIKON_WEBMASTER . "\n";
239
                    $userMessage  .= '' . $xoopsConfig['adminmail'] . '';
240
241
                    $xoopsMailer = xoops_getMailer();
242
                    $xoopsMailer->useMail();
243
                    $xoopsMailer->multimailer->isHTML(true);
244
                    $xoopsMailer->setToEmails($usermail);
245
                    $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
246
                    $xoopsMailer->setFromName($xoopsConfig['sitename']);
247
                    $xoopsMailer->setSubject($conf_subject);
248
                    $xoopsMailer->setBody($userMessage);
249
                    $xoopsMailer->send();
250
                    $messagesent = _MD_LEXIKON_RECEIVED . '<br>' . _MD_LEXIKON_THANKS1 . '';
251
                    $messagesent .= sprintf(_MD_LEXIKON_SENTCONFIRMMAIL, $usermail);
252
                } else {
253
                    $messagesent = sprintf(_MD_LEXIKON_RECEIVED) . '<br>' . _MD_LEXIKON_THANKS1 . '';
254
                }
255
                redirect_header('index.php', 2, $messagesent);
256
            }
257
        } else {
258
            redirect_header('submit.php', 2, _MD_LEXIKON_ERRORSAVINGDB);
259
        }
260
        exit();
261
        break;
262
263
    case 'form':
264
    default:
265
        global $xoopsUser, $_SERVER;
266
        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/class/Utility.php';// to create pagetitle
267
        $myts = MyTextSanitizer:: getInstance();
268
        if (!is_object($xoopsUser)) {
269
            $name = _MD_LEXIKON_GUEST;
270
        } else {
271
            $name = ucfirst($xoopsUser->getVar('uname'));
272
        }
273
274
        $xoopsTpl->assign('send_def_to', sprintf(_MD_LEXIKON_SUB_SNEWNAME, ucfirst($xoopsModule->name())));
275
        $xoopsTpl->assign('send_def_g', sprintf(_MD_LEXIKON_SUB_SNEWNAME, ucfirst($xoopsModule->name())));
276
        $xoopsTpl->assign('lx_user_name', $name);
277
278
        $block      = 1;
279
        $html       = 1;
280
        $smiley     = 1;
281
        $xcodes     = 1;
282
        $breaks     = 1;
283
        $categoryID = 0;
284
        $notifypub  = 1;
285
        $term       = $termino;
286
        $definition = '';
287
        $ref        = '';
288
        $url        = '';
289
290
        include_once __DIR__ . '/include/storyform.inc.php';
291
292
        $xoopsTpl->assign('modulename', $xoopsModule->dirname());
293
294
        $sform->assign($xoopsTpl);
295
296
        $xoopsTpl->assign('lang_modulename', $xoopsModule->name());
297
        $xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
298
        $xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars($xoopsModule->name()) . ' - ' . _MD_LEXIKON_SUBMITART);
299
        $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css" />');
300
        // Meta data
301
        $meta_description = _MD_LEXIKON_SUBMITART . ' - ' . $myts->htmlSpecialChars($xoopsModule->name());
302
        if (isset($xoTheme) && is_object($xoTheme)) {
303
            $xoTheme->addMeta('meta', 'description', $meta_description);
304
        } else {
305
            $xoopsTpl->assign('xoops_meta_description', $meta_description);
306
  }
307
308
        include XOOPS_ROOT_PATH . '/footer.php';
309
        break;
310
}
311