Completed
Pull Request — master (#10)
by Michael
02:01
created

xfcreate.php (14 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
//             XF Guestbook                                                  //
4
// ------------------------------------------------------------------------- //
5
//  This program is free software; you can redistribute it and/or modify     //
6
//  it under the terms of the GNU General Public License as published by     //
7
//  the Free Software Foundation; either version 2 of the License, or        //
8
//  (at your option) any later version.                                      //
9
//                                                                           //
10
//  You may not change or alter any portion of this comment or credits       //
11
//  of supporting developers from this source code or any supporting         //
12
//  source code which is considered copyrighted (c) material of the          //
13
//  original comment or credit authors.                                      //
14
//                                                                           //
15
//  This program is distributed in the hope that it will be useful,          //
16
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
17
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
18
//  GNU General Public License for more details.                             //
19
//                                                                           //
20
//  You should have received a copy of the GNU General Public License        //
21
//  along with this program; if not, write to the Free Software              //
22
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
23
//  ------------------------------------------------------------------------ //
24
25
include __DIR__ . '/../../mainfile.php';
26
if (!is_object($xoopsUser) && 1 != $xoopsModuleConfig['anonsign']) {
27
    redirect_header(XOOPS_URL . '/user.php', 2, MD_XFGUESTBOOK_MUSTREGFIRST);
28
}
29
30
//include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/msg.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/class/util.php';
32
include_once __DIR__ . '/include/config.inc.php';
33
34
$option     = getOptions();
35
$msgHandler = xoops_getModuleHandler('msg');
36
37
$confirm_code = isset($_POST['confirm_code']) ? $_POST['confirm_code'] : '';
38
$confirm_str  = isset($_POST['confirm_str']) ? $_POST['confirm_str'] : '';
39
$user_id      = isset($_POST['user_id']) ? (int)$_POST['user_id'] : 0;
40
$title        = (isset($_POST['title']) ? $_POST['title'] : '');
41
$message      = (isset($_POST['message']) ? $_POST['message'] : '');
42
$gender       = (isset($_POST['gender']) ? $_POST['gender'] : '');
43
$preview_name = (isset($_POST['preview_name']) ? $_POST['preview_name'] : '');
44
$email        = (isset($_POST['email']) ? $_POST['email'] : '');
45
$name         = (isset($_POST['name']) ? $_POST['name'] : '');
46
$url          = (isset($_POST['url']) ? $_POST['url'] : '');
47
$country      = (isset($_POST['country']) ? $_POST['country'] : '');
48
49 View Code Duplication
if (isset($_POST['preview'])) {
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...
50
    $op = 'preview';
51
} elseif (isset($_POST['post'])) {
52
    $op = 'post';
53
} else {
54
    $op = 'form';
55
}
56
57
$badip = in_array($_SERVER['REMOTE_ADDR'], XfguestbookUtil::get_badips()) ? true : false;
58
59
switch ($op) {
60 View Code Duplication
    case 'cancel':
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...
61
        $photos_dir     = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
62
        $nb_removed_tmp = XfguestbookUtil::clear_tmp_files($photos_dir);
63
        redirect_header('index.php', 0);
64
        break;
65
66
    case 'preview':
67
        $ts                                      = MyTextSanitizer::getInstance();
68
        $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_signform.tpl';
69
        include XOOPS_ROOT_PATH . '/header.php';
70
        $msgstop = '';
71
72
        /*if ($option['opt_code']==1) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
            xoops_load('XoopsCaptcha');
74
            $xoopsCaptcha = XoopsCaptcha::getInstance();
75
            if (!$xoopsCaptcha->verify()) {
76
                $msgstop .= $xoopsCaptcha->getMessage();
77
            }
78
        }*/
79 View Code Duplication
        if (2 == $option['opt_url'] && preg_match('/(http)|(www)/i', $message)) {
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...
80
            $msgstop .= MD_XFGUESTBOOK_URL_DISABLED . '<br>';
81
        }
82
83
        if ('' !== $email && !checkEmail($email)) {
84
            $msgstop .= MD_XFGUESTBOOK_INVALIDMAIL . '<br>';
85
        }
86
        if (!empty($_FILES['photo']['name'])) {
87
            XfguestbookUtil::upload();
88
        }
89
        $title   = $ts->htmlSpecialChars($ts->stripSlashesGPC($title));
90
        $message = $ts->htmlSpecialChars($ts->stripSlashesGPC($message));
91
        if (!empty($msgstop)) {
92
            $xoopsTpl->assign('preview', true);
93
            $xoopsTpl->assign('msgstop', $msgstop);
94
            include_once __DIR__ . '/include/form_sign.inc.php';
95
            $signform->assign($xoopsTpl);
96
            include XOOPS_ROOT_PATH . '/footer.php';
97
            exit();
98
        }
99
        $msgpost['title']   = $ts->previewTarea($title);
100
        $msgpost['message'] = $ts->previewTarea($message);
101
        $msgpost['poster']  = $name;
102
        $msgpost['user_id'] = $user_id;
103
        $msgpost['date']    = formatTimestamp(time(), 's');
104
        $msgpost['photo']   = $preview_name;
105
        if (1 == $option['opt_url']) {
106
            $msgpost['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $msgpost['message']);
107
        }
108
        if ($gender) {
109
            $msgpost['gender'] = '<img src="assets/images/' . $gender . '.gif"';
110
        }
111
        if ($email) {
112
            $msgpost['email'] = '<img src="' . XOOPS_URL . '/images/icons/email.gif" alt="' . _SENDEMAILTO . '" />';
113
        }
114
        if ($url) {
115
            $msgpost['url'] = '<img src="' . XOOPS_URL . '/images/icons/www.gif" alt="' . _VISITWEBSITE . '">';
116
        }
117
        if ($country) {
118
            $flag         = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $country . '.gif';
119
            $arr_country  = XfguestbookUtil::getCountry("country_code ='" . $country . '\'');
120
            $country_name = (count($arr_country) > 0) ? $arr_country[0]['country_name'] : '';
121 View Code Duplication
            if (file_exists($flag)) {
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...
122
                $msgpost['country'] = '<img src="'
123
                                      . XOOPS_URL
124
                                      . '/modules/xfguestbook/assets/images/flags/'
125
                                      . $xoopsModuleConfig['flagdir']
126
                                      . '/'
127
                                      . $country
128
                                      . '.gif" alt="'
129
                                      . $country_name
130
                                      . '">';
131
            } else {
132
                $msgpost['country'] = $country_name;
133
            }
134
        }
135
136
        $xoopsTpl->assign('preview', true);
137
        $xoopsTpl->assign('msgstop', $msgstop);
138
        include __DIR__ . '/include/form_sign.inc.php';
139
        $xoopsTpl->assign('msg', $msgpost);
140
        $signform->assign($xoopsTpl);
141
        include XOOPS_ROOT_PATH . '/footer.php';
142
        break;
143
144
    case 'post':
145
        $msgstop = '';
146 View Code Duplication
        if (1 == $option['opt_code']) {
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...
147
            xoops_load('XoopsCaptcha');
148
            $xoopsCaptcha = XoopsCaptcha::getInstance();
149
            if (!$xoopsCaptcha->verify()) {
150
                $msgstop .= $xoopsCaptcha->getMessage() . '<br><br>';
151
            }
152
            include XOOPS_ROOT_PATH . '/header.php';
153
        }
154
        if ('' == $_POST['uman']) {
155
            redirect_header('index.php', 2, '');
156
        }
157 View Code Duplication
        if (2 == $option['opt_url'] && preg_match('/(http)|(www)/i', $message)) {
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...
158
            $msgstop .= MD_XFGUESTBOOK_URL_DISABLED . '<br><br>';
159
        }
160
        if (!XfguestbookUtil::email_exist($email)) {
161
            $msgstop .= MD_XFGUESTBOOK_INVALIDMAIL . '<br><br>';
162
        }
163
        if ('' !== $email && !checkEmail($email)) {
164
            $msgstop .= MD_XFGUESTBOOK_INVALIDMAIL . '<br><br>';
165
        }
166
        if (!empty($_FILES['photo']['name'])) {
167
            XfguestbookUtil::upload();
168
        }
169
        if (!empty($msgstop)) {
170
            $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_signform.tpl';
171
            include XOOPS_ROOT_PATH . '/header.php';
172
            $xoopsTpl->assign('preview', true);
173
            $xoopsTpl->assign('msgstop', $msgstop);
174
            include_once __DIR__ . '/include/form_sign.inc.php';
175
            $signform->assign($xoopsTpl);
176
            include XOOPS_ROOT_PATH . '/footer.php';
177
            exit();
178
        }
179
        $photos_dir = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
180
        if ('' !== $preview_name) {
181
            $photo = str_replace('tmp_', 'msg_', $preview_name);
182
            rename("$photos_dir/$preview_name", "$photos_dir/$photo");
183
        }
184
185
        $msgpost = $msgHandler->create();
186
        $xoopsUser ? $user_id = $xoopsUser->uid() : $user_id = 0;
0 ignored issues
show
The method uid cannot be called on $xoopsUser (of type integer|double|string|array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
187
        $xoopsUser ? $username = $xoopsUser->uname() : $username = $name;
0 ignored issues
show
The method uname cannot be called on $xoopsUser (of type integer|double|string|array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
188
        $msgpost->setVar('user_id', $user_id);
189
        $msgpost->setVar('uname', $username);
190
        $msgpost->setVar('title', $title);
191
        $msgpost->setVar('message', $message);
192
        $msgpost->setVar('note', '');
193
        $msgpost->setVar('post_time', time());
194
        $msgpost->setVar('email', $email);
195
        $msgpost->setVar('url', $url);
196
        $msgpost->setVar('poster_ip', $_SERVER['REMOTE_ADDR']);
197
        $msgpost->setVar('country', $country);
198
        $msgpost->setVar('flagdir', $xoopsModuleConfig['flagdir']);
199
        $msgpost->setVar('gender', $gender);
200
        if (!isset($photo)) {
201
            $photo = '';
202
        }
203
        $msgpost->setVar('photo', $photo);
204
205
        if ($badip) {
206
            $msgpost->setVar('moderate', 1);
207
        } else {
208
            $msgpost->setVar('moderate', $xoopsModuleConfig['moderate']);
209
        }
210
        $nb_removed_tmp = XfguestbookUtil::clear_tmp_files($photos_dir);
211
        $messagesent    = MD_XFGUESTBOOK_MESSAGESENT;
212
213
        if ($msgHandler->insert($msgpost)) {
214
            if ($badip || $xoopsModuleConfig['moderate']) {
215
                $messagesent .= '<br>' . MD_XFGUESTBOOK_AFTERMODERATE;
216
            }
217
218
            // Send mail to webmaster
219
            if (1 == $xoopsModuleConfig['sendmail2wm']) {
220
                $subject     = $xoopsConfig['sitename'] . ' - ' . MD_XFGUESTBOOK_NAMEMODULE;
221
                $xoopsMailer =& xoops_getMailer();
222
                $xoopsMailer->useMail();
223
                $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
224
                $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
225
                $xoopsMailer->setFromName($xoopsConfig['sitename']);
226
                $xoopsMailer->setSubject($subject);
227
                $xoopsMailer->setBody(MD_XFGUESTBOOK_NEWMESSAGE . ' ' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/');
228
                if (!$xoopsMailer->send()) {
229
                    echo $xoopsMailer->getErrors();
230
                }
231
            }
232
            redirect_header('index.php', 2, $messagesent);
233
        } else {
234
            $messagesent = $msgpost->getHtmlErrors();
235
            redirect_header('index.php', 2, $messagesent);
236
        }
237
        break;
238
239
    case 'form':
240
    default:
241
        $xoopsOption['template_main'] = 'xfguestbook_signform.tpl';
242
243
        include XOOPS_ROOT_PATH . '/header.php';
244
        $user_id = !empty($xoopsUser) ? $xoopsUser->getVar('uid', 'E') : 0;
0 ignored issues
show
The method getVar cannot be called on $xoopsUser (of type integer|double|string|array|boolean|resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
245
        $name    = !empty($xoopsUser) ? $xoopsUser->getVar('uname', 'E') : '';
0 ignored issues
show
The method getVar cannot be called on $xoopsUser (of type integer|double|string|array|boolean|resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
246
        $email   = !empty($xoopsUser) ? $xoopsUser->getVar('email', 'E') : '';
0 ignored issues
show
The method getVar cannot be called on $xoopsUser (of type integer|double|string|array|boolean|resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
247
        $url     = !empty($xoopsUser) ? $xoopsUser->getVar('url', 'E') : '';
0 ignored issues
show
The method getVar cannot be called on $xoopsUser (of type integer|double|string|array|boolean|resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
248
        $country = $option['countrybydefault'];
249
250
        if (1 == $option['opt_code']) {
251
            xoops_load('XoopsCaptcha');
252
            $xoopsCaptcha = XoopsCaptcha::getInstance();
253
        }
254
        if ($badip || $xoopsModuleConfig['moderate']) {
255
            $xoopsTpl->assign('moderate', MD_XFGUESTBOOK_MODERATED);
256
        }
257
258
        include __DIR__ . '/include/form_sign.inc.php';
259
        $signform->assign($xoopsTpl);
260
        include XOOPS_ROOT_PATH . '/footer.php';
261
        break;
262
}
263