Passed
Push — master ( 188361...fd3319 )
by Michael
03:02
created

mailAd()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 66
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 58
c 0
b 0
f 0
dl 0
loc 66
rs 8.9163
cc 3
nc 3
nop 5

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