Completed
Push — master ( 76b4a1...141e43 )
by Michael
06:17 queued 02:44
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
// $Id: xfcreate.php, v 0.1 2007/12/04 C. Asswipe php team
3
//  ------------------------------------------------------------------------ //
4
//             XF Guestbook                                                  //
5
// ------------------------------------------------------------------------- //
6
//  This program is free software; you can redistribute it and/or modify     //
7
//  it under the terms of the GNU General Public License as published by     //
8
//  the Free Software Foundation; either version 2 of the License, or        //
9
//  (at your option) any later version.                                      //
10
//                                                                           //
11
//  You may not change or alter any portion of this comment or credits       //
12
//  of supporting developers from this source code or any supporting         //
13
//  source code which is considered copyrighted (c) material of the          //
14
//  original comment or credit authors.                                      //
15
//                                                                           //
16
//  This program is distributed in the hope that it will be useful,          //
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
19
//  GNU General Public License for more details.                             //
20
//                                                                           //
21
//  You should have received a copy of the GNU General Public License        //
22
//  along with this program; if not, write to the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
include dirname(dirname(__DIR__)) . '/mainfile.php';
27
if (!is_object($xoopsUser) && 1 != $xoopsModuleConfig['anonsign']) {
28
    redirect_header(XOOPS_URL . '/user.php', 2, _MD_XFGB_MUSTREGFIRST);
29
}
30
31
//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...
32
include_once(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/functions.php');
33
include_once('include/config.inc.php');
34
35
$option      = getOptions();
36
$msg_handler = xoops_getModuleHandler('msg');
37
38
$confirm_code = isset($_POST['confirm_code']) ? $_POST['confirm_code'] : '';
39
$confirm_str  = isset($_POST['confirm_str']) ? $_POST['confirm_str'] : '';
40
$user_id      = isset($_POST['user_id']) ? (int)$_POST['user_id'] : 0;
41
$title        = (isset($_POST['title']) ? $_POST['title'] : '');
42
$message      = (isset($_POST['message']) ? $_POST['message'] : '');
43
$gender       = (isset($_POST['gender']) ? $_POST['gender'] : '');
44
$preview_name = (isset($_POST['preview_name']) ? $_POST['preview_name'] : '');
45
$email        = (isset($_POST['email']) ? $_POST['email'] : '');
46
$name         = (isset($_POST['name']) ? $_POST['name'] : '');
47
$url          = (isset($_POST['url']) ? $_POST['url'] : '');
48
$country      = (isset($_POST['country']) ? $_POST['country'] : '');
49
50 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...
51
    $op = 'preview';
52
} elseif (isset($_POST['post'])) {
53
    $op = 'post';
54
} else {
55
    $op = 'form';
56
}
57
58
$badip = in_array($_SERVER['REMOTE_ADDR'], xfgb_get_badips()) ? true : false;
59
60
switch ($op) {
61 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...
62
        $photos_dir     = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
63
        $nb_removed_tmp = xfgb_clear_tmp_files($photos_dir);
64
        redirect_header('index.php', 0);
65
        break;
66
67
    case 'preview':
68
        $ts = MyTextSanitizer::getInstance();
69
        include XOOPS_ROOT_PATH . '/header.php';
70
        $xoopsOption['template_main'] = 'xfguestbook_signform.tpl';
71
        $msgstop                      = '';
72
73
        /*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...
74
            xoops_load('XoopsCaptcha');
75
            $xoopsCaptcha = XoopsCaptcha::getInstance();
76
            if (!$xoopsCaptcha->verify()) {
77
                $msgstop .= $xoopsCaptcha->getMessage();
78
            }
79
        }*/
80 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...
81
            $msgstop .= _MD_XFGB_URL_DISABLED . '<br>';
82
        }
83
84
        if ('' !== $email && !checkEmail($email)) {
85
            $msgstop .= _MD_XFGB_INVALIDMAIL . '<br>';
86
        }
87
        if (!empty($_FILES['photo']['name'])) {
88
            xfgb_upload();
89
        }
90
        $title   = $ts->htmlSpecialChars($ts->stripSlashesGPC($title));
91
        $message = $ts->htmlSpecialChars($ts->stripSlashesGPC($message));
92
        if (!empty($msgstop)) {
93
            $xoopsTpl->assign('preview', true);
94
            $xoopsTpl->assign('msgstop', $msgstop);
95
            include_once __DIR__ . '/include/form_sign.inc.php';
96
            $signform->assign($xoopsTpl);
97
            include XOOPS_ROOT_PATH . '/footer.php';
98
            exit();
99
        }
100
        $msgpost['title']   = $ts->previewTarea($title);
101
        $msgpost['message'] = $ts->previewTarea($message);
102
        $msgpost['poster']  = $name;
103
        $msgpost['user_id'] = $user_id;
104
        $msgpost['date']    = formatTimestamp(time(), 's');
105
        $msgpost['photo']   = $preview_name;
106
        if (1 == $option['opt_url']) {
107
            $msgpost['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $msgpost['message']);
108
        }
109
        if ($gender) {
110
            $msgpost['gender'] = '<img src="assets/images/' . $gender . '.gif"';
111
        }
112
        if ($email) {
113
            $msgpost['email'] = "<img src=\"" . XOOPS_URL . "/images/icons/email.gif\" alt=\"" . _SENDEMAILTO . "\" />";
114
        }
115
        if ($url) {
116
            $msgpost['url'] = '<img src="' . XOOPS_URL . '/images/icons/www.gif" alt="' . _VISITWEBSITE . '">';
117
        }
118
        if ($country) {
119
            $flag         = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $country . '.gif';
120
            $arr_country  = xfgb_getCountry("country_code ='" . $country . "'");
121
            $country_name = (count($arr_country) > 0) ? $arr_country[0]['country_name'] : '';
122 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...
123
                $msgpost['country'] =
124
                    "<img src=\"" . XOOPS_URL . '/modules/xfguestbook/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $country . ".gif\" alt=\"" . $country_name . "\">";
125
            } else {
126
                $msgpost['country'] = $country_name;
127
            }
128
        }
129
130
        $xoopsTpl->assign('preview', true);
131
        $xoopsTpl->assign('msgstop', $msgstop);
132
        include __DIR__ . '/include/form_sign.inc.php';
133
        $xoopsTpl->assign('msg', $msgpost);
134
        $signform->assign($xoopsTpl);
135
        include XOOPS_ROOT_PATH . '/footer.php';
136
        break;
137
138
    case 'post':
139
        $msgstop = '';
140 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...
141
            xoops_load('XoopsCaptcha');
142
            $xoopsCaptcha = XoopsCaptcha::getInstance();
143
            if (!$xoopsCaptcha->verify()) {
144
                $msgstop .= $xoopsCaptcha->getMessage() . '<br><br>';
145
            }
146
            include XOOPS_ROOT_PATH . '/header.php';
147
        }
148
        if ('' !== $_POST['uman']) {
149
            redirect_header('index.php', 2, '');
150
        }
151 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...
152
            $msgstop .= _MD_XFGB_URL_DISABLED . '<br><br>';
153
        }
154
        if (!email_exist($email)) {
155
            $msgstop .= _MD_XFGB_INVALIDMAIL . '<br><br>';
156
        }
157
        if ('' !== $email && !checkEmail($email)) {
158
            $msgstop .= _MD_XFGB_INVALIDMAIL . '<br><br>';
159
        }
160
        if (!empty($_FILES['photo']['name'])) {
161
            xfgb_upload();
162
        }
163
        if (!empty($msgstop)) {
164
            include XOOPS_ROOT_PATH . '/header.php';
165
            $xoopsOption['template_main'] = 'xfguestbook_signform.tpl';
166
            $xoopsTpl->assign('preview', true);
167
            $xoopsTpl->assign('msgstop', $msgstop);
168
            include_once __DIR__ . '/include/form_sign.inc.php';
169
            $signform->assign($xoopsTpl);
170
            include XOOPS_ROOT_PATH . '/footer.php';
171
            exit();
172
        }
173
        $photos_dir = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
174
        if ('' !== $preview_name) {
175
            $photo = str_replace('tmp_', 'msg_', $preview_name);
176
            rename("$photos_dir/$preview_name", "$photos_dir/$photo");
177
        }
178
179
        $msgpost = $msg_handler->create();
180
        $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...
181
        $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...
182
        $msgpost->setVar('user_id', $user_id);
183
        $msgpost->setVar('uname', $username);
184
        $msgpost->setVar('title', $title);
185
        $msgpost->setVar('message', $message);
186
        $msgpost->setVar('note', '');
187
        $msgpost->setVar('post_time', time());
188
        $msgpost->setVar('email', $email);
189
        $msgpost->setVar('url', $url);
190
        $msgpost->setVar('poster_ip', $_SERVER['REMOTE_ADDR']);
191
        $msgpost->setVar('country', $country);
192
        $msgpost->setVar('flagdir', $xoopsModuleConfig['flagdir']);
193
        $msgpost->setVar('gender', $gender);
194
        if (!isset($photo)) {
195
            $photo = '';
196
        }
197
        $msgpost->setVar('photo', $photo);
198
199
        if ($badip) {
200
            $msgpost->setVar('moderate', 1);
201
        } else {
202
            $msgpost->setVar('moderate', $xoopsModuleConfig['moderate']);
203
        }
204
        $nb_removed_tmp = xfgb_clear_tmp_files($photos_dir);
205
        $messagesent    = _MD_XFGB_MESSAGESENT;
206
207
        if ($msg_handler->insert($msgpost)) {
208
            if ($badip || $xoopsModuleConfig['moderate']) {
209
                $messagesent .= '<br>' . _MD_XFGB_AFTERMODERATE;
210
            }
211
212
            // Send mail to webmaster
213
            if (1 == $xoopsModuleConfig['sendmail2wm']) {
214
                $subject     = $xoopsConfig['sitename'] . ' - ' . _MD_XFGB_NAMEMODULE;
215
                $xoopsMailer =& xoops_getMailer();
216
                $xoopsMailer->useMail();
217
                $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
218
                $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
219
                $xoopsMailer->setFromName($xoopsConfig['sitename']);
220
                $xoopsMailer->setSubject($subject);
221
                $xoopsMailer->setBody(_MD_XFGB_NEWMESSAGE . ' ' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/');
222
                if (!$xoopsMailer->send()) {
223
                    echo $xoopsMailer->getErrors();
224
                }
225
            }
226
            redirect_header('index.php', 2, $messagesent);
227
        } else {
228
            $messagesent = $msgpost->getHtmlErrors();
229
            redirect_header('index.php', 2, $messagesent);
230
        }
231
        break;
232
233
    case 'form':
234
    default:
235
        $xoopsOption['template_main'] = 'xfguestbook_signform.tpl';
236
237
        include XOOPS_ROOT_PATH . '/header.php';
238
        $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...
239
        $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...
240
        $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...
241
        $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...
242
        $country = $option['countrybydefault'];
243
244
        if (1 == $option['opt_code']) {
245
            xoops_load('XoopsCaptcha');
246
            $xoopsCaptcha = XoopsCaptcha::getInstance();
247
        }
248
        if ($badip || $xoopsModuleConfig['moderate']) {
249
            $xoopsTpl->assign('moderate', _MD_XFGB_MODERATED);
250
        }
251
252
        include __DIR__ . '/include/form_sign.inc.php';
253
        $signform->assign($xoopsTpl);
254
        include XOOPS_ROOT_PATH . '/footer.php';
255
        break;
256
}
257