Ejemplo n.º 1
0
function approveTopics($topics, $approve = true)
{
    if (!is_array($topics)) {
        $topics = array($topics);
    }
    if (empty($topics)) {
        return false;
    }
    $approve_type = $approve ? 0 : 1;
    // Just get the messages to be approved and pass through...
    $request = smf_db_query('
		SELECT id_msg
		FROM {db_prefix}messages
		WHERE id_topic IN ({array_int:topic_list})
			AND approved = {int:approve_type}', array('topic_list' => $topics, 'approve_type' => $approve_type));
    $msgs = array();
    while ($row = mysql_fetch_assoc($request)) {
        $msgs[] = $row['id_msg'];
    }
    mysql_free_result($request);
    return approvePosts($msgs, $approve);
}
Ejemplo n.º 2
0
/**
 * Modifying a post...
 *
 * @package Posts
 * @param mixed[] $msgOptions
 * @param mixed[] $topicOptions
 * @param mixed[] $posterOptions
 */
function modifyPost(&$msgOptions, &$topicOptions, &$posterOptions)
{
    global $user_info, $modSettings;
    $db = database();
    $topicOptions['poll'] = isset($topicOptions['poll']) ? (int) $topicOptions['poll'] : null;
    $topicOptions['lock_mode'] = isset($topicOptions['lock_mode']) ? $topicOptions['lock_mode'] : null;
    $topicOptions['sticky_mode'] = isset($topicOptions['sticky_mode']) ? $topicOptions['sticky_mode'] : null;
    // This is longer than it has to be, but makes it so we only set/change what we have to.
    $messages_columns = array();
    if (isset($posterOptions['name'])) {
        $messages_columns['poster_name'] = $posterOptions['name'];
    }
    if (isset($posterOptions['email'])) {
        $messages_columns['poster_email'] = $posterOptions['email'];
    }
    if (isset($msgOptions['icon'])) {
        $messages_columns['icon'] = $msgOptions['icon'];
    }
    if (isset($msgOptions['subject'])) {
        $messages_columns['subject'] = $msgOptions['subject'];
    }
    if (isset($msgOptions['body'])) {
        $messages_columns['body'] = $msgOptions['body'];
        // using a custom search index, then lets get the old message so we can update our index as needed
        if (!empty($modSettings['search_custom_index_config'])) {
            require_once SUBSDIR . '/Messages.subs.php';
            $message = basicMessageInfo($msgOptions['id'], true);
            $msgOptions['old_body'] = $message['body'];
        }
    }
    if (!empty($msgOptions['modify_time'])) {
        $messages_columns['modified_time'] = $msgOptions['modify_time'];
        $messages_columns['modified_name'] = $msgOptions['modify_name'];
        $messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
    }
    if (isset($msgOptions['smileys_enabled'])) {
        $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
    }
    // Which columns need to be ints?
    $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
    $update_parameters = array('id_msg' => $msgOptions['id']);
    call_integration_hook('integrate_before_modify_post', array(&$messages_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions, &$messageInts));
    foreach ($messages_columns as $var => $val) {
        $messages_columns[$var] = $var . ' = {' . (in_array($var, $messageInts) ? 'int' : 'string') . ':var_' . $var . '}';
        $update_parameters['var_' . $var] = $val;
    }
    // Nothing to do?
    if (empty($messages_columns)) {
        return true;
    }
    // Change the post.
    $db->query('', '
		UPDATE {db_prefix}messages
		SET ' . implode(', ', $messages_columns) . '
		WHERE id_msg = {int:id_msg}', $update_parameters);
    // Lock and or sticky the post.
    if ($topicOptions['sticky_mode'] !== null || $topicOptions['lock_mode'] !== null || $topicOptions['poll'] !== null) {
        $db->query('', '
			UPDATE {db_prefix}topics
			SET
				is_sticky = {raw:is_sticky},
				locked = {raw:locked},
				id_poll = {raw:id_poll}
			WHERE id_topic = {int:id_topic}', array('is_sticky' => $topicOptions['sticky_mode'] === null ? 'is_sticky' : (int) $topicOptions['sticky_mode'], 'locked' => $topicOptions['lock_mode'] === null ? 'locked' : (int) $topicOptions['lock_mode'], 'id_poll' => $topicOptions['poll'] === null ? 'id_poll' : (int) $topicOptions['poll'], 'id_topic' => $topicOptions['id']));
    }
    // Mark the edited post as read.
    if (!empty($topicOptions['mark_as_read']) && !$user_info['is_guest']) {
        // Since it's likely they *read* it before editing, let's try an UPDATE first.
        $db->query('', '
			UPDATE {db_prefix}log_topics
			SET id_msg = {int:id_msg}
			WHERE id_member = {int:current_member}
				AND id_topic = {int:id_topic}', array('current_member' => $user_info['id'], 'id_msg' => $modSettings['maxMsgID'], 'id_topic' => $topicOptions['id']));
        $flag = $db->affected_rows() != 0;
        if (empty($flag)) {
            require_once SUBSDIR . '/Topic.subs.php';
            markTopicsRead(array($user_info['id'], $topicOptions['id'], $modSettings['maxMsgID'], 0), false);
        }
    }
    // If there's a custom search index, it needs to be modified...
    require_once SUBSDIR . '/Search.subs.php';
    $searchAPI = findSearchAPI();
    if (is_callable(array($searchAPI, 'postModified'))) {
        $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
    }
    if (isset($msgOptions['subject'])) {
        // Only update the subject if this was the first message in the topic.
        $request = $db->query('', '
			SELECT id_topic
			FROM {db_prefix}topics
			WHERE id_first_msg = {int:id_first_msg}
			LIMIT 1', array('id_first_msg' => $msgOptions['id']));
        if ($db->num_rows($request) == 1) {
            updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
        }
        $db->free_result($request);
    }
    // Finally, if we are setting the approved state we need to do much more work :(
    if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
        approvePosts($msgOptions['id'], $msgOptions['approved']);
    }
    return true;
}
Ejemplo n.º 3
0
/**
 * Approve topics, all we got.
 *
 * @param int[] $topics array of topics ids
 * @param bool $approve = true
 */
function approveTopics($topics, $approve = true)
{
    $db = database();
    if (!is_array($topics)) {
        $topics = array($topics);
    }
    if (empty($topics)) {
        return false;
    }
    $approve_type = $approve ? 0 : 1;
    // Just get the messages to be approved and pass through...
    $request = $db->query('', '
		SELECT id_msg
		FROM {db_prefix}messages
		WHERE id_topic IN ({array_int:topic_list})
			AND approved = {int:approve_type}', array('topic_list' => $topics, 'approve_type' => $approve_type));
    $msgs = array();
    while ($row = $db->fetch_assoc($request)) {
        $msgs[] = $row['id_msg'];
    }
    $db->free_result($request);
    require_once SUBSDIR . '/Post.subs.php';
    return approvePosts($msgs, $approve);
}
Ejemplo n.º 4
0
function approveAllData()
{
    global $smcFunc, $sourcedir;
    // Start with messages and topics.
    $request = $smcFunc['db_query']('', '
		SELECT id_msg
		FROM {db_prefix}messages
		WHERE approved = {int:not_approved}', array('not_approved' => 0));
    $msgs = array();
    while ($row = $smcFunc['db_fetch_row']($request)) {
        $msgs[] = $row[0];
    }
    $smcFunc['db_free_result']($request);
    if (!empty($msgs)) {
        require_once $sourcedir . '/Subs-Post.php';
        approvePosts($msgs);
    }
    // Now do attachments
    $request = $smcFunc['db_query']('', '
		SELECT id_attach
		FROM {db_prefix}attachments
		WHERE approved = {int:not_approved}', array('not_approved' => 0));
    $attaches = array();
    while ($row = $smcFunc['db_fetch_row']($request)) {
        $attaches[] = $row[0];
    }
    $smcFunc['db_free_result']($request);
    if (!empty($attaches)) {
        require_once $sourcedir . '/ManageAttachments.php';
        ApproveAttachments($attaches);
    }
}
Ejemplo n.º 5
0
function approveAllData()
{
    global $sourcedir, $backend_subdir;
    // Start with messages and topics.
    $request = smf_db_query('
		SELECT id_msg
		FROM {db_prefix}messages
		WHERE approved = {int:not_approved}', array('not_approved' => 0));
    $msgs = array();
    while ($row = mysql_fetch_row($request)) {
        $msgs[] = $row[0];
    }
    mysql_free_result($request);
    if (!empty($msgs)) {
        require_once $sourcedir . '/lib/Subs-Post.php';
        approvePosts($msgs);
    }
    // Now do attachments
    $request = smf_db_query('
		SELECT id_attach
		FROM {db_prefix}attachments
		WHERE approved = {int:not_approved}', array('not_approved' => 0));
    $attaches = array();
    while ($row = mysql_fetch_row($request)) {
        $attaches[] = $row[0];
    }
    mysql_free_result($request);
    if (!empty($attaches)) {
        require_once $sourcedir . '/lib/Subs-ManageAttachments.php';
        ApproveAttachments($attaches);
    }
}
Ejemplo n.º 6
0
/**
 * This is a helper function: approve everything unapproved.
 * Used from moderation panel.
 */
function approveAllUnapproved()
{
    $db = database();
    // Start with messages and topics.
    $request = $db->query('', '
		SELECT id_msg
		FROM {db_prefix}messages
		WHERE approved = {int:not_approved}', array('not_approved' => 0));
    $msgs = array();
    while ($row = $db->fetch_row($request)) {
        $msgs[] = $row[0];
    }
    $db->free_result($request);
    if (!empty($msgs)) {
        require_once SUBSDIR . '/Post.subs.php';
        approvePosts($msgs);
        cache_put_data('num_menu_errors', null, 900);
    }
    // Now do attachments
    $request = $db->query('', '
		SELECT id_attach
		FROM {db_prefix}attachments
		WHERE approved = {int:not_approved}', array('not_approved' => 0));
    $attaches = array();
    while ($row = $db->fetch_row($request)) {
        $attaches[] = $row[0];
    }
    $db->free_result($request);
    if (!empty($attaches)) {
        require_once SUBSDIR . '/ManageAttachments.subs.php';
        approveAttachments($attaches);
        cache_put_data('num_menu_errors', null, 900);
    }
}
Ejemplo n.º 7
0
 /**
  * Approve a post, just the one.
  */
 public function action_approve()
 {
     global $user_info, $topic, $board;
     checkSession('get');
     $current_msg = (int) $_REQUEST['msg'];
     require_once SUBSDIR . '/Topic.subs.php';
     require_once SUBSDIR . '/Post.subs.php';
     require_once SUBSDIR . '/Messages.subs.php';
     isAllowedTo('approve_posts');
     $message_info = basicMessageInfo($current_msg, false, true);
     // If it's the first in a topic then the whole topic gets approved!
     if ($message_info['id_first_msg'] == $current_msg) {
         approveTopics($topic, !$message_info['approved']);
         if ($message_info['id_member_started'] != $user_info['id']) {
             logAction(($message_info['approved'] ? 'un' : '') . 'approve_topic', array('topic' => $topic, 'subject' => $message_info['subject'], 'member' => $message_info['id_member_started'], 'board' => $board));
         }
     } else {
         approvePosts($current_msg, !$message_info['approved']);
         if ($message_info['id_member'] != $user_info['id']) {
             logAction(($message_info['approved'] ? 'un' : '') . 'approve', array('topic' => $topic, 'subject' => $message_info['subject'], 'member' => $message_info['id_member'], 'board' => $board));
         }
     }
     cache_put_data('num_menu_errors', null, 900);
     redirectexit('topic=' . $topic . '.msg' . $current_msg . '#msg' . $current_msg);
 }