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->init_relations(true);
        } 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_user_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_user_ID = ' . $this->ID);
            if (is_a($Log, 'log')) {
                $Log->add('Transforming user\'s comments to unregistered comments... ' . sprintf('(%d rows)', $ret), 'note');
            }
        }
        // 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;
        }
        if ($deltype == 'spammer') {
            // User was deleted as spammer, we should mark email of this user as 'Spammer'
            $EmailAddressCache =& get_EmailAddressCache();
            $EmailAddress =& $EmailAddressCache->get_by_name($old_email, false, false);
            if (!$EmailAddress) {
                // Create new record in the T_email_address table
                $EmailAddress = new EmailAddress();
                $EmailAddress->set('address', $old_email);
            }
            if (!empty($EmailAddress)) {
                // Save status of an email address
                $EmailAddress->set('status', 'spammer');
                $EmailAddress->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;
        // BLOCK CACHE INVALIDATION:
        // This User has been modified, cached content depending on it should be invalidated:
        BlockCache::invalidate_key('user_ID', $old_ID);
        return true;
    }
/**
 * Insert/Update the data of email address into DB
 *
 * @param array Data of returned email:
 *               'address'
 *               'errormsg'
 *               'message'
 *               'headers'
 *               'errtype'
 */
function dre_save_email_address_data($email_returned)
{
    global $DB;
    if (empty($email_returned['address'])) {
        // No emails, Exit here
        return;
    }
    $EmailAddressCache =& get_EmailAddressCache();
    // Get an existing email address to update if it exist
    $EmailAddress =& $EmailAddressCache->get_by_name($email_returned['address'], false);
    if (!$EmailAddress) {
        // Insert new email address
        $EmailAddress = new EmailAddress();
        $EmailAddress->set('address', $email_returned['address']);
    }
    switch ($email_returned['errtype']) {
        // Error type of the returned email:
        case 'P':
            // Permanent error
            $EmailAddress->increase_counter('prmerror');
            // Update only the adresses with NOT spammer statuses
            $EmailAddress->set_status('prmerror');
            break;
        case 'T':
            // Temporary error
            if (in_array($EmailAddress->get('status'), array('suspicious1', 'suspicious2', 'suspicious3'))) {
                // If current status already is defined as 'suspicious1', 'suspicious2' or 'suspicious3'
                if ($EmailAddress->get('sent_last_returnerror') <= 1) {
                    if ($EmailAddress->get('status') == 'suspicious1') {
                        // Increase status from suspicious1 to suspicious2
                        $EmailAddress->set('status', 'suspicious2');
                    } elseif ($EmailAddress->get('status') == 'suspicious2') {
                        // Increase status from suspicious2 to suspicious3
                        $EmailAddress->set('status', 'suspicious3');
                    }
                }
            } elseif ($EmailAddress->get('status') == 'redemption') {
                // IF current status is 'redemption' we should set it as 'suspicious3'
                $EmailAddress->set_status('suspicious3');
            } else {
                // Update only the email addresses with level status less then Suspicious 1
                $EmailAddress->set_status('suspicious1');
            }
            $EmailAddress->increase_counter('tmperror');
            break;
        case 'S':
            // Spam suspicion
            $EmailAddress->increase_counter('spamerror');
            // Update only the email addresses with 'unknown' status
            $EmailAddress->set_status('warning');
            break;
        default:
            // Other errors
            $EmailAddress->increase_counter('othererror');
            // Update only the email addresses with 'unknown' status
            $EmailAddress->set_status('warning');
            break;
    }
    // Insert/Update an email address
    $EmailAddress->dbsave();
}