/** * Delete user and dependencies from database * * Includes WAY TOO MANY requests because we try to be compatible with MySQL 3.23, bleh! * * @param Log Log object where output gets added (by reference). */ function dbdelete(&$Log) { global $DB, $Plugins; if ($this->ID == 0) { debug_die('Non persistant object cannot be deleted!'); } $deltype = param('deltype', 'string', ''); // spammer $DB->begin(); if ($deltype == 'spammer') { // If we delete user as spammer we should delete private messaged of this user $this->delete_messages(); } else { // If we delete user as not spammer we keep his comments as from anonymous user // Transform registered user comments to unregistered: $ret = $DB->query('UPDATE T_comments SET comment_author_ID = NULL, comment_author = ' . $DB->quote($this->get('preferredname')) . ', comment_author_email = ' . $DB->quote($this->get('email')) . ', comment_author_url = ' . $DB->quote($this->get('url')) . ' WHERE comment_author_ID = ' . $this->ID); if (is_a($Log, 'log')) { $Log->add('Transforming user\'s comments to unregistered comments... ' . sprintf('(%d rows)', $ret), 'note'); } } // Get list of posts that are going to be deleted (3.23) $post_list = implode(',', $DB->get_col(' SELECT post_ID FROM T_items__item WHERE post_creator_user_ID = ' . $this->ID)); if (!empty($post_list)) { // Delete comments $ret = $DB->query("DELETE FROM T_comments\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE comment_post_ID IN ({$post_list})"); if (is_a($Log, 'log')) { $Log->add(sprintf('Deleted %d comments on user\'s posts.', $ret), 'note'); } // Delete post extracats $ret = $DB->query("DELETE FROM T_postcats\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE postcat_post_ID IN ({$post_list})"); if (is_a($Log, 'log')) { $Log->add(sprintf('Deleted %d extracats of user\'s posts\'.', $ret)); // TODO: geeky wording. } // Posts will we auto-deleted by parent method } else { // no posts if (is_a($Log, 'log')) { $Log->add('No posts to delete.', 'note'); } } // Get list of sessions that are going to be deleted $sessions_SQL = new SQL(); $sessions_SQL->SELECT('sess_ID'); $sessions_SQL->FROM('T_sessions'); $sessions_SQL->WHERE('sess_user_ID = ' . $this->ID); $sessions_list = $DB->get_col($sessions_SQL->get()); if (!empty($sessions_list)) { // Delete all hit logs of this user $DB->query('DELETE FROM T_hitlog WHERE hit_sess_ID IN ( ' . $DB->quote($sessions_list) . ' )'); } // delete user involved ophan threads delete_orphan_threads($this->ID); // Remove this user from posts where it was as last edit user $DB->query('UPDATE T_items__item SET post_lastedit_user_ID = NULL WHERE post_lastedit_user_ID = ' . $this->ID); $DB->query('UPDATE T_items__version SET iver_edit_user_ID = NULL WHERE iver_edit_user_ID = ' . $this->ID); // Remove this user from links where it was as last edit user $DB->query('UPDATE T_links SET link_lastedit_user_ID = NULL WHERE link_lastedit_user_ID = ' . $this->ID); // remember ID, because parent method resets it to 0 $old_ID = $this->ID; $old_email = $this->get('email'); // Delete main object: if (!parent::dbdelete()) { $DB->rollback(); $Log->add('User has not been deleted.', 'error'); return false; } // user was deleted, also delete this user's media folder recursively $FileRootCache =& get_FileRootCache(); $root_directory = $FileRootCache->get_root_dir('user', $old_ID); rmdir_r($root_directory); if ($deltype == 'spammer') { // User was deleted as spammer, we should mark email of this user as 'Spammer' load_class('tools/model/_emailblocked.class.php', 'EmailBlocked'); $EmailBlockedCache =& get_EmailBlockedCache(); $EmailBlocked =& $EmailBlockedCache->get_by_name($old_email, false, false); if (!$EmailBlocked) { // Create new record in the T_email_blocked table $EmailBlocked = new EmailBlocked(); $EmailBlocked->set('address', $old_email); } if (!empty($EmailBlocked)) { // Save status of an email address $EmailBlocked->set('status', 'spammer'); $EmailBlocked->dbsave(); } } $DB->commit(); if (is_a($Log, 'log')) { $Log->add('Deleted User.', 'note'); } // Notify plugins: $this->ID = $old_ID; $Plugins->trigger_event('AfterUserDelete', $params = array('User' => &$this)); $this->ID = 0; return true; }
// We will display the output in a scrollable fieldset $repath_test_output = implode("<br />\n", $dre_messages); } break; case 'blocked_new': // Init Email Blocked to show on the form $edited_EmailBlocked = new EmailBlocked(); break; case 'blocked_save': // Update Email Blocked... // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('email_blocked'); $action = 'blocked_edit'; if (!isset($edited_EmailBlocked)) { // Create a new address $edited_EmailBlocked = new EmailBlocked(); $action = 'blocked_new'; } // load data from request if ($edited_EmailBlocked->load_from_Request()) { // We could load data from form without errors: // Save Email Blocked in DB: $edited_EmailBlocked->dbsave(); $Messages->add(T_('The email address was updated.'), 'success'); // Redirect so that a reload doesn't write to the DB twice: header_redirect('?ctrl=email&tab=blocked', 303); // Will EXIT // We have EXITed already at this point!! } break; case 'blocked_delete':
/** * Insert/Update a blocked email's data into DB * * @param array Data of returned email: * 'address' * 'errormsg' * 'message' * 'headers' * 'errtype' */ function dre_save_blocked_email($email_returned) { global $DB; if (empty($email_returned['address'])) { // No emails, Exit here return; } load_class('tools/model/_emailblocked.class.php', 'EmailBlocked'); $EmailBlockedCache =& get_EmailBlockedCache(); // Get an existing email address to update if it exist $EmailBlocked =& $EmailBlockedCache->get_by_name($email_returned['address'], false); if (!$EmailBlocked) { // Insert new email address $EmailBlocked = new EmailBlocked(); $EmailBlocked->set('address', $email_returned['address']); } switch ($email_returned['errtype']) { // Error type of the returned email: case 'P': // Permanent error $EmailBlocked->increase_counter('prmerror'); // Update only the adresses with NOT spammer statuses $EmailBlocked->set_status('prmerror'); break; case 'T': // Temporary error if (in_array($EmailBlocked->get('status'), array('suspicious1', 'suspicious2', 'suspicious3'))) { // If current status alredy is defined as 'suspicious1', 'suspicious2' or 'suspicious3' if ($EmailBlocked->get('sent_last_returnerror') <= 1) { if ($EmailBlocked->get('status') == 'suspicious1') { // Increase status from suspicious1 to suspicious2 $EmailBlocked->set('status', 'suspicious2'); } elseif ($EmailBlocked->get('status') == 'suspicious2') { // Increase status from suspicious2 to suspicious3 $EmailBlocked->set('status', 'suspicious3'); } } } else { // Update only the email addresses with level status less then Suspicious 1 $EmailBlocked->set_status('suspicious1'); } $EmailBlocked->increase_counter('tmperror'); break; case 'S': // Spam suspicion $EmailBlocked->increase_counter('spamerror'); // Update only the email addresses with 'unknown' status $EmailBlocked->set_status('warning'); break; default: // Other errors $EmailBlocked->increase_counter('othererror'); // Update only the email addresses with 'unknown' status $EmailBlocked->set_status('warning'); break; } // Insert/Update an email address $EmailBlocked->dbsave(); }