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

print.php ➔ PrintAd()   C

Complexity

Conditions 8
Paths 96

Size

Total Lines 86
Code Lines 54

Duplication

Lines 7
Ratio 8.14 %

Importance

Changes 0
Metric Value
cc 8
eloc 54
nc 96
nop 1
dl 7
loc 86
rs 5.7638
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_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
function PrintAd($lid)
33
{
34
    global $xoopsConfig, $xoopsDB, $useroffset, $myts, $xoopsLogger, $moduleDirName, $main_lang;
35
36
    $currenttheme = $xoopsConfig['theme_set'];
37
    $lid          = (int)$lid;
38
39
    $result = $xoopsDB->query('SELECT l.lid, l.title, l.expire, l.type, l.desctext, l.tel, l.price, l.typeprice, l.date, l.email, l.submitter, l.town, l.country, l.photo, p.cod_img, p.lid, p.uid_owner, p.url FROM '
40
                              . $xoopsDB->prefix('adslight_listing')
41
                              . ' l LEFT JOIN '
42
                              . $xoopsDB->prefix('adslight_pictures')
43
                              . ' p ON l.lid=p.lid WHERE l.lid='
44
                              . $xoopsDB->escape($lid));
45
    list($lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date, $email, $submitter, $town, $country, $photo, $cod_img, $pic_lid, $uid_owner, $url) = $xoopsDB->fetchRow($result);
0 ignored issues
show
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 $cod_img 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 $pic_lid 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 $uid_owner 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...
46
47
    $title     = $myts->htmlSpecialChars($title);
48
    $expire    = $myts->htmlSpecialChars($expire);
49
    $type      = AdslightUtility::getNameType($myts->htmlSpecialChars($type));
50
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
51
    $tel       = $myts->htmlSpecialChars($tel);
52
    $price     = $myts->htmlSpecialChars($price);
53
    $typeprice = $myts->htmlSpecialChars($typeprice);
54
    $submitter = $myts->htmlSpecialChars($submitter);
55
    $town      = $myts->htmlSpecialChars($town);
56
    $country   = $myts->htmlSpecialChars($country);
57
58
    echo '
59
    <html>
60
    <head><title>' . $xoopsConfig['sitename'] . "</title>
61
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" >
62
    <meta http-equiv=\”robots\” content=\"noindex, nofollow, noarchive\" >
63
    <link rel=\"StyleSheet\" href=\"../../themes/" . $currenttheme . "/style/style.css\" type=\"text/css\">
64
    </head>
65
    <body bgcolor=\"#FFFFFF\" text=\"#000000\">
66
    <table border=0><tr><td>
67
    <table border=0 width=100% cellpadding=0 cellspacing=1 bgcolor=\"#000000\"><tr><td>
68
    <table border=0 width=100% cellpadding=15 cellspacing=1 bgcolor=\"#FFFFFF\"><tr><td>";
69
70
    $useroffset = 0;
71 View Code Duplication
    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...
72
        $timezone   = $GLOBALS['xoopsUser']->timezone();
73
        $useroffset = (!empty($timezone)) ? $GLOBALS['xoopsUser']->timezone() : $xoopsConfig['default_TZ'];
74
    }
75
    $date  = ($useroffset * 3600) + $date;
76
    $date2 = $date + ($expire * 86400);
77
    $date  = formatTimestamp($date, 's');
78
    $date2 = formatTimestamp($date2, 's');
79
80
    echo '<br><br><table width=99% border=0>
81
        <tr>
82
      <td>' . _ADSLIGHT_CLASSIFIED . " (No. $lid ) <br>" . _ADSLIGHT_FROM . " $submitter <br><br>";
83
84
    echo " <strong>$type :</strong> <i>$title</i><br>";
85 View Code Duplication
    if ($price > 0) {
86
        echo '<strong>' . _ADSLIGHT_PRICE2 . "</strong> $price " . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol'] . "  - $typeprice<br>";
87
    }
88
    if ($photo) {
89
        echo "<tr><td><div style='text-align:left'><img class=\"thumb\" src=\"" . XOOPS_URL . "/uploads/AdsLight/$url\" width=\"130px\" border=0 ></div>";
90
    }
91
    echo '</td>
92
          </tr>
93
    <tr>
94
      <td><strong>' . _ADSLIGHT_DESC . "</strong><br><br><div style=\"text-align:justify;\">$desctext</div><p>";
95
    if ($tel) {
96
        echo '<br><strong>' . _ADSLIGHT_TEL . "</strong> $tel";
97
    }
98
    if ($town) {
99
        echo '<br><strong>' . _ADSLIGHT_TOWN . "</strong> $town";
100
    }
101
    if ($country) {
102
        echo '<br><strong>' . _ADSLIGHT_COUNTRY . "</strong> $country";
103
    }
104
    echo '<hr>';
105
    echo '' . _ADSLIGHT_NOMAIL . ' <br>' . XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid . '<br>';
106
    echo '<br><br>' . _ADSLIGHT_DATE2 . " $date " . _ADSLIGHT_AND . ' ' . _ADSLIGHT_DISPO . " $date2<br><br>";
107
    echo '</td>
108
    </tr>
109
    </table>';
110
    echo '<br><br></td></tr></table></td></tr></table>
111
    <br><br><div style="text-align:center">
112
    ' . _ADSLIGHT_EXTRANN . ' <strong>' . $xoopsConfig['sitename'] . "</strong></div><br>
113
    <a href=\"" . XOOPS_URL . "/modules/adslight/\">" . XOOPS_URL . '/modules/adslight/</a>
114
    </td></tr></table>
115
    </body>
116
    </html>';
117
}
118
119
##############################################################
120
121
$lid = Request::getInt('lid', 0);
122
$op  = Request::getString('op', '');
123
124
switch ($op) {
125
126
    case 'PrintAd':
127
        PrintAd($lid);
128
        break;
129
130
    default:
131
        redirect_header('index.php', 3, ' ' . _RETURNANN . ' ');
132
        break;
133
134
}
135