예제 #1
0
/**
 * Related Topics
 *
 * @package RelatedTopics
 * @author Niko Pahajoki http://madjoki.com/
 * @version 1.5
 * @license http://madjoki.com/smf-mods/license/ New-BSD
 */
function RelatedTopicsAdminBuildIndex()
{
    global $smcFunc, $scripturl, $modSettings, $context, $txt;
    loadTemplate('Admin');
    loadLanguage('Admin');
    if (!isset($context['relatedClass']) && !initRelated()) {
        fatal_lang_error('no_methods_selected');
    }
    $context['step'] = empty($_REQUEST['step']) ? 0 : (int) $_REQUEST['step'];
    if ($context['step'] == 0) {
        // Clear caches
        foreach ($context['relatedClass'] as $class) {
            $class->recreateIndexTables();
        }
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}related_topics');
    }
    $request = $smcFunc['db_query']('', '
		SELECT MAX(id_topic)
		FROM {db_prefix}topics');
    list($max_topics) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    // How many topics to do per page load?
    $perStep = 150;
    $last = $context['step'] + $perStep;
    // Search for topic ids between first and last which are not in ignored boards
    $request = $smcFunc['db_query']('', '
		SELECT t.id_topic
		FROM {db_prefix}topics AS t
		WHERE t.id_topic > {int:start}
			AND t.id_topic <= {int:last}' . (!empty($context['rt_ignore']) ? '
			AND t.id_board NOT IN({array_int:ignored})' : ''), array('start' => $context['step'], 'last' => $last, 'ignored' => $context['rt_ignore']));
    $topics = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $topics[] = $row['id_topic'];
    }
    $smcFunc['db_free_result']($request);
    // Update topics
    relatedUpdateTopics($topics, true);
    if ($last >= $max_topics) {
        redirectexit('action=admin;area=relatedtopics;sa=methods');
    }
    $context['sub_template'] = 'not_done';
    $context['continue_get_data'] = '?action=admin;area=relatedtopics;sa=buildIndex;step=' . $last;
    $context['continue_percent'] = round(100 * ($last / $max_topics));
    $context['continue_post_data'] = '';
    $context['continue_countdown'] = '2';
    obExit();
}
예제 #2
0
파일: Subs-Post.php 프로젝트: norv/EosAlpha
function modifyPost(&$msgOptions, &$topicOptions, &$posterOptions)
{
    global $user_info, $modSettings, $context, $sourcedir;
    $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;
    $tagged_users = array();
    $context['can_tag_users'] = allowedTo('tag_users');
    if (isset($msgOptions['body'])) {
        $tagged_users = handleUserTags($msgOptions['body']);
    }
    // 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'];
        if (!empty($modSettings['search_custom_index_config'])) {
            $request = smf_db_query('
				SELECT body, smileys_enabled
				FROM {db_prefix}messages
				WHERE id_msg = {int:id_msg}', array('id_msg' => $msgOptions['id']));
            list($old_body, $old_smileys_enabled) = mysql_fetch_row($request);
            mysql_free_result($request);
        }
    }
    if (isset($msgOptions['locked'])) {
        $messages_columns['locked'] = $msgOptions['locked'];
    }
    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;
        $smileys_enabled = $msgOptions['smileys_enabled'];
    } else {
        if (isset($msgOptions['body'])) {
            $smileys_enabled = $old_smileys_enabled;
        }
    }
    // Which columns need to be ints?
    $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
    $update_parameters = array('id_msg' => $msgOptions['id']);
    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.
    smf_db_query('
		UPDATE {db_prefix}messages
		SET ' . implode(', ', $messages_columns) . '
		WHERE id_msg = {int:id_msg}', $update_parameters);
    /*
     * delete cached posts (they will update at the next view)
     */
    if (isset($msgOptions['body'])) {
        smf_db_query('DELETE FROM {db_prefix}messages_cache WHERE id_msg = {int:id_msg}', array('id_msg' => $msgOptions['id']));
        CacheAPI::clearCacheByPrefix('parse:' . trim($msgOptions['id']) . '-');
    } else {
        $context['no_astream'] = true;
    }
    $context['no_astream'] = isset($context['no_astream']) ? $context['no_astream'] : 0;
    // Lock and or sticky the post.
    if ($topicOptions['sticky_mode'] !== null || $topicOptions['lock_mode'] !== null || $topicOptions['poll'] !== null) {
        smf_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']));
    }
    if (isset($topicOptions['id_first_msg']) && $msgOptions['id'] == $topicOptions['id_first_msg']) {
        if (isset($topicOptions['topic_prefix'])) {
            smf_db_query('
				UPDATE {db_prefix}topics
				SET
					id_prefix = {int:id_prefix}
				WHERE id_topic = {int:id_topic}', array('id_prefix' => $topicOptions['topic_prefix'], 'id_topic' => $topicOptions['id']));
        }
        if (isset($topicOptions['topic_layout'])) {
            smf_db_query('
				UPDATE {db_prefix}topics
				SET
					id_layout = {int:id_layout}
				WHERE id_topic = {int:id_topic}', array('id_layout' => $topicOptions['topic_layout'], '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.
        smf_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 = smf_db_affected_rows() != 0;
        if (empty($flag)) {
            smf_db_insert('ignore', '{db_prefix}log_topics', array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), array($topicOptions['id'], $user_info['id'], $modSettings['maxMsgID']), array('id_topic', 'id_member'));
        }
    }
    if (count($tagged_users) > 0) {
        notifyTaggedUsers($tagged_users, array('id_topic' => $topicOptions['id'], 'id_message' => $msgOptions['id']));
    }
    // If there's a custom search index, it needs to be modified...
    if (isset($msgOptions['body']) && !empty($modSettings['search_custom_index_config'])) {
        $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
        $stopwords = empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
        $old_index = text2words($old_body, $customIndexSettings['bytes_per_word'], true);
        $new_index = text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true);
        // Calculate the words to be added and removed from the index.
        $removed_words = array_diff(array_diff($old_index, $new_index), $stopwords);
        $inserted_words = array_diff(array_diff($new_index, $old_index), $stopwords);
        // Delete the removed words AND the added ones to avoid key constraints.
        if (!empty($removed_words)) {
            $removed_words = array_merge($removed_words, $inserted_words);
            smf_db_query('
				DELETE FROM {db_prefix}log_search_words
				WHERE id_msg = {int:id_msg}
					AND id_word IN ({array_int:removed_words})', array('removed_words' => $removed_words, 'id_msg' => $msgOptions['id']));
        }
        // Add the new words to be indexed.
        if (!empty($inserted_words)) {
            $inserts = array();
            foreach ($inserted_words as $word) {
                $inserts[] = array($word, $msgOptions['id']);
            }
            smf_db_insert('insert', '{db_prefix}log_search_words', array('id_word' => 'string', 'id_msg' => 'int'), $inserts, array('id_word', 'id_msg'));
        }
    }
    if (isset($msgOptions['subject'])) {
        // Only update the subject if this was the first message in the topic.
        $request = smf_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 (mysql_num_rows($request) == 1) {
            updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
            // Added by Related Topics
            if (isset($modSettings['have_related_topics']) && $modSettings['have_related_topics']) {
                require_once $sourcedir . '/lib/Subs-Related.php';
                relatedUpdateTopics($topicOptions['id']);
            }
            // Related Topics END
        }
        mysql_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']);
    }
    // record in activity stream
    if ($modSettings['astream_active'] && !$context['no_astream']) {
        require_once $sourcedir . '/lib/Subs-Activities.php';
        aStreamAdd($user_info['id'], ACT_MODIFY_POST, array('member_name' => $user_info['name'], 'topic_title' => $msgOptions['subject']), $topicOptions['board'], $topicOptions['id'], $msgOptions['id'], $msgOptions['id_owner']);
    }
    return true;
}