Completed
Push — master ( ded118...cf7347 )
by Michael
02:48
created

entry.php ➔ entrySave()   F

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 143
Code Lines 115

Duplication

Lines 49
Ratio 34.27 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 28
eloc 115
c 1
b 0
f 0
nc 380928
nop 1
dl 49
loc 143
rs 2

How to fix   Long Method    Complexity   

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

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
 * $Id: entry.php v 1.0 8 May 2004 hsalazar Exp $
4
 * Module: Lexikon - glossary module
5
 * Version: v 1.00
6
 * Release Date: 8 May 2004
7
 * Author: hsalazar
8
 * Modifs: Yerres
9
 * Licence: GNU
10
 */
11
12
include( "admin_header.php" );
13
$myts =& MyTextSanitizer::getInstance();
14
xoops_cp_header();
15
$indexAdmin = new ModuleAdmin();
16
echo $indexAdmin->addNavigation('entry.php');
17
$indexAdmin->addItemButton(_AM_LEXIKON_CREATEENTRY, 'entry.php?op=add', 'add');
18
echo $indexAdmin->renderButton('left');
19
20
$op = '';
21
#if ( isset( $_GET['op'] ) ) $op = $_GET['op'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
22
#if ( isset( $_POST['op'] ) ) $op = $_POST['op'];
23
error_reporting(E_ALL);
24
 error_reporting(E_ERROR | E_WARNING | E_PARSE);
25
/* -- Available operations -- */
26
function entryDefault() {
0 ignored issues
show
Coding Style introduced by
entryDefault uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
27
    global $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $entryID, $pathIcon16;
0 ignored issues
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...
28
    include_once XOOPS_ROOT_PATH . "/class/xoopslists.php";
29
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
30
    xoops_load('XoopsUserUtility');
31
//    lx_adminMenu(2, _AM_LEXIKON_ENTRIES);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
32
33
    $startentry = isset( $_GET['startentry'] ) ? intval( $_GET['startentry'] ) : 0;
34
    $startcat = isset( $_GET['startcat'] ) ? intval( $_GET['startcat'] ) : 0;
0 ignored issues
show
Unused Code introduced by
$startcat 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...
35
    $startsub = isset( $_GET['startsub'] ) ? intval( $_GET['startsub'] ) : 0;
0 ignored issues
show
Unused Code introduced by
$startsub 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...
36
    $datesub = isset( $_GET['datesub'] ) ? intval( $_GET['datesub'] ) : 0;
0 ignored issues
show
Unused Code introduced by
$datesub 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...
37
38
    $myts =& MyTextSanitizer::getInstance();
39
40
    $result01 = $xoopsDB -> query( "SELECT COUNT(*)
41
                                   FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
42
    list( $totalcategories ) = $xoopsDB -> fetchRow( $result01 );
0 ignored issues
show
Unused Code introduced by
The assignment to $totalcategories 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...
43
44
    $result02 = $xoopsDB -> query( "SELECT COUNT(*)
45
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
46
                                   WHERE submit = 0" );
47
    list( $totalpublished ) = $xoopsDB -> fetchRow( $result02 );
48
49
    $result03 = $xoopsDB -> query( "SELECT COUNT(*)
50
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
51
                                   WHERE submit = '1' AND request = '0' " );
52
    list( $totalsubmitted ) = $xoopsDB -> fetchRow( $result03 );
0 ignored issues
show
Unused Code introduced by
The assignment to $totalsubmitted 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...
53
54
    $result04 = $xoopsDB -> query( "SELECT COUNT(*)
55
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
56
                                   WHERE submit = '1' AND request = '1' " );
57
    list( $totalrequested ) = $xoopsDB -> fetchRow( $result04 );
0 ignored issues
show
Unused Code introduced by
The assignment to $totalrequested 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...
58
59
//    echo "<table width='100%' class='outer' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' ><tr>";
60
//    echo "<td class='odd'>" . _AM_LEXIKON_TOTALENTRIES . "</td><td align='center' class='even'>" . $totalpublished . "</td>";
61
//    if ($xoopsModuleConfig['multicats'] == 1) {
62
//        echo "<td class='odd'>" . _AM_LEXIKON_TOTALCATS . "</td><td align='center' class='even'>" . $totalcategories . "</td>";
63
//    }
64
//    echo "<td class='odd'>" . _AM_LEXIKON_TOTALSUBM . "</td><td align='center' class='even'>" . $totalsubmitted . "</td>
65
//    <td class='odd'>" . _AM_LEXIKON_TOTALREQ . "</td><td align='center' class='even'>" . $totalrequested . "</td>
66
//    </tr></table>
67
//    <br /><br />";
68
//
69
    /**
70
    * Code to show existing terms
71
    **/
72
73
    // create existing terms table
74
    $resultA1 = $xoopsDB -> query( "SELECT COUNT(*)
75
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
76
                                   WHERE submit = 0" );
77
    list( $numrows ) = $xoopsDB -> fetchRow( $resultA1 );
78
79
    $sql = "SELECT entryID, categoryID, term, uid, datesub, offline
80
           FROM ".$xoopsDB->prefix('lxentries')."
81
           WHERE submit = 0
82
           ORDER BY entryID DESC";
83
    $resultA2 = $xoopsDB -> query( $sql, $xoopsModuleConfig['perpage'], $startentry );
84
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage']);
0 ignored issues
show
Unused Code introduced by
$result 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...
85
86
    echo "	<table class='outer' width='100%' border='0'>
87
    <tr>
88
    <td colspan='7' class='odd'>
89
    <strong>". _AM_LEXIKON_SHOWENTRIES . ' (' . $totalpublished . ')'. "</strong></td></TR>";
90
    echo "<tr>";
91
92
    echo "<th width='40' align='center'><b>" . _AM_LEXIKON_ENTRYID . "</A></b></td>";
93
    if ($xoopsModuleConfig['multicats'] == 1) {
94
        echo "<th width='20%'  align='center'><b>" . _AM_LEXIKON_ENTRYCATNAME . "</b></td>";
95
    }
96
    echo "<th width='*' align='center'><b>" . _AM_LEXIKON_ENTRYTERM . "</b></td>
97
    <th width='90'  align='center'><b>" . _AM_LEXIKON_SUBMITTER . "</b></td>
98
    <th width='90'  align='center'><b>" . _AM_LEXIKON_ENTRYCREATED . "</b></td>
99
    <th width='30'  align='center'><b>" . _AM_LEXIKON_STATUS . "</b></td>
100
    <th width='60'  align='center'><b>" . _AM_LEXIKON_ACTION . "</b></td>
101
    </tr>";
102
    $class   = "odd";
103
    if ( $numrows > 0 ) // That is, if there ARE entries in the system
104
105
    {
106
        while ( list( $entryID, $categoryID, $term, $uid, $created, $offline ) = $xoopsDB -> fetchrow( $resultA2 ) ) {
107
            $resultA3 = $xoopsDB -> query( "SELECT name
108
                                           FROM " . $xoopsDB -> prefix( "lxcategories" ) . "
109
                                           WHERE categoryID = '$categoryID'" );
110
            list( $name ) = $xoopsDB -> fetchrow( $resultA3 );
111
112
            $sentby = XoopsUserUtility::getUnameFromId($uid);
113
            $catname = $myts -> htmlSpecialChars( $name );
114
            $term = $myts -> htmlSpecialChars( $term );
115
            $created= formatTimestamp( $created, 's' );
116
            $modify = "<a href='entry.php?op=mod&entryID=" . $entryID . "'><img src=" . $pathIcon16."/edit.png width='16' height='16' ALT='"._AM_LEXIKON_EDITENTRY."'></a>";
117
            $delete = "<a href='entry.php?op=del&entryID=" . $entryID . "'><img src=" . $pathIcon16."/delete.png width='16' height='16' ALT='"._AM_LEXIKON_DELETEENTRY."'></a>";
118
119 View Code Duplication
            if ( $offline == 0 ) {
0 ignored issues
show
Duplication introduced by
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...
120
                $status = "<img src=" . XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/images/icon/on.gif alt='"._AM_LEXIKON_ENTRYISON."'>";
121
            } else {
122
                $status = "<img src=" . XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/images/icon/off.gif alt='"._AM_LEXIKON_ENTRYISOFF."'>";
123
            }
124
            echo "<tr class='" . $class . "'>";
125
            $class = ($class == "even") ? "odd" : "even";
126
127
            echo "<td align='center'>" . $entryID . "</td>";
128
129
            if ($xoopsModuleConfig['multicats'] == 1) {
130
                echo "<td class='odd' align='left'>" . $catname . "</td>";
131
            }
132
            //echo "<td class='$class'align='left'>" . $term . "</td>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
133
            echo "<td class='odd'align='left'><a href='../entry.php?entryID=" . $entryID . "'>" . $term . "</td>
134
            <td class='odd' align='center'>" . $sentby . "</td>
135
            <td class='odd' align='center'>" . $created . "</td>
136
            <td class='odd' align='center'>" . $status . "</td>
137
            <td class='even' align='center'> $modify $delete </td>
138
            </tr></DIV>";
139
        }
140
    }
141
    else // that is, $numrows = 0, there's no entries yet
142
    {
143
        echo "<tr>";
144
        echo "<td class='odd' align='center' colspan= '7'>"._AM_LEXIKON_NOTERMS."</td>";
145
        echo "</tr></DIV>";
146
    }
147
    echo "</table>\n";
148
    $pagenav = new XoopsPageNav( $numrows, $xoopsModuleConfig['perpage'], $startentry, 'startentry');
149
    echo '<div style="text-align:right;">' . $pagenav -> renderNav(8) . '</div>';
150
    echo "<br /><BR>\n";
151
    echo "</div>";
152
}
153
154
// -- Edit function --
155
function entryEdit( $entryID = '' ) {
156
  global $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $init;
0 ignored issues
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...
157
  $myts =& MyTextSanitizer::getInstance();
158
  /**
159
   * Clear all variables before we start
160
   */
161
    if(!isset($block)) { $block = 1; }
0 ignored issues
show
Bug introduced by
The variable $block seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
162
    if(!isset($html)) { $html = 1; }
0 ignored issues
show
Bug introduced by
The variable $html seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
163
    if(!isset($smiley)) { $smiley = 1; }
0 ignored issues
show
Bug introduced by
The variable $smiley seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
164
    if(!isset($xcodes)) { $xcodes = 1; }
0 ignored issues
show
Bug introduced by
The variable $xcodes seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
165
    if(!isset($breaks)) { $breaks = 1; }
0 ignored issues
show
Bug introduced by
The variable $breaks seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
166
    if(!isset($offline)) { $offline = 0; }
0 ignored issues
show
Bug introduced by
The variable $offline seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
167
    if(!isset($submit)) { $submit = 0; }
0 ignored issues
show
Bug introduced by
The variable $submit seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
168
    if(!isset($request)) { $request = 0; }
0 ignored issues
show
Bug introduced by
The variable $request seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
Unused Code introduced by
$request 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...
169
    if(!isset($notifypub)) { $notifypub = 1; }
0 ignored issues
show
Bug introduced by
The variable $notifypub seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
170
    if(!isset($categoryID)) { $categoryID = 1; }
0 ignored issues
show
Bug introduced by
The variable $categoryID seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
171
    if(!isset($term)) { $term = ""; }
0 ignored issues
show
Bug introduced by
The variable $term seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
172
  if(!isset($init)) { $init = ""; }
173
  if (!isset($definition)) {
0 ignored issues
show
Bug introduced by
The variable $definition seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
174
      $definition = _AM_LEXIKON_WRITEHERE;
175
  }
176
    if(!isset($ref)) { $ref = ""; }
0 ignored issues
show
Bug introduced by
The variable $ref seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
177
    if(!isset($url)) { $url = ""; }
0 ignored issues
show
Bug introduced by
The variable $url seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
178
    if(!isset($datesub)) { $datesub = 0; }
0 ignored issues
show
Bug introduced by
The variable $datesub seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
Unused Code introduced by
$datesub 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...
179
180
    // If there is a parameter, and the id exists, retrieve data: we're editing an entry
181
    if ( $entryID ) {
182
        $result = $xoopsDB -> query( "
183
                                     SELECT categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub, request
184
                                     FROM " . $xoopsDB -> prefix( "lxentries" ) . "
185
                                     WHERE entryID = '$entryID'" );
186
        list( $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $html, $smiley, $xcodes, $breaks, $block, $offline, $notifypub, $request ) = $xoopsDB -> fetchrow( $result );
0 ignored issues
show
Unused Code introduced by
The assignment to $datesub 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 $request 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...
187
188
        if ( !$xoopsDB -> getRowsNum( $result ) ) {
189
            redirect_header( "index.php", 1, _AM_LEXIKON_NOENTRYTOEDIT );
190
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function entryEdit() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
191
        }
192
        $term = $myts->stripSlashesGPC($myts->htmlSpecialChars($term));
193
194
//        lx_adminMenu(2, _AM_LEXIKON_ADMINENTRYMNGMT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
195
196
        echo "<h3 style=\"color: #2F5376; margin-top: 6px; \">" . _AM_LEXIKON_ADMINENTRYMNGMT . "</h3>";
197
        $sform = new XoopsThemeForm( _AM_LEXIKON_MODENTRY . ": $term" , "op", xoops_getenv( 'PHP_SELF' ) );
198
    } else // there's no parameter, so we're adding an entry
199
    {
200
        $result01 = $xoopsDB -> query( "SELECT COUNT(*) FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
201
        list( $totalcats ) = $xoopsDB -> fetchRow( $result01 );
202
        if ( $totalcats == 0 && $xoopsModuleConfig['multicats'] == 1 ) {
203
            redirect_header( "index.php", 1, _AM_LEXIKON_NEEDONECOLUMN );
204
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function entryEdit() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
205
        }
206
//        lx_adminMenu(2, _AM_LEXIKON_ADMINENTRYMNGMT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
207
        $uid = $xoopsUser->getVar('uid');
208
        echo "<h3 style=\"color: #2F5376; margin-top: 6px; \">" . _AM_LEXIKON_ADMINENTRYMNGMT . "</h3>";
209
        $sform = new XoopsThemeForm( _AM_LEXIKON_NEWENTRY, "op", xoops_getenv( 'PHP_SELF' ) );
210
    }
211
212
    $sform -> setExtra( 'enctype="multipart/form-data"' );
213
    // Category selector
214
    if ($xoopsModuleConfig['multicats'] == 1) {
215
        $mytree = new XoopsTree( $xoopsDB->prefix( "lxcategories" ), "categoryID" , "0" );
216
        $categoryselect = new XoopsFormSelect(_AM_LEXIKON_CATNAME, 'categoryID', $categoryID);
217
        $tbl = array();
0 ignored issues
show
Unused Code introduced by
$tbl 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...
218
        $tbl = $mytree->getChildTreeArray(0,'name');
219 View Code Duplication
        foreach($tbl as $oneline) {
0 ignored issues
show
Duplication introduced by
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...
220
            if ($oneline['prefix']=='.') {
221
                $oneline['prefix']='';
222
            }
223
            $oneline['prefix'] = str_replace('.','-',$oneline['prefix']);
224
            $categoryselect->addOption($oneline['categoryID'], $oneline['prefix'].' '.$oneline['name']);
225
        }
226
        $sform->addElement($categoryselect,true);
227
    }
228
229
    // Author selector
230
    ob_start();
231
    lx_getuserForm( intval($uid) );
232
    $sform -> addElement( new XoopsFormLabel( _AM_LEXIKON_AUTHOR, ob_get_contents() ) );
233
    ob_end_clean();
234
235
    // Initial selector
236
    ob_start();
237
    lx_getinit( intval($init) );
238
    $sform -> addElement( new XoopsFormLabel( _AM_LEXIKON_INIT, ob_get_contents() ) );
239
    ob_end_clean();
240
241
    // Term, definition, reference and related URL
242
    $sform -> addElement( new XoopsFormText( _AM_LEXIKON_ENTRYTERM, 'term', 50, 80, $term ), true );
243
244
    // set editor according to the module's option "form_options"
245
    $editor = lx_getWysiwygForm( _AM_LEXIKON_ENTRYDEF, 'definition', $definition, 15, 60 );
246
    if ($definition == _MD_LEXIKON_WRITEHERE) {
247
        $editor -> setExtra( 'onfocus="this.select()"' );
248
    }
249
    $sform -> addElement( $editor,true );
250
    unset($editor);
251
252
    $sform -> addElement( new XoopsFormTextArea( _AM_LEXIKON_ENTRYREFERENCE, 'ref', $ref, 5, 60 ), false );
253
    $sform -> addElement( new XoopsFormText( _AM_LEXIKON_ENTRYURL, 'url', 50, 80, $url ), false );
254
255
    // tags of this term - for module 'Tag'
256
    $module_handler = xoops_gethandler('module');
257
    $tagsModule = $module_handler->getByDirname("tag");
258
    if (is_object($tagsModule)) {
259
        include_once XOOPS_ROOT_PATH."/modules/tag/include/formtag.php";
260
        $sform->addElement(new XoopsFormTag("item_tag", 60, 255, $entryID, $catid = 0));
261
    }
262
    // Code to take entry offline, for maintenance purposes
263
    $offline_radio = new XoopsFormRadioYN(_AM_LEXIKON_SWITCHOFFLINE, 'offline', $offline, ' '._AM_LEXIKON_YES.'', ' '._AM_LEXIKON_NO.'');
264
    $sform -> addElement($offline_radio);
265
266
    // Code to put entry in block
267
    $block_radio = new XoopsFormRadioYN( _AM_LEXIKON_BLOCK, 'block', $block , ' ' . _AM_LEXIKON_YES . '', ' ' . _AM_LEXIKON_NO . '' );
268
    $sform -> addElement( $block_radio );
269
270
    // VARIOUS OPTIONS
271
    $options_tray = new XoopsFormElementTray(_AM_LEXIKON_OPTIONS,'<br />');
272
    if ($submit) {
273
        $notify_checkbox = new XoopsFormCheckBox('', 'notifypub', $notifypub);
274
        $notify_checkbox->addOption(1, _AM_LEXIKON_NOTIFYPUBLISH);
275
        $options_tray->addElement($notify_checkbox);
276
    }else{
277
        $notifypub=0;
0 ignored issues
show
Unused Code introduced by
$notifypub 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...
278
    }
279
    $html_checkbox = new XoopsFormCheckBox( '', 'html', $html );
280
    $html_checkbox -> addOption( 1, _AM_LEXIKON_DOHTML );
281
    $options_tray -> addElement( $html_checkbox );
282
283
    $smiley_checkbox = new XoopsFormCheckBox( '', 'smiley', $smiley );
284
    $smiley_checkbox -> addOption( 1, _AM_LEXIKON_DOSMILEY );
285
    $options_tray -> addElement( $smiley_checkbox );
286
287
    $xcodes_checkbox = new XoopsFormCheckBox( '', 'xcodes', $xcodes );
288
    $xcodes_checkbox -> addOption( 1, _AM_LEXIKON_DOXCODE );
289
    $options_tray -> addElement( $xcodes_checkbox );
290
291
    $breaks_checkbox = new XoopsFormCheckBox( '', 'breaks', $breaks );
292
    $breaks_checkbox -> addOption( 1, _AM_LEXIKON_BREAKS );
293
    $options_tray -> addElement( $breaks_checkbox );
294
295
    $sform -> addElement( $options_tray );
296
297
    $sform -> addElement( new XoopsFormHidden( 'entryID', $entryID ) );
298
299
    $button_tray = new XoopsFormElementTray( '', '' );
300
    $hidden = new XoopsFormHidden( 'op', 'addentry' );
301
    $button_tray -> addElement( $hidden );
302
303 View Code Duplication
    if ( !$entryID ) // there's no entryID? Then it's a new entry
0 ignored issues
show
Duplication introduced by
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...
304
    {
305
306
        $butt_create = new XoopsFormButton( '', '', _AM_LEXIKON_CREATE, 'submit' );
307
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addentry\'"');
308
        $button_tray->addElement( $butt_create );
309
310
        $butt_clear = new XoopsFormButton( '', '', _AM_LEXIKON_CLEAR, 'reset' );
311
        $button_tray->addElement( $butt_clear );
312
313
        $butt_cancel = new XoopsFormButton( '', '', _AM_LEXIKON_CANCEL, 'button' );
314
        $butt_cancel->setExtra('onclick="history.go(-1)"');
315
        $button_tray->addElement( $butt_cancel );
316
    } else // else, we're editing an existing entry
317
    {
318
        $butt_create = new XoopsFormButton( '', '', _AM_LEXIKON_MODIFY, 'submit' );
319
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addentry\'"');
320
        $button_tray->addElement( $butt_create );
321
322
        $butt_cancel = new XoopsFormButton( '', '', _AM_LEXIKON_CANCEL, 'button' );
323
        $butt_cancel->setExtra('onclick="history.go(-1)"');
324
        $button_tray->addElement( $butt_cancel );
325
    }
326
327
    $sform -> addElement( $button_tray );
328
    $sform -> display();
329
    unset( $hidden );
330
}
331
332
/* Save */
333
function entrySave ($entryID = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $entryID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
entrySave uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
entrySave uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
334
    Global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule, $xoopsDB;
0 ignored issues
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...
335
    $myts =& MyTextSanitizer::getInstance();
336
    $entryID = isset($_POST['entryID']) ? intval($_POST['entryID']) : intval($_GET['entryID']);
337
    if ($xoopsModuleConfig['multicats'] == 1) {
338
        $categoryID = isset($_POST['categoryID']) ? intval($_POST['categoryID']) : intval($_GET['categoryID']);
339
    } else {
340
        $categoryID = 1;
341
    }
342
    $block = isset($_POST['block']) ? intval($_POST['block']) : intval($_GET['block']);
343
    $breaks = isset($_POST['breaks']) ? intval($_POST['breaks']) : intval($_GET['breaks']);
344
345
    $html = isset($_POST['html']) ? intval($_POST['html']) : intval($_GET['html']);
346
    $smiley = isset($_POST['smiley']) ? intval($_POST['smiley']) : intval($_GET['smiley']);
347
    $xcodes = isset($_POST['xcodes']) ? intval($_POST['xcodes']) : intval($_GET['xcodes']);
348
    $offline = isset($_POST['offline']) ? intval($_POST['offline']) : intval($_GET['offline']);
349
    $init= $myts->addslashes($_POST['init']);
350
    $term = $myts->addSlashes(xoops_trim($_POST['term']));
351
    //$definition = $myts -> xoopsCodeDecode($_POST['definition'], $allowimage = 1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
352
    //$ref = isset($_POST['ref']) ? $myts->addSlashes($_POST['ref']) : '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
353
    $definition = $myts -> xoopsCodeDecode($myts->censorString($_POST['definition']), $allowimage = 1);
354
    $ref = isset($_POST['ref']) ? $myts->addSlashes($myts->censorString($_POST['ref'])) : '';
355
    $url = isset($_POST['url']) ? $myts->addSlashes($_POST['url']) : '';
356
357
    $date = time();
358
    $submit = 0;
359
    //$notifypub = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
360
    $notifypub = isset($_POST['notifypub']) ? intval($_POST['notifypub']) : intval($_GET['notifypub']);
361
    $request = 0;
362
    $uid = isset($_POST['author']) ? intval($_POST['author']) : $xoopsUser->uid();
363
364
    //-- module Tag
365
    $module_handler = xoops_gethandler('module');
366
    $tagsModule = $module_handler->getByDirname("tag");
367
    if (is_object($tagsModule)) {
368
        $tag_handler = xoops_getmodulehandler('tag', 'tag');
369
        $tag_handler->updateByItem($_POST["item_tag"], $entryID, $xoopsModule->getVar("dirname"), $catid =0);
370
    }
371
// Save to database
372
    if ( !$entryID ) {
373
        // verify that the term does not exists
374 View Code Duplication
        if (lx_TermExists($term,$xoopsDB->prefix('lxentries')))  redirect_header("javascript:history.go(-1)", 2,  _AM_LEXIKON_ITEMEXISTS . "<br />" . $term );
0 ignored issues
show
Duplication introduced by
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...
375
        if ( $xoopsDB -> query( "INSERT INTO " . $xoopsDB -> prefix( "lxentries" ) . " (entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub, request ) VALUES ('', '$categoryID', '$term', '$init', '$definition', '$ref', '$url', '$uid', '$submit', '$date', '$html', '$smiley', '$xcodes', '$breaks', '$block', '$offline', '$notifypub', '$request' )" ) ) {
376
              $newid = $xoopsDB->getInsertId();
377
            // Increment author's posts count (only if it's a new definition)
378 View Code Duplication
            if (is_object($xoopsUser) && empty($entryID)) {
0 ignored issues
show
Duplication introduced by
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...
379
                $member_handler = &xoops_gethandler('member');
380
                $submitter =& $member_handler -> getUser($uid);
381
                if (is_object($submitter) ) {
382
                    $submitter -> setVar('posts',$submitter -> getVar('posts') + 1);
383
                    $res=$member_handler -> insertUser($submitter, true);
0 ignored issues
show
Unused Code introduced by
$res 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...
384
                    unset($submitter);
385
                }
386
            }
387
            // trigger Notification only if its a new definition
388 View Code Duplication
            if(!empty($xoopsModuleConfig['notification_enabled']) ){
0 ignored issues
show
Duplication introduced by
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...
389
                global $xoopsModule;
0 ignored issues
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...
390
                if ($newid == 0) {
391
                    $newid = $xoopsDB->getInsertId();
392
                }
393
                $notification_handler =& xoops_gethandler('notification');
394
                $tags = array();
395
                $shortdefinition = $myts -> htmlSpecialChars(xoops_substr( strip_tags( $definition ),0,45));
396
                $tags['ITEM_NAME'] = $term;
397
                $tags['ITEM_BODY'] = $shortdefinition;
398
                $tags['DATESUB'] = formatTimestamp( $date, 'd M Y' );
399
                $tags['ITEM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/entry.php?entryID='. $newid;
400
                $sql = "SELECT name FROM " . $xoopsDB->prefix("lxcategories") . " WHERE categoryID=" . $categoryID;
401
                $result = $xoopsDB->query($sql);
402
                $row = $xoopsDB->fetchArray($result);
403
                $tags['CATEGORY_NAME'] = $row['name'];
404
                $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID;
405
                $notification_handler->triggerEvent('global', 0, 'new_post', $tags);
406
                $notification_handler->triggerEvent('category', $categoryID, 'new_post', $tags);
407
                //$notification_handler->triggerEvent('term', $newid, 'approve', $tags);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
408
            }
409
            lx_calculateTotals();
410
            redirect_header( "entry.php", 1, _AM_LEXIKON_ENTRYCREATEDOK );
411
        } else {
412
            redirect_header( "index.php", 1, _AM_LEXIKON_ENTRYNOTCREATED );
413
        }
414
    } else { // That is, $entryID exists, thus we're editing an entry
415
        if ( $xoopsDB -> query( "UPDATE " . $xoopsDB -> prefix( "lxentries" ) . " SET term = '$term', categoryID = '$categoryID', init = '$init', definition = '$definition', ref = '$ref', url = '$url', uid = '$uid', submit = '$submit', datesub = '$date', html = '$html', smiley = '$smiley', xcodes = '$xcodes', breaks = '$breaks', block = '$block', offline = '$offline', notifypub = '$notifypub', request = '$request' WHERE entryID = '$entryID'" ) ) {
416
            // trigger Notification only if its a new submission
417 View Code Duplication
            if(!empty($xoopsModuleConfig['notification_enabled']) ){
0 ignored issues
show
Duplication introduced by
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...
418
                global $xoopsModule;
0 ignored issues
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...
419
                $notification_handler =& xoops_gethandler('notification');
420
                $tags = array();
421
                $shortdefinition = $myts -> htmlSpecialChars(xoops_substr( strip_tags( $definition ),0,45));
422
                $tags['ITEM_NAME'] = $term;
423
                $tags['ITEM_BODY'] = $shortdefinition;
424
                $tags['DATESUB'] = formatTimestamp( $date, 'd M Y' );
425
                $tags['ITEM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/entry.php?entryID='. $entryID;
426
                $sql = "SELECT name FROM " . $xoopsDB->prefix("lxcategories") . " WHERE categoryID=" . $categoryID;
427
                $result = $xoopsDB->query($sql);
428
                $row = $xoopsDB->fetchArray($result);
429
                $tags['CATEGORY_NAME'] = $row['name'];
430
                $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID;
431
                $notification_handler->triggerEvent('global', 0, 'new_post', $tags);
432
                $notification_handler->triggerEvent('category', $categoryID, 'new_post', $tags);
433
                $notification_handler->triggerEvent('term', $entryID, 'approve', $tags);
434
            }
435
436
         lx_calculateTotals();
437
            if ($notifypub == '0'){
438
                redirect_header( "entry.php", 1, _AM_LEXIKON_ENTRYMODIFIED );
439
                exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function entrySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
440
            } else {
441
                $user = new XoopsUser($uid);
442
                $userMessage = sprintf(_MD_LEXIKON_GOODDAY2, $user->getVar('uname'));
443
                $userMessage .= "\n\n";
444
                if ($request == '1'){$userMessage .= sprintf(_MD_LEXIKON_CONFREQ,$xoopsConfig['sitename']);
445
                } else { $userMessage .= sprintf(_MD_LEXIKON_CONFSUB);}
446
                $userMessage .= "\n";
447
                $userMessage .= sprintf(_MD_LEXIKON_APPROVED,$xoopsConfig['sitename']);
448
                $userMessage .= "\n\n";
449
                $userMessage .= sprintf(_MD_LEXIKON_REGARDS);
450
                $userMessage .= "\n";
451
                $userMessage .= "__________________\n";
452
                $userMessage .= "".$xoopsConfig['sitename']." "._MD_LEXIKON_WEBMASTER."\n";
453
                $userMessage .= "".$xoopsConfig['adminmail']."";
454
                $xoopsMailer =& getMailer();
455
                $xoopsMailer->useMail();
456
                $xoopsMailer->setToEmails($user->getVar('email'));
457
                $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
458
                //$xoopsMailer->setFromName($xoopsConfig['sitename']." - "._MI_LEXIKON_MD_NAME);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
459
                $xoopsMailer->setFromName($xoopsConfig['sitename']." - ".$xoopsModule->name());
460
                if ($request == '1'){ $conf_subject = sprintf(_MD_LEXIKON_SUBJECTREQ,$xoopsConfig['sitename']);
461
                        } else { $conf_subject = sprintf(_MD_LEXIKON_SUBJECTSUB,$xoopsConfig['sitename']);}
462
                $xoopsMailer->setSubject($conf_subject);
463
                $xoopsMailer->setBody($userMessage);
464
                $xoopsMailer->send();
465
                $messagesent = sprintf(_AM_LEXIKON_SENTCONFIRMMAIL,$user->getVar('uname'));
466
467
                redirect_header( "entry.php", 1, $messagesent );
468
                exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function entrySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
469
                }
470
            redirect_header( "entry.php", 1, _AM_LEXIKON_ENTRYMODIFIED );
0 ignored issues
show
Unused Code introduced by
redirect_header('entry.p...LEXIKON_ENTRYMODIFIED); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
471
        } else {
472
            redirect_header( "index.php", 1, _AM_LEXIKON_ENTRYNOTUPDATED );
473
        }
474
    }
475
}
476
477
function entryDelete($entryID = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $entryID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
entryDelete uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
entryDelete uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
478
    global $xoopsDB, $xoopsModule;
0 ignored issues
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...
479
    $entryID = isset($_POST['entryID']) ? intval($_POST['entryID']) : intval($_GET['entryID']);
480
    $ok = isset($_POST['ok']) ? intval($_POST['ok']) : 0;
481
    $result = $xoopsDB -> query( "SELECT entryID, term, uid FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE entryID = $entryID" );
482
    list( $entryID, $term, $uid  ) = $xoopsDB -> fetchrow( $result );
483
484
    // confirmed, so delete
485
    if ( $ok == 1 ) {
486
        $result = $xoopsDB -> query( "DELETE FROM " .$xoopsDB -> prefix("lxentries")." WHERE entryID = $entryID");
0 ignored issues
show
Unused Code introduced by
$result 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...
487
        xoops_comment_delete( $xoopsModule->getVar('mid'), $entryID );
488
        // delete notifications
489
        xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'term', $entryID);
490
        // update user posts
491
        if (!empty($uid)) {
492
            $submitter = new xoopsUser($uid);
493
            $member_handler =& xoops_gethandler('member');
494
            $member_handler->updateUserByField($submitter, 'posts', $submitter->getVar('posts') - 1);
495
        }
496
        redirect_header("entry.php",1,sprintf( _AM_LEXIKON_ENTRYISDELETED, $term ) );
497
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function entryDelete() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
498
    } else {
499
        //xoops_cp_header();
500
        xoops_confirm(array('op' => 'del', 'entryID' => $entryID, 'ok' => 1, 'term' => $term ), 'entry.php', _AM_LEXIKON_DELETETHISENTRY . "<br /><br>" . $term, _AM_LEXIKON_DELETE );
501
        xoops_cp_footer();
502
    }
503
//	break;
504
    exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function entryDelete() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
505
}
506
507
/* -- Available operations -- */
508
$op = 'default';
509 View Code Duplication
if (isset($_POST['op'])) {
0 ignored issues
show
Duplication introduced by
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...
510
    $op=$_POST['op'];
511
} else {
512
    if (isset($_GET['op'])) {
513
        $op=$_GET['op'];
514
    }
515
}
516
switch ( $op ) {
517
    case "mod":
518
        $entryID = ( isset( $_GET['entryID'] ) ) ? intval($_GET['entryID']) : intval($_POST['entryID']);
519
        entryEdit($entryID);
520
        break;
521
    
522
    case "add":
523
        entryEdit();
524
        break;
525
    
526
    case "addentry":
527
        entrySave();
528
        break;
529
    
530
    case "del":
531
        entryDelete();
532
        break;//
533
    
534
    case "default":
535
    default:
536
        entryDefault();
537
        break;
538
    }
539
xoops_cp_footer();
540