Passed
Push — master ( fd97e0...73464b )
by Michael
02:21 queued 11s
created

member_search()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 6
eloc 20
nc 8
nop 5
dl 0
loc 29
rs 8.9777
c 3
b 0
f 0
1
<?php
2
3
/**
4
 * @param $queryarray
5
 * @param $andor
6
 * @param $limit
7
 * @param $offset
8
 * @param $userid
9
 * @return array
10
 */
11
function member_search($queryarray, $andor, $limit, $offset, $userid)
12
{
13
    $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('users') . ' WHERE level > 0';
14
    if (0 != $userid) {
15
        $sql .= " AND uid='0'";
16
    }
17
    // because count() returns 1 even if a supplied variable  
18
    // is not an array, we must check if $querryarray is really an array  
19
    if (is_array($queryarray) && $count = count($queryarray)) {
20
        $sql .= " AND ((uname LIKE '%{$queryarray[0]}%' OR name LIKE '%{$queryarray[0]}%')";
21
        for ($i = 1; $i < $count; $i++) {
22
            $sql .= " $andor ";
23
            $sql .= "(uname LIKE '%{$queryarray[$i]}%' OR name LIKE '%{$queryarray[$i]}%')";
24
        }
25
        $sql .= ') ';
26
    }
27
    $sql .= ' ORDER BY uname,name ASC';
28
29
    $result = $GLOBALS['xoopsDB']->query($sql, (int)$limit, (int)$offset);
30
    $ret    = [];
31
    $i      = 0;
32
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
33
        $ret[$i]['link']  = '' . XOOPS_URL . "\userinfo.php?uid=" . $myrow['uid'] . '';
34
        $ret[$i]['title'] = '' . htmlspecialchars($myrow['uname'], ENT_QUOTES | ENT_HTML5) . ' / ' . htmlspecialchars($myrow['name'], ENT_QUOTES | ENT_HTML5) . '';
35
        $ret[$i]['time']  = '' . $myrow['user_regdate'] . '';
36
        $ret[$i]['uid']   = '' . $myrow['uid'] . '';
37
        $i++;
38
    }
39
    return $ret;
40
}
41
42
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
43