Passed
Push — master ( 52e9bd...87584b )
by Michael
01:55
created

index.php (2 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * Xoops Members Module
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright XOOPS Project (https://xoops.org)
14
 * @license http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package Xoops Members
16
 * @since 2.3.0
17
 * @author onokazu
18
 * @author John Neill
19
 */
20
21
$xoopsOption['template_main'] = 'xoopsmembers_index.tpl';
22
require_once  __DIR__ . '/header.php';
23
//global $pathIcon16;
24
25
global $xoopsModule;
26
27
/** @var \XoopsMemberHandler $memberHandler */
28
$memberHandler = xoops_getHandler('member');
29
    $total     = $memberHandler->getUserCount( new Criteria( 'level', 0, '>' ) );
30
31
    $iamadmin = $xoopsUserIsAdmin;
32
$myts     = \MyTextSanitizer::getInstance();
33
$criteria = new \CriteriaCompo();
34
35
$criteria->add(new \Criteria('level', 0, '>'));
36
$validsort = ['uname', 'name', 'last_login', 'user_regdate', 'posts'];
37
$sort      = (!in_array($helper->getModule()->getInfo('sortmembers'), $validsort)) ? 'uname' : $helper->getModule()->getInfo('sortmembers');
38
    
39
	$order = 'ASC';
40
$temp  = $helper->getModule()->getInfo('membersorder');
41
if (isset($temp) && 'DESC' == $temp) {
42
        $order = 'DESC';
43
    }
44
    $limit = \Xmf\Request::getInt('limit', 20, 'POST');
45
if (0 == $limit || $limit > 50) {
46
        $limit = 50;
47
    }
48
49
    $start         = \Xmf\Request::getInt('start', 0, 'POST');
50
    $memberHandler = xoops_getHandler('member');
51
    $total         = $memberHandler->getUserCount($criteria);
0 ignored issues
show
The method getUserCount() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
    $total         = $memberHandler->/** @scrutinizer ignore-call */ getUserCount($criteria);
Loading history...
52
	$xoopsTpl->assign( 'totalmember', $total );
53
54
if (0 == $total) {
55
    } elseif ( $start < $total ) {
56
        if ( $iamadmin ) {
57
            $xoopsTpl->assign( 'is_admin', true );
58
        }
59
        $criteria->setSort( $sort );
60
        $criteria->setOrder( $order );
61
        $criteria->setStart( $start );
62
        $criteria->setLimit( $limit );
63
        $foundusers = $memberHandler->getUsers($criteria, true);
0 ignored issues
show
The method getUsers() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        /** @scrutinizer ignore-call */ 
64
        $foundusers = $memberHandler->getUsers($criteria, true);
Loading history...
64
        foreach ( array_keys( $foundusers ) as $j ) {
65
            $userdata['avatar']   = $foundusers[$j]->getVar('user_avatar') ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar('user_avatar') . '" alt="">' : '&nbsp;';
66
        $userdata['realname'] = $foundusers[$j]->getVar('name') ?: '&nbsp;';
67
        $userdata['name']     = $foundusers[$j]->getVar('uname');
68
        $userdata['id']       = $foundusers[$j]->getVar('uid');
69
        if (1 == $foundusers[$j]->getVar('user_viewemail') || $iamadmin) {
70
                $userdata['email'] = '<a href="mailto:' . $foundusers[$j]->getVar('email') . '"><img src="' . XOOPS_URL . '/images/icons/email.gif" border="0" alt="' . sprintf(_SENDEMAILTO, $foundusers[$j]->getVar('uname', 'e')) . '"></a>';
71
            } else {
72
            $userdata['email'] = '&nbsp;';
73
            }
74
            if ( $xoopsUser ) {
75
            $userdata['pmlink'] = '<a href="javascript:openWithSelfMain(\'' . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $foundusers[$j]->getVar('uid') . '\',\'pmlite\',450,370);"><img src="' . XOOPS_URL . '/images/icons/pm.gif" border="0" alt="' . sprintf(_SENDPMTO, $foundusers[$j]->getVar('uname', 'e')) . '"></a>';
76
            } else {
77
            $userdata['pmlink'] = '&nbsp;';
78
            }
79
        if ('' != $foundusers[$j]->getVar('url', 'e')) {
80
                $userdata['website'] = '<a href="' . $foundusers[$j]->getVar('url', 'e') . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '"></a>';
81
            } else {
82
            $userdata['website'] = '&nbsp;';
83
            }
84
        $userdata['registerdate'] = formatTimestamp($foundusers[$j]->getVar('user_regdate'), 's');
85
        if (0 != $foundusers[$j]->getVar('last_login')) {
86
            $userdata['lastlogin'] = formatTimestamp($foundusers[$j]->getVar('last_login'), 'm');
87
            } else {
88
            $userdata['lastlogin'] = '&nbsp;';
89
            }
90
        $userdata['posts'] = $foundusers[$j]->getVar('posts');
91
            if ( $iamadmin ) {
92
                $userdata['adminlink'] = '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=users&amp;uid=' . $foundusers[$j]->getVar('uid') . '&amp;op=users_edit">' . '<img src=' . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'>"
93
94
                                         . '</a> | <a href="' . XOOPS_URL . '/modules/system/admin.php?fct=users&amp;op=users_delete&amp;uid=' . $foundusers[$j]->getVar('uid') . '">' . '<img src=' . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>" . '</a>';
95
            }
96
        $xoopsTpl->append('users', $userdata);
97
        }
98
99
        $totalpages = ceil( $total / $limit );
100
        if ( $totalpages > 1 ) {
101
            $hiddenform = '<form name="findnext" action="index.php" method="post">';
102
            foreach ( $_POST as $k => $v ) {
103
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars($k) . '" value="' . $myts->previewTarea($v) . '">';
104
            }
105
            if ( !isset( $_POST['limit'] ) ) {
106
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '">';
107
            }
108
            if ( !isset( $_POST['start'] ) ) {
109
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '">';
110
            }
111
            $prev = $start - $limit;
112
            if ( $start - $limit >= 0 ) {
113
            $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XOOPSMEMBERS_PREVIOUS . '</a>&nbsp;';
114
            }
115
            $counter = 1;
116
            $currentpage = ( $start + $limit ) / $limit;
117
            while ( $counter <= $totalpages ) {
118
                if ( $counter == $currentpage ) {
119
                    $hiddenform .= '<b>' . $counter . '</b> ';
120
            } elseif (($counter > $currentpage - 4 && $counter < $currentpage + 4) || 1 == $counter || $counter == $totalpages) {
121
                    if ( $counter == $totalpages && $currentpage < $totalpages-4 ) {
122
                        $hiddenform .= '... ';
123
                    }
124
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ( $counter-1 ) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
125
                if (1 == $counter && $currentpage > 5) {
126
                        $hiddenform .= '... ';
127
                    }
128
                }
129
                $counter++;
130
            }
131
            $next = $start + $limit;
132
            if ( $total > $next ) {
133
            $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XOOPSMEMBERS_NEXT . '</a>';
134
            }
135
            $hiddenform .= '</form>';
136
            $xoopsTpl->assign( 'pagenav', $hiddenform );
137
        $xoopsTpl->assign('lang_numfound', sprintf(_MD_XOOPSMEMBERS_USERSFOUND, $total));
138
        }
139
    }
140
141
include 'footer.php';
142
include_once XOOPS_ROOT_PATH . '/footer.php';
143
exit();
144
145
/**
146
 * xoops_Criteria()
147
 *
148
 * @param        $criteria
149
 * @param string $name
150
 * @param string $ret
151
 * @param string $match
152
 * @return void
153
 */
154
function xoops_Criteria(&$criteria, $name = '', $ret = '', $match = '')
155
{
156
    global $criteria;
157
158
    switch ( $match ) {
159
        case XOOPS_MATCH_START:
160
            $criteria->add(new \Criteria($name, $ret . '%', 'LIKE'));
161
            break;
162
        case XOOPS_MATCH_END:
163
            $criteria->add(new \Criteria($name, '%' . $ret . '%', 'LIKE'));
164
            break;
165
        case XOOPS_MATCH_EQUAL:
166
            $criteria->add(new \Criteria($name, $ret));
167
            break;
168
        case XOOPS_MATCH_CONTAIN:
169
            $criteria->add(new \Criteria($name, '%' . $ret . '%', 'LIKE'));
170
            break;
171
    }
172
}
173