Completed
Pull Request — master (#12)
by
unknown
01:54
created

functions.php ➔ lx_extract_keywords()   D

Complexity

Conditions 15
Paths 144

Size

Total Lines 119
Code Lines 106

Duplication

Lines 63
Ratio 52.94 %

Importance

Changes 0
Metric Value
cc 15
eloc 106
nc 144
nop 1
dl 63
loc 119
rs 4.597
c 0
b 0
f 0

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

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: functions.php v 1.0 8 May 2004 hsalazar Exp $
4
 * Module: Lexikon
5
 * Author: hsalazar
6
 * Additions and Modifications: Yerres
7
 * Licence: GNU
8
 */
9
10
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die( 'XOOPS root path not defined' ) ;
11
12
/**
13
 * lx_getLinkedUnameFromId()
14
 *
15
 * @param integer $userid Userid of author etc
16
 * @param integer $name:  0 Use Usenamer 1 Use realname
0 ignored issues
show
Bug introduced by
There is no parameter named $name:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
17
 * @return
18
 **/
19 View Code Duplication
function lx_getLinkedUnameFromId($userid = 0, $name= 0) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
Coding Style introduced by
lx_getLinkedUnameFromId uses the super-global variable $GLOBALS 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...
20
    if (!is_numeric($userid)) {
21
        return $userid;
22
    }
23
24
    $userid = intval($userid);
25
    if ($userid > 0) {
26
        $member_handler = xoops_gethandler('member');
27
        $user = $member_handler->getUser($userid);
28
29
        if (is_object($user)) {
30
            $ts = MyTextSanitizer::getInstance();
31
            $username = $user->getVar('uname');
32
            $usernameu = $user->getVar('name');
33
34
            if ( ($name) && !empty($usernameu))  {
35
                $username = $user->getVar('name');
36
            }
37
            if ( !empty($usernameu)) {
38
                $linkeduser = "$usernameu [<a href='".XOOPS_URL."/userinfo.php?uid=".$userid."'>". $ts->htmlSpecialChars($username) ."</a>]";
39
            } else {
40
                $linkeduser = "<a href='".XOOPS_URL."/userinfo.php?uid=".$userid."'>". ucfirst($ts->htmlSpecialChars($username)) ."</a>";
41
            }
42
43
            return $linkeduser;
44
        }
45
    }
46
47
    return $GLOBALS['xoopsConfig']['anonymous'];
48
}
49
50 View Code Duplication
function lx_getuserForm($user) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
51
    global $xoopsDB, $xoopsConfig;
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...
52
53
    echo "<select name='author'>";
54
    echo "<option value='-1'>------</option>";
55
    $result = $xoopsDB->query("SELECT uid, uname FROM ".$xoopsDB->prefix("users")." ORDER BY uname");
56
57
    while (list($uid, $uname) = $xoopsDB->fetchRow($result)) {
58
        if ( $uid == $user ) {
59
            $opt_selected = "selected='selected'";
60
        } else {
61
            $opt_selected = "";
62
        }
63
        echo "<option value='".$uid."' $opt_selected>".$uname."</option>";
64
    }
65
    echo "</select></div>";
66
}
67
68 View Code Duplication
function lx_calculateTotals() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
69
    global $xoopsUser, $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...
70
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
71
    $gperm_handler = xoops_gethandler('groupperm');
72
73
    $result01 = $xoopsDB -> query( "SELECT categoryID, total FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
74
    list ( $totalcategories ) = $xoopsDB -> getRowsNum( $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...
75
    while (list ( $categoryID, $total ) = $xoopsDB -> fetchRow ( $result01 )) {
0 ignored issues
show
Unused Code introduced by
The assignment to $total 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...
76
        if ($gperm_handler->checkRight('lexikon_view', $categoryID, $groups, $xoopsModule->getVar('mid'))) {
77
            $newcount = lx_countByCategory ( $categoryID );
78
            $xoopsDB -> queryF( "UPDATE " . $xoopsDB -> prefix( "lxcategories" ) . " SET total = '$newcount' WHERE categoryID = '$categoryID'");
79
        }
80
    }
81
}
82
83 View Code Duplication
function lx_countByCategory( $c ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
84
    global $xoopsUser, $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...
85
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
0 ignored issues
show
Unused Code introduced by
$groups 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...
86
    $gperm_handler = xoops_gethandler('groupperm');
0 ignored issues
show
Unused Code introduced by
$gperm_handler 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...
87
    $count = 0;
88
    $sql = $xoopsDB -> query( "SELECT entryID FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE offline = '0' AND categoryID = '$c'" );
89
    while ( $myrow = $xoopsDB -> fetchArray( $sql ) ) {
0 ignored issues
show
Unused Code introduced by
$myrow 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...
90
        //if ($gperm_handler->checkRight('lexikon_view', $c, $groups, $xoopsModule->getVar('mid'))) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
91
        $count++;
92
        //}
93
    }
94
95
    return $count;
96
}
97
98 View Code Duplication
function lx_countCats () {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
99
    global $xoopsUser, $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...
100
    $gperm_handler = xoops_gethandler('groupperm');
101
    $groups = (is_object($xoopsUser)) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
102
    $totalcats = $gperm_handler->getItemIds("lexikon_view", $groups, $xoopsModule->getVar('mid'));
103
104
    return count($totalcats);
105
}
106
107 View Code Duplication
function lx_countWords () {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
108
    global $xoopsUser, $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...
109
    $gperm_handler = xoops_gethandler('groupperm');
110
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
111
      $module_handler = xoops_gethandler('module');
112
    $module = $module_handler->getByDirname('lexikon');
113
    $module_id = $module->getVar('mid');
114
      $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
115
      $catids = implode(',', $allowed_cats);
116
      $catperms = " AND categoryID IN ($catids) ";
117
118
    $pubwords = $xoopsDB -> query( "SELECT * FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE submit = '0' AND offline ='0' AND request = '0' ".$catperms." " );
119
    $publishedwords = $xoopsDB -> getRowsNum ( $pubwords );
120
121
    return $publishedwords;
122
}
123
124
// To display the list of categories
125
function lx_CatsArray(){
126
    global $xoopsDB, $xoopsModuleConfig,$xoopsUser,$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...
127
    $myts = MyTextSanitizer::getInstance();
128
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
129
    $gperm_handler = xoops_gethandler('groupperm');
130
    $block0 = [];
131
    $count = 1;
132
    $resultcat = $xoopsDB -> query ( "SELECT categoryID, name, total, logourl FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY weight ASC" );
133
    while (list( $catID, $name, $total, $logourl) = $xoopsDB->fetchRow($resultcat)) {
134
        if ($gperm_handler->checkRight('lexikon_view', $catID, $groups, $xoopsModule->getVar('mid'))) {
135
            $catlinks = [];
136
            $count++;
137
            if ($logourl && $logourl != "http://") {
138
                $logourl = $myts->htmlSpecialChars($logourl);
139
            } else {
140
                $logourl = '';
141
            }
142
            $xoopsModule = XoopsModule::getByDirname("lexikon");
143
            $catlinks['id'] = intval($catID);
144
            $catlinks['total'] = intval($total);
145
            $catlinks['linktext'] = $myts -> htmlSpecialChars( $name );
146
            $catlinks['image'] = $logourl;
147
            $catlinks['count'] = intval($count);
148
149
            $block0['categories'][] = $catlinks;
150
        }
151
    }
152
153
    return $block0;
154
}
155
156
function lx_alphaArray () {
157
    global $xoopsUser, $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...
158
    $gperm_handler = xoops_gethandler('groupperm');
159
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
160
      $module_handler = xoops_gethandler('module');
161
    $module = $module_handler->getByDirname('lexikon');
162
    $module_id = $module->getVar('mid');
163
    $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
164
    $catids = implode(',', $allowed_cats);
165
      $catperms = " AND categoryID IN ($catids) ";
166
    $alpha = [];
167 View Code Duplication
    for ($a = 65; $a < (65+26); $a++ ) {
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...
168
        $letterlinks = [];
169
        $initial = chr($a);
170
        $sql = $xoopsDB -> query ( "SELECT entryID FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '$initial' AND submit = '0' AND offline ='0' AND request = '0' ".$catperms."");
171
        $howmany = $xoopsDB -> getRowsNum( $sql );
172
        $letterlinks['total'] = $howmany;
173
        $letterlinks['id'] = chr($a);
174
        $letterlinks['linktext'] = chr($a);
175
176
        $alpha['initial'][] = $letterlinks;
177
    }
178
179
    return $alpha;
180
}
181
182
/**
183
 * chr() with unicode support
184
 * I found this on this site http://en.php.net/chr
185
 * don't take credit for this.
186
 *
187
 */
188 View Code Duplication
function lx_uchr ($initials) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
189
    if (is_scalar($initials)) $initials= func_get_args();
190
    $str= '';
191
    foreach ($initials as $init) $str.= html_entity_decode('&#'.$init.';',ENT_NOQUOTES,'UTF-8');
192
193
    return $str;
194
}
195
/* sample */
196
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
197
    echo lx_uchr(23383); echo '<br/>';
198
    echo lx_uchr(23383,215,23383); echo '<br/>';
199
    echo lx_uchr(array(23383,215,23383,215,23383)); echo '<br/>';
200
*/
201
202
// Functional links
203 View Code Duplication
function lx_serviceLinks ( $variable ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
204
    global $xoopsUser, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $xoopsConfig, $entrytype;
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...
205
206
    $module_handler  = xoops_gethandler('module');
207
    $moduleInfo = $module_handler->get($xoopsModule->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
$moduleInfo 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...
208
    $pathIcon16 = $xoopsModule->getInfo('icons16');
209
210
    $srvlinks = "";
211
    if ( $xoopsUser ) {
212
        if ( $xoopsUser->isAdmin() ) {
213
            $srvlinks .= "<a title=\""
214
                          . _EDIT
215
                          . "\" href=\"admin/entry.php?op=mod&entryID="
216
                          . $variable['id']
217
                          . "\" target=\"_blank\"><img src=\""
218
                          . $pathIcon16
219
                          . "/edit.png\" alt=\""
220
                          . _MD_LEXIKON_EDITTERM
221
                          . "\" style=\"width:16px; height:16px;\"></a>&nbsp;<a TITLE=\""
222
                          . _DELETE
223
                          . "\" href=\"admin/entry.php?op=del&entryID="
224
                          . $variable['id']
225
                          . "\" target=\"_self\"><img src=\""
226
                          . $pathIcon16
227
                          . "/delete.png\" alt=\""
228
                          . _MD_LEXIKON_DELTERM
229
                          . "\" style=\"width:16px; height:16px;\"></a>&nbsp;";
230
        }
231
    }
232
    if ( $entrytype != "1" ) {
233
        $srvlinks .= "<a title=\""
234
                      . _MD_LEXIKON_PRINTTERM
235
                      . "\" href=\"print.php?entryID="
236
                      . $variable['id']
237
                      . "\" target=\"_blank\"><img src=\""
238
                      . $pathIcon16
239
                      . "/printer.png\" alt=\""
240
                      . _MD_LEXIKON_PRINTTERM
241
                      . "\" style=\"width:16px; height:16px;\"></a>&nbsp;<a TITLE=\""
242
                      . _MD_LEXIKON_SENDTOFRIEND
243
                      . "\" href=\"mailto:?subject="
244
                      . sprintf(_MD_LEXIKON_INTENTRY,$xoopsConfig["sitename"])
245
                      . "&amp;body="
246
                      . sprintf(_MD_LEXIKON_INTENTRYFOUND, $xoopsConfig['sitename'])
247
                      . ": "
248
                      . XOOPS_URL
249
                      . "/modules/".$xoopsModule->dirname()
250
                      . "/entry.php?entryID="
251
                      . $variable['id']
252
                      . " \" target=\"_blank\"><img src=\""
253
                      . $pathIcon16
254
                      . "/mail_replay.png\" alt=\""
255
                      . _MD_LEXIKON_SENDTOFRIEND
256
                      . "\" style=\"width:16px; height:16px;\"></a>&nbsp;";
257
        if (( $xoopsModuleConfig['com_rule'] != 0 ) && (!empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser))) {
258
            $srvlinks .= "<a title=\""
259
                          . _COMMENTS
260
                          . "?\" href=\"comment_new.php?com_itemid="
261
                          . $variable['id']
262
                          . "\" target=\"_parent\"><img src=\"images/comments.gif\" alt=\""
263
                          . _COMMENTS
264
                          . "?\" style=\"width:16px; height:16px;\"></a>&nbsp;";
265
            }
266
    }
267
268
    return $srvlinks;
269
}
270
// entry footer
271 View Code Duplication
function lx_serviceLinksnew ( $variable ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
272
    global $xoopsUser, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $xoopsConfig, $myts;
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...
273
    $srvlinks2 = "<a title=\""
274
                  . _MD_LEXIKON_PRINTTERM
275
                  . "\" href=\"print.php?entryID="
276
                  . $variable['id']
277
                  . "\" target=\"_blank\"><img src=\"images/print.gif\" alt=\""
278
                  . _MD_LEXIKON_PRINTTERM
279
                  . "\" style=\"vertical-align: middle; width:16px; height:16px; margin: 2px 4px;\"> "
280
                  . _MD_LEXIKON_PRINTTERM2
281
                  . "</a>&nbsp; <a title=\""
282
                  . _MD_LEXIKON_SENDTOFRIEND
283
                  . "\" href=\"mailto:?subject="
284
                  . sprintf(_MD_LEXIKON_INTENTRY,$xoopsConfig["sitename"])
285
                  . "&amp;body="
286
                  . sprintf(_MD_LEXIKON_INTENTRYFOUND, $xoopsConfig['sitename'])
287
                  . ": ".$variable['term']
288
                  . " "
289
                  . XOOPS_URL
290
                  . "/modules/"
291
                  . $xoopsModule->dirname()
292
                  . "/entry.php?entryID="
293
                  . $variable['id']
294
                  . " \" target=\"_blank\"><img src=\"images/friend.gif\" alt=\""
295
                  . _MD_LEXIKON_SENDTOFRIEND
296
                  . "\" style=\"vertical-align: middle; width:16px; height:16px; margin: 2px 4px;\"> "
297
                  . _MD_LEXIKON_SENDTOFRIEND2
298
                  . "</a>&nbsp;";
299
300
    return $srvlinks2;
301
}
302
303 View Code Duplication
function lx_showSearchForm() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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
    global $xoopsUser, $xoopsDB, $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
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...
305
    $gperm_handler = xoops_gethandler('groupperm');
306
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
307
    
308
    $searchform = "<table style=\"width:100%;\">";
309
    $searchform .= "<form name=\"op\" id=\"op\" action=\"search.php\" method=\"post\">";
310
    $searchform .= "<tr><td style=\"text-align: right; line-height: 200%; width:150px;\">";
311
    $searchform .= _MD_LEXIKON_LOOKON."</td><td style=\"width:10px;\">&nbsp;</td><td style=\"text-align: left;\">";
312
    $searchform .= "<select name=\"type\"><option value=\"1\">"._MD_LEXIKON_TERMS."</option><option value=\"2\">"._MD_LEXIKON_DEFINS."</option>";
313
    $searchform .= "<option SELECTED value=\"3\">"._MD_LEXIKON_TERMSDEFS."</option></select></td></tr>";
314
315
    if ($xoopsModuleConfig['multicats'] == 1) {
316
        $searchform .= "<tr><td style=\"text-align: right; line-height: 200%;\">"._MD_LEXIKON_CATEGORY."</td>";
317
        $searchform .= "<td>&nbsp;</td><td style=\"text-align: left;\">";
318
        $resultcat = $xoopsDB -> query ( "SELECT categoryID, name FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY categoryID" );
319
        $searchform .= "<select name=\"categoryID\">";
320
        $searchform .= "<option value=\"0\">"._MD_LEXIKON_ALLOFTHEM."</option>";
321
322
        while (list( $categoryID, $name) = $xoopsDB->fetchRow($resultcat)) {
323
            if ($gperm_handler->checkRight('lexikon_view', intval($categoryID), $groups, $xoopsModule->getVar('mid'))) {
324
                $searchform .= "<option value=\"$categoryID\">$categoryID : $name</option>";
325
            }
326
        }
327
        $searchform .= "</select></td></tr>";
328
    }
329
330
    $searchform .= "<tr><td style=\"text-align: right; line-height: 200%;\">";
331
    $searchform .= _MD_LEXIKON_TERM."</td><td>&nbsp;</td><td style=\"text-align: left;\">";
332
    $searchform .= "<input type=\"text\" name=\"term\" class=\"searchBox\" /></td></tr><tr>";
333
    $searchform .= "<td>&nbsp;</td><td>&nbsp;</td><td><input type=\"submit\" class=\"btnDefault\" value=\""._MD_LEXIKON_SEARCH."\" />";
334
    $searchform .= "</td></tr></form></table>";
335
336
    return $searchform;
337
}
338
339 View Code Duplication
function lx_getHTMLHighlight($needle, $haystack, $hlS, $hlE) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
340
    $parts = explode(">", $haystack);
341
    foreach($parts as $key=>$part) {
342
        $pL = "";
343
        $pR = "";
344
345
        if (($pos = strpos($part, "<")) === false)
346
            $pL = $part;
347
        elseif($pos > 0) {
348
            $pL = substr($part, 0, $pos);
349
            $pR = substr($part, $pos, strlen($part));
350
        }
351
        if ($pL != "")
352
            $parts[$key] = preg_replace('|('.quotemeta($needle).')|iU', $hlS.'\\1'.$hlE, $pL) . $pR;
353
    }
354
355
    return(implode(">", $parts));
356
}
357
358
/* *******************************************************************************
359
 * Most of the following functions are modified functions from Herve's News Module
360
 * other functions are from  AMS by Novasmart/Mithrandir
361
 * others from Red Mexico Soft Rmdp
362
 * others from Xhelp 0.78 thanks to ackbarr and eric_juden
363
 * *******************************************************************************
364
 */
365
366
// Create the meta keywords based on content
367 View Code Duplication
function lx_extract_keywords($content) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
Coding Style introduced by
lx_extract_keywords uses the super-global variable $_SESSION 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...
368
    global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig;
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...
369
    include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php';
370
    $keywords_count = $xoopsModuleConfig['metakeywordsnum'];
371
    $tmp=array();
372
    if (isset($_SESSION['xoops_keywords_limit'])) {    // Search the "Minimum keyword length"
373
        $limit = $_SESSION['xoops_keywords_limit'];
374
    } else {
375
        $config_handler = xoops_gethandler('config');
376
        $xoopsConfigSearch = $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
377
        $limit=$xoopsConfigSearch['keyword_min'];
378
        $_SESSION['xoops_keywords_limit']=$limit;
379
    }
380
    $myts = MyTextSanitizer::getInstance();
381
    $content = str_replace ("<br />", " ", $content);
382
    $content= $myts->undoHtmlSpecialChars($content);
383
    $content= strip_tags($content);
384
    $content=strtolower($content);
385
    $search_pattern=[
386
                    "&nbsp;",
387
                    "\t",
388
                    "\r\n",
389
                    "\r",
390
                    "\n",
391
                    ",",
392
                    ".",
393
                    "'",
394
                    ";",
395
                    ":",
396
                    ")",
397
                    "(",
398
                    '"',
399
                    '?',
400
                    '!',
401
                    '{',
402
                    '}',
403
                    '[',
404
                    ']',
405
                    '<',
406
                    '>',
407
                    '/',
408
                    '+',
409
                    '-',
410
                    '_',
411
                    '\\',
412
                    '*'
413
                    ];
414
    $replace_pattern=[
415
                    ' ',
416
                    ' ',
417
                    ' ',
418
                    ' ',
419
                    ' ',
420
                    ' ',
421
                    ' ',
422
                    ' ',
423
                    '',
424
                    '',
425
                    '',
426
                    '',
427
                    '',
428
                    '',
429
                    '',
430
                    '',
431
                    '',
432
                    '',
433
                    '',
434
                    '',
435
                    '',
436
                    '',
437
                    '',
438
                    '',
439
                    '',
440
                    '',
441
                    ''
442
                    ];
443
    $content = str_replace($search_pattern, $replace_pattern, $content);
444
    $keywords=explode(' ',$content);
445
    switch (META_KEYWORDS_ORDER) {
446
    case 1:    // Returns keywords in the same order that they were created in the text
447
            $keywords=array_unique($keywords);
448
        break;
449
450
    case 2:    // the keywords order is made according to the reverse keywords frequency (so the less frequent words appear in first in the list)
451
        $keywords=array_count_values($keywords);
452
        asort($keywords);
453
        $keywords=array_keys($keywords);
454
        break;
455
456
    case 3:    // Same as previous, the only difference is that the most frequent words will appear in first in the list
457
        $keywords=array_count_values($keywords);
458
        arsort($keywords);
459
        $keywords=array_keys($keywords);
460
        break;
461
    }
462
    foreach($keywords as $keyword) {
463
        if (strlen($keyword)>=$limit && !is_numeric($keyword)) {
464
            $tmp[]=$keyword;
465
        }
466
    }
467
    $tmp=array_slice($tmp,0,$keywords_count);
468
    if (count($tmp)>0) {
469
        if (isset($xoTheme) && is_object($xoTheme)) {
470
            $xoTheme->addMeta( 'meta', 'keywords', implode(',',$tmp));
471
        } else {    // Compatibility for old Xoops versions
472
            $xoopsTpl->assign('xoops_meta_keywords', implode(',',$tmp));
473
        }
474
    } else {
475
        if (!isset($config_handler) || !is_object($config_handler)) {
476
            $config_handler = xoops_gethandler('config');
477
        }
478
        $xoopsConfigMetaFooter = $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
479
        if (isset($xoTheme) && is_object($xoTheme)) {
480
            $xoTheme->addMeta( 'meta', 'keywords', $xoopsConfigMetaFooter['meta_keywords']);
481
        } else {    // Compatibility for old Xoops versions
482
            $xoopsTpl->assign('xoops_meta_keywords', $xoopsConfigMetaFooter['meta_keywords']);
483
        }
484
    }
485
}
486
487
// Create meta description based on content
488 View Code Duplication
function lx_get_metadescription($content) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
489
    global $xoopsTpl, $xoTheme;
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...
490
    $myts = MyTextSanitizer::getInstance();
491
    $content= $myts->undoHtmlSpecialChars($myts->displayTarea($content));
492
    if (isset($xoTheme) && is_object($xoTheme)) {
493
        $xoTheme->addMeta( 'meta', 'description', strip_tags($content));
494
    } else {  // Compatibility for old Xoops versions
495
        $xoopsTpl->assign('xoops_meta_description', strip_tags($content));
496
    }
497
}
498
499
// Create pagetitles
500 View Code Duplication
function lx_create_pagetitle($article='', $topic='') {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
501
    global $xoopsModule, $xoopsTpl;
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...
502
    $myts = MyTextSanitizer::getInstance();
503
    $content='';
504
    if (!empty($article)) $content .= strip_tags($myts->displayTarea($article));
505
    if (!empty($topic)) {
506
        if (xoops_trim($content)!='') {
507
            $content .= ' - '.strip_tags($myts->displayTarea($topic));
508
        } else {
509
            $content .= strip_tags($myts->displayTarea($topic));
510
        }
511
    }
512
    if (is_object($xoopsModule) && xoops_trim($xoopsModule->name())!='') {
513
        if (xoops_trim($content)!='') {
514
            $content.=' - '.strip_tags($myts->displayTarea($xoopsModule->name()));
515
        } else {
516
            $content.=strip_tags($myts->displayTarea($xoopsModule->name()));
517
        }
518
    }
519
    if ($content!='') {
520
        $xoopsTpl->assign('xoops_pagetitle', $content);
521
    }
522
}
523
524
// clear descriptions
525 View Code Duplication
function lx_html2text($document) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
526
    // PHP Manual:: function preg_replace $document should contain an HTML document.
527
    // This will remove HTML tags, javascript sections and white space. It will also
528
    // convert some common HTML entities to their text equivalent.
529
530
    $search       = ["'<script[^>]*?>.*?</script>'si",  // Strip out javascript
531
                     "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
532
                     "'([\r\n])[\s]+'",                // Strip out white space
533
                     "'&(quot|#34);'i",                // Replace HTML entities
534
                     "'&(amp|#38);'i",
535
                     "'&(lt|#60);'i",
536
                     "'&(gt|#62);'i",
537
                     "'&(nbsp|#160);'i",
538
                     "'&(iexcl|#161);'i",
539
                     "'&(cent|#162);'i",
540
                     "'&(pound|#163);'i",
541
                     "'&(copy|#169);'i"];
542
543
    $replace       = ["",
544
                      "",
545
                      "\\1",
546
                      "\"",
547
                      "&",
548
                      "<",
549
                      ">",
550
                      " ",
551
                      chr(161),
552
                      chr(162),
553
                      chr(163),
554
                      chr(169)];
555
556
    $text = preg_replace($search, $replace, $document);
557
558
    $text = preg_replace_callback("&#(\d+)&", create_function('$matches',"return chr(\$matches[1]);"),$text);
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
559
560
    return $text;
561
}
562
563
//Retrieve moduleoptions equivalent to $Xoopsmoduleconfig
564 View Code Duplication
function lx_getmoduleoption($option, $repmodule='lexikon') {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
565
    global $xoopsModuleConfig, $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...
566
    static $tbloptions= [];
567
    if (is_array($tbloptions) && array_key_exists($option,$tbloptions)) {
568
        return $tbloptions[$option];
569
    }
570
571
    $retval=false;
572
    if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) {
573
        if (isset($xoopsModuleConfig[$option])) {
574
            $retval= $xoopsModuleConfig[$option];
575
        }
576
    } else {
577
        $module_handler = xoops_gethandler('module');
578
        $module = $module_handler->getByDirname($repmodule);
579
        $config_handler = xoops_gethandler('config');
580
        if ($module) {
581
            $moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
582
            if (isset($moduleConfig[$option])) {
583
                $retval= $moduleConfig[$option];
584
            }
585
        }
586
    }
587
    $tbloptions[$option]=$retval;
588
589
    return $retval;
590
}
591
592
/**
593
 * Is Xoops 2.3.x ?
594
 *
595
 * @return boolean need to say it ?
596
 */
597 View Code Duplication
function lx_isX23()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
598
{
599
    $x23 = false;
600
    $xv = str_replace('XOOPS ','',XOOPS_VERSION);
601
    if(substr($xv,2,1) >= '3') {
602
        $x23 = true;
603
    }
604
605
    return $x23;
606
}
607
608
/**
609
 * Retreive an editor according to the module's option "form_options"
610
 * following function is from News modified by trabis
611
 */
612 View Code Duplication
function &lx_getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental='')
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
613
{
614
    $editor_option = strtolower(lx_getmoduleoption('form_options'));
615
    $editor = false;
616
    $editor_configs = [];
617
    $editor_configs['name'] = $name;
618
    $editor_configs['value'] = $value;
619
    $editor_configs['rows'] = 35;
620
    $editor_configs['cols'] = 60;
621
    $editor_configs['width'] = '100%';
622
    $editor_configs['height'] = '350px';
623
    $editor_configs['editor'] = $editor_option;
624
625
    if(lx_isX23()) {
626
        $editor = new XoopsFormEditor($caption, $name, $editor_configs);
627
628
        return $editor;
629
            }
630
631
    // Only for Xoops 2.0.x
632
    switch($editor_option) {
633
        case 'fckeditor':
634
            if ( is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'))    {
635
                require_once(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php');
636
                $editor = new XoopsFormFckeditor($caption, $name, $value);
637
            }
638
            break;
639
640
        case 'htmlarea':
641
                if ( is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'))    {
642
                require_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php');
643
                    $editor = new XoopsFormHtmlarea($caption, $name, $value);
644
            }
645
            break;
646
647
        case 'dhtmltextarea':
648
        case 'dhtml':
649
                $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental);
650
            break;
651
652
        case 'textarea':
653
            $editor = new XoopsFormTextArea($caption, $name, $value);
654
            break;
655
656
        case 'tinyeditor':
657
        case 'tinymce':
658
            if ( is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) {
659
                require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php';
660
                $editor = new XoopsFormTinyeditorTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'400px'));
661
            }
662
            break;
663
664
        case 'koivi':
665
                if ( is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) {
666
                require_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php');
667
                $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, '');
668
            }
669
            break;
670
        }
671
672
        return $editor;
673
}
674
675
/**
676
 * linkterms: assign module header
677
 *
678
 * tooltips (c) dhtmlgoodies
679
 */
680 View Code Duplication
function lx_module_header() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
681
    global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig, $lexikon_module_header;
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...
682
    if(isset($xoTheme) && is_object($xoTheme)) {
683
        $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/style.css' );
684
        if ($xoopsModuleConfig['linkterms'] == 3) {
685
            $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' );
686
            $xoTheme->addScript( '/modules/lexikon/assets/js/tooltipscript2.js', array( 'type' => 'text/javascript' ) );
687
            }
688
        if ($xoopsModuleConfig['linkterms'] == 4) {
689
            $xoTheme->addScript( '/modules/lexikon/assets/js/popup.js', array( 'type' => 'text/javascript' ) );
690
            }
691
        if ($xoopsModuleConfig['linkterms'] == 5) {
692
            $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' );
693
            $xoTheme->addScript( '/modules/lexikon/assets/js/balloontooltip.js', array( 'type' => 'text/javascript' ) );
694
            }
695
        if ($xoopsModuleConfig['linkterms'] == 6) {
696
            $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' );
697
            $xoTheme->addScript( '/modules/lexikon/assets/js/shadowtooltip.js', array( 'type' => 'text/javascript' ) );
698
            }
699
    } else {
700
        $lexikon_url = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname');
701
        if ($xoopsModuleConfig['linkterms'] == 3) {
702
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
703
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
704
			<script src="'.$lexikon_url.'/assets/js/tooltipscript2.js" type="text/javascript"></script>';
705
            }
706
        if ($xoopsModuleConfig['linkterms'] == 4) {
707
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
708
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
709
			<script src="'.$lexikon_url.'/assets/js/popup.js" type="text/javascript"></script>';
710
            }
711
        if ($xoopsModuleConfig['linkterms'] == 5) {
712
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
713
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
714
			<script src="'.$lexikon_url.'/assets/js/balloontooltip.js" type="text/javascript"></script>';
715
            }
716
        if ($xoopsModuleConfig['linkterms'] == 6) {
717
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
718
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
719
			<script src="'.$lexikon_url.'/assets/js/shadowtooltip.js" type="text/javascript"></script>';
720
            }
721
        }
722
}
723
724
/**
725
 * Validate userid
726
 */
727 View Code Duplication
function lx_val_user_data($uids) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
728
    global $xoopsDB,$xoopsUser, $xoopsUserIsAdmin;
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...
729
730
    if ($uids<=0) {
731
        return false;
732
    }
733
    if ($uids > 0) {
734
        $member_handler = xoops_gethandler('member');
735
        $user = $member_handler->getUser($uids);
736
        if (!is_object($user)) {
737
            return false;
738
        }
739
    }
740
    $result = $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("users")." WHERE uid='$uids'");
741
    if ($xoopsDB->getRowsNum($result)<=0) {
742
        return false;
743
    }
744
    $row = $xoopsDB->fetchArray($result);
745
746
    return $row;
747
}
748
749
// Get all terms published by an author
750
function lx_AuthorProfile($uid ) {
0 ignored issues
show
Coding Style introduced by
lx_AuthorProfile 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...
751
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
752
    global $authortermstotal, $xoopsTpl, $xoopsDB, $xoopsUser, $xoopsModuleConfig;
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...
753
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
754
    //permissions
755
    $gperm_handler = xoops_gethandler('groupperm');
756
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
757
    $module_handler = xoops_gethandler('module');
758
    $module = $module_handler->getByDirname('lexikon');
759
    $module_id = $module->getVar('mid');
760
    $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
761
    $catids = implode(',', $allowed_cats);
762
    $catperms = " AND categoryID IN ($catids) ";
763
        
764
    $start = isset( $_GET['start'] ) ? intval( $_GET['start'] ) : 0;
765
    $limit = $xoopsModuleConfig['indexperpage'];
766
767
    $sql = $xoopsDB -> query( "SELECT *
768
                              FROM " . $xoopsDB -> prefix( "lxentries" ) . "
769
                              WHERE uid='".intval($uid)."' AND  offline = '0' AND submit = '0' AND request = '0' ".$catperms."
770
                              ORDER BY term
771
                              LIMIT $start,$limit");
772
773 View Code Duplication
    while ($row=$xoopsDB->fetchArray($sql)) {
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...
774
        $xoopsTpl->append('entries', array('id'=>$row['entryID'],'name'=>$row['term'],'date'=>date($xoopsModuleConfig['dateformat'], $row['datesub']),'counter'=>$row['counter']));
775
    }
776
777
    $navstring = '';
778
    $navstring .= "uid=".$uid."&start";
779
    $pagenav = new XoopsPageNav( $authortermstotal , $xoopsModuleConfig['indexperpage'], $start, $navstring);
780
    $authortermsarr['navbar'] = '<span style="text-align:right;">' . $pagenav -> renderNav(6) . '</span>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$authortermsarr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $authortermsarr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
781
    $xoopsTpl -> assign( 'authortermsarr', $authortermsarr);
782
}
783
784
// Returns the author's IDs for authorslist
785 View Code Duplication
function lx_getAuthors($limit=0, $start=0) {
0 ignored issues
show
Unused Code introduced by
The parameter $limit 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...
Unused Code introduced by
The parameter $start 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...
Duplication introduced by
This function seems to be duplicated in 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...
786
    global $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...
787
788
    $ret = [];
789
    $sql = 'SELECT distinct(uid) as uid FROM '.$xoopsDB->prefix('lxentries').' WHERE offline = 0 ';
790
    $sql .= " ORDER BY uid";
791
    $result = $xoopsDB->query($sql);
792
    while ( $myrow = $xoopsDB->fetchArray($result) ) {
793
        $ret[] = $myrow['uid'];
794
    }
795
796
    return $ret;
797
}
798
799
// link to userprofile
800 View Code Duplication
function lx_getLinkedProfileFromId($userid) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $userid 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...
Duplication introduced by
This function seems to be duplicated in 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...
Coding Style introduced by
lx_getLinkedProfileFromId uses the super-global variable $GLOBALS 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...
801
    global $uid, $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...
802
    $userid = intval($uid);
803
    if ($userid > 0) {
804
        $member_handler = xoops_gethandler('member');
805
        $user = $member_handler->getUser($userid);
806
        if (is_object($user)) {
807
            $linkeduser = '<a title="'._MD_LEXIKON_AUTHORPROFILETEXT.'" href="'.XOOPS_URL.'/modules/'.$xoopsModule->dirname().'/profile.php?uid='.$uid.'">'. $user->getVar('uname').'</a>';
808
            //$linkeduser = XoopsUserUtility::getUnameFromId ( $uid );
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
809
            //$linkeduser .= '<div style=\'position:relative; right: 4px; top: 2px;\'><a title="'._MD_LEXIKON_AUTHORPROFILETEXT.'" href="'.XOOPS_URL.'/modules/'.$xoopsModule->dirname().'/profile.php?uid='.$uid.'">'._MD_LEXIKON_AUTHORPROFILETEXT.'</a></div>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
810
            return $linkeduser;
811
        }
812
    }
813
814
    return $GLOBALS['xoopsConfig']['anonymous'];
815
}
816
817
// functionset to assign terms with accentuated or umlaut initials to the adequate initial
818 View Code Duplication
function lx_removeAccents($string) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
819
    $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
0 ignored issues
show
Coding Style Comprehensibility introduced by
$chars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $chars = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
820
      .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
821
      .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
822
      .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
823
      .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
824
      .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
825
      .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
826
      .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
827
      .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
828
      .chr(252).chr(253).chr(255);
829
    $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
830
    if (lx_seemsUtf8($string)) {
831
        $invalid_latin_chars = [
832
                                chr(197).chr(146) => 'OE',
833
                                chr(197).chr(147) => 'oe',
834
                                chr(197).chr(160) => 'S',
835
                                chr(197).chr(189) => 'Z',
836
                                chr(197).chr(161) => 's',
837
                                chr(197).chr(190) => 'z',
838
                                chr(226).chr(130).chr(172) => 'E'
839
                                ];
840
        $string = utf8_decode(strtr($string, $invalid_latin_chars));
841
    }
842
    $string = strtr($string, $chars['in'], $chars['out']);
843
    $double_chars['in'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$double_chars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $double_chars = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
844
                          chr(140),
845
                          chr(156),
846
                          chr(198),
847
                          chr(208),
848
                          chr(222),
849
                          chr(223),
850
                          chr(230),
851
                          chr(240),
852
                          chr(254)
853
                          ];
854
    $double_chars['out'] = [
855
                            'OE',
856
                            'oe',
857
                            'AE',
858
                            'DH',
859
                            'TH',
860
                            'ss',
861
                            'ae',
862
                            'dh',
863
                            'th'
864
                            ];
865
    $string = str_replace($double_chars['in'], $double_chars['out'], $string);
866
867
    return $string;
868
}
869
870
function lx_seemsUtf8($Str) { # by bmorel at ssi dot fr
871
    for ($i=0; $i<strlen($Str); $i++) {
872 View Code Duplication
        if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
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...
873
        elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
874
        elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
875
        elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
876
        elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
877
        elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
878
        else return false; # Does not match any model
879 View Code Duplication
        for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
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...
880
            if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
881
            return false;
882
        }
883
    }
884
885
    return true;
886
}
887
888 View Code Duplication
function lx_sanitizeFieldName($field) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
889
    $field = lx_removeAccents($field);
890
    $field = strtolower($field);
891
    $field = preg_replace('/&.+?;/', '', $field); // kill entities
892
    $field = preg_replace('/[^a-z0-9 _-]/', '', $field);
893
    $field = preg_replace('/\s+/', ' ', $field);
894
    $field = str_replace(' ', '-', $field);
895
    $field = preg_replace('|-+|', '-', $field);
896
    $field = trim($field, '-');
897
898
    return $field;
899
}
900
901
// Verify that a term does not exist for submissions and requests (both user frontend and admin backend)
902 View Code Duplication
function lx_TermExists($term, $table) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
903
    global $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...
904
    $sql = sprintf('SELECT COUNT(*) FROM %s WHERE term = %s', $table, $xoopsDB->quoteString(addslashes($term)));
905
    $result = $xoopsDB->query($sql);
906
    list($count) = $xoopsDB->fetchRow($result);
907
908
    return($count);
909
}
910
911
// Static method to get author data block authors - from AMS
912
function lexikon_block_getAuthors($limit = 5, $sort = "count", $name = 'uname', $compute_method = "average") {
913
    $limit = intval($limit);
914
    if ($name != "uname")
915
        $name = "name"; //making sure that there is not invalid information in field value
916
    $ret = [];
917
    $db = XoopsDatabaseFactory::getDatabaseConnection();
918
    if ($sort == "count") {
919
        $sql = "SELECT u.".$name." AS name, u.uid , count( n.entryID ) AS count
920
              FROM ".$db->prefix("users")." u, ".$db->prefix("lxentries")." n
921
              WHERE u.uid = n.uid
922
              AND n.datesub > 0 AND n.datesub <= ".time()." AND n.offline = 0 AND n.submit = 0
923
              GROUP BY u.uid ORDER BY count DESC";
924 View Code Duplication
    } elseif ($sort == "read") {
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...
925
        if ($compute_method == "average") {
926
            $compute = "sum( n.counter ) / count( n.entryID )";
927
        } else {
928
            $compute = "sum( n.counter )";
929
        }
930
        $sql = "SELECT u.".$name." AS name, u.uid , $compute AS count
931
              FROM ".$db->prefix("users")." u, ".$db->prefix("lxentries")." n
932
              WHERE u.uid = n.uid
933
              AND n.datesub > 0 AND n.datesub <= ".time()." AND n.offline = 0 AND n.submit = 0
934
              GROUP BY u.uid ORDER BY count DESC";
935
    }
936
    if (!$result = $db->query($sql, $limit))
0 ignored issues
show
Bug introduced by
The variable $sql 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...
937
        return false;
938
        
939 View Code Duplication
    while ($row = $db->fetchArray($result)) {
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...
940
        if ($name == "name" && $row['name'] == '')
941
            $row['name'] = XoopsUser::getUnameFromId($row['uid']);
942
        $row['count'] = round($row['count'], 0);
943
        $ret[] = $row;
944
    }
945
946
    return $ret;
947
}
948
949
/**
950
 * close all unclosed xhtml tags *Test*
951
 *
952
 * @param string $html
953
 * @return string
954
 * @author Milian Wolff <mail -at- milianw.de>
955
 */
956 View Code Duplication
function lx_closetags2($html){
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
957
  // put all opened tags into an array
958
  preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
959
  $openedtags=$result[1];
960
961
  // put all closed tags into an array
962
  preg_match_all("#</([a-z]+)>#iU",$html,$result);
963
  $closedtags=$result[1];
964
  $len_opened = count($openedtags);
965
  // all tags are closed
966
  if(count($closedtags) == $len_opened){
967
    return $html;
968
  }
969
970
  $openedtags = array_reverse($openedtags);
971
  // close tags
972
  for($i=0;$i < $len_opened;$i++) {
973
    if (!in_array($openedtags[$i],$closedtags)){
974
      $html .= '</'.$openedtags[$i].'>';
975
    } else {
976
      unset($closedtags[array_search($openedtags[$i],$closedtags)]);
977
    }
978
  }
979
980
  return $html;
981
}
982
983
/**
984
 * @author   Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson
985
 *           <amos dot robinson at gmail dot com>
986
 */
987 View Code Duplication
function lx_close_tags($string) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
988
    // match opened tags
989
    if(preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
990
        $start_tags = $start_tags[1];
991
        // match closed tags
992
        if(preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
993
            $complete_tags = array();
994
            $end_tags = $end_tags[1];
995
    
996
            foreach($start_tags as $key => $val) {
997
                $posb = array_search($val, $end_tags);
998
                   if(is_integer($posb)) {
999
                      unset($end_tags[$posb]);
1000
                   } else {
1001
                    $complete_tags[] = $val;
1002
                }
1003
            }
1004
        } else {
1005
            $complete_tags = $start_tags;
1006
        }
1007
        
1008
        $complete_tags = array_reverse($complete_tags);
1009
        for($i = 0; $i < count($complete_tags); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1010
            $string .= '</' . $complete_tags[$i] . '>';
1011
        }
1012
    }
1013
1014
    return $string;
1015
}
1016
1017
/**
1018
 * Smarty plugin
1019
 * @package Smarty
1020
 * @subpackage plugins
1021
 */
1022
/**
1023
 * Smarty truncate_tagsafe modifier plugin
1024
 *
1025
 * Type:     modifier<br>
1026
 * Name:     truncate_tagsafe<br>
1027
 * Purpose:  Truncate a string to a certain length if necessary,
1028
 *           optionally splitting in the middle of a word, and
1029
 *           appending the $etc string or inserting $etc into the middle.
1030
 *           Makes sure no tags are left half-open or half-closed (e.g. "Banana in a <a...")
1031
 * @author   Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson
1032
 *           <amos dot robinson at gmail dot com>
1033
 * used in Block entries_scrolling.php
1034
 */
1035 View Code Duplication
function lx_truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This function seems to be duplicated in 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...
1036
    if ($length == 0) return '';
1037
    if (strlen($string) > $length) {
1038
        $length -= strlen($etc);
1039
        if (!$break_words) {
1040
            $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
1041
            $string = preg_replace('/<[^>]*$/', '', $string);
1042
            $string = lx_close_tags($string);
1043
        }
1044
1045
        return $string . $etc;
1046
    } else {
1047
        return $string;
1048
    }
1049
}
1050
1051
function lexikon_summary() {
1052
global $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...
1053
1054
    $summary = [];
1055
1056
    $result01 = $xoopsDB -> query( "SELECT COUNT(*)
1057
                                   FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
1058
    list( $totalcategories ) = $xoopsDB -> fetchRow( $result01 );
1059
1060
    $result02 = $xoopsDB -> query( "SELECT COUNT(*)
1061
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
1062
                                   WHERE submit = 0" );
1063
    list( $totalpublished ) = $xoopsDB -> fetchRow( $result02 );
1064
1065
    $result03 = $xoopsDB -> query( "SELECT COUNT(*)
1066
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
1067
                                   WHERE submit = '1' AND request = '0' " );
1068
    list( $totalsubmitted ) = $xoopsDB -> fetchRow( $result03 );
1069
1070
    $result04 = $xoopsDB -> query( "SELECT COUNT(*)
1071
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
1072
                                   WHERE submit = '1' AND request = '1' " );
1073
    list( $totalrequested ) = $xoopsDB -> fetchRow( $result04 );
1074
1075
// Recuperer les valeurs dans la base de donnees
1076
1077
$summary['publishedEntries']   = $totalpublished ? $totalpublished : '0';
1078
$summary['availableCategories']   = $totalcategories ? $totalcategories : '0';
1079
$summary['submittedEntries'] = $totalsubmitted ? $totalsubmitted : '0';
1080
$summary['requestedEntries'] = $totalrequested ? $totalrequested : '0';
1081
1082
    //print_r($summary);
1083
    return $summary;
1084
1085
} // end function
1086