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 | require __DIR__ . '/../../mainfile.php'; |
||
26 | if (!is_object($GLOBALS['xoopsUser']) && 1 != $GLOBALS['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"); |
||
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 = Xmf\Request::getString('confirm_code', '', 'POST'); |
||
38 | $confirm_str = Xmf\Request::getString('confirm_str', '', 'POST'); |
||
39 | $user_id = Xmf\Request::getInt('user_id', 0, 'POST'); |
||
40 | $title = Xmf\Request::getString('title', '', 'POST'); |
||
41 | $message = Xmf\Request::getString('message', '', 'POST'); |
||
42 | $gender = Xmf\Request::getString('gender', '', 'POST'); |
||
43 | $preview_name = Xmf\Request::getString('preview_name', '', 'POST'); |
||
44 | $email = Xmf\Request::getEmail('email', '', 'POST'); |
||
45 | $name = Xmf\Request::getString('name', '', 'POST'); |
||
46 | $url = Xmf\Request::getUrl('url', '', 'POST'); |
||
47 | $country = Xmf\Request::getString('country', '', 'POST'); |
||
48 | /* |
||
0 ignored issues
–
show
|
|||
49 | $confirm_code = isset($_POST['confirm_code']) ? $_POST['confirm_code'] : ''; |
||
50 | $confirm_str = isset($_POST['confirm_str']) ? $_POST['confirm_str'] : ''; |
||
51 | $user_id = isset($_POST['user_id']) ? (int)$_POST['user_id'] : 0; |
||
52 | $title = (isset($_POST['title']) ? $_POST['title'] : ''); |
||
53 | $message = (isset($_POST['message']) ? $_POST['message'] : ''); |
||
54 | $gender = (isset($_POST['gender']) ? $_POST['gender'] : ''); |
||
55 | $preview_name = (isset($_POST['preview_name']) ? $_POST['preview_name'] : ''); |
||
56 | $email = (isset($_POST['email']) ? $_POST['email'] : ''); |
||
57 | $name = (isset($_POST['name']) ? $_POST['name'] : ''); |
||
58 | $url = (isset($_POST['url']) ? $_POST['url'] : ''); |
||
59 | $country = (isset($_POST['country']) ? $_POST['country'] : ''); |
||
60 | */ |
||
61 | $op = Xmf\Request::getCmd('preview', null, 'POST'); |
||
62 | $op = Xmf\Request::getCmd('post', $op, 'POST'); |
||
63 | $op = (null === $op) ? 'form' : $op; |
||
64 | /* |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% 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. ![]() |
|||
65 | if (isset($_POST['preview'])) { |
||
66 | $op = 'preview'; |
||
67 | } elseif (isset($_POST['post'])) { |
||
68 | $op = 'post'; |
||
69 | } else { |
||
70 | $op = 'form'; |
||
71 | } |
||
72 | */ |
||
73 | $badip = in_array($_SERVER['REMOTE_ADDR'], XfguestbookUtil::get_badips()) ? true : false; |
||
74 | |||
75 | switch ($op) { |
||
76 | View Code Duplication | case 'cancel': |
|
77 | $photos_dir = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname'); |
||
78 | $nb_removed_tmp = XfguestbookUtil::clear_tmp_files($photos_dir); |
||
79 | redirect_header('index.php', 0); |
||
80 | break; |
||
81 | |||
82 | case 'preview': |
||
83 | $ts = MyTextSanitizer::getInstance(); |
||
84 | $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_signform.tpl'; |
||
85 | include XOOPS_ROOT_PATH . '/header.php'; |
||
86 | $msgstop = ''; |
||
87 | |||
88 | /*if ($option['opt_code']==1) { |
||
89 | xoops_load('XoopsCaptcha'); |
||
90 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
91 | if (!$xoopsCaptcha->verify()) { |
||
92 | $msgstop .= $xoopsCaptcha->getMessage(); |
||
93 | } |
||
94 | }*/ |
||
95 | View Code Duplication | if (2 == $option['opt_url'] && preg_match('/(http)|(www)/i', $message)) { |
|
96 | $msgstop .= MD_XFGUESTBOOK_URL_DISABLED . '<br>'; |
||
97 | } |
||
98 | |||
99 | if ('' !== $email && !checkEmail($email)) { |
||
100 | $msgstop .= MD_XFGUESTBOOK_INVALIDMAIL . '<br>'; |
||
101 | } |
||
102 | if (!empty($_FILES['photo']['name'])) { |
||
103 | XfguestbookUtil::upload(); |
||
104 | } |
||
105 | $title = $ts->htmlSpecialChars($ts->stripSlashesGPC($title)); |
||
106 | $message = $ts->htmlSpecialChars($ts->stripSlashesGPC($message)); |
||
107 | if (!empty($msgstop)) { |
||
108 | $xoopsTpl->assign('preview', true); |
||
109 | $xoopsTpl->assign('msgstop', $msgstop); |
||
110 | include_once __DIR__ . '/include/form_sign.inc.php'; |
||
111 | $signform->assign($xoopsTpl); |
||
112 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
113 | exit(); |
||
114 | } |
||
115 | $msgpost['title'] = $ts->previewTarea($title); |
||
116 | $msgpost['message'] = $ts->previewTarea($message); |
||
117 | $msgpost['poster'] = $name; |
||
118 | $msgpost['user_id'] = $user_id; |
||
119 | $msgpost['date'] = formatTimestamp(time(), 's'); |
||
120 | $msgpost['photo'] = $preview_name; |
||
121 | if (1 == $option['opt_url']) { |
||
122 | $msgpost['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $msgpost['message']); |
||
123 | } |
||
124 | if ($gender) { |
||
125 | $msgpost['gender'] = '<img src="assets/images/' . $gender . '.gif"'; |
||
126 | } |
||
127 | if ($email) { |
||
128 | $msgpost['email'] = '<img src="' . XOOPS_URL . '/images/icons/email.gif" alt="' . _SENDEMAILTO . '">'; |
||
129 | } |
||
130 | if ($url) { |
||
131 | $msgpost['url'] = '<img src="' . XOOPS_URL . '/images/icons/www.gif" alt="' . _VISITWEBSITE . '">'; |
||
132 | } |
||
133 | if ($country) { |
||
134 | $flag = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $country . '.gif'; |
||
135 | $arr_country = XfguestbookUtil::getCountry("country_code ='" . $country . '\''); |
||
136 | $country_name = (count($arr_country) > 0) ? $arr_country[0]['country_name'] : ''; |
||
137 | View Code Duplication | if (file_exists($flag)) { |
|
138 | $msgpost['country'] = '<img src="' |
||
139 | . XOOPS_URL |
||
140 | . '/modules/xfguestbook/assets/images/flags/' |
||
141 | . $xoopsModuleConfig['flagdir'] |
||
142 | . '/' |
||
143 | . $country |
||
144 | . '.gif" alt="' |
||
145 | . $country_name |
||
146 | . '">'; |
||
147 | } else { |
||
148 | $msgpost['country'] = $country_name; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | $xoopsTpl->assign('preview', true); |
||
153 | $xoopsTpl->assign('msgstop', $msgstop); |
||
154 | include __DIR__ . '/include/form_sign.inc.php'; |
||
155 | $xoopsTpl->assign('msg', $msgpost); |
||
156 | $signform->assign($xoopsTpl); |
||
157 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
158 | break; |
||
159 | |||
160 | case 'post': |
||
161 | $msgstop = ''; |
||
162 | View Code Duplication | if (1 == $option['opt_code']) { |
|
163 | xoops_load('XoopsCaptcha'); |
||
164 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
165 | if (!$xoopsCaptcha->verify()) { |
||
166 | $msgstop .= $xoopsCaptcha->getMessage() . '<br><br>'; |
||
167 | } |
||
168 | include XOOPS_ROOT_PATH . '/header.php'; |
||
169 | } |
||
170 | if ('' == $_POST['uman']) { |
||
171 | redirect_header('index.php', 2, ''); |
||
172 | } |
||
173 | View Code Duplication | if (2 == $option['opt_url'] && preg_match('/(http[s])|(www)/i', $message)) { |
|
174 | $msgstop .= MD_XFGUESTBOOK_URL_DISABLED . '<br><br>'; |
||
175 | } |
||
176 | if (!XfguestbookUtil::email_exist($email)) { |
||
177 | $msgstop .= MD_XFGUESTBOOK_INVALIDMAIL . '<br><br>'; |
||
178 | } |
||
179 | if ('' !== $email && !checkEmail($email)) { |
||
180 | $msgstop .= MD_XFGUESTBOOK_INVALIDMAIL . '<br><br>'; |
||
181 | } |
||
182 | if (!empty($_FILES['photo']['name'])) { |
||
183 | XfguestbookUtil::upload(); |
||
184 | } |
||
185 | if (!empty($msgstop)) { |
||
186 | $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_signform.tpl'; |
||
187 | include XOOPS_ROOT_PATH . '/header.php'; |
||
188 | $xoopsTpl->assign('preview', true); |
||
189 | $xoopsTpl->assign('msgstop', $msgstop); |
||
190 | include_once __DIR__ . '/include/form_sign.inc.php'; |
||
191 | $signform->assign($xoopsTpl); |
||
192 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
193 | exit(); |
||
194 | } |
||
195 | $photos_dir = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname'); |
||
196 | if ('' !== $preview_name) { |
||
197 | $photo = str_replace('tmp_', 'msg_', $preview_name); |
||
198 | rename("$photos_dir/$preview_name", "$photos_dir/$photo"); |
||
199 | } |
||
200 | |||
201 | $msgpost = $msgHandler->create(); |
||
202 | $xoopsUser ? $user_id = $xoopsUser->uid() : $user_id = 0; |
||
203 | $xoopsUser ? $username = $xoopsUser->uname() : $username = $name; |
||
204 | $msgpost->setVar('user_id', $user_id); |
||
205 | $msgpost->setVar('uname', $username); |
||
206 | $msgpost->setVar('title', $title); |
||
207 | $msgpost->setVar('message', $message); |
||
208 | $msgpost->setVar('note', ''); |
||
209 | $msgpost->setVar('post_time', time()); |
||
210 | $msgpost->setVar('email', $email); |
||
211 | $msgpost->setVar('url', $url); |
||
212 | $msgpost->setVar('poster_ip', $_SERVER['REMOTE_ADDR']); |
||
213 | $msgpost->setVar('country', $country); |
||
214 | $msgpost->setVar('flagdir', $xoopsModuleConfig['flagdir']); |
||
215 | $msgpost->setVar('gender', $gender); |
||
216 | if (!isset($photo)) { |
||
217 | $photo = ''; |
||
218 | } |
||
219 | $msgpost->setVar('photo', $photo); |
||
220 | |||
221 | if ($badip) { |
||
222 | $msgpost->setVar('moderate', 1); |
||
223 | } else { |
||
224 | $msgpost->setVar('moderate', $xoopsModuleConfig['moderate']); |
||
225 | } |
||
226 | $nb_removed_tmp = XfguestbookUtil::clear_tmp_files($photos_dir); |
||
227 | $messagesent = MD_XFGUESTBOOK_MESSAGESENT; |
||
228 | |||
229 | if ($msgHandler->insert($msgpost)) { |
||
230 | if ($badip || $xoopsModuleConfig['moderate']) { |
||
231 | $messagesent .= '<br>' . MD_XFGUESTBOOK_AFTERMODERATE; |
||
232 | } |
||
233 | |||
234 | // Send mail to webmaster |
||
235 | if (1 == $xoopsModuleConfig['sendmail2wm']) { |
||
236 | $subject = $xoopsConfig['sitename'] . ' - ' . MD_XFGUESTBOOK_NAMEMODULE; |
||
237 | $xoopsMailer = xoops_getMailer(); |
||
238 | $xoopsMailer->useMail(); |
||
239 | $xoopsMailer->setToEmails($xoopsConfig['adminmail']); |
||
240 | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
241 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
242 | $xoopsMailer->setSubject($subject); |
||
243 | $xoopsMailer->setBody(MD_XFGUESTBOOK_NEWMESSAGE . ' ' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/'); |
||
244 | if (!$xoopsMailer->send()) { |
||
245 | echo $xoopsMailer->getErrors(); |
||
246 | } |
||
247 | } |
||
248 | redirect_header('index.php', 2, $messagesent); |
||
249 | } else { |
||
250 | $messagesent = $msgpost->getHtmlErrors(); |
||
251 | redirect_header('index.php', 2, $messagesent); |
||
252 | } |
||
253 | break; |
||
254 | |||
255 | case 'form': |
||
256 | default: |
||
257 | $xoopsOption['template_main'] = 'xfguestbook_signform.tpl'; |
||
258 | |||
259 | include XOOPS_ROOT_PATH . '/header.php'; |
||
260 | $user_id = !empty($xoopsUser) ? $xoopsUser->getVar('uid', 'E') : 0; |
||
261 | $name = !empty($xoopsUser) ? $xoopsUser->getVar('uname', 'E') : ''; |
||
262 | $email = !empty($xoopsUser) ? $xoopsUser->getVar('email', 'E') : ''; |
||
263 | $url = !empty($xoopsUser) ? $xoopsUser->getVar('url', 'E') : ''; |
||
264 | $country = $option['countrybydefault']; |
||
265 | |||
266 | if (1 == $option['opt_code']) { |
||
267 | xoops_load('XoopsCaptcha'); |
||
268 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
269 | } |
||
270 | if ($badip || $xoopsModuleConfig['moderate']) { |
||
271 | $xoopsTpl->assign('moderate', MD_XFGUESTBOOK_MODERATED); |
||
272 | } |
||
273 | |||
274 | include __DIR__ . '/include/form_sign.inc.php'; |
||
275 | $signform->assign($xoopsTpl); |
||
276 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
277 | break; |
||
278 | } |
||
279 |
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.