Code Duplication    Length = 210-211 lines in 2 locations

class/SmallWorldUser.php 1 location

@@ 26-236 (lines=211) @@
23
//include_once $GLOBALS['xoops']->path('include/common.php');
24
25
26
class SmallWorldUser
27
{
28
29
    /**
30
     * @Check if user has profile
31
     * @param int $userID
32
     * @return int
33
     */
34
    public function checkIfProfile($userID)
35
    {
36
        global $xoopsUser, $xoopsDB;
37
        $i      = 0;
38
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userID . "'";
39
        $result = $xoopsDB->queryF($sql);
40
        $i      = $xoopsDB->getRowsNum($result);
41
        if ($xoopsUser) {
42
            // If xoopsuser but no smallworld profile
43
            if (0 == $i) {
44
                $i = 1;
45
            } else {
46
                // if xoopsuser and has profile
47
                $i = 2;
48
            }
49
        } else {
50
            // if not xoopsUser ie anonymous user
51
            $i = 0;
52
        }
53
        return $i;
54
    }
55
56
    /**
57
     * @Create user
58
     * @param int $userid
59
     * @return void
60
     */
61
    public function createUser($userid)
62
    {
63
        global $xoopsUser, $xoopsDB;
64
        $a      = new $xoopsUser($userid);
65
        $b      = $a->uname();
66
        $sql    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_user') . ' (userid) VALUES (' . (int)$userid . ')';
67
        $result = $xoopsDB->queryF($sql);
68
    }
69
70
    /**
71
     * @Check is user is smallworld user
72
     * @return void
73
     */
74
    public function chkUser()
75
    {
76
        global $xoopsUser, $xoopsTpl;
77
        $greeting = '<br>';
78
        $greeting .= _SMALLWORLD_NOTYETUSER_GREETING . ' ' . $xoopsUser->uname() . '.<br><br>';
79
        $greeting .= _SMALLWORLD_NOTYETUSER_BOXTEXT;
80
81
        $xoopsTpl->assign('notyetusercontent', $greeting);
82
        $xoopsTpl->assign('check', 0);
83
    }
84
85
    /**
86
     * @Check is user is friend
87
     * @param int $user
88
     * @param int $userID
89
     * @return array|int
90
     */
91
    public function friendcheck($user, $userID)
92
    {
93
        global $xoopsUser, $xoopsDB;
94
        $respons = [];
95
        if ($user == $userID) {
96
            $respons[0] = 2;
97
            return $respons;
98
        }
99
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$user . "' AND you = '" . (int)$userID . "'";
100
        $result = $xoopsDB->query($sql);
101
        $i      = $xoopsDB->getRowsNum($result);
102
        if (0 == $i) {
103
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$user . "' AND me = '" . (int)$userID . "'";
104
            $result = $xoopsDB->query($sql);
105
            $i      = $xoopsDB->getRowsNum($result);
106
        }
107
        while ($row = $xoopsDB->fetchArray($result)) {
108
            if (0 == $i and '' == $i) {
109
                $respons[0] = 0;
110
            }
111
112
            if (1 == $i and 1 == $row['status']) {
113
                $respons[0] = 1;
114
            }
115
            if (1 == $i and 2 == $row['status']) {
116
                $respons[0] = 2;
117
            }
118
            return $respons;
119
        }
120
    }
121
122
    /**
123
     * @Get name from userid
124
     * @param int $userID
125
     * @return string
126
     */
127
    public function getName($userID)
128
    {
129
        global $xoopsUser, $xoopsDB;
130
        $name = '';
131
        $sql    = 'SELECT username FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'";
132
        $result = $xoopsDB->queryF($sql);
133
        while ($row = $xoopsDB->fetchArray($result)) {
134
            $name = $row['username'];
135
        }
136
        return $name;
137
    }
138
139
    /**
140
     * @Check if user is follower
141
     * @param int $userid
142
     * @param int $friendid
143
     * @return int
144
     */
145
    public function following_or($userid, $friendid)
146
    {
147
        global $xoopsDB, $xoopsUser;
148
        $respons[0] = 0;
149
        if ($userid != $friendid) {
150
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'";
151
            $result = $xoopsDB->query($sql);
152
            $i      = $xoopsDB->getRowsNum($result);
153
            while ($row = $xoopsDB->fetchArray($result)) {
154
                if (0 == $i) {
155
                    $respons[0] = 0;
156
                }
157
158
                if (1 == $i and 1 == $row['status']) {
159
                    $respons[0] = 1;
160
                }
161
                if (1 == $i and 2 == $row['status']) {
162
                    $respons[0] = 2;
163
                }
164
            }
165
        } else {
166
        }
167
        return $respons;
168
    }
169
170
    /**
171
     * @Get requests
172
     * @param int $userid
173
     * @return array
174
     */
175
    public function getRequests($userid)
176
    {
177
        global $xoopsDB, $xoopsUser;
178
        $msg      = [];
179
        $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$userid . "' AND status = '1'";
180
        $result   = $xoopsDB->queryF($sql);
181
        $i        = $xoopsDB->getRowsNum($result);
182
        $db       = new SmallWorldDB;
183
        $Wall     = new WallUpdates();
184
        $myavatar = $Wall->Gravatar($userid);
185
        $start    = 0;
186
        while ($row = $xoopsDB->fetchArray($result) and $start <= count($row)) {
187
            $msg[$start]['friendname']  = $this->getName($row['me']);
188
            $msg[$start]['img']         = $Wall->Gravatar($row['me']);
189
            $msg[$start]['friendimage'] = "<img src='" . XOOPS_UPLOAD_URL . '/' . $msg[$start]['img'] . "' height='40px'>";
190
            $msg[$start]['frienddate']  = date('d-m-Y', $row['date']);
191
            $msg[$start]['accept']      = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_ACCEPT . '</a>';
192
            $msg[$start]['deny']        = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(-1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_DENY . '</a>';
193
            $msg[$start]['later']       = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(0,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_LATER . '</a>';
194
            $msg[$start]['cnt']         = $start;
195
            ++$start;
196
        }
197
        return $msg;
198
    }
199
200
    /**
201
     * @Get partner
202
     * @param string $name
203
     * @return int
204
     */
205
    public function spousexist($name)
206
    {
207
        global $xoopsUser, $xoopsDB;
208
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $name . "'";
209
        $result = $xoopsDB->queryF($sql);
210
        $i      = $xoopsDB->getRowsNum($result);
211
        return $i;
212
    }
213
214
    /**
215
     * Get all users
216
     * @return array
217
     */
218
219
    public function allUsers()
220
    {
221
        global $xoopsDB;
222
        $sql    = 'SELECT userid FROM ' . $xoopsDB->prefix('smallworld_user') . ' ORDER BY userid';
223
        $result = $xoopsDB->queryF($sql);
224
        $i      = $xoopsDB->getRowsNum($result);
225
        if (0 != $i) {
226
            while ($r = $xoopsDB->fetchArray($result)) {
227
                $data[] = $r;
228
            }
229
            if (!empty($data)) {
230
                return Smallworld_array_flatten($data, 0);
231
            }
232
        } else {
233
            //redirect_header(XOOPS_URL . "/modules/smallworld/register.php");
234
        }
235
    }
236
}
237

class/user.php 1 location

@@ 22-231 (lines=210) @@
19
 * @since        1.0
20
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
21
 */
22
class SmallWorldUser
23
{
24
25
    /**
26
     * @Check if user has profile
27
     * @param int $userID
28
     * @return int
29
     */
30
    public function CheckIfProfile($userID)
31
    {
32
        global $xoopsUser, $xoopsDB;
33
        $i      = 0;
34
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userID . "'";
35
        $result = $xoopsDB->queryF($sql);
36
        $i      = $xoopsDB->getRowsNum($result);
37
        if ($xoopsUser) {
38
            // If xoopsuser but no smallworld profile
39
            if (0 == $i) {
40
                $i = 1;
41
            } else {
42
                // if xoopsuser and has profile
43
                $i = 2;
44
            }
45
        } else {
46
            // if not xoopsUser ie anonymous user
47
            $i = 0;
48
        }
49
        return $i;
50
    }
51
52
    /**
53
     * @Create user
54
     * @param int $userid
55
     * @return void
56
     */
57
    public function createUser($userid)
58
    {
59
        global $xoopsUser, $xoopsDB;
60
        $a      = new $xoopsUser($userid);
61
        $b      = $a->uname();
62
        $sql    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_user') . ' (userid) VALUES (' . (int)$userid . ')';
63
        $result = $xoopsDB->queryF($sql);
64
    }
65
66
    /**
67
     * @Check is user is smallworld user
68
     * @return void
69
     */
70
    public function chkUser()
71
    {
72
        global $xoopsUser, $xoopsTpl;
73
        $greeting = '<br>';
74
        $greeting .= _SMALLWORLD_NOTYETUSER_GREETING . ' ' . $xoopsUser->uname() . '.<br><br>';
75
        $greeting .= _SMALLWORLD_NOTYETUSER_BOXTEXT;
76
77
        $xoopsTpl->assign('notyetusercontent', $greeting);
78
        $xoopsTpl->assign('check', 0);
79
    }
80
81
    /**
82
     * @Check is user is friend
83
     * @param int $user
84
     * @param int $userID
85
     * @return array|int
86
     */
87
    public function friendcheck($user, $userID)
88
    {
89
        global $xoopsUser, $xoopsDB;
90
        $respons = [];
91
        if ($user == $userID) {
92
            $respons[0] = 2;
93
            return $respons;
94
        }
95
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$user . "' AND you = '" . (int)$userID . "'";
96
        $result = $xoopsDB->query($sql);
97
        $i      = $xoopsDB->getRowsNum($result);
98
        if (0 == $i) {
99
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$user . "' AND me = '" . (int)$userID . "'";
100
            $result = $xoopsDB->query($sql);
101
            $i      = $xoopsDB->getRowsNum($result);
102
        }
103
        while ($row = $xoopsDB->fetchArray($result)) {
104
            if (0 == $i and '' == $i) {
105
                $respons[0] = 0;
106
            }
107
108
            if (1 == $i and 1 == $row['status']) {
109
                $respons[0] = 1;
110
            }
111
            if (1 == $i and 2 == $row['status']) {
112
                $respons[0] = 2;
113
            }
114
            return $respons;
115
        }
116
    }
117
118
    /**
119
     * @Get name from userid
120
     * @param int $userID
121
     * @return string
122
     */
123
    public function getName($userID)
124
    {
125
        global $xoopsUser, $xoopsDB;
126
        $sql    = 'SELECT username FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . (int)$userID . "'";
127
        $result = $xoopsDB->queryF($sql);
128
        while ($row = $xoopsDB->fetchArray($result)) {
129
            $name = $row['username'];
130
        }
131
        return $name;
132
    }
133
134
    /**
135
     * @Check if user is follower
136
     * @param int $userid
137
     * @param int $friendid
138
     * @return int
139
     */
140
    public function following_or($userid, $friendid)
141
    {
142
        global $xoopsDB, $xoopsUser;
143
        $respons[0] = 0;
144
        if ($userid != $friendid) {
145
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'";
146
            $result = $xoopsDB->query($sql);
147
            $i      = $xoopsDB->getRowsNum($result);
148
            while ($row = $xoopsDB->fetchArray($result)) {
149
                if (0 == $i) {
150
                    $respons[0] = 0;
151
                }
152
153
                if (1 == $i and 1 == $row['status']) {
154
                    $respons[0] = 1;
155
                }
156
                if (1 == $i and 2 == $row['status']) {
157
                    $respons[0] = 2;
158
                }
159
            }
160
        } else {
161
        }
162
        return $respons;
163
    }
164
165
    /**
166
     * @Get requests
167
     * @param int $userid
168
     * @return array
169
     */
170
    public function getRequests($userid)
171
    {
172
        global $xoopsDB, $xoopsUser;
173
        $msg      = [];
174
        $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$userid . "' AND status = '1'";
175
        $result   = $xoopsDB->queryF($sql);
176
        $i        = $xoopsDB->getRowsNum($result);
177
        $db       = new SmallWorldDB;
178
        $Wall     = new Wall_Updates();
179
        $myavatar = $Wall->Gravatar($userid);
180
        $start    = 0;
181
        while ($row = $xoopsDB->fetchArray($result) and $start <= count($row)) {
182
            $msg[$start]['friendname']  = $this->getName($row['me']);
183
            $msg[$start]['img']         = $Wall->Gravatar($row['me']);
184
            $msg[$start]['friendimage'] = "<img src='" . XOOPS_UPLOAD_URL . '/' . $msg[$start]['img'] . "' height='40px'>";
185
            $msg[$start]['frienddate']  = date('d-m-Y', $row['date']);
186
            $msg[$start]['accept']      = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_ACCEPT . '</a>';
187
            $msg[$start]['deny']        = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(-1,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_DENY . '</a>';
188
            $msg[$start]['later']       = '<a class="smallworldrequestlink" id = "smallworldfriendrequest_' . $msg[$start]['friendname'] . '" href = "javascript:Smallworld_AcceptDenyFriend(0,' . $row['me'] . ',' . $row['you'] . ',' . $start . ');">' . _SMALLWORLD_LATER . '</a>';
189
            $msg[$start]['cnt']         = $start;
190
            ++$start;
191
        }
192
        return $msg;
193
    }
194
195
    /**
196
     * @Get partner
197
     * @param string $name
198
     * @return int
199
     */
200
    public function spousexist($name)
201
    {
202
        global $xoopsUser, $xoopsDB;
203
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE username = '" . $name . "'";
204
        $result = $xoopsDB->queryF($sql);
205
        $i      = $xoopsDB->getRowsNum($result);
206
        return $i;
207
    }
208
209
    /**
210
     * Get all users
211
     * @return array
212
     */
213
214
    public function allUsers()
215
    {
216
        global $xoopsDB;
217
        $sql    = 'SELECT userid FROM ' . $xoopsDB->prefix('smallworld_user') . ' ORDER BY userid';
218
        $result = $xoopsDB->queryF($sql);
219
        $i      = $xoopsDB->getRowsNum($result);
220
        if (0 != $i) {
221
            while ($r = $xoopsDB->fetchArray($result)) {
222
                $data[] = $r;
223
            }
224
            if (!empty($data)) {
225
                return Smallworld_array_flatten($data, 0);
226
            }
227
        } else {
228
            //redirect_header(XOOPS_URL . "/modules/smallworld/register.php");
229
        }
230
    }
231
}
232