Exemplo n.º 1
0
 /**
  * Modify any setting related to posts and posting.
  *
  * - Requires the admin_forum permission.
  * - Accessed from ?action=admin;area=postsettings;sa=posts.
  *
  * @uses Admin template, edit_post_settings sub-template.
  */
 public function action_postSettings_display()
 {
     global $context, $txt, $modSettings, $scripturl, $db_type;
     // Initialize the form
     $this->_initPostSettingsForm();
     $config_vars = $this->_postSettings->settings();
     // 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 (and we are using MySQL) let's check the column is big enough.
         if (isset($_POST['max_messageLength']) && $_POST['max_messageLength'] != $modSettings['max_messageLength'] && $db_type == 'mysql') {
             require_once SUBSDIR . '/Maintenance.subs.php';
             $colData = getMessageTableColumns();
             foreach ($colData as $column) {
                 if ($column['name'] == 'body') {
                     $body_type = $column['type'];
                 }
             }
             if (isset($body_type) && ($_POST['max_messageLength'] > 65535 || $_POST['max_messageLength'] == 0) && $body_type == 'text') {
                 fatal_lang_error('convert_to_mediumtext', false, array($scripturl . '?action=admin;area=maintain;sa=database'));
             }
         }
         // If we're changing the post preview length let's check its valid
         if (!empty($_POST['preview_characters'])) {
             $_POST['preview_characters'] = (int) min(max(0, $_POST['preview_characters']), 512);
         }
         call_integration_hook('integrate_save_post_settings');
         Settings_Form::save_db($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...
     Settings_Form::prepare_db($config_vars);
 }
Exemplo n.º 2
0
    /**
     * Convert the column "body" of the table {db_prefix}messages from TEXT to
     * MEDIUMTEXT and vice versa.
     *
     * What it does:
     * - It requires the admin_forum permission.
     * - This is needed only for MySQL.
     * - During the convertion from MEDIUMTEXT to TEXT it check if any of the
     * posts exceed the TEXT length and if so it aborts.
     * - This action is linked from the maintenance screen (if it's applicable).
     * - Accessed by ?action=admin;area=maintain;sa=database;activity=convertmsgbody.
     *
     * @uses the convert_msgbody sub template of the Admin template.
     */
    public function action_convertmsgbody_display()
    {
        global $context, $txt, $db_type, $modSettings, $time_start;
        // Show me your badge!
        isAllowedTo('admin_forum');
        if ($db_type != 'mysql') {
            return;
        }
        $colData = getMessageTableColumns();
        foreach ($colData as $column) {
            if ($column['name'] == 'body') {
                $body_type = $column['type'];
                break;
            }
        }
        $context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
        if ($body_type == 'text' || $body_type != 'text' && isset($_POST['do_conversion'])) {
            checkSession();
            validateToken('admin-maint');
            // Make it longer so we can do their limit.
            if ($body_type == 'text') {
                resizeMessageTableBody('mediumtext');
            } else {
                resizeMessageTableBody('text');
            }
            $colData = getMessageTableColumns();
            foreach ($colData as $column) {
                if ($column['name'] == 'body') {
                    $body_type = $column['type'];
                }
            }
            $context['maintenance_finished'] = $txt[$context['convert_to'] . '_title'];
            $context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
            $context['convert_to_suggest'] = $body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536;
            return;
        } elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont']))) {
            checkSession();
            if (empty($_REQUEST['start'])) {
                validateToken('admin-maint');
            } else {
                validateToken('admin-convertMsg');
            }
            $context['page_title'] = $txt['not_done_title'];
            $context['continue_post_data'] = '';
            $context['continue_countdown'] = 3;
            $context['sub_template'] = 'not_done';
            $increment = 500;
            $id_msg_exceeding = isset($_POST['id_msg_exceeding']) ? explode(',', $_POST['id_msg_exceeding']) : array();
            $max_msgs = countMessages();
            // Try for as much time as possible.
            @set_time_limit(600);
            while ($_REQUEST['start'] < $max_msgs) {
                $id_msg_exceeding = detectExceedingMessages($_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-convertMsg');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-convertMsg_token_var'] . '" value="' . $context['admin-convertMsg_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
						<input type="hidden" name="id_msg_exceeding" value="' . implode(',', $id_msg_exceeding) . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=database;activity=convertmsgbody;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round(100 * $_REQUEST['start'] / $max_msgs);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            createToken('admin-maint');
            $context['page_title'] = $txt[$context['convert_to'] . '_title'];
            $context['sub_template'] = 'convert_msgbody';
            if (!empty($id_msg_exceeding)) {
                if (count($id_msg_exceeding) > 100) {
                    $query_msg = array_slice($id_msg_exceeding, 0, 100);
                    $context['exceeding_messages_morethan'] = sprintf($txt['exceeding_messages_morethan'], count($id_msg_exceeding));
                } else {
                    $query_msg = $id_msg_exceeding;
                }
                $context['exceeding_messages'] = getExceedingMessages($query_msg);
            }
        }
    }