Completed
Push — master ( deac0a...054aa6 )
by Michael
01:55
created

report-abuse.php ➔ ReportAbuse()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 55
Code Lines 33

Duplication

Lines 7
Ratio 12.73 %

Importance

Changes 0
Metric Value
cc 3
eloc 33
nc 4
nop 1
dl 7
loc 55
rs 9.7692
c 0
b 0
f 0

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
use Xmf\Request;
24
25
require_once __DIR__ . '/header.php';
26
//require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
27
//include XOOPS_ROOT_PATH . '/modules/adslight/class/utility.php';
28
29
/**
30
 * @param $lid
31
 *
32
 * @return void
33
 */
34
function ReportAbuse($lid)
35
{
36
    global $xoopsConfig, $xoopsDB, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
37
38
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
39
    include XOOPS_ROOT_PATH . '/header.php';
40
41
    $lid    = (int)$lid;
42
    $idd    = $idde = $iddee = '';
0 ignored issues
show
Unused Code introduced by
$iddee is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
    $result = $xoopsDB->query('SELECT lid, title, type FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid));
44
    list($lid, $title, $type) = $xoopsDB->fetchRow($result);
45
46
    $GLOBALS['xoTheme']->addMeta('meta', 'robots', 'noindex, nofollow');
47
48
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>\n";
49
    echo '<strong>' . _ADSLIGHT_REPORTSENDTO . " $lid </strong>: \" $type : $title \"<br><br>
50
        <form action=\"report-abuse.php\" method=post>
51
        <input type=\"hidden\" name=\"lid\" value=\"$lid\" >";
52
    if ($GLOBALS['xoopsUser']) {
53
        $idd   = $GLOBALS['xoopsUser']->getVar('uname', 'E');
54
        $idde  = $GLOBALS['xoopsUser']->getVar('email', 'E');
55
        $iddee = $xoopsConfig['adminmail'];
56
    } else {
57
        $iddee = $xoopsConfig['adminmail'];
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'></td>
72
      <td class='even'><input class=\"textbox\" type=\"hidden\" name=\"fmail\" value=\"$iddee\"></td>
73
    </tr>";
74
75 View Code Duplication
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_captcha']) {
76
        echo "<tr><td class='head'>" . _ADSLIGHT_CAPTCHA . " </td><td class='even'>";
77
        $jlm_captcha = '';
0 ignored issues
show
Unused Code introduced by
$jlm_captcha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
78
        $jlm_captcha = new XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, 'xoopscaptcha', false);
79
        echo $jlm_captcha->render();
80
        echo '</td></tr>';
81
    }
82
83
    echo '</table><br>
84
    <input type=hidden name=op value=MailAd>
85
    <input type=submit value=' . _ADSLIGHT_SENDFR . '>
86
    </form>     ';
87
    echo '</td></tr></table>';
88
}
89
90
/**
91
 * @param $lid
92
 * @param $yname
93
 * @param $ymail
94
 * @param $fname
95
 * @param $fmail
96
 */
97
function MailAd($lid, $yname, $ymail, $fname, $fmail)
98
{
99
    global $xoopsConfig, $xoopsTpl, $xoopsDB, $xoopsModule, $myts, $xoopsLogger, $moduleDirName, $main_lang;
100
101 View Code Duplication
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_captcha']) {
102
        xoops_load('xoopscaptcha');
103
        $xoopsCaptcha = XoopsCaptcha::getInstance();
104
        if (!$xoopsCaptcha->verify()) {
105
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 2, $xoopsCaptcha->getMessage());
106
        }
107
    }
108
109
    $lid    = (int)$lid;
110
    $result = $xoopsDB->query('SELECT lid, title, expire, type, desctext, tel, price, typeprice, date, email, submitter, town, country, photo FROM '
111
                              . $xoopsDB->prefix('adslight_listing')
112
                              . ' WHERE lid='
113
                              . $xoopsDB->escape($lid));
114
    list($lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date, $email, $submitter, $town, $country, $photo) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $date is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $email is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $photo is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
115
116
    $title     = $myts->addSlashes($title);
117
    $expire    = $myts->addSlashes($expire);
0 ignored issues
show
Unused Code introduced by
$expire is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
    $type      = $myts->addSlashes($type);
119
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
120
    $tel       = $myts->addSlashes($tel);
121
    $price     = $myts->addSlashes($price);
122
    $typeprice = $myts->addSlashes($typeprice);
123
    $submitter = $myts->addSlashes($submitter);
0 ignored issues
show
Unused Code introduced by
$submitter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
124
    $town      = $myts->addSlashes($town);
125
    $country   = $myts->addSlashes($country);
126
127
    $tags                       = array();
128
    $tags['YNAME']              = stripslashes($yname);
129
    $tags['YMAIL']              = $ymail;
130
    $tags['FNAME']              = stripslashes($fname);
131
    $tags['FMAIL']              = $fmail;
132
    $tags['HELLO']              = _ADSLIGHT_HELLO;
133
    $tags['LID']                = $lid;
134
    $tags['LISTING_NUMBER']     = _ADSLIGHT_LISTING_NUMBER;
135
    $tags['TITLE']              = $title;
136
    $tags['TYPE']               = AdslightUtility::getNameType($type);
137
    $tags['DESCTEXT']           = $desctext;
138
    $tags['PRICE']              = $price;
139
    $tags['TYPEPRICE']          = $typeprice;
140
    $tags['TEL']                = $tel;
141
    $tags['TOWN']               = $town;
142
    $tags['COUNTRY']            = $country;
143
    $tags['OTHER']              = '' . _ADSLIGHT_INTERESS . '' . $xoopsConfig['sitename'] . '';
144
    $tags['LISTINGS']           = '' . XOOPS_URL . '/modules/adslight/';
145
    $tags['LINK_URL']           = '' . XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid . '';
146
    $tags['THINKS_REPORT']      = '' . _ADSLIGHT_REPORTMESSAGE . '';
147
    $tags['NO_MAIL']            = '' . _ADSLIGHT_NOMAIL . '';
148
    $tags['YOU_CAN_VIEW_BELOW'] = '' . _ADSLIGHT_YOU_CAN_VIEW_BELOW . '';
149
    $tags['WEBMASTER']          = _ADSLIGHT_WEBMASTER;
150
    $tags['NO_REPLY']           = _ADSLIGHT_NOREPLY;
151
    $subject                    = '' . _ADSLIGHT_REPORTSUBJET . ' ' . $xoopsConfig['sitename'] . '';
152
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_report_abuse.tpl');
158
    $xoopsMailer->setFromEmail($ymail);
159
    $xoopsMailer->setToEmails($fmail);
160
    $xoopsMailer->setSubject($subject);
161
    $xoopsMailer->assign($tags);
162
163
    // $fmail = $xoopsConfig['adminmail'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
164
    // $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
165
    // $idde = $xoopsUserIsAdmin->getVar("adminmail", "E");
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
167
    $xoopsMailer->send();
168
    echo $xoopsMailer->getErrors();
169
170
    redirect_header('index.php', 3, _ADSLIGHT_REPORTANNSEND);
171
}
172
173
##############################################################
174
$yname = Request::getString('yname', '', 'POST');
175
$ymail = Request::getString('ymail', '', 'POST');
176
$fname = Request::getString('fname', '', 'POST');
177
$fmail = Request::getString('fmail', '', 'POST');
178
179
$lid = Request::getInt('lid', 0);
180
$op  = Request::getString('op', '');
181
182 View Code Duplication
switch ($op) {
183
    case 'ReportAbuse':
184
        include XOOPS_ROOT_PATH . '/header.php';
185
        ReportAbuse($lid);
186
        include XOOPS_ROOT_PATH . '/footer.php';
187
        break;
188
189
    case 'MailAd':
190
        MailAd($lid, $yname, $ymail, $fname, $fmail);
191
        break;
192
193
    default:
194
        redirect_header('index.php', 1, _RETURNANN);
195
        break;
196
}
197