<?php
/**
 * eXtreme Message Board
 * XMB 1.9.11
 *
 * Post Moderation Add-On
 *   Version 1.3 by Robert Chapin (miqrogroove)
 *   http://www.miqrogroove.com/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 **/

/* Configurable, edit as you like! */

// TRUE/FALSE items
define('MODERATE_GUESTS', TRUE);
define('MODERATE_NEW_USERS', TRUE);

// List of forums by fid like array(3, 15, 20);  All posts in these forums will be moderated.
$moderate_forums = array(47, 95);


/* Begin program */

if (X_SMOD or defined('MODERATE_DISABLE')) {
    // Default immunity
    $moderate_this_post = FALSE;
} else {
    // Set moderation defaults.
    $moderate_this_post = TRUE;

    // Whitelist exceptions.
    if (isset($self['postnum']) and isset($self['moderation'])) {
        if (($self['postnum'] > 0 or !MODERATE_NEW_USERS) and 1 != $self['moderation']) {
            // Member has posted before and is not moderated.
            $moderate_this_post = FALSE;
        } elseif (0 == $self['postnum'] and MODERATE_NEW_USERS and 0 == $self['moderation']) {
            // Member has not posted before and will be moderated.
            $self['moderation'] = 1;
            $db->query("UPDATE ".X_PREFIX."members SET moderation = 1 WHERE username='$xmbuser'");
        }
    } elseif (X_GUEST and !MODERATE_GUESTS) {
        // Guest is posting anonymously and is not moderated.
        $moderate_this_post = FALSE;
    } elseif (X_MEMBER) {
        // Hack may be installed wrong or partly missing.
        $moderate_this_post = FALSE;
    }

    // Blacklist exceptions.
    if (in_array($fid, $moderate_forums)) {
        $moderate_this_post = TRUE;
        if (isset($self['moderation']) and 0 == $self['moderation']) {
            // Flag this user as participating in moderated discussions.
            $self['moderation'] = 2;
            $db->query("UPDATE ".X_PREFIX."members SET moderation = 2 WHERE username='$xmbuser'");
        }
    }
}

// Set destination table names.
if ($moderate_this_post) {
    $attach_table = X_PREFIX.'new_attachments';
    $favs_table = X_PREFIX.'new_favorites';
    $pollopts_table = X_PREFIX.'new_vote_results';
    $polls_table = X_PREFIX.'new_vote_desc';
    $posts_table = X_PREFIX.'new_posts';
    $threads_table = X_PREFIX.'new_threads';
    $tid_field = 'newtid';
} else {
    $attach_table = X_PREFIX.'attachments';
    $favs_table = X_PREFIX.'favorites';
    $pollopts_table = X_PREFIX.'vote_results';
    $polls_table = X_PREFIX.'vote_desc';
    $posts_table = X_PREFIX.'posts';
    $threads_table = X_PREFIX.'threads';
    $tid_field = 'tid';
}

$moderate_storage_path = $SETTINGS['files_storage_path'];
if ($moderate_this_post) {
    $SETTINGS['files_storage_path'] = '';
}

return;
?>
