Пример #1
0
function ModifyPostSettings($return_config = false)
{
    global $context, $txt, $modSettings, $scripturl, $sourcedir, $backend_subdir;
    // All the settings...
    $config_vars = array(array('check', 'enableUserTagging'), array('int', 'maxTagsPerPost'), array('check', 'removeNestedQuotes'), array('check', 'disable_wysiwyg'), array('check', 'use_post_cache'), array('int', 'post_cache_cutoff'), '', array('int', 'max_messageLength', 'subtext' => $txt['max_messageLength_zero'], 'postinput' => $txt['manageposts_characters']), array('int', 'fixLongWords', 'subtext' => $txt['fixLongWords_zero'] . ($context['utf8'] ? ' <span class="alert">' . $txt['fixLongWords_warning'] . '</span>' : ''), 'postinput' => $txt['manageposts_characters']), array('int', 'topicSummaryPosts', 'postinput' => $txt['manageposts_posts']), '', array('int', 'spamWaitTime', 'postinput' => $txt['manageposts_seconds']), array('int', 'edit_wait_time', 'postinput' => $txt['manageposts_seconds']), array('int', 'edit_disable_time', 'subtext' => $txt['edit_disable_time_zero'], 'postinput' => $txt['manageposts_minutes']));
    if (!isset($modSettings['post_cache_cutoff']) || $modSettings['post_cache_cutoff'] < 10) {
        $modSettings['post_cache_cutoff'] = 10;
    }
    if ($modSettings['post_cache_cutoff'] > 9999) {
        $modSettings['post_cache_cutoff'] = 9999;
    }
    if (empty($modSettings['maxTagsPerPost']) || $modSettings['maxTagsPerPost'] > 20) {
        $modSettings['maxTagsPerPost'] = 10;
    }
    if ($return_config) {
        return $config_vars;
    }
    // We'll want this for our easy save.
    require_once $sourcedir . '/' . $backend_subdir . '/ManageServer.php';
    // Setup the template.
    $context['page_title'] = $txt['manageposts_settings'];
    $context['sub_template'] = 'show_settings';
    // Are we saving them - are we??
    if (isset($_GET['save'])) {
        checkSession();
        // If we're changing the message length let's check the column is big enough.
        if (!empty($_POST['max_messageLength']) && $_POST['max_messageLength'] != $modSettings['max_messageLength']) {
            db_extend('packages');
            $colData = smf_db_list_columns('{db_prefix}messages', true);
            foreach ($colData as $column) {
                if ($column['name'] == 'body') {
                    $body_type = $column['type'];
                }
            }
            $indData = smf_db_list_indexes('{db_prefix}messages', true);
            foreach ($indData as $index) {
                foreach ($index['columns'] as $column) {
                    if ($column == 'body' && $index['type'] == 'fulltext') {
                        $fulltext = true;
                    }
                }
            }
            if (isset($body_type) && $_POST['max_messageLength'] > 65535 && $body_type == 'text') {
                // !!! Show an error message?!
                // MySQL only likes fulltext indexes on text columns... for now?
                if (!empty($fulltext)) {
                    $_POST['max_messageLength'] = 65535;
                } else {
                    // Make it longer so we can do their limit.
                    smf_db_change_column('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
                }
            } elseif (isset($body_type) && $_POST['max_messageLength'] <= 65535 && $body_type != 'text') {
                // Shorten the column so we can have the benefit of fulltext searching again!
                smf_db_change_column('{db_prefix}messages', 'body', array('type' => 'text'));
            }
        }
        saveDBSettings($config_vars);
        redirectexit('action=admin;area=postsettings;sa=posts');
    }
    // Final settings...
    $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=posts';
    $context['settings_title'] = $txt['manageposts_settings'];
    // Prepare the settings...
    prepareDBSettingContext($config_vars);
}
Пример #2
0
function smf_db_add_column($table_name, $column_info, $parameters = array(), $if_exists = 'update', $error = 'fatal')
{
    global $db_package_log, $txt, $db_prefix;
    $table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
    // Log that we will want to uninstall this!
    $db_package_log[] = array('remove_column', $table_name, $column_info['name']);
    // Does it exist - if so don't add it again!
    $columns = smf_db_list_columns($table_name, false);
    foreach ($columns as $column) {
        if ($column == $column_info['name']) {
            // If we're going to overwrite then use change column.
            if ($if_exists == 'update') {
                return smf_db_change_column($table_name, $column_info['name'], $column_info);
            } else {
                return false;
            }
        }
    }
    // Get the specifics...
    $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
    list($type, $size) = smf_db_calculate_type($column_info['type'], $column_info['size']);
    // Allow unsigned integers (mysql only)
    $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
    if ($size !== null) {
        $type = $type . '(' . $size . ')';
    }
    // Now add the thing!
    $query = '
		ALTER TABLE ' . $table_name . '
		ADD `' . $column_info['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (empty($column_info['null']) ? 'NOT NULL' : '') . ' ' . (!isset($column_info['default']) ? '' : 'default \'' . addslashes($column_info['default']) . '\'') . ' ' . (empty($column_info['auto']) ? '' : 'auto_increment primary key') . ' ';
    smf_db_query($query, array('security_override' => true));
    return true;
}