Exemple #1
0
    /**
     * 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;
    }
Exemple #2
0
 * @var User
 */
global $current_User;
global $DB;
// Check permission:
$current_User->check_perm('emails', 'view', true);
load_funcs('tools/model/_email.funcs.php');
param_action();
$tab = param('tab', 'string', 'blocked', true);
param('action', 'string');
if ($tab == 'blocked') {
    // Email addresses
    load_class('tools/model/_emailblocked.class.php', 'EmailBlocked');
    if (param('emblk_ID', 'integer', '', true)) {
        // Load Email Blocked object
        $EmailBlockedCache =& get_EmailBlockedCache();
        if (($edited_EmailBlocked =& $EmailBlockedCache->get_by_ID($emblk_ID, false)) === false) {
            // We could not find the goal to edit:
            unset($edited_EmailBlocked);
            forget_param('emblk_ID');
            $Messages->add(sprintf(T_('Requested «%s» object does not exist any longer.'), T_('Email Blocked')), 'error');
        }
    }
}
switch ($action) {
    case 'settings':
        // Update the email settings
        // Check that this action request is not a CSRF hacked request:
        $Session->assert_received_crumb('emailsettings');
        // Check permission:
        $current_User->check_perm('emails', 'edit', true);
/**
 * 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();
}