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

sendfriend.php ➔ SendFriend()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 53
Code Lines 29

Duplication

Lines 7
Ratio 13.21 %

Importance

Changes 0
Metric Value
cc 3
eloc 29
nc 4
nop 1
dl 7
loc 53
rs 9.5797
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 32 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 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
function SendFriend($lid)
33
{
34
    global $xoopsConfig, $xoopsDB, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
35
    $idd = $idde = $iddee = '';
36
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
37
    include XOOPS_ROOT_PATH . '/header.php';
38
    $GLOBALS['xoTheme']->addMeta('meta', 'robots', 'noindex, nofollow');
39
40
    $result = $xoopsDB->query('SELECT lid, title, type FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid={$lid}");
41
    list($lid, $title, $type) = $xoopsDB->fetchRow($result);
42
43
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>
44
        <strong>" . _ADSLIGHT_SENDTO . " $lid \"<strong>$type : $title</strong>\" " . _ADSLIGHT_FRIEND . "<br><br>
45
        <form action=\"sendfriend.php\" method=post>
46
        <input type=\"hidden\" name=\"lid\" value=\"$lid\" >";
47
48
    if ($GLOBALS['xoopsUser'] instanceof XoopsUser) {
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
49
        $idd  = $GLOBALS['xoopsUser']->getVar('uname', 'E');
50
        $idde = $GLOBALS['xoopsUser']->getVar('email', 'E');
51
    }
52
53
    echo "
54
    <table width='99%' class='outer' cellspacing='1'>
55
    <tr>
56
      <td class='head' width='30%'>" . _ADSLIGHT_NAME . " </td>
57
      <td class='even'><input class='textbox' type='text' name='yname' value='$idd' ></td>
58
    </tr>
59
    <tr>
60
      <td class='head'>" . _ADSLIGHT_MAIL . " </td>
61
      <td class='even'><input class='textbox' type='text' name='ymail' value='$idde' ></td>
62
    </tr>
63
    <tr>
64
      <td class='head'>" . _ADSLIGHT_NAMEFR . " </td>
65
      <td class='even'><input class='textbox' type='text' name='fname' ></td>
66
    </tr>
67
    <tr>
68
      <td class='head'>" . _ADSLIGHT_MAILFR . " </td>
69
      <td class='even'><input class='textbox' type='text' name='fmail' ></td>
70
    </tr>";
71
72 View Code Duplication
    if ($GLOBALS['xoopsModuleConfig']['adslight_use_captcha'] == '1') {
73
        echo "<tr><td class='head'>" . _ADSLIGHT_CAPTCHA . " </td><td class='even'>";
74
        $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...
75
        $jlm_captcha = new XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, 'xoopscaptcha', false);
76
        echo $jlm_captcha->render();
77
        echo '</td></tr>';
78
    }
79
80
    echo '</table><br>
81
    <input type=hidden name=op value=MailAd>
82
    <input type=submit value=' . _ADSLIGHT_SENDFR . '>
83
    </form></td></tr></table>';
84
}
85
86
/**
87
 * @param $lid
88
 * @param $yname
89
 * @param $ymail
90
 * @param $fname
91
 * @param $fmail
92
 */
93
function MailAd($lid, $yname, $ymail, $fname, $fmail)
0 ignored issues
show
Best Practice introduced by
The function MailAd() has been defined more than once; this definition is ignored, only the first definition in report-abuse.php (L97-171) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
94
{
95
    global $xoopsConfig, $xoopsTpl, $xoopsDB, $xoopsModule, $myts, $xoopsLogger, $moduleDirName, $main_lang;
96
97 View Code Duplication
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_captcha']) {
98
        xoops_load('xoopscaptcha');
99
        $xoopsCaptcha = XoopsCaptcha::getInstance();
100
        if (!$xoopsCaptcha->verify()) {
101
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 2, $xoopsCaptcha->getMessage());
102
        }
103
    }
104
105
    $result = $xoopsDB->query('SELECT lid, title, expire, type, desctext, tel, price, typeprice, date, email, submitter, town, country, photo FROM '
106
                              . $xoopsDB->prefix('adslight_listing')
107
                              . ' WHERE lid='
108
                              . $xoopsDB->escape($lid));
109
    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...
110
111
    $title     = $myts->addSlashes($title);
112
    $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...
113
    $type      = $myts->addSlashes($type);
114
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
115
    $tel       = $myts->addSlashes($tel);
116
    $price     = $myts->addSlashes($price);
117
    $typeprice = $myts->addSlashes($typeprice);
118
    $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...
119
    $town      = $myts->addSlashes($town);
120
    $country   = $myts->addSlashes($country);
121
122
    $tags                       = array();
123
    $tags['YNAME']              = stripslashes($yname);
124
    $tags['YMAIL']              = $ymail;
125
    $tags['FNAME']              = stripslashes($fname);
126
    $tags['FMAIL']              = $fmail;
127
    $tags['HELLO']              = _ADSLIGHT_HELLO;
128
    $tags['LID']                = $lid;
129
    $tags['LISTING_NUMBER']     = _ADSLIGHT_LISTING_NUMBER;
130
    $tags['TITLE']              = $title;
131
    $tags['TYPE']               = AdslightUtility::getNameType($type);
132
    $tags['DESCTEXT']           = $desctext;
133
    $tags['PRICE']              = $price;
134
    $tags['TYPEPRICE']          = $typeprice;
135
    $tags['TEL']                = $tel;
136
    $tags['TOWN']               = $town;
137
    $tags['COUNTRY']            = $country;
138
    $tags['OTHER']              = '' . _ADSLIGHT_INTERESS . '' . $xoopsConfig['sitename'] . '';
139
    $tags['LISTINGS']           = XOOPS_URL . '/modules/adslight/';
140
    $tags['LINK_URL']           = XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid;
141
    $tags['THINKS_INTERESTING'] = _ADSLIGHT_MESSAGE;
142
    $tags['NO_MAIL']            = _ADSLIGHT_NOMAIL;
143
    $tags['YOU_CAN_VIEW_BELOW'] = _ADSLIGHT_YOU_CAN_VIEW_BELOW;
144
    $tags['WEBMASTER']          = _ADSLIGHT_WEBMASTER;
145
    $tags['NO_REPLY']           = _ADSLIGHT_NOREPLY;
146
    $subject                    = '' . _ADSLIGHT_SUBJET . ' ' . $xoopsConfig['sitename'] . '';
147
    $xoopsMailer                = xoops_getMailer();
148
    $xoopsMailer->multimailer->isHTML(true);
149
    $xoopsMailer->useMail();
150
    $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
151
    $xoopsMailer->setTemplate('listing_send_friend.tpl');
152
    $xoopsMailer->setFromEmail($ymail);
153
    $xoopsMailer->setToEmails($fmail);
154
    $xoopsMailer->setSubject($subject);
155
    $xoopsMailer->assign($tags);
156
    $xoopsMailer->send();
157
    echo $xoopsMailer->getErrors();
158
159
    redirect_header('index.php', 3, _ADSLIGHT_ANNSEND);
160
}
161
162
##############################################################
163
$yname = Request::getString('yname', '', 'POST');
164
$ymail = Request::getString('ymail', '', 'POST');
165
$fname = Request::getString('fname', '', 'POST');
166
$fmail = Request::getString('fmail', '', 'POST');
167
168
$lid = Request::getInt('lid', 0);
169
$op  = Request::getString('op', '');
170
171 View Code Duplication
switch ($op) {
172
173
    case 'SendFriend':
174
        include XOOPS_ROOT_PATH . '/header.php';
175
        SendFriend($lid);
176
        include XOOPS_ROOT_PATH . '/footer.php';
177
        break;
178
179
    case 'MailAd':
180
        MailAd($lid, $yname, $ymail, $fname, $fmail);
181
        break;
182
183
    default:
184
        redirect_header('index.php', 1, ' ' . _RETURNANN . ' ');
185
        break;
186
187
}
188