Completed
Pull Request — master (#10)
by Michael
03:18
created

index.php (2 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
//  ------------------------------------------------------------------------ //
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 metalslugto the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
include __DIR__ . '/../../mainfile.php';
27
//include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/msg.php");
28
include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/functions.php';
29 View Code Duplication
if (isset($_GET['msg_id'])) {
30
    $msg_id = (int)$_GET['msg_id'];
31
} elseif (isset($_POST['msg_id'])) {
32
    $msg_id = (int)$_POST['msg_id'];
33
} else {
34
    $msg_id = 0;
35
}
36
37 View Code Duplication
if (isset($_GET['op'])) {
38
    $op = $_GET['op'];
39
} elseif (isset($_POST['op'])) {
40
    $op = $_POST['op'];
41
} else {
42
    $op = 'show_all';
43
}
44
45
$msgHandler = xoops_getModuleHandler('msg');
46
47
//Admin or not
48
$xoopsUser ? $adminview = $xoopsUser->isAdmin() : $adminview = 0;
49
50
/**
51
 * @param $msg_id
52
 */
53
function delete($msg_id)
54
{
55
    global $msgHandler, $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...
56
    $ok = isset($_POST['ok']) ? (int)$_POST['ok'] : 0;
57
    if ($ok == 1) {
58
        $msg        = $msgHandler->get($msg_id);
59
        $del_msg_ok = $msgHandler->delete($msg);
60
        $filename   = $msg->getVar('photo');
61 View Code Duplication
        if ($filename !== '') {
62
            $filename = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname') . '/' . $filename;
63
            unlink($filename);
64
        }
65
        if ($del_msg_ok) {
66
            $messagesent = _MD_XFGB_MSGDELETED;
67
        } else {
68
            $messagesent = _MD_XFGB_ERRORDEL;
69
        }
70
        redirect_header('index.php', 2, $messagesent);
71
    } else {
72
        xoops_confirm(array('op' => 'delete', 'msg_id' => $msg_id, 'ok' => 1), 'index.php', _DELETE);
73
    }
74
}
75
76
/**
77
 * @param $msg_id
78
 */
79
function approve($msg_id)
80
{
81
    global $msgHandler;
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...
82
83
    $msg = $msgHandler->get($msg_id);
84
    $msg->setVar('moderate', 0);
85
    if (!$msgHandler->insert($msg)) {
86
        $messagesent = _MD_XFGB_ERRORVALID;
87
    } else {
88
        $messagesent = _MD_XFGB_VALIDATE;
89
    }
90
    redirect_header('index.php?op=show_waiting', 2, $messagesent);
91
}
92
93
/**
94
 * @param $msg
95
 */
96
function xfgb_getmsg($msg)
97
{
98
    global $nbmsg, $xoopsModule, $xoopsUser, $xoopsModuleConfig, $xoopsTpl, $xoopsConfig, $options, $opt, $xoopsDB;
99
100
    $arr_country = xfgb_getAllCountry();
101
    $xoopsTpl->assign('display_msg', true);
102
    foreach ($msg as $onemsg) {
103
        if ($poster = xfgb_get_user_data($onemsg->getVar('user_id'))) {
104
            $a_msg = &$poster;
105
        } else {
106
            $a_msg             = array();
107
            $a_msg['poster']   = $onemsg->getVar('uname');
108
            $a_msg['rank']     = '';
109
            $a_msg['rank_img'] = '';
110
            $a_msg['avatar']   = '';
111
        }
112
        $memberHandler = xoops_getHandler('member');
113
        $user          = $memberHandler->getUser($onemsg->getVar('user_id'));
114
        // email
115
        if ($xoopsModuleConfig['showemail']
116
            || ($onemsg->getVar('email')
117
                && (($user->getVar('user_viewemail') == 1
118
                     || $onemsg->getVar('user_id') == 0)
119
                    && is_object($xoopsUser)))
120
        ) {
121
            $a_msg['email'] = "<a href=\"javascript:openWithSelfMain('"
122
                              . XOOPS_URL
123
                              . '/modules/xfguestbook/contact.php?msg_id='
124
                              . $onemsg->getVar('msg_id')
125
                              . "', 'contact', 600, 450);\"><img src=\""
126
                              . XOOPS_URL
127
                              . "/images/icons/email.gif\" alt=\""
128
                              . _SENDEMAILTO
129
                              . "\" /></a>";
130
        }
131
        // url
132
        if ($onemsg->getVar('url')) {
133
            $a_msg['url'] = '<a href="'
134
                            . $onemsg->getVar('url')
135
                            . '" target="_blank"><img src="'
136
                            . XOOPS_URL
137
                            . '/images/icons/www.gif" alt="'
138
                            . _VISITWEBSITE
139
                            . '"></a>';
140
        }
141
        // gender
142
        if ($onemsg->getVar('gender') !== '') {
143
            $a_msg['gender'] = '<a href="index.php?op=show_gender&param='
144
                               . $onemsg->getVar('gender')
145
                               . '"><img src="assets/images/'
146
                               . $onemsg->getVar('gender')
147
                               . '.gif"</a>';
148
        }
149
        // flag
150
        if ($onemsg->getVar('country') !== '') {
151
            if ($onemsg->getVar('country') != 'other') {
152
                $flag = XOOPS_ROOT_PATH
153
                        . '/modules/'
154
                        . $xoopsModule->dirname()
155
                        . '/assets/images/flags/'
156
                        . $onemsg->getVar('flagdir')
157
                        . '/'
158
                        . $onemsg->getVar('country')
159
                        . '.gif';
160
                if (array_key_exists($onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country'), $arr_country)) {
161
                    $country_name = $arr_country[$onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country')];
162
                } else {
163
                    $country_name = '';
164
                }
165 View Code Duplication
                if (file_exists($flag)) {
166
                    $a_msg['country'] = "<img src=\""
167
                                        . XOOPS_URL
168
                                        . '/modules/xfguestbook/assets/images/flags/'
169
                                        . $onemsg->getVar('flagdir')
170
                                        . '/'
171
                                        . $onemsg->getVar('country')
172
                                        . ".gif\" alt=\""
173
                                        . $country_name
174
                                        . "\">";
175
                } else {
176
                    $a_msg['country'] = $country_name;
177
                }
178
                $a_msg['country'] = "<a href=\"index.php?op=show_country&param="
179
                                    . $onemsg->getVar('flagdir')
180
                                    . '/'
181
                                    . $onemsg->getVar('country')
182
                                    . "\">"
183
                                    . $a_msg['country']
184
                                    . '</a>';
185
            } else {
186
                $a_msg['country'] = $onemsg->getVar('other');
187
            }
188
        }
189
        $a_msg['msg_id']  = $onemsg->getVar('msg_id');
190
        $a_msg['i']       = $nbmsg;
191
        $a_msg['title']   = $onemsg->getVar('title');
192
        $a_msg['date']    = formatTimestamp($onemsg->getVar('post_time'), 's');
193
        $a_msg['message'] = $onemsg->getVar('message');
194
        if ($options['opt_url'] == 1) {
195
            $a_msg['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $a_msg['message']);
196
        }
197
        $a_msg['note_msg']  = $onemsg->getVar('note');
198
        $a_msg['poster_ip'] = $onemsg->getVar('poster_ip');
199
        $a_msg['moderate']  = $onemsg->getVar('moderate');
200
        if (isset($country_name)) {
201
            $a_msg['local'] = "<a href=\"index.php?op=show_country&param="
202
                              . $onemsg->getVar('flagdir')
203
                              . '/'
204
                              . $onemsg->getVar('country')
205
                              . "\">"
206
                              . $country_name
207
                              . '</a>';
208
        }
209
        $a_msg['photo'] = $onemsg->getVar('photo');
210
        $xoopsTpl->append('msg', $a_msg);
211
        $nbmsg--;
212
    }
213
}
214
215
function xfgb_genderlist()
216
{
217
    global $options, $xoopsTpl, $xoopsModuleConfig, $xoopsModule, $msgHandler;
218
    $criteria = new Criteria('moderate', 0);
219
    $arr_msg  = $msgHandler->countMsgByGender($criteria);
220
    $i        = 0;
221
    foreach ($arr_msg as $k => $v) {
222
        if ($k === 'M') {
223
            $gender[$i] = _MD_XFGB_MALES . '<br>';
224
            $gender[$i] .= '<img src="assets/images/M.gif" alt="' . _MD_XFGB_MALES . '"><br><br>';
225
            $gender[$i] .= '<a href="index.php?op=show_gender&param=M">' . $v . _MD_XFGB_MESSAGES . '</a>';
226
        } elseif ($k === 'F') {
227
            $gender[$i] = _MD_XFGB_FEMALES . '<br>';
228
            $gender[$i] .= '<img src="assets/images/F.gif" alt="' . _MD_XFGB_FEMALES . '"><br><br>';
229
            $gender[$i] .= '<a href="index.php?op=show_gender&param=F">' . $v . _MD_XFGB_MESSAGES . '</a>';
230
        } else {
231
            $gender[$i] = _MD_XFGB_UNKNOW2 . '<br>';
232
            $gender[$i] .= '<img src="assets/images/U.gif"><br><br>';
233
            $gender[$i] .= $v . _MD_XFGB_MESSAGES;
234
        }
235
        $i++;
236
    }
237
    $xoopsTpl->assign('gender', $gender);
238
    $xoopsTpl->assign('display_gender', $options['opt_gender']);
239
}
240
241
// end functions
242
243
// if op = show_***, functions needed
244
//if (substr($op, 0, 4) == 'show') {
245
if (0 === strpos($op, 'show')) {
246
    $debut = isset($_GET['debut']) ? (int)$_GET['debut'] : 0;
247
    $param = isset($_GET['param']) ? $_GET['param'] : '';
248
249
    include_once __DIR__ . '/include/functions.php';
250
    $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_index.tpl';
251
    include_once XOOPS_ROOT_PATH . '/header.php';
252
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
253
    include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/config.inc.php';
254
    $options = getOptions();
255
256
    $criteria = new Criteria('moderate', 0);
257
    $nbmsg    = $msgHandler->countMsg($criteria);
258
259
    $xoopsTpl->assign('msg_message_count', sprintf(_MD_XFGB_THEREIS, '<b>' . $nbmsg . '</b>'));
260
    $xoopsTpl->assign('msg_moderated', $xoopsModuleConfig['moderate']);
261
    $xoopsTpl->assign('msg_lang_name', $xoopsConfig['language']);
262
    $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name() . ' -messages');
263
    if ($adminview) {
264
        $nbwait = $msgHandler->countMsg(new Criteria('moderate', '1'));
265
        $xoopsTpl->assign('msg_moderate_text', sprintf(_MD_XFGB_MODERATING, "<font class='fg2'><a href='"
266
                                                                            . XOOPS_URL
267
                                                                            . "/modules/xfguestbook/index.php?op=show_waiting'>"
268
                                                                            . $nbwait
269
                                                                            . '</a></font>'));
270
    }
271
}
272
273
switch ($op) {
274 View Code Duplication
    case 'delete':
275
        if ($adminview) {
276
            include_once XOOPS_ROOT_PATH . '/header.php';
277
            delete($msg_id);
278
        } else {
279
            redirect_header('index.php', 1, '');
280
        }
281
        break;
282
283 View Code Duplication
    case 'approve':
284
        if ($adminview) {
285
            include_once XOOPS_ROOT_PATH . '/header.php';
286
            approve($msg_id);
287
        } else {
288
            redirect_header('index.php', 1, '');
289
        }
290
        break;
291
292
    case 'show_stat':
293
        if ($options['opt_gender'] > 0) {
294
            xfgb_genderlist();
295
        }
296
        break;
297
298 View Code Duplication
    case 'show_waiting':
299
        $pagenav = new XoopsPageNav($nbwait, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_waiting');
300
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
301
        $criteria = new Criteria('moderate', 1);
302
        $criteria->setOrder('DESC');
303
        $criteria->setLimit($xoopsModuleConfig['perpage']);
304
        $criteria->setStart($debut);
305
        $msg =& $msgHandler->getObjects($criteria);
306
        $nbwait -= $debut;
307
        $nbmsg = $nbwait;
308
        xfgb_getmsg($msg);
309
        break;
310
311
    case 'show_one':
312
        if ($adminview) {
313
            $criteria = new Criteria('msg_id', $msg_id);
314
        } else {
315
            $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
316
            $criteria->add(new Criteria('msg_id', $msg_id));
317
        }
318
        $msg =& $msgHandler->getObjects($criteria);
319
        xfgb_getmsg($msg);
320
        if ($options['opt_gender'] > 0) {
321
            xfgb_genderlist();
322
        }
323
        break;
324
325
    case 'show_country':
326
        list($flagdir, $country) = explode('/', $param);
327
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
328
        if ($flagdir == $xoopsModuleConfig['flagdir']) {
329
            $criteria->add(new Criteria('flagdir', $flagdir));
330
        }
331
        $criteria->add(new Criteria('country', $country));
332
        $nbmsg   = $msgHandler->countMsg($criteria);
333
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_country&param=' . $param);
334
        $criteria->setOrder('DESC');
335
        $criteria->setLimit($xoopsModuleConfig['perpage']);
336
        $criteria->setStart($debut);
337
        $msg =& $msgHandler->getObjects($criteria);
338
        $nbmsg -= $debut;
339
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
340
        xfgb_getmsg($msg);
341
        break;
342
343
    case 'show_gender':
344
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
345
        $criteria->add(new Criteria('gender', $param));
346
        $nbmsg   = $msgHandler->countMsg($criteria);
347
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_gender&param=' . $param);
348
        $criteria->setOrder('DESC');
349
        $criteria->setLimit($xoopsModuleConfig['perpage']);
350
        $criteria->setStart($debut);
351
        $msg =& $msgHandler->getObjects($criteria);
352
        $nbmsg -= $debut;
353
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
354
        xfgb_getmsg($msg);
355
        if ($options['opt_gender'] > 0) {
356
            xfgb_genderlist();
357
        }
358
        break;
359
360
    case 'show_all':
361 View Code Duplication
    default:
362
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', '');
363
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
364
        $criteria = new Criteria('moderate', 0);
365
        $criteria->setOrder('DESC');
366
        $criteria->setLimit($xoopsModuleConfig['perpage']);
367
        $criteria->setStart($debut);
368
        $msg =& $msgHandler->getObjects($criteria);
369
        $nbmsg -= $debut;
370
        xfgb_getmsg($msg);
371
        if ($options['opt_gender'] > 0) {
372
            xfgb_genderlist();
373
        }
374
        break;
375
376 View Code Duplication
    case 'cancel':
377
        $photos_dir     = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
378
        $nb_removed_tmp = xfgb_clear_tmp_files($photos_dir);
379
        redirect_header('index.php', 0);
380
        break;
381
}
382
$sql = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country') . ' ORDER BY country_name ASC');
383
384
while ($coun = $xoopsDB->fetchArray($sql)) {
385
    $sql2 = $xoopsDB->query('SELECT COUNT(country) tot FROM '
386
                            . $xoopsDB->prefix('xfguestbook_msg')
387
                            . " WHERE country='"
388
                            . $coun['country_code']
389
                            . "'");
390
    list($tlocal) = $xoopsDB->fetchRow($sql2);
391
    $tlocal = $tlocal ?: '0';
392
    if ($tlocal > 0) {
393
        $opt["<a href=\"index.php?op=show_country&param="
394
             . $xoopsModuleConfig['flagdir']
395
             . '/'
396
             . $coun['country_code']
397
             . "\">"
398
             . $coun['country_name']
399
             . '</a>'] = $tlocal;
400
    } else {
401
        $opt[$coun['country_name']] = $tlocal;
402
    }
403
}
404
$xoopsTpl->assign('country_l', $opt);
405
406
include XOOPS_ROOT_PATH . '/footer.php';
407