Completed
Pull Request — master (#12)
by
unknown
02:07
created

functions.php ➔ lx_module_header()   C

Complexity

Conditions 11
Paths 32

Size

Total Lines 43
Code Lines 29

Duplication

Lines 43
Ratio 100 %

Importance

Changes 0
Metric Value
cc 11
eloc 29
nc 32
nop 0
dl 43
loc 43
rs 5.2653
c 0
b 0
f 0

How to fix   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 21 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * $Id: functions.php v 1.0 8 May 2004 hsalazar Exp $
4
 * Module: Lexikon
5
 * Version: v 1.00
6
 * Release Date: 8 May 2004
7
 * Author: hsalazar
8
 * Additions and Modifications: Yerres
9
 * Licence: GNU
10
 */
11
12
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die( 'XOOPS root path not defined' ) ;
13
14
/**
15
 * lx_getLinkedUnameFromId()
16
 *
17
 * @param integer $userid Userid of author etc
18
 * @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...
19
 * @return
20
 **/
21 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...
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...
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...
22
    if (!is_numeric($userid)) {
23
        return $userid;
24
    }
25
26
    $userid = intval($userid);
27
    if ($userid > 0) {
28
        $member_handler = xoops_gethandler('member');
29
        $user = $member_handler->getUser($userid);
30
31
        if (is_object($user)) {
32
            $ts = MyTextSanitizer::getInstance();
33
            $username = $user->getVar('uname');
34
            $usernameu = $user->getVar('name');
35
36
            if ( ($name) && !empty($usernameu))  {
37
                $username = $user->getVar('name');
38
            }
39
            if ( !empty($usernameu)) {
40
                $linkeduser = "$usernameu [<a href='".XOOPS_URL."/userinfo.php?uid=".$userid."'>". $ts->htmlSpecialChars($username) ."</a>]";
41
            } else {
42
                $linkeduser = "<a href='".XOOPS_URL."/userinfo.php?uid=".$userid."'>". ucfirst($ts->htmlSpecialChars($username)) ."</a>";
43
            }
44
45
            return $linkeduser;
46
        }
47
    }
48
49
    return $GLOBALS['xoopsConfig']['anonymous'];
50
}
51
52 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...
53
    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...
54
55
    echo "<select name='author'>";
56
    echo "<option value='-1'>------</option>";
57
    $result = $xoopsDB->query("SELECT uid, uname FROM ".$xoopsDB->prefix("users")." ORDER BY uname");
58
59
    while (list($uid, $uname) = $xoopsDB->fetchRow($result)) {
60
        if ( $uid == $user ) {
61
            $opt_selected = "selected='selected'";
62
        } else {
63
            $opt_selected = "";
64
        }
65
        echo "<option value='".$uid."' $opt_selected>".$uname."</option>";
66
    }
67
    echo "</select></div>";
68
}
69
70 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...
71
    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...
72
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
73
    $gperm_handler = xoops_gethandler('groupperm');
74
75
    $result01 = $xoopsDB -> query( "SELECT categoryID, total FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
76
    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...
77
    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...
78
        if ($gperm_handler->checkRight('lexikon_view', $categoryID, $groups, $xoopsModule->getVar('mid'))) {
79
            $newcount = lx_countByCategory ( $categoryID );
80
            $xoopsDB -> queryF( "UPDATE " . $xoopsDB -> prefix( "lxcategories" ) . " SET total = '$newcount' WHERE categoryID = '$categoryID'");
81
        }
82
    }
83
}
84
85 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...
86
    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...
87
    $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...
88
    $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...
89
    $count = 0;
90
    $sql = $xoopsDB -> query( "SELECT entryID FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE offline = '0' AND categoryID = '$c'" );
91
    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...
92
        //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...
93
        $count++;
94
        //}
95
    }
96
97
    return $count;
98
}
99
100 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...
101
    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...
102
    $gperm_handler = xoops_gethandler('groupperm');
103
    $groups = (is_object($xoopsUser)) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
104
    $totalcats = $gperm_handler->getItemIds("lexikon_view", $groups, $xoopsModule->getVar('mid'));
105
106
    return count($totalcats);
107
}
108
109 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...
110
    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...
111
    $gperm_handler = xoops_gethandler('groupperm');
112
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
113
      $module_handler = xoops_gethandler('module');
114
    $module = $module_handler->getByDirname('lexikon');
115
    $module_id = $module->getVar('mid');
116
      $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
117
      $catids = implode(',', $allowed_cats);
118
      $catperms = " AND categoryID IN ($catids) ";
119
120
    $pubwords = $xoopsDB -> query( "SELECT * FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE submit = '0' AND offline ='0' AND request = '0' ".$catperms." " );
121
    $publishedwords = $xoopsDB -> getRowsNum ( $pubwords );
122
123
    return $publishedwords;
124
}
125
126
// To display the list of categories
127
function lx_CatsArray(){
128
    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...
129
    $myts = MyTextSanitizer::getInstance();
130
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
131
    $gperm_handler = xoops_gethandler('groupperm');
132
    $block0 = array();
133
    $count = 1;
134
    $resultcat = $xoopsDB -> query ( "SELECT categoryID, name, total, logourl FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY weight ASC" );
135
    while (list( $catID, $name, $total, $logourl) = $xoopsDB->fetchRow($resultcat)) {
136
        if ($gperm_handler->checkRight('lexikon_view', $catID, $groups, $xoopsModule->getVar('mid'))) {
137
            $catlinks = array();
138
            $count++;
139
            if ($logourl && $logourl != "http://") {
140
                $logourl = $myts->htmlSpecialChars($logourl);
141
            } else {
142
                $logourl = '';
143
            }
144
            $xoopsModule = XoopsModule::getByDirname("lexikon");
145
            $catlinks['id'] = intval($catID);
146
            $catlinks['total'] = intval($total);
147
            $catlinks['linktext'] = $myts -> htmlSpecialChars( $name );
148
            $catlinks['image'] = $logourl;
149
            $catlinks['count'] = intval($count);
150
151
            $block0['categories'][] = $catlinks;
152
        }
153
    }
154
155
    return $block0;
156
}
157
158
function lx_alphaArray () {
159
    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...
160
    $gperm_handler = xoops_gethandler('groupperm');
161
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
162
      $module_handler = xoops_gethandler('module');
163
    $module = $module_handler->getByDirname('lexikon');
164
    $module_id = $module->getVar('mid');
165
    $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
166
    $catids = implode(',', $allowed_cats);
167
      $catperms = " AND categoryID IN ($catids) ";
168
    $alpha = array();
169 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...
170
        $letterlinks = array();
171
        $initial = chr($a);
172
        $sql = $xoopsDB -> query ( "SELECT entryID FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '$initial' AND submit = '0' AND offline ='0' AND request = '0' ".$catperms."");
173
        $howmany = $xoopsDB -> getRowsNum( $sql );
174
        $letterlinks['total'] = $howmany;
175
        $letterlinks['id'] = chr($a);
176
        $letterlinks['linktext'] = chr($a);
177
178
        $alpha['initial'][] = $letterlinks;
179
    }
180
181
    return $alpha;
182
}
183
184
/**
185
 * chr() with unicode support
186
 * I found this on this site http://en.php.net/chr
187
 * don't take credit for this.
188
 *
189
 */
190 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...
191
    if (is_scalar($initials)) $initials= func_get_args();
192
    $str= '';
193
    foreach ($initials as $init) $str.= html_entity_decode('&#'.$init.';',ENT_NOQUOTES,'UTF-8');
194
195
    return $str;
196
}
197
/* sample */
198
/*
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...
199
    echo lx_uchr(23383); echo '<br/>';
200
    echo lx_uchr(23383,215,23383); echo '<br/>';
201
    echo lx_uchr(array(23383,215,23383,215,23383)); echo '<br/>';
202
*/
203
204
// Functional links
205 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...
206
    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...
207
208
    $module_handler  = xoops_gethandler('module');
209
    $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...
210
    $pathIcon16 = $xoopsModule->getInfo('icons16');
211
212
    $srvlinks = "";
213
    if ( $xoopsUser ) {
214
        if ( $xoopsUser->isAdmin() ) {
215
            $srvlinks .= "<a TITLE=\""._EDIT."\" href=\"admin/entry.php?op=mod&entryID=".$variable['id']."\" target=\"_blank\"><img src=\"" . $pathIcon16. "/edit.png\" alt=\""._MD_LEXIKON_EDITTERM."\" style=\"width:16px; height:16px;\"></a>&nbsp;<a TITLE=\""._DELETE."\" href=\"admin/entry.php?op=del&entryID=".$variable['id']."\" target=\"_self\"><img src=\"" . $pathIcon16. "/delete.png\"   alt=\""._MD_LEXIKON_DELTERM."\" style=\"width:16px; height:16px;\"></a>&nbsp;";
216
        }
217
    }
218
    if ( $entrytype != "1" ) {
219
        $srvlinks .= "<a TITLE=\""._MD_LEXIKON_PRINTTERM."\" href=\"print.php?entryID=".$variable['id']."\" target=\"_blank\"><img src=\"" . $pathIcon16. "/printer.png\" alt=\""._MD_LEXIKON_PRINTTERM."\" style=\"width:16px; height:16px;\"></a>&nbsp;<a TITLE=\""._MD_LEXIKON_SENDTOFRIEND."\" href=\"mailto:?subject=".sprintf(_MD_LEXIKON_INTENTRY,$xoopsConfig["sitename"])."&amp;body=".sprintf(_MD_LEXIKON_INTENTRYFOUND, $xoopsConfig['sitename']).": ".XOOPS_URL."/modules/".$xoopsModule->dirname()."/entry.php?entryID=".$variable['id']." \" target=\"_blank\"><img src=\"" . $pathIcon16. "/mail_replay.png\"   alt=\""._MD_LEXIKON_SENDTOFRIEND."\" style=\"width:16px; height:16px;\"></a>&nbsp;";
220
        if (( $xoopsModuleConfig['com_rule'] != 0 ) && (!empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser))) {
221
            $srvlinks .= "<a TITLE=\""._COMMENTS."?\" href=\"comment_new.php?com_itemid=".$variable['id']."\" target=\"_parent\"><img src=\"images/comments.gif\" alt=\"" ._COMMENTS. "?\" style=\"width:16px; height:16px;\"></a>&nbsp;";
222
            }
223
    }
224
225
    return $srvlinks;
226
}
227
// entry footer
228
function lx_serviceLinksnew ( $variable ) {
229
    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...
230
    $srvlinks2 = "<a title=\""._MD_LEXIKON_PRINTTERM."\" href=\"print.php?entryID=".$variable['id']."\" target=\"_blank\"><img src=\"images/print.gif\" alt=\""._MD_LEXIKON_PRINTTERM."\" style=\"vertical-align: middle; width:16px; height:16px; margin: 2px 4px;\"> "._MD_LEXIKON_PRINTTERM2."</a>&nbsp; <a title=\""._MD_LEXIKON_SENDTOFRIEND."\" href=\"mailto:?subject=".sprintf(_MD_LEXIKON_INTENTRY,$xoopsConfig["sitename"])."&amp;body=".sprintf(_MD_LEXIKON_INTENTRYFOUND, $xoopsConfig['sitename']).": ".$variable['term']." ".XOOPS_URL."/modules/".$xoopsModule->dirname()."/entry.php?entryID=".$variable['id']." \" target=\"_blank\"><img src=\"images/friend.gif\" alt=\""._MD_LEXIKON_SENDTOFRIEND."\" style=\"vertical-align: middle; width:16px; height:16px; margin: 2px 4px;\"> "._MD_LEXIKON_SENDTOFRIEND2."</a>&nbsp;";
231
232
    return $srvlinks2;
233
}
234
235 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...
236
    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...
237
    $gperm_handler = xoops_gethandler('groupperm');
238
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
239
    
240
    $searchform = "<table style=\"width:100%;\">";
241
    $searchform .= "<form name=\"op\" id=\"op\" action=\"search.php\" method=\"post\">";
242
    $searchform .= "<tr><td style=\"text-align: right; line-height: 200%; width:150px;\">";
243
    $searchform .= _MD_LEXIKON_LOOKON."</td><td style=\"width:10px;\">&nbsp;</td><td style=\"text-align: left;\">";
244
    $searchform .= "<select name=\"type\"><option value=\"1\">"._MD_LEXIKON_TERMS."</option><option value=\"2\">"._MD_LEXIKON_DEFINS."</option>";
245
    $searchform .= "<option SELECTED value=\"3\">"._MD_LEXIKON_TERMSDEFS."</option></select></td></tr>";
246
247
    if ($xoopsModuleConfig['multicats'] == 1) {
248
        $searchform .= "<tr><td style=\"text-align: right; line-height: 200%;\">"._MD_LEXIKON_CATEGORY."</td>";
249
        $searchform .= "<td>&nbsp;</td><td style=\"text-align: left;\">";
250
        $resultcat = $xoopsDB -> query ( "SELECT categoryID, name FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY categoryID" );
251
        $searchform .= "<select name=\"categoryID\">";
252
        $searchform .= "<option value=\"0\">"._MD_LEXIKON_ALLOFTHEM."</option>";
253
254
        while (list( $categoryID, $name) = $xoopsDB->fetchRow($resultcat)) {
255
            if ($gperm_handler->checkRight('lexikon_view', intval($categoryID), $groups, $xoopsModule->getVar('mid'))) {
256
                $searchform .= "<option value=\"$categoryID\">$categoryID : $name</option>";
257
            }
258
        }
259
        $searchform .= "</select></td></tr>";
260
    }
261
262
    $searchform .= "<tr><td style=\"text-align: right; line-height: 200%;\">";
263
    $searchform .= _MD_LEXIKON_TERM."</td><td>&nbsp;</td><td style=\"text-align: left;\">";
264
    $searchform .= "<input type=\"text\" name=\"term\" class=\"searchBox\" /></td></tr><tr>";
265
    $searchform .= "<td>&nbsp;</td><td>&nbsp;</td><td><input type=\"submit\" class=\"btnDefault\" value=\""._MD_LEXIKON_SEARCH."\" />";
266
    $searchform .= "</td></tr></form></table>";
267
268
    return $searchform;
269
}
270
271 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...
272
    $parts = explode(">", $haystack);
273
    foreach($parts as $key=>$part) {
274
        $pL = "";
275
        $pR = "";
276
277
        if (($pos = strpos($part, "<")) === false)
278
            $pL = $part;
279
        elseif($pos > 0) {
280
            $pL = substr($part, 0, $pos);
281
            $pR = substr($part, $pos, strlen($part));
282
        }
283
        if ($pL != "")
284
            $parts[$key] = preg_replace('|('.quotemeta($needle).')|iU', $hlS.'\\1'.$hlE, $pL) . $pR;
285
    }
286
287
    return(implode(">", $parts));
288
}
289
290
/* *******************************************************************************
291
 * Most of the following functions are modified functions from Herve's News Module
292
 * other functions are from  AMS by Novasmart/Mithrandir
293
 * others from Red Mexico Soft Rmdp
294
 * others from Xhelp 0.78 thanks to ackbarr and eric_juden
295
 * *******************************************************************************
296
 */
297
298
// Create the meta keywords based on content
299 View Code Duplication
function lx_extract_keywords($content) {
0 ignored issues
show
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...
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...
300
    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...
301
    include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php';
302
    $keywords_count = $xoopsModuleConfig['metakeywordsnum'];
303
    $tmp=array();
304
    if (isset($_SESSION['xoops_keywords_limit'])) {    // Search the "Minimum keyword length"
305
        $limit = $_SESSION['xoops_keywords_limit'];
306
    } else {
307
        $config_handler = xoops_gethandler('config');
308
        $xoopsConfigSearch = $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
309
        $limit=$xoopsConfigSearch['keyword_min'];
310
        $_SESSION['xoops_keywords_limit']=$limit;
311
    }
312
    $myts = MyTextSanitizer::getInstance();
313
    $content = str_replace ("<br />", " ", $content);
314
    $content= $myts->undoHtmlSpecialChars($content);
315
    $content= strip_tags($content);
316
    $content=strtolower($content);
317
    $search_pattern=array("&nbsp;","\t","\r\n","\r","\n",",",".","'",";",":",")","(",'"','?','!','{','}','[',']','<','>','/','+','-','_','\\','*');
318
    $replace_pattern=array(' ',' ',' ',' ',' ',' ',' ',' ','','','','','','','','','','','','','','','','','','','');
319
    $content = str_replace($search_pattern, $replace_pattern, $content);
320
    $keywords=explode(' ',$content);
321
    switch (META_KEYWORDS_ORDER) {
322
    case 1:    // Returns keywords in the same order that they were created in the text
323
            $keywords=array_unique($keywords);
324
        break;
325
326
    case 2:    // the keywords order is made according to the reverse keywords frequency (so the less frequent words appear in first in the list)
327
        $keywords=array_count_values($keywords);
328
        asort($keywords);
329
        $keywords=array_keys($keywords);
330
        break;
331
332
    case 3:    // Same as previous, the only difference is that the most frequent words will appear in first in the list
333
        $keywords=array_count_values($keywords);
334
        arsort($keywords);
335
        $keywords=array_keys($keywords);
336
        break;
337
    }
338
    foreach($keywords as $keyword) {
339
        if (strlen($keyword)>=$limit && !is_numeric($keyword)) {
340
            $tmp[]=$keyword;
341
        }
342
    }
343
    $tmp=array_slice($tmp,0,$keywords_count);
344
    if (count($tmp)>0) {
345
        if (isset($xoTheme) && is_object($xoTheme)) {
346
            $xoTheme->addMeta( 'meta', 'keywords', implode(',',$tmp));
347
        } else {    // Compatibility for old Xoops versions
348
            $xoopsTpl->assign('xoops_meta_keywords', implode(',',$tmp));
349
        }
350
    } else {
351
        if (!isset($config_handler) || !is_object($config_handler)) {
352
            $config_handler = xoops_gethandler('config');
353
        }
354
        $xoopsConfigMetaFooter = $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
355
        if (isset($xoTheme) && is_object($xoTheme)) {
356
            $xoTheme->addMeta( 'meta', 'keywords', $xoopsConfigMetaFooter['meta_keywords']);
357
        } else {    // Compatibility for old Xoops versions
358
            $xoopsTpl->assign('xoops_meta_keywords', $xoopsConfigMetaFooter['meta_keywords']);
359
        }
360
    }
361
}
362
363
// Create meta description based on content
364 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...
365
    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...
366
    $myts = MyTextSanitizer::getInstance();
367
    $content= $myts->undoHtmlSpecialChars($myts->displayTarea($content));
368
    if (isset($xoTheme) && is_object($xoTheme)) {
369
        $xoTheme->addMeta( 'meta', 'description', strip_tags($content));
370
    } else {  // Compatibility for old Xoops versions
371
        $xoopsTpl->assign('xoops_meta_description', strip_tags($content));
372
    }
373
}
374
375
// Create pagetitles
376 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...
377
    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...
378
    $myts = MyTextSanitizer::getInstance();
379
    $content='';
380
    if (!empty($article)) $content .= strip_tags($myts->displayTarea($article));
381
    if (!empty($topic)) {
382
        if (xoops_trim($content)!='') {
383
            $content .= ' - '.strip_tags($myts->displayTarea($topic));
384
        } else {
385
            $content .= strip_tags($myts->displayTarea($topic));
386
        }
387
    }
388
    if (is_object($xoopsModule) && xoops_trim($xoopsModule->name())!='') {
389
        if (xoops_trim($content)!='') {
390
            $content.=' - '.strip_tags($myts->displayTarea($xoopsModule->name()));
391
        } else {
392
            $content.=strip_tags($myts->displayTarea($xoopsModule->name()));
393
        }
394
    }
395
    if ($content!='') {
396
        $xoopsTpl->assign('xoops_pagetitle', $content);
397
    }
398
}
399
400
// clear descriptions
401 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...
402
    // PHP Manual:: function preg_replace $document should contain an HTML document.
403
    // This will remove HTML tags, javascript sections and white space. It will also
404
    // convert some common HTML entities to their text equivalent.
405
406
    $search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
407
                     "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
408
                     "'([\r\n])[\s]+'",                // Strip out white space
409
                     "'&(quot|#34);'i",                // Replace HTML entities
410
                     "'&(amp|#38);'i",
411
                     "'&(lt|#60);'i",
412
                     "'&(gt|#62);'i",
413
                     "'&(nbsp|#160);'i",
414
                     "'&(iexcl|#161);'i",
415
                     "'&(cent|#162);'i",
416
                     "'&(pound|#163);'i",
417
                     "'&(copy|#169);'i");
418
419
    $replace = array ("",
420
                      "",
421
                      "\\1",
422
                      "\"",
423
                      "&",
424
                      "<",
425
                      ">",
426
                      " ",
427
                      chr(161),
428
                      chr(162),
429
                      chr(163),
430
                      chr(169));
431
432
    $text = preg_replace($search, $replace, $document);
433
434
    $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...
435
436
    return $text;
437
}
438
439
//Retrieve moduleoptions equivalent to $Xoopsmoduleconfig
440 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...
441
    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...
442
    static $tbloptions= Array();
443
    if (is_array($tbloptions) && array_key_exists($option,$tbloptions)) {
444
        return $tbloptions[$option];
445
    }
446
447
    $retval=false;
448
    if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) {
449
        if (isset($xoopsModuleConfig[$option])) {
450
            $retval= $xoopsModuleConfig[$option];
451
        }
452
    } else {
453
        $module_handler = xoops_gethandler('module');
454
        $module = $module_handler->getByDirname($repmodule);
455
        $config_handler = xoops_gethandler('config');
456
        if ($module) {
457
            $moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
458
            if (isset($moduleConfig[$option])) {
459
                $retval= $moduleConfig[$option];
460
            }
461
        }
462
    }
463
    $tbloptions[$option]=$retval;
464
465
    return $retval;
466
}
467
468
/**
469
 * Is Xoops 2.3.x ?
470
 *
471
 * @return boolean need to say it ?
472
 */
473 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...
474
{
475
    $x23 = false;
476
    $xv = str_replace('XOOPS ','',XOOPS_VERSION);
477
    if(substr($xv,2,1) >= '3') {
478
        $x23 = true;
479
    }
480
481
    return $x23;
482
}
483
484
/**
485
 * Retreive an editor according to the module's option "form_options"
486
 * following function is from News modified by trabis
487
 */
488 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...
489
{
490
    $editor_option = strtolower(lx_getmoduleoption('form_options'));
491
    $editor = false;
492
    $editor_configs=array();
493
    $editor_configs['name'] =$name;
494
    $editor_configs['value'] = $value;
495
    $editor_configs['rows'] = 35;
496
    $editor_configs['cols'] = 60;
497
    $editor_configs['width'] = '100%';
498
    $editor_configs['height'] = '350px';
499
    $editor_configs['editor'] = $editor_option;
500
501
    if(lx_isX23()) {
502
        $editor = new XoopsFormEditor($caption, $name, $editor_configs);
503
504
        return $editor;
505
            }
506
507
    // Only for Xoops 2.0.x
508
    switch($editor_option) {
509
        case 'fckeditor':
510
            if ( is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'))    {
511
                require_once(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php');
512
                $editor = new XoopsFormFckeditor($caption, $name, $value);
513
            }
514
            break;
515
516
        case 'htmlarea':
517
                if ( is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'))    {
518
                require_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php');
519
                    $editor = new XoopsFormHtmlarea($caption, $name, $value);
520
            }
521
            break;
522
523
        case 'dhtmltextarea':
524
        case 'dhtml':
525
                $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental);
526
            break;
527
528
        case 'textarea':
529
            $editor = new XoopsFormTextArea($caption, $name, $value);
530
            break;
531
532
        case 'tinyeditor':
533
        case 'tinymce':
534
            if ( is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) {
535
                require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php';
536
                $editor = new XoopsFormTinyeditorTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'400px'));
537
            }
538
            break;
539
540
        case 'koivi':
541
                if ( is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) {
542
                require_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php');
543
                $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, '');
544
            }
545
            break;
546
        }
547
548
        return $editor;
549
}
550
551
/**
552
 * linkterms: assign module header
553
 *
554
 * tooltips (c) dhtmlgoodies
555
 */
556 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...
557
    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...
558
    if(isset($xoTheme) && is_object($xoTheme)) {
559
        $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/style.css' );
560
        if ($xoopsModuleConfig['linkterms'] == 3) {
561
            $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' );
562
            $xoTheme->addScript( '/modules/lexikon/assets/js/tooltipscript2.js', array( 'type' => 'text/javascript' ) );
563
            }
564
        if ($xoopsModuleConfig['linkterms'] == 4) {
565
            $xoTheme->addScript( '/modules/lexikon/assets/js/popup.js', array( 'type' => 'text/javascript' ) );
566
            }
567
        if ($xoopsModuleConfig['linkterms'] == 5) {
568
            $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' );
569
            $xoTheme->addScript( '/modules/lexikon/assets/js/balloontooltip.js', array( 'type' => 'text/javascript' ) );
570
            }
571
        if ($xoopsModuleConfig['linkterms'] == 6) {
572
            $xoTheme -> addStylesheet( 'modules/lexikon/assets/css/linkterms.css' );
573
            $xoTheme->addScript( '/modules/lexikon/assets/js/shadowtooltip.js', array( 'type' => 'text/javascript' ) );
574
            }
575
    } else {
576
        $lexikon_url = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname');
577
        if ($xoopsModuleConfig['linkterms'] == 3) {
578
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
579
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
580
			<script src="'.$lexikon_url.'/assets/js/tooltipscript2.js" type="text/javascript"></script>';
581
            }
582
        if ($xoopsModuleConfig['linkterms'] == 4) {
583
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
584
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
585
			<script src="'.$lexikon_url.'/assets/js/popup.js" type="text/javascript"></script>';
586
            }
587
        if ($xoopsModuleConfig['linkterms'] == 5) {
588
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
589
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
590
			<script src="'.$lexikon_url.'/assets/js/balloontooltip.js" type="text/javascript"></script>';
591
            }
592
        if ($xoopsModuleConfig['linkterms'] == 6) {
593
            $lexikon_module_header = '<link rel="stylesheet" type="text/css" href="style.css" />
594
			<link rel="stylesheet" type="text/css" href="assets/css/linkterms.css" />
595
			<script src="'.$lexikon_url.'/assets/js/shadowtooltip.js" type="text/javascript"></script>';
596
            }
597
        }
598
}
599
600
/**
601
 * Validate userid
602
 */
603 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...
604
    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...
605
606
    if ($uids<=0) {
607
        return false;
608
    }
609
    if ($uids > 0) {
610
        $member_handler = xoops_gethandler('member');
611
        $user = $member_handler->getUser($uids);
612
        if (!is_object($user)) {
613
            return false;
614
        }
615
    }
616
    $result = $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("users")." WHERE uid='$uids'");
617
    if ($xoopsDB->getRowsNum($result)<=0) {
618
        return false;
619
    }
620
    $row = $xoopsDB->fetchArray($result);
621
622
    return $row;
623
}
624
625
// Get all terms published by an author
626
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...
627
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
628
    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...
629
    $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...
630
    //permissions
631
    $gperm_handler = xoops_gethandler('groupperm');
632
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
633
    $module_handler = xoops_gethandler('module');
634
    $module = $module_handler->getByDirname('lexikon');
635
    $module_id = $module->getVar('mid');
636
    $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
637
    $catids = implode(',', $allowed_cats);
638
    $catperms = " AND categoryID IN ($catids) ";
639
        
640
    $start = isset( $_GET['start'] ) ? intval( $_GET['start'] ) : 0;
641
    $limit = $xoopsModuleConfig['indexperpage'];
642
643
    $sql = $xoopsDB -> query( "SELECT *
644
                              FROM " . $xoopsDB -> prefix( "lxentries" ) . "
645
                              WHERE uid='".intval($uid)."' AND  offline = '0' AND submit = '0' AND request = '0' ".$catperms."
646
                              ORDER BY term
647
                              LIMIT $start,$limit");
648
649 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...
650
        $xoopsTpl->append('entries', array('id'=>$row['entryID'],'name'=>$row['term'],'date'=>date($xoopsModuleConfig['dateformat'], $row['datesub']),'counter'=>$row['counter']));
651
    }
652
653
    $navstring = '';
654
    $navstring .= "uid=".$uid."&start";
655
    $pagenav = new XoopsPageNav( $authortermstotal , $xoopsModuleConfig['indexperpage'], $start, $navstring);
656
    $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...
657
    $xoopsTpl -> assign( 'authortermsarr', $authortermsarr);
658
}
659
660
// Returns the author's IDs for authorslist
661 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...
662
    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...
663
664
    $ret = array();
665
    $sql = 'SELECT distinct(uid) as uid FROM '.$xoopsDB->prefix('lxentries').' WHERE offline = 0 ';
666
    $sql .= " ORDER BY uid";
667
    $result = $xoopsDB->query($sql);
668
    while ( $myrow = $xoopsDB->fetchArray($result) ) {
669
        $ret[] = $myrow['uid'];
670
    }
671
672
    return $ret;
673
}
674
675
// link to userprofile
676 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...
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...
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...
677
    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...
678
    $userid = intval($uid);
679
    if ($userid > 0) {
680
        $member_handler = xoops_gethandler('member');
681
        $user = $member_handler->getUser($userid);
682
        if (is_object($user)) {
683
            $linkeduser = '<A TITLE="'._MD_LEXIKON_AUTHORPROFILETEXT.'" HREF="'.XOOPS_URL.'/modules/'.$xoopsModule->dirname().'/profile.php?uid='.$uid.'">'. $user->getVar('uname').'</a>';
684
            //$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...
685
            //$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...
686
            return $linkeduser;
687
        }
688
    }
689
690
    return $GLOBALS['xoopsConfig']['anonymous'];
691
}
692
693
// functionset to assign terms with accentuated or umlaut initials to the adequate initial
694 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...
695
    $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...
696
      .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
697
      .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
698
      .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
699
      .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
700
      .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
701
      .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
702
      .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
703
      .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
704
      .chr(252).chr(253).chr(255);
705
    $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
706
    if (lx_seemsUtf8($string)) {
707
        $invalid_latin_chars = array(chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe', chr(197).chr(160) => 'S', chr(197).chr(189) => 'Z', chr(197).chr(161) => 's', chr(197).chr(190) => 'z', chr(226).chr(130).chr(172) => 'E');
708
        $string = utf8_decode(strtr($string, $invalid_latin_chars));
709
    }
710
    $string = strtr($string, $chars['in'], $chars['out']);
711
    $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
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...
712
    $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
713
    $string = str_replace($double_chars['in'], $double_chars['out'], $string);
714
715
    return $string;
716
}
717
718
function lx_seemsUtf8($Str) { # by bmorel at ssi dot fr
719
    for ($i=0; $i<strlen($Str); $i++) {
720 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...
721
        elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
722
        elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
723
        elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
724
        elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
725
        elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
726
        else return false; # Does not match any model
727 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...
728
            if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
729
            return false;
730
        }
731
    }
732
733
    return true;
734
}
735
736 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...
737
    $field = lx_removeAccents($field);
738
    $field = strtolower($field);
739
    $field = preg_replace('/&.+?;/', '', $field); // kill entities
740
    $field = preg_replace('/[^a-z0-9 _-]/', '', $field);
741
    $field = preg_replace('/\s+/', ' ', $field);
742
    $field = str_replace(' ', '-', $field);
743
    $field = preg_replace('|-+|', '-', $field);
744
    $field = trim($field, '-');
745
746
    return $field;
747
}
748
749
// Verify that a term does not exist for submissions and requests (both user frontend and admin backend)
750 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...
751
    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...
752
    $sql = sprintf('SELECT COUNT(*) FROM %s WHERE term = %s', $table, $xoopsDB->quoteString(addslashes($term)));
753
    $result = $xoopsDB->query($sql);
754
    list($count) = $xoopsDB->fetchRow($result);
755
756
    return($count);
757
}
758
759
// Static method to get author data block authors - from AMS
760
function lexikon_block_getAuthors($limit = 5, $sort = "count", $name = 'uname', $compute_method = "average") {
761
    $limit = intval($limit);
762
    if ($name != "uname")
763
        $name = "name"; //making sure that there is not invalid information in field value
764
    $ret = array();
765
    $db = XoopsDatabaseFactory::getDatabaseConnection();
766
    if ($sort == "count") {
767
        $sql = "SELECT u.".$name." AS name, u.uid , count( n.entryID ) AS count
768
              FROM ".$db->prefix("users")." u, ".$db->prefix("lxentries")." n
769
              WHERE u.uid = n.uid
770
              AND n.datesub > 0 AND n.datesub <= ".time()." AND n.offline = 0 AND n.submit = 0
771
              GROUP BY u.uid ORDER BY count DESC";
772 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...
773
        if ($compute_method == "average") {
774
            $compute = "sum( n.counter ) / count( n.entryID )";
775
        } else {
776
            $compute = "sum( n.counter )";
777
        }
778
        $sql = "SELECT u.".$name." AS name, u.uid , $compute AS count
779
              FROM ".$db->prefix("users")." u, ".$db->prefix("lxentries")." n
780
              WHERE u.uid = n.uid
781
              AND n.datesub > 0 AND n.datesub <= ".time()." AND n.offline = 0 AND n.submit = 0
782
              GROUP BY u.uid ORDER BY count DESC";
783
    }
784
    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...
785
        return false;
786
        
787 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...
788
        if ($name == "name" && $row['name'] == '')
789
            $row['name'] = XoopsUser::getUnameFromId($row['uid']);
790
        $row['count'] = round($row['count'], 0);
791
        $ret[] = $row;
792
    }
793
794
    return $ret;
795
}
796
797
/**
798
 * close all unclosed xhtml tags *Test*
799
 *
800
 * @param string $html
801
 * @return string
802
 * @author Milian Wolff <mail -at- milianw.de>
803
 */
804 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...
805
  // put all opened tags into an array
806
  preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
807
  $openedtags=$result[1];
808
809
  // put all closed tags into an array
810
  preg_match_all("#</([a-z]+)>#iU",$html,$result);
811
  $closedtags=$result[1];
812
  $len_opened = count($openedtags);
813
  // all tags are closed
814
  if(count($closedtags) == $len_opened){
815
    return $html;
816
  }
817
818
  $openedtags = array_reverse($openedtags);
819
  // close tags
820
  for($i=0;$i < $len_opened;$i++) {
821
    if (!in_array($openedtags[$i],$closedtags)){
822
      $html .= '</'.$openedtags[$i].'>';
823
    } else {
824
      unset($closedtags[array_search($openedtags[$i],$closedtags)]);
825
    }
826
  }
827
828
  return $html;
829
}
830
831
/**
832
 * @author   Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson
833
 *           <amos dot robinson at gmail dot com>
834
 */
835 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...
836
    // match opened tags
837
    if(preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
838
        $start_tags = $start_tags[1];
839
        // match closed tags
840
        if(preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
841
            $complete_tags = array();
842
            $end_tags = $end_tags[1];
843
    
844
            foreach($start_tags as $key => $val) {
845
                $posb = array_search($val, $end_tags);
846
                   if(is_integer($posb)) {
847
                      unset($end_tags[$posb]);
848
                   } else {
849
                    $complete_tags[] = $val;
850
                }
851
            }
852
        } else {
853
            $complete_tags = $start_tags;
854
        }
855
        
856
        $complete_tags = array_reverse($complete_tags);
857
        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...
858
            $string .= '</' . $complete_tags[$i] . '>';
859
        }
860
    }
861
862
    return $string;
863
}
864
865
/**
866
 * Smarty plugin
867
 * @package Smarty
868
 * @subpackage plugins
869
 */
870
/**
871
 * Smarty truncate_tagsafe modifier plugin
872
 *
873
 * Type:     modifier<br>
874
 * Name:     truncate_tagsafe<br>
875
 * Purpose:  Truncate a string to a certain length if necessary,
876
 *           optionally splitting in the middle of a word, and
877
 *           appending the $etc string or inserting $etc into the middle.
878
 *           Makes sure no tags are left half-open or half-closed (e.g. "Banana in a <a...")
879
 * @author   Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson
880
 *           <amos dot robinson at gmail dot com>
881
 * used in Block entries_scrolling.php
882
 */
883 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...
884
    if ($length == 0) return '';
885
    if (strlen($string) > $length) {
886
        $length -= strlen($etc);
887
        if (!$break_words) {
888
            $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
889
            $string = preg_replace('/<[^>]*$/', '', $string);
890
            $string = lx_close_tags($string);
891
        }
892
893
        return $string . $etc;
894
    } else {
895
        return $string;
896
    }
897
}
898
899
function lexikon_summary() {
900
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...
901
902
    $summary = array();
903
904
    $result01 = $xoopsDB -> query( "SELECT COUNT(*)
905
                                   FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
906
    list( $totalcategories ) = $xoopsDB -> fetchRow( $result01 );
907
908
    $result02 = $xoopsDB -> query( "SELECT COUNT(*)
909
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
910
                                   WHERE submit = 0" );
911
    list( $totalpublished ) = $xoopsDB -> fetchRow( $result02 );
912
913
    $result03 = $xoopsDB -> query( "SELECT COUNT(*)
914
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
915
                                   WHERE submit = '1' AND request = '0' " );
916
    list( $totalsubmitted ) = $xoopsDB -> fetchRow( $result03 );
917
918
    $result04 = $xoopsDB -> query( "SELECT COUNT(*)
919
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
920
                                   WHERE submit = '1' AND request = '1' " );
921
    list( $totalrequested ) = $xoopsDB -> fetchRow( $result04 );
922
923
// Recuperer les valeurs dans la base de donnees
924
925
$summary['publishedEntries']   = $totalpublished ? $totalpublished : '0';
926
$summary['availableCategories']   = $totalcategories ? $totalcategories : '0';
927
$summary['submittedEntries'] = $totalsubmitted ? $totalsubmitted : '0';
928
$summary['requestedEntries'] = $totalrequested ? $totalrequested : '0';
929
930
    //print_r($summary);
931
    return $summary;
932
933
} // end function
934