Пример #1
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);
            }
        }
    }
Пример #2
0
<?php

$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$type = isset($_GET['type']) ? $_GET['type'] : NULL;
$cat = isset($_GET['cat']) ? $_GET['cat'] : NULL;
$count = countMessages($mysql_link, $type, $cat);
if ($count != 0) {
    $messages = getMessages($mysql_link, $type, $cat, $page, PERPAGE);
    if (is_array($messages)) {
        $messages = messageIntro($messages);
    }
    $pager = Pager($page, $count, PERPAGE);
} else {
    $messages = FALSE;
    $pager = FALSE;
}
if ($type) {
    $type = '&type=' . $type;
}
if ($cat) {
    $cat = '&cat=' . $cat;
}
$content = template('content.tpl.php', array('title' => 'Главная страница', 'messages' => $messages, 'pager' => $pager, 'type' => $type, 'cat' => $cat));