Completed
Pull Request — master (#10)
by Michael
01:59
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(['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             = [];
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="' . $onemsg->getVar('url') . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" alt="' . _VISITWEBSITE . '"></a>';
134
        }
135
        // gender
136
        if ($onemsg->getVar('gender') !== '') {
137
            $a_msg['gender'] = '<a href="index.php?op=show_gender&param=' . $onemsg->getVar('gender') . '"><img src="assets/images/' . $onemsg->getVar('gender') . '.gif"</a>';
138
        }
139
        // flag
140
        if ($onemsg->getVar('country') !== '') {
141
            if ($onemsg->getVar('country') !== 'other') {
142
                $flag = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country') . '.gif';
143
                if (array_key_exists($onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country'), $arr_country)) {
144
                    $country_name = $arr_country[$onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country')];
145
                } else {
146
                    $country_name = '';
147
                }
148 View Code Duplication
                if (file_exists($flag)) {
149
                    $a_msg['country'] = '<img src="'
150
                                        . XOOPS_URL
151
                                        . '/modules/xfguestbook/assets/images/flags/'
152
                                        . $onemsg->getVar('flagdir')
153
                                        . '/'
154
                                        . $onemsg->getVar('country')
155
                                        . '.gif" alt="'
156
                                        . $country_name
157
                                        . '">';
158
                } else {
159
                    $a_msg['country'] = $country_name;
160
                }
161
                $a_msg['country'] = '<a href="index.php?op=show_country&param=' . $onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country') . '">' . $a_msg['country'] . '</a>';
162
            } else {
163
                $a_msg['country'] = $onemsg->getVar('other');
164
            }
165
        }
166
        $a_msg['msg_id']  = $onemsg->getVar('msg_id');
167
        $a_msg['i']       = $nbmsg;
168
        $a_msg['title']   = $onemsg->getVar('title');
169
        $a_msg['date']    = formatTimestamp($onemsg->getVar('post_time'), 's');
170
        $a_msg['message'] = $onemsg->getVar('message');
171
        if ($options['opt_url'] == 1) {
172
            $a_msg['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $a_msg['message']);
173
        }
174
        $a_msg['note_msg']  = $onemsg->getVar('note');
175
        $a_msg['poster_ip'] = $onemsg->getVar('poster_ip');
176
        $a_msg['moderate']  = $onemsg->getVar('moderate');
177
        if (isset($country_name)) {
178
            $a_msg['local'] = '<a href="index.php?op=show_country&param=' . $onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country') . '">' . $country_name . '</a>';
179
        }
180
        $a_msg['photo'] = $onemsg->getVar('photo');
181
        $xoopsTpl->append('msg', $a_msg);
182
        $nbmsg--;
183
    }
184
}
185
186
function xfgb_genderlist()
187
{
188
    global $options, $xoopsTpl, $xoopsModuleConfig, $xoopsModule, $msgHandler;
189
    $criteria = new Criteria('moderate', 0);
190
    $arr_msg  = $msgHandler->countMsgByGender($criteria);
191
    $i        = 0;
192
    foreach ($arr_msg as $k => $v) {
193
        if ($k === 'M') {
194
            $gender[$i] = MD_XFGB_MALES . '<br>';
195
            $gender[$i] .= '<img src="assets/images/M.gif" alt="' . MD_XFGB_MALES . '"><br><br>';
196
            $gender[$i] .= '<a href="index.php?op=show_gender&param=M">' . $v . MD_XFGB_MESSAGES . '</a>';
197
        } elseif ($k === 'F') {
198
            $gender[$i] = MD_XFGB_FEMALES . '<br>';
199
            $gender[$i] .= '<img src="assets/images/F.gif" alt="' . MD_XFGB_FEMALES . '"><br><br>';
200
            $gender[$i] .= '<a href="index.php?op=show_gender&param=F">' . $v . MD_XFGB_MESSAGES . '</a>';
201
        } else {
202
            $gender[$i] = MD_XFGB_UNKNOW2 . '<br>';
203
            $gender[$i] .= '<img src="assets/images/U.gif"><br><br>';
204
            $gender[$i] .= $v . MD_XFGB_MESSAGES;
205
        }
206
        $i++;
207
    }
208
    $xoopsTpl->assign('gender', $gender);
209
    $xoopsTpl->assign('display_gender', $options['opt_gender']);
210
}
211
212
// end functions
213
214
// if op = show_***, functions needed
215
//if (substr($op, 0, 4) == 'show') {
216
if (0 === strpos($op, 'show')) {
217
    $debut = isset($_GET['debut']) ? (int)$_GET['debut'] : 0;
218
    $param = isset($_GET['param']) ? $_GET['param'] : '';
219
220
    include_once __DIR__ . '/include/functions.php';
221
    $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_index.tpl';
222
    include_once XOOPS_ROOT_PATH . '/header.php';
223
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
224
    include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/config.inc.php';
225
    $options = getOptions();
226
227
    $criteria = new Criteria('moderate', 0);
228
    $nbmsg    = $msgHandler->countMsg($criteria);
229
230
    $xoopsTpl->assign('msg_message_count', sprintf(MD_XFGB_THEREIS, '<b>' . $nbmsg . '</b>'));
231
    $xoopsTpl->assign('msg_moderated', $xoopsModuleConfig['moderate']);
232
    $xoopsTpl->assign('msg_lang_name', $xoopsConfig['language']);
233
    $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name() . ' -messages');
234
    if ($adminview) {
235
        $nbwait = $msgHandler->countMsg(new Criteria('moderate', '1'));
236
        $xoopsTpl->assign('msg_moderate_text', sprintf(MD_XFGB_MODERATING, "<font class='fg2'><a href='" . XOOPS_URL . "/modules/xfguestbook/index.php?op=show_waiting'>" . $nbwait . '</a></font>'));
237
    }
238
}
239
240
switch ($op) {
241 View Code Duplication
    case 'delete':
242
        if ($adminview) {
243
            include_once XOOPS_ROOT_PATH . '/header.php';
244
            delete($msg_id);
245
        } else {
246
            redirect_header('index.php', 1, '');
247
        }
248
        break;
249
250 View Code Duplication
    case 'approve':
251
        if ($adminview) {
252
            include_once XOOPS_ROOT_PATH . '/header.php';
253
            approve($msg_id);
254
        } else {
255
            redirect_header('index.php', 1, '');
256
        }
257
        break;
258
259
    case 'show_stat':
260
        if ($options['opt_gender'] > 0) {
261
            xfgb_genderlist();
262
        }
263
        break;
264
265 View Code Duplication
    case 'show_waiting':
266
        $pagenav = new XoopsPageNav($nbwait, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_waiting');
267
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
268
        $criteria = new Criteria('moderate', 1);
269
        $criteria->setOrder('DESC');
270
        $criteria->setLimit($xoopsModuleConfig['perpage']);
271
        $criteria->setStart($debut);
272
        $msg    =& $msgHandler->getObjects($criteria);
273
        $nbwait -= $debut;
274
        $nbmsg  = $nbwait;
275
        xfgb_getmsg($msg);
276
        break;
277
278
    case 'show_one':
279
        if ($adminview) {
280
            $criteria = new Criteria('msg_id', $msg_id);
281
        } else {
282
            $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
283
            $criteria->add(new Criteria('msg_id', $msg_id));
284
        }
285
        $msg =& $msgHandler->getObjects($criteria);
286
        xfgb_getmsg($msg);
287
        if ($options['opt_gender'] > 0) {
288
            xfgb_genderlist();
289
        }
290
        break;
291
292
    case 'show_country':
293
        list($flagdir, $country) = explode('/', $param);
294
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
295
        if ($flagdir == $xoopsModuleConfig['flagdir']) {
296
            $criteria->add(new Criteria('flagdir', $flagdir));
297
        }
298
        $criteria->add(new Criteria('country', $country));
299
        $nbmsg   = $msgHandler->countMsg($criteria);
300
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_country&param=' . $param);
301
        $criteria->setOrder('DESC');
302
        $criteria->setLimit($xoopsModuleConfig['perpage']);
303
        $criteria->setStart($debut);
304
        $msg   =& $msgHandler->getObjects($criteria);
305
        $nbmsg -= $debut;
306
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
307
        xfgb_getmsg($msg);
308
        break;
309
310
    case 'show_gender':
311
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
312
        $criteria->add(new Criteria('gender', $param));
313
        $nbmsg   = $msgHandler->countMsg($criteria);
314
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_gender&param=' . $param);
315
        $criteria->setOrder('DESC');
316
        $criteria->setLimit($xoopsModuleConfig['perpage']);
317
        $criteria->setStart($debut);
318
        $msg   =& $msgHandler->getObjects($criteria);
319
        $nbmsg -= $debut;
320
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
321
        xfgb_getmsg($msg);
322
        if ($options['opt_gender'] > 0) {
323
            xfgb_genderlist();
324
        }
325
        break;
326
327
    case 'show_all':
328 View Code Duplication
    default:
329
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', '');
330
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
331
        $criteria = new Criteria('moderate', 0);
332
        $criteria->setOrder('DESC');
333
        $criteria->setLimit($xoopsModuleConfig['perpage']);
334
        $criteria->setStart($debut);
335
        $msg   =& $msgHandler->getObjects($criteria);
336
        $nbmsg -= $debut;
337
        xfgb_getmsg($msg);
338
        if ($options['opt_gender'] > 0) {
339
            xfgb_genderlist();
340
        }
341
        break;
342
343 View Code Duplication
    case 'cancel':
344
        $photos_dir     = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
345
        $nb_removed_tmp = xfgb_clear_tmp_files($photos_dir);
346
        redirect_header('index.php', 0);
347
        break;
348
}
349
$sql = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country') . ' ORDER BY country_name ASC');
350
351
while ($coun = $xoopsDB->fetchArray($sql)) {
352
    $sql2 = $xoopsDB->query('SELECT COUNT(country) tot FROM ' . $xoopsDB->prefix('xfguestbook_msg') . " WHERE country='" . $coun['country_code'] . '\'');
353
    list($tlocal) = $xoopsDB->fetchRow($sql2);
354
    $tlocal = $tlocal ?: '0';
355
    if ($tlocal > 0) {
356
        $opt['<a href="index.php?op=show_country&param=' . $xoopsModuleConfig['flagdir'] . '/' . $coun['country_code'] . '">' . $coun['country_name'] . '</a>'] = $tlocal;
357
    } else {
358
        $opt[$coun['country_name']] = $tlocal;
359
    }
360
}
361
$xoopsTpl->assign('country_l', $opt);
362
363
include XOOPS_ROOT_PATH . '/footer.php';
364