1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Smallworld; |
4
|
|
|
|
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
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* SmallWorld |
17
|
|
|
* |
18
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
19
|
|
|
* @copyright 2011 Culex |
20
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
21
|
|
|
* @package SmallWorld |
22
|
|
|
* @since 1.0 |
23
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/* |
27
|
|
|
* Does a sync to remove orphans from smallworld db |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class DoSync |
33
|
|
|
*/ |
34
|
|
|
class DoSync |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* check for orphans (xoops_users <-> smallworld_users) and remove from smallworld |
38
|
|
|
*/ |
39
|
|
|
public function checkOrphans() |
40
|
|
|
{ |
41
|
|
|
$sql = 'SELECT userid FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . ' WHERE userid NOT IN ( SELECT uid FROM ' . $GLOBALS['xoopsDB']->prefix('users') . ')'; |
42
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
43
|
|
|
if ($result) { |
44
|
|
|
while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) { |
45
|
|
|
$this->deleteAccount($r['userid']); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* deleteAccount function |
52
|
|
|
* - Delete user account and associate rows across tables |
53
|
|
|
* |
54
|
|
|
* @param int $userid |
55
|
|
|
* @return bool true on success, false on failure |
56
|
|
|
*/ |
57
|
|
|
public function deleteAccount($userid) |
58
|
|
|
{ |
59
|
|
|
$user = new \XoopsUser($userid); |
|
|
|
|
60
|
|
|
//$username = $user->uname(); |
61
|
|
|
$sql01 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_admin') . " WHERE userid = '" . $userid . "'"; |
62
|
|
|
$sql02 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_comments') . " WHERE uid_fk = '" . $userid . "'"; |
63
|
|
|
$sql03 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_followers') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'"; |
64
|
|
|
$sql04 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_friends') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'"; |
65
|
|
|
$sql05 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_images') . " WHERE userid = '" . $userid . "'"; |
66
|
|
|
$sql06 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . " WHERE uid_fk = '" . $userid . "'"; |
67
|
|
|
$sql07 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE userid = '" . $userid . "'"; |
68
|
|
|
$sql08 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . " WHERE user_id = '" . $userid . "'"; |
69
|
|
|
$sql09 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_complaints') . " WHERE owner = '" . $userid . "' OR byuser_id = '" . $userid . "'"; |
70
|
|
|
$sql10 = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_settings') . " WHERE userid = '" . $userid . "'"; |
71
|
|
|
|
72
|
|
|
$result01 = $GLOBALS['xoopsDB']->queryF($sql01); |
73
|
|
|
$result02 = $GLOBALS['xoopsDB']->queryF($sql02); |
74
|
|
|
$result03 = $GLOBALS['xoopsDB']->queryF($sql03); |
75
|
|
|
$result04 = $GLOBALS['xoopsDB']->queryF($sql04); |
76
|
|
|
$result05 = $GLOBALS['xoopsDB']->queryF($sql05); |
77
|
|
|
$result06 = $GLOBALS['xoopsDB']->queryF($sql06); |
78
|
|
|
$result07 = $GLOBALS['xoopsDB']->queryF($sql07); |
79
|
|
|
$result08 = $GLOBALS['xoopsDB']->queryF($sql08); |
80
|
|
|
$result09 = $GLOBALS['xoopsDB']->queryF($sql09); |
81
|
|
|
$result10 = $GLOBALS['xoopsDB']->queryF($sql10); |
82
|
|
|
// Remove picture dir |
83
|
|
|
$dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/'; |
84
|
|
|
$result11 = $this->smallworld_remDir($userid, $dirname, $empty = false); |
85
|
|
|
|
86
|
|
|
return $result01 && $result02 && $result03 && $result04 && $result05 && $result06 && $result07 && $result08 && $result09 && $result10 && $result11; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* smallworld_remDir function |
91
|
|
|
* - Remove user image dir in uploads. |
92
|
|
|
* @param int $userid |
93
|
|
|
* @param string|bool $directory |
94
|
|
|
* @param bool|int $empty |
95
|
|
|
* @return bool |
|
|
|
|
96
|
|
|
*/ |
97
|
|
View Code Duplication |
public function smallworld_remDir($userid, $directory, $empty = false) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
if ('' != $userid) { |
100
|
|
|
if ('/' === mb_substr($directory, -1)) { |
101
|
|
|
$directory = mb_substr($directory, 0, -1); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if (!file_exists($directory) || !is_dir($directory)) { |
105
|
|
|
return false; |
106
|
|
|
} elseif (!is_readable($directory)) { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
$directoryHandle = opendir($directory); |
110
|
|
|
while (false !== ($contents = readdir($directoryHandle))) { |
111
|
|
|
if ('.' !== $contents && '..' !== $contents) { |
112
|
|
|
$path = $directory . '/' . $contents; |
113
|
|
|
if (is_dir($path)) { |
114
|
|
|
$this->smallworld_remDir($userid, $path); |
115
|
|
|
} else { |
116
|
|
|
unlink($path); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
closedir($directoryHandle); |
121
|
|
|
if (false === $empty) { |
122
|
|
|
if (!rmdir($directory)) { |
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return true; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* SmallworldDeleteDirectory function |
133
|
|
|
* - Delete images from users on delete |
134
|
|
|
* @param int $userid |
135
|
|
|
* @return true |
|
|
|
|
136
|
|
|
*/ |
137
|
|
|
public function SmallworldDeleteDirectory($userid) |
138
|
|
|
{ |
139
|
|
|
$dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/'; |
140
|
|
|
if (is_dir($dirname)) { |
141
|
|
|
$dir_handle = opendir($dirname); |
142
|
|
|
} |
143
|
|
|
if (!$dir_handle) { |
|
|
|
|
144
|
|
|
return false; |
145
|
|
|
} |
146
|
|
|
while ($file = readdir($dir_handle)) { |
147
|
|
View Code Duplication |
if ('.' != $file && '..' != $file) { |
|
|
|
|
148
|
|
|
if (!is_dir($dirname . '/' . $file)) { |
149
|
|
|
unlink($dirname . '/' . $file); |
150
|
|
|
} else { |
151
|
|
|
$this->SmallworldDeleteDirectory($dirname . '/' . $file); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
closedir($dir_handle); |
156
|
|
|
rmdir($dirname); |
157
|
|
|
|
158
|
|
|
return true; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.