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

request.php (5 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
 * Module: Lexikon - glossary module
4
 * Author: hsalazar
5
 * Licence: GNU
6
 */
7
8
include __DIR__ . '/header.php';
9
10
global $xoTheme, $xoopsUser, $xoopsModuleConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
11
12
// permissions
13
$gpermHandler = xoops_getHandler('groupperm');
14
$groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
15
$module_id    = $xoopsModule->getVar('mid');
16
$perm_itemid  = isset($_POST['categoryID']) ? (int)$_POST['categoryID'] : 0;
17
if (!$gpermHandler->checkRight('lexikon_request', $perm_itemid, $groups, $module_id)) {
18
    redirect_header('javascript:history.go(-1)', 3, _ERRORS);
19
}
20
if (empty($_POST['submit'])) {
21
    $GLOBALS['xoopsOption']['template_main'] = 'lx_request.tpl';
22
    include XOOPS_ROOT_PATH . '/header.php';
23
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
24
    $username_v = !empty($xoopsUser) ? $xoopsUser->getVar('uname', 'E') : '';
25
    $usermail_v = !empty($xoopsUser) ? $xoopsUser->getVar('email', 'E') : '';
26
    $notifypub  = '1';
27
    include __DIR__ . '/include/requestform.php';
28
    $xoopsTpl->assign('modulename', $xoopsModule->dirname());
29
30
    $rform->assign($xoopsTpl);
31
32
    $xoopsTpl->assign('lang_modulename', $xoopsModule->name());
33
    $xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
34
35
    $xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars($xoopsModule->name()) . ' - ' . _MD_LEXIKON_ASKFORDEF);
36
    $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css" />');
37
    // Meta data
38
    $meta_description = _MD_LEXIKON_ASKFORDEF . ' - ' . $myts->htmlSpecialChars($xoopsModule->name());
39
    if (isset($xoTheme) && is_object($xoTheme)) {
40
        $xoTheme->addMeta('meta', 'description', $meta_description);
41
    } else {
42
        $xoopsTpl->assign('xoops_meta_description', $meta_description);
43
    }
44
    include XOOPS_ROOT_PATH . '/footer.php';
45
} else {
46
    extract($_POST);
47
48
    $display   = 'D';
49
    $myts      = MyTextSanitizer::getInstance();
50
    $usermail  = isset($_POST['usermail']) ? $myts->stripSlashesGPC($_POST['usermail']) : '';
51
    $username  = isset($_POST['username']) ? $myts->stripSlashesGPC($_POST['username']) : '';
52
    $reqterm   = isset($_POST['reqterm']) ? $myts->htmlSpecialChars($_POST['reqterm']) : '';
53
    $notifypub = isset($_POST['notifypub']) ? (int)$_POST['notifypub'] : 1;
54
    $html      = isset($_POST['html']) ? (int)$_POST['html'] : 1;
55
    $smiley    = isset($_POST['smiley']) ? (int)$_POST['smiley'] : 1;
56
    $xcodes    = isset($_POST['xcodes']) ? (int)$_POST['xcodes'] : 1;
57
    if ($xoopsUser) {
58
        $user = $xoopsUser->getVar('uid');
59
    } else {
60
        $user = _MD_LEXIKON_ANONYMOUS;
61
    }
62
    $submit  = 1;
63
    $date    = time();
64
    $offline = 1;
65
    $request = 1;
66
    $ref     = '';
67
    $url     = '';
68
    $init    = substr($reqterm, 0, 1);
69
70
    $xoopsDB->query('INSERT INTO '
71
                    . $xoopsDB->prefix('lxentries')
72
                    . " (entryID, term, init, ref, url, uid, submit, datesub, html, smiley, xcodes, offline, notifypub, request ) VALUES ('', '$reqterm', '$init', '$ref', '$url', '$user', '$submit', '$date', '$html', '$smiley', '$xcodes', '$offline', '$notifypub', '$request' )");
73
    $newid = $xoopsDB->getInsertId();
74
    // Increment author's posts count
75 View Code Duplication
    if (is_object($xoopsUser) && !empty($user)) {
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...
76
        $memberHandler = xoops_getHandler('member');
77
        $submitter     = $memberHandler->getUser($user);
78
        if (is_object($submitter)) {
79
            $submitter->setVar('posts', $submitter->getVar('posts') + 1);
80
            $res = $memberHandler->insertUser($submitter, true);
81
            unset($submitter);
82
        }
83
    }
84
    // trigger Notification
85
    if (!empty($xoopsModuleConfig['notification_enabled'])) {
86
        global $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
87
        if ($newid == 0) {
88
            $newid = $xoopsDB->getInsertId();
89
        }
90
        $notificationHandler = xoops_getHandler('notification');
91
        $tags                = [];
92
        $tags['ITEM_NAME']   = $reqterm;
93
        $tags['DATESUB']     = formatTimestamp($date, 'd M Y');
94
        $tags['ITEM_URL']    = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/submit.php?suggest=' . $newid;
95
        $notificationHandler->triggerEvent('global', 0, 'term_request', $tags);
96
    }
97
    $adminmail = $xoopsConfig['adminmail'];
98
99
    if ($xoopsUser) {
100
        $logname = $xoopsUser->getVar('uname', 'E');
101
    } else {
102
        $logname = $xoopsConfig['anonymous'];
103
    }
104
105 View Code Duplication
    if ($xoopsUser) {
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...
106
        $result = $xoopsDB->query('select email from ' . $xoopsDB->prefix('users') . " where uname='$logname'");
107
        list($address) = $xoopsDB->fetchRow($result);
108
    } else {
109
        $address = $xoopsConfig['adminmail'];
110
    }
111
112
    if ($xoopsModuleConfig['mailtoadmin'] == 1) {
113
        $adminMessage = sprintf(_MD_LEXIKON_WHOASKED, $logname);
114
        $adminMessage .= '' . $reqterm . "\n";
115
        $adminMessage .= '' . _MD_LEXIKON_EMAILLEFT . " $address\n";
116
        $adminMessage .= "\n";
117
        if ($notifypub == '1') {
118
            $adminMessage .= _MD_LEXIKON_NOTIFYONPUB;
119
        }
120
        $adminMessage .= "\n" . $_SERVER['HTTP_USER_AGENT'] . "\n";
121
        $subject      = $xoopsConfig['sitename'] . ' - ' . _MD_LEXIKON_DEFINITIONREQ;
122
        $xoopsMailer  = xoops_getMailer();
123
        $xoopsMailer->useMail();
124
        $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
125
        $xoopsMailer->setFromEmail($address);
126
        $xoopsMailer->setFromName($xoopsConfig['sitename']);
127
        $xoopsMailer->setSubject($subject);
128
        $xoopsMailer->setBody($adminMessage);
129
        $xoopsMailer->send();
130
    }
131
    //send 'received!' mail
132 View Code Duplication
    if ($xoopsModuleConfig['mailtosender'] == 1 && $address) {
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...
133
        $conf_subject = _MD_LEXIKON_THANKS2;
134
        $userMessage  = sprintf(_MD_LEXIKON_GOODDAY2, $logname);
135
        $userMessage  .= "\n\n";
136
        $userMessage  .= sprintf(_MD_LEXIKON_THANKYOU, $xoopsConfig['sitename']);
137
        $userMessage  .= "\n";
138
        $userMessage  .= sprintf(_MD_LEXIKON_REQUESTSENT, $xoopsConfig['sitename']);
139
        $userMessage  .= "\n";
140
        $userMessage  .= "--------------\n";
141
        $userMessage  .= '' . $xoopsConfig['sitename'] . ' ' . _MD_LEXIKON_WEBMASTER . "\n";
142
        $userMessage  .= '' . $xoopsConfig['adminmail'] . '';
143
        $xoopsMailer  = xoops_getMailer();
144
        $xoopsMailer->useMail();
145
        $xoopsMailer->setToEmails($address);
146
        $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
147
        $xoopsMailer->setFromName($xoopsConfig['sitename']);
148
        $xoopsMailer->setSubject($conf_subject);
149
        $xoopsMailer->setBody($userMessage);
150
        $xoopsMailer->send();
151
152
        $messagesent = sprintf(_MD_LEXIKON_MESSAGESENT, $xoopsConfig['sitename']) . '<br>' . _MD_LEXIKON_THANKS1 . '';
153
        $messagesent .= sprintf(_MD_LEXIKON_SENTCONFIRMMAIL, $address);
154
    } else {
155
        $messagesent = sprintf(_MD_LEXIKON_MESSAGESENT, $xoopsConfig['sitename']) . '<br>' . _MD_LEXIKON_THANKS1 . '';
156
    }
157
    redirect_header('index.php', 2, $messagesent);
158
}
159