root/include/functions_delete.php

Revision 324, 10.8 kB (checked in by Nafania, 1 year ago)

Много мелких изменений. Если используется xbtt, то надо обязательно скачать новую версию на форуме.
Добавлен файл cron.php - если есть возможность, то пускайте cron таски через него. Особенно если используете массовую рассылку почты.

Line 
1 <?php
2 function deletetorrent( $arr_ids ) {</span>
3 <span class="code-keyword">    global $config, $db, $root_path;
4
5     $torrent_dir = $root_path . ( !empty($config['torrent_dir']) ? $config['torrent_dir'] : 'torrents');
6     $ids = implode(',', $arr_ids) ;
7
8     if ( $count = sizeof($arr_ids) ) {
9         if ( defined('USE_XBTT') ) {
10             foreach ( $arr_ids  AS $info_hash => $id ) {
11                 $sql = 'INSERT INTO ' . XBT_DELETED_HASHES . ' ' . $db->sql_build_array('INSERT', array(
12                     'fid' => $id,
13                     'info_hash' => $info_hash
14                 ));
15                 $db->sql_query($sql);
16             }
17           }
18
19         $sql = 'DELETE FROM ' . TORRENTS_TABLE . ' WHERE fid IN (' . $ids . ')';
20         $db->sql_query($sql);
21           $sql = 'DELETE FROM ' . SNATCHED_TABLE . ' WHERE torrentid IN (' . $ids . ')';
22           $db->sql_query($sql);
23           $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . ' WHERE torrentid IN (' . $ids . ')';
24           $db->sql_query($sql);
25           $sql = 'DELETE FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_for_id IN (' . $ids . ') AND checkcomm_type = ' . TYPE_TORRENT;
26           $db->sql_query($sql);
27           $sql = 'DELETE FROM ' . REPORTS_TABLE . ' WHERE type = 2 AND votedfor IN (' . $ids . ')';
28           $db->sql_query($sql);
29           $sql = 'DELETE FROM ' . INDEXRELEASES_TABLE . ' WHERE torrent_id IN (' . $ids . ')';
30           $db->sql_query($sql);
31           $sql = 'DELETE FROM ' . SOS_TABLE . ' WHERE torrentid IN (' . $ids . ')';
32           $db->sql_query($sql);
33           $sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE simpid IN (' . $ids . ') AND type = 2';
34           $db->sql_query($sql);
35           $sql = 'DELETE FROM ' . THANKS_TABLE . ' WHERE torrentid IN (' . $ids . ')';
36           $db->sql_query($sql);
37           $sql = 'DELETE FROM ' . PEERS_TABLE . ' WHERE fid IN (' . $ids . ')';
38           $db->sql_query($sql);
39           $sql = 'DELETE FROM ' . FILES_TABLE . ' WHERE torrent IN (' . $ids . ')';
40           $db->sql_query($sql);
41           $sql = 'DELETE FROM ' . COMMENTS_TABLE . ' WHERE comment_for_id IN (' . $ids . ') AND comment_type = ' . TYPE_TORRENT;
42           $db->sql_query($sql);
43           $sql = 'DELETE FROM ' . RATINGS_TABLE . ' WHERE torrent IN (' . $ids . ')';
44           $db->sql_query($sql);
45           $sql = 'DELETE FROM ' . CHEATERS_TABLE . ' WHERE torrentid IN (' . $ids . ')';
46           $db->sql_query($sql);
47         $sql = 'DELETE FROM ' . TAGS_TABLE . ' WHERE tag_for_id IN (' . $ids . ') AND tag_type = ' . TYPE_TORRENT;
48         $db->sql_query($sql);
49         $sql = 'DELETE FROM ' . TAGS_USERS_TABLE . ' WHERE tag_users_for_id IN (' . $ids . ') AND tag_users_type = ' . TYPE_TORRENT;
50         $db->sql_query($sql);
51
52           foreach ( $arr_ids AS $_null => $id ) {
53               @unlink($torrent_dir . '/' . $id . '.torrent');
54               @unlink($root_path . 'cache/png/torrent_nfo_' . $id . '.png');
55           }
56      }
57      return;
58 }
59
60 function deleteuser($arr_ids) {
61     global $db;
62
63     if ( sizeof($arr_ids) ) {
64
65         deleteuser_phpbbuser($arr_ids);
66
67         $sql = 'DELETE FROM ' . USERS_TABLE . ' WHERE uid IN (' . implode(',', $arr_ids) . ')';
68         $db->sql_query($sql);
69         $sql = 'DELETE FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE receiver IN (' . implode(',', $arr_ids) . ')';
70         $db->sql_query($sql);
71         $sql = 'DELETE FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE sender IN (' . implode(',', $arr_ids) . ')';
72         $db->sql_query($sql);
73         $sql = 'DELETE FROM ' . REPORTS_TABLE . ' WHERE type = 1 AND votedfor IN (' . implode(',', $arr_ids) . ')';
74         $db->sql_query($sql);
75         $sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE touserid IN (' . implode(',', $arr_ids) . ')';
76         $db->sql_query($sql);
77         $sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE fromuserid IN (' . implode(',', $arr_ids) . ')';
78         $db->sql_query($sql);
79         $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id IN (' . implode(',', $arr_ids) . ')';
80         $db->sql_query($sql);
81         $sql = 'DELETE FROM ' . RATINGS_TABLE . ' WHERE user IN (' . implode(',', $arr_ids) . ')';
82         $db->sql_query($sql);
83         $sql = 'DELETE FROM ' . FRIENDS_TABLE . ' WHERE blockid IN (' . implode(',', $arr_ids) . ')';
84         $db->sql_query($sql);
85         $sql = 'DELETE FROM ' . FRIENDS_TABLE . ' WHERE friendid IN (' . implode(',', $arr_ids) . ')';
86         $db->sql_query($sql);
87         $sql = 'DELETE FROM ' . FRIENDS_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
88         $db->sql_query($sql);
89         $sql = 'DELETE FROM ' . CHEATERS_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
90         $db->sql_query($sql);
91         $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
92         $db->sql_query($sql);
93         $sql = 'DELETE FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_userid IN (' . implode(',', $arr_ids) . ')';
94         $db->sql_query($sql);
95         $sql = 'DELETE FROM ' . OFFERS_VOTES_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
96         $db->sql_query($sql);
97         $sql = 'DELETE FROM ' . REQUESTS_VOTES_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
98         $db->sql_query($sql);
99         $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' WHERE user_id IN (' . implode(',', $arr_ids) . ')';
100         $db->sql_query($sql);
101         $sql = 'DELETE FROM ' . SNATCHED_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
102         $db->sql_query($sql);
103         $sql = 'DELETE FROM ' . SOS_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
104         $db->sql_query($sql);
105         $sql = 'DELETE FROM ' . THANKS_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
106         $db->sql_query($sql);
107         $sql = 'DELETE FROM ' . USER_GROUP_TABLE . ' WHERE user_id IN (' . implode(',', $arr_ids) . ')';
108         $db->sql_query($sql);
109         $sql = 'DELETE FROM ' . UPLOADAPP_TABLE . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
110         $db->sql_query($sql);
111         $sql = 'DELETE FROM ' . TAGS_USERS_TABLE . ' WHERE tag_users_uid IN (' . implode(',', $arr_ids) . ')';
112         $db->sql_query($sql);
113         $sql = 'UPDATE ' . COMMENTS_TABLE . ' SET comment_user = ' . ANONYMOUS . ' WHERE comment_user IN (' . implode(',', $arr_ids) . ')';
114         $db->sql_query($sql);
115         $sql = 'UPDATE ' . TORRENTS_TABLE . ' SET owner = ' . ANONYMOUS . ' WHERE owner IN (' . implode(',', $arr_ids) . ')';
116         $db->sql_query($sql);
117         $sql = 'UPDATE ' . REQUESTS_TABLE . ' SET userid = ' . ANONYMOUS . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
118         $db->sql_query($sql);
119         $sql = 'UPDATE ' . OFFERS_TABLE . ' SET userid = ' . ANONYMOUS . ' WHERE userid IN (' . implode(',', $arr_ids) . ')';
120         $db->sql_query($sql);
121         $sql = 'UPDATE ' . USERS_TABLE . ' SET invited_by = ' . ANONYMOUS . ' WHERE uid IN (' . implode(',', $arr_ids) . ')';
122         $db->sql_query($sql);
123
124         foreach ( $arr_ids AS $_null => $id ) {
125             @unlink($root_path . $config['avatar_path'] . '/user_avatar_' . $id . '.png');
126             @unlink($root_path . $config['avatar_path'] . '/user_avatar_' . $id . '.gif');
127             @unlink($root_path . $config['avatar_path'] . '/user_avatar_' . $id . '.jpg');
128         }
129     }
130     return;
131 }
132
133 function deleteuser_phpbbuser($arr_ids) {
134     global $db;
135
136     foreach( $arr_ids AS $_null => $user_id ) {
137         $sql = 'SELECT name AS username FROM ' . USERS_TABLE . ' WHERE uid = ' . $user_id;
138         $result = $db->sql_query($sql);
139         $username = ( $row = $db->sql_fetchrow($result) ) ? $row['username'] : '';
140         $db->sql_freeresult($result);
141
142         $sql = "SELECT g.group_id FROM " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
143                 WHERE ug.user_id = $user_id
144                 AND g.group_id = ug.group_id
145                 AND g.group_single_user = 1";
146         $result = $db->sql_query($sql);
147         $row = $db->sql_fetchrow($result);
148         $db->sql_freeresult($result);
149
150         $sql = "UPDATE " . POSTS_TABLE . "
151                 SET poster_id = " . ANONYMOUS . ", post_username = '" . str_replace("\\'", "''", addslashes($username)) . "'
152                 WHERE poster_id = $user_id";
153         $db->sql_query($sql);
154
155         $sql = "UPDATE " . TOPICS_TABLE . "
156                 SET topic_poster = " . ANONYMOUS . "
157                 WHERE topic_poster = $user_id";
158         $db->sql_query($sql);
159
160         $sql = "DELETE FROM " . VOTE_USERS_TABLE . "
161                 WHERE vote_user_id = $user_id";
162         $db->sql_query($sql);
163
164         $sql = "SELECT group_id
165                 FROM " . GROUPS_TABLE . "
166                 WHERE group_moderator = $user_id";
167         $result = $db->sql_query($sql);
168
169         $group_moderator = array();
170
171         while ( $row_group = $db->sql_fetchrow($result) ) {
172             $group_moderator[] = $row_group['group_id'];
173         }
174         $db->sql_freeresult($result);
175
176         if ( sizeof($group_moderator) ) {
177                 $update_moderator_id = implode(', ', $group_moderator);
178                 $sql = "UPDATE " . GROUPS_TABLE . "
179                 SET group_moderator = " . ANONYMOUS . "
180                 WHERE group_moderator IN ($update_moderator_id)";
181                 $db->sql_query($sql);
182
183         }
184
185         if ( isset($row['group_id']) && $row['group_id'] ) {
186             $sql = "DELETE FROM " . GROUPS_TABLE . " WHERE group_id = " . $row['group_id'];
187             $db->sql_query($sql);
188
189             $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . " WHERE group_id = " . $row['group_id'];
190             $db->sql_query($sql);
191         }
192     }
193      return;
194 }
195
196 function delete_request($ids) {
197     global $db;
198
199     if ( sizeof($ids) ) {
200         $sql = 'DELETE FROM ' . REQUESTS_TABLE . ' WHERE id IN (' . implode(', ', $ids) . ')';
201             $db->sql_query($sql);
202             $sql = 'DELETE FROM ' . REQUESTS_VOTES_TABLE . ' WHERE requestid IN (' . implode(', ', $ids) . ')';
203             $db->sql_query($sql);
204             $sql = 'DELETE FROM ' . COMMENTS_TABLE . ' WHERE comment_for_id IN (' . implode(', ', $ids) . ') AND comment_type = ' . TYPE_REQUEST;
205             $db->sql_query($sql);
206             $sql = 'DELETE FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_for_id IN (' . implode(', ', $ids) . ') AND checkcomm_type = ' . TYPE_REQUEST;
207             $db->sql_query($sql);
208             $sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE simpid IN (' . implode(', ', $ids) . ') AND type = 3';
209             $db->sql_query($sql);
210      }
211     return;
212 }
213
214 function delete_offer($ids) {
215     global $db;
216
217     if ( sizeof($ids) ) {
218         $sql = 'DELETE FROM ' . OFFERS_TABLE . ' WHERE id IN (' . implode(', ', $ids) . ')';
219         $db->sql_query($sql);
220         $sql = 'DELETE FROM ' . OFFERS_VOTES_TABLE . ' WHERE offerid IN (' . implode(', ', $ids) . ')';
221         $db->sql_query($sql);
222         $sql = 'DELETE FROM ' . COMMENTS_TABLE . ' WHERE comment_for_id IN (' . implode(', ', $ids) . ') AND comment_type = ' . TYPE_OFFER;
223         $db->sql_query($sql);
224         $sql = 'DELETE FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_for_id IN (' . implode(', ', $ids) . ') AND checkcomm_type = ' . TYPE_OFFER;
225         $db->sql_query($sql);
226         $sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE simpid IN (' . implode(', ', $ids) . ') AND type = 4';
227         $db->sql_query($sql);
228     }
229     return;
230 }
231
232 function delete_news ( $id ) {
233     global $db;
234
235     $sql = 'DELETE FROM ' . NEWS_TABLE . ' WHERE id = ' . $id;
236      $db->sql_query($sql);
237     $sql = 'DELETE FROM ' . COMMENTS_TABLE . ' WHERE comment_for_id = ' . $id . ' AND comment_type = ' . TYPE_NEWS;
238     $db->sql_query($sql);
239     $sql = 'DELETE FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_for_id = ' . $id . ' AND checkcomm_type = ' . TYPE_NEWS;
240     $db->sql_query($sql);
241 }
242 ?>
Note: See TracBrowser for help on using the browser.