| 1 |
<?php |
|---|
| 2 |
class cleanup_types {</span> |
|---|
| 3 |
<span class="code-keyword"> |
|---|
| 4 |
var $privmsg_insert_arr = array(); |
|---|
| 5 |
var $time_now; |
|---|
| 6 |
|
|---|
| 7 |
function cleanup_types () { |
|---|
| 8 |
$this->time_now = time(); |
|---|
| 9 |
} |
|---|
| 10 |
|
|---|
| 11 |
function _clean_peers () { |
|---|
| 12 |
global $config, $db; |
|---|
| 13 |
|
|---|
| 14 |
if ( defined('USE_XBTT') ) { |
|---|
| 15 |
return true; |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
$sql = 'DELETE FROM ' . PEERS_TABLE . ' WHERE mtime < ' . ( $this->time_now - floor($config['announce_interval']) * 1.4 ); |
|---|
| 19 |
$db->sql_query($sql); |
|---|
| 20 |
|
|---|
| 21 |
return true; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
function _sync_torrents_info () { |
|---|
| 25 |
global $db; |
|---|
| 26 |
|
|---|
| 27 |
if ( defined('USE_XBTT') ) { |
|---|
| 28 |
return true; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
$torrents = array(); |
|---|
| 32 |
$sql = 'SELECT fid, `left`, COUNT(*) AS c |
|---|
| 33 |
FROM ' . PEERS_TABLE . ' |
|---|
| 34 |
GROUP BY fid, `left` = 0'; |
|---|
| 35 |
$result = $db->sql_query($sql); |
|---|
| 36 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 37 |
do { |
|---|
| 38 |
$key = ( $row['left'] ? 'leechers' : 'seeders' ); |
|---|
| 39 |
$torrents[$row['fid']][$key] = $row['c']; |
|---|
| 40 |
} |
|---|
| 41 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 42 |
} |
|---|
| 43 |
$db->sql_freeresult($result); |
|---|
| 44 |
if ( sizeof($torrents) ) { |
|---|
| 45 |
$sql = 'SELECT fid, seeders, leechers, visible FROM ' . TORRENTS_TABLE; |
|---|
| 46 |
$result = $db->sql_query($sql); |
|---|
| 47 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 48 |
do { |
|---|
| 49 |
$update = array(); |
|---|
| 50 |
$torr = ( isset($torrents[$row['fid']]) ? $torrents[$row['fid']] : '' ); |
|---|
| 51 |
$torr['leechers'] = ( !isset($torr['leechers']) ? 0 : $torr['leechers'] ); |
|---|
| 52 |
$torr['seeders'] = ( !isset($torr['seeders']) ? 0 : $torr['seeders'] ); |
|---|
| 53 |
if ( $torr['leechers'] != $row['leechers'] ) { |
|---|
| 54 |
$update[] = 'leechers = ' . $torr['leechers']; |
|---|
| 55 |
} |
|---|
| 56 |
if ( $torr['seeders'] != $row['seeders'] ) { |
|---|
| 57 |
$update[] = 'seeders = ' . $torr['seeders']; |
|---|
| 58 |
} |
|---|
| 59 |
if ( $torr['seeders'] && !$row['visible'] ) { |
|---|
| 60 |
$update[] = 'visible = 1'; |
|---|
| 61 |
} |
|---|
| 62 |
if ( !$torr['seeders'] && $row['visible'] ) { |
|---|
| 63 |
$update[] = 'visible = 0'; |
|---|
| 64 |
} |
|---|
| 65 |
if ( sizeof($update) ) { |
|---|
| 66 |
$sql = 'UPDATE ' . TORRENTS_TABLE . ' SET ' . implode(', ', $update) . ' WHERE fid = ' . $row['fid']; |
|---|
| 67 |
$db->sql_query($sql); |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 71 |
} |
|---|
| 72 |
$db->sql_freeresult($result); |
|---|
| 73 |
} |
|---|
| 74 |
else { |
|---|
| 75 |
$sql = 'UPDATE ' . TORRENTS_TABLE . ' SET seeders = 0, leechers = 0'; |
|---|
| 76 |
$db->sql_query($sql); |
|---|
| 77 |
} |
|---|
| 78 |
$db->sql_freeresult($result); |
|---|
| 79 |
|
|---|
| 80 |
return true; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
function _clean_pending_accounts () { |
|---|
| 84 |
global $db, $config, $root_path; |
|---|
| 85 |
|
|---|
| 86 |
if ( !$config['signup_timeout'] ) { |
|---|
| 87 |
return true; |
|---|
| 88 |
} |
|---|
| 89 |
@require_once ($root_path . 'include/functions_delete.php'); |
|---|
| 90 |
|
|---|
| 91 |
$signup_timeout = intval($config['signup_timeout']) * 24 * 60 * 60; |
|---|
| 92 |
|
|---|
| 93 |
$sql = 'SELECT uid FROM ' . USERS_TABLE . ' WHERE status = 0 AND added < ' . ( $this->time_now - $signup_timeout ); |
|---|
| 94 |
$result = $db->sql_query($sql); |
|---|
| 95 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 96 |
$pending_users_arr = array(); |
|---|
| 97 |
do { |
|---|
| 98 |
$pending_users_arr[] = $row['uid']; |
|---|
| 99 |
} |
|---|
| 100 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 101 |
deleteuser($pending_users_arr); |
|---|
| 102 |
} |
|---|
| 103 |
$db->sql_freeresult($result); |
|---|
| 104 |
|
|---|
| 105 |
return true; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
function _clean_inactive_users () { |
|---|
| 109 |
global $config, $db, $root_path; |
|---|
| 110 |
|
|---|
| 111 |
if ( !$config['inactive_users_del_days'] && !$config['inactive_users_parked_del_days'] ) { |
|---|
| 112 |
return true; |
|---|
| 113 |
} |
|---|
| 114 |
@require_once ($root_path . 'include/functions_delete.php'); |
|---|
| 115 |
@require_once ($root_path . 'include/functions_check.php'); |
|---|
| 116 |
if ( !check_user_class($config['inactive_users_del_min_class']) ) { |
|---|
| 117 |
return true; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
if ( $config['inactive_users_del_days'] ) { |
|---|
| 121 |
|
|---|
| 122 |
$del_time = $this->time_now - intval($config['inactive_users_del_days']) * 24 * 60 * 60; |
|---|
| 123 |
$delete_ary = array(); |
|---|
| 124 |
|
|---|
| 125 |
$sql = 'SELECT uid |
|---|
| 126 |
FROM ' . USERS_TABLE . ' |
|---|
| 127 |
WHERE parked = 0 AND status = 1 AND class <= ' . $config['inactive_users_del_min_class'] . ' AND user_session_time < ' . $del_time . ' AND added < ' . $del_time . ' AND uid != ' . ANONYMOUS . ' AND donor = 0'; |
|---|
| 128 |
$result = $db->sql_query($sql); |
|---|
| 129 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 130 |
do { |
|---|
| 131 |
$delete_ary[] = $row['uid']; |
|---|
| 132 |
} |
|---|
| 133 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 134 |
deleteuser ($delete_ary); |
|---|
| 135 |
} |
|---|
| 136 |
$db->sql_freeresult($result); |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
if ( $config['inactive_users_parked_del_days'] ) { |
|---|
| 140 |
|
|---|
| 141 |
$del_time = $this->time_now - intval($config['inactive_users_parked_del_days']) * 24 * 60 * 60; |
|---|
| 142 |
$delete_ary = array(); |
|---|
| 143 |
|
|---|
| 144 |
$sql = 'SELECT uid |
|---|
| 145 |
FROM ' . USERS_TABLE . ' |
|---|
| 146 |
WHERE parked = 1 AND status = 1 AND class <= ' . $config['inactive_users_del_min_class'] . ' AND user_session_time < ' . $del_time . ' AND added < ' . $del_time . ' AND uid != ' . ANONYMOUS . ' AND donor = 0'; |
|---|
| 147 |
$result = $db->sql_query($sql); |
|---|
| 148 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 149 |
do { |
|---|
| 150 |
$delete_ary[] = $row['uid']; |
|---|
| 151 |
} |
|---|
| 152 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 153 |
deleteuser ($delete_ary); |
|---|
| 154 |
} |
|---|
| 155 |
$db->sql_freeresult($result); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
return true; |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
function _promote_demote_users () { |
|---|
| 162 |
global $db, $config, $phpbb_class, $root_path; |
|---|
| 163 |
|
|---|
| 164 |
$user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']); |
|---|
| 165 |
|
|---|
| 166 |
if ( $config['promote_to_power_megs_limit'] && $config['promote_to_power_min_ratio'] && $config['promote_to_power_reg_date_ago'] ) { |
|---|
| 167 |
|
|---|
| 168 |
$limit = $config['promote_to_power_megs_limit'] * 1024 * 1024; |
|---|
| 169 |
$maxdt = $this->time_now - 86400 * $config['promote_to_power_reg_date_ago']; |
|---|
| 170 |
|
|---|
| 171 |
$sql = 'SELECT uid, language FROM ' . USERS_TABLE . ' WHERE class = ' . UC_USER . ' AND uploaded > ' . $limit . ' AND ( uploaded / downloaded ) > ' . $config['promote_to_power_min_ratio'] . ' AND added < ' . $maxdt; |
|---|
| 172 |
$result = $db->sql_query($sql); |
|---|
| 173 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 174 |
$users = array(); |
|---|
| 175 |
$tor_limit = ( isset($user_limit_ary_torrents[UC_POWER_USER]) ? intval($user_limit_ary_torrents[UC_POWER_USER]) : 0 ); |
|---|
| 176 |
do { |
|---|
| 177 |
$users[$row['language']][] = $row['uid']; |
|---|
| 178 |
} |
|---|
| 179 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 180 |
|
|---|
| 181 |
foreach ( $users AS $user_lang => $user_id ) { |
|---|
| 182 |
@include($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 183 |
|
|---|
| 184 |
for ( $i = 0; $i < sizeof($user_id); $i++ ) { |
|---|
| 185 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, class = ' . UC_POWER_USER . ', torrents_limit = ' . $tor_limit . ' WHERE uid = ' . $user_id[$i]; |
|---|
| 186 |
$db->sql_query($sql); |
|---|
| 187 |
|
|---|
| 188 |
$sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_POWER_USER] . ' WHERE user_id = ' . $user_id[$i] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')'; |
|---|
| 189 |
$db->sql_query($sql); |
|---|
| 190 |
|
|---|
| 191 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $user_id[$i], 'added' => $this->time_now, 'msg' => $lang['pm_promote_to_power_user_body'], 'subject' => $lang['pm_promote_to_power_user_subject'], 'location' => 1 ); |
|---|
| 192 |
} |
|---|
| 193 |
} |
|---|
| 194 |
} |
|---|
| 195 |
$db->sql_freeresult($result); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
if ( $config['promote_to_power_demote_ratio'] ) { |
|---|
| 199 |
|
|---|
| 200 |
$sql = 'SELECT uid, language FROM ' . USERS_TABLE . ' WHERE class = ' . UC_POWER_USER . ' AND uploaded / downloaded < ' . $config['promote_to_power_demote_ratio']; |
|---|
| 201 |
$result = $db->sql_query($sql); |
|---|
| 202 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 203 |
$users = array(); |
|---|
| 204 |
$tor_limit = ( isset($user_limit_ary_torrents[UC_USER]) ? intval($user_limit_ary_torrents[UC_USER]) : 0 ); |
|---|
| 205 |
do { |
|---|
| 206 |
$users[$row['language']][] = $row['uid']; |
|---|
| 207 |
} |
|---|
| 208 |
while ($row = $db->sql_fetchrow($result)); |
|---|
| 209 |
|
|---|
| 210 |
foreach ( $users AS $user_lang => $user_id ) { |
|---|
| 211 |
@include($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 212 |
|
|---|
| 213 |
for ( $i = 0; $i < sizeof($user_id); $i++ ) { |
|---|
| 214 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, class = ' . UC_USER .', torrents_limit = ' . $tor_limit . ' WHERE uid = ' . $user_id[$i]; |
|---|
| 215 |
$db->sql_query($sql); |
|---|
| 216 |
|
|---|
| 217 |
$sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_USER] . ' WHERE user_id = ' . $user_id[$i] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')'; |
|---|
| 218 |
$db->sql_query($sql); |
|---|
| 219 |
|
|---|
| 220 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $user_id[$i], 'added' => $this->time_now, 'msg' => sprintf($lang['pm_demote_to_user_body'], $minratio), 'subject' => $lang['pm_demote_to_user_subject'], 'location' => 1 ); |
|---|
| 221 |
} |
|---|
| 222 |
} |
|---|
| 223 |
} |
|---|
| 224 |
$db->sql_freeresult($result); |
|---|
| 225 |
} |
|---|
| 226 |
if ( sizeof($this->privmsg_insert_arr) ) { |
|---|
| 227 |
$db->sql_multi_insert(PRIVATE_MESSAGES_TABLE, $this->privmsg_insert_arr); |
|---|
| 228 |
} |
|---|
| 229 |
$this->privmsg_insert_arr = array(); |
|---|
| 230 |
|
|---|
| 231 |
return true; |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
function _clean_old_torrents () { |
|---|
| 235 |
global $config, $db, $lang, $root_path; |
|---|
| 236 |
|
|---|
| 237 |
if ( !$config['ttl'] && !$config['alternate_ttl'] ) { |
|---|
| 238 |
return true; |
|---|
| 239 |
} |
|---|
| 240 |
@require_once ($root_path . 'include/functions_delete.php'); |
|---|
| 241 |
@include ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_modcomment_log.php'); |
|---|
| 242 |
|
|---|
| 243 |
if ( $config['ttl'] > 0 ) { |
|---|
| 244 |
$dt = $this->time_now - ($config['ttl'] * 24 * 60 * 60); |
|---|
| 245 |
$sql = 'SELECT fid, name, info_hash FROM ' . TORRENTS_TABLE . ' WHERE ctime < ' . $dt . ' AND leechers = 0'; |
|---|
| 246 |
$result = $db->sql_query($sql); |
|---|
| 247 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 248 |
$delete_arr_torrents = array(); |
|---|
| 249 |
do { |
|---|
| 250 |
write_log( sprintf($lang['log_torrent_deleted_by_system_ttl_expired'], $row['fid'], $row['name'], $config['ttl']) ); |
|---|
| 251 |
$delete_arr_torrents[$row['info_hash']] = $row['fid']; |
|---|
| 252 |
} |
|---|
| 253 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 254 |
deletetorrent ($delete_arr_torrents); |
|---|
| 255 |
} |
|---|
| 256 |
$db->sql_freeresult($result); |
|---|
| 257 |
} |
|---|
| 258 |
elseif ( $config['alternate_ttl'] > 0 ) { |
|---|
| 259 |
$dt = $this->time_now - ($config['alternate_ttl'] * 24 * 60 * 60); |
|---|
| 260 |
$sql = 'SELECT fid, name, info_hash FROM ' . TORRENTS_TABLE . ' WHERE mtime < ' . $dt . ' AND leechers = 0'; |
|---|
| 261 |
$result = $db->sql_query($sql); |
|---|
| 262 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 263 |
$delete_arr_torrents = array(); |
|---|
| 264 |
do { |
|---|
| 265 |
write_log( sprintf($lang['log_torrent_deleted_by_system_no_activity'], $row['fid'], $row['name'], $config['alternate_ttl']) ); |
|---|
| 266 |
$delete_arr_torrents[$row['info_hash']] = $row['fid']; |
|---|
| 267 |
} |
|---|
| 268 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 269 |
deletetorrent ($delete_arr_torrents); |
|---|
| 270 |
} |
|---|
| 271 |
$db->sql_freeresult($result); |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
return true; |
|---|
| 275 |
} |
|---|
| 276 |
|
|---|
| 277 |
function _autowarn_autodemote () { |
|---|
| 278 |
global $db, $config, $phpbb_class, $lang, $root_path; |
|---|
| 279 |
|
|---|
| 280 |
if ( !$config['autowarn_settings'] || !$config['allow_autowarn'] ) { |
|---|
| 281 |
return true; |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
$auto_warn_table_arr = @explode(';', $config['autowarn_settings']); |
|---|
| 285 |
if ( !is_array($auto_warn_table_arr) ) { |
|---|
| 286 |
set_config('allow_autowarn', 0); |
|---|
| 287 |
return true; |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
@include ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_modcomment_log.php'); |
|---|
| 291 |
|
|---|
| 292 |
$user_limit_ary_allow_download = unserialize($config['user_limit_ary_allow_download']); |
|---|
| 293 |
$user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']); |
|---|
| 294 |
|
|---|
| 295 |
$limit = $minratio = $until = 0; |
|---|
| 296 |
|
|---|
| 297 |
for ( $i = 0; $i < sizeof($auto_warn_table_arr); ++$i ) { |
|---|
| 298 |
list($length, $limit, $minratio) = explode('-', $auto_warn_table_arr[$i]); |
|---|
| 299 |
$until = $this->time_now + ( ( $length + 1 ) * 24 * 60 * 60 ); |
|---|
| 300 |
$limit = $limit * 1024 * 1024 * 1024; |
|---|
| 301 |
$minratio = (float) $minratio; |
|---|
| 302 |
|
|---|
| 303 |
$now = $this->time_now - $config['autowarn_min_added'] * 24 * 60 * 60; |
|---|
| 304 |
|
|---|
| 305 |
$sql = 'SELECT uid, warn, language, user_reputation, user_reputation_level, user_rank_id, modcomment, ip |
|---|
| 306 |
FROM ' . USERS_TABLE . ' |
|---|
| 307 |
WHERE class = ' . UC_USER . ' |
|---|
| 308 |
AND enabled = 1 |
|---|
| 309 |
AND downloaded > ' . $limit . ' |
|---|
| 310 |
AND uploaded / downloaded < ' . $minratio . ' |
|---|
| 311 |
AND warneduntil = 0 |
|---|
| 312 |
AND donor = 0 |
|---|
| 313 |
AND added < ' . $now; |
|---|
| 314 |
$result = $db->sql_query($sql); |
|---|
| 315 |
|
|---|
| 316 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 317 |
$users = array(); |
|---|
| 318 |
$simpaty_update = array(); |
|---|
| 319 |
$tor_limit = ( isset($user_limit_ary_torrents['W']) ? intval($user_limit_ary_torrents['W']) : 0 ); |
|---|
| 320 |
|
|---|
| 321 |
do { |
|---|
| 322 |
$users[$row['language']][] = $row; |
|---|
| 323 |
$simpaty_update[] = $row; |
|---|
| 324 |
} |
|---|
| 325 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 326 |
|
|---|
| 327 |
foreach ( $users AS $user_lang => $ary ) { |
|---|
| 328 |
include($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 329 |
$modcomment_warn = "\n" . sprintf( $lang['modcomment_received_autowarn'], 't' . $this->time_now);; |
|---|
| 330 |
$modcomment_ban = "\n" . sprintf( $lang['modcomment_autobanned'], 't' . $this->time_now); |
|---|
| 331 |
|
|---|
| 332 |
foreach ( $ary AS $_null => $users_ary ) { |
|---|
| 333 |
$modcomment = $users_ary['modcomment']; |
|---|
| 334 |
$modcomment .= $modcomment_warn; |
|---|
| 335 |
if ( $users_ary['warn'] >= $config['max_warn_for_user'] ) { |
|---|
| 336 |
$modcomment .= $modcomment_ban; |
|---|
| 337 |
|
|---|
| 338 |
session_reset_keys($users_ary['uid'], $users_ary['ip']); |
|---|
| 339 |
} |
|---|
| 340 |
|
|---|
| 341 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, warn = warn + 1, modcomment = \'' . $db->sql_escape($modcomment) . '\', ' . ( $users_ary['warn'] >= $config['max_warn_for_user'] ? 'enabled = 0' : 'warneduntil = ' . $until . ', torrents_limit = ' . $tor_limit) . ' WHERE uid = ' . $users_ary['uid']; |
|---|
| 342 |
$db->sql_query($sql); |
|---|
| 343 |
|
|---|
| 344 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $users_ary['uid'], 'added' => $this->time_now, 'msg' => sprintf($lang['pm_auto_warning_body'], $length, $length), 'subject' => $lang['pm_auto_warning_subject'], 'location' => 1 ); |
|---|
| 345 |
} |
|---|
| 346 |
} |
|---|
| 347 |
|
|---|
| 348 |
update_reputation($simpaty_update, SIMPATY_WARN, 1); |
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
$db->sql_freeresult($result); |
|---|
| 352 |
|
|---|
| 353 |
$length = $this->time_now + 1 * 24 * 60 * 60; |
|---|
| 354 |
|
|---|
| 355 |
$sql = 'SELECT uid, language, modcomment |
|---|
| 356 |
FROM ' . USERS_TABLE . ' |
|---|
| 357 |
WHERE class = ' . UC_USER . ' |
|---|
| 358 |
AND warneduntil <> 0 |
|---|
| 359 |
AND warneduntil < ' . $length . ' |
|---|
| 360 |
AND enabled = 1 |
|---|
| 361 |
AND downloaded > ' . $limit . ' |
|---|
| 362 |
AND ( uploaded / downloaded ) < ' . $minratio . ' |
|---|
| 363 |
AND added < ' . $now . ' |
|---|
| 364 |
AND autodemote = 1'; |
|---|
| 365 |
|
|---|
| 366 |
$result = $db->sql_query($sql); |
|---|
| 367 |
|
|---|
| 368 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 369 |
$modcomment_demote = "\n" . sprintf( $lang['modcomment_auto_demoted_to_peasant'], 't' . $this->time_now); |
|---|
| 370 |
$users = array(); |
|---|
| 371 |
$can_leech = ( isset($user_limit_ary_allow_download[UC_PEASANT]) ? 1 : 0 ); |
|---|
| 372 |
|
|---|
| 373 |
do { |
|---|
| 374 |
$users[$row['language']][] = $row; |
|---|
| 375 |
} |
|---|
| 376 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 377 |
|
|---|
| 378 |
foreach ( $users AS $user_lang => $ary ) { |
|---|
| 379 |
include($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 380 |
|
|---|
| 381 |
foreach ( $ary AS $_null => $users_ary ) { |
|---|
| 382 |
$modcomment = $users_ary['modcomment'] . $modcomment_demote; |
|---|
| 383 |
|
|---|
| 384 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, class = ' . UC_PEASANT . ', warneduntil = 0, modcomment = \'' . $db->sql_escape($modcomment) . '\', can_leech = ' . $can_leech . ' WHERE uid = ' . $users_ary['uid']; |
|---|
| 385 |
$db->sql_query($sql); |
|---|
| 386 |
|
|---|
| 387 |
$sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_PEASANT] . ' WHERE user_id = ' . $users_ary['uid'] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')'; |
|---|
| 388 |
$db->sql_query($sql); |
|---|
| 389 |
|
|---|
| 390 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $users_ary['uid'], 'added' => $this->time_now, 'msg' => $lang['pm_demote_to_peasant_body'], 'subject' => $lang['pm_demote_to_user_subject'], 'location' => 1 ); |
|---|
| 391 |
} |
|---|
| 392 |
} |
|---|
| 393 |
} |
|---|
| 394 |
$db->sql_freeresult($result); |
|---|
| 395 |
} |
|---|
| 396 |
|
|---|
| 397 |
$auto_warn_table_arr2 = $not_in_arr = array(); |
|---|
| 398 |
for ( $i = 0; $i < sizeof($auto_warn_table_arr); ++$i ) { |
|---|
| 399 |
list($length, $limit, $minratio) = explode('-', $auto_warn_table_arr[$i]); |
|---|
| 400 |
$auto_warn_table_arr2[$limit] = $minratio + 0.05; |
|---|
| 401 |
} |
|---|
| 402 |
|
|---|
| 403 |
foreach ( $auto_warn_table_arr2 AS $gigs => $minratio ) { |
|---|
| 404 |
if ( isset($not_in_arr) && sizeof($not_in_arr) ) { |
|---|
| 405 |
$not_in_sql = $not_in_arr; |
|---|
| 406 |
} |
|---|
| 407 |
$limit = intval($gigs) * 1024 * 1024 * 1024; |
|---|
| 408 |
$sql = 'SELECT uid, language, uploaded, downloaded, modcomment |
|---|
| 409 |
FROM ' . USERS_TABLE . ' |
|---|
| 410 |
WHERE class = ' . UC_PEASANT . ' |
|---|
| 411 |
AND enabled = 1 |
|---|
| 412 |
AND downloaded > ' . $limit . ( isset($not_in_sql) ? ' AND uid NOT IN (' . implode(', ', $not_in_sql) . ')' : '' ) ; |
|---|
| 413 |
$result = $db->sql_query($sql); |
|---|
| 414 |
|
|---|
| 415 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 416 |
$modcomment_promote = "\n" . sprintf( $lang['modcomment_auto_promoted_to_user'], 't' . $this->time_now); |
|---|
| 417 |
$can_leech = ( isset($user_limit_ary_allow_download[UC_USER]) ? 1 : 0 ); |
|---|
| 418 |
$tor_limit = ( isset($user_limit_ary_torrents[UC_USER]) ? intval($user_limit_ary_torrents[UC_USER]) : 0 ); |
|---|
| 419 |
|
|---|
| 420 |
do { |
|---|
| 421 |
$not_in_arr[] = $row['uid']; |
|---|
| 422 |
if ( ( $row['uploaded'] / $row['downloaded'] ) > ( $minratio + ( 100 * 1024 * 1024 ) ) ) { |
|---|
| 423 |
include($root_path . 'languages/lang_' . $row['language'] . '/lang_pms.php'); |
|---|
| 424 |
|
|---|
| 425 |
$modcomment = $row['modcomment'] . $modcomment_promote; |
|---|
| 426 |
|
|---|
| 427 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, class = ' . UC_USER . ', modcomment = \'' . $db->sql_escape($modcomment) . '\', can_leech = ' . $can_leech . ', torrents_limit = ' . $tor_limit . ' WHERE uid = ' . $row['uid']; |
|---|
| 428 |
$db->sql_query($sql); |
|---|
| 429 |
|
|---|
| 430 |
$sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_USER] . ' WHERE user_id = ' . $row['uid'] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')'; |
|---|
| 431 |
$db->sql_query($sql); |
|---|
| 432 |
|
|---|
| 433 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $row['uid'], 'added' => $this->time_now, 'msg' => $lang['pm_auto_promoted_to_user'], 'subject' => $lang['pm_promote_to_power_user_subject'], 'location' => 1 ); |
|---|
| 434 |
} |
|---|
| 435 |
} |
|---|
| 436 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 437 |
} |
|---|
| 438 |
$db->sql_freeresult($result); |
|---|
| 439 |
} |
|---|
| 440 |
|
|---|
| 441 |
if ( sizeof($this->privmsg_insert_arr) ) { |
|---|
| 442 |
$db->sql_multi_insert(PRIVATE_MESSAGES_TABLE, $this->privmsg_insert_arr); |
|---|
| 443 |
} |
|---|
| 444 |
$this->privmsg_insert_arr = array(); |
|---|
| 445 |
|
|---|
| 446 |
return true; |
|---|
| 447 |
} |
|---|
| 448 |
|
|---|
| 449 |
function _remove_expired_warnings () { |
|---|
| 450 |
global $db, $root_path, $config; |
|---|
| 451 |
|
|---|
| 452 |
$sql = 'SELECT uid, language, class FROM ' . USERS_TABLE . ' WHERE warneduntil < ' . $this->time_now . ' AND warneduntil <> 0'; |
|---|
| 453 |
$result = $db->sql_query($sql); |
|---|
| 454 |
|
|---|
| 455 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 456 |
$user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']); |
|---|
| 457 |
|
|---|
| 458 |
$users = array(); |
|---|
| 459 |
do { |
|---|
| 460 |
$users[$row['language']][] = array($row['uid'] => $row['class']); |
|---|
| 461 |
} |
|---|
| 462 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 463 |
|
|---|
| 464 |
foreach ( $users AS $user_lang => $ary ) { |
|---|
| 465 |
@include($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 466 |
|
|---|
| 467 |
for ( $i = 0; $i < sizeof($ary); $i++ ) { |
|---|
| 468 |
foreach ( $ary[$i] AS $user_id => $class ) { |
|---|
| 469 |
$tor_limit = ( isset($user_limit_ary_torrents[$class]) ? intval($user_limit_ary_torrents[$class]) : 0 ); |
|---|
| 470 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, warneduntil = 0, torrents_limit = ' . $tor_limit . ' WHERE uid = ' . $user_id; |
|---|
| 471 |
$db->sql_query($sql); |
|---|
| 472 |
|
|---|
| 473 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $user_id, 'added' => $this->time_now, 'msg' => $lang['pm_warn_auto_removed'], 'subject' => $lang['pm_warn_deleted_subject'], 'location' => 1 ); |
|---|
| 474 |
} |
|---|
| 475 |
} |
|---|
| 476 |
} |
|---|
| 477 |
} |
|---|
| 478 |
$db->sql_freeresult($result); |
|---|
| 479 |
|
|---|
| 480 |
if ( sizeof($this->privmsg_insert_arr) ) { |
|---|
| 481 |
$db->sql_multi_insert(PRIVATE_MESSAGES_TABLE, $this->privmsg_insert_arr); |
|---|
| 482 |
} |
|---|
| 483 |
$this->privmsg_insert_arr = array(); |
|---|
| 484 |
|
|---|
| 485 |
$sql = 'DELETE FROM ' . BANLIST_TABLE . ' WHERE ban_until < ' . $this->time_now . ' AND ban_until <> 0'; |
|---|
| 486 |
$db->sql_query($sql); |
|---|
| 487 |
|
|---|
| 488 |
return true; |
|---|
| 489 |
} |
|---|
| 490 |
|
|---|
| 491 |
function _demote_uploaders () { |
|---|
| 492 |
global $db, $config, $lang, $root_path, $phpbb_class; |
|---|
| 493 |
|
|---|
| 494 |
if ( !$config['demote_uploader_days'] ) { |
|---|
| 495 |
return true; |
|---|
| 496 |
} |
|---|
| 497 |
$user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']); |
|---|
| 498 |
|
|---|
| 499 |
include ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_modcomment_log.php'); |
|---|
| 500 |
|
|---|
| 501 |
$days = $this->time_now - $config['demote_uploader_days'] * 24 * 60 * 60; |
|---|
| 502 |
|
|---|
| 503 |
$sql = 'SELECT u.uid, u.name, u.language, up.applied, u.modcomment |
|---|
| 504 |
FROM ' . TORRENTS_TABLE . ' t, ' . USERS_TABLE . ' u |
|---|
| 505 |
LEFT JOIN ' . UPLOADAPP_TABLE . ' up ON (u.uid = up.userid) |
|---|
| 506 |
WHERE u.class = ' . UC_UPLOADER . ' AND u.autodemote = 1 AND t.owner = u.uid AND t.owner AND u.uid != ' . ANONYMOUS . ' |
|---|
| 507 |
GROUP BY u.uid |
|---|
| 508 |
HAVING MAX(t.ctime) < ' . $days; |
|---|
| 509 |
$result = $db->sql_query($sql); |
|---|
| 510 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 511 |
$modcomment = "\n" . sprintf( $lang['modcomment_auto_demote_uploader'], 't' . $this->time_now); |
|---|
| 512 |
|
|---|
| 513 |
$users = array(); |
|---|
| 514 |
$tor_limit = ( isset($user_limit_ary_torrents[UC_USER]) ? intval($user_limit_ary_torrents[UC_USER]) : 0 ); |
|---|
| 515 |
do { |
|---|
| 516 |
if ( is_null($row['applied']) || ( $row['applied'] < $this->time_now - $config['uploader_promoted_demote_days'] * 24 * 60 * 60 ) ) { |
|---|
| 517 |
$users[$row['language']][] = $row; |
|---|
| 518 |
} |
|---|
| 519 |
} |
|---|
| 520 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 521 |
|
|---|
| 522 |
foreach ( $users AS $user_lang => $ary ) { |
|---|
| 523 |
include($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 524 |
|
|---|
| 525 |
foreach ( $ary AS $_null => $users_ary ) { |
|---|
| 526 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms + 1, class=' . UC_USER . ', modcomment = \'' . $db->sql_escape($modcomment) . '\', torrents_limit = ' . $tor_limit . ' WHERE uid=' . $users_ary['uid']; |
|---|
| 527 |
$db->sql_query($sql); |
|---|
| 528 |
|
|---|
| 529 |
$sql = 'UPDATE ' . USER_GROUP_TABLE . ' SET group_id = ' . $phpbb_class[UC_USER] . ' WHERE user_id = ' . $users_ary['uid'] . ' AND group_id IN (' . implode(', ', $phpbb_class) . ')'; |
|---|
| 530 |
$db->sql_query($sql); |
|---|
| 531 |
|
|---|
| 532 |
write_log ( sprintf($lang['log_auto_demote_uploader'], $users_ary['uid'], $users_ary['name'], $config['demote_uploader_days']), LOG_VIEW_MOD ); |
|---|
| 533 |
|
|---|
| 534 |
$this->privmsg_insert_arr[] = array( 'sender' => 0, 'receiver' => $users_ary['uid'], 'added' => $this->time_now, 'msg' => sprintf($lang['pm_auto_demote_uploader'], $config['demote_uploader_days']), 'subject' => $lang['pm_demote_to_user_subject'], 'location' => 1 ); |
|---|
| 535 |
} |
|---|
| 536 |
} |
|---|
| 537 |
} |
|---|
| 538 |
$db->sql_freeresult($result); |
|---|
| 539 |
|
|---|
| 540 |
if ( sizeof($this->privmsg_insert_arr) ) { |
|---|
| 541 |
$db->sql_multi_insert(PRIVATE_MESSAGES_TABLE, $this->privmsg_insert_arr); |
|---|
| 542 |
} |
|---|
| 543 |
$this->privmsg_insert_arr = array(); |
|---|
| 544 |
|
|---|
| 545 |
return true; |
|---|
| 546 |
} |
|---|
| 547 |
|
|---|
| 548 |
function _receive_invites () { |
|---|
| 549 |
global $db, $config; |
|---|
| 550 |
|
|---|
| 551 |
if ( !$config['allow_invite'] ) { |
|---|
| 552 |
return true; |
|---|
| 553 |
} |
|---|
| 554 |
|
|---|
| 555 |
$number_invites = explode(',', $config['number_invites']); |
|---|
| 556 |
$users_class_arr = array(); |
|---|
| 557 |
$i = 0; |
|---|
| 558 |
while ( get_user_class_name($i) !== '' ) { |
|---|
| 559 |
$users_class_arr[$i] = intval($number_invites[$i]); |
|---|
| 560 |
++$i; |
|---|
| 561 |
} |
|---|
| 562 |
$users_class_count = sizeof($users_class_arr); |
|---|
| 563 |
$number_invites_count = sizeof($number_invites); |
|---|
| 564 |
|
|---|
| 565 |
if ( $number_invites_count == $users_class_count ) { |
|---|
| 566 |
foreach( $users_class_arr AS $class => $num_invites ) { |
|---|
| 567 |
if ( $num_invites ) { |
|---|
| 568 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET invites = invites + ' . $num_invites . ' WHERE class = ' . $class; |
|---|
| 569 |
$db->sql_query($sql); |
|---|
| 570 |
} |
|---|
| 571 |
} |
|---|
| 572 |
} |
|---|
| 573 |
|
|---|
| 574 |
return true; |
|---|
| 575 |
} |
|---|
| 576 |
|
|---|
| 577 |
function _delete_old_sessions () { |
|---|
| 578 |
global $db, $config; |
|---|
| 579 |
|
|---|
| 580 |
$batch_size = 100; |
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
$sql = 'DELETE FROM ' . SESSIONS_TABLE . ' |
|---|
| 584 |
WHERE session_user_id = ' . ANONYMOUS . ' |
|---|
| 585 |
AND session_time < ' . (int) ($this->time_now - $config['session_length']); |
|---|
| 586 |
$db->sql_query($sql); |
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
$sql = 'SELECT session_user_id, session_page, MAX(session_time) AS recent_time |
|---|
| 590 |
FROM ' . SESSIONS_TABLE . ' |
|---|
| 591 |
WHERE session_time < ' . ($this->time_now - $config['session_length']) . ' |
|---|
| 592 |
GROUP BY session_user_id, session_page'; |
|---|
| 593 |
$result = $db->sql_query_limit($sql, $batch_size); |
|---|
| 594 |
|
|---|
| 595 |
$del_user_id = array(); |
|---|
| 596 |
$del_sessions = 0; |
|---|
| 597 |
|
|---|
| 598 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 599 |
{ |
|---|
| 600 |
$sql = 'UPDATE ' . USERS_TABLE . ' |
|---|
| 601 |
SET user_lastvisit = ' . (int) $row['recent_time'] . ", user_session_page = '" . $db->sql_escape($row['session_page']) . "' |
|---|
| 602 |
WHERE uid = " . (int) $row['session_user_id']; |
|---|
| 603 |
$db->sql_query($sql); |
|---|
| 604 |
|
|---|
| 605 |
$del_user_id[] = (int) $row['session_user_id']; |
|---|
| 606 |
$del_sessions++; |
|---|
| 607 |
} |
|---|
| 608 |
$db->sql_freeresult($result); |
|---|
| 609 |
|
|---|
| 610 |
if (sizeof($del_user_id)) |
|---|
| 611 |
{ |
|---|
| 612 |
|
|---|
| 613 |
$sql = 'DELETE FROM ' . SESSIONS_TABLE . ' |
|---|
| 614 |
WHERE ' . $db->sql_in_set('session_user_id', $del_user_id) . ' |
|---|
| 615 |
AND session_time < ' . ($this->time_now - $config['session_length']); |
|---|
| 616 |
$db->sql_query($sql); |
|---|
| 617 |
} |
|---|
| 618 |
|
|---|
| 619 |
if ($del_sessions < $batch_size) |
|---|
| 620 |
{ |
|---|
| 621 |
|
|---|
| 622 |
if ($config['max_autologin_time']) |
|---|
| 623 |
{ |
|---|
| 624 |
$sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' |
|---|
| 625 |
WHERE last_login < ' . ($this->time_now - (86400 * (int) $config['max_autologin_time'])); |
|---|
| 626 |
$db->sql_query($sql); |
|---|
| 627 |
} |
|---|
| 628 |
|
|---|
| 629 |
$sql = 'SELECT DISTINCT c.session_id |
|---|
| 630 |
FROM ' . CONFIRM_TABLE . ' c |
|---|
| 631 |
LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) |
|---|
| 632 |
WHERE s.session_id IS NULL' . |
|---|
| 633 |
((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type); |
|---|
| 634 |
$result = $db->sql_query($sql); |
|---|
| 635 |
|
|---|
| 636 |
if ($row = $db->sql_fetchrow($result)) |
|---|
| 637 |
{ |
|---|
| 638 |
$sql_in = array(); |
|---|
| 639 |
do |
|---|
| 640 |
{ |
|---|
| 641 |
$sql_in[] = (string) $row['session_id']; |
|---|
| 642 |
} |
|---|
| 643 |
while ($row = $db->sql_fetchrow($result)); |
|---|
| 644 |
|
|---|
| 645 |
if (sizeof($sql_in)) |
|---|
| 646 |
{ |
|---|
| 647 |
$sql = 'DELETE FROM ' . CONFIRM_TABLE . ' |
|---|
| 648 |
WHERE ' . $db->sql_in_set('session_id', $sql_in); |
|---|
| 649 |
$db->sql_query($sql); |
|---|
| 650 |
} |
|---|
| 651 |
} |
|---|
| 652 |
$db->sql_freeresult($result); |
|---|
| 653 |
|
|---|
| 654 |
} |
|---|
| 655 |
|
|---|
| 656 |
$sql = 'DELETE FROM ' . SEARCH_TABLE . ' |
|---|
| 657 |
WHERE search_time < ' . ($this->time_now - (int) $config['session_length']); |
|---|
| 658 |
$db->sql_query($sql); |
|---|
| 659 |
|
|---|
| 660 |
return true; |
|---|
| 661 |
} |
|---|
| 662 |
|
|---|
| 663 |
function _parse_queue () { |
|---|
| 664 |
global $root_path; |
|---|
| 665 |
|
|---|
| 666 |
include_once($root_path . 'include/functions_messenger.php'); |
|---|
| 667 |
|
|---|
| 668 |
if ( @file_exists($root_path . 'cache/queue.php') ) { |
|---|
| 669 |
$queue = new queue(); |
|---|
| 670 |
$queue->process(); |
|---|
| 671 |
} |
|---|
| 672 |
|
|---|
| 673 |
if ( @file_exists($root_path . 'cache/queue_huge.php') ) { |
|---|
| 674 |
$queue = new queue($root_path . 'cache/queue_huge.php'); |
|---|
| 675 |
$queue->process(); |
|---|
| 676 |
} |
|---|
| 677 |
|
|---|
| 678 |
return true; |
|---|
| 679 |
} |
|---|
| 680 |
|
|---|
| 681 |
function _tidy_cache () { |
|---|
| 682 |
global $cache; |
|---|
| 683 |
|
|---|
| 684 |
if ( method_exists($cache, 'tidy') ) { |
|---|
| 685 |
$cache->tidy(); |
|---|
| 686 |
} |
|---|
| 687 |
|
|---|
| 688 |
return true; |
|---|
| 689 |
} |
|---|
| 690 |
} |
|---|
| 691 |
?> |
|---|