reportAbuse()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 57
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 35
c 0
b 0
f 0
dl 0
loc 57
rs 9.36
cc 4
nc 8
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project (https://xoops.org)
15
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author       XOOPS Development Team
17
 * @author       Pascal Le Boustouller: original author ([email protected])
18
 * @author       Luc Bizet (www.frxoops.org)
19
 * @author       jlm69 (www.jlmzone.com)
20
 * @author       mamba (www.xoops.org)
21
 */
22
23
use Xmf\Request;
24
use XoopsModules\Adslight\{
25
    Helper,
26
    Utility
27
};
28
/** @var Helper $helper */
29
require_once __DIR__ . '/header.php';
30
//require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
31
32
/**
33
 * @param $lid
34
 */
35
function reportAbuse($lid): void
36
{
37
    global $xoopsConfig, $xoopsDB, $xoopsTheme;
38
    $helper = Helper::getInstance();
39
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
40
    require_once XOOPS_ROOT_PATH . '/header.php';
41
42
    $lid    = (int)$lid;
43
    $idd    = $idde = $iddee = '';
44
    $sql    = 'SELECT lid, title, type FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid);
45
    $result = $xoopsDB->query($sql);
46
    if (!$xoopsDB->isResultSet($result)) {
47
        \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
48
    }
49
    [$lid, $title, $type] = $xoopsDB->fetchRow($result);
50
51
    $GLOBALS['xoTheme']->addMeta('meta', 'robots', 'noindex, nofollow');
52
53
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>\n";
54
    echo '<strong>' . _ADSLIGHT_REPORTSENDTO . " {$lid} </strong>: \" {$type} : {$title} \"<br><br>
55
        <form action=\"report-abuse.php\" method=post>
56
        <input type=\"hidden\" name=\"lid\" value=\"{$lid}\" >";
57
    if ($GLOBALS['xoopsUser']) {
58
        $idd   = $GLOBALS['xoopsUser']->getVar('uname', 'E');
59
        $idde  = $GLOBALS['xoopsUser']->getVar('email', 'E');
60
        $iddee = $xoopsConfig['adminmail'];
61
    } else {
62
        $iddee = $xoopsConfig['adminmail'];
63
    }
64
65
    echo "
66
    <table width='99%' class='outer' cellspacing='1'>
67
    <tr>
68
      <td class='head' width='30%'>" . _ADSLIGHT_NAME . " </td>
69
      <td class='even'><input class=\"textbox\" type=\"text\" name=\"yname\" value=\"{$idd}\" ></td>
70
    </tr>
71
    <tr>
72
      <td class='head'>" . _ADSLIGHT_MAIL . " </td>
73
      <td class='even'><input class=\"textbox\" type=\"text\" name=\"ymail\" value=\"{$idde}\" ></td>
74
    </tr>
75
    <tr>
76
      <td class='head'></td>
77
      <td class='even'><input class=\"textbox\" type=\"hidden\" name=\"fmail\" value=\"{$iddee}\"></td>
78
    </tr>";
79
80
    if ('1' === $helper->getConfig('adslight_use_captcha')) {
81
        echo "<tr><td class='head'>" . _ADSLIGHT_CAPTCHA . " </td><td class='even'>";
82
        $jlm_captcha = new \XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, 'xoopscaptcha', false);
83
        echo $jlm_captcha->render();
84
        echo '</td></tr>';
85
    }
86
87
    echo '</table><br>
88
    <input type=hidden name=op value=MailAd>
89
    <input type=submit value=' . _ADSLIGHT_SENDFR . '>
90
    </form>     ';
91
    echo '</td></tr></table>';
92
}
93
94
/**
95
 * @param $lid
96
 * @param $yname
97
 * @param $ymail
98
 * @param $fname
99
 * @param $fmail
100
 */
101
function mailAd($lid, $yname, $ymail, $fname, $fmail): void
102
{
103
    global $xoopsConfig, $xoopsTpl, $xoopsDB, $xoopsModule, $myts;
104
    $helper = Helper::getInstance();
105
    if ('1' === $helper->getConfig('adslight_use_captcha')) {
106
        xoops_load('xoopscaptcha');
107
        $xoopsCaptcha = XoopsCaptcha::getInstance();
108
        if (!$xoopsCaptcha->verify()) {
109
            $helper->redirect('index.php', 2, $xoopsCaptcha->getMessage());
110
        }
111
    }
112
113
    $lid    = (int)$lid;
114
    $sql    = 'SELECT lid, title, expire, type, desctext, tel, price, typeprice, date_created, email, submitter, town, country, photo FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid);
115
    $result = $xoopsDB->query($sql);
116
    if (!$xoopsDB->isResultSet($result)) {
117
        \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
118
    }
119
    [$lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date_created, $email, $submitter, $town, $country, $photo] = $xoopsDB->fetchRow($result);
120
121
    $title     = $GLOBALS['xoopsDB']->escape($title);
122
    $expire    = $GLOBALS['xoopsDB']->escape($expire);
0 ignored issues
show
Unused Code introduced by
The assignment to $expire is dead and can be removed.
Loading history...
123
    $type      = $GLOBALS['xoopsDB']->escape($type);
124
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
125
    $tel       = $GLOBALS['xoopsDB']->escape($tel);
126
    $price     = $GLOBALS['xoopsDB']->escape($price);
127
    $typeprice = $GLOBALS['xoopsDB']->escape($typeprice);
128
    $submitter = $GLOBALS['xoopsDB']->escape($submitter);
0 ignored issues
show
Unused Code introduced by
The assignment to $submitter is dead and can be removed.
Loading history...
129
    $town      = $GLOBALS['xoopsDB']->escape($town);
130
    $country   = $GLOBALS['xoopsDB']->escape($country);
131
132
    $tags                       = [];
133
    $tags['YNAME']              = stripslashes($yname);
134
    $tags['YMAIL']              = $ymail;
135
    $tags['FNAME']              = stripslashes($fname);
136
    $tags['FMAIL']              = $fmail;
137
    $tags['HELLO']              = _ADSLIGHT_HELLO;
138
    $tags['LID']                = $lid;
139
    $tags['LISTING_NUMBER']     = _ADSLIGHT_LISTING_NUMBER;
140
    $tags['TITLE']              = $title;
141
    $tags['TYPE']               = Utility::getNameType($type);
142
    $tags['DESCTEXT']           = $desctext;
143
    $tags['PRICE']              = $price;
144
    $tags['TYPEPRICE']          = $typeprice;
145
    $tags['TEL']                = $tel;
146
    $tags['TOWN']               = $town;
147
    $tags['COUNTRY']            = $country;
148
    $tags['OTHER']              = _ADSLIGHT_INTERESS . $xoopsConfig['sitename'];
149
    $tags['LISTINGS']           = XOOPS_URL . '/modules/adslight/';
150
    $tags['LINK_URL']           = XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid;
151
    $tags['THINKS_REPORT']      = _ADSLIGHT_REPORTMESSAGE;
152
    $tags['NO_MAIL']            = _ADSLIGHT_NOMAIL;
153
    $tags['YOU_CAN_VIEW_BELOW'] = _ADSLIGHT_YOU_CAN_VIEW_BELOW;
154
    $tags['WEBMASTER']          = _ADSLIGHT_WEBMASTER;
155
    $tags['NO_REPLY']           = _ADSLIGHT_NOREPLY;
156
    $subject                    = _ADSLIGHT_REPORTSUBJET . ' ' . $xoopsConfig['sitename'];
157
158
    $xoopsMailer = xoops_getMailer();
159
    $xoopsMailer->multimailer->isHTML(true);
160
    $xoopsMailer->useMail();
161
    $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
162
    $xoopsMailer->setTemplate('listing_report_abuse.tpl');
163
    $xoopsMailer->setFromEmail($ymail);
164
    $xoopsMailer->setToEmails($fmail);
165
    $xoopsMailer->setSubject($subject);
166
    $xoopsMailer->assign($tags);
167
168
    // $fmail = $xoopsConfig['adminmail'];
169
    // $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
170
    // $idde = $xoopsUserIsAdmin->getVar("adminmail", "E");
171
172
    $xoopsMailer->send();
173
    echo $xoopsMailer->getErrors();
174
    $helper->redirect('index.php', 3, _ADSLIGHT_REPORTANNSEND);
175
}
176
177
##############################################################
178
$yname = Request::getString('yname', '', 'POST');
179
$ymail = Request::getString('ymail', '', 'POST');
180
$fname = Request::getString('fname', '', 'POST');
181
$fmail = Request::getString('fmail', '', 'POST');
182
183
$lid = Request::getInt('lid', 0);
184
$op  = Request::getString('op', '');
185
186
switch ($op) {
187
    case 'ReportAbuse':
188
        require_once XOOPS_ROOT_PATH . '/header.php';
189
        reportAbuse($lid);
190
        require_once XOOPS_ROOT_PATH . '/footer.php';
191
        break;
192
    case 'MailAd':
193
        mailAd($lid, $yname, $ymail, $fname, $fmail);
194
        break;
195
    default:
196
        $helper->redirect('index.php', 1, _RETURNANN);
197
        break;
198
}
199