Completed
Push — master ( 25ce06...a84b6a )
by Michael
02:49
created

sendfriend.php (17 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 29 and the first side effect is on line 22.

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
include_once __DIR__ . '/header.php';
23
require XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
24
//include XOOPS_ROOT_PATH . '/modules/adslight/class/utilities.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
25
26
/**
27
 * @param $lid
28
 */
29
function SendFriend($lid)
30
{
31
    global $xoopsConfig, $xoopsModuleConfig, $xoopsDB, $xoopsUser, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
32
33
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
34
    include XOOPS_ROOT_PATH . '/header.php';
35
    $xoTheme->addMeta('meta', 'robots', 'noindex, nofollow');
0 ignored issues
show
The variable $xoTheme does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
37
    $result = $xoopsDB->query('SELECT lid, title, type FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid={$lid}");
38
    list($lid, $title, $type) = $xoopsDB->fetchRow($result);
39
40
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>
41
        <strong>" . _ADSLIGHT_SENDTO . " $lid \"<strong>$type : $title</strong>\" " . _ADSLIGHT_FRIEND . "<br><br>
42
        <form action=\"sendfriend.php\" method=post>
43
        <input type=\"hidden\" name=\"lid\" value=\"$lid\" />";
44
45
    if ($xoopsUser instanceof XoopsUser) {
0 ignored issues
show
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...
46
        $idd  = $xoopsUser->getVar('uname', 'E');
47
        $idde = $xoopsUser->getVar('email', 'E');
48
    }
49
50
    echo "
51
    <table width='99%' class='outer' cellspacing='1'>
52
    <tr>
53
      <td class='head' width='30%'>" . _ADSLIGHT_NAME . " </td>
54
      <td class='even'><input class='textbox' type='text' name='yname' value='$idd' /></td>
0 ignored issues
show
The variable $idd does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
55
    </tr>
56
    <tr>
57
      <td class='head'>" . _ADSLIGHT_MAIL . " </td>
58
      <td class='even'><input class='textbox' type='text' name='ymail' value='$idde' /></td>
0 ignored issues
show
The variable $idde does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
59
    </tr>
60
    <tr>
61
      <td class='head'>" . _ADSLIGHT_NAMEFR . " </td>
62
      <td class='even'><input class='textbox' type='text' name='fname' /></td>
63
    </tr>
64
    <tr>
65
      <td class='head'>" . _ADSLIGHT_MAILFR . " </td>
66
      <td class='even'><input class='textbox' type='text' name='fmail' /></td>
67
    </tr>";
68
69 View Code Duplication
    if ($xoopsModuleConfig['adslight_use_captcha'] == '1') {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
        echo "<tr><td class='head'>" . _ADSLIGHT_CAPTCHA . " </td><td class='even'>";
71
        $jlm_captcha = '';
0 ignored issues
show
$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...
72
        $jlm_captcha = new XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, 'xoopscaptcha', false);
73
        echo $jlm_captcha->render();
74
        echo '</td></tr>';
75
    }
76
77
    echo '</table><br>
78
    <input type=hidden name=op value=MailAd>
79
    <input type=submit value=' . _ADSLIGHT_SENDFR . '>
80
    </form></td></tr></table>';
81
}
82
83
/**
84
 * @param $lid
85
 * @param $yname
86
 * @param $ymail
87
 * @param $fname
88
 * @param $fmail
89
 */
90
function MailAd($lid, $yname, $ymail, $fname, $fmail)
0 ignored issues
show
The function MailAd() has been defined more than once; this definition is ignored, only the first definition in report-abuse.php (L94-169) 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...
91
{
92
    global $xoopsConfig, $xoopsUser, $xoopsTpl, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $myts, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
93
94
    if ('1' == $xoopsModuleConfig['adslight_use_captcha']) {
95
        xoops_load('xoopscaptcha');
96
        $xoopsCaptcha = XoopsCaptcha::getInstance();
97
        if (!$xoopsCaptcha->verify()) {
98
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 2, $xoopsCaptcha->getMessage());
99
        }
100
    }
101
102
    $result = $xoopsDB->query('SELECT lid, title, expire, type, desctext, tel, price, typeprice, date, email, submitter, town, country, photo FROM '
103
                              . $xoopsDB->prefix('adslight_listing')
104
                              . ' WHERE lid='
105
                              . $xoopsDB->escape($lid)
106
                              . '');
107
    list($lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date, $email, $submitter, $town, $country, $photo) = $xoopsDB->fetchRow($result);
0 ignored issues
show
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...
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...
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...
108
109
    $title     = $myts->addSlashes($title);
110
    $expire    = $myts->addSlashes($expire);
0 ignored issues
show
$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...
111
    $type      = $myts->addSlashes($type);
112
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
113
    $tel       = $myts->addSlashes($tel);
114
    $price     = $myts->addSlashes($price);
115
    $typeprice = $myts->addSlashes($typeprice);
116
    $submitter = $myts->addSlashes($submitter);
0 ignored issues
show
$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...
117
    $town      = $myts->addSlashes($town);
118
    $country   = $myts->addSlashes($country);
119
120
    $tags                       = array();
121
    $tags['YNAME']              = stripslashes($yname);
122
    $tags['YMAIL']              = $ymail;
123
    $tags['FNAME']              = stripslashes($fname);
124
    $tags['FMAIL']              = $fmail;
125
    $tags['HELLO']              = _ADSLIGHT_HELLO;
126
    $tags['LID']                = $lid;
127
    $tags['LISTING_NUMBER']     = _ADSLIGHT_LISTING_NUMBER;
128
    $tags['TITLE']              = $title;
129
    $tags['TYPE']               = AdslightUtilities::getNameType($type);
130
    $tags['DESCTEXT']           = $desctext;
131
    $tags['PRICE']              = $price;
132
    $tags['TYPEPRICE']          = $typeprice;
133
    $tags['TEL']                = $tel;
134
    $tags['TOWN']               = $town;
135
    $tags['COUNTRY']            = $country;
136
    $tags['OTHER']              = '' . _ADSLIGHT_INTERESS . '' . $xoopsConfig['sitename'] . '';
137
    $tags['LISTINGS']           = XOOPS_URL . '/modules/adslight/';
138
    $tags['LINK_URL']           = XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid;
139
    $tags['THINKS_INTERESTING'] = _ADSLIGHT_MESSAGE;
140
    $tags['NO_MAIL']            = _ADSLIGHT_NOMAIL;
141
    $tags['YOU_CAN_VIEW_BELOW'] = _ADSLIGHT_YOU_CAN_VIEW_BELOW;
142
    $tags['WEBMASTER']          = _ADSLIGHT_WEBMASTER;
143
    $tags['NO_REPLY']           = _ADSLIGHT_NOREPLY;
144
    $subject                    = '' . _ADSLIGHT_SUBJET . ' ' . $xoopsConfig['sitename'] . '';
145
    $xoopsMailer                =& xoops_getMailer();
146
    $xoopsMailer->multimailer->isHTML(true);
147
    $xoopsMailer->useMail();
148
    $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
149
    $xoopsMailer->setTemplate('listing_send_friend.tpl');
150
    $xoopsMailer->setFromEmail($ymail);
151
    $xoopsMailer->setToEmails($fmail);
152
    $xoopsMailer->setSubject($subject);
153
    $xoopsMailer->assign($tags);
154
    $xoopsMailer->send();
155
    echo $xoopsMailer->getErrors();
156
157
    redirect_header('index.php', 3, _ADSLIGHT_ANNSEND);
158
}
159
160
##############################################################
161
$yname = !empty($_POST['yname']) ? $myts->addSlashes($_POST['yname']) : '';
162
$ymail = !empty($_POST['ymail']) ? $myts->addSlashes($_POST['ymail']) : '';
163
$fname = !empty($_POST['fname']) ? $myts->addSlashes($_POST['fname']) : '';
164
$fmail = !empty($_POST['fmail']) ? $myts->addSlashes($_POST['fmail']) : '';
165
166
$lid = XoopsRequest::getInt('lid', 0);
167
$op  = XoopsRequest::getCmd('op', '');
168
169 View Code Duplication
switch ($op) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
171
    case 'SendFriend':
172
        include XOOPS_ROOT_PATH . '/header.php';
173
        SendFriend($lid);
174
        include XOOPS_ROOT_PATH . '/footer.php';
175
        break;
176
177
    case 'MailAd':
178
        MailAd($lid, $yname, $ymail, $fname, $fmail);
179
        break;
180
181
    default:
182
        redirect_header('index.php', 1, '' . _RETURNGLO . '');
183
        break;
184
185
}
186