Файл: CMS/core/admin/del.inc.php
Строк: 109
<?php
if (!defined('CMS')) { die('Access Denied!'); }
# Функция полного удаления юзера
function delete_users($user = '') {
global $db;
if (!empty($user)) {
$userpic = $db->selectCell("SELECT `users_picture` FROM ?_users WHERE `users_login` = ? LIMIT 1;", $user);
unlink_image('upload/photos/', $userpic);
unlink_image('upload/avatars/', $user.'.gif');
$db->query("DELETE FROM ?_board_posts WHERE `board_user` = ?;", $user); // ??? - xz del BLOG ???
$db->query("DELETE FROM ?_users_inbox WHERE `inbox_user` = ?;", $user);
$db->query("DELETE FROM ?_users_outbox WHERE `outbox_author` = ?;", $user);
$db->query("DELETE FROM ?_users_trash WHERE `trash_user` = ?;", $user);
$db->query("DELETE FROM ?_users_contact_list WHERE `contact_user` = ?;", $user);
$db->query("DELETE FROM ?_users_ignor_list WHERE `ignore_user` = ?;", $user);
$db->query("DELETE FROM ?_users_index WHERE `index_user` = ?;", $user);
$db->query("DELETE FROM ?_users_rating WHERE `rating_user` = ?;", $user);
$db->query("DELETE FROM ?_users_visit WHERE `visit_user` = ?;", $user);
$db->query("DELETE FROM ?_users_wall WHERE `wall_user` = ?;", $user);
$db->query("DELETE FROM ?_users_note WHERE `note_user` = ?;", $user);
$db->query("DELETE FROM ?_users_ban_history WHERE `ban_user` = ?;", $user);
$db->query("DELETE FROM ?_users_bookmarks WHERE `book_user` = ?;", $user);
$db->query("DELETE FROM ?_users_login WHERE `login_user` = ?;", $user);
$db->query("DELETE FROM ?_users_shop WHERE `shop_user` = ?;", $user);
$db->query("DELETE FROM ?_users WHERE `users_login` = ?;", $user);
$db->query("DELETE FROM ?_present WHERE (`user_from` = ? OR `user_to` = ?);", $user, $user);
$db->query("DELETE FROM ?_users_lenta WHERE (`lenta_subscriber` = ? OR `lenta_publisher` = ?);", $user, $user);
$db->query("DELETE FROM ?_users_lenta_subscribe WHERE (`sub_subscriber` = ? OR `sub_publisher` = ?);", $user, $user);
$db->query("DELETE FROM ?_friends WHERE (`users_login` = ? OR `friends_login` = ?);", $user, $user);
}
}
# Функция удаления фотоальбома юзера
function delete_album($user = '') {
global $db;
if (!empty($user)){
$arr_photo = $db->select("SELECT * FROM ?_users_photos WHERE `photo_user` = ?;", $user);
if (count($arr_photo) > 0) {
foreach ($arr_photo as $delete) {
$db->query("DELETE FROM ?_users_photos WHERE `photo_id` = ? LIMIT 1;", $delete['photo_id']);
$db->query("DELETE FROM ?_users_photos_rated WHERE `rated_photo` = ? LIMIT 1;", $delete['photo_id']);
$db->query("DELETE FROM ?_users_battle_rated WHERE `rated_photo` = ? LIMIT 1;", $delete['photo_id']);
$db->query("DELETE FROM ?_comments
WHERE (`comm_type` = 'gallery' OR `comm_type` = 'battle')
AND `comm_post` = ?;", $delete['photo_id']);
$db->query("DELETE FROM ?_users_battle
WHERE `battle_photo_1` = ? OR `battle_photo_2` = ?", $delete['photo_id'], $delete['photo_id']);
unlink_image('upload/pictures/', $delete['photo_link']);
}
$db->query("OPTIMIZE TABLE ?_users_photos, ?_users_photos_rated, ?_comments, ?_users_battle, ?_users_battle_rated;");
$db->query("UPDATE ?_users_photos SET `photo_comments` = (SELECT COUNT(1) FROM ?_comments WHERE ?_users_photos.`photo_id` = ?_comments.`comm_post` AND ?_comments.`comm_type` = 'gallery');");
$db->query("UPDATE ?_users_battle SET `battle_comm` = (SELECT COUNT(1) FROM ?_comments WHERE ?_users_battle.`battle_id` = ?_comments.`comm_post` AND ?_comments.`comm_type` = 'battle');");
}
}
}
# Функция удаления файлов юзера
function delete_files($user = '') {
global $db, $config;
if (!empty($user)){
$arr_files = $db->select("SELECT * FROM ?_downs WHERE `downs_user` = ?;", $user);
if (count($arr_files) > 0) {
foreach($arr_files as $delete) {
deldir(ROOTPATH . DS . $config['files_folder'] . DS . $delete['downs_id'], 1);
$db->query("DELETE FROM ?_comments WHERE `comm_type` = 'load' AND `comm_post` = ?;", $delete['downs_id']);
}
}
$db->query("DELETE FROM ?_downs WHERE `downs_user` = ?;", $user);
$db->query("DELETE FROM ?_downs_category WHERE `cats_user` = ?;", $user);
$db->query("OPTIMIZE TABLE ?_downs, ?_downs_category;");
/* Пересчет */
$db->query("UPDATE ?_downs SET `downs_comments` = (SELECT COUNT(*) FROM ?_comments
WHERE ?_downs.`downs_id` = ?_comments.`comm_post` AND ?_comments.`comm_type` = 'load');");
$db->query("UPDATE ?_downs_category SET `cats_count` = (SELECT COUNT(*) FROM ?_downs
WHERE ?_downs_category.`cats_id` = ?_downs.`downs_cats_id`);");
$rows = $db->select("SELECT * FROM ?_downs_category WHERE `cats_upload` = '1' AND `cats_count` > '0'");
$arrs = array();
foreach($rows as $row) {
if (!empty($row['cats_parent_all'])) {
$exp = explode(',', $row['cats_parent_all']);
if (!empty($exp)) {
for($i = 0; $i < count($exp); $i++) {
if (empty($exp[$i])) continue;
$key = !empty($exp[$i]) ? num($exp[$i]) : 0;
@$arrs[$key] += !empty($row['cats_count']) ? num($row['cats_count']) : 0;
}
}
}
}
if (!empty($arrs)) {
foreach($arrs as $key => $count) {
$db->query("UPDATE ?_downs_category SET `cats_count` = ? WHERE `cats_id` = ?", $count, $key);
}
}
del_vars('loads_categories');
del_vars('loads_cats_names');
}
}
# Функция полного удаления сообщества
function delete_soo($soo_id = '', $image = '') {
global $db, $config;
if (!empty($soo_id)) {
$soo_id = num($soo_id);
$dels = $db->select("SELECT `files_id` FROM ?_comm_files
WHERE `files_comm` = ?", $soo_id);
if (!empty($dels)) {
foreach($dels as $del) {
$db->query("DELETE FROM ?_comments WHERE `comm_post` = ? AND `comm_type` = 'soo_files';", $del['files_id']);
}
}
$db->query("DELETE FROM ?_comm_chat WHERE `chat_comm` = ? LIMIT 1;", $soo_id);
$db->query("DELETE FROM ?_comm_files_category WHERE `cats_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_files WHERE `files_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_forums WHERE `forums_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_topics WHERE `topics_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_posts WHERE `posts_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_users WHERE `cu_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_new_users WHERE `new_comm` = ?;", $soo_id);
$db->query("DELETE FROM ?_comm_comm WHERE `comm_id` = ?;", $soo_id);
$db->query("OPTIMIZE TABLE ?_comm_chat, ?_comments, ?_comm_files_category, ?_comm_files, ?_comm_forums, ?_comm_topics,
?_comm_posts, ?_comm_users, ?_comm_new_users, ?_comm_comm;");
clearstatcache();
@chmod( ROOTPATH . '/upload/comm/', 0755 );
$small = str_ireplace('_small', '', $image);
if ( @file_exists( ROOTPATH . '/upload/comm/' . $image ) ) {
@unlink( ROOTPATH . '/upload/comm/' . $image );
}
if ( @file_exists( ROOTPATH . '/upload/comm/' . $small ) ) {
@unlink( ROOTPATH . '/upload/comm/' . $small );
}
}
}
?>