Passed
Push — master ( 37a2f2...290aa0 )
by Michael
02:35
created

contact.php (1 issue)

Severity
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 to the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//---------------------------------------------------------------------------//
25
26
use XoopsModules\Xfguestbook;
27
28
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
29
//** @var Xfguestbook\Helper $helper */
30
$helper = Xfguestbook\Helper::getInstance();
31
32
$op = 'form';
33
foreach ($_POST as $k => $v) {
34
    ${$k} = $v;
35
}
36
foreach ($_GET as $k => $v) {
37
    ${$k} = $v;
38
}
39
40
if (isset($preview)) {
41
    $op = 'preview';
42
} elseif (isset($post)) {
43
    $op = 'post';
44
}
45
require_once __DIR__ . '/include/config.inc.php';
46
$option = getOptions();
47
48
/**
49
 * @param $title
50
 * @param $content
51
 */
52
function displaypost($title, $content)
53
{
54
    echo '<table cellpadding="4" cellspacing="1" width="98%" class="outer"><tr><td class="head">' . $title . '</td></tr><tr><td><br>' . $content . '<br></td></tr></table>';
55
}
56
57
switch ($op) {
58
59
    case 'post':
60
        global $xoopsConfig;
61
        $ts = \MyTextSanitizer::getInstance();
62
        xoops_header();
63
64
        if (1 == $option['opt_code']) {
65
            xoops_load('XoopsCaptcha');
66
            $xoopsCaptcha = XoopsCaptcha::getInstance();
67
            if (!$xoopsCaptcha->verify()) {
68
                redirect_header('index.php', 3, $xoopsCaptcha->getMessage());
69
            }
70
        }
71
        $fullmsg = MD_XFGUESTBOOK_FROMUSER . " $name_user " . MD_XFGUESTBOOK_YOURMSG . ' ' . $xoopsConfig['sitename'] . ' :<br><br>';
72
        $fullmsg .= $title . '<br>';
73
        $fullmsg .= '<hr><br>';
74
        $fullmsg .= "$message<br><br>";
75
        $fullmsg .= '<hr><br>';
76
        $fullmsg .= MD_XFGUESTBOOK_CANJOINT . ' [email]' . $email_user . '[/email]';
77
78
        $xoopsMailer = xoops_getMailer();
79
        $xoopsMailer->useMail();
80
        $xoopsMailer->setFromEmail($email_user);
81
        $xoopsMailer->setFromName($xoopsConfig['sitename']);
82
        $xoopsMailer->setToEmails($email_author);
83
        $xoopsMailer->setSubject(MD_XFGUESTBOOK_CONTACTAFTERMSG);
84
        $xoopsMailer->multimailer->isHTML(true);
85
        $xoopsMailer->setBody($ts->xoopsCodeDecode($fullmsg));
86
        $msgsend = "<div style='text-align:center;'><br><br>";
87
        if (!$xoopsMailer->send()) {
88
            $msgsend .= $xoopsMailer->getErrors();
89
        } else {
90
            $msgsend .= '<h4>' . MD_XFGUESTBOOK_MSGSEND . '</h4>';
91
        }
92
        $msgsend .= '<br><br><a href="javascript:window.close();">' . MD_XFGUESTBOOK_CLOSEWINDOW . '</a></div>';
93
        echo $msgsend;
94
        break;
95
96
    case 'preview':
97
98
        $ts = \MyTextSanitizer::getInstance();
99
        xoops_header();
100
101
        if (1 == $option['opt_code']) {
102
            xoops_load('XoopsCaptcha');
103
            $xoopsCaptcha = XoopsCaptcha::getInstance();
104
            if (!$xoopsCaptcha->verify()) {
105
                redirect_header('index.php', 3, $xoopsCaptcha->getMessage());
106
            }
107
        }
108
        $p_title = $title;
109
        $p_title = $ts->htmlSpecialChars($ts->stripSlashesGPC($p_title));
110
        $p_msg   = MD_XFGUESTBOOK_FROMUSER . " $name_user " . MD_XFGUESTBOOK_YOURMSG . ' ' . $xoopsConfig['sitename'] . ' :<br>';
111
        $p_msg   .= $title . '<br>';
112
        $p_msg   .= '<hr><br>';
113
        $p_msg   .= $message . '<br><br>';
114
        $p_msg   .= '<hr><br>';
115
        $p_msg   .= MD_XFGUESTBOOK_CANJOINT . " $email_user";
116
117
        $p_msg .= '<br>';
118
        displaypost($p_title, $p_msg);
119
120
        $title   = $ts->htmlSpecialChars($ts->stripSlashesGPC($title));
121
        $message = $ts->htmlSpecialChars($ts->stripSlashesGPC($message));
122
123
        require_once __DIR__   . '/include/form_contact.inc.php';
124
        xoops_footer();
125
        break;
126
127
    case 'form':
128
    default:
129
130
        xoops_header();
131
        $msgHandler = $helper->getHandler('Message');
132
        $msg        = $msgHandler->get($msg_id);
133
        if (!$msg) {
0 ignored issues
show
$msg is of type XoopsObject, thus it always evaluated to true.
Loading history...
134
            redirect_header('index.php', 3, _NOPERM);
135
        }
136
        $message      = '';
137
        $phone        = '';
138
        $name_user    = '';
139
        $email_user   = '';
140
        $email_author = $msg->getVar('email');
141
        $title        = $msg->getVar('title');
142
        if ($xoopsUser) {
143
            $name_user  = ('' !== $xoopsUser->getVar('name')) ? $xoopsUser->getVar('name') : $xoopsUser->getVar('uname');
144
            $email_user = $xoopsUser->getVar('email', 'E');
145
        }
146
        if (1 == $option['opt_code']) {
147
            xoops_load('XoopsCaptcha');
148
            $xoopsCaptcha = XoopsCaptcha::getInstance();
149
        }
150
        require_once __DIR__   . '/include/form_contact.inc.php';
151
        xoops_footer();
152
        break;
153
}
154