当前位置: 首页>>代码示例>>PHP>>正文


PHP updateLastMessages函数代码示例

本文整理汇总了PHP中updateLastMessages函数的典型用法代码示例。如果您正苦于以下问题:PHP updateLastMessages函数的具体用法?PHP updateLastMessages怎么用?PHP updateLastMessages使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了updateLastMessages函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: approvePosts


//.........这里部分代码省略.........
        } else {
            $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
            // This will be a post... but don't notify unless it's not followed by approved ones.
            if ($row['id_msg'] > $row['id_last_msg']) {
                $notification_posts[$row['id_topic']][] = array('id' => $row['id_msg'], 'body' => $row['body'], 'subject' => $row['subject'], 'name' => $row['poster_name'], 'topic' => $row['id_topic']);
            }
        }
        // If this is being approved and id_msg is higher than the current id_last_msg then it changes.
        if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
            $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
        } elseif (!$approve) {
            // Default to the first message and then we'll override in a bit ;)
            $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
        }
        $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
        $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
        $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
        // Post count for the user?
        if ($row['id_member'] && empty($row['count_posts'])) {
            $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
        }
    }
    $db->free_result($request);
    if (empty($msgs)) {
        return;
    }
    // Now we have the differences make the changes, first the easy one.
    $db->query('', '
		UPDATE {db_prefix}messages
		SET approved = {int:approved_state}
		WHERE id_msg IN ({array_int:message_list})', array('message_list' => $msgs, 'approved_state' => $approve ? 1 : 0));
    // If we were unapproving find the last msg in the topics...
    if (!$approve) {
        $request = $db->query('', '
			SELECT id_topic, MAX(id_msg) AS id_last_msg
			FROM {db_prefix}messages
			WHERE id_topic IN ({array_int:topic_list})
				AND approved = {int:approved}
			GROUP BY id_topic', array('topic_list' => $topics, 'approved' => 1));
        while ($row = $db->fetch_assoc($request)) {
            $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
        }
        $db->free_result($request);
    }
    // ... next the topics...
    foreach ($topic_changes as $id => $changes) {
        $db->query('', '
			UPDATE {db_prefix}topics
			SET
				approved = {int:approved},
				unapproved_posts = CASE WHEN unapproved_posts + {int:unapproved_posts} < 0 THEN 0 ELSE unapproved_posts + {int:unapproved_posts} END,
				num_replies = CASE WHEN num_replies + {int:num_replies} < 0 THEN 0 ELSE num_replies + {int:num_replies} END,
				id_last_msg = {int:id_last_msg}
			WHERE id_topic = {int:id_topic}', array('approved' => $changes['approved'], 'unapproved_posts' => $changes['unapproved_posts'], 'num_replies' => $changes['replies'], 'id_last_msg' => $changes['id_last_msg'], 'id_topic' => $id));
    }
    // ... finally the boards...
    foreach ($board_changes as $id => $changes) {
        $db->query('', '
			UPDATE {db_prefix}boards
			SET
				num_posts = num_posts + {int:num_posts},
				unapproved_posts = CASE WHEN unapproved_posts + {int:unapproved_posts} < 0 THEN 0 ELSE unapproved_posts + {int:unapproved_posts} END,
				num_topics = CASE WHEN num_topics + {int:num_topics} < 0 THEN 0 ELSE num_topics + {int:num_topics} END,
				unapproved_topics = CASE WHEN unapproved_topics + {int:unapproved_topics} < 0 THEN 0 ELSE unapproved_topics + {int:unapproved_topics} END
			WHERE id_board = {int:id_board}', array('num_posts' => $changes['posts'], 'unapproved_posts' => $changes['unapproved_posts'], 'num_topics' => $changes['topics'], 'unapproved_topics' => $changes['unapproved_topics'], 'id_board' => $id));
    }
    // Finally, least importantly, notifications!
    if ($approve) {
        require_once SUBSDIR . '/Notification.subs.php';
        if (!empty($notification_topics)) {
            sendBoardNotifications($notification_topics);
        }
        if (!empty($notification_posts)) {
            sendApprovalNotifications($notification_posts);
        }
        $db->query('', '
			DELETE FROM {db_prefix}approval_queue
			WHERE id_msg IN ({array_int:message_list})
				AND id_attach = {int:id_attach}', array('message_list' => $msgs, 'id_attach' => 0));
    } else {
        $msgInserts = array();
        foreach ($msgs as $msg) {
            $msgInserts[] = array($msg);
        }
        $db->insert('ignore', '{db_prefix}approval_queue', array('id_msg' => 'int'), $msgInserts, array('id_msg'));
    }
    if (!empty($modSettings['mentions_enabled'])) {
        require_once SUBSDIR . '/Mentions.subs.php';
        toggleMentionsApproval($msgs, $approve);
    }
    // Update the last messages on the boards...
    updateLastMessages(array_keys($board_changes));
    // Post count for the members?
    if (!empty($member_post_changes)) {
        foreach ($member_post_changes as $id_member => $count_change) {
            updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
        }
    }
    return true;
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:101,代码来源:Post.subs.php

示例2: QuickModeration


//.........这里部分代码省略.........
    // Approve the topics...
    if (!empty($approveCache)) {
        // We need unapproved topic ids and their authors!
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, id_member_started
			FROM {db_prefix}topics
			WHERE id_topic IN ({array_int:approve_topic_ids})
				AND approved = {int:not_approved}
			LIMIT ' . count($approveCache), array('approve_topic_ids' => $approveCache, 'not_approved' => 0));
        $approveCache = array();
        $approveCacheMembers = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $approveCache[] = $row['id_topic'];
            $approveCacheMembers[$row['id_topic']] = $row['id_member_started'];
        }
        $smcFunc['db_free_result']($request);
        // Any topics to approve?
        if (!empty($approveCache)) {
            // Handle the approval part...
            approveTopics($approveCache);
            // Time for some logging!
            foreach ($approveCache as $topic) {
                logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
            }
        }
    }
    // And (almost) lastly, lock the topics...
    if (!empty($lockCache)) {
        $lockStatus = array();
        // Gotta make sure they CAN lock/unlock these topics...
        if (!empty($board) && !allowedTo('lock_any')) {
            // Make sure they started the topic AND it isn't already locked by someone with higher priv's.
            $result = $smcFunc['db_query']('', '
				SELECT id_topic, locked, id_board
				FROM {db_prefix}topics
				WHERE id_topic IN ({array_int:locked_topic_ids})
					AND id_member_started = {int:current_member}
					AND locked IN (2, 0)
				LIMIT ' . count($lockCache), array('current_member' => $user_info['id'], 'locked_topic_ids' => $lockCache));
            $lockCache = array();
            $lockCacheBoards = array();
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                $lockCache[] = $row['id_topic'];
                $lockCacheBoards[$row['id_topic']] = $row['id_board'];
                $lockStatus[$row['id_topic']] = empty($row['locked']);
            }
            $smcFunc['db_free_result']($result);
        } else {
            $result = $smcFunc['db_query']('', '
				SELECT id_topic, locked, id_board
				FROM {db_prefix}topics
				WHERE id_topic IN ({array_int:locked_topic_ids})
				LIMIT ' . count($lockCache), array('locked_topic_ids' => $lockCache));
            $lockCacheBoards = array();
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                $lockStatus[$row['id_topic']] = empty($row['locked']);
                $lockCacheBoards[$row['id_topic']] = $row['id_board'];
            }
            $smcFunc['db_free_result']($result);
        }
        // It could just be that *none* were their own topics...
        if (!empty($lockCache)) {
            // Alternate the locked value.
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}topics
				SET locked = CASE WHEN locked = {int:is_locked} THEN ' . (allowedTo('lock_any') ? '1' : '2') . ' ELSE 0 END
				WHERE id_topic IN ({array_int:locked_topic_ids})', array('locked_topic_ids' => $lockCache, 'is_locked' => 0));
        }
    }
    if (!empty($markCache)) {
        $markArray = array();
        foreach ($markCache as $topic) {
            $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic);
        }
        $smcFunc['db_insert']('replace', '{db_prefix}log_topics', array('id_msg' => 'int', 'id_member' => 'int', 'id_topic' => 'int'), $markArray, array('id_member', 'id_topic'));
    }
    foreach ($moveCache as $topic) {
        // Didn't actually move anything!
        if (!isset($topic[0])) {
            break;
        }
        logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
        sendNotifications($topic[0], 'move');
    }
    foreach ($lockCache as $topic) {
        logAction($lockStatus[$topic] ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $lockCacheBoards[$topic]));
        sendNotifications($topic, $lockStatus[$topic] ? 'lock' : 'unlock');
    }
    foreach ($stickyCache as $topic) {
        logAction($stickyCacheStatus[$topic] ? 'unsticky' : 'sticky', array('topic' => $topic, 'board' => $stickyCacheBoards[$topic]));
        sendNotifications($topic, 'sticky');
    }
    updateStats('topic');
    updateStats('message');
    updateSettings(array('calendar_updated' => time()));
    if (!empty($affectedBoards)) {
        updateLastMessages(array_keys($affectedBoards));
    }
    redirectexit($redirect_url);
}
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:101,代码来源:MessageIndex.php

示例3: move_topic

function move_topic($topic, $board, $newboard, $topicinfo)
{
    global $mobdb;
    // Move the topic and fix the stats
    $mobdb->query('
        UPDATE {db_prefix}topics
        SET ID_BOARD = {int:board}
        WHERE ID_TOPIC = {int:topic}', array('board' => $newboard['id_board'], 'topic' => $topic));
    $mobdb->query('
        UPDATE {db_prefix}calendar
        SET ID_BOARD = {int:board}
        WHERE ID_TOPIC = {int:topic}', array('topic' => $topic, 'board' => $newboard['id_board']));
    $mobdb->query('
        UPDATE {db_prefix}messages
        SET ID_BOARD = {int:board}
        WHERE ID_TOPIC = {int:topic}', array('board' => $newboard['id_board'], 'topic' => $topic));
    $mobdb->query('
        UPDATE {db_prefix}boards
        SET numPosts = numPosts + {int:new_posts},
            numTopics = numTopics + 1
        WHERE ID_BOARD = {int:board}', array('new_posts' => $topicinfo['replies'] + 1, 'board' => $newboard['id_board']));
    $mobdb->query('
        UPDATE {db_prefix}boards
        SET numPosts = numPosts - {int:new_posts},
            numTopics = numTopics - 1
        WHERE ID_BOARD = {int:board}', array('new_posts' => $topicinfo['replies'] + 1, 'board' => $board));
    // Update the last messages
    updateLastMessages(array($board, $newboard['id_board']));
}
开发者ID:keweiliu6,项目名称:test_smf1,代码行数:29,代码来源:Subs-Mobiquo.php

示例4: MergeExecute


//.........这里部分代码省略.........
    // Determine the subject of the newly merged topic - was a custom subject specified?
    if (empty($_POST['subject']) && isset($_POST['custom_subject']) && $_POST['custom_subject'] != '') {
        $target_subject = $func['htmlspecialchars']($_POST['custom_subject']);
    } elseif (!empty($topic_data[(int) $_POST['subject']]['subject'])) {
        $target_subject = addslashes($topic_data[(int) $_POST['subject']]['subject']);
    } else {
        $target_subject = addslashes($topic_data[$firstTopic]['subject']);
    }
    // Get the first and last message and the number of messages....
    $request = db_query("\n\t\tSELECT MIN(ID_MSG), MAX(ID_MSG), COUNT(ID_MSG) - 1\n\t\tFROM {$db_prefix}messages\n\t\tWHERE ID_TOPIC IN (" . implode(', ', $topics) . ")", __FILE__, __LINE__);
    list($first_msg, $last_msg, $num_replies) = mysql_fetch_row($request);
    mysql_free_result($request);
    // Get the member ID of the first and last message.
    $request = db_query("\n\t\tSELECT ID_MEMBER\n\t\tFROM {$db_prefix}messages\n\t\tWHERE ID_MSG IN ({$first_msg}, {$last_msg})\n\t\tORDER BY ID_MSG\n\t\tLIMIT 2", __FILE__, __LINE__);
    list($member_started) = mysql_fetch_row($request);
    list($member_updated) = mysql_fetch_row($request);
    mysql_free_result($request);
    // Assign the first topic ID to be the merged topic.
    $ID_TOPIC = min($topics);
    // Delete the remaining topics.
    $deleted_topics = array_diff($topics, array($ID_TOPIC));
    db_query("\n\t\tDELETE FROM {$db_prefix}topics\n\t\tWHERE ID_TOPIC IN (" . implode(', ', $deleted_topics) . ")\n\t\tLIMIT " . count($deleted_topics), __FILE__, __LINE__);
    db_query("\n\t\tDELETE FROM {$db_prefix}log_search_subjects\n\t\tWHERE ID_TOPIC IN (" . implode(', ', $deleted_topics) . ")", __FILE__, __LINE__);
    // Asssign the properties of the newly merged topic.
    db_query("\n\t\tUPDATE {$db_prefix}topics\n\t\tSET\n\t\t\tID_BOARD = {$target_board},\n\t\t\tID_MEMBER_STARTED = {$member_started},\n\t\t\tID_MEMBER_UPDATED = {$member_updated},\n\t\t\tID_FIRST_MSG = {$first_msg},\n\t\t\tID_LAST_MSG = {$last_msg},\n\t\t\tID_POLL = {$target_poll},\n\t\t\tnumReplies = {$num_replies},\n\t\t\tnumViews = {$num_views},\n\t\t\tisSticky = {$isSticky}\n\t\tWHERE ID_TOPIC = {$ID_TOPIC}\n\t\tLIMIT 1", __FILE__, __LINE__);
    // Grab the response prefix (like 'Re: ') in the default forum language.
    if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) {
        if ($language === $user_info['language']) {
            $context['response_prefix'] = $txt['response_prefix'];
        } else {
            loadLanguage('index', $language, false);
            $context['response_prefix'] = $txt['response_prefix'];
            loadLanguage('index');
        }
        cache_put_data('response_prefix', $context['response_prefix'], 600);
    }
    // Change the topic IDs of all messages that will be merged.  Also adjust subjects if 'enforce subject' was checked.
    db_query("\n\t\tUPDATE {$db_prefix}messages\n\t\tSET\n\t\t\tID_TOPIC = {$ID_TOPIC},\n\t\t\tID_BOARD = {$target_board}" . (!empty($_POST['enforce_subject']) ? ",\n\t\t\tsubject = '{$context['response_prefix']}{$target_subject}'" : '') . "\n\t\tWHERE ID_TOPIC IN (" . implode(', ', $topics) . ")", __FILE__, __LINE__);
    // Change the subject of the first message...
    db_query("\n\t\tUPDATE {$db_prefix}messages\n\t\tSET subject = '{$target_subject}'\n\t\tWHERE ID_MSG = {$first_msg}\n\t\tLIMIT 1", __FILE__, __LINE__);
    // Adjust all calendar events to point to the new topic.
    db_query("\n\t\tUPDATE {$db_prefix}calendar\n\t\tSET\n\t\t\tID_TOPIC = {$ID_TOPIC},\n\t\t\tID_BOARD = {$target_board}\n\t\tWHERE ID_TOPIC IN (" . implode(', ', $deleted_topics) . ")", __FILE__, __LINE__);
    // Merge log topic entries.
    $request = db_query("\n\t\tSELECT ID_MEMBER, MIN(ID_MSG) AS new_ID_MSG\n\t\tFROM {$db_prefix}log_topics\n\t\tWHERE ID_TOPIC IN (" . implode(', ', $topics) . ")\n\t\tGROUP BY ID_MEMBER", __FILE__, __LINE__);
    if (mysql_num_rows($request) > 0) {
        $replaceEntries = array();
        while ($row = mysql_fetch_assoc($request)) {
            $replaceEntries[] = "({$row['ID_MEMBER']}, {$ID_TOPIC}, {$row['new_ID_MSG']})";
        }
        db_query("\n\t\t\tREPLACE INTO {$db_prefix}log_topics\n\t\t\t\t(ID_MEMBER, ID_TOPIC, ID_MSG)\n\t\t\tVALUES " . implode(', ', $replaceEntries), __FILE__, __LINE__);
        unset($replaceEntries);
        // Get rid of the old log entries.
        db_query("\n\t\t\tDELETE FROM {$db_prefix}log_topics\n\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $deleted_topics) . ")", __FILE__, __LINE__);
    }
    mysql_free_result($request);
    // Merge topic notifications.
    if (!empty($_POST['notifications']) && is_array($_POST['notifications'])) {
        // Check if the notification array contains valid topics.
        if (count(array_diff($_POST['notifications'], $topics)) > 0) {
            fatal_lang_error('smf232');
        }
        $request = db_query("\n\t\t\tSELECT ID_MEMBER, MAX(sent) AS sent\n\t\t\tFROM {$db_prefix}log_notify\n\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $_POST['notifications']) . ")\n\t\t\tGROUP BY ID_MEMBER", __FILE__, __LINE__);
        if (mysql_num_rows($request) > 0) {
            $replaceEntries = array();
            while ($row = mysql_fetch_assoc($request)) {
                $replaceEntries[] = "({$row['ID_MEMBER']}, {$ID_TOPIC}, 0, {$row['sent']})";
            }
            db_query("\n\t\t\t\tREPLACE INTO {$db_prefix}log_notify\n\t\t\t\t\t(ID_MEMBER, ID_TOPIC, ID_BOARD, sent)\n\t\t\t\tVALUES " . implode(', ', $replaceEntries), __FILE__, __LINE__);
            unset($replaceEntries);
            db_query("\n\t\t\t\tDELETE FROM {$db_prefix}log_topics\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $deleted_topics) . ")", __FILE__, __LINE__);
        }
        mysql_free_result($request);
    }
    // Get rid of the redundant polls.
    if (!empty($deleted_polls)) {
        db_query("\n\t\t\tDELETE FROM {$db_prefix}polls\n\t\t\tWHERE ID_POLL IN (" . implode(', ', $deleted_polls) . ")\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        db_query("\n\t\t\tDELETE FROM {$db_prefix}poll_choices\n\t\t\tWHERE ID_POLL IN (" . implode(', ', $deleted_polls) . ")", __FILE__, __LINE__);
        db_query("\n\t\t\tDELETE FROM {$db_prefix}log_polls\n\t\t\tWHERE ID_POLL IN (" . implode(', ', $deleted_polls) . ")", __FILE__, __LINE__);
    }
    // Fix the board totals.
    if (count($boards) > 1) {
        $request = db_query("\n\t\t\tSELECT ID_BOARD, COUNT(*) AS numTopics, SUM(numReplies) + COUNT(*) AS numPosts\n\t\t\tFROM {$db_prefix}topics\n\t\t\tWHERE ID_BOARD IN (" . implode(', ', $boards) . ")\n\t\t\tGROUP BY ID_BOARD\n\t\t\tLIMIT " . count($boards), __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($request)) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\tSET\n\t\t\t\t\tnumPosts = {$row['numPosts']},\n\t\t\t\t\tnumTopics = {$row['numTopics']}\n\t\t\t\tWHERE ID_BOARD = {$row['ID_BOARD']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
        mysql_free_result($request);
    } else {
        db_query("\n\t\t\tUPDATE {$db_prefix}boards\n\t\t\tSET numTopics = IF(" . (count($topics) - 1) . " > numTopics, 0, numTopics - " . (count($topics) - 1) . ")\n\t\t\tWHERE ID_BOARD = {$target_board}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
    }
    require_once $sourcedir . '/Subs-Post.php';
    // Update all the statistics.
    updateStats('topic');
    updateStats('subject', $ID_TOPIC, $target_subject);
    updateLastMessages($boards);
    logAction('merge', array('topic' => $ID_TOPIC));
    // Notify people that these topics have been merged?
    sendNotifications($ID_TOPIC, 'merge');
    // Send them to the all done page.
    redirectexit('action=mergetopics;sa=done;to=' . $ID_TOPIC . ';targetboard=' . $target_board);
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:101,代码来源:SplitTopics.php

示例5: MergeExecute


//.........这里部分代码省略.........
    // Change the subject of the first message...
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}messages
		SET subject = {string:target_subject}
		WHERE id_msg = {int:first_msg}', array('first_msg' => $first_msg, 'target_subject' => $target_subject));
    // Adjust all calendar events to point to the new topic.
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}calendar
		SET
			id_topic = {int:id_topic},
			id_board = {int:target_board}
		WHERE id_topic IN ({array_int:deleted_topics})', array('deleted_topics' => $deleted_topics, 'id_topic' => $id_topic, 'target_board' => $target_board));
    // Merge log topic entries.
    $request = $smcFunc['db_query']('', '
		SELECT id_member, MIN(id_msg) AS new_id_msg
		FROM {db_prefix}log_topics
		WHERE id_topic IN ({array_int:topics})
		GROUP BY id_member', array('topics' => $topics));
    if ($smcFunc['db_num_rows']($request) > 0) {
        $replaceEntries = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $replaceEntries[] = array($row['id_member'], $id_topic, $row['new_id_msg']);
        }
        $smcFunc['db_insert']('replace', '{db_prefix}log_topics', array('id_member' => 'int', 'id_topic' => 'int', 'id_msg' => 'int'), $replaceEntries, array('id_member', 'id_topic'));
        unset($replaceEntries);
        // Get rid of the old log entries.
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}log_topics
			WHERE id_topic IN ({array_int:deleted_topics})', array('deleted_topics' => $deleted_topics));
    }
    $smcFunc['db_free_result']($request);
    // Merge topic notifications.
    $notifications = isset($_POST['notifications']) && is_array($_POST['notifications']) ? array_intersect($topics, $_POST['notifications']) : array();
    if (!empty($notifications)) {
        $request = $smcFunc['db_query']('', '
			SELECT id_member, MAX(sent) AS sent
			FROM {db_prefix}log_notify
			WHERE id_topic IN ({array_int:topics_list})
			GROUP BY id_member', array('topics_list' => $notifications));
        if ($smcFunc['db_num_rows']($request) > 0) {
            $replaceEntries = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $replaceEntries[] = array($row['id_member'], $id_topic, 0, $row['sent']);
            }
            $smcFunc['db_insert']('replace', '{db_prefix}log_notify', array('id_member' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'sent' => 'int'), $replaceEntries, array('id_member', 'id_topic', 'id_board'));
            unset($replaceEntries);
            $smcFunc['db_query']('', '
				DELETE FROM {db_prefix}log_topics
				WHERE id_topic IN ({array_int:deleted_topics})', array('deleted_topics' => $deleted_topics));
        }
        $smcFunc['db_free_result']($request);
    }
    // Get rid of the redundant polls.
    if (!empty($deleted_polls)) {
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}polls
			WHERE id_poll IN ({array_int:deleted_polls})', array('deleted_polls' => $deleted_polls));
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}poll_choices
			WHERE id_poll IN ({array_int:deleted_polls})', array('deleted_polls' => $deleted_polls));
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}log_polls
			WHERE id_poll IN ({array_int:deleted_polls})', array('deleted_polls' => $deleted_polls));
    }
    // Cycle through each board...
    foreach ($boardTotals as $id_board => $stats) {
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}boards
			SET
				num_topics = CASE WHEN {int:topics} > num_topics THEN 0 ELSE num_topics - {int:topics} END,
				unapproved_topics = CASE WHEN {int:unapproved_topics} > unapproved_topics THEN 0 ELSE unapproved_topics - {int:unapproved_topics} END,
				num_posts = CASE WHEN {int:posts} > num_posts THEN 0 ELSE num_posts - {int:posts} END,
				unapproved_posts = CASE WHEN {int:unapproved_posts} > unapproved_posts THEN 0 ELSE unapproved_posts - {int:unapproved_posts} END
			WHERE id_board = {int:id_board}', array('id_board' => $id_board, 'topics' => $stats['topics'], 'unapproved_topics' => $stats['unapproved_topics'], 'posts' => $stats['posts'], 'unapproved_posts' => $stats['unapproved_posts']));
    }
    // Determine the board the final topic resides in
    $request = $smcFunc['db_query']('', '
		SELECT id_board
		FROM {db_prefix}topics
		WHERE id_topic = {int:id_topic}
		LIMIT 1', array('id_topic' => $id_topic));
    list($id_board) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    require_once $sourcedir . '/Subs-Post.php';
    // Update all the statistics.
    updateStats('topic');
    updateStats('subject', $id_topic, $target_subject);
    updateLastMessages($boards);
    logAction('merge', array('topic' => $id_topic, 'board' => $id_board));
    // Notify people that these topics have been merged?
    sendNotifications($id_topic, 'merge');
    // If there's a search index that needs updating, update it...
    require_once $sourcedir . '/Search.php';
    $searchAPI = findSearchAPI();
    if (is_callable(array($searchAPI, 'topicMerge'))) {
        $searchAPI->topicMerge($id_topic, $topics, $affected_msgs, empty($_POST['enforce_subject']) ? null : array($context['response_prefix'], $target_subject));
    }
    // Send them to the all done page.
    redirectexit('action=mergetopics;sa=done;to=' . $id_topic . ';targetboard=' . $target_board);
}
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:101,代码来源:SplitTopics.php

示例6: mergePosts


//.........这里部分代码省略.........
        if (!$row['approved']) {
            $target_topic_data['unapproved_posts'] = $row['message_count'];
        } else {
            $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
        }
    }
    $smcFunc['db_free_result']($request);
    // We have a new post count for the board.
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}boards
		SET
			num_posts = num_posts + {int:diff_replies},
			unapproved_posts = unapproved_posts + {int:diff_unapproved_posts}
		WHERE id_board = {int:target_board}', array('diff_replies' => $target_topic_data['num_replies'] - $target_replies, 'diff_unapproved_posts' => $target_topic_data['unapproved_posts'] - $target_unapproved_posts, 'target_board' => $target_board));
    // In some cases we merged the only post in a topic so the topic data is left behind in the topic table.
    $request = $smcFunc['db_query']('', '
		SELECT id_topic
		FROM {db_prefix}messages
		WHERE id_topic = {int:from_topic}', array('from_topic' => $from_topic));
    // Remove the topic if it doesn't have any messages.
    $topic_exists = true;
    if ($smcFunc['db_num_rows']($request) == 0) {
        removeTopics($from_topic, false, true);
        $topic_exists = false;
    }
    $smcFunc['db_free_result']($request);
    // Recycled topic.
    if ($topic_exists == true) {
        // Fix the id_first_msg and id_last_msg for the source topic.
        $source_topic_data = array('num_replies' => 0, 'unapproved_posts' => 0, 'id_first_msg' => 9999999999);
        $request = $smcFunc['db_query']('', '
			SELECT MIN(id_msg) AS id_first_msg, MAX(id_msg) AS id_last_msg, COUNT(*) AS message_count, approved, subject
			FROM {db_prefix}messages
			WHERE id_topic = {int:from_topic}
			GROUP BY id_topic, approved
			ORDER BY approved ASC
			LIMIT 2', array('from_topic' => $from_topic));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
                $source_topic_data['id_first_msg'] = $row['id_first_msg'];
            }
            $source_topic_data['id_last_msg'] = $row['id_last_msg'];
            if (!$row['approved']) {
                $source_topic_data['unapproved_posts'] = $row['message_count'];
            } else {
                $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
            }
        }
        $smcFunc['db_free_result']($request);
        // Update the topic details for the source topic.
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}topics
			SET
				id_first_msg = {int:id_first_msg},
				id_last_msg = {int:id_last_msg},
				num_replies = {int:num_replies},
				unapproved_posts = {int:unapproved_posts}
			WHERE id_topic = {int:from_topic}', array('id_first_msg' => $source_topic_data['id_first_msg'], 'id_last_msg' => $source_topic_data['id_last_msg'], 'num_replies' => $source_topic_data['num_replies'], 'unapproved_posts' => $source_topic_data['unapproved_posts'], 'from_topic' => $from_topic));
        // We have a new post count for the source board.
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}boards
			SET
				num_posts = num_posts + {int:diff_replies},
				unapproved_posts = unapproved_posts + {int:diff_unapproved_posts}
			WHERE id_board = {int:from_board}', array('diff_replies' => $source_topic_data['num_replies'] - $from_replies, 'diff_unapproved_posts' => $source_topic_data['unapproved_posts'] - $from_unapproved_posts, 'from_board' => $from_board));
    }
    // Finally get around to updating the destination topic, now all indexes etc on the source are fixed.
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}topics
		SET
			id_first_msg = {int:id_first_msg},
			id_last_msg = {int:id_last_msg},
			num_replies = {int:num_replies},
			unapproved_posts = {int:unapproved_posts}
		WHERE id_topic = {int:target_topic}', array('id_first_msg' => $target_topic_data['id_first_msg'], 'id_last_msg' => $target_topic_data['id_last_msg'], 'num_replies' => $target_topic_data['num_replies'], 'unapproved_posts' => $target_topic_data['unapproved_posts'], 'target_topic' => $target_topic));
    // Need it to update some stats.
    require_once $sourcedir . '/Subs-Post.php';
    // Update stats.
    updateStats('topic');
    updateStats('message');
    // Subject cache?
    $cache_updates = array();
    if ($target_first_msg != $target_topic_data['id_first_msg']) {
        $cache_updates[] = $target_topic_data['id_first_msg'];
    }
    if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
        $cache_updates[] = $source_topic_data['id_first_msg'];
    }
    if (!empty($cache_updates)) {
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, subject
			FROM {db_prefix}messages
			WHERE id_msg IN ({array_int:first_messages})', array('first_messages' => $cache_updates));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            updateStats('subject', $row['id_topic'], $row['subject']);
        }
        $smcFunc['db_free_result']($request);
    }
    updateLastMessages(array($from_board, $target_board));
}
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:101,代码来源:RemoveTopic.php

示例7: CopyTopics


//.........这里部分代码省略.........
    unset($fix, $row);
    // --- Fix some stats and logs ---
    // Fix id_msg_modified to the New id_msg
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}messages
		SET id_msg_modified = id_msg
		WHERE id_topic = {int:topic_id}', array('topic_id' => $topic_id));
    // Grab First & Last Message Id
    $request = $smcFunc['db_query']('', '
		SELECT max(id_msg) as last, min(id_msg) as first
		FROM {db_prefix}messages
		WHERE id_topic = {int:topic_id}', array('topic_id' => $topic_id));
    $row = $smcFunc['db_fetch_assoc']($request);
    // Update the topic info with that info
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}topics
		SET id_first_msg = {int:first}, id_last_msg = {int:last}
		WHERE id_topic = {int:topic_id}', array('topic_id' => $topic_id, 'first' => $row['first'], 'last' => $row['last']));
    // Update log topics (for this user only)
    $smcFunc['db_query']('', '
		REPLACE
		INTO {db_prefix}log_topics
			(id_topic, id_member, id_msg)
		VALUES ({int:topic_id}, {int:user_id}, {int:last})
		', array('topic_id' => $topic_id, 'last' => $row['last'], 'user_id' => $context['user']['id']));
    // Update log boards (for this user only)
    $smcFunc['db_query']('', '
		REPLACE
		INTO {db_prefix}log_boards
			(id_board, id_member, id_msg)
		VALUES ({int:board_id}, {int:user_id}, {int:last})
		', array('board_id' => $board_id, 'last' => $row['last'], 'user_id' => $context['user']['id']));
    require_once $sourcedir . '/Subs-Post.php';
    updateLastMessages($board_id, $row['last']);
    // --- Fix Post Counts ---
    // Posts in the board we're copying the topic to count, so we need to get the figures for each
    if ($count_posts) {
        // Increase the stats for the board
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}boards
			SET num_posts = num_posts + {int:num_posts}, num_topics = num_topics + 1
			WHERE id_board = {int:board_id}
			', array('board_id' => $board_id, 'num_posts' => $num_posts));
        // How many posts have been made by each user in the copied topic?
        $request = $smcFunc['db_query']('', '
			SELECT count(*) as increase, id_member
			FROM {db_prefix}messages
			WHERE id_topic = {int:topic_id}
				AND id_member > 0
			GROUP BY id_member
			', array('topic_id' => $topic_id));
        // Any members to update (non-guests);
        if ($smcFunc['db_num_rows']($request) != 0) {
            $members = $increase = array();
            // Prepare the information in arrays for easy update
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $increase[$row['id_member']] = $row['increase'];
                // Store the member ids, as we will need to Update PostGroups
                if (!in_array($row['id_member'], $members)) {
                    $members[] = $row['id_member'];
                }
            }
            // Update each users postcount accordingly.  Could add significant number of queries for large topics.
            foreach ($increase as $a => $b) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}members
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:67,代码来源:CopyTopic.php

示例8: shd_topictoticket2


//.........这里部分代码省略.........
        // The ID of the ticket we created
        $ticket = $ticketOptions['id'];
        if ($smcFunc['db_num_rows']($request) != 0) {
            // Now loop through each reply and post it.  Hopefully there aren't too many. *looks at clock*
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $msgOptions = array('body' => $row['body'], 'smileys_enabled' => !empty($row['smileys_enabled']) ? 1 : 0);
                $ticketOptions = array('id' => $ticket, 'mark_as_read' => false);
                $posterOptions = array('id' => $row['id_member'], 'name' => !empty($row['poster_name']) ? $row['poster_name'] : '', 'email' => !empty($row['poster_email']) ? $row['poster_email'] : '', 'ip' => !empty($row['poster_ip']) ? $row['poster_ip'] : '');
                shd_create_ticket_post($msgOptions, $ticketOptions, $posterOptions);
                $msg_assoc[$row['id_msg']] = $msgOptions['id'];
            }
        }
        // Ticket: check; Replies: check; Notfiy the topic starter, if desired.
        if (isset($_POST['send_pm'])) {
            require_once $sourcedir . '/Subs-Post.php';
            $request = shd_db_query('pm_find_username', '
				SELECT id_member, real_name
				FROM {db_prefix}members
				WHERE id_member = {int:user}
				LIMIT 1', array('user' => $owner));
            list($userid, $username) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            // Fix the content
            $replacements = array('{user}' => $username, '{subject}' => $old_subject, '{link}' => $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $ticket);
            $message = str_replace(array_keys($replacements), array_values($replacements), $_POST['pm_content']);
            $recipients = array('to' => array($owner), 'bcc' => array());
            sendpm($recipients, $txt['shd_ticket_moved_subject_topic'], un_htmlspecialchars($message));
        }
        // And now for something completely different: attachments
        if (!empty($msg_assoc)) {
            // 1. Get all the attachments for these messages from the attachments table
            $attachIDs = array();
            $query = shd_db_query('', '
				SELECT id_attach, id_msg
				FROM {db_prefix}attachments
				WHERE id_msg IN ({array_int:smf_msgs})', array('smf_msgs' => array_keys($msg_assoc)));
            while ($row = $smcFunc['db_fetch_assoc']($query)) {
                $attachIDs[] = $row;
            }
            $smcFunc['db_free_result']($query);
            if (!empty($attachIDs)) {
                // 2. Do the switch
                // 2.1. Add them to SD's tables
                $array = array();
                foreach ($attachIDs as $attach) {
                    $array[] = array($attach['id_attach'], $ticket, $msg_assoc[$attach['id_msg']]);
                }
                $smcFunc['db_insert']('replace', '{db_prefix}helpdesk_attachments', array('id_attach' => 'int', 'id_ticket' => 'int', 'id_msg' => 'int'), $array, array('id_attach'));
                // 2.2. "Remove" them from SMF's table
                shd_db_query('', '
					UPDATE {db_prefix}attachments
					SET id_msg = 0
					WHERE id_msg IN ({array_int:smf_msgs})', array('smf_msgs' => array_keys($msg_assoc)));
            }
        }
        // Now we'll add this to the log.
        $log_params = array('subject' => $subject, 'ticket' => $ticket);
        shd_log_action('topictoticket', $log_params);
        // Update post counts.
        $request = shd_db_query('', '
			SELECT id_member
			FROM {db_prefix}messages
			WHERE id_topic = {int:topic}', array('topic' => $context['topic_id']));
        $posters = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (!isset($posters[$row['id_member']])) {
                $posters[$row['id_member']] = 0;
            }
            $posters[$row['id_member']]++;
        }
        $smcFunc['db_free_result']($request);
        foreach ($posters as $id_member => $posts) {
            updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
        }
        // Lastly, delete the topic from the database.
        shd_db_query('', '
			DELETE FROM {db_prefix}topics
			WHERE id_topic = {int:topic}
			LIMIT 1', array('topic' => $context['topic_id']));
        // And the replies, too.
        shd_db_query('', '
			DELETE FROM {db_prefix}messages
			WHERE id_topic = {int:topic}', array('topic' => $context['topic_id']));
        // Update the stats.
        require_once $sourcedir . '/Subs-Post.php';
        updateStats('message');
        updateStats('topic');
        updateLastMessages($board);
        // Update board post counts.
        shd_db_query('', '
			UPDATE {db_prefix}boards
			SET num_topics = num_topics - 1,
				num_posts = num_posts - {int:num_posts}
			WHERE id_board = {int:board}', array('board' => $board, 'num_posts' => $num_replies));
    } else {
        fatal_lang_error('shd_move_ticket_not_created', false);
    }
    // Send them to the ticket.
    redirectexit('action=helpdesk;sa=ticket;ticket=' . $ticket);
}
开发者ID:wintstar,项目名称:Testing,代码行数:101,代码来源:SimpleDesk-TicketTopicMove.php

示例9: removeMessage


//.........这里部分代码省略.........
                require_once SUBSDIR . '/Boards.subs.php';
                markBoardsRead($modSettings['recycle_board']);
            }
            // Add one topic and post to the recycle bin board.
            $db->query('', '
				UPDATE {db_prefix}boards
				SET
					num_topics = num_topics + {int:num_topics_inc},
					num_posts = num_posts + 1' . ($message > $last_board_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . '
				WHERE id_board = {int:recycle_board}', array('num_topics_inc' => empty($id_recycle_topic) ? 1 : 0, 'recycle_board' => $modSettings['recycle_board'], 'id_merged_msg' => $message));
            // Lets increase the num_replies, and the first/last message ID as appropriate.
            if (!empty($id_recycle_topic)) {
                $db->query('', '
					UPDATE {db_prefix}topics
					SET num_replies = num_replies + 1' . ($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . ($message < $first_topic_msg ? ', id_first_msg = {int:id_merged_msg}' : '') . '
					WHERE id_topic = {int:id_recycle_topic}', array('id_recycle_topic' => $id_recycle_topic, 'id_merged_msg' => $message));
            }
            // Make sure this message isn't getting deleted later on.
            $recycle = true;
            // Make sure we update the search subject index.
            updateSubjectStats($topicID, $row['subject']);
        }
        // If it wasn't approved don't keep it in the queue.
        if (!$row['approved']) {
            $db->query('', '
				DELETE FROM {db_prefix}approval_queue
				WHERE id_msg = {int:id_msg}
					AND id_attach = {int:id_attach}', array('id_msg' => $message, 'id_attach' => 0));
        }
    }
    $db->query('', '
		UPDATE {db_prefix}boards
		SET ' . ($row['approved'] ? '
			num_posts = CASE WHEN num_posts = {int:no_posts} THEN 0 ELSE num_posts - 1 END' : '
			unapproved_posts = CASE WHEN unapproved_posts = {int:no_unapproved} THEN 0 ELSE unapproved_posts - 1 END') . '
		WHERE id_board = {int:id_board}', array('no_posts' => 0, 'no_unapproved' => 0, 'id_board' => $row['id_board']));
    // If the poster was registered and the board this message was on incremented
    // the member's posts when it was posted, decrease his or her post count.
    if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
        updateMemberData($row['id_member'], array('posts' => '-'));
    }
    // Only remove posts if they're not recycled.
    if (!$recycle) {
        // Remove the likes!
        $db->query('', '
			DELETE FROM {db_prefix}message_likes
			WHERE id_msg = {int:id_msg}', array('id_msg' => $message));
        // Remove the mentions!
        $db->query('', '
			DELETE FROM {db_prefix}log_mentions
			WHERE id_msg = {int:id_msg}', array('id_msg' => $message));
        // Remove the message!
        $db->query('', '
			DELETE FROM {db_prefix}messages
			WHERE id_msg = {int:id_msg}', array('id_msg' => $message));
        if (!empty($modSettings['search_custom_index_config'])) {
            $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
            $words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
            if (!empty($words)) {
                $db->query('', '
					DELETE FROM {db_prefix}log_search_words
					WHERE id_word IN ({array_int:word_list})
						AND id_msg = {int:id_msg}', array('word_list' => $words, 'id_msg' => $message));
            }
        }
        // Delete attachment(s) if they exist.
        require_once SUBSDIR . '/ManageAttachments.subs.php';
        $attachmentQuery = array('attachment_type' => 0, 'id_msg' => $message);
        removeAttachments($attachmentQuery);
        // Delete follow-ups too
        require_once SUBSDIR . '/FollowUps.subs.php';
        // If it is an entire topic
        if ($row['id_first_msg'] == $message) {
            $db->query('', '
				DELETE FROM {db_prefix}follow_ups
				WHERE follow_ups IN ({array_int:topics})', array('topics' => $row['id_topic']));
        }
        // Allow mods to remove message related data of their own (likes, maybe?)
        call_integration_hook('integrate_remove_message', array($message));
    }
    // Update the pesky statistics.
    updateMessageStats();
    updateStats('topic');
    updateSettings(array('calendar_updated' => time()));
    // And now to update the last message of each board we messed with.
    require_once SUBSDIR . '/Post.subs.php';
    if ($recycle) {
        updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
    } else {
        updateLastMessages($row['id_board']);
    }
    // Close any moderation reports for this message.
    require_once SUBSDIR . '/Moderation.subs.php';
    $updated_reports = updateReportsStatus($message, 'close', 1);
    if ($updated_reports != 0) {
        updateSettings(array('last_mod_report_action' => time()));
        recountOpenReports();
    }
    return false;
}
开发者ID:Ralkage,项目名称:Elkarte,代码行数:101,代码来源:Messages.subs.php

示例10: removeMessage


//.........这里部分代码省略.........
                fatal_lang_error('cannot_remove_own');
            }
        } else {
            // Check permissions to delete a whole topic.
            if ($row['ID_MEMBER'] != $ID_MEMBER) {
                isAllowedTo('remove_any');
            } elseif (!allowedTo('remove_any')) {
                isAllowedTo('remove_own');
            }
        }
        // ...if there is only one post.
        if (!empty($row['numReplies'])) {
            fatal_lang_error('delFirstPost', false);
        }
        removeTopics($row['ID_TOPIC']);
        return true;
    }
    // Default recycle to false.
    $recycle = false;
    // If recycle topics has been set, make a copy of this message in the recycle board.
    // Make sure we're not recycling messages that are already on the recycle board.
    if (!empty($modSettings['recycle_enable']) && $row['ID_BOARD'] != $modSettings['recycle_board'] && $row['icon'] != 'recycled') {
        // Check if the recycle board exists and if so get the read status.
        $request = db_query("\n\t\t\tSELECT (IFNULL(lb.ID_MSG, 0) >= b.ID_MSG_UPDATED) AS isSeen\n\t\t\tFROM {$db_prefix}boards AS b\n\t\t\t\tLEFT JOIN {$db_prefix}log_boards AS lb ON (lb.ID_BOARD = b.ID_BOARD AND lb.ID_MEMBER = {$ID_MEMBER})\n\t\t\tWHERE b.ID_BOARD = {$modSettings['recycle_board']}", __FILE__, __LINE__);
        if (mysql_num_rows($request) == 0) {
            fatal_lang_error('recycle_no_valid_board');
        }
        list($isRead) = mysql_fetch_row($request);
        mysql_free_result($request);
        // Insert a new topic in the recycle board.
        db_query("\n\t\t\tINSERT INTO {$db_prefix}topics\n\t\t\t\t(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG)\n\t\t\tVALUES ({$modSettings['recycle_board']}, {$row['ID_MEMBER']}, {$row['ID_MEMBER']}, {$message}, {$message})", __FILE__, __LINE__);
        // Capture the ID of the new topic...
        $topicID = db_insert_id();
        // If the topic creation went successful, move the message.
        if ($topicID > 0) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}messages\n\t\t\t\tSET \n\t\t\t\t\tID_TOPIC = {$topicID},\n\t\t\t\t\tID_BOARD = {$modSettings['recycle_board']},\n\t\t\t\t\ticon = 'recycled'\n\t\t\t\tWHERE ID_MSG = {$message}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            // Mark recycled topic as read.
            if (!$user_info['is_guest']) {
                db_query("\n\t\t\t\t\tREPLACE INTO {$db_prefix}log_topics\n\t\t\t\t\t\t(ID_TOPIC, ID_MEMBER, ID_MSG)\n\t\t\t\t\tVALUES ({$topicID}, {$ID_MEMBER}, {$modSettings['maxMsgID']})", __FILE__, __LINE__);
            }
            // Mark recycle board as seen, if it was marked as seen before.
            if (!empty($isRead) && !$user_info['is_guest']) {
                db_query("\n\t\t\t\t\tREPLACE INTO {$db_prefix}log_boards\n\t\t\t\t\t\t(ID_BOARD, ID_MEMBER, ID_MSG)\n\t\t\t\t\tVALUES ({$modSettings['recycle_board']}, {$ID_MEMBER}, {$modSettings['maxMsgID']})", __FILE__, __LINE__);
            }
            // Add one topic and post to the recycle bin board.
            db_query("\n\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\tSET\n\t\t\t\t\tnumTopics = numTopics + 1,\n\t\t\t\t\tnumPosts = numPosts + 1\n\t\t\t\tWHERE ID_BOARD = {$modSettings['recycle_board']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            // Make sure this message isn't getting deleted later on.
            $recycle = true;
            // Make sure we update the search subject index.
            updateStats('subject', $topicID, $row['subject']);
        }
    }
    // Deleting a recycled message can not lower anyone's post count.
    if ($row['icon'] == 'recycled') {
        $decreasePostCount = false;
    }
    // This is the last post, update the last post on the board.
    if ($row['ID_LAST_MSG'] == $message) {
        // Find the last message, set it, and decrease the post count.
        $request = db_query("\n\t\t\tSELECT ID_MSG, ID_MEMBER\n\t\t\tFROM {$db_prefix}messages\n\t\t\tWHERE ID_TOPIC = {$row['ID_TOPIC']}\n\t\t\t\tAND ID_MSG != {$message}\n\t\t\tORDER BY ID_MSG DESC\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        $row2 = mysql_fetch_assoc($request);
        mysql_free_result($request);
        db_query("\n\t\t\tUPDATE {$db_prefix}topics\n\t\t\tSET\n\t\t\t\tID_LAST_MSG = {$row2['ID_MSG']},\n\t\t\t\tnumReplies = IF(numReplies = 0, 0, numReplies - 1),\n\t\t\t\tID_MEMBER_UPDATED = {$row2['ID_MEMBER']}\n\t\t\tWHERE ID_TOPIC = {$row['ID_TOPIC']}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
    } else {
        db_query("\n\t\t\tUPDATE {$db_prefix}topics\n\t\t\tSET numReplies = IF(numReplies = 0, 0, numReplies - 1)\n\t\t\tWHERE ID_TOPIC = {$row['ID_TOPIC']}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
    }
    db_query("\n\t\tUPDATE {$db_prefix}boards\n\t\tSET numPosts = IF(numPosts = 0, 0, numPosts - 1)\n\t\tWHERE ID_BOARD = {$row['ID_BOARD']}\n\t\tLIMIT 1", __FILE__, __LINE__);
    // If the poster was registered and the board this message was on incremented
    // the member's posts when it was posted, decrease his or her post count.
    if (!empty($row['ID_MEMBER']) && $decreasePostCount && empty($row['countPosts'])) {
        updateMemberData($row['ID_MEMBER'], array('posts' => '-'));
    }
    // Only remove posts if they're not recycled.
    if (!$recycle) {
        // Remove the message!
        db_query("\n\t\t\tDELETE FROM {$db_prefix}messages\n\t\t\tWHERE ID_MSG = {$message}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        if (!empty($modSettings['search_custom_index_config'])) {
            $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
            $words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
            if (!empty($words)) {
                db_query("\n\t\t\t\t\tDELETE FROM {$db_prefix}log_search_words\n\t\t\t\t\tWHERE ID_WORD IN (" . implode(', ', $words) . ")\n\t\t\t\t\t\tAND ID_MSG = {$message}", __FILE__, __LINE__);
            }
        }
        // Delete attachment(s) if they exist.
        require_once $sourcedir . '/ManageAttachments.php';
        removeAttachments('a.attachmentType = 0 AND a.ID_MSG = ' . $message);
    }
    // Update the pesky statistics.
    updateStats('message');
    updateStats('topic');
    updateStats('calendar');
    // And now to update the last message of each board we messed with.
    require_once $sourcedir . '/Subs-Post.php';
    if ($recycle) {
        updateLastMessages(array($row['ID_BOARD'], $modSettings['recycle_board']));
    } else {
        updateLastMessages($row['ID_BOARD']);
    }
    return false;
}
开发者ID:alencarmo,项目名称:OCF,代码行数:101,代码来源:RemoveTopic.php

示例11: moveTopics

function moveTopics($topics, $toBoard)
{
    global $db_prefix, $sourcedir, $ID_MEMBER, $user_info, $modSettings;
    // Empty array?
    if (empty($topics)) {
        return;
    } elseif (is_numeric($topics)) {
        $condition = '= ' . $topics;
    } elseif (count($topics) == 1) {
        $condition = '= ' . $topics[0];
    } else {
        $condition = 'IN (' . implode(', ', $topics) . ')';
    }
    $numTopics = count($topics);
    $fromBoards = array();
    // Destination board empty or equal to 0?
    if (empty($toBoard)) {
        return;
    }
    // Determine the source boards...
    $request = db_query("\n\t\tSELECT ID_BOARD, COUNT(*) AS numTopics, SUM(numReplies) AS numReplies\n\t\tFROM {$db_prefix}topics\n\t\tWHERE ID_TOPIC {$condition}\n\t\tGROUP BY ID_BOARD", __FILE__, __LINE__);
    // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
    if (mysql_num_rows($request) == 0) {
        return;
    }
    while ($row = mysql_fetch_assoc($request)) {
        // Posts = (numReplies + 1) for each topic.
        $fromBoards[$row['ID_BOARD']] = array('numPosts' => $row['numReplies'] + $row['numTopics'], 'numTopics' => $row['numTopics'], 'ID_BOARD' => $row['ID_BOARD']);
    }
    mysql_free_result($request);
    // Move over the mark_read data. (because it may be read and now not by some!)
    $SaveAServer = max(0, $modSettings['maxMsgID'] - 50000);
    $request = db_query("\n\t\tSELECT lmr.ID_MEMBER, lmr.ID_MSG, t.ID_TOPIC\n\t\tFROM ({$db_prefix}topics AS t, {$db_prefix}log_mark_read AS lmr)\n\t\t\tLEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = t.ID_TOPIC AND lt.ID_MEMBER = lmr.ID_MEMBER)\n\t\tWHERE t.ID_TOPIC {$condition}\n\t\t\tAND lmr.ID_BOARD = t.ID_BOARD\n\t\t\tAND lmr.ID_MSG > t.ID_FIRST_MSG\n\t\t\tAND lmr.ID_MSG > {$SaveAServer}\n\t\t\tAND lmr.ID_MSG > IFNULL(lt.ID_MSG, 0)", __FILE__, __LINE__);
    $log_topics = array();
    while ($row = mysql_fetch_assoc($request)) {
        $log_topics[] = '(' . $row['ID_TOPIC'] . ', ' . $row['ID_MEMBER'] . ', ' . $row['ID_MSG'] . ')';
        // Prevent queries from getting too big. Taking some steam off.
        if (count($log_topics) > 500) {
            db_query("\n\t\t\t\tREPLACE INTO {$db_prefix}log_topics\n\t\t\t\t\t(ID_TOPIC, ID_MEMBER, ID_MSG)\n\t\t\t\tVALUES " . implode(',
					', $log_topics), __FILE__, __LINE__);
            $log_topics = array();
        }
    }
    mysql_free_result($request);
    // Now that we have all the topics that *should* be marked read, and by which members...
    if (!empty($log_topics)) {
        // Insert that information into the database!
        db_query("\n\t\t\tREPLACE INTO {$db_prefix}log_topics\n\t\t\t\t(ID_TOPIC, ID_MEMBER, ID_MSG)\n\t\t\tVALUES " . implode(',
				', $log_topics), __FILE__, __LINE__);
    }
    // Update the number of posts on each board.
    $totalTopics = 0;
    $totalPosts = 0;
    foreach ($fromBoards as $stats) {
        db_query("\n\t\t\tUPDATE {$db_prefix}boards\n\t\t\tSET \n\t\t\t\tnumPosts = IF({$stats['numPosts']} > numPosts, 0, numPosts - {$stats['numPosts']}),\n\t\t\t\tnumTopics = IF({$stats['numTopics']} > numTopics, 0, numTopics - {$stats['numTopics']})\n\t\t\tWHERE ID_BOARD = {$stats['ID_BOARD']}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        $totalTopics += $stats['numTopics'];
        $totalPosts += $stats['numPosts'];
    }
    db_query("\n\t\tUPDATE {$db_prefix}boards\n\t\tSET \n\t\t\tnumTopics = numTopics + {$totalTopics}, \n\t\t\tnumPosts = numPosts + {$totalPosts}\n\t\tWHERE ID_BOARD = {$toBoard}\n\t\tLIMIT 1", __FILE__, __LINE__);
    // Move the topic.  Done.  :P
    db_query("\n\t\tUPDATE {$db_prefix}topics\n\t\tSET ID_BOARD = {$toBoard}\n\t\tWHERE ID_TOPIC {$condition}\n\t\tLIMIT {$numTopics}", __FILE__, __LINE__);
    db_query("\n\t\tUPDATE {$db_prefix}messages\n\t\tSET ID_BOARD = {$toBoard}\n\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
    db_query("\n\t\tUPDATE {$db_prefix}calendar\n\t\tSET ID_BOARD = {$toBoard}\n\t\tWHERE ID_TOPIC {$condition}\n\t\tLIMIT {$numTopics}", __FILE__, __LINE__);
    // Mark target board as seen, if it was already marked as seen before.
    $request = db_query("\n\t\tSELECT (IFNULL(lb.ID_MSG, 0) >= b.ID_MSG_UPDATED) AS isSeen\n\t\tFROM {$db_prefix}boards AS b\n\t\t\tLEFT JOIN {$db_prefix}log_boards AS lb ON (lb.ID_BOARD = b.ID_BOARD AND lb.ID_MEMBER = {$ID_MEMBER})\n\t\tWHERE b.ID_BOARD = {$toBoard}", __FILE__, __LINE__);
    list($isSeen) = mysql_fetch_row($request);
    mysql_free_result($request);
    if (!empty($isSeen) && !$user_info['is_guest']) {
        db_query("\n\t\t\tREPLACE INTO {$db_prefix}log_boards\n\t\t\t\t(ID_BOARD, ID_MEMBER, ID_MSG)\n\t\t\tVALUES ({$toBoard}, {$ID_MEMBER}, {$modSettings['maxMsgID']})", __FILE__, __LINE__);
    }
    // Update 'em pesky stats.
    updateStats('topic');
    updateStats('message');
    updateStats('calendar');
    require_once $sourcedir . '/Subs-Post.php';
    $updates = array_keys($fromBoards);
    $updates[] = $toBoard;
    updateLastMessages(array_unique($updates));
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:79,代码来源:MoveTopic.php

示例12: QuickModeration


//.........这里部分代码省略.........
                $affectedBoards[$to] = array(0, 0);
            }
            if (!isset($affectedBoards[$row['ID_BOARD']])) {
                $affectedBoards[$row['ID_BOARD']] = array(0, 0);
            }
            $affectedBoards[$row['ID_BOARD']][0]--;
            $affectedBoards[$row['ID_BOARD']][1] -= $row['numReplies'];
            $affectedBoards[$to][0]++;
            $affectedBoards[$to][1] += $row['numReplies'];
            // Move the actual topic.
            db_query("\n\t\t\t\tUPDATE {$db_prefix}topics\n\t\t\t\tSET ID_BOARD = {$to}\n\t\t\t\tWHERE ID_TOPIC = {$row['ID_TOPIC']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            db_query("\n\t\t\t\tUPDATE {$db_prefix}messages\n\t\t\t\tSET ID_BOARD = {$to}\n\t\t\t\tWHERE ID_TOPIC = {$row['ID_TOPIC']}", __FILE__, __LINE__);
            db_query("\n\t\t\t\tUPDATE {$db_prefix}calendar\n\t\t\t\tSET ID_BOARD = {$to}\n\t\t\t\tWHERE ID_TOPIC = {$row['ID_TOPIC']}", __FILE__, __LINE__);
            $moveCache2[] = array($row['ID_TOPIC'], $row['ID_BOARD'], $to);
        }
        mysql_free_result($request);
        $moveCache = $moveCache2;
        foreach ($affectedBoards as $ID_BOARD => $topicsPosts) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\tSET numPosts = numPosts + {$topicsPosts['1']}, numTopics = numTopics + {$topicsPosts['0']}\n\t\t\t\tWHERE ID_BOARD = {$ID_BOARD}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
    }
    // Now delete the topics...
    if (!empty($removeCache)) {
        // They can only delete their own topics. (we wouldn't be here if they couldn't do that..)
        if (!empty($board) && !allowedTo('remove_any')) {
            $result = db_query("\n\t\t\t\tSELECT ID_TOPIC\n\t\t\t\tFROM {$db_prefix}topics\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $removeCache) . ")\n\t\t\t\t\tAND ID_MEMBER_STARTED = {$ID_MEMBER}\n\t\t\t\tLIMIT " . count($removeCache), __FILE__, __LINE__);
            $removeCache = array();
            while ($row = mysql_fetch_assoc($result)) {
                $removeCache[] = $row['ID_TOPIC'];
            }
            mysql_free_result($result);
        }
        // Maybe *none* were their own topics.
        if (!empty($removeCache)) {
            // Gotta send the notifications *first*!
            foreach ($removeCache as $topic) {
                logAction('remove', array('topic' => $topic));
                sendNotifications($topic, 'remove');
            }
            require_once $sourcedir . '/RemoveTopic.php';
            removeTopics($removeCache);
        }
    }
    // And lastly, lock the topics...
    if (!empty($lockCache)) {
        $lockStatus = array();
        // Gotta make sure they CAN lock/unlock these topics...
        if (!empty($board) && !allowedTo('lock_any')) {
            // Make sure they started the topic AND it isn't already locked by someone with higher priv's.
            $result = db_query("\n\t\t\t\tSELECT ID_TOPIC, locked\n\t\t\t\tFROM {$db_prefix}topics\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $lockCache) . ")\n\t\t\t\t\tAND ID_MEMBER_STARTED = {$ID_MEMBER}\n\t\t\t\t\tAND locked IN (2, 0)\n\t\t\t\tLIMIT " . count($lockCache), __FILE__, __LINE__);
            $lockCache = array();
            while ($row = mysql_fetch_assoc($result)) {
                $lockCache[] = $row['ID_TOPIC'];
                $lockStatus[$row['ID_TOPIC']] = empty($row['locked']);
            }
            mysql_free_result($result);
        } else {
            $result = db_query("\n\t\t\t\tSELECT ID_TOPIC, locked\n\t\t\t\tFROM {$db_prefix}topics\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $lockCache) . ")\n\t\t\t\tLIMIT " . count($lockCache), __FILE__, __LINE__);
            while ($row = mysql_fetch_assoc($result)) {
                $lockStatus[$row['ID_TOPIC']] = empty($row['locked']);
            }
            mysql_free_result($result);
        }
        // It could just be that *none* were their own topics...
        if (!empty($lockCache)) {
            // Alternate the locked value.
            db_query("\n\t\t\t\tUPDATE {$db_prefix}topics\n\t\t\t\tSET locked = IF(locked = 0, " . (allowedTo('lock_any') ? '1' : '2') . ", 0)\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $lockCache) . ")\n\t\t\t\tLIMIT " . count($lockCache), __FILE__, __LINE__);
        }
    }
    if (!empty($markCache)) {
        $setString = '';
        foreach ($markCache as $topic) {
            $setString .= "\n\t\t\t\t({$modSettings['maxMsgID']}, {$ID_MEMBER}, {$topic}),";
        }
        db_query("\n\t\t\tREPLACE INTO {$db_prefix}log_topics\n\t\t\t\t(ID_MSG, ID_MEMBER, ID_TOPIC)\n\t\t\tVALUES" . substr($setString, 0, -1), __FILE__, __LINE__);
    }
    foreach ($moveCache as $topic) {
        // Didn't actually move anything!
        if (!isset($topic[0])) {
            break;
        }
        logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
        sendNotifications($topic[0], 'move');
    }
    foreach ($lockCache as $topic) {
        logAction('lock', array('topic' => $topic));
        sendNotifications($topic, $lockStatus ? 'lock' : 'unlock');
    }
    foreach ($stickyCache as $topic) {
        logAction('sticky', array('topic' => $topic));
        sendNotifications($topic, 'sticky');
    }
    updateStats('topic');
    updateStats('message');
    updateStats('calendar');
    if (!empty($affectedBoards)) {
        updateLastMessages(array_keys($affectedBoards));
    }
    redirectexit($redirect_url);
}
开发者ID:alencarmo,项目名称:OCF,代码行数:101,代码来源:Subs-Boards.php

示例13: createPost


//.........这里部分代码省略.........
            // Couldn't find the current poster?
            if (mysql_num_rows($request) == 0) {
                trigger_error('createPost(): Invalid member id ' . $posterOptions['id'], E_USER_NOTICE);
                $posterOptions['id'] = 0;
                $posterOptions['name'] = $txt[28];
                $posterOptions['email'] = '';
            } else {
                list($posterOptions['name'], $posterOptions['email']) = mysql_fetch_row($request);
            }
            mysql_free_result($request);
        } else {
            $posterOptions['name'] = $user_info['name'];
            $posterOptions['email'] = $user_info['email'];
        }
        $posterOptions['email'] = addslashes($posterOptions['email']);
    }
    // It's do or die time: forget any user aborts!
    $previous_ignore_user_abort = ignore_user_abort(true);
    $new_topic = empty($topicOptions['id']);
    // Insert the post.
    db_query("\n\t\tINSERT INTO {$db_prefix}messages\n\t\t\t(ID_BOARD, ID_TOPIC, ID_MEMBER, subject, body, posterName, posterEmail, posterTime,\n\t\t\tposterIP, smileysEnabled, modifiedName, icon)\n\t\tVALUES ({$topicOptions['board']}, {$topicOptions['id']}, {$posterOptions['id']}, SUBSTRING('{$msgOptions['subject']}', 1, 255), SUBSTRING('{$msgOptions['body']}', 1, 65534), SUBSTRING('{$posterOptions['name']}', 1, 255), SUBSTRING('{$posterOptions['email']}', 1, 255), " . time() . ",\n\t\t\tSUBSTRING('{$posterOptions['ip']}', 1, 255), " . ($msgOptions['smileys_enabled'] ? '1' : '0') . ", '', SUBSTRING('{$msgOptions['icon']}', 1, 16))", __FILE__, __LINE__);
    $msgOptions['id'] = db_insert_id();
    // Something went wrong creating the message...
    if (empty($msgOptions['id'])) {
        return false;
    }
    // Fix the attachments.
    if (!empty($msgOptions['attachments'])) {
        db_query("\n\t\t\tUPDATE {$db_prefix}attachments\n\t\t\tSET ID_MSG = {$msgOptions['id']}\n\t\t\tWHERE ID_ATTACH IN (" . implode(', ', $msgOptions['attachments']) . ')', __FILE__, __LINE__);
    }
    // Insert a new topic (if the topicID was left empty.
    if ($new_topic) {
        db_query("\n\t\t\tINSERT INTO {$db_prefix}topics\n\t\t\t\t(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, locked, isSticky, numViews, ID_POLL)\n\t\t\tVALUES ({$topicOptions['board']}, {$posterOptions['id']}, {$posterOptions['id']}, {$msgOptions['id']}, {$msgOptions['id']},\n\t\t\t\t" . ($topicOptions['lock_mode'] === null ? '0' : $topicOptions['lock_mode']) . ', ' . ($topicOptions['sticky_mode'] === null ? '0' : $topicOptions['sticky_mode']) . ", 0, " . ($topicOptions['poll'] === null ? '0' : $topicOptions['poll']) . ')', __FILE__, __LINE__);
        $topicOptions['id'] = db_insert_id();
        // The topic couldn't be created for some reason.
        if (empty($topicOptions['id'])) {
            // We should delete the post that did work, though...
            db_query("\n\t\t\t\tDELETE FROM {$db_prefix}messages\n\t\t\t\tWHERE ID_MSG = {$msgOptions['id']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            return false;
        }
        // Fix the message with the topic.
        db_query("\n\t\t\tUPDATE {$db_prefix}messages\n\t\t\tSET ID_TOPIC = {$topicOptions['id']}\n\t\t\tWHERE ID_MSG = {$msgOptions['id']}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        // There's been a new topic AND a new post today.
        trackStats(array('topics' => '+', 'posts' => '+'));
        updateStats('topic', true);
        updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
    } else {
        // Update the number of replies and the lock/sticky status.
        db_query("\n\t\t\tUPDATE {$db_prefix}topics\n\t\t\tSET\n\t\t\t\tID_MEMBER_UPDATED = {$posterOptions['id']}, ID_LAST_MSG = {$msgOptions['id']},\n\t\t\t\tnumReplies = numReplies + 1" . ($topicOptions['lock_mode'] === null ? '' : ",\n\t\t\t\tlocked = {$topicOptions['lock_mode']}") . ($topicOptions['sticky_mode'] === null ? '' : ",\n\t\t\t\tisSticky = {$topicOptions['sticky_mode']}") . "\n\t\t\tWHERE ID_TOPIC = {$topicOptions['id']}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        // One new post has been added today.
        trackStats(array('posts' => '+'));
    }
    // Creating is modifying...in a way.
    db_query("\n\t\tUPDATE {$db_prefix}messages\n\t\tSET ID_MSG_MODIFIED = {$msgOptions['id']}\n\t\tWHERE ID_MSG = {$msgOptions['id']}", __FILE__, __LINE__);
    // Increase the number of posts and topics on the board.
    db_query("\n\t\tUPDATE {$db_prefix}boards\n\t\tSET numPosts = numPosts + 1" . ($new_topic ? ', numTopics = numTopics + 1' : '') . "\n\t\tWHERE ID_BOARD = {$topicOptions['board']}\n\t\tLIMIT 1", __FILE__, __LINE__);
    // Mark inserted topic as read (only for the user calling this function).
    if (!empty($topicOptions['mark_as_read']) && !$user_info['is_guest']) {
        // Since it's likely they *read* it before replying, let's try an UPDATE first.
        if (!$new_topic) {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}log_topics\n\t\t\t\tSET ID_MSG = {$msgOptions['id']} + 1\n\t\t\t\tWHERE ID_MEMBER = {$ID_MEMBER}\n\t\t\t\t\tAND ID_TOPIC = {$topicOptions['id']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            $flag = db_affected_rows() != 0;
        }
        if (empty($flag)) {
            db_query("\n\t\t\t\tREPLACE INTO {$db_prefix}log_topics\n\t\t\t\t\t(ID_TOPIC, ID_MEMBER, ID_MSG)\n\t\t\t\tVALUES ({$topicOptions['id']}, {$ID_MEMBER}, {$msgOptions['id']} + 1)", __FILE__, __LINE__);
        }
    }
    // If there's a custom search index, it needs updating...
    if (!empty($modSettings['search_custom_index_config'])) {
        //$index_settings = unserialize($modSettings['search_custom_index_config']);
        $inserts = '';
        foreach (text2words(stripslashes($msgOptions['body']), 4, true) as $word) {
            $inserts .= "({$word}, {$msgOptions['id']}),\n";
        }
        if (!empty($inserts)) {
            db_query("\n\t\t\t\tINSERT IGNORE INTO {$db_prefix}log_search_words\n\t\t\t\t\t(ID_WORD, ID_MSG)\n\t\t\t\tVALUES\n\t\t\t\t\t" . substr($inserts, 0, -2), __FILE__, __LINE__);
        }
    }
    // Increase the post counter for the user that created the post.
    if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id'])) {
        // Are you the one that happened to create this post?
        if ($ID_MEMBER == $posterOptions['id']) {
            $user_info['posts']++;
        }
        updateMemberData($posterOptions['id'], array('posts' => '+'));
    }
    // They've posted, so they can make the view count go up one if they really want. (this is to keep views >= replies...)
    $_SESSION['last_read_topic'] = 0;
    // Better safe than sorry.
    if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
        $_SESSION['topicseen_cache'][$topicOptions['board']]--;
    }
    // Update all the stats so everyone knows about this new topic and message.
    updateStats('message', true, $msgOptions['id']);
    updateLastMessages($topicOptions['board'], $msgOptions['id']);
    // Alright, done now... we can abort now, I guess... at least this much is done.
    ignore_user_abort($previous_ignore_user_abort);
    // Success.
    return true;
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:101,代码来源:Subs-Post.php

示例14: splitTopic


//.........这里部分代码省略.........
		LIMIT 2', array('msg_list' => $splitMessages, 'id_topic' => $split1_ID_TOPIC));
    while ($row = $db->fetch_assoc($request)) {
        // As before get the right first and last message dependant on approved state...
        if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) {
            $split2_first_msg = $row['myid_first_msg'];
        }
        if (empty($split2_last_msg) || $row['approved']) {
            $split2_last_msg = $row['myid_last_msg'];
        }
        // Then do the counts again...
        if ($row['approved']) {
            $split2_approved = true;
            $split2_replies = $row['message_count'] - 1;
            $split2_unapprovedposts = 0;
        } else {
            // Should this one be approved??
            if ($split2_first_msg == $row['myid_first_msg']) {
                $split2_approved = false;
            }
            if (!isset($split2_replies)) {
                $split2_replies = 0;
            } elseif (!$split2_approved) {
                $split2_replies++;
            }
            $split2_unapprovedposts = $row['message_count'];
        }
    }
    $db->free_result($request);
    $split2_firstMem = getMsgMemberID($split2_first_msg);
    $split2_lastMem = getMsgMemberID($split2_last_msg);
    // No database changes yet, so let's double check to see if everything makes at least a little sense.
    if ($split1_first_msg <= 0 || $split1_last_msg <= 0 || $split2_first_msg <= 0 || $split2_last_msg <= 0 || $split1_replies < 0 || $split2_replies < 0 || $split1_unapprovedposts < 0 || $split2_unapprovedposts < 0 || !isset($split1_approved) || !isset($split2_approved)) {
        fatal_lang_error('cant_find_messages');
    }
    // You cannot split off the first message of a topic.
    if ($split1_first_msg > $split2_first_msg) {
        fatal_lang_error('split_first_post', false);
    }
    // We're off to insert the new topic!  Use 0 for now to avoid UNIQUE errors.
    $db->insert('', '{db_prefix}topics', array('id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int', 'id_last_msg' => 'int', 'num_replies' => 'int', 'unapproved_posts' => 'int', 'approved' => 'int', 'is_sticky' => 'int'), array((int) $id_board, $split2_firstMem, $split2_lastMem, 0, 0, $split2_replies, $split2_unapprovedposts, (int) $split2_approved, 0), array('id_topic'));
    $split2_ID_TOPIC = $db->insert_id('{db_prefix}topics', 'id_topic');
    if ($split2_ID_TOPIC <= 0) {
        fatal_lang_error('cant_insert_topic');
    }
    // Move the messages over to the other topic.
    $new_subject = strtr(Util::htmltrim(Util::htmlspecialchars($new_subject)), array("\r" => '', "\n" => '', "\t" => ''));
    // Check the subject length.
    if (Util::strlen($new_subject) > 100) {
        $new_subject = Util::substr($new_subject, 0, 100);
    }
    // Valid subject?
    if ($new_subject != '') {
        $db->query('', '
			UPDATE {db_prefix}messages
			SET
				id_topic = {int:id_topic},
				subject = CASE WHEN id_msg = {int:split_first_msg} THEN {string:new_subject} ELSE {string:new_subject_replies} END
			WHERE id_msg IN ({array_int:split_msgs})', array('split_msgs' => $splitMessages, 'id_topic' => $split2_ID_TOPIC, 'new_subject' => $new_subject, 'split_first_msg' => $split2_first_msg, 'new_subject_replies' => $txt['response_prefix'] . $new_subject));
        // Cache the new topics subject... we can do it now as all the subjects are the same!
        updateStats('subject', $split2_ID_TOPIC, $new_subject);
    }
    // Any associated reported posts better follow...
    require_once SUBSDIR . '/Topic.subs.php';
    updateSplitTopics(array('splitMessages' => $splitMessages, 'split2_ID_TOPIC' => $split2_ID_TOPIC, 'split1_replies' => $split1_replies, 'split1_first_msg' => $split1_first_msg, 'split1_last_msg' => $split1_last_msg, 'split1_firstMem' => $split1_firstMem, 'split1_lastMem' => $split1_lastMem, 'split1_unapprovedposts' => $split1_unapprovedposts, 'split1_ID_TOPIC' => $split1_ID_TOPIC, 'split2_first_msg' => $split2_first_msg, 'split2_last_msg' => $split2_last_msg, 'split2_ID_TOPIC' => $split2_ID_TOPIC, 'split2_approved' => $split2_approved), $id_board);
    require_once SUBSDIR . '/FollowUps.subs.php';
    // Let's see if we can create a stronger bridge between the two topics
    // @todo not sure what message from the oldest topic I should link to the new one, so I'll go with the first
    linkMessages($split1_first_msg, $split2_ID_TOPIC);
    // Copy log topic entries.
    // @todo This should really be chunked.
    $request = $db->query('', '
		SELECT id_member, id_msg, unwatched
		FROM {db_prefix}log_topics
		WHERE id_topic = {int:id_topic}', array('id_topic' => (int) $split1_ID_TOPIC));
    if ($db->num_rows($request) > 0) {
        $replaceEntries = array();
        while ($row = $db->fetch_assoc($request)) {
            $replaceEntries[] = array($row['id_member'], $split2_ID_TOPIC, $row['id_msg'], $row['unwatched']);
        }
        require_once SUBSDIR . '/Topic.subs.php';
        markTopicsRead($replaceEntries, false);
        unset($replaceEntries);
    }
    $db->free_result($request);
    // Housekeeping.
    updateTopicStats();
    updateLastMessages($id_board);
    logAction('split', array('topic' => $split1_ID_TOPIC, 'new_topic' => $split2_ID_TOPIC, 'board' => $id_board));
    // Notify people that this topic has been split?
    require_once SUBSDIR . '/Notification.subs.php';
    sendNotifications($split1_ID_TOPIC, 'split');
    // If there's a search index that needs updating, update it...
    require_once SUBSDIR . '/Search.subs.php';
    $searchAPI = findSearchAPI();
    if (is_callable(array($searchAPI, 'topicSplit'))) {
        $searchAPI->topicSplit($split2_ID_TOPIC, $splitMessages);
    }
    // Return the ID of the newly created topic.
    return $split2_ID_TOPIC;
}
开发者ID:Ralkage,项目名称:Elkarte,代码行数:101,代码来源:Topic.subs.php

示例15: moveTopics


//.........这里部分代码省略.........
    }
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}boards
		SET
			num_topics = num_topics + {int:total_topics},
			num_posts = num_posts + {int:total_posts},' . ($isRecycleDest ? '
			unapproved_posts = {int:no_unapproved}, unapproved_topics = {int:no_unapproved}' : '
			unapproved_posts = unapproved_posts + {int:total_unapproved_posts},
			unapproved_topics = unapproved_topics + {int:total_unapproved_topics}') . '
		WHERE id_board = {int:id_board}', array('id_board' => $toBoard, 'total_topics' => $totalTopics, 'total_posts' => $totalPosts, 'total_unapproved_topics' => $totalUnapprovedTopics, 'total_unapproved_posts' => $totalUnapprovedPosts, 'no_unapproved' => 0));
    // Move the topic.  Done.  :P
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}topics
		SET id_board = {int:id_board}' . ($isRecycleDest ? ',
			unapproved_posts = {int:no_unapproved}, approved = {int:is_approved}' : '') . '
		WHERE id_topic IN ({array_int:topics})', array('id_board' => $toBoard, 'topics' => $topics, 'is_approved' => 1, 'no_unapproved' => 0));
    // If this was going to the recycle bin, check what messages are being recycled, and remove them from the queue.
    if ($isRecycleDest && ($totalUnapprovedTopics || $totalUnapprovedPosts)) {
        $request = $smcFunc['db_query']('', '
			SELECT id_msg
			FROM {db_prefix}messages
			WHERE id_topic IN ({array_int:topics})
				and approved = {int:not_approved}', array('topics' => $topics, 'not_approved' => 0));
        $approval_msgs = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $approval_msgs[] = $row['id_msg'];
        }
        $smcFunc['db_free_result']($request);
        // Empty the approval queue for these, as we're going to approve them next.
        if (!empty($approval_msgs)) {
            $smcFunc['db_query']('', '
				DELETE FROM {db_prefix}approval_queue
				WHERE id_msg IN ({array_int:message_list})
					AND id_attach = {int:id_attach}', array('message_list' => $approval_msgs, 'id_attach' => 0));
        }
        // Get all the current max and mins.
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, id_first_msg, id_last_msg
			FROM {db_prefix}topics
			WHERE id_topic IN ({array_int:topics})', array('topics' => $topics));
        $topicMaxMin = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $topicMaxMin[$row['id_topic']] = array('min' => $row['id_first_msg'], 'max' => $row['id_last_msg']);
        }
        $smcFunc['db_free_result']($request);
        // Check the MAX and MIN are correct.
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, MIN(id_msg) AS first_msg, MAX(id_msg) AS last_msg
			FROM {db_prefix}messages
			WHERE id_topic IN ({array_int:topics})
			GROUP BY id_topic', array('topics' => $topics));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // If not, update.
            if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) {
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}topics
					SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
					WHERE id_topic = {int:selected_topic}', array('first_msg' => $row['first_msg'], 'last_msg' => $row['last_msg'], 'selected_topic' => $row['id_topic']));
            }
        }
        $smcFunc['db_free_result']($request);
    }
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}messages
		SET id_board = {int:id_board}' . ($isRecycleDest ? ',approved = {int:is_approved}' : '') . '
		WHERE id_topic IN ({array_int:topics})', array('id_board' => $toBoard, 'topics' => $topics, 'is_approved' => 1));
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}log_reported
		SET id_board = {int:id_board}
		WHERE id_topic IN ({array_int:topics})', array('id_board' => $toBoard, 'topics' => $topics));
    $smcFunc['db_query']('', '
		UPDATE {db_prefix}calendar
		SET id_board = {int:id_board}
		WHERE id_topic IN ({array_int:topics})', array('id_board' => $toBoard, 'topics' => $topics));
    // Mark target board as seen, if it was already marked as seen before.
    $request = $smcFunc['db_query']('', '
		SELECT (IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS isSeen
		FROM {db_prefix}boards AS b
			LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
		WHERE b.id_board = {int:id_board}', array('current_member' => $user_info['id'], 'id_board' => $toBoard));
    list($isSeen) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    if (!empty($isSeen) && !$user_info['is_guest']) {
        $smcFunc['db_insert']('replace', '{db_prefix}log_boards', array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), array($toBoard, $user_info['id'], $modSettings['maxMsgID']), array('id_board', 'id_member'));
    }
    // Update 'em pesky stats.
    updateStats('topic');
    updateStats('message');
    updateSettings(array('calendar_updated' => time()));
    // Update the cache?
    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) {
        foreach ($topics as $topic_id) {
            cache_put_data('topic_board-' . $topic_id, null, 120);
        }
    }
    require_once $sourcedir . '/Subs-Post.php';
    $updates = array_keys($fromBoards);
    $updates[] = $toBoard;
    updateLastMessages(array_unique($updates));
}
开发者ID:Kheros,项目名称:MMOver,代码行数:101,代码来源:MoveTopic.php


注:本文中的updateLastMessages函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。